slact / nchan.js

NPM package for the Javasript client for Nchan
Other
91 stars 25 forks source link

When connecting to how pub/sub routes, how to publish messages with this utility? #1

Closed bzroom closed 7 years ago

bzroom commented 7 years ago

Using this utility to subscribe to a pubsub route, how do we write a message to the publish end point?

Right now i'm trying to force it to use websockets and then i'm trying to get access to the websock so i can write a message but this seems like part of the nchan api that should be supported by the official client.

slact commented 7 years ago

NChan.js is for subscribing only. To publish, you can POST to the pubsub (or publisher) location, or use the websocket in nchan.js directly (accessible at nchanSubscriberObject.transport.listener).

It's probably a good idea to add publishing functionality in the future, but for the moment this is strictly a subscriber library.

bzroom commented 7 years ago

Thank you for your response. In terms of abstracting the publishing, would we want to just register another callback for the transport for "onSend"? Each different transport would register this function. Websocket would call .send, but the others would wire up a POST.

I can see why it's a little weird. Because the decision to pub or sub actually happens in the server, often a publisher route is a different route all together. The client is not made aware of the capabilities (maybe it is, maybe it doesnt matter). Either way, i love this nginx module. I hope I can be a useful community member.

slact commented 7 years ago

Closing this. I'll update it if I figure out how to add publishing into the mix.