Display local peer video

This commit is contained in:
Pierre HUBERT 2020-04-11 14:18:27 +02:00
parent dea30cb0ce
commit c840193007
2 changed files with 47 additions and 2 deletions

View File

@ -53,4 +53,13 @@
.call-window .members-area span { .call-window .members-area span {
margin: 0px 5px; margin: 0px 5px;
}
.call-window .videos-area {
display: flex;
flex-direction: row;
}
.call-window .videos-area video {
} }

View File

@ -14,8 +14,15 @@ class CallWindow extends CustomEvents {
*/ */
constructor(conv) { constructor(conv) {
super() super()
// Initialize variables
this.conv = conv; this.conv = conv;
this.callID = conv.ID; this.callID = conv.ID;
/** @type {Map<number, HTMLVideoElement>} */
this.videoEls = new Map()
this.construct(conv); this.construct(conv);
} }
@ -68,6 +75,13 @@ class CallWindow extends CustomEvents {
}) })
// Create videos area
this.videosArea = createElem2({
appendTo: this.rootEl,
type: "div",
class: "videos-area"
})
// Join the call // Join the call
await ws("calls/join", { await ws("calls/join", {
@ -215,6 +229,15 @@ class CallWindow extends CustomEvents {
if(el) if(el)
el.remove() el.remove()
// Remove video (if any)
if(this.videoEls.has(userID)) {
const el = this.videoEls.get(userID);
this.videoEls.delete(userID)
el.pause()
el.remove()
}
} }
/** /**
@ -229,10 +252,20 @@ class CallWindow extends CustomEvents {
/** /**
* Add video stream to the user * Add video stream to the user
* *
* * @param {number} peerID Remove peer ID
* @param {boolean} muted True to mute video
* @param {MediaStream} stream Target stream
*/ */
addVideoStream(video) { addVideoStream(peerID, muted, stream) {
const videoEl = document.createElement("video");
this.videosArea.appendChild(videoEl)
videoEl.muted = muted;
videoEl.srcObject = stream
videoEl.play()
this.videoEls.set(peerID, videoEl)
} }
/** /**
@ -246,6 +279,9 @@ class CallWindow extends CustomEvents {
audio: true audio: true
}) })
// Show user video
this.addVideoStream(userID(), true, stream)
this.mainPeer = new SimplePeer({ this.mainPeer = new SimplePeer({
initiator: true, initiator: true,
trickle: true, // Allow exchange of multiple ice candidates trickle: true, // Allow exchange of multiple ice candidates