Closed windbug closed 11 years ago
Actually is only possible send messages to a channel and all users on it will receive. To send message to only one user you have to connect him to an individual channel. Keep in mind that you can subscribe multiple channels with a single connection.
On Sun, Apr 14, 2013 at 2:39 PM, windbug notifications@github.com wrote:
Hi.
most of all, i send push msg every user. but sometimes, must send push msg to Only 1 User.
so, i wanna open multi websocket/stream. how can i push msg to specific user via websocket/stream?
ex) e-mail Alert Messenger Alert
— Reply to this email directly or view it on GitHubhttps://github.com/wandenberg/nginx-push-stream-module/issues/70 .
wow...thx for fastest reply.
by the way.
var pushstream = new PushStream; pushstream.onmessage = _Push.Init; pushstream.addChannel('site@admin'); pushstream.connect(); pushstream.addChannel('site');
i wrote a script this..
multi channel works well. by the way... Chrome console WebSocket is closed before the connection is established.
so modify like this
var pushstream = new PushStream; pushstream.onmessage = _Push.Init; pushstream.onstatuschange = _statuschanged; pushstream.addChannel('site@admin'); pushstream.connect();
function _statuschanged(state) { if (state == PushStream.OPEN) { pushstream.addChannel('site'); } }
and..Chrome console uncaught Cannot add channel site: already subscribed
how can i subscribe multiple channels without Console log Error?
When a connection is established and you add another channel the connection is closed and another one is created, subscribing all channels together. Try to invert the order.
pushstream.addChannel('site@admin'); pushstream.addChannel('site'); pushstream.connect();
ps: for doubts or ask for help, give preference to use the email grouphttps://groups.google.com/group/nginxpushstream
On Sun, Apr 14, 2013 at 3:17 PM, windbug notifications@github.com wrote:
wow...thx for fastest reply.
by the way.
var pushstream = new PushStream; pushstream.onmessage = _Push.Init; pushstream.addChannel('site@admin'); pushstream.connect(); pushstream.addChannel('site');
i wrote a script this..
multi channel works well. by the way... Chrome console WebSocket is closed before the connection is established.
— Reply to this email directly or view it on GitHubhttps://github.com/wandenberg/nginx-push-stream-module/issues/70#issuecomment-16356402 .
Good Work!!!!!!!!!!!!!! Thx Thx! Thx!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Good tip!
What if we pushstream.addChannel('anIdFromAjaxRequest')
multiple time after an Ajax request ?
I thought we could disconnect, do all the addChannel and reconnect again so the websocket will connect only once. But we might never get messages that would have been received between the disconect and connect.
@Jeremlicious You can control the time you want to connect if you disconnect first. If you are already connected, each call to addChannel will make the client disconnect and connect again. About loose messages during this period, it depends on how you configured your server, to store or not old messages, and on your client code, if it is setting that it wants to receive old messages based on one of the ways to get old messages. Take a look on the examples.
Thanks for your quick reply. I found a hack to avoid disconnecting first :
// Get new channels names via Ajax
pushstream.readyState=0
// pushstream.addChannel(eachNewOne)
pushstream.connect()
Maybe addChannel
could be changed and accept an array of channels names ? I can code it if you are ok.
Cheers.
@Jeremlicious definitely change the readyState
on this way is not a good idea.
You can add a addChannels
method, just do not forgot to add tests to it. ;)
Hi.
most of all, i send push msg every user. but sometimes, must send push msg to Only 1 User.
so, i wanna open multi websocket/stream. how can i push msg to specific user via websocket/stream? or how can i use authorized socket? ex) e-mail Alert Messenger Alert Private chat