Skip to content
This repository has been archived by the owner on Nov 27, 2022. It is now read-only.

Commit

Permalink
Works on non-websocket environment refs #86
Browse files Browse the repository at this point in the history
At non-websocket environment:

- Don't raise exception, when message is post
- Use a form POST to post message, instead of Ajax
  • Loading branch information
mzp committed May 28, 2013
1 parent f575d22 commit 1f723ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
18 changes: 12 additions & 6 deletions app/assets/javascripts/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $(function() {
// ------------------------------
// chat
// ------------------------------
var connected = false;
$(".message-list")
.webSocket({
pusher : AsakusaSatellite.pusher,
Expand All @@ -60,12 +61,15 @@ $(function() {
}
},
'websocket::connect' : function(){
connected = true;
$("img.websocket-status").attr('src', AsakusaSatellite.resouces.connect);
},
'websocket::error' : function(){
connected = false;
$("img.websocket-status").attr('src', AsakusaSatellite.resouces.disconnect);
},
'websocket::disconnect' : function(){
connected = false;
$("img.websocket-status").attr('src', AsakusaSatellite.resouces.disconnect);
}
});
Expand All @@ -76,12 +80,14 @@ $(function() {
$('textarea#message').multiline();

$('form.inputarea').bind('submit', function(e){
e.preventDefault();
jQuery.post(AsakusaSatellite.url.create, {
'room_id' : AsakusaSatellite.current.room,
'message' : $('textarea#message').val()
});
$('textarea#message').val('');
if(connected) {
e.preventDefault();
jQuery.post(AsakusaSatellite.url.create, {
'room_id' : AsakusaSatellite.current.room,
'message' : $('textarea#message').val()
});
$('textarea#message').val('');
}
});

// ------------------------------
Expand Down
11 changes: 8 additions & 3 deletions app/helpers/chat_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ def publish_message(event, message, room)
else
{ :content => to_json(message, room) }
end
AsakusaSatellite::MessagePusher.trigger("as-#{room.id}",
"message_#{event}",
data.to_json)

begin
AsakusaSatellite::MessagePusher.trigger("as-#{room.id}",
"message_#{event}",
data.to_json)
rescue => e
Rails.logger.warn "fali to send message: #{e.inspect}"
end

if event == :create then
call_hook(:after_create_message, :message => message, :room => room)
Expand Down

0 comments on commit 1f723ad

Please sign in to comment.