forked from WonderInventions/node-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
33 lines (24 loc) · 1.06 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
const createExample = require('../../lib/browser/example');
const description = 'This example uses node-webrtc’s RTCVideoSource \
along with <a href="https://www.npmjs.com/package/beamcoder">beamcoder</a> \
to send a looping video stream from a file.'
const remoteVideo = document.createElement('video');
remoteVideo.autoplay = true;
async function beforeAnswer(peerConnection) {
const remoteStream = new MediaStream(peerConnection.getReceivers().map(receiver => receiver.track));
remoteVideo.srcObject = remoteStream;
// NOTE(mroberts): This is a hack so that we can get a callback when the
// RTCPeerConnection is closed. In the future, we can subscribe to
// "connectionstatechange" events.
const { close } = peerConnection;
peerConnection.close = function() {
remoteVideo.srcObject = null;
return close.apply(this, arguments);
};
}
createExample('rickroll', description, { beforeAnswer });
const videos = document.createElement('div');
videos.className = 'grid';
videos.appendChild(remoteVideo);
document.body.appendChild(videos);