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 @@ @@ -22,7 +22,7 @@
"use strict";
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({
baseType: 'notify',
@ -537,7 +537,7 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web @@ -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) {
$scope.fingerprint = identity.getFingerprint();
} else {

4
static/js/directives/buddylist.js

@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
// 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");
@ -125,7 +125,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { @@ -125,7 +125,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
onContactUpdated(data);
});
appData.e.on("identity.received", function(event, peer, identity) {
endToEndEncryption.events.on("identity.received", function(event, peer, identity) {
buddylist.onIdentityReceived(peer, identity);
});
}];

6
static/js/directives/chat.js

@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
"use strict";
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 groupChatId = "";
@ -130,7 +130,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro @@ -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];
if (room) {
room.$apply(function(scope) {
@ -138,7 +138,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro @@ -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];
if (room) {
room.$apply(function(scope) {

22
static/js/services/endtoendencryption.js

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

Loading…
Cancel
Save