mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Display local peer video
This commit is contained in:
		@@ -14,8 +14,15 @@ class CallWindow extends CustomEvents {
 | 
			
		||||
	 */
 | 
			
		||||
	constructor(conv) {
 | 
			
		||||
		super()
 | 
			
		||||
		
 | 
			
		||||
		// Initialize variables
 | 
			
		||||
		this.conv = conv;
 | 
			
		||||
		this.callID = conv.ID;
 | 
			
		||||
 | 
			
		||||
		/** @type {Map<number, HTMLVideoElement>} */
 | 
			
		||||
		this.videoEls = new Map()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		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
 | 
			
		||||
			await ws("calls/join", {
 | 
			
		||||
@@ -215,6 +229,15 @@ class CallWindow extends CustomEvents {
 | 
			
		||||
		if(el)
 | 
			
		||||
			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
 | 
			
		||||
	 * 
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @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
 | 
			
		||||
		})
 | 
			
		||||
 | 
			
		||||
		// Show user video
 | 
			
		||||
		this.addVideoStream(userID(), true, stream)
 | 
			
		||||
 | 
			
		||||
		this.mainPeer = new SimplePeer({
 | 
			
		||||
			initiator: true,
 | 
			
		||||
			trickle: true, // Allow exchange of multiple ice candidates
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user