a b/backend/ws/mobile.js
1
'use strict';
2
3
// var CONSTANTS = require('../lib/constants');
4
var initialized = false;
5
var NAMESPACE = '/mobileApp';
6
var mobileNamespace;
7
8
function init(dependencies) {
9
  var logger = dependencies('logger');
10
  var pubsub = dependencies('pubsub').global;
11
  var io = dependencies('wsserver').io;
12
13
  //console.log (io);
14
15
  if (initialized) {
16
    logger.warn('The contact notification service is already initialized');
17
    return;
18
  }
19
20
  mobileNamespace = io.of(NAMESPACE);
21
  
22
  //console.log ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
23
  //console.log (mobileNamespace);
24
25
  mobileNamespace.on('connection', function(socket) {
26
    logger.info('New connection on ' + NAMESPACE);
27
28
    setInterval(function(){
29
     socket.emit('notification', { hello: 'world' });
30
   },2000);
31
32
      /*
33
      setTimeout(function(){
34
          console.log(io);
35
      },5000);
36
      */
37
38
    socket.on('messages', function (data) {
39
        console.log(data);
40
    });
41
42
    // socket.on('subscribe', function(bookId) {
43
    //   logger.info('Joining contact room', bookId);
44
    //   socket.join(bookId);
45
    // });
46
47
    // socket.on('unsubscribe', function(bookId) {
48
    //   logger.info('Leaving contact room', bookId);
49
    //   socket.leave(bookId);
50
    // });
51
  });
52
53
  initialized = true;
54
}
55
56
module.exports.init = init;