remove redundancy
This commit is contained in:
parent
221431d6cb
commit
8272232d0c
28
lib/wsapp.js
28
lib/wsapp.js
|
@ -18,37 +18,31 @@ var subscriptions = {};
|
|||
|
||||
var WsApp = function() {};
|
||||
|
||||
WsApp._unauthorized = function() {
|
||||
socket.emit('unauthorized');
|
||||
socket.disconnect();
|
||||
};
|
||||
|
||||
WsApp.start = function(server) {
|
||||
var self = this;
|
||||
|
||||
var io = require('socket.io')(server);
|
||||
|
||||
WalletService.onNotification(function(serviceInstance, args) {
|
||||
var walletId = serviceInstance.walletId;
|
||||
var copayerId = serviceInstance.copayerId;
|
||||
|
||||
io.to(walletId).emit('notification', args);
|
||||
io.to(serviceInstance.walletId).emit('notification', args);
|
||||
});
|
||||
|
||||
|
||||
io.on('connection', function(socket) {
|
||||
socket.nonce = Uuid.v4();
|
||||
socket.emit('challenge', socket.nonce);
|
||||
|
||||
socket.on('authorize', function(data) {
|
||||
if (data.message != socket.nonce) {
|
||||
socket.emit('unauthorized');
|
||||
socket.disconnect();
|
||||
return;
|
||||
}
|
||||
if (data.message != socket.nonce) return WsApp.unauthorized();
|
||||
|
||||
WalletService.getInstanceWithAuth(data, function(err, res) {
|
||||
var room = res.walletId;
|
||||
if (err) {
|
||||
socket.emit('unauthorized');
|
||||
socket.disconnect();
|
||||
return;
|
||||
}
|
||||
socket.join(room);
|
||||
if (err) return WsApp.unauthorized();
|
||||
|
||||
socket.join(res.walletId);
|
||||
socket.emit('authorized');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue