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

Couldn't get the expected response info ,include redundant bracket by jsonp request #167

Closed solderain closed 9 years ago

solderain commented 9 years ago

The client get the following response information when using jsonp request :

PushStreamManager_0_onmessage_1418199211102([Hello World!] )

But i just execute command : curl -s -v -X POST 'http://localhost/pub?id=my_channel_1' -d 'Hello World!' , the expected response doesn't include that redundant bracket mark as bold. My configuration is : location ~ /lp/(.*) {

activate long-polling mode for this location

        push_stream_subscriber      long-polling
        # positional channel path
        push_stream_channels_path         $1;
        push_stream_message_template                "~text~";
        # connection timeout
        push_stream_longpolling_connection_ttl        30s;
     }

I try to change the push_stream_message_template by different way ,but still cann't remove that brackets.
How to remove the bracket ?

wandenberg commented 9 years ago

You cannot remove. This is part of the module. Since you can receive multiple messages at once we always send them as an array. Imagine that you are connected and a message was published, your connection will be closed and reopened. In this mean time if two more messages were published, the server will send both on a single callback function. The pushstream.js already deal with that. If you are not using it your callback function should handle this. Probably you are having problems because you are not using a json message template like on examples.

solderain commented 9 years ago

Thanks wandenberg for your quickly reponse . So you mean the offline messages will be delievered automatically when using jsonp request ? I remember it have to set the following instructions ask for the past messages : push_stream_last_received_message_tag $arg_tag; push_stream_last_received_message_time $arg_time;

wandenberg commented 9 years ago

You have to set these directives in order to let the server know which was the last message you received, as a client. If there are messages published after that time/tag (and stored is 'on') they will be delivered to your client as an array.

Just a fix to my last answer, the message template could be other than a json, just has to produce a valid javascript code. So you can set the template like '\"~text~\"' producing a response like callback(["some text"]); But, to work with pushstream.js the message template must be a valid json properly configured.

solderain commented 9 years ago

Ok, i understand the purpose of that design . Thank you for your detailed explanation.