Browse Source

Delay hellow until authorization is finished.

pull/108/head
Simon Eisenmann 12 years ago
parent
commit
436697c857
  1. 9
      static/js/controllers/mediastreamcontroller.js
  2. 23
      static/js/mediastream/connector.js
  3. 30
      static/js/services/mediastream.js

9
static/js/controllers/mediastreamcontroller.js

@ -431,8 +431,17 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte
}, 0); }, 0);
} }
// Propagate authentication event.
appData.e.triggerHandler("selfReceived", [data]); appData.e.triggerHandler("selfReceived", [data]);
// Unmark authorization process.
if (data.Userid) {
mediaStream.users.authorizing(false);
}
// Always apply room after self received to avoid double stuff.
mediaStream.applyRoom();
}); });
mediaStream.webrtc.e.on("peercall", function(event, peercall) { mediaStream.webrtc.e.on("peercall", function(event, peercall) {

23
static/js/mediastream/connector.js

@ -29,10 +29,9 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
this.e = $({}); this.e = $({});
this.error = false; this.error = false;
this.connected = false; this.connected = false;
this.disabled = false;
this.isopen = false;
this.connecting = null; this.connecting = null;
this.connecting_timeout = timeout; this.connecting_timeout = timeout;
this.disabled = false;
this.token = null; this.token = null;
this.queue = []; this.queue = [];
@ -100,7 +99,7 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
Connector.prototype.close = function() { Connector.prototype.close = function() {
this.connected = this.isopen = false; this.connected = false;
if (this.conn) { if (this.conn) {
var conn = this.conn; var conn = this.conn;
this.conn = null; this.conn = null;
@ -121,7 +120,7 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
}; };
Connector.prototype.room = function(roomid, cb) { Connector.prototype.room = function(roomid) {
var was_connected = this.connected; var was_connected = this.connected;
@ -145,10 +144,7 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
Id: roomid Id: roomid
} }
}, true); }, true);
this.e.triggerHandler("helloed", [roomid]);
if (cb) {
cb();
}
if (was_connected) { if (was_connected) {
this.e.triggerHandler("open", [{ this.e.triggerHandler("open", [{
@ -162,15 +158,10 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
window.clearTimeout(this.connecting); window.clearTimeout(this.connecting);
this.connecting_timeout = timeout; this.connecting_timeout = timeout;
this.isopen = true;
//console.log("onopen", event); // Connection successfully established.
console.info("Connector on connection open."); console.info("Connector on connection open.");
this.room(this.roomid, _.bind(function() { this.connected = true;
this.connected = true;
//console.log("Connector sent hello to room:", this.roomid);
this.e.triggerHandler("helloed");
}, this));
this.e.triggerHandler("open", [null, event]); this.e.triggerHandler("open", [null, event]);
// Send out stuff which was previously queued. // Send out stuff which was previously queued.
@ -180,6 +171,8 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
this.send(data); this.send(data);
} }
this.e.triggerHandler("opened");
}; };
Connector.prototype.onerror = function(event) { Connector.prototype.onerror = function(event) {

30
static/js/services/mediastream.js

@ -45,6 +45,7 @@ define([
// Create encryption key from server token and browser name. // Create encryption key from server token and browser name.
var secureKey = sjcl.codec.base64.fromBits(sjcl.hash.sha256.hash(context.Cfg.Token + uaparser().browser.name)); var secureKey = sjcl.codec.base64.fromBits(sjcl.hash.sha256.hash(context.Cfg.Token + uaparser().browser.name));
var authorizing = false;
var mediaStream = { var mediaStream = {
version: version, version: version,
@ -134,7 +135,12 @@ define([
}); });
} }
}, },
authorizing: function(value) {
// Boolean flag to indicate that an authentication is currently in progress.
authorizing = !!value;
},
authorize: function(data, success_cb, error_cb) { authorize: function(data, success_cb, error_cb) {
mediaStream.users.authorizing(true);
var url = mediaStream.url.api("sessions") + "/" + mediaStream.api.id + "/"; var url = mediaStream.url.api("sessions") + "/" + mediaStream.api.id + "/";
var login = _.clone(data); var login = _.clone(data);
login.id = mediaStream.api.id; login.id = mediaStream.api.id;
@ -151,12 +157,14 @@ define([
if (data.nonce !== "" && data.success) { if (data.nonce !== "" && data.success) {
success_cb(data, status); success_cb(data, status);
} else { } else {
mediaStream.users.authorizing(false);
if (error_cb) { if (error_cb) {
error_cb(data, status); error_cb(data, status);
} }
} }
}). }).
error(function(data, status) { error(function(data, status) {
mediaStream.users.authorizing(false);
if (error_cb) { if (error_cb) {
error_cb(data, status) error_cb(data, status)
} }
@ -225,6 +233,17 @@ define([
}); });
return id; return id;
}, },
applyRoom: function() {
if (authorizing) {
// Do nothing while authorizing.
return;
}
var roomid = $rootScope.roomid;
if (roomid !== connector.roomid) {
console.log("Apply room", roomid);
connector.room(roomid);
}
},
initialize: function($rootScope, translation) { initialize: function($rootScope, translation) {
var cont = false; var cont = false;
@ -280,16 +299,17 @@ define([
room = ""; room = "";
} }
console.info("Selected room is:", [room], ready, cont); console.info("Selected room is:", [room], ready, cont);
$rootScope.roomid = room;
if (!ready || !cont) { if (!ready || !cont) {
ready = true; ready = true;
connector.roomid = room;
connect(); connect();
} else { } else {
connector.room(room); // Auto apply room when already connected.
mediaStream.applyRoom();
} }
$rootScope.roomid = room;
$rootScope.roomlink = room ? mediaStream.url.room(room) : null;
$rootScope.roomlink = room ? mediaStream.url.room(room) : null;
if ($rootScope.roomlink) { if ($rootScope.roomlink) {
title.element.text(room + " - " + title.text); title.element.text(room + " - " + title.text);
} else { } else {
@ -303,6 +323,7 @@ define([
var roomCache = null; var roomCache = null;
var roomCache2 = null; var roomCache2 = null;
$rootScope.$on("roomStatus", function(event, status) { $rootScope.$on("roomStatus", function(event, status) {
// roomStatus is triggered by the buddylist when received.users.
roomStatusCache = status ? true : false; roomStatusCache = status ? true : false;
roomCache = status ? $rootScope.roomid : null; roomCache = status ? $rootScope.roomid : null;
$timeout(function() { $timeout(function() {
@ -310,6 +331,7 @@ define([
$rootScope.roomstatus = roomStatusCache; $rootScope.roomstatus = roomStatusCache;
} }
if (roomCache !== roomCache2) { if (roomCache !== roomCache2) {
// Let every one know about the new room.
$rootScope.$broadcast("room", roomCache); $rootScope.$broadcast("room", roomCache);
roomCache2 = roomCache; roomCache2 = roomCache;
} }

Loading…
Cancel
Save