Browse Source

Delay hellow until authorization is finished.

pull/108/head
Simon Eisenmann 11 years ago
parent
commit
436697c857
  1. 9
      static/js/controllers/mediastreamcontroller.js
  2. 21
      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 @@ -431,8 +431,17 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte
}, 0);
}
// Propagate authentication event.
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) {

21
static/js/mediastream/connector.js

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

30
static/js/services/mediastream.js

@ -45,6 +45,7 @@ define([ @@ -45,6 +45,7 @@ define([
// 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 authorizing = false;
var mediaStream = {
version: version,
@ -134,7 +135,12 @@ define([ @@ -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) {
mediaStream.users.authorizing(true);
var url = mediaStream.url.api("sessions") + "/" + mediaStream.api.id + "/";
var login = _.clone(data);
login.id = mediaStream.api.id;
@ -151,12 +157,14 @@ define([ @@ -151,12 +157,14 @@ define([
if (data.nonce !== "" && data.success) {
success_cb(data, status);
} else {
mediaStream.users.authorizing(false);
if (error_cb) {
error_cb(data, status);
}
}
}).
error(function(data, status) {
mediaStream.users.authorizing(false);
if (error_cb) {
error_cb(data, status)
}
@ -225,6 +233,17 @@ define([ @@ -225,6 +233,17 @@ define([
});
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) {
var cont = false;
@ -280,16 +299,17 @@ define([ @@ -280,16 +299,17 @@ define([
room = "";
}
console.info("Selected room is:", [room], ready, cont);
$rootScope.roomid = room;
if (!ready || !cont) {
ready = true;
connector.roomid = room;
connect();
} 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) {
title.element.text(room + " - " + title.text);
} else {
@ -303,6 +323,7 @@ define([ @@ -303,6 +323,7 @@ define([
var roomCache = null;
var roomCache2 = null;
$rootScope.$on("roomStatus", function(event, status) {
// roomStatus is triggered by the buddylist when received.users.
roomStatusCache = status ? true : false;
roomCache = status ? $rootScope.roomid : null;
$timeout(function() {
@ -310,6 +331,7 @@ define([ @@ -310,6 +331,7 @@ define([
$rootScope.roomstatus = roomStatusCache;
}
if (roomCache !== roomCache2) {
// Let every one know about the new room.
$rootScope.$broadcast("room", roomCache);
roomCache2 = roomCache;
}

Loading…
Cancel
Save