v1.6.0/speculative fix for call conflict

This commit is contained in:
2020-08-08 17:41:40 -04:00
parent f375d33311
commit 6ccf7c6201
4 changed files with 157 additions and 75 deletions
+53 -33
View File
@@ -9,14 +9,14 @@ ALL CONTENT ON WATCH PARTY'S WEBSITE OR IN WATCH PARTY'S CHROME EXTENSION APP, U
CITED ARE THE SOLE INTELECTUAL PROPERTY OF AYUSHYA AMITABH, AND MAY NOT BE
COPIED, EDITED, OR REPRODUCED WITHOUT PERMISSION.
************************************************************************/
import VoxeetSDK from '@voxeet/voxeet-web-sdk';
import VoxeetSDK from "@voxeet/voxeet-web-sdk";
import {
GetVoxeetTokenApi,
GetRefreshedVoxeetTokenApi,
LocalData,
UpdateVoxeetApi,
updateLocalData,
} from './Api';
} from "./Api";
export default class CallManager {
constructor(listener, notify) {
@@ -29,11 +29,15 @@ export default class CallManager {
this.__adminOnly = true;
}
toggleCall(onCall, conference, admin, adminOnly) {
this.listener({ callActionPending: true });
this.__admin = admin;
this.__adminOnly = adminOnly;
if (onCall === true) this.leaveCall();
else this.boot(conference);
try {
this.listener({ callActionPending: true });
this.__admin = admin;
this.__adminOnly = adminOnly;
if (onCall === true) this.leaveCall();
else this.boot(conference);
} catch (e) {
this.notify("Uh oh something went wrong, try rejoining the call.");
}
}
toggleMute(muted) {
this.listener({ callActionPending: true });
@@ -48,20 +52,23 @@ export default class CallManager {
.fetch(conference._id)
.then(this.joinCall)
.catch((err) => {
console.error('Failed to fetch conference', err);
console.error("Failed to fetch conference", err);
this.startCall();
});
} else if (opened && !conference) {
this.startCall();
} else {
this.listener({ onCall: false, muted: false, callActionPending: false });
console.error('Unable to open Voxeet Session');
console.error("Unable to open Voxeet Session");
}
}
async startCall() {
if (!this.__adminOnly || (this.__adminOnly && this.__admin)) {
VoxeetSDK.conference
.create({ alias: `AUTODELETE_${LocalData().partyName}`, pin: LocalData().partyPin })
.create({
alias: `AUTODELETE_${LocalData().partyName}`,
pin: LocalData().partyPin,
})
.then(async (conference) => {
const updatedVoxeet = await UpdateVoxeetApi({
conference,
@@ -77,20 +84,28 @@ export default class CallManager {
return true;
} else {
this.notify(err.message);
this.listener({ onCall: false, muted: false, callActionPending: false });
console.error('Update Voxeet API Error', err);
this.listener({
onCall: false,
muted: false,
callActionPending: false,
});
console.error("Update Voxeet API Error", err);
return false;
}
});
if (updatedVoxeet === true) {
this.joinCall(conference);
} else {
this.listener({ onCall: false, muted: false, callActionPending: false });
console.error('Failed to update party Voxeet');
this.listener({
onCall: false,
muted: false,
callActionPending: false,
});
console.error("Failed to update party Voxeet");
}
});
} else {
this.notify('Ask your party admin to start the call.');
this.notify("Ask your party admin to start the call.");
this.leaveCall();
}
}
@@ -99,14 +114,15 @@ export default class CallManager {
.join(conference, { constraints: { audio: true, video: false } })
.then(() => true)
.catch((e) => {
this.listener({ onCall: false, muted: false, callActionPending: false });
this.notify('Unable to join call. Try again in a moment.');
console.error('Error joining call', e);
this.listener({
onCall: false,
muted: false,
callActionPending: false,
});
this.notify("Unable to join call. Try again in a moment.");
console.error("Error joining call", e);
return true;
});
if (!joined) {
this.startCall();
}
}
async leaveCall() {
VoxeetSDK.conference.leave().then(() => {
@@ -123,9 +139,9 @@ export default class CallManager {
});
return true;
} catch (error) {
console.error('Error Opening Voxeet Session', error);
console.error("Error Opening Voxeet Session", error);
}
console.error('Session not initialized');
console.error("Session not initialized");
return false;
}
return true;
@@ -138,22 +154,26 @@ export default class CallManager {
this.listener({ usersOnCall });
}
async initialize() {
VoxeetSDK.conference.on('participantAdded', () => this.usersListHandle());
VoxeetSDK.conference.on('participantUpdated', () => this.usersListHandle());
VoxeetSDK.conference.on("participantAdded", () => this.usersListHandle());
VoxeetSDK.conference.on("participantUpdated", () => this.usersListHandle());
VoxeetSDK.conference.on('joined', () => {
VoxeetSDK.conference.on("joined", () => {
this.listener({ onCall: true, callActionPending: false });
});
VoxeetSDK.conference.on('left', () => {
this.listener({ onCall: false, callActionPending: false, usersOnCall: {} });
VoxeetSDK.conference.on("left", () => {
this.listener({
onCall: false,
callActionPending: false,
usersOnCall: {},
});
});
VoxeetSDK.conference.on('streamAdded', (participant, stream) => {
VoxeetSDK.conference.on("streamAdded", (participant, stream) => {
this.listener({ callActionPending: false });
});
VoxeetSDK.conference.on('streamRemoved', (participant, stream) => {
VoxeetSDK.conference.on("streamRemoved", (participant, stream) => {
this.listener({ callActionPending: false });
});
@@ -171,11 +191,11 @@ export default class CallManager {
this.updateTokens(access_token, refresh_token);
VoxeetSDK.initializeToken(access_token, refresh_token);
} else {
console.error('Get Voxeet Token API Result Error', tokenResult);
console.error("Get Voxeet Token API Result Error", tokenResult);
}
})
.catch((err) => {
console.error('Get Voxeet Token API error', err);
console.error("Get Voxeet Token API error", err);
});
} else {
VoxeetSDK.initializeToken(this.__accessToken, this.__refreshToken);
@@ -191,7 +211,7 @@ export default class CallManager {
resolve(access_token);
})
.catch((err) => {
console.error('Get Voxeet Token API error', err);
console.error("Get Voxeet Token API error", err);
reject(err);
});
});