mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-03 19:54:14 +00:00 
			
		
		
		
	Display local peer video
This commit is contained in:
		@@ -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 {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -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
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user