-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedia.js
More file actions
27 lines (25 loc) · 702 Bytes
/
media.js
File metadata and controls
27 lines (25 loc) · 702 Bytes
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
class CustomMediaStream{
constructor({video = true, audio = true} = {}){
this.settings = {video, audio}
this.tracks = {
videoTrack: null,
audioTrack: null
}
this.stream = null
}
stopStream(){
audioTrack.stop()
videoTrack.stop()
}
async startStream(){
const stream = await navigator.mediaDevices.getUserMedia({
video: true,
audio: true
})
let videoTrack = stream.getVideoTracks()[0]
let audioTrack = stream.getAudioTracks()[0]
this.tracks.videoTrack = videoTrack
this.tracks.audioTrack = audioTrack
return this.tracks
}
}