Notify server when joining call

This commit is contained in:
Pierre HUBERT 2020-04-10 16:07:05 +02:00
parent 51dcef4565
commit f3466a98e0

View File

@ -14,10 +14,13 @@ class CallWindow extends CustomEvents {
*/ */
constructor(conv) { constructor(conv) {
super() super()
this.conv = conv;
this.construct(conv); this.construct(conv);
} }
async construct(conv) { async construct(conv) {
try {
// Check if calls target exists or not // Check if calls target exists or not
if(!byId("callsTarget")) if(!byId("callsTarget"))
createElem2({ createElem2({
@ -53,7 +56,17 @@ class CallWindow extends CustomEvents {
onclick: () => this.Close() onclick: () => this.Close()
}) })
this.makeWindowDraggable() this.makeWindowDraggable();
// Join the call
await ws("calls/join", {
convID: this.conv.ID
})
} catch(e) {
console.error(e)
notify("Could not initialize call!", "danger");
}
} }
/** /**
@ -131,9 +144,14 @@ class CallWindow extends CustomEvents {
* @param {boolean} propagate Set to true to propagate * @param {boolean} propagate Set to true to propagate
* the event * the event
*/ */
Close(propagate = true) { async Close(propagate = true) {
this.rootEl.remove(); this.rootEl.remove();
// Leave the call
await ws("calls/leave", {
convID: this.conv.ID
})
if(propagate) if(propagate)
this.emitEvent("close"); this.emitEvent("close");
} }