Advertisement
Guest User

sockets.js

a guest
Jan 18th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var config = require('../config.js');
  2. var users  = require('./users.js');
  3. var Socket = {
  4.     init: function() {
  5.         Socket.io = require('socket.io').listen(config.port);
  6.     },
  7.     on: function(socket, rsa, header, callback) {
  8.         socket.on(header, function(d) {
  9.             var data = JSON.parse(rsa.Decrypt(d));
  10.             callback(data);
  11.         });
  12.     },
  13.     onN: function(socket, rsa, header, callback) {
  14.         var uid = users.getIdBySocketID(socket.id);
  15.         if(uid == false) Socket.on(socket, rsa, header, callback);
  16.     },
  17.     onL: function(socket, rsa, header, callback) {
  18.         var uid = users.getIdBySocketID(socket.id);
  19.         if(uid != false) Socket.on(socket, rsa, header, callback);
  20.     },
  21.     emitClient: function(clientId, header, data) {
  22.         Socket.io.to(clientId).emit(header, data);
  23.     },
  24.     emitAll: function(header, data) {
  25.         Socket.io.sockets.emit(header, data);
  26.     },
  27.     kik: function(socketID) {
  28.         Socket.io.sockets.connected[socketID].disconnect();
  29.         var uid = users.getIdBySocketID(socketID);
  30.         if(uid != false) users.Remove(uid);
  31.     }
  32. }
  33. Socket.init();
  34. module.exports = Socket;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement