Closed windbug closed 11 years ago
Hi, you are probably having an issue with the document.domain value set on both, main and iframe pages. Can you send your configuration and your client side code? Will be easier to help you with that.
nginx Configuration
server { listen 9080 default_server; servername ws.example.co.wo;
location /channels-stats {
# activate channels statistics mode for this location
push_stream_channels_statistics;
# query string based channel id
set $push_stream_channel_id $arg_id;
}
location /pub {
# activate publisher mode for this location, with admin support
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
# store messages in memory
push_stream_store_messages off;
push_stream_keepalive on;
# Message size limit
# client_max_body_size MUST be equal to client_body_buffer_size or
# you will be sorry.
client_max_body_size 32k;
client_body_buffer_size 32k;
}
location ~ /sub/(.*) {
# activate subscriber mode for this location
push_stream_subscriber;
# positional channel path
set $push_stream_channels_path $1;
# header to be sent when receiving new subscriber connection
push_stream_header_template "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script type=\"text/javascript\">\r\nwindow.onError = null;\r\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-1 * Math.max(window.location.hostname.split('.').length - 1, 2)).join('.');}catch(e){}\r\nparent.PushStream.register(this);\r\n</script>\r\n</head>\r\n<body>";
# message template
push_stream_message_template "<script>p(~id~,'~channel~','~text~','~event-id~');</script>";
#push_stream_message_template "<script>p(~id~,'~channel~','~text~');</script>";
# footer to be sent when finishing subscriber connection
push_stream_footer_template "</body></html>";
# content-type
push_stream_content_type "text/html; charset=utf-8";
}
location ~ /ev/(.*) {
# activate subscriber mode for this location
push_stream_subscriber;
# positional channel path
set $push_stream_channels_path $1;
# activate event source support for this location
push_stream_eventsource_support on;
}
location ~ /lp/(.*) {
add_header "Access-Control-Allow-Origin" "*";
add_header Last-Modified "";
if_modified_since off;
FileETag on;
etag_format \"%x%x\";
# activate long-polling mode for this location
push_stream_subscriber long-polling;
# positional channel path
set $push_stream_channels_path $1;
}
location ~ /ws/(.*) {
# activate websocket mode for this location
push_stream_websocket;
# positional channel path
set $push_stream_channels_path $1;
# store messages in memory
push_stream_store_messages on;
push_stream_websocket_allow_publish on;
}
}
and... client side code
<script src="/websocket/js/jquery.min.js" type="text/javascript" language="javascript" charset="utf-8"></script>
<script src="/websocket/js/pushstream.js" type="text/javascript" language="javascript" charset="utf-8"></script>
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
//PushStream.LOG_LEVEL = 'debug';
var pushstream = new PushStream({
host: window.location.hostname,
//port: window.location.port,
port: 9080,
modes: "websocket|eventsource|stream"
});
pushstream.onmessage = _manageEvent;
pushstream.onstatuschange = _statuschanged;
function onSendText() {
$("#message").val('');
};
function _manageEvent(eventMessage) {
var chat = $("#chat");
if (eventMessage != '') {
var values = $.parseJSON(eventMessage);
var line = values.nick + ': ' + values.text.replace(/\\r/g, '\r').replace(/\\n/g, '\n');
if (chat.val() == '') {
chat.val(line);
} else {
chat.val(chat.val() + '\n' + line);
}
var lines = chat.val().split('\n');
if (lines.length > 100) {
chat.val(lines.slice(-100).join('\n'));
}
}
chat.scrollTop(chat[0].scrollHeight - chat.height());
};
function _statuschanged(state) {
if (state == PushStream.OPEN) {
$(".offline").hide();
$(".online").show();
$("#mode").html(pushstream.wrapper.type);
} else {
$(".offline").show();
$(".online").hide();
$("#mode").html("");
}
};
function _connect(channel) {
pushstream.removeAllChannels();
try {
pushstream.addChannel(channel);
pushstream.connect();
} catch(e) {alert(e)};
$("#chat").val('');
}
$("#sendButton").click(function(){
if (($("#nick").val() != "") && ($("#message").val() != "") && ($("#room").val() != "")) {
pushstream.sendMessage('{"nick":"' + $("#nick").val() + '","message2":"' + $("#message2").val() + '", "text":"' + $("#message").val().replace(/\r/g, '\\\\r').replace(/\n/g, '\\\\n') + '"}', onSendText);
} else {
alert("nick, room and text are required");
}
return false;
});
$("#room").change(function(){
_connect($("#room").val());
});
_connect($("#room").val());
// ]]>
</script>
stream is not work. Console Log Stream problem setting document.domain = co.wo (OBS: IE8 does not support set IP numbers as domain)
and... longpolling... just 1 send msg. but...serveral return msg..
Hi, I've just fixed the problem of domain name on IE8, get the last updates. About the long polling problem you are using the location in a wrong way, do not set these directives
add_header "Access-Control-Allow-Origin" "*";
add_header Last-Modified "";
if_modified_since off;
FileETag on;
etag_format \"%x%x\";
They cause the problem you got on your print screen. The module already set the needed headers to work. If you need use only the push_stream_allowed_origins directive as push_stream_allowed_origins "test.example.co.wo,example.co.wo"; Do not set it to "*" at least you are sure about what you are doing, because this may turn your server insecure.
Very Very thx for this module!! this module is wonderful.
by the way.. i've a problem.
all works. but..some times not work. use pushstream.js
example.com <-- websocket work well example.com <- stream work well test.example.com <-- websocket work well test.example.com <- stream work well
but.. example.co.wo <-- websocket work well example.co.wo <- stream not work example.co.wo <-- longpolling not work
test.example.co.wo <-- websocket work well test.example.co.wo <- stream work well test.example.co.wo <-- longpolling work well
IE8 is not support websocket. so..must use stream.
how can i use it?