Created
March 23, 2021 04:45
-
-
Save sidouglas/a3b0e686e31376df3d32e7b1b4aa6c4f to your computer and use it in GitHub Desktop.
MediaStream to MediaStream JSON Mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// run this in the browser console. | |
function buildJSON(streams) { | |
clear(); | |
var mock = [] | |
var mockTrack = (stream) => { | |
const output = stream.reduce((acc, next) => { | |
const clone = {} | |
for (var i in next) { | |
if (typeof next[i] === 'string' || typeof next[i] === 'boolean') { | |
clone[i] = next[i] | |
} | |
} | |
const settings = next.getSettings() | |
clone.getSettings = JSON.stringify(settings) | |
clone.stop = 'MOCK_FUNCTION' | |
acc.push(clone) | |
return acc | |
}, []) | |
return `${JSON.stringify(output)}` | |
} | |
streams.forEach((stream) => { | |
mock.push({ | |
id: stream.id, | |
active: stream.active, | |
getTracks: mockTrack(stream.getTracks()), | |
getAudioTracks: mockTrack(stream.getAudioTracks()), | |
getVideoTracks: mockTrack(stream.getVideoTracks()), | |
onactive: Function.prototype, | |
onaddtrack: Function.prototype, | |
oninactive: Function.prototype, | |
onremovetrack: Function.prototype, | |
}) | |
console.dir(mock) | |
copy(mock) | |
}) | |
} | |
// buildJSON(mediaStreams) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment