Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 1.15 KB | None | 0 0
  1. redis.subscribe('new-message', function (err, count) {});
  2. redis.subscribe('new-chat', function (err, count) {});
  3. redis.subscribe('update-chats', function (err, count) {});
  4. redis.subscribe('message-read', function (err, count) {});
  5. redis.subscribe('typing-chat', function (err, count) {});
  6. redis.subscribe('update-user', function (err, count) {});
  7.  
  8. io.sockets.on('connection', function (socket) {
  9.     socket.on('join', function (room) {
  10.         socket.join(room);
  11.  
  12.         socket.on('typing', async function (data) {
  13.             data['auth_id'] = room;
  14.             console.log(`ENV: ${process.env.NODE_ENV}. User_id: ${room}. Base url: ${api_url}`);
  15.             const res = await request('typing', data);
  16.         });
  17.  
  18.         socket.on('read-message', async (data) => {
  19.             data['auth_id'] = room;
  20.             await request('read_message', data);
  21.         });
  22.     });
  23. });
  24.  
  25. redis.on('message', function (eventName, msgData) {
  26.     console.log(`Event: ${eventName}`);
  27.     const msg = JSON.parse(msgData);
  28.     const channel_id = msg.data.channel_id;
  29.     io.sockets.to(channel_id).emit(eventName, msg.data);
  30. }, err => {
  31.     console.log(err);
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement