Browse Source

Trigger events through service instead of "appData".

pull/225/head
Joachim Bauch 11 years ago
parent
commit
6591cdfae1
  1. 4
      static/js/controllers/uicontroller.js
  2. 4
      static/js/directives/buddylist.js
  3. 6
      static/js/directives/chat.js
  4. 22
      static/js/services/endtoendencryption.js

4
static/js/controllers/uicontroller.js

@ -22,7 +22,7 @@
"use strict"; "use strict";
define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapter'], function($, _, BigScreen, moment, sjcl, Modernizr) { define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapter'], function($, _, BigScreen, moment, sjcl, Modernizr) {
return ["$scope", "$rootScope", "$element", "$window", "$timeout", "safeDisplayName", "safeApply", "mediaStream", "appData", "playSound", "desktopNotify", "alertify", "toastr", "translation", "fileDownload", "localStorage", "screensharing", "localStatus", "dialogs", "rooms", "constraints", function($scope, $rootScope, $element, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload, localStorage, screensharing, localStatus, dialogs, rooms, constraints) { return ["$scope", "$rootScope", "$element", "$window", "$timeout", "safeDisplayName", "safeApply", "mediaStream", "appData", "playSound", "desktopNotify", "alertify", "toastr", "translation", "fileDownload", "localStorage", "screensharing", "localStatus", "dialogs", "rooms", "constraints", "endToEndEncryption", function($scope, $rootScope, $element, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload, localStorage, screensharing, localStatus, dialogs, rooms, constraints, endToEndEncryption) {
alertify.dialog.registerCustom({ alertify.dialog.registerCustom({
baseType: 'notify', baseType: 'notify',
@ -537,7 +537,7 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web
} }
}); });
appData.e.on("identity.own", function(event, identity) { endToEndEncryption.events.on("identity.own", function(event, identity) {
if (identity) { if (identity) {
$scope.fingerprint = identity.getFingerprint(); $scope.fingerprint = identity.getFingerprint();
} else { } else {

4
static/js/directives/buddylist.js

@ -23,7 +23,7 @@
define(['underscore', 'text!partials/buddylist.html'], function(_, template) { define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
// buddyList // buddyList
return ["buddyList", "api", "webrtc", "contacts", "appData", function(buddyList, api, webrtc, contacts, appData) { return ["buddyList", "api", "webrtc", "contacts", "endToEndEncryption", function(buddyList, api, webrtc, contacts, endToEndEncryption) {
//console.log("buddyList directive"); //console.log("buddyList directive");
@ -125,7 +125,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
onContactUpdated(data); onContactUpdated(data);
}); });
appData.e.on("identity.received", function(event, peer, identity) { endToEndEncryption.events.on("identity.received", function(event, peer, identity) {
buddylist.onIdentityReceived(peer, identity); buddylist.onIdentityReceived(peer, identity);
}); });
}]; }];

6
static/js/directives/chat.js

@ -22,7 +22,7 @@
"use strict"; "use strict";
define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], function($, _, templateChat, templateChatroom) { define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], function($, _, templateChat, templateChatroom) {
return ["$compile", "safeDisplayName", "mediaStream", "safeApply", "alertify", "desktopNotify", "translation", "playSound", "fileUpload", "randomGen", "buddyData", "appData", "$timeout", "geolocation", function($compile, safeDisplayName, mediaStream, safeApply, alertify, desktopNotify, translation, playSound, fileUpload, randomGen, buddyData, appData, $timeout, geolocation) { return ["$compile", "safeDisplayName", "mediaStream", "safeApply", "alertify", "desktopNotify", "translation", "playSound", "fileUpload", "randomGen", "buddyData", "appData", "$timeout", "geolocation", "endToEndEncryption", function($compile, safeDisplayName, mediaStream, safeApply, alertify, desktopNotify, translation, playSound, fileUpload, randomGen, buddyData, appData, $timeout, geolocation, endToEndEncryption) {
var displayName = safeDisplayName; var displayName = safeDisplayName;
var groupChatId = ""; var groupChatId = "";
@ -130,7 +130,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
} }
}); });
appData.e.on("identity.request", function(event, peer) { endToEndEncryption.events.on("identity.request", function(event, peer) {
var room = rooms[peer]; var room = rooms[peer];
if (room) { if (room) {
room.$apply(function(scope) { room.$apply(function(scope) {
@ -138,7 +138,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
}); });
} }
}); });
appData.e.on("identity.received", function(event, peer, identity) { endToEndEncryption.events.on("identity.received", function(event, peer, identity) {
var room = rooms[peer]; var room = rooms[peer];
if (room) { if (room) {
room.$apply(function(scope) { room.$apply(function(scope) {

22
static/js/services/endtoendencryption.js

@ -36,11 +36,9 @@ define([
return [ return [
"$window", "$window",
"$q", "$q",
"appData",
function( function(
$window, $window,
$q, $q
appData
) { ) {
// Bitflags for the different components that need to be ready for // Bitflags for the different components that need to be ready for
@ -251,8 +249,11 @@ define([
return fingerprint.substr(2); return fingerprint.substr(2);
}; };
var EndToEndEncryption = function(api) { var EndToEndEncryption = function(api, events) {
// Private events.
this.e = $({}); this.e = $({});
// Public events.
this.events = events;
this.api = api; this.api = api;
// TODO(fancycode): Look into using IndexedDB as storage backend. // TODO(fancycode): Look into using IndexedDB as storage backend.
if (modernizr.localstorage) { if (modernizr.localstorage) {
@ -315,7 +316,7 @@ define([
EndToEndEncryption.prototype.setOwnIdentity = function(public_key) { EndToEndEncryption.prototype.setOwnIdentity = function(public_key) {
var identity = new PeerIdentity(null, public_key); var identity = new PeerIdentity(null, public_key);
this.own_identity = identity; this.own_identity = identity;
appData.e.triggerHandler("identity.own", [identity]); this.events.triggerHandler("identity.own", [identity]);
}; };
EndToEndEncryption.prototype.storePeerIdentity = function(peer, public_key) { EndToEndEncryption.prototype.storePeerIdentity = function(peer, public_key) {
@ -329,7 +330,7 @@ define([
} else { } else {
// Uh oh, remote peer has a new identity, this is something // Uh oh, remote peer has a new identity, this is something
// the user should know about! // the user should know about!
appData.e.triggerHandler("identity.changed", [ this.events.triggerHandler("identity.changed", [
peer, peer,
existing, existing,
identity identity
@ -337,7 +338,7 @@ define([
} }
} }
this.peer_identities[peer] = identity; this.peer_identities[peer] = identity;
appData.e.triggerHandler("identity.received", [peer, identity]); this.events.triggerHandler("identity.received", [peer, identity]);
}; };
EndToEndEncryption.prototype.getReadyPromise = function() { EndToEndEncryption.prototype.getReadyPromise = function() {
@ -613,7 +614,7 @@ define([
"message": message, "message": message,
"callback": callback "callback": callback
}); });
appData.e.triggerHandler("identity.request", [peer]); this.events.triggerHandler("identity.request", [peer]);
this.apiSend("EncryptionRequestKeyBundle", {"To": peer}); this.apiSend("EncryptionRequestKeyBundle", {"To": peer});
return; return;
} }
@ -685,13 +686,16 @@ define([
var endToEndEncryption; var endToEndEncryption;
var events = $({});
// Only export limited public encryption API. // Only export limited public encryption API.
var endToEndEncryptionApi = { var endToEndEncryptionApi = {
"events": events,
"initialize": function(api) { "initialize": function(api) {
if (endToEndEncryption) { if (endToEndEncryption) {
return endToEndEncryption; return endToEndEncryption;
} }
endToEndEncryption = new EndToEndEncryption(api); endToEndEncryption = new EndToEndEncryption(api, events);
if (!endToEndEncryption.isSupported()) { if (!endToEndEncryption.isSupported()) {
console.warn("EndToEnd encryption services not supported"); console.warn("EndToEnd encryption services not supported");
endToEndEncryption = null; endToEndEncryption = null;

Loading…
Cancel
Save