wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.22k stars 295 forks source link

in pushstream.js allow the very first connection to retrieve backtrack and the following to not use backtrack #79

Closed dzhao closed 10 years ago

dzhao commented 11 years ago

hi, the use case is straightforward, i guess someone must have mentioned but i couldn't find a good solution on pushstream.js.. i have a chat program, i want to retrive the first 10 chat messages when client first connects, but NOT to send historic messages in the ensuing requests. I am using long polling and i tried using: chat.addChannel("chat", {"backtrack": 10}) but then everytime when reestablishing the connection, the clients sends a .b10 to server, cuasing server to continuously send back last 10 messages.

I am trying to do some trick to:

  1. initially addChannel("chat", {"backtrack":10}
  2. then in the listener, i will remove the channel and add it back without backtracking.

Just feel it's a little hacky. any good formal way to resolve this? I am pretty sure this is a common scenario. Thanks!

wandenberg commented 11 years ago

Hi,

for long polling connections you should user the secondsAgo attribute. Try this var pushstream = new PushStream({secondsAgo: 30, ... })

dzhao commented 11 years ago

Two questions: What if my latest chat is one day ago? Do i get empty history on initial connection? Does this secondsAgo atyribute also get requested everytime? 在 2013-5-12 AM9:11,"Wandenberg Peixoto" notifications@github.com写道:

Hi,

for long polling connections you should user the secondsAgo attribute. Try this var pushstream = new PushStream({secondsAgo: 30, ... })

— Reply to this email directly or view it on GitHubhttps://github.com/wandenberg/nginx-push-stream-module/issues/79#issuecomment-17770555 .

wandenberg commented 11 years ago

What if my latest chat is one day ago? Do i get empty history on initial connection? Yes, you will get an empty history. To get some message on this case you should store messages on memory for a long period what is not a good thing, you could get a "no memory" when try to publish a new message.

Does this secondsAgo atyribute also get requested everytime? On long polling connections, the mechanism to get the messages is sent a header telling when was the last message received. So on the first connection we sent the current time less the secondsAgo value (default is 0), on the subsequent requests the time sent is the time of the last message or the time of the timeout sent by the server.

dzhao commented 11 years ago

For point one i think max_stream_message_stored_per_channel can limit the memory usage. I use a value of 5 which should be small enough to go a long way..

What i am lookig for is a similar attribute to secondsAgo, say, numOfMessagesAgo. It would just read latest n number of messagrs on initial connection.

This is a more reliable way of getting histories than time. Say if I develop a chess game, for each new joiner i want to display the last five moves. The last five moves may span 5 minutes or 5 hours.. 在 2013-5-12 PM9:03,"Wandenberg Peixoto" notifications@github.com写道:

What if my latest chat is one day ago? Do i get empty history on initial connection? Yes, you will get an empty history. To get some message on this case you should store messages on memory for a long period what is not a good thing, you could get a "no memory" when try to publish a new message.

Does this secondsAgo atyribute also get requested everytime? On long polling connections, the mechanism to get the messages is sent a header telling when was the last message received. So on the first connection we sent the current time less the secondsAgo value (default is 0), on the subsequent requests the time sent is the time of the last message or the time of the timeout sent by the server.

— Reply to this email directly or view it on GitHubhttps://github.com/wandenberg/nginx-push-stream-module/issues/79#issuecomment-17777595 .

wandenberg commented 10 years ago

This was solved on tag 0.4.0 3d3a204177d3a7ab8a2858e04e792a6d11bf133f