better support for call hangups

This commit is contained in:
David Baker 2014-08-29 15:18:37 +01:00
parent 1cdc29e260
commit 0ef54caa28

View File

@ -73,9 +73,7 @@ angular.module('MatrixCall', [])
this.state = 'wait_local_media'; this.state = 'wait_local_media';
}; };
MatrixCall.prototype.hangup = function() { MatrixCall.prototype.stopAllMedia = function() {
console.trace("Ending call "+this.call_id);
if (this.localAVStream) { if (this.localAVStream) {
forAllTracksOnStream(this.localAVStream, function(t) { forAllTracksOnStream(this.localAVStream, function(t) {
t.stop(); t.stop();
@ -86,6 +84,12 @@ angular.module('MatrixCall', [])
t.stop(); t.stop();
}); });
} }
};
MatrixCall.prototype.hangup = function() {
console.trace("Ending call "+this.call_id);
this.stopAllMedia();
var content = { var content = {
version: 0, version: 0,
@ -232,8 +236,9 @@ angular.module('MatrixCall', [])
t.onstarted = self.onRemoteStreamTrackStarted; t.onstarted = self.onRemoteStreamTrackStarted;
}); });
event.stream.onended = function(e) { self.onRemoteStreamEnded(e); };
// not currently implemented in chrome // not currently implemented in chrome
event.stream.onstarted = this.onRemoteStreamStarted; event.stream.onstarted = function(e) { self.onRemoteStreamStarted(e); };
var player = new Audio(); var player = new Audio();
player.src = URL.createObjectURL(s); player.src = URL.createObjectURL(s);
player.play(); player.play();
@ -243,24 +248,19 @@ angular.module('MatrixCall', [])
this.state = 'connected'; this.state = 'connected';
}; };
MatrixCall.prototype.onRemoteStreamEnded = function(event) {
this.state = 'ended';
this.stopAllMedia();
this.onHangup();
};
MatrixCall.prototype.onRemoteStreamTrackStarted = function(event) { MatrixCall.prototype.onRemoteStreamTrackStarted = function(event) {
this.state = 'connected'; this.state = 'connected';
}; };
MatrixCall.prototype.onHangupReceived = function() { MatrixCall.prototype.onHangupReceived = function() {
this.state = 'ended'; this.state = 'ended';
this.stopAllMedia();
if (this.localAVStream) {
forAllTracksOnStream(this.localAVStream, function(t) {
t.stop();
});
}
if (this.remoteAVStream) {
forAllTracksOnStream(this.remoteAVStream, function(t) {
t.stop();
});
}
this.onHangup(); this.onHangup();
}; };