Custom socket emit through plugins not sending the attached data object. [resolved]



  • I am trying to emit a custom socket event through my plugin which is successfully sending out the event but not the attached data. Which was working prior to upgrade to nodebb version 0.5.2

    Here is my socket emit event,

    socket.emit('plugins.Vote.topicVoteup', data_tid, function(err, data) {
    if (err) {
    	return app.alertError(err.message);
    }
    });
    

    where data_tid is ,

    var data_tid = {
      tid: postContainer.attr('data-tid')
     } 
    

    And my client socket handler is using plugin custom socket as mentioned by @julian in this thread.

    SocketPlugins.Vote.topicVoteup = function(data) {
    console.log(data); 
    var topic_id = "topic:"+data.tid;
    db.incrObjectFieldBy(topic_id, 'vote', 1, function(err, value){
      if(err){
        console.log('error increasing vote count');
      }
    });
    };
    

    And the console log of "data" object i am getting on my terminal is

    { id: 'ya_pkpH-uo1EohvP8xay',
    namespace:
    { manager:
    { server: [Object],
    namespaces: [Object],
    sockets: [Circular],
    _events: [Object],
    settings: [Object],
    handshaken: [Object],
    connected: [Object],
    open: [Object],
    closed: {},
    rooms: [Object],
    roomClients: [Object],
    oldListeners: [Object],
    flashPolicyServer: [Object],
    sequenceNumber: -118286670,
    gc: [Object] },
    name: '',
    sockets:
    { uRBucEoalw6x0Wn78xav: [Object],
    qjUtmAz6Mvk2KrKj8xaw: [Object],
    'ya_pkpH-uo1EohvP8xay': [Circular] },
    auth: false,
    flags: { endpoint: '', exceptions: [] },
    _events: { connection: [Object] } },
    manager:
    { server:
    { domain: null,
    _events: [Object],
    _maxListeners: 10,
    _connections: 10,
    connections: [Getter/Setter],
    _handle: [Object],
    _usingSlaves: false,
    _slaves: [],
    allowHalfOpen: true,
    httpAllowHalfOpen: false,
    timeout: 120000,
    '@': [Function: connection],
    _connectionKey: '4:0.0.0.0:4567' },
    namespaces: { '': [Object] },
    sockets:
    { manager: [Circular],
    name: '',
    sockets: [Object],
    auth: false,
    flags: [Object],
    _events: [Object] },
    _events:
    { 'set:transports': [Object],
    'set:store': [Function],
    'set:origins': [Function],
    'set:flash policy port': [Function],
    'set:flash policy server': [Function] },
    settings:
    { origins: ':',
    log: false,
    store: [Object],
    logger: [Object],
    static: [Object],
    heartbeats: true,
    resource: '/socket.io',
    transports: [Object],
    authorization: false,
    blacklist: [Object],
    'log level': 3,
    'log colors': true,
    'close timeout': 60,
    'heartbeat interval': 25,
    'heartbeat timeout': 60,
    'polling duration': 20,
    'flash policy server': true,
    'flash policy port': 10843,
    'destroy upgrade': true,
    'destroy buffer size': 100000000,
    'browser client': true,
    'browser client cache': true,
    'browser client minification': true,
    'browser client etag': false,
    'browser client expires': 315360000,
    'browser client gzip': false,
    'browser client handler': false,
    'client store expiration': 15,
    'match origin protocol': false },
    handshaken:
    { uRBucEoalw6x0Wn78xav: [Object],
    qjUtmAz6Mvk2KrKj8xaw: [Object],
    'ya_pkpH-uo1EohvP8xay': [Object] },
    connected:
    { uRBucEoalw6x0Wn78xav: true,
    qjUtmAz6Mvk2KrKj8xaw: true,
    'ya_pkpH-uo1EohvP8xay': true },
    open:
    { uRBucEoalw6x0Wn78xav: true,
    qjUtmAz6Mvk2KrKj8xaw: true,
    'ya_pkpH-uo1EohvP8xay': true },
    closed: {},
    rooms:
    { '': [Object],
    '/category_2': [Object],
    '/uid_9': [Object],
    '/online_users': [Object],
    '/uid_81': [Object],
    '/topic_76': [Object] },
    roomClients:
    { uRBucEoalw6x0Wn78xav: [Object],
    qjUtmAz6Mvk2KrKj8xaw: [Object],
    'ya_pkpH-uo1EohvP8xay': [Object] },
    oldListeners: [ [Object] ],
    flashPolicyServer:
    { origins: [Object],
    port: 10843,
    log: [Function],
    socket: [Object],
    buffer: <Buffer 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 3f 3e 3c 21 44 4f 43 54 59 50 45 20 63 72 6f 73 73 2d 64 6f 6d 61 69 6e 2d 70 6f 6c 69 63 79 20 ...>,
    server: [Object] },
    sequenceNumber: -118286670,
    gc:
    { _idleTimeout: 10000,
    _idlePrev: [Object],
    _idleNext: [Object],
    _idleStart: 1412925975510,
    _onTimeout: [Function: wrapper],
    _repeat: true } },
    disconnected: false,
    ackPackets: 0,
    acks: {},
    flags: { endpoint: '', room: '' },
    readable: true,
    store:
    { store:
    { nodeId: 194853466,
    pack: [Function: stringify],
    unpack: [Function: parse],
    pub: [Object],
    sub: [Object],
    cmd: [Object],
    options: [Object],
    clients: [Object],
    _maxListeners: 0,
    manager: [Object],
    _events: [Object] },
    id: 'ya_pkpH-uo1EohvP8xay' },
    _events: { error: [Function], disconnect: [Function], '*': [Function] },
    uid: 9 }

    which does not have my "data_tid" object, which I was expecting.

    So I guess this is a bug or please correct me if I am wrong in my interpretation to this.


  • Admin Staff

    Change your function to

    SocketPlugins.Vote.topicVoteup = function(socket, data, callback) {
    console.log(data);
    }
    


  • @baris thanks ­čÖé


  • GNU/Linux Admin

    @vatsal There are upvote and downvote plugins, I'm not sure if they may work better? Although I suppose "don't fix what ain't broke" now ­čśä


Log in to reply
 

Suggested Topics

  • 2
  • 6
  • 4
  • 5
  • 1
| |