Merge pull request #1258 from cmgustavo/feature/01-remove-peerjs

Feature: remove peerjs
This commit is contained in:
Esteban Ordano 2014-09-02 18:23:36 -03:00
commit a0c7d2cb66
19 changed files with 47 additions and 2960 deletions

View file

@ -26,4 +26,15 @@ angular.module('copayApp.controllers').controller('CopayersController',
});
};
// Cached list of copayers
$scope.copayers = $rootScope.wallet.getRegisteredPeerIds();
$scope.copayersList = function() {
return $rootScope.wallet.getRegisteredPeerIds();
}
$scope.isBackupReady = function(copayer) {
return $rootScope.wallet.publicKeyRing.isBackupReady(copayer.copayerId);
}
});

View file

@ -37,7 +37,6 @@ angular.module('copayApp.controllers').controller('CreateController',
controllerUtils.redirIfLogged();
$rootScope.fromSetup = true;
$rootScope.videoInfo = {};
$scope.loading = false;
$scope.walletPassword = $rootScope.walletPassword;
$scope.isMobile = !!window.cordova;

View file

@ -8,7 +8,6 @@ angular.module('copayApp.controllers').controller('SettingsController', function
$scope.insightHost = config.blockchain.host;
$scope.insightPort = config.blockchain.port;
$scope.insightSecure = config.blockchain.schema === 'https';
$scope.disableVideo = typeof config.disableVideo === undefined ? true : config.disableVideo;
$scope.forceNetwork = config.forceNetwork;
$scope.unitOpts = [{
@ -85,7 +84,6 @@ angular.module('copayApp.controllers').controller('SettingsController', function
schema: $scope.insightSecure ? 'https' : 'http',
},
network: network,
disableVideo: $scope.disableVideo,
unitName: $scope.selectedUnit.shortName,
unitToSatoshi: $scope.selectedUnit.value,
unitDecimals: $scope.selectedUnit.decimals,

View file

@ -1,46 +0,0 @@
'use strict';
angular.module('copayApp.controllers').controller('VideoController',
function($scope, $rootScope, $sce) {
$rootScope.videoInfo = {};
// Cached list of copayers
$scope.copayers = $rootScope.wallet.getRegisteredPeerIds();
$scope.copayersList = function() {
return $rootScope.wallet.getRegisteredPeerIds();
}
$scope.hasVideo = function(copayer) {
return $rootScope.videoInfo[copayer.peerId];
}
$scope.isConnected = function(copayer) {
return $rootScope.wallet.getOnlinePeerIDs().indexOf(copayer.peerId) != -1;
}
$scope.isBackupReady = function(copayer) {
return $rootScope.wallet.publicKeyRing.isBackupReady(copayer.copayerId);
}
$scope.getVideoURL = function(copayer) {
if (config.disableVideo) return;
var vi = $scope.videoInfo[copayer.peerId];
if (!vi) return;
if ($scope.isConnected(copayer)) {
// peer disconnected, remove his video
delete $rootScope.videoInfo[copayer.peerId];
return;
}
var encoded = vi.url;
var url = decodeURI(encoded);
var trusted = $sce.trustAsResourceUrl(url);
return trusted;
};
});

View file

@ -109,20 +109,6 @@ angular.module('copayApp.directives')
}
}
})
.directive('avatar', function($rootScope, controllerUtils) {
return {
link: function(scope, element, attrs) {
var peer = JSON.parse(attrs.peer)
var peerId = peer.peerId;
var nick = peer.nick;
element.addClass('video-small');
var muted = controllerUtils.getVideoMutedStatus(peerId);
if (true || muted) { // mute everyone for now
element.attr("muted", true);
}
}
}
})
.directive('contact', function() {
return {
restrict: 'E',

View file

@ -455,28 +455,12 @@ Wallet.prototype.netStart = function(callback) {
self.emit('ready', net.getPeer());
setTimeout(function() {
self.emit('publicKeyRingUpdated', true);
//self.scheduleConnect();
// no connection logic for now
self.emit('txProposalsUpdated');
}, 10);
});
};
// not being used now
Wallet.prototype.scheduleConnect = function() {
var self = this;
if (self.network.isOnline()) {
self.connectToAll();
self.currentDelay = self.currentDelay * 2 || self.reconnectDelay;
setTimeout(self.scheduleConnect.bind(self), self.currentDelay);
}
}
Wallet.prototype.getOnlinePeerIDs = function() {
return this.network.getOnlinePeerIDs();
};
Wallet.prototype.getRegisteredCopayerIds = function() {
var l = this.publicKeyRing.registeredCopayers();
var copayers = [];

View file

@ -2,17 +2,8 @@
var bitcore = require('bitcore');
angular.module('copayApp.services')
.factory('controllerUtils', function($rootScope, $sce, $location, notification, $timeout, video, uriHandler, rateService) {
.factory('controllerUtils', function($rootScope, $sce, $location, notification, $timeout, uriHandler, rateService) {
var root = {};
root.getVideoMutedStatus = function(copayer) {
if (!$rootScope.videoInfo) return;
var vi = $rootScope.videoInfo[copayer]
if (!vi) {
return;
}
return vi.muted;
};
root.redirIfLogged = function() {
if ($rootScope.wallet) {
@ -27,7 +18,6 @@ angular.module('copayApp.services')
$rootScope.wallet = null;
delete $rootScope['wallet'];
video.close();
// Clear rootScope
for (var i in $rootScope) {
if (i.charAt(0) != '$') {
@ -102,18 +92,6 @@ angular.module('copayApp.services')
root.installStartupHandlers(w, $scope);
root.updateGlobalAddresses();
var handlePeerVideo = function(err, peerID, url) {
if (err) {
delete $rootScope.videoInfo[peerID];
return;
}
$rootScope.videoInfo[peerID] = {
url: encodeURI(url),
muted: peerID === w.network.peerId
};
$rootScope.$digest();
};
notification.enableHtml5Mode(); // for chrome: if support, enable it
w.on('corrupt', function(peerId) {
@ -128,8 +106,6 @@ angular.module('copayApp.services')
} else {
$location.path('receive');
}
if (!config.disableVideo)
video.setOwnPeer(myPeerID, w, handlePeerVideo);
});
w.on('publicKeyRingUpdated', function(dontDigest) {
@ -172,9 +148,6 @@ angular.module('copayApp.services')
root.onErrorDigest(null, msg);
});
w.on('connect', function(peerID) {
if (peerID && !config.disableVideo) {
video.callPeer(peerID, handlePeerVideo);
}
$rootScope.$digest();
});
w.on('close', root.onErrorDigest);

View file

@ -1,92 +0,0 @@
'use strict';
var Video = function() {
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
this.mediaConnections = {};
this.localStream = null;
};
Video.prototype.setOwnPeer = function(peer, wallet, cb) {
var self = this;
var VWIDTH = 320;
var VHEIGHT = 320;
var constraints = {
audio: true,
video: {
mandatory: {
maxWidth: VWIDTH,
maxHeight: VHEIGHT,
}
}
};
navigator.getUserMedia(constraints, function(stream) {
// This is called when user accepts using webcam
self.localStream = stream;
var online = wallet.getOnlinePeerIDs();
for (var i = 0; i < online.length; i++) {
var o = online[i];
if (o !== peer.id) {
self.callPeer(o, cb);
}
}
cb(null, peer.id, URL.createObjectURL(stream));
}, function() {
cb(new Error('Failed to access the webcam and microphone.'));
});
// Receiving a call
peer.on('call', function(mediaConnection) {
if (self.localStream) {
mediaConnection.answer(self.localStream);
} else {
mediaConnection.answer();
}
self._addCall(mediaConnection, cb);
});
this.peer = peer;
};
Video.prototype.callPeer = function(peerID, cb) {
if (this.localStream) {
var mediaConnection = this.peer.call(peerID, this.localStream);
this._addCall(mediaConnection, cb);
}
};
Video.prototype._addCall = function(mediaConnection, cb) {
var self = this;
var peerID = mediaConnection.peer;
// Wait for stream on the call, then set peer video display
mediaConnection.on('stream', function(stream) {
cb(null, peerID, URL.createObjectURL(stream));
});
mediaConnection.on('close', function() {
cb(true, peerID, null); // ask to stop video streaming in UI
});
mediaConnection.on('error', function(e) {
cb(e, peerID, null);
});
this.mediaConnections[peerID] = mediaConnection;
}
Video.prototype.close = function() {
if (this.localStream) {
this.localStream.stop();
this.localStream.mozSrcObject = null;
this.localStream.src = "";
this.localStream.src = null;
this.localStream = null;
}
for (var i = 0; this.mediaConnections.length; i++) {
this.mediaConnections[i].close();
}
this.mediaConnections = {};
};
angular.module('copayApp.services').value('video', new Video());