summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Baker <dbkr@matrix.org>2014-08-29 15:18:37 +0100
committerDavid Baker <dbkr@matrix.org>2014-08-29 15:18:57 +0100
commit0ef54caa282fa159a011cb4f65c7c5c1b4b25101 (patch)
tree882b150e899c7b7183cf517a90f130aacd6ce78b
parentFix JSFiddles to work with the new C-S API. (diff)
downloadsynapse-0ef54caa282fa159a011cb4f65c7c5c1b4b25101.tar.xz
better support for call hangups
-rw-r--r--webclient/components/matrix/matrix-call.js32
1 files changed, 16 insertions, 16 deletions
diff --git a/webclient/components/matrix/matrix-call.js b/webclient/components/matrix/matrix-call.js
index 45d00ee792..c0a7735a7c 100644
--- a/webclient/components/matrix/matrix-call.js
+++ b/webclient/components/matrix/matrix-call.js
@@ -73,9 +73,7 @@ angular.module('MatrixCall', [])
         this.state = 'wait_local_media';
     };
 
-    MatrixCall.prototype.hangup = function() {
-        console.trace("Ending call "+this.call_id);
-
+    MatrixCall.prototype.stopAllMedia = function() {
         if (this.localAVStream) {
             forAllTracksOnStream(this.localAVStream, function(t) {
                 t.stop();
@@ -86,6 +84,12 @@ angular.module('MatrixCall', [])
                 t.stop();
             });
         }
+    };
+
+    MatrixCall.prototype.hangup = function() {
+        console.trace("Ending call "+this.call_id);
+
+        this.stopAllMedia();
 
         var content = {
             version: 0,
@@ -232,8 +236,9 @@ angular.module('MatrixCall', [])
             t.onstarted = self.onRemoteStreamTrackStarted;
         });
 
+        event.stream.onended = function(e) { self.onRemoteStreamEnded(e); }; 
         // not currently implemented in chrome
-        event.stream.onstarted = this.onRemoteStreamStarted;
+        event.stream.onstarted = function(e) { self.onRemoteStreamStarted(e); };
         var player = new Audio();
         player.src = URL.createObjectURL(s);
         player.play();
@@ -243,24 +248,19 @@ angular.module('MatrixCall', [])
         this.state = 'connected';
     };
 
+    MatrixCall.prototype.onRemoteStreamEnded = function(event) {
+        this.state = 'ended';
+        this.stopAllMedia();
+        this.onHangup();
+    };
+
     MatrixCall.prototype.onRemoteStreamTrackStarted = function(event) {
         this.state = 'connected';
     };
 
     MatrixCall.prototype.onHangupReceived = function() {
         this.state = 'ended';
-
-        if (this.localAVStream) {
-            forAllTracksOnStream(this.localAVStream, function(t) {
-                t.stop();
-            });
-        }
-        if (this.remoteAVStream) {
-            forAllTracksOnStream(this.remoteAVStream, function(t) {
-                t.stop();
-            });
-        }
-
+        this.stopAllMedia();
         this.onHangup();
     };