summary refs log tree commit diff
path: root/syweb/webclient/components
diff options
context:
space:
mode:
Diffstat (limited to 'syweb/webclient/components')
-rw-r--r--syweb/webclient/components/matrix/event-handler-service.js24
-rw-r--r--syweb/webclient/components/matrix/matrix-call.js20
-rw-r--r--syweb/webclient/components/matrix/matrix-service.js2
-rw-r--r--syweb/webclient/components/matrix/recents-service.js99
4 files changed, 135 insertions, 10 deletions
diff --git a/syweb/webclient/components/matrix/event-handler-service.js b/syweb/webclient/components/matrix/event-handler-service.js

index 7b2a75507d..6645d20374 100644 --- a/syweb/webclient/components/matrix/event-handler-service.js +++ b/syweb/webclient/components/matrix/event-handler-service.js
@@ -95,14 +95,22 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati modelService.createRoomIdToAliasMapping(event.room_id, event.content.aliases[0]); }; + var containsBingWord = function(event) { + if (!event.content || !event.content.body) { + return false; + } + + return notificationService.containsBingWord( + matrixService.config().user_id, + matrixService.config().display_name, + matrixService.config().bingWords, + event.content.body + ); + }; + var displayNotification = function(event) { if (window.Notification && event.user_id != matrixService.config().user_id) { - var shouldBing = notificationService.containsBingWord( - matrixService.config().user_id, - matrixService.config().display_name, - matrixService.config().bingWords, - event.content.body - ); + var shouldBing = containsBingWord(event); // Ideally we would notify only when the window is hidden (i.e. document.hidden = true). // @@ -529,6 +537,10 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati resetRoomMessages(room_id); }, + eventContainsBingWord: function(event) { + return containsBingWord(event); + }, + /** * Return the last message event of a room * @param {String} room_id the room id diff --git a/syweb/webclient/components/matrix/matrix-call.js b/syweb/webclient/components/matrix/matrix-call.js
index b560cf7daa..a1c3aaa103 100644 --- a/syweb/webclient/components/matrix/matrix-call.js +++ b/syweb/webclient/components/matrix/matrix-call.js
@@ -82,7 +82,7 @@ angular.module('MatrixCall', []) }); } - // FIXME: we should prevent any class from being placed or accepted before this has finished + // FIXME: we should prevent any calls from being placed or accepted before this has finished MatrixCall.getTurnServer(); MatrixCall.CALL_TIMEOUT = 60000; @@ -92,7 +92,8 @@ angular.module('MatrixCall', []) var pc; if (window.mozRTCPeerConnection) { var iceServers = []; - if (MatrixCall.turnServer) { + // https://github.com/EricssonResearch/openwebrtc/issues/85 + if (MatrixCall.turnServer /*&& !this.isOpenWebRTC()*/) { if (MatrixCall.turnServer.uris) { for (var i = 0; i < MatrixCall.turnServer.uris.length; i++) { iceServers.push({ @@ -110,7 +111,8 @@ angular.module('MatrixCall', []) pc = new window.mozRTCPeerConnection({"iceServers":iceServers}); } else { var iceServers = []; - if (MatrixCall.turnServer) { + // https://github.com/EricssonResearch/openwebrtc/issues/85 + if (MatrixCall.turnServer /*&& !this.isOpenWebRTC()*/) { if (MatrixCall.turnServer.uris) { iceServers.push({ 'urls': MatrixCall.turnServer.uris, @@ -492,6 +494,8 @@ angular.module('MatrixCall', []) $timeout(function() { var vel = self.getRemoteVideoElement(); if (vel.play) vel.play(); + // OpenWebRTC does not support oniceconnectionstatechange yet + if (self.isOpenWebRTC()) self.state = 'connected'; }); } }; @@ -641,5 +645,15 @@ angular.module('MatrixCall', []) return null; }; + MatrixCall.prototype.isOpenWebRTC = function() { + var scripts = angular.element('script'); + for (var i = 0; i < scripts.length; i++) { + if (scripts[i].src.indexOf("owr.js") > -1) { + return true; + } + } + return false; + }; + return MatrixCall; }]); diff --git a/syweb/webclient/components/matrix/matrix-service.js b/syweb/webclient/components/matrix/matrix-service.js
index c1264887c8..cfe8691f85 100644 --- a/syweb/webclient/components/matrix/matrix-service.js +++ b/syweb/webclient/components/matrix/matrix-service.js
@@ -23,7 +23,7 @@ This serves to isolate the caller from changes to the underlying url paths, as well as attach common params (e.g. access_token) to requests. */ angular.module('matrixService', []) -.factory('matrixService', ['$http', '$q', '$rootScope', function($http, $q, $rootScope) { +.factory('matrixService', ['$http', '$q', function($http, $q) { /* * Permanent storage of user information diff --git a/syweb/webclient/components/matrix/recents-service.js b/syweb/webclient/components/matrix/recents-service.js new file mode 100644
index 0000000000..3d82b8218b --- /dev/null +++ b/syweb/webclient/components/matrix/recents-service.js
@@ -0,0 +1,99 @@ +/* +Copyright 2014 OpenMarket Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +'use strict'; + +/* +This service manages shared state between *instances* of recent lists. The +recents controller will hook into this central service to get things like: +- which rooms should be highlighted +- which rooms have been binged +- which room is currently selected +- etc. +This is preferable to polluting the $rootScope with recents specific info, and +makes the dependency on this shared state *explicit*. +*/ +angular.module('recentsService', []) +.factory('recentsService', ['$rootScope', 'eventHandlerService', function($rootScope, eventHandlerService) { + // notify listeners when variables in the service are updated. We need to do + // this since we do not tie them to any scope. + var BROADCAST_SELECTED_ROOM_ID = "recentsService:BROADCAST_SELECTED_ROOM_ID(room_id)"; + var selectedRoomId = undefined; + + var BROADCAST_UNREAD_MESSAGES = "recentsService:BROADCAST_UNREAD_MESSAGES(room_id, unreadCount)"; + var unreadMessages = { + // room_id: <number> + }; + + var BROADCAST_UNREAD_BING_MESSAGES = "recentsService:BROADCAST_UNREAD_BING_MESSAGES(room_id, event)"; + var unreadBingMessages = { + // room_id: bingEvent + }; + + // listen for new unread messages + $rootScope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) { + if (isLive && event.room_id !== selectedRoomId) { + if (eventHandlerService.eventContainsBingWord(event)) { + if (!unreadBingMessages[event.room_id]) { + unreadBingMessages[event.room_id] = {}; + } + unreadBingMessages[event.room_id] = event; + $rootScope.$broadcast(BROADCAST_UNREAD_BING_MESSAGES, event.room_id, event); + } + + if (!unreadMessages[event.room_id]) { + unreadMessages[event.room_id] = 0; + } + unreadMessages[event.room_id] += 1; + $rootScope.$broadcast(BROADCAST_UNREAD_MESSAGES, event.room_id, unreadMessages[event.room_id]); + } + }); + + return { + BROADCAST_SELECTED_ROOM_ID: BROADCAST_SELECTED_ROOM_ID, + BROADCAST_UNREAD_MESSAGES: BROADCAST_UNREAD_MESSAGES, + + getSelectedRoomId: function() { + return selectedRoomId; + }, + + setSelectedRoomId: function(room_id) { + selectedRoomId = room_id; + $rootScope.$broadcast(BROADCAST_SELECTED_ROOM_ID, room_id); + }, + + getUnreadMessages: function() { + return unreadMessages; + }, + + getUnreadBingMessages: function() { + return unreadBingMessages; + }, + + markAsRead: function(room_id) { + if (unreadMessages[room_id]) { + unreadMessages[room_id] = 0; + } + if (unreadBingMessages[room_id]) { + unreadBingMessages[room_id] = undefined; + } + $rootScope.$broadcast(BROADCAST_UNREAD_MESSAGES, room_id, 0); + $rootScope.$broadcast(BROADCAST_UNREAD_BING_MESSAGES, room_id, undefined); + } + + }; + +}]);