Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the use of a custom parser #2829

Merged

Conversation

darrachequesne
Copy link
Member

The kind of change this PR does introduce

  • a new feature

New behaviour

This would enable the use of some custom parsers, like the following based on msgpack:

const msgpack = require('notepack.io');
const Emitter = require('component-emitter');

class Encoder {
  encode(obj, callback){
    var encoded = msgpack.encode(obj);
    callback([encoded]);
  }
}

class Decoder extends Emitter {
  add(obj){
    var decoded = msgpack.decode(obj);
    this.emit('decoded', decoded);
  }
  destroy(){}
}

exports.Encoder = Encoder;
exports.Decoder = Decoder;

And then:

const server = require('http').createServer();
const myCustomParser = require('./my-custom-parser');
const io = require('socket.io')(server, {
  parser: myCustomParser
});

That would also provide a workaround for socketio/socket.io-parser#61.

Related: #1652 #1946

Note: that would need to update socket.io-client and socket.io-adapter too.

@darrachequesne darrachequesne merged commit 3b92cc2 into socketio:master Jan 24, 2017
@darrachequesne darrachequesne deleted the feature/custom-parser branch January 24, 2017 06:10
darrachequesne pushed a commit to darrachequesne/socket.io-adapter that referenced this pull request Feb 16, 2017
That will allow to use a custom parser (see socketio/socket.io#2829).
darrachequesne added a commit to socketio/socket.io-adapter that referenced this pull request Feb 16, 2017
darrachequesne pushed a commit to darrachequesne/socket.io-client that referenced this pull request Feb 17, 2017
darrachequesne added a commit to darrachequesne/socket.io-client that referenced this pull request Feb 20, 2017
darrachequesne added a commit to socketio/socket.io-client that referenced this pull request Feb 20, 2017
@darrachequesne darrachequesne added this to the 2.0.0 milestone May 13, 2017
@darrachequesne darrachequesne mentioned this pull request Jun 3, 2017
5 tasks
enderson-pan pushed a commit to holytiny/feathersjs-wxmp-socket.io-client that referenced this pull request Nov 1, 2019
@darrachequesne darrachequesne mentioned this pull request Nov 9, 2020
sunrise30 added a commit to sunrise30/socket.io-client that referenced this pull request Jan 8, 2022
dzad pushed a commit to dzad/socket.io that referenced this pull request May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant