diff --git a/docs/specification.rst b/docs/specification.rst
index 1d3c283331..5b044459e2 100644
--- a/docs/specification.rst
+++ b/docs/specification.rst
@@ -418,6 +418,16 @@ which can be set when creating a room:
If this is included, an ``m.room.topic`` event will be sent into the room to indicate the
topic for the room. See `Room Events`_ for more information on ``m.room.topic``.
+``invite``
+ Type:
+ List
+ Optional:
+ Yes
+ Value:
+ A list of user ids to invite.
+ Description:
+ This will tell the server to invite everyone in the list to the newly created room.
+
Example::
{
@@ -909,6 +919,22 @@ prefixed with ``m.``
``ban_level`` will be greater than or equal to ``kick_level`` since
banning is more severe than kicking.
+``m.room.aliases``
+ Summary:
+ These state events are used to inform the room about what room aliases it has.
+ Type:
+ State event
+ JSON format:
+ ``{ "aliases": ["string", ...] }``
+ Example:
+ ``{ "aliases": ["#foo:example.com"] }``
+ Description:
+ A server `may` inform the room that it has added or removed an alias for
+ the room. This is purely for informational purposes and may become stale.
+ Clients `should` check that the room alias is still valid before using it.
+ The ``state_key`` of the event is the homeserver which owns the room
+ alias.
+
``m.room.message``
Summary:
A message.
diff --git a/synapse/api/auth.py b/synapse/api/auth.py
index 5d7c607702..8f32191b57 100644
--- a/synapse/api/auth.py
+++ b/synapse/api/auth.py
@@ -18,7 +18,7 @@
from twisted.internet import defer
from synapse.api.constants import Membership, JoinRules
-from synapse.api.errors import AuthError, StoreError, Codes
+from synapse.api.errors import AuthError, StoreError, Codes, SynapseError
from synapse.api.events.room import RoomMemberEvent, RoomPowerLevelsEvent
from synapse.util.logutils import log_function
@@ -308,7 +308,9 @@ class Auth(object):
else:
user_level = 0
- logger.debug("Checking power level for %s, %s", event.user_id, user_level)
+ logger.debug(
+ "Checking power level for %s, %s", event.user_id, user_level
+ )
if current_state and hasattr(current_state, "required_power_level"):
req = current_state.required_power_level
@@ -321,12 +323,35 @@ class Auth(object):
@defer.inlineCallbacks
def _check_power_levels(self, event):
+ for k, v in event.content.items():
+ if k == "default":
+ continue
+
+ # FIXME (erikj): We don't want hsob_Ts in content.
+ if k == "hsob_ts":
+ continue
+
+ try:
+ self.hs.parse_userid(k)
+ except:
+ raise SynapseError(400, "Not a valid user_id: %s" % (k,))
+
+ try:
+ int(v)
+ except:
+ raise SynapseError(400, "Not a valid power level: %s" % (v,))
+
current_state = yield self.store.get_current_state(
event.room_id,
event.type,
event.state_key,
)
+ if not current_state:
+ return
+ else:
+ current_state = current_state[0]
+
user_level = yield self.store.get_power_level(
event.room_id,
event.user_id,
@@ -341,7 +366,10 @@ class Auth(object):
# FIXME (erikj)
old_people = {k: v for k, v in old_list.items() if k.startswith("@")}
- new_people = {k: v for k, v in event.content if k.startswith("@")}
+ new_people = {
+ k: v for k, v in event.content.items()
+ if k.startswith("@")
+ }
removed = set(old_people.keys()) - set(new_people.keys())
added = set(old_people.keys()) - set(new_people.keys())
@@ -351,22 +379,24 @@ class Auth(object):
if int(old_list.content[r]) > user_level:
raise AuthError(
403,
- "You don't have permission to change that state"
+ "You don't have permission to remove user: %s" % (r, )
)
- for n in new_people:
+ for n in added:
if int(event.content[n]) > user_level:
raise AuthError(
403,
- "You don't have permission to change that state"
+ "You don't have permission to add ops level greater "
+ "than your own"
)
for s in same:
if int(event.content[s]) != int(old_list[s]):
- if int(old_list[s]) > user_level:
+ if int(event.content[s]) > user_level:
raise AuthError(
403,
- "You don't have permission to change that state"
+ "You don't have permission to add ops level greater "
+ "than your own"
)
if "default" in old_list:
@@ -375,7 +405,8 @@ class Auth(object):
if old_default > user_level:
raise AuthError(
403,
- "You don't have permission to change that state"
+ "You don't have permission to add ops level greater than "
+ "your own"
)
if "default" in event.content:
@@ -384,5 +415,6 @@ class Auth(object):
if new_default > user_level:
raise AuthError(
403,
- "You don't have permission to change that state"
+ "You don't have permission to add ops level greater "
+ "than your own"
)
diff --git a/synapse/api/events/__init__.py b/synapse/api/events/__init__.py
index f95468fc65..5f300de108 100644
--- a/synapse/api/events/__init__.py
+++ b/synapse/api/events/__init__.py
@@ -157,7 +157,12 @@ class SynapseEvent(JsonEncodedObject):
class SynapseStateEvent(SynapseEvent):
- def __init__(self, **kwargs):
+
+ valid_keys = SynapseEvent.valid_keys + [
+ "prev_content",
+ ]
+
+ def __init__(self, **kwargs):
if "state_key" not in kwargs:
kwargs["state_key"] = ""
super(SynapseStateEvent, self).__init__(**kwargs)
diff --git a/synapse/api/events/factory.py b/synapse/api/events/factory.py
index a3b293e024..5e38cdbc44 100644
--- a/synapse/api/events/factory.py
+++ b/synapse/api/events/factory.py
@@ -47,11 +47,14 @@ class EventFactory(object):
self._event_list[event_class.TYPE] = event_class
self.clock = hs.get_clock()
+ self.hs = hs
def create_event(self, etype=None, **kwargs):
kwargs["type"] = etype
if "event_id" not in kwargs:
- kwargs["event_id"] = random_string(10)
+ kwargs["event_id"] = "%s@%s" % (
+ random_string(10), self.hs.hostname
+ )
if "ts" not in kwargs:
kwargs["ts"] = int(self.clock.time_msec())
diff --git a/synapse/api/events/room.py b/synapse/api/events/room.py
index 33f0f0cb99..3a4dbc58ce 100644
--- a/synapse/api/events/room.py
+++ b/synapse/api/events/room.py
@@ -173,3 +173,10 @@ class RoomOpsPowerLevelsEvent(SynapseStateEvent):
def get_content_template(self):
return {}
+
+
+class RoomAliasesEvent(SynapseStateEvent):
+ TYPE = "m.room.aliases"
+
+ def get_content_template(self):
+ return {}
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index 49cf928cc1..d675d8c8f9 100755
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -57,7 +57,7 @@ SCHEMAS = [
# Remember to update this number every time an incompatible change is made to
# database schema files, so the users will be informed on server restarts.
-SCHEMA_VERSION = 2
+SCHEMA_VERSION = 3
class SynapseHomeServer(HomeServer):
diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py
index 9989fe8670..de4d23bbb3 100644
--- a/synapse/handlers/_base.py
+++ b/synapse/handlers/_base.py
@@ -42,9 +42,6 @@ class BaseHandler(object):
retry_after_ms=int(1000*(time_allowed - time_now)),
)
-
-class BaseRoomHandler(BaseHandler):
-
@defer.inlineCallbacks
def _on_new_room_event(self, event, snapshot, extra_destinations=[],
extra_users=[]):
diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py
index 1b9e831fc0..4ab00a761a 100644
--- a/synapse/handlers/directory.py
+++ b/synapse/handlers/directory.py
@@ -19,8 +19,10 @@ from ._base import BaseHandler
from synapse.api.errors import SynapseError
from synapse.http.client import HttpClient
+from synapse.api.events.room import RoomAliasesEvent
import logging
+import sqlite3
logger = logging.getLogger(__name__)
@@ -37,7 +39,8 @@ class DirectoryHandler(BaseHandler):
)
@defer.inlineCallbacks
- def create_association(self, room_alias, room_id, servers=None):
+ def create_association(self, user_id, room_alias, room_id, servers=None):
+
# TODO(erikj): Do auth.
if not room_alias.is_mine:
@@ -54,12 +57,37 @@ class DirectoryHandler(BaseHandler):
if not servers:
raise SynapseError(400, "Failed to get server list")
- yield self.store.create_room_alias_association(
- room_alias,
- room_id,
- servers
+
+ try:
+ yield self.store.create_room_alias_association(
+ room_alias,
+ room_id,
+ servers
+ )
+ except sqlite3.IntegrityError:
+ defer.returnValue("Already exists")
+
+ # TODO: Send the room event.
+
+ aliases = yield self.store.get_aliases_for_room(room_id)
+
+ event = self.event_factory.create_event(
+ etype=RoomAliasesEvent.TYPE,
+ state_key=self.hs.hostname,
+ room_id=room_id,
+ user_id=user_id,
+ content={"aliases": aliases},
+ )
+
+ snapshot = yield self.store.snapshot_room(
+ room_id=room_id,
+ user_id=user_id,
)
+ yield self.state_handler.handle_new_event(event, snapshot)
+ yield self._on_new_room_event(event, snapshot, extra_users=[user_id])
+
+
@defer.inlineCallbacks
def get_association(self, room_alias):
room_id = None
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index dad2bbd1a4..87fc04478b 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -19,7 +19,7 @@ from synapse.api.constants import Membership
from synapse.api.events.room import RoomTopicEvent
from synapse.api.errors import RoomError
from synapse.streams.config import PaginationConfig
-from ._base import BaseRoomHandler
+from ._base import BaseHandler
import logging
@@ -27,7 +27,7 @@ logger = logging.getLogger(__name__)
-class MessageHandler(BaseRoomHandler):
+class MessageHandler(BaseHandler):
def __init__(self, hs):
super(MessageHandler, self).__init__(hs)
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index 171ca3d797..a0d0f2af16 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -25,14 +25,14 @@ from synapse.api.events.room import (
RoomSendEventLevelEvent, RoomOpsPowerLevelsEvent, RoomNameEvent,
)
from synapse.util import stringutils
-from ._base import BaseRoomHandler
+from ._base import BaseHandler
import logging
logger = logging.getLogger(__name__)
-class RoomCreationHandler(BaseRoomHandler):
+class RoomCreationHandler(BaseHandler):
@defer.inlineCallbacks
def create_room(self, user_id, room_id, config):
@@ -65,6 +65,13 @@ class RoomCreationHandler(BaseRoomHandler):
else:
room_alias = None
+ invite_list = config.get("invite", [])
+ for i in invite_list:
+ try:
+ self.hs.parse_userid(i)
+ except:
+ raise SynapseError(400, "Invalid user_id: %s" % (i,))
+
is_public = config.get("visibility", None) == "public"
if room_id:
@@ -105,7 +112,9 @@ class RoomCreationHandler(BaseRoomHandler):
)
if room_alias:
- yield self.store.create_room_alias_association(
+ directory_handler = self.hs.get_handlers().directory_handler
+ yield directory_handler.create_association(
+ user_id=user_id,
room_id=room_id,
room_alias=room_alias,
servers=[self.hs.hostname],
@@ -176,6 +185,25 @@ class RoomCreationHandler(BaseRoomHandler):
do_auth=False
)
+ content = {"membership": Membership.INVITE}
+ for invitee in invite_list:
+ invite_event = self.event_factory.create_event(
+ etype=RoomMemberEvent.TYPE,
+ state_key=invitee,
+ room_id=room_id,
+ user_id=user_id,
+ content=content
+ )
+
+ yield self.hs.get_handlers().room_member_handler.change_membership(
+ invite_event,
+ do_auth=False
+ )
+
+ yield self.hs.get_handlers().room_member_handler.change_membership(
+ join_event,
+ do_auth=False
+ )
result = {"room_id": room_id}
if room_alias:
result["room_alias"] = room_alias.to_string()
@@ -239,7 +267,7 @@ class RoomCreationHandler(BaseRoomHandler):
]
-class RoomMemberHandler(BaseRoomHandler):
+class RoomMemberHandler(BaseHandler):
# TODO(paul): This handler currently contains a messy conflation of
# low-level API that works on UserID objects and so on, and REST-level
# API that takes ID strings and returns pagination chunks. These concerns
@@ -560,7 +588,7 @@ class RoomMemberHandler(BaseRoomHandler):
extra_users=[target_user]
)
-class RoomListHandler(BaseRoomHandler):
+class RoomListHandler(BaseHandler):
@defer.inlineCallbacks
def get_public_room_list(self):
diff --git a/synapse/rest/directory.py b/synapse/rest/directory.py
index 18df7c8d8b..31849246a1 100644
--- a/synapse/rest/directory.py
+++ b/synapse/rest/directory.py
@@ -45,6 +45,8 @@ class ClientDirectoryServer(RestServlet):
@defer.inlineCallbacks
def on_PUT(self, request, room_alias):
+ user = yield self.auth.get_user_by_req(request)
+
content = _parse_json(request)
if not "room_id" in content:
raise SynapseError(400, "Missing room_id key",
@@ -69,12 +71,13 @@ class ClientDirectoryServer(RestServlet):
try:
yield dir_handler.create_association(
- room_alias, room_id, servers
+ user.to_string(), room_alias, room_id, servers
)
except SynapseError as e:
raise e
except:
logger.exception("Failed to create association")
+ raise
defer.returnValue((200, {}))
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index d97014f4da..81c3c94b2e 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -81,7 +81,7 @@ class DataStore(RoomMemberStore, RoomStore,
defer.returnValue(latest)
@defer.inlineCallbacks
- def get_event(self, event_id):
+ def get_event(self, event_id, allow_none=False):
events_dict = yield self._simple_select_one(
"events",
{"event_id": event_id},
@@ -92,8 +92,12 @@ class DataStore(RoomMemberStore, RoomStore,
"content",
"unrecognized_keys"
],
+ allow_none=allow_none,
)
+ if not events_dict:
+ defer.returnValue(None)
+
event = self._parse_event_from_row(events_dict)
defer.returnValue(event)
@@ -220,7 +224,8 @@ class DataStore(RoomMemberStore, RoomStore,
results = yield self._execute_and_decode(sql, *args)
- defer.returnValue([self._parse_event_from_row(r) for r in results])
+ events = yield self._parse_events(results)
+ defer.returnValue(events)
@defer.inlineCallbacks
def _get_min_token(self):
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index bae50e7d1f..8037225079 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -312,6 +312,25 @@ class SQLBaseStore(object):
**d
)
+ def _parse_events(self, rows):
+ return self._db_pool.runInteraction(self._parse_events_txn, rows)
+
+ def _parse_events_txn(self, txn, rows):
+ events = [self._parse_event_from_row(r) for r in rows]
+
+ sql = "SELECT * FROM events WHERE event_id = ?"
+
+ for ev in events:
+ if hasattr(ev, "prev_state"):
+ # Load previous state_content.
+ # TODO: Should we be pulling this out above?
+ cursor = txn.execute(sql, (ev.prev_state,))
+ prevs = self.cursor_to_dict(cursor)
+ if prevs:
+ prev = self._parse_event_from_row(prevs[0])
+ ev.prev_content = prev.content
+
+ return events
class Table(object):
""" A base class used to store information about a particular table.
diff --git a/synapse/storage/directory.py b/synapse/storage/directory.py
index bf55449253..540eb4c2c4 100644
--- a/synapse/storage/directory.py
+++ b/synapse/storage/directory.py
@@ -92,3 +92,10 @@ class DirectoryStore(SQLBaseStore):
"server": server,
}
)
+
+ def get_aliases_for_room(self, room_id):
+ return self._simple_select_onecol(
+ "room_aliases",
+ {"room_id": room_id},
+ "room_alias",
+ )
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index 75c9a60101..9a393e2568 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -88,7 +88,7 @@ class RoomMemberStore(SQLBaseStore):
txn.execute(sql, (user_id, room_id))
rows = self.cursor_to_dict(txn)
if rows:
- return self._parse_event_from_row(rows[0])
+ return self._parse_events_txn(txn, rows)[0]
else:
return None
@@ -161,7 +161,7 @@ class RoomMemberStore(SQLBaseStore):
# logger.debug("_get_members_query Got rows %s", rows)
- results = [self._parse_event_from_row(r) for r in rows]
+ results = yield self._parse_events(rows)
defer.returnValue(results)
@defer.inlineCallbacks
diff --git a/synapse/storage/schema/delta/v3.sql b/synapse/storage/schema/delta/v3.sql
new file mode 100644
index 0000000000..cade295989
--- /dev/null
+++ b/synapse/storage/schema/delta/v3.sql
@@ -0,0 +1,27 @@
+/* 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.
+ */
+
+
+CREATE INDEX IF NOT EXISTS room_aliases_alias ON room_aliases(room_alias);
+CREATE INDEX IF NOT EXISTS room_aliases_id ON room_aliases(room_id);
+
+
+CREATE INDEX IF NOT EXISTS room_alias_servers_alias ON room_alias_servers(room_alias);
+
+DELETE FROM room_aliases WHERE rowid NOT IN (SELECT max(rowid) FROM room_aliases GROUP BY room_alias, room_id);
+
+CREATE UNIQUE INDEX IF NOT EXISTS room_aliases_uniq ON room_aliases(room_alias, room_id);
+
+PRAGMA user_version = 3;
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py
index 2cb0067a67..aff6dc9855 100644
--- a/synapse/storage/stream.py
+++ b/synapse/storage/stream.py
@@ -188,7 +188,7 @@ class StreamStore(SQLBaseStore):
user_id, user_id, from_id, to_id
)
- ret = [self._parse_event_from_row(r) for r in rows]
+ ret = yield self._parse_events(rows)
if rows:
key = "s%d" % max([r["stream_ordering"] for r in rows])
@@ -243,9 +243,11 @@ class StreamStore(SQLBaseStore):
# TODO (erikj): We should work out what to do here instead.
next_token = to_key if to_key else from_key
+ events = yield self._parse_events(rows)
+
defer.returnValue(
(
- [self._parse_event_from_row(r) for r in rows],
+ events,
next_token
)
)
@@ -277,12 +279,11 @@ class StreamStore(SQLBaseStore):
else:
token = (end_token, end_token)
- defer.returnValue(
- (
- [self._parse_event_from_row(r) for r in rows],
- token
- )
- )
+ events = yield self._parse_events(rows)
+
+ ret = (events, token)
+
+ defer.returnValue(ret)
def get_room_events_max_id(self):
return self._db_pool.runInteraction(self._get_room_events_max_id_txn)
diff --git a/webclient/app-controller.js b/webclient/app-controller.js
index ea48cbb011..064bde3ab2 100644
--- a/webclient/app-controller.js
+++ b/webclient/app-controller.js
@@ -21,8 +21,8 @@ limitations under the License.
'use strict';
angular.module('MatrixWebClientController', ['matrixService', 'mPresence', 'eventStreamService'])
-.controller('MatrixWebClientController', ['$scope', '$location', '$rootScope', 'matrixService', 'mPresence', 'eventStreamService', 'matrixPhoneService',
- function($scope, $location, $rootScope, matrixService, mPresence, eventStreamService, matrixPhoneService) {
+.controller('MatrixWebClientController', ['$scope', '$location', '$rootScope', '$timeout', '$animate', 'matrixService', 'mPresence', 'eventStreamService', 'matrixPhoneService',
+ function($scope, $location, $rootScope, $timeout, $animate, matrixService, mPresence, eventStreamService, matrixPhoneService) {
// Check current URL to avoid to display the logout button on the login page
$scope.location = $location.path();
@@ -89,6 +89,23 @@ angular.module('MatrixWebClientController', ['matrixService', 'mPresence', 'even
$scope.user_id = matrixService.config().user_id;
};
+ $rootScope.$watch('currentCall', function(newVal, oldVal) {
+ if (!$rootScope.currentCall) return;
+
+ var roomMembers = angular.copy($rootScope.events.rooms[$rootScope.currentCall.room_id].members);
+ delete roomMembers[matrixService.config().user_id];
+
+ $rootScope.currentCall.user_id = Object.keys(roomMembers)[0];
+ matrixService.getProfile($rootScope.currentCall.user_id).then(
+ function(response) {
+ $rootScope.currentCall.userProfile = response.data;
+ },
+ function(error) {
+ $scope.feedback = "Can't load user profile";
+ }
+ );
+ });
+
$rootScope.$on(matrixPhoneService.INCOMING_CALL_EVENT, function(ngEvent, call) {
console.trace("incoming call");
call.onError = $scope.onCallError;
@@ -97,12 +114,19 @@ angular.module('MatrixWebClientController', ['matrixService', 'mPresence', 'even
});
$scope.answerCall = function() {
- $scope.currentCall.answer();
+ $rootScope.currentCall.answer();
};
$scope.hangupCall = function() {
- $scope.currentCall.hangup();
- $scope.currentCall = undefined;
+ $rootScope.currentCall.hangup();
+
+ $timeout(function() {
+ var icon = angular.element('#callEndedIcon');
+ $animate.addClass(icon, 'callIconRotate');
+ $timeout(function(){
+ $rootScope.currentCall = undefined;
+ }, 2000);
+ }, 100);
};
$rootScope.onCallError = function(errStr) {
@@ -110,5 +134,12 @@ angular.module('MatrixWebClientController', ['matrixService', 'mPresence', 'even
}
$rootScope.onCallHangup = function() {
+ $timeout(function() {
+ var icon = angular.element('#callEndedIcon');
+ $animate.addClass(icon, 'callIconRotate');
+ $timeout(function(){
+ $rootScope.currentCall = undefined;
+ }, 2000);
+ }, 100);
}
}]);
diff --git a/webclient/app.css b/webclient/app.css
index dbee02f83d..e0ca2f77a8 100755
--- a/webclient/app.css
+++ b/webclient/app.css
@@ -44,7 +44,49 @@ a:active { color: #000; }
}
#callBar {
- float: left;
+ float: left;
+ height: 32px;
+ margin: auto;
+ text-align: right;
+ line-height: 16px;
+}
+
+.callIcon {
+ margin-left: 4px;
+ margin-right: 4px;
+ margin-top: 8px;
+ -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
+ -moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
+ -o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
+ transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
+}
+
+.callIconRotate {
+ -webkit-transform: rotateZ(45deg);
+ -moz-transform: rotateZ(45deg);
+ -ms-transform: rotateZ(45deg);
+ -o-transform: rotateZ(45deg);
+ transform: rotateZ(45deg);
+}
+
+#callPeerImage {
+ width: 32px;
+ height: 32px;
+ border: none;
+ float: left;
+}
+
+#callPeerNameAndState {
+ float: left;
+ margin-left: 4px;
+}
+
+#callState {
+ font-size: 60%;
+}
+
+#callPeerName {
+ font-size: 80%;
}
#headerContent {
diff --git a/webclient/components/matrix/matrix-call.js b/webclient/components/matrix/matrix-call.js
index 3e13e4e81f..3cb5e8b693 100644
--- a/webclient/components/matrix/matrix-call.js
+++ b/webclient/components/matrix/matrix-call.js
@@ -41,6 +41,7 @@ angular.module('MatrixCall', [])
this.room_id = room_id;
this.call_id = "c" + new Date().getTime();
this.state = 'fledgling';
+ this.didConnect = false;
}
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
@@ -52,6 +53,7 @@ angular.module('MatrixCall', [])
matrixPhoneService.callPlaced(this);
navigator.getUserMedia({audio: true, video: false}, function(s) { self.gotUserMediaForInvite(s); }, function(e) { self.getUserMediaFailed(e); });
self.state = 'wait_local_media';
+ this.direction = 'outbound';
};
MatrixCall.prototype.initWithInvite = function(msg) {
@@ -64,6 +66,7 @@ angular.module('MatrixCall', [])
this.peerConn.onaddstream = function(s) { self.onAddStream(s); };
this.peerConn.setRemoteDescription(new RTCSessionDescription(this.msg.offer), self.onSetRemoteDescriptionSuccess, self.onSetRemoteDescriptionError);
this.state = 'ringing';
+ this.direction = 'inbound';
};
MatrixCall.prototype.answer = function() {
@@ -204,10 +207,12 @@ angular.module('MatrixCall', [])
};
MatrixCall.prototype.onIceConnectionStateChanged = function() {
+ if (this.state == 'ended') return; // because ICE can still complete as we're ending the call
console.trace("Ice connection state changed to: "+this.peerConn.iceConnectionState);
// 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.didConnect = true;
$rootScope.$apply();
}
};
diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js
index cc785269a1..b7e03657f0 100644
--- a/webclient/components/matrix/matrix-service.js
+++ b/webclient/components/matrix/matrix-service.js
@@ -312,6 +312,11 @@ angular.module('matrixService', [])
return doRequest("GET", path);
},
+ // get a user's profile
+ getProfile: function(userId) {
+ return this.getProfileInfo(userId);
+ },
+
// get a display name for this user ID
getDisplayName: function(userId) {
return this.getProfileInfo(userId, "displayname");
@@ -345,8 +350,8 @@ angular.module('matrixService', [])
},
getProfileInfo: function(userId, info_segment) {
- var path = "/profile/$user_id/" + info_segment;
- path = path.replace("$user_id", userId);
+ var path = "/profile/"+userId
+ if (info_segment) path += '/' + info_segment;
return doRequest("GET", path);
},
diff --git a/webclient/img/green_phone.png b/webclient/img/green_phone.png
new file mode 100644
index 0000000000..28807c749b
--- /dev/null
+++ b/webclient/img/green_phone.png
Binary files differdiff --git a/webclient/img/red_phone.png b/webclient/img/red_phone.png
new file mode 100644
index 0000000000..11fc44940c
--- /dev/null
+++ b/webclient/img/red_phone.png
Binary files differdiff --git a/webclient/index.html b/webclient/index.html
index 0981373134..baaaa8cef8 100644
--- a/webclient/index.html
+++ b/webclient/index.html
@@ -47,18 +47,29 @@
<div id="header">
<!-- Do not show buttons on the login page -->
<div id="headerContent" ng-hide="'/login' == location || '/register' == location">
- <div id="callBar">
- <div ng-show="currentCall.state == 'ringing'">
- Incoming call from {{ currentCall.user_id }}
- <button ng-click="answerCall()">Answer</button>
- <button ng-click="hangupCall()">Reject</button>
+ <div id="callBar" ng-show="currentCall">
+ <img id="callPeerImage" ng-show="currentCall.userProfile.avatar_url" ngSrc="{{ currentCall.userProfile.avatar_url }}" />
+ <img class="callIcon" src="img/green_phone.png" ng-show="currentCall.state != 'ended'" />
+ <img class="callIcon" id="callEndedIcon" src="img/red_phone.png" ng-show="currentCall.state == 'ended'" />
+ <div id="callPeerNameAndState">
+ <span id="callPeerName">{{ currentCall.userProfile.displayname }}</span>
+ <br />
+ <span id="callState">
+ <span ng-show="currentCall.state == 'invite_sent'">Calling...</span>
+ <span ng-show="currentCall.state == 'connecting'">Call Connecting...</span>
+ <span ng-show="currentCall.state == 'connected'">Call Connected</span>
+ <span ng-show="currentCall.state == 'ended' && !currentCall.didConnect && currentCall.direction == 'outbound'">Call Rejected</span>
+ <span ng-show="currentCall.state == 'ended' && currentCall.didConnect && currentCall.direction == 'outbound'">Call Ended</span>
+ <span ng-show="currentCall.state == 'ended' && !currentCall.didConnect && currentCall.direction == 'inbound'">Call Canceled</span>
+ <span ng-show="currentCall.state == 'ended' && currentCall.didConnect && currentCall.direction == 'inbound'">Call Ended</span>
+ <span ng-show="currentCall.state == 'wait_local_media'">Waiting for media permission...</span>
+ </span>
</div>
+ <span ng-show="currentCall.state == 'ringing'">
+ <button ng-click="answerCall()">Answer</button>
+ <button ng-click="hangupCall()">Reject</button>
+ </span>
<button ng-click="hangupCall()" ng-show="currentCall && currentCall.state != 'ringing' && currentCall.state != 'ended' && currentCall.state != 'fledgling'">Hang up</button>
- <span ng-show="currentCall.state == 'invite_sent'">Calling...</span>
- <span ng-show="currentCall.state == 'connecting'">Call Connecting...</span>
- <span ng-show="currentCall.state == 'connected'">Call Connected</span>
- <span ng-show="currentCall.state == 'ended'">Call Ended</span>
- <span style="display: none; ">{{ currentCall.state }}</span>
</div>
<a href id="headerUserId" ng-click='goToUserPage(user_id)'>{{ user_id }}</a>
|