From e6f2182e49a9cb9f49faff5f7b4278b7c8e28e20 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Mon, 16 Jun 2014 00:04:59 +0200 Subject: [PATCH] Implemented client side sessions request. --- doc/CHANNELING-API.txt | 46 ++++++++++------------ src/app/spreed-webrtc-server/channeling.go | 25 ++++++------ src/app/spreed-webrtc-server/hub.go | 8 ++-- static/js/mediastream/api.js | 13 ++++++ static/js/services/buddylist.js | 4 ++ 5 files changed, 55 insertions(+), 41 deletions(-) diff --git a/doc/CHANNELING-API.txt b/doc/CHANNELING-API.txt index 6cde44fa..edadbd2c 100644 --- a/doc/CHANNELING-API.txt +++ b/doc/CHANNELING-API.txt @@ -389,11 +389,9 @@ Information retrieval { "Type": "Sessions", - "Sessions": { - "Id": "Client generated request ID", - "Token": "Request token", - "Type": "Token type" - } + "Id": "Client generated request ID", + "Token": "Request token", + "TokenType": "Token type" } Valid known token types are: "contact". @@ -403,26 +401,24 @@ Information retrieval { "Type": "Sessions", - "Sessions": { - "Id": "ID as from request", - "Token": "Token as in request", - "Type": "Type as in request", - "Users": [ - { - "Type": "Online", - "Id": "1", - "Ua": "Firefox 27", - "Status": {...} - }, - { - "Type": "Online", - "Id": "3", - "Userid": "u3", - "Ua": "Chrome 28", - "Status": {...} - }, ... - ] - } + "Id": "ID as from request", + "Token": "Token as in request", + "TokenType": "Type as in request", + "Users": [ + { + "Type": "Online", + "Id": "1", + "Ua": "Firefox 27", + "Status": {...} + }, + { + "Type": "Online", + "Id": "3", + "Userid": "u3", + "Ua": "Chrome 28", + "Status": {...} + }, ... + ] } diff --git a/src/app/spreed-webrtc-server/channeling.go b/src/app/spreed-webrtc-server/channeling.go index db3ed4ae..00a19aea 100644 --- a/src/app/spreed-webrtc-server/channeling.go +++ b/src/app/spreed-webrtc-server/channeling.go @@ -65,13 +65,13 @@ type DataTurn struct { } type DataSession struct { - Type string Id string - Userid string `json:"Userid,omitempty"` - Ua string `json:"Ua,omitempty"` - Token string `json:"Token,omitempty"` - Version string `json:"Version,omitempty"` - Rev uint64 `json:"Rev,omitempty"` + Type string `json:",omitempty"` + Userid string `json:",omitempty"` + Ua string `json:",omitempty"` + Token string `json:",omitempty"` + Version string `json:",omitempty"` + Rev uint64 `json:",omitempty"` Status interface{} } @@ -157,12 +157,13 @@ type DataOutgoing struct { } type DataSessions struct { - Type string - Users []*DataSession - Id string `json:",omitempty"` - Token string `json:",omitempty"` - Index uint64 `json:",omitempty"` - Batch uint64 `json:",omitempty"` + Type string + Users []*DataSession + Id string `json:",omitempty"` + Token string `json:",omitempty"` + TokenType string `json:",omitempty"` + Index uint64 `json:",omitempty"` + Batch uint64 `json:",omitempty"` } type DataConference struct { diff --git a/src/app/spreed-webrtc-server/hub.go b/src/app/spreed-webrtc-server/hub.go index 88c8737e..a16ba59f 100644 --- a/src/app/spreed-webrtc-server/hub.go +++ b/src/app/spreed-webrtc-server/hub.go @@ -424,12 +424,12 @@ func (h *Hub) sessionsHandler(c *Connection, sessions *DataSessions) { reply := false - switch sessions.Type { + switch sessions.TokenType { case "contact": contact := &Contact{} - err := h.contacts.Decode("contactConfirmed", sessions.Token, contact) + err := h.contacts.Decode("contactRequest", sessions.Token, contact) if err != nil { - log.Println("Failed to decode incoming contact token", err) + log.Println("Failed to decode incoming contact token", err, sessions.Token) return } // Use the userid which is not ours from the contact data. @@ -454,7 +454,7 @@ func (h *Hub) sessionsHandler(c *Connection, sessions *DataSessions) { sessions.Users = user.SessionsData() reply = true default: - log.Println("Unkown incoming sessions request type", sessions.Type) + log.Println("Unkown incoming sessions request type", sessions.TokenType) } if reply { diff --git a/static/js/mediastream/api.js b/static/js/mediastream/api.js index 7ed60a44..756ac4ac 100644 --- a/static/js/mediastream/api.js +++ b/static/js/mediastream/api.js @@ -321,6 +321,19 @@ define(['jquery', 'underscore'], function($, _) { return this.send("Alive", data); }; + Api.prototype.sendSessions = function(token, type) { + + var data = { + Type: "Sessions", + Id: "some-random-whatever", + Token: token, + TokenType: type + } + + return this.send("Sessions", data); + + }; + return Api; }); diff --git a/static/js/services/buddylist.js b/static/js/services/buddylist.js index ffb81475..6378b778 100644 --- a/static/js/services/buddylist.js +++ b/static/js/services/buddylist.js @@ -664,6 +664,10 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! if (!sessionData) { // TODO(longsleep): Find session with help of contact. console.log("No sessions for this buddy.", session, contact); + if (contact && contact.Token) { + mediaStream.api.sendSessions(contact.Token, "contact"); + } + return; } else { id = sessionData.Id; }