Browse Source

Implemented fake data lookup using attestation token.

pull/51/head
Simon Eisenmann 11 years ago
parent
commit
27a08dc006
  1. 24
      src/app/spreed-webrtc-server/hub.go
  2. 2
      static/js/filters/buddyimagesrc.js
  3. 2
      static/js/filters/displayname.js
  4. 60
      static/js/services/buddydata.js

24
src/app/spreed-webrtc-server/hub.go

@ -267,6 +267,14 @@ func (h *Hub) EncodeAttestation(session *Session) (string, error) { @@ -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 @@ -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)
}

2
static/js/filters/buddyimagesrc.js

@ -77,7 +77,7 @@ define(["underscore"], function(_) { @@ -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) {

2
static/js/filters/displayname.js

@ -33,7 +33,7 @@ define([], function() { @@ -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;

60
static/js/services/buddydata.js

@ -21,12 +21,13 @@ @@ -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) { @@ -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) { @@ -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) { @@ -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())

Loading…
Cancel
Save