mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-03 19:54:14 +00:00 
			
		
		
		
	Handles remote signals
This commit is contained in:
		@@ -229,6 +229,10 @@ class UserWebSocket {
 | 
			
		||||
				SendEvent("userLeftCall", msg.data);
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			case "new_call_signal":
 | 
			
		||||
				SendEvent("newCallSignal", msg.data);
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			default:
 | 
			
		||||
				console.error("WS Unspported kind of message!", msg);
 | 
			
		||||
				break;
 | 
			
		||||
 
 | 
			
		||||
@@ -90,6 +90,13 @@ document.addEventListener("userLeftCall", (e) => {
 | 
			
		||||
		OpenConversations.get(detail.callID).RemoveMember(detail.userID)
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
document.addEventListener("newCallSignal", (e) => {
 | 
			
		||||
	const detail = e.detail
 | 
			
		||||
 | 
			
		||||
	if(OpenConversations.has(detail.callID))
 | 
			
		||||
		OpenConversations.get(detail.callID).NewSignal(detail.peerID, detail.data)
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
document.addEventListener("wsClosed", () => {
 | 
			
		||||
	// Close all the current conversations
 | 
			
		||||
 
 | 
			
		||||
@@ -271,5 +271,32 @@ class CallWindow extends CustomEvents {
 | 
			
		||||
			console.error("Peer error!", err);
 | 
			
		||||
			notify("An error occured while trying to connect!", "danger", 5)
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		this.mainPeer.on("connect", () => console.info("Connected to remote peer!"))
 | 
			
		||||
 | 
			
		||||
		this.mainPeer.on("message", message => {
 | 
			
		||||
			console.log("Message from remote peer: " + message);
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		this.mainPeer.on("stream", stream => {
 | 
			
		||||
			console.log("mainPeer stream", stream)
 | 
			
		||||
			alert("Stream on main peer!!!")
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Handles new signals
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {Number} peerID Target peer ID
 | 
			
		||||
	 * @param {any} data Signal data
 | 
			
		||||
	 */
 | 
			
		||||
	NewSignal(peerID, data) {
 | 
			
		||||
 | 
			
		||||
		if(peerID == userID())
 | 
			
		||||
			this.mainPeer.signal(data)
 | 
			
		||||
		
 | 
			
		||||
		else
 | 
			
		||||
			console.error("Unsupported type of signal!")
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user