Time out calls from both ends properly.
This commit is contained in:
parent
890178cf25
commit
84372cef4a
|
@ -80,19 +80,29 @@ angular.module('MatrixCall', [])
|
||||||
this.config = config;
|
this.config = config;
|
||||||
};
|
};
|
||||||
|
|
||||||
MatrixCall.prototype.initWithInvite = function(msg) {
|
MatrixCall.prototype.initWithInvite = function(event) {
|
||||||
this.msg = msg;
|
this.msg = event.content;
|
||||||
this.peerConn = this.createPeerConnection();
|
this.peerConn = this.createPeerConnection();
|
||||||
this.peerConn.setRemoteDescription(new RTCSessionDescription(this.msg.offer), this.onSetRemoteDescriptionSuccess, this.onSetRemoteDescriptionError);
|
this.peerConn.setRemoteDescription(new RTCSessionDescription(this.msg.offer), this.onSetRemoteDescriptionSuccess, this.onSetRemoteDescriptionError);
|
||||||
this.state = 'ringing';
|
this.state = 'ringing';
|
||||||
this.direction = 'inbound';
|
this.direction = 'inbound';
|
||||||
|
var self = this;
|
||||||
|
$timeout(function() {
|
||||||
|
if (self.state == 'ringing') {
|
||||||
|
self.state = 'ended';
|
||||||
|
self.hangupParty = 'remote'; // effectively
|
||||||
|
self.stopAllMedia();
|
||||||
|
if (self.peerConn.signalingState != 'closed') self.peerConn.close();
|
||||||
|
if (self.onHangup) self.onHangup(self);
|
||||||
|
}
|
||||||
|
}, this.msg.lifetime - event.age);
|
||||||
};
|
};
|
||||||
|
|
||||||
// perverse as it may seem, sometimes we want to instantiate a call with a hangup message
|
// perverse as it may seem, sometimes we want to instantiate a call with a hangup message
|
||||||
// (because when getting the state of the room on load, events come in reverse order and
|
// (because when getting the state of the room on load, events come in reverse order and
|
||||||
// we want to remember that a call has been hung up)
|
// we want to remember that a call has been hung up)
|
||||||
MatrixCall.prototype.initWithHangup = function(msg) {
|
MatrixCall.prototype.initWithHangup = function(event) {
|
||||||
this.msg = msg;
|
this.msg = event.content;
|
||||||
this.state = 'ended';
|
this.state = 'ended';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -228,8 +238,10 @@ angular.module('MatrixCall', [])
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
self.hangupReason = 'invite_timeout';
|
if (self.state == 'invite_sent') {
|
||||||
self.hangup();
|
self.hangupReason = 'invite_timeout';
|
||||||
|
self.hangup();
|
||||||
|
}
|
||||||
}, MatrixCall.CALL_TIMEOUT);
|
}, MatrixCall.CALL_TIMEOUT);
|
||||||
|
|
||||||
$rootScope.$apply(function() {
|
$rootScope.$apply(function() {
|
||||||
|
|
|
@ -60,7 +60,7 @@ angular.module('matrixPhoneService', [])
|
||||||
var MatrixCall = $injector.get('MatrixCall');
|
var MatrixCall = $injector.get('MatrixCall');
|
||||||
var call = new MatrixCall(event.room_id);
|
var call = new MatrixCall(event.room_id);
|
||||||
call.call_id = msg.call_id;
|
call.call_id = msg.call_id;
|
||||||
call.initWithInvite(msg);
|
call.initWithInvite(event);
|
||||||
matrixPhoneService.allCalls[call.call_id] = call;
|
matrixPhoneService.allCalls[call.call_id] = call;
|
||||||
|
|
||||||
// if we stashed candidate events for that call ID, play them back now
|
// if we stashed candidate events for that call ID, play them back now
|
||||||
|
@ -132,7 +132,7 @@ angular.module('matrixPhoneService', [])
|
||||||
var MatrixCall = $injector.get('MatrixCall');
|
var MatrixCall = $injector.get('MatrixCall');
|
||||||
var call = new MatrixCall(event.room_id);
|
var call = new MatrixCall(event.room_id);
|
||||||
call.call_id = msg.call_id;
|
call.call_id = msg.call_id;
|
||||||
call.initWithHangup(msg);
|
call.initWithHangup(event);
|
||||||
matrixPhoneService.allCalls[msg.call_id] = call;
|
matrixPhoneService.allCalls[msg.call_id] = call;
|
||||||
} else {
|
} else {
|
||||||
call.onHangupReceived();
|
call.onHangupReceived();
|
||||||
|
|
Loading…
Reference in New Issue