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

Add support of msgpack format #1652

Closed
mrniko opened this issue Jun 26, 2014 · 12 comments
Closed

Add support of msgpack format #1652

mrniko opened this issue Jun 26, 2014 · 12 comments

Comments

@mrniko
Copy link

mrniko commented Jun 26, 2014

I think it will be useful to add support of msgpack and have ability to switch between json and msgpack formats in configuration. http://msgpack.org/

@rase-
Copy link
Contributor

rase- commented Jan 13, 2015

i think alternative formats would serve better as plugins. I'd be happy to merge in any hooks needed to make that happen.

Thought, @rauchg?

@rauchg
Copy link
Contributor

rauchg commented Jan 13, 2015

Agreed on hooks. Pluggable codecs is something we've been meaning to introduce for a while!
As a matter of fact, the current "codec" is highly opinionated in several areas (performance, usage of UTF8 JSON even in binary stream, etc), and many applications would definitely be better served with a custom one.

@rauchg
Copy link
Contributor

rauchg commented Jan 13, 2015

It'd be interesting to test the performance of a demo app that shows users cursors on a page in realtime using the default codec and a custom codec that can only receive integer tuples over a binary stream (x,y).

In other words:

io.emit('position', x, y)

could be encoded in a very minimal way instead of using JSON.

@legomind
Copy link

any progress on this? I have msgpack working via monkey-patching - something I would like to avoid.

@darrachequesne
Copy link
Member

darrachequesne commented Dec 23, 2016

I'd be happy to merge in any hooks needed to make that happen.

Related: #1946

@darrachequesne
Copy link
Member

darrachequesne commented Dec 23, 2016

Question: aren't most users already using something like io.emit(<message id>, msgpack.encode({ x: x, y: y }));?

@legomind
Copy link

@darrachequesne that is the only way to do it right now, but it would be far more convenient if there were a way to preprocess all outgoing and incoming messages automatically.

As far as hooks go, what would you like them named?

I was thinking something like:

server

const socket = new SocketIO(httpServer, {
  prepareMessage: msgpack.encode,
  unprepareMessage: msgpack.decode,
})

client

const socket = new SocketIO({
  prepareMessage: msgpack.encode,
  unprepareMessage: msgpack.decode,
})

@legomind
Copy link

Or closer to the request in #1946,

server

const codec = {
  encode: msgpack.encode,
  decode: msgpack.decode,
}
const socket = new SocketIO(httpServer, {
  codec,
})

client

const codec = {
  encode: msgpack.encode,
  decode: msgpack.decode,
}
const socket = new SocketIO({
  codec,
})

@darrachequesne
Copy link
Member

On a per-event level

Maybe something like the following?
io.registerCodec(<eventName>, { encode: <encode>, decode: <decode> });

That would allow to use not only msgpack, but also protobuf or schemapack (among others).

Question: since socket.io does add some metadata to the payload (i.e. the event name, the packet type, the namespace name, the optional acknowledgment id), should the user be aware of that?

Example: socket.emit('hello', 'world', function () {}) results in the following packet:

{
  type: parser.EVENT,
  data: ['hello', 'world'],
  id: 1,
  nsp: '/test'
}

@darrachequesne
Copy link
Member

darrachequesne commented Jan 18, 2017

That may make sense too: socketio/socket.io-parser#61

@darrachequesne
Copy link
Member

What do you think of #2829?

@darrachequesne
Copy link
Member

Closed by #2829.

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

No branches or pull requests

6 participants
@rauchg @mrniko @rase- @legomind @darrachequesne and others