mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
More basic functionality for voip calls (like hanging up)
This commit is contained in:
parent
ca7426eee0
commit
41d02ab674
@ -16,6 +16,25 @@ limitations under the License.
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var forAllVideoTracksOnStream = function(s, f) {
|
||||||
|
var tracks = s.getVideoTracks();
|
||||||
|
for (var i = 0; i < tracks.length; i++) {
|
||||||
|
f(tracks[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var forAllAudioTracksOnStream = function(s, f) {
|
||||||
|
var tracks = s.getAudioTracks();
|
||||||
|
for (var i = 0; i < tracks.length; i++) {
|
||||||
|
f(tracks[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var forAllTracksOnStream = function(s, f) {
|
||||||
|
forAllVideoTracksOnStream(s, f);
|
||||||
|
forAllAudioTracksOnStream(s, f);
|
||||||
|
}
|
||||||
|
|
||||||
angular.module('MatrixCall', [])
|
angular.module('MatrixCall', [])
|
||||||
.factory('MatrixCall', ['matrixService', 'matrixPhoneService', function MatrixCallFactory(matrixService, matrixPhoneService) {
|
.factory('MatrixCall', ['matrixService', 'matrixPhoneService', function MatrixCallFactory(matrixService, matrixPhoneService) {
|
||||||
var MatrixCall = function(room_id) {
|
var MatrixCall = function(room_id) {
|
||||||
@ -55,7 +74,15 @@ angular.module('MatrixCall', [])
|
|||||||
};
|
};
|
||||||
|
|
||||||
MatrixCall.prototype.hangup = function() {
|
MatrixCall.prototype.hangup = function() {
|
||||||
console.trace("Rejecting call "+this.call_id);
|
console.trace("Ending call "+this.call_id);
|
||||||
|
|
||||||
|
forAllTracksOnStream(this.localAVStream, function(t) {
|
||||||
|
t.stop();
|
||||||
|
});
|
||||||
|
forAllTracksOnStream(this.remoteAVStream, function(t) {
|
||||||
|
t.stop();
|
||||||
|
});
|
||||||
|
|
||||||
var content = {
|
var content = {
|
||||||
msgtype: "m.call.hangup",
|
msgtype: "m.call.hangup",
|
||||||
version: 0,
|
version: 0,
|
||||||
@ -66,6 +93,7 @@ angular.module('MatrixCall', [])
|
|||||||
};
|
};
|
||||||
|
|
||||||
MatrixCall.prototype.gotUserMediaForInvite = function(stream) {
|
MatrixCall.prototype.gotUserMediaForInvite = function(stream) {
|
||||||
|
this.localAVStream = stream;
|
||||||
var audioTracks = stream.getAudioTracks();
|
var audioTracks = stream.getAudioTracks();
|
||||||
for (var i = 0; i < audioTracks.length; i++) {
|
for (var i = 0; i < audioTracks.length; i++) {
|
||||||
audioTracks[i].enabled = true;
|
audioTracks[i].enabled = true;
|
||||||
@ -86,6 +114,7 @@ angular.module('MatrixCall', [])
|
|||||||
};
|
};
|
||||||
|
|
||||||
MatrixCall.prototype.gotUserMediaForAnswer = function(stream) {
|
MatrixCall.prototype.gotUserMediaForAnswer = function(stream) {
|
||||||
|
this.localAVStream = stream;
|
||||||
var audioTracks = stream.getAudioTracks();
|
var audioTracks = stream.getAudioTracks();
|
||||||
for (var i = 0; i < audioTracks.length; i++) {
|
for (var i = 0; i < audioTracks.length; i++) {
|
||||||
audioTracks[i].enabled = true;
|
audioTracks[i].enabled = true;
|
||||||
@ -172,7 +201,8 @@ angular.module('MatrixCall', [])
|
|||||||
|
|
||||||
MatrixCall.prototype.onIceConnectionStateChanged = function() {
|
MatrixCall.prototype.onIceConnectionStateChanged = function() {
|
||||||
console.trace("Ice connection state changed to: "+this.peerConn.iceConnectionState);
|
console.trace("Ice connection state changed to: "+this.peerConn.iceConnectionState);
|
||||||
if (this.peerConn.iceConnectionState == 'completed') {
|
// ideally we'd consider the call to be connected when we get media but chrome doesn't implement nay of the 'onstarted' events yet
|
||||||
|
if (this.peerConn.iceConnectionState == 'completed' || this.peerConn.iceConnectionState == 'connected') {
|
||||||
this.state = 'connected';
|
this.state = 'connected';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -191,10 +221,44 @@ angular.module('MatrixCall', [])
|
|||||||
|
|
||||||
MatrixCall.prototype.onAddStream = function(event) {
|
MatrixCall.prototype.onAddStream = function(event) {
|
||||||
console.trace("Stream added"+event);
|
console.trace("Stream added"+event);
|
||||||
|
|
||||||
|
var s = event.stream;
|
||||||
|
|
||||||
|
this.remoteAVStream = s;
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
forAllTracksOnStream(s, function(t) {
|
||||||
|
// not currently implemented in chrome
|
||||||
|
t.onstarted = self.onRemoteStreamTrackStarted;
|
||||||
|
});
|
||||||
|
|
||||||
|
// not currently implemented in chrome
|
||||||
|
event.stream.onstarted = this.onRemoteStreamStarted;
|
||||||
var player = new Audio();
|
var player = new Audio();
|
||||||
player.src = URL.createObjectURL(event.stream);
|
player.src = URL.createObjectURL(s);
|
||||||
player.play();
|
player.play();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MatrixCall.prototype.onRemoteStreamStarted = function(event) {
|
||||||
|
this.state = 'connected';
|
||||||
|
};
|
||||||
|
|
||||||
|
MatrixCall.prototype.onRemoteStreamTrackStarted = function(event) {
|
||||||
|
this.state = 'connected';
|
||||||
|
};
|
||||||
|
|
||||||
|
MatrixCall.prototype.onHangupReceived = function() {
|
||||||
|
this.state = 'ended';
|
||||||
|
|
||||||
|
forAllTracksOnStream(this.localAVStream, function(t) {
|
||||||
|
t.stop();
|
||||||
|
});
|
||||||
|
forAllTracksOnStream(this.remoteAVStream, function(t) {
|
||||||
|
t.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.onHangup();
|
||||||
|
};
|
||||||
|
|
||||||
return MatrixCall;
|
return MatrixCall;
|
||||||
}]);
|
}]);
|
||||||
|
@ -59,7 +59,7 @@ angular.module('matrixPhoneService', [])
|
|||||||
console.trace("Got hangup for unknown call ID "+msg.call_id);
|
console.trace("Got hangup for unknown call ID "+msg.call_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
call.onHangup();
|
call.onHangupReceived();
|
||||||
matrixPhoneService.allCalls[msg.call_id] = undefined;
|
matrixPhoneService.allCalls[msg.call_id] = undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -104,6 +104,7 @@
|
|||||||
<button ng-click="answerCall()">Answer</button>
|
<button ng-click="answerCall()">Answer</button>
|
||||||
<button ng-click="hangupCall()">Reject</button>
|
<button ng-click="hangupCall()">Reject</button>
|
||||||
</div>
|
</div>
|
||||||
|
<button ng-click="hangupCall()" ng-show="currentCall && currentCall.state != 'ringing'">Hang up</button>
|
||||||
{{ currentCall.state }}
|
{{ currentCall.state }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -111,7 +112,6 @@
|
|||||||
<div ng-hide="!state.stream_failure">
|
<div ng-hide="!state.stream_failure">
|
||||||
{{ state.stream_failure.data.error || "Connection failure" }}
|
{{ state.stream_failure.data.error || "Connection failure" }}
|
||||||
</div>
|
</div>
|
||||||
<audio id="remoteAudio" autoplay="autoplay"></audio>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user