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

Bug Reports
  • 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.

  • Change your function to

    SocketPlugins.Vote.topicVoteup = function(socket, data, callback) {
    console.log(data);
    }
    
  • @baris thanks 🙂

  • @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 😄

    https://www.npmjs.org/package/nodebb-plugin-upvote-post
    https://www.npmjs.org/package/nodebb-plugin-downvote-post


Suggested Topics


  • 0 Votes
    4 Posts
    2k Views

    what is the value of uid

  • load JS in custom HTML

    Bug Reports
    0 Votes
    2 Posts
    1k Views

    Hi, I have a trouble with embedding an external script into a custom page, like you had.
    What solution did you find to make it working finally ?

  • Unix Sockets

    Feature Requests
    1 Votes
    5 Posts
    3k Views

    Then, I opened my thread in the good topic. I would request that feature. 😉

  • 0 Votes
    1 Posts
    697 Views

    I'm not sure if it's just me, but I thought I'd mention it.

    I'm using @Schamper's shoutbox plugin and noticed if I deactivate the plugin without removing the widgets first there will be an empty object listed in on the page in the section where the widget would have been. So, I tested it with the widget-essentials too and it does the same thing...

    I'm on 0.5.1. Here is how you can duplicate:

    Drop any widget into a widget section (aka sidebar or MOTD) Deactivate the plugin that contains the widget Go to the page where the widget would have been and you should see
    the text '[Object object]' where the widget would have been Go to the ACP > Extend > Widgets section and the widget won't be listed where you added it.

    What makes this really confusing #4 because you can't get rid of it. It only reappears when you activate the plugin that had the widget again.

    Has anyone else experienced this?

    And if you added some custom widget sections in your theme.js (like a sidebar for topics.tpl in the vanilla theme), and changed the theme...god help you...but seriously, if you did do that hit me up and I'll tell you how to fix it.

  • 0 Votes
    7 Posts
    2k Views

    Yeah we definitely have form validation in place... Sounds like a regression