v1.6.0/conference call upgrade

- anyone can start call
- colision check for calls
- better error handing for calls
This commit is contained in:
2020-08-02 01:11:48 -04:00
parent c80a99cea1
commit 86ee168045
9 changed files with 184 additions and 51 deletions
+2 -2
View File
@@ -149,9 +149,9 @@ export const UpdatePlayerApi = async (data) => {
});
};
export const GetVoxeetTokenApi = async () => {
export const GetVoxeetTokenApi = async (data) => {
return fetcher({
endpoint: 'validator',
endpoint: `validator/${data.partyName}`,
method: 'GET',
});
};
+31 -8
View File
@@ -33,10 +33,12 @@ export default class CallManager {
this.__accessToken = LocalData().vrT;
this.__sessionInitialized = false;
this.__admin = false;
this.__adminOnly = true;
}
toggleCall(onCall, conference, admin) {
toggleCall(onCall, conference, admin, adminOnly) {
this.listener({ callActionPending: true });
this.__admin = admin;
this.__adminOnly = adminOnly;
if (onCall === true) this.leaveCall();
else this.boot(conference);
}
@@ -56,13 +58,17 @@ export default class CallManager {
console.error('Failed to fetch conference', err);
this.startCall();
});
} else if (opened && !conference) this.startCall();
else console.error('Unable to open Voxeet Session');
} else if (opened && !conference) {
this.startCall();
} else {
this.listener({ onCall: false, muted: false, callActionPending: false });
console.error('Unable to open Voxeet Session');
}
}
async startCall() {
if (this.__admin === true) {
if (!this.__adminOnly || (this.__adminOnly && this.__admin)) {
VoxeetSDK.conference
.create({ alias: LocalData().partyName, pin: LocalData().partyPin })
.create({ alias: `AUTODELETE_${LocalData().partyName}`, pin: LocalData().partyPin })
.then(async (conference) => {
const updatedVoxeet = await UpdateVoxeetApi({
conference,
@@ -72,10 +78,21 @@ export default class CallManager {
})
.then((res) => res.json())
.then((res) => res.status <= 299)
.catch((err) => console.error('Update Voxeet API Error', err));
.catch((err) => {
if (err.conference) {
this.joinCall(err.conference);
return true;
} else {
this.notify(err.message);
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');
}
});
@@ -87,7 +104,13 @@ export default class CallManager {
async joinCall(conference) {
const joined = await VoxeetSDK.conference
.join(conference, { constraints: { audio: true, video: false } })
.then(() => true);
.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);
return true;
});
if (!joined) {
this.startCall();
}
@@ -158,7 +181,7 @@ export default class CallManager {
this.__accessToken !== null ||
this.__refreshToken !== null
) {
await GetVoxeetTokenApi()
await GetVoxeetTokenApi({ partyName: LocalData().partyName })
.then((res) => res.json())
.then((tokenResult) => {
if (tokenResult.status <= 299) {
+5 -3
View File
@@ -235,6 +235,7 @@ export default class Chat extends Component {
const data = {
partyName: LocalData().partyName,
};
if (this.state.onCall) this.mCallManager.toggleCall(this.state.onCall, this.state.conference, this.state.admin, this.state.adminOnly);
DeleteRoomApi(data)
.then((res) => {
this.props.notify('Ended party');
@@ -255,6 +256,7 @@ export default class Chat extends Component {
partyName: LocalData().partyName,
userUid: LocalData().userUid,
};
if (this.state.onCall) this.mCallManager.toggleCall(this.state.onCall, this.state.conference, this.state.admin, this.state.adminOnly);
LeaveRoomApi(data)
.then((res) => {
this.props.notify('Left party');
@@ -312,7 +314,7 @@ export default class Chat extends Component {
: giphyFetch.search(this.state.newMessage, { offset, limit: 1 });
}
handlePhoneCall() {
const { onCall, conference, admin } = this.state;
const { onCall, conference, admin, adminOnly } = this.state;
if (window.navigator && onCall === false) {
try {
const overlay = document.createElement('div');
@@ -328,7 +330,7 @@ export default class Chat extends Component {
})
.then(() => {
document.getElementById('mic-permission-overlay').remove();
this.mCallManager.toggleCall(onCall, conference, admin);
this.mCallManager.toggleCall(onCall, conference, admin, adminOnly);
})
.catch(() => {
document.getElementById('mic-permission-overlay').remove();
@@ -339,7 +341,7 @@ export default class Chat extends Component {
} catch (err) {
console.error('Handle Phone Call Error', err);
}
} else this.mCallManager.toggleCall(onCall, conference, admin);
} else this.mCallManager.toggleCall(onCall, conference, admin, adminOnly);
}
handleMute() {
this.mCallManager.toggleMute(this.state.muted);