mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-06 12:11:02 +01:00
Updated the Socket client service, with a connect() method. Moved state redirect out of from Socket service. Added the Authentication.user check to the Chat client controller, and added a check to make sure the Socket client service is connected to the server; if not, then connect using the new connect() method. Had to do a hard reset from 0.4.0 due to conflicts when merging and pushing to remote.
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
// Create the Socket.io wrapper service
|
|
angular.module('core').service('Socket', ['Authentication', '$state', '$timeout',
|
|
function(Authentication, $state, $timeout) {
|
|
|
|
// Connect to Socket.io server
|
|
this.connect = function () {
|
|
// Connect only when authenticated
|
|
if (Authentication.user) {
|
|
this.socket = io();
|
|
}
|
|
};
|
|
this.connect();
|
|
|
|
// Wrap the Socket.io 'on' method
|
|
this.on = function(eventName, callback) {
|
|
if (this.socket) {
|
|
this.socket.on(eventName, function(data) {
|
|
$timeout(function() {
|
|
callback(data);
|
|
});
|
|
});
|
|
}
|
|
};
|
|
|
|
// Wrap the Socket.io 'emit' method
|
|
this.emit = function(eventName, data) {
|
|
if (this.socket) {
|
|
this.socket.emit(eventName, data);
|
|
}
|
|
};
|
|
|
|
// Wrap the Socket.io 'removeListener' method
|
|
this.removeListener = function(eventName) {
|
|
if (this.socket) {
|
|
this.socket.removeListener(eventName);
|
|
}
|
|
};
|
|
}
|
|
]);
|