-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ov-components-refactor'
- Loading branch information
Showing
27 changed files
with
16,772 additions
and
1,310 deletions.
There are no files selected for viewing
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
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
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
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
30 changes: 30 additions & 0 deletions
30
openvidu-components-angular/e2e/webcomponent-app/utils/filter-stream.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class FilterStream { | ||
constructor(stream, label) { | ||
const videoTrack = stream.getVideoTracks()[0]; | ||
const { width, height } = videoTrack.getSettings(); | ||
const canvas = document.createElement('canvas'); | ||
const ctx = canvas.getContext('2d'); | ||
const video = document.createElement('video'); | ||
video.srcObject = new MediaStream([videoTrack]); | ||
video.play(); | ||
|
||
video.addEventListener('play', () => { | ||
const loop = () => { | ||
if (!video.paused && !video.ended) { | ||
ctx.filter = 'grayscale(100%)'; | ||
ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, video.videoWidth, video.videoHeight); | ||
setTimeout(loop, 33); | ||
} | ||
}; | ||
loop(); | ||
}); | ||
this.outputStream = canvas.captureStream(); | ||
|
||
Object.defineProperty(this.outputStream.getVideoTracks()[0], 'label', { | ||
writable: true, | ||
value: label | ||
}); | ||
} | ||
} | ||
|
||
export { FilterStream }; |
62 changes: 62 additions & 0 deletions
62
openvidu-components-angular/e2e/webcomponent-app/utils/media-devices.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Ideally we'd use an editor or import shaders directly from the API. | ||
import { FilterStream } from './filter-stream.js'; | ||
|
||
export default function monkeyPatchMediaDevices() { | ||
const enumerateDevicesFn = MediaDevices.prototype.enumerateDevices; | ||
const getUserMediaFn = MediaDevices.prototype.getUserMedia; | ||
const getDisplayMediaFn = MediaDevices.prototype.getDisplayMedia; | ||
|
||
const fakeDevice = { | ||
deviceId: 'virtual', | ||
groupID: '', | ||
kind: 'videoinput', | ||
label: 'custom_fake_video_1' | ||
}; | ||
|
||
MediaDevices.prototype.enumerateDevices = async function () { | ||
const res = await enumerateDevicesFn.call(navigator.mediaDevices); | ||
res.push(fakeDevice); | ||
return res; | ||
}; | ||
|
||
MediaDevices.prototype.getUserMedia = async function () { | ||
const args = arguments[0]; | ||
const { deviceId, advanced, width, height } = args.video; | ||
if (deviceId === 'virtual' || deviceId?.exact === 'virtual') { | ||
const constraints = { | ||
video: { | ||
facingMode: args.facingMode, | ||
advanced, | ||
width, | ||
height | ||
}, | ||
audio: false | ||
}; | ||
const res = await getUserMediaFn.call(navigator.mediaDevices, constraints); | ||
|
||
if (res) { | ||
const filter = new FilterStream(res, fakeDevice.label); | ||
return filter.outputStream; | ||
} | ||
|
||
return res; | ||
} | ||
|
||
return getUserMediaFn.call(navigator.mediaDevices, ...arguments); | ||
}; | ||
|
||
MediaDevices.prototype.getDisplayMedia = async function () { | ||
const { video, audio } = arguments[0]; | ||
|
||
const screenVideoElement = document.getElementsByClassName("OT_video-element screen-type")[0]; | ||
const currentTrackLabel = screenVideoElement?.srcObject?.getVideoTracks()[0]?.label; | ||
const res = await getDisplayMediaFn.call(navigator.mediaDevices, { video, audio }); | ||
|
||
if (res && currentTrackLabel && currentTrackLabel !== 'custom_fake_screen') { | ||
const filter = new FilterStream(res, 'custom_fake_screen'); | ||
return filter.outputStream; | ||
} | ||
|
||
return res; | ||
}; | ||
} |
Oops, something went wrong.