Play ringback/busy/callend audio at the right times.
parent
827e777079
commit
812eb66ed5
|
@ -61,6 +61,25 @@ var calls = {
|
||||||
//room_id: MatrixCall
|
//room_id: MatrixCall
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function play(audioId) {
|
||||||
|
// TODO: Attach an invisible element for this instead
|
||||||
|
// which listens?
|
||||||
|
var audio = document.getElementById(audioId);
|
||||||
|
if (audio) {
|
||||||
|
audio.load();
|
||||||
|
audio.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function pause(audioId) {
|
||||||
|
// TODO: Attach an invisible element for this instead
|
||||||
|
// which listens?
|
||||||
|
var audio = document.getElementById(audioId);
|
||||||
|
if (audio) {
|
||||||
|
audio.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _setCallListeners(call) {
|
function _setCallListeners(call) {
|
||||||
call.on("error", function(err) {
|
call.on("error", function(err) {
|
||||||
console.error("Call error: %s", err);
|
console.error("Call error: %s", err);
|
||||||
|
@ -76,27 +95,36 @@ function _setCallListeners(call) {
|
||||||
call.on("state", function(newState, oldState) {
|
call.on("state", function(newState, oldState) {
|
||||||
if (newState === "ringing") {
|
if (newState === "ringing") {
|
||||||
_setCallState(call, call.roomId, "ringing");
|
_setCallState(call, call.roomId, "ringing");
|
||||||
|
pause("ringbackAudio");
|
||||||
}
|
}
|
||||||
else if (newState === "invite_sent") {
|
else if (newState === "invite_sent") {
|
||||||
_setCallState(call, call.roomId, "ringback");
|
_setCallState(call, call.roomId, "ringback");
|
||||||
|
play("ringbackAudio");
|
||||||
}
|
}
|
||||||
else if (newState === "ended" && oldState === "connected") {
|
else if (newState === "ended" && oldState === "connected") {
|
||||||
_setCallState(call, call.roomId, "ended");
|
_setCallState(call, call.roomId, "ended");
|
||||||
|
pause("ringbackAudio");
|
||||||
|
play("callendAudio");
|
||||||
}
|
}
|
||||||
else if (newState === "ended" && oldState === "invite_sent" &&
|
else if (newState === "ended" && oldState === "invite_sent" &&
|
||||||
(call.hangupParty === "remote" ||
|
(call.hangupParty === "remote" ||
|
||||||
(call.hangupParty === "local" && call.hangupReason === "invite_timeout")
|
(call.hangupParty === "local" && call.hangupReason === "invite_timeout")
|
||||||
)) {
|
)) {
|
||||||
_setCallState(call, call.roomId, "busy");
|
_setCallState(call, call.roomId, "busy");
|
||||||
|
pause("ringbackAudio");
|
||||||
|
play("busyAudio");
|
||||||
}
|
}
|
||||||
else if (oldState === "invite_sent") {
|
else if (oldState === "invite_sent") {
|
||||||
_setCallState(call, call.roomId, "stop_ringback");
|
_setCallState(call, call.roomId, "stop_ringback");
|
||||||
|
pause("ringbackAudio");
|
||||||
}
|
}
|
||||||
else if (oldState === "ringing") {
|
else if (oldState === "ringing") {
|
||||||
_setCallState(call, call.roomId, "stop_ringing");
|
_setCallState(call, call.roomId, "stop_ringing");
|
||||||
|
pause("ringbackAudio");
|
||||||
}
|
}
|
||||||
else if (newState === "connected") {
|
else if (newState === "connected") {
|
||||||
_setCallState(call, call.roomId, "connected");
|
_setCallState(call, call.roomId, "connected");
|
||||||
|
pause("ringbackAudio");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue