forked from node-webrtc/node-webrtc-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
39 lines (28 loc) · 1.18 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
34
35
36
37
38
39
'use strict';
const createExample = require('../../lib/browser/example');
const description = 'Transcode and record audio and video into different video resolutions and then merge into single file.';
const localVideo = document.createElement('video');
localVideo.autoplay = true;
localVideo.muted = true;
async function beforeAnswer(peerConnection) {
const localStream = await window.navigator.mediaDevices.getUserMedia({
audio: true,
video: true
});
localStream.getTracks().forEach(track => peerConnection.addTrack(track, localStream));
localVideo.srcObject = localStream;
// 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() {
localVideo.srcObject = null;
localStream.getTracks().forEach(track => track.stop());
return close.apply(this, arguments);
};
}
createExample('record-audio-video-stream', description, { beforeAnswer });
const videos = document.createElement('div');
videos.className = 'grid';
videos.appendChild(localVideo);
document.body.appendChild(videos);