summary refs log tree commit diff
path: root/webclient
diff options
context:
space:
mode:
authorDavid Baker <dbkr@matrix.org>2014-09-16 15:25:51 +0100
committerDavid Baker <dbkr@matrix.org>2014-09-16 15:26:22 +0100
commit84372cef4a512ae4603767c97c8055c218ac1557 (patch)
tree6cb020a365073b61bff4dcd7f69599aed1eddf86 /webclient
parentFixed scroll flickering when opening the room (diff)
downloadsynapse-84372cef4a512ae4603767c97c8055c218ac1557.tar.xz
Time out calls from both ends properly.
Diffstat (limited to '')
-rw-r--r--webclient/components/matrix/matrix-call.js24
-rw-r--r--webclient/components/matrix/matrix-phone-service.js4
2 files changed, 20 insertions, 8 deletions
diff --git a/webclient/components/matrix/matrix-call.js b/webclient/components/matrix/matrix-call.js
index 650c415c83..bf1e61ad7e 100644
--- a/webclient/components/matrix/matrix-call.js
+++ b/webclient/components/matrix/matrix-call.js
@@ -80,19 +80,29 @@ angular.module('MatrixCall', [])
         this.config = config;
     };
 
-    MatrixCall.prototype.initWithInvite = function(msg) {
-        this.msg = msg;
+    MatrixCall.prototype.initWithInvite = function(event) {
+        this.msg = event.content;
         this.peerConn = this.createPeerConnection();
         this.peerConn.setRemoteDescription(new RTCSessionDescription(this.msg.offer), this.onSetRemoteDescriptionSuccess, this.onSetRemoteDescriptionError);
         this.state = 'ringing';
         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
     // (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)
-    MatrixCall.prototype.initWithHangup = function(msg) {
-        this.msg = msg;
+    MatrixCall.prototype.initWithHangup = function(event) {
+        this.msg = event.content;
         this.state = 'ended';
     };
 
@@ -228,8 +238,10 @@ angular.module('MatrixCall', [])
 
         var self = this;
         $timeout(function() {
-            self.hangupReason = 'invite_timeout';
-            self.hangup();
+            if (self.state == 'invite_sent') {
+                self.hangupReason = 'invite_timeout';
+                self.hangup();
+            }
         }, MatrixCall.CALL_TIMEOUT);
 
         $rootScope.$apply(function() {
diff --git a/webclient/components/matrix/matrix-phone-service.js b/webclient/components/matrix/matrix-phone-service.js
index 3e99a7d112..d05eecf72a 100644
--- a/webclient/components/matrix/matrix-phone-service.js
+++ b/webclient/components/matrix/matrix-phone-service.js
@@ -60,7 +60,7 @@ angular.module('matrixPhoneService', [])
             var MatrixCall = $injector.get('MatrixCall');
             var call = new MatrixCall(event.room_id);
             call.call_id = msg.call_id;
-            call.initWithInvite(msg);
+            call.initWithInvite(event);
             matrixPhoneService.allCalls[call.call_id] = call;
 
             // 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 call = new MatrixCall(event.room_id);
                 call.call_id = msg.call_id;
-                call.initWithHangup(msg);
+                call.initWithHangup(event);
                 matrixPhoneService.allCalls[msg.call_id] = call;
             } else {
                 call.onHangupReceived();