diff options
author | David Baker <dbkr@matrix.org> | 2014-08-29 13:23:01 +0100 |
---|---|---|
committer | David Baker <dbkr@matrix.org> | 2014-08-29 13:23:01 +0100 |
commit | 5308e3026a088be2c0c0edc406053fe192e827c2 (patch) | |
tree | 75de1065db178ffe0758316793fec4d0c429fbdd /webclient | |
parent | Merge branch 'voip' into develop (diff) | |
download | synapse-5308e3026a088be2c0c0edc406053fe192e827c2.tar.xz |
Change call signalling messages to be their own types of room events rather than room messages with different msgtypes: room messages should be things that the client can display as a unit message to the user.
Diffstat (limited to '')
-rw-r--r-- | webclient/components/matrix/event-handler-service.js | 9 | ||||
-rw-r--r-- | webclient/components/matrix/matrix-call.js | 12 | ||||
-rw-r--r-- | webclient/components/matrix/matrix-phone-service.js | 14 | ||||
-rw-r--r-- | webclient/components/matrix/matrix-service.js | 8 | ||||
-rw-r--r-- | webclient/room/room-controller.js | 2 |
5 files changed, 27 insertions, 18 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index 2f7580d682..b6e5c2eaac 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -31,6 +31,7 @@ angular.module('eventHandlerService', []) var MSG_EVENT = "MSG_EVENT"; var MEMBER_EVENT = "MEMBER_EVENT"; var PRESENCE_EVENT = "PRESENCE_EVENT"; + var CALL_EVENT = "CALL_EVENT"; var InitialSyncDeferred = $q.defer(); @@ -94,11 +95,16 @@ angular.module('eventHandlerService', []) $rootScope.presence[event.content.user_id] = event; $rootScope.$broadcast(PRESENCE_EVENT, event, isLiveEvent); }; + + var handleCallEvent = function(event, isLiveEvent) { + $rootScope.$broadcast(CALL_EVENT, event, isLiveEvent); + }; return { MSG_EVENT: MSG_EVENT, MEMBER_EVENT: MEMBER_EVENT, PRESENCE_EVENT: PRESENCE_EVENT, + CALL_EVENT: CALL_EVENT, handleEvent: function(event, isLiveEvent) { @@ -116,6 +122,9 @@ angular.module('eventHandlerService', []) console.log("Unable to handle event type " + event.type); break; } + if (event.type.indexOf('m.call.') == 0) { + handleCallEvent(event, isLiveEvent); + } }, // isLiveEvents determines whether notifications should be shown, whether diff --git a/webclient/components/matrix/matrix-call.js b/webclient/components/matrix/matrix-call.js index 3aab6413fc..b66c914d7b 100644 --- a/webclient/components/matrix/matrix-call.js +++ b/webclient/components/matrix/matrix-call.js @@ -84,11 +84,10 @@ angular.module('MatrixCall', []) }); var content = { - msgtype: "m.call.hangup", version: 0, call_id: this.call_id, }; - matrixService.sendMessage(this.room_id, undefined, content).then(this.messageSent, this.messageSendFailed); + matrixService.sendEvent(this.room_id, 'm.call.hangup', undefined, content).then(this.messageSent, this.messageSendFailed); this.state = 'ended'; }; @@ -135,12 +134,11 @@ angular.module('MatrixCall', []) console.trace(event); if (event.candidate) { var content = { - msgtype: "m.call.candidate", version: 0, call_id: this.call_id, candidate: event.candidate }; - matrixService.sendMessage(this.room_id, undefined, content).then(this.messageSent, this.messageSendFailed); + matrixService.sendEvent(this.room_id, 'm.call.candidate', undefined, content).then(this.messageSent, this.messageSendFailed); } } @@ -163,12 +161,11 @@ angular.module('MatrixCall', []) this.peerConn.setLocalDescription(description); var content = { - msgtype: "m.call.invite", version: 0, call_id: this.call_id, offer: description }; - matrixService.sendMessage(this.room_id, undefined, content).then(this.messageSent, this.messageSendFailed); + matrixService.sendEvent(this.room_id, 'm.call.invite', undefined, content).then(this.messageSent, this.messageSendFailed); this.state = 'invite_sent'; }; @@ -176,12 +173,11 @@ angular.module('MatrixCall', []) console.trace("Created answer: "+description); this.peerConn.setLocalDescription(description); var content = { - msgtype: "m.call.answer", version: 0, call_id: this.call_id, answer: description }; - matrixService.sendMessage(this.room_id, undefined, content).then(this.messageSent, this.messageSendFailed); + matrixService.sendEvent(this.room_id, 'm.call.answer', undefined, content).then(this.messageSent, this.messageSendFailed); this.state = 'connecting'; }; diff --git a/webclient/components/matrix/matrix-phone-service.js b/webclient/components/matrix/matrix-phone-service.js index 7f1ff531c4..d9e2e8baa3 100644 --- a/webclient/components/matrix/matrix-phone-service.js +++ b/webclient/components/matrix/matrix-phone-service.js @@ -21,39 +21,39 @@ angular.module('matrixPhoneService', []) var matrixPhoneService = function() { }; - matrixPhoneService.CALL_EVENT = "CALL_EVENT"; + matrixPhoneService.INCOMING_CALL_EVENT = "INCOMING_CALL_EVENT"; matrixPhoneService.allCalls = {}; matrixPhoneService.callPlaced = function(call) { matrixPhoneService.allCalls[call.call_id] = call; }; - $rootScope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) { + $rootScope.$on(eventHandlerService.CALL_EVENT, function(ngEvent, event, isLive) { if (!isLive) return; // until matrix supports expiring messages if (event.user_id == matrixService.config().user_id) return; var msg = event.content; - if (msg.msgtype == 'm.call.invite') { + if (event.type == 'm.call.invite') { var MatrixCall = $injector.get('MatrixCall'); var call = new MatrixCall(event.room_id); call.call_id = msg.call_id; call.initWithInvite(msg); matrixPhoneService.allCalls[call.call_id] = call; - $rootScope.$broadcast(matrixPhoneService.CALL_EVENT, call); - } else if (msg.msgtype == 'm.call.answer') { + $rootScope.$broadcast(matrixPhoneService.INCOMING_CALL_EVENT, call); + } else if (event.type == 'm.call.answer') { var call = matrixPhoneService.allCalls[msg.call_id]; if (!call) { console.trace("Got answer for unknown call ID "+msg.call_id); return; } call.receivedAnswer(msg); - } else if (msg.msgtype == 'm.call.candidate') { + } else if (event.type == 'm.call.candidate') { var call = matrixPhoneService.allCalls[msg.call_id]; if (!call) { console.trace("Got candidate for unknown call ID "+msg.call_id); return; } call.gotRemoteIceCandidate(msg.candidate); - } else if (msg.msgtype == 'm.call.hangup') { + } else if (event.type == 'm.call.hangup') { var call = matrixPhoneService.allCalls[msg.call_id]; if (!call) { console.trace("Got hangup for unknown call ID "+msg.call_id); diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js index b56eef6af5..06f920b15d 100644 --- a/webclient/components/matrix/matrix-service.js +++ b/webclient/components/matrix/matrix-service.js @@ -172,9 +172,9 @@ angular.module('matrixService', []) return doRequest("GET", path, undefined, {}); }, - sendMessage: function(room_id, txn_id, content) { + sendEvent: function(room_id, eventType, txn_id, content) { // The REST path spec - var path = "/rooms/$room_id/send/m.room.message/$txn_id"; + var path = "/rooms/$room_id/send/"+eventType+"/$txn_id"; if (!txn_id) { txn_id = "m" + new Date().getTime(); @@ -190,6 +190,10 @@ angular.module('matrixService', []) return doRequest("PUT", path, undefined, content); }, + sendMessage: function(room_id, txn_id, content) { + return self.sendObject(room_id, 'm.room.message', txn_id, content); + }, + // Send a text message sendTextMessage: function(room_id, body, msg_id) { var content = { diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index 15710d2ba3..8bb48b3692 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -83,7 +83,7 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) updatePresence(event); }); - $rootScope.$on(matrixPhoneService.CALL_EVENT, function(ngEvent, call) { + $rootScope.$on(matrixPhoneService.INCOMING_CALL_EVENT, function(ngEvent, call) { console.trace("incoming call"); call.onError = $scope.onCallError; call.onHangup = $scope.onCallHangup; |