diff --git a/src/app/spreed-webrtc-server/hub.go b/src/app/spreed-webrtc-server/hub.go index e8761fde..5a5691ad 100644 --- a/src/app/spreed-webrtc-server/hub.go +++ b/src/app/spreed-webrtc-server/hub.go @@ -267,6 +267,14 @@ func (h *Hub) EncodeAttestation(session *Session) (string, error) { } +func (h *Hub) DecodeAttestation(token string) (string, error) { + + var id string + err := h.attestations.Decode("attestation", token, &id) + return id, err + +} + func (h *Hub) EncodeSessionToken(st *SessionToken) (string, error) { return h.tickets.Encode(h.tokenName, st) @@ -465,13 +473,27 @@ func (h *Hub) sessionsHandler(c *Connection, srq *DataSessionsRequest, iid strin } // Find foreign user. h.mutex.RLock() - defer h.mutex.RUnlock() user, ok := h.userTable[userid] + h.mutex.RUnlock() if !ok { return } // Add sessions for forein user. users = user.SessionsData() + case "session": + id, err := h.DecodeAttestation(srq.Token) + if err != nil { + log.Println("Failed to decode incoming attestation", err, srq.Token) + return + } + h.mutex.RLock() + session, ok := h.sessionTable[id] + h.mutex.RUnlock() + if !ok { + return + } + users = make([]*DataSession, 1, 1) + users[0] = session.Data() default: log.Println("Unkown incoming sessions request type", srq.Type) } diff --git a/static/js/filters/buddyimagesrc.js b/static/js/filters/buddyimagesrc.js index 852a71c0..a3a9ec3f 100644 --- a/static/js/filters/buddyimagesrc.js +++ b/static/js/filters/buddyimagesrc.js @@ -77,7 +77,7 @@ define(["underscore"], function(_) { return function(id) { - var scope = buddyData.lookup(id); + var scope = buddyData.lookup(id, false, true); if (scope) { var display = scope.display; if (display) { diff --git a/static/js/filters/displayname.js b/static/js/filters/displayname.js index f3695968..a3a7a27f 100644 --- a/static/js/filters/displayname.js +++ b/static/js/filters/displayname.js @@ -33,7 +33,7 @@ define([], function() { if (id === group_chat_id) { return ""; } - var scope = buddyData.lookup(id); + var scope = buddyData.lookup(id, false, true); if (scope) { if (scope.display.displayName) { return scope.display.displayName; diff --git a/static/js/services/buddydata.js b/static/js/services/buddydata.js index 5d9fab1d..afec76bb 100644 --- a/static/js/services/buddydata.js +++ b/static/js/services/buddydata.js @@ -21,12 +21,13 @@ define(['underscore'], function(underscore) { // buddyData - return ["contactData", "mediaStream", function(contactData, mediaStream) { + return ["contactData", "mediaStream", "$rootScope", function(contactData, mediaStream, $rootScope) { var scopes = {}; var brain = {}; var pushed = {}; var attestations = {}; + var fakes = {}; var count = 0; var buddyData = { @@ -40,10 +41,15 @@ define(['underscore'], function(underscore) { push: function(id) { var entry = pushed[id]; if (!entry) { - entry = pushed[id] = { - count: 1, - scope: scopes[id] - }; + var scope = scopes[id]; + if (scope) { + entry = pushed[id] = { + count: 1, + scope: scopes[id] + }; + } else { + return 0; + } } else { entry.count++; } @@ -105,18 +111,48 @@ define(['underscore'], function(underscore) { } } }, - lookup: function(id, onlyactive) { - var scope = null; + lookup: function(id, onlyactive, withfakes) { + if (!id) { + return; + } if (scopes.hasOwnProperty(id)) { - scope = scopes[id]; + return scopes[id]; } else if (!onlyactive) { if (brain.hasOwnProperty(id)) { - scope = brain[id]; + return brain[id]; } else if (pushed.hasOwnProperty(id)) { - scope = pushed[id].scope; + return pushed[id].scope; + } + if (withfakes) { + var fake = fakes[id]; + //console.log("check fake", id, fake); + if (fake) { + //console.log("found fake", fake); + if (fake.display) { + return fake; + } + } else { + if (attestations.hasOwnProperty(id)) { + // Fetch with help of session attestation token. + fake = fakes[id] = {}; + var token = attestations[id].a; + console.log("attestation request", id); + mediaStream.api.sendSessions(token, "session", function(event, type, data) { + console.log("attestation session response", id, type, data); + if (data.Users && data.Users.length > 0) { + var s = data.Users[0]; + fake.display = { + displayName: s.Status.displayName + } + // TODO(longsleep): Find a better way to apply this than digest on root scope. + $rootScope.$digest(); + } + }); + } + } } } - return scope; + return null; }, del: function(id, hard) { var scope = scopes[id]; @@ -158,7 +194,7 @@ define(['underscore'], function(underscore) { } } if (create) { - //console.log("Created attestation entry", from); + console.log("Created attestation entry", from); attestations[from] = { a: attestation, t: (new Date().getTime())