mirror of https://github.com/vector-im/riot-web
map-ify calls map
parent
adc93ca7d6
commit
4269c26e76
|
@ -74,8 +74,11 @@ import {base32} from "rfc4648";
|
||||||
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
|
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
|
||||||
import ErrorDialog from "./components/views/dialogs/ErrorDialog";
|
import ErrorDialog from "./components/views/dialogs/ErrorDialog";
|
||||||
|
|
||||||
|
// until we ts-ify the js-sdk voip code
|
||||||
|
type Call = any;
|
||||||
|
|
||||||
export default class CallHandler {
|
export default class CallHandler {
|
||||||
private calls = {};
|
private calls = new Map<string, Call>();
|
||||||
private audioPromises = {};
|
private audioPromises = {};
|
||||||
|
|
||||||
static sharedInstance() {
|
static sharedInstance() {
|
||||||
|
@ -101,16 +104,16 @@ export default class CallHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getCallForRoom(roomId: string) {
|
getCallForRoom(roomId: string): Call {
|
||||||
return this.calls[roomId] || null;
|
return this.calls.get(roomId) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAnyActiveCall() {
|
getAnyActiveCall() {
|
||||||
const roomsWithCalls = Object.keys(this.calls);
|
const roomsWithCalls = Object.keys(this.calls);
|
||||||
for (let i = 0; i < roomsWithCalls.length; i++) {
|
for (let i = 0; i < roomsWithCalls.length; i++) {
|
||||||
if (this.calls[roomsWithCalls[i]] &&
|
if (this.calls.get(roomsWithCalls[i]) &&
|
||||||
this.calls[roomsWithCalls[i]].call_state !== "ended") {
|
this.calls.get(roomsWithCalls[i]).call_state !== "ended") {
|
||||||
return this.calls[roomsWithCalls[i]];
|
return this.calls.get(roomsWithCalls[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -219,7 +222,7 @@ export default class CallHandler {
|
||||||
console.log(
|
console.log(
|
||||||
`Call state in ${roomId} changed to ${status} (${call ? call.call_state : "-"})`,
|
`Call state in ${roomId} changed to ${status} (${call ? call.call_state : "-"})`,
|
||||||
);
|
);
|
||||||
this.calls[roomId] = call;
|
this.calls.set(roomId, call);
|
||||||
|
|
||||||
if (status === "ringing") {
|
if (status === "ringing") {
|
||||||
this.play("ringAudio");
|
this.play("ringAudio");
|
||||||
|
@ -368,18 +371,18 @@ export default class CallHandler {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'hangup':
|
case 'hangup':
|
||||||
if (!this.calls[payload.room_id]) {
|
if (!this.calls.get(payload.room_id)) {
|
||||||
return; // no call to hangup
|
return; // no call to hangup
|
||||||
}
|
}
|
||||||
this.calls[payload.room_id].hangup();
|
this.calls.get(payload.room_id).hangup();
|
||||||
this.setCallState(null, payload.room_id, "ended");
|
this.setCallState(null, payload.room_id, "ended");
|
||||||
break;
|
break;
|
||||||
case 'answer':
|
case 'answer':
|
||||||
if (!this.calls[payload.room_id]) {
|
if (!this.calls.get(payload.room_id)) {
|
||||||
return; // no call to answer
|
return; // no call to answer
|
||||||
}
|
}
|
||||||
this.calls[payload.room_id].answer();
|
this.calls.get(payload.room_id).answer();
|
||||||
this.setCallState(this.calls[payload.room_id], payload.room_id, "connected");
|
this.setCallState(this.calls.get(payload.room_id), payload.room_id, "connected");
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: "view_room",
|
action: "view_room",
|
||||||
room_id: payload.room_id,
|
room_id: payload.room_id,
|
||||||
|
|
Loading…
Reference in New Issue