hapijs / nes

WebSocket adapter plugin for hapi routes
Other
502 stars 87 forks source link

Sequence number? #268

Closed peteclark3 closed 5 years ago

peteclark3 commented 5 years ago

Just wondering if anyone has tried to implement a sequence number as part of every subscription payload that is sent (unique per subscribed client, starting at 0 for new connections).. or if this is available in here somewhere and I'm missing it?

mtharrison commented 5 years ago

I think you could implement this using the filter option if you wanted to.

const seqMap = new WeakMap();

server.subscription('/item', {
    filter: function (path, message, options) {

        const seq = (seqMap.get(options.socket) || 0) + 1;
        seqMap.set(options.socket, seq);

        const override = Object.assign({}, message, { seq });

        return { override };
    }
});
lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.