Handles remote signals

This commit is contained in:
Pierre HUBERT 2020-04-11 14:05:29 +02:00
parent f3ae21c5c1
commit dea30cb0ce
3 changed files with 38 additions and 0 deletions

View File

@ -229,6 +229,10 @@ class UserWebSocket {
SendEvent("userLeftCall", msg.data); SendEvent("userLeftCall", msg.data);
break; break;
case "new_call_signal":
SendEvent("newCallSignal", msg.data);
break;
default: default:
console.error("WS Unspported kind of message!", msg); console.error("WS Unspported kind of message!", msg);
break; break;

View File

@ -90,6 +90,13 @@ document.addEventListener("userLeftCall", (e) => {
OpenConversations.get(detail.callID).RemoveMember(detail.userID) 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", () => { document.addEventListener("wsClosed", () => {
// Close all the current conversations // Close all the current conversations

View File

@ -271,5 +271,32 @@ class CallWindow extends CustomEvents {
console.error("Peer error!", err); console.error("Peer error!", err);
notify("An error occured while trying to connect!", "danger", 5) 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!")
} }
} }