This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function appendCount (count) { | |
$("#count").text(count); | |
} | |
function appendMessage (name, text) { | |
$("#chat").append('<span class="label label-default">' + name + "</span>" + text + "<br/>"); | |
} | |
function sendMessage() { | |
var name = $('#username').val(); | |
var text = $('#msgbody').val(); | |
if(name && text) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
module Websockettest2 | |
class App < Sinatra::Base | |
get "/" do | |
erb :index | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class @ChatClass | |
constructor: (url, useWebsocket) -> | |
# これがソケットのディスパッチャー | |
@dispatcher = new WebSocketRails(url, useWebsocket) | |
# イベントを監視 | |
@bindEvents() | |
bindEvents: () => | |
# 送信ボタンが押されたらサーバへメッセージを送信 | |
$('#send').on 'click', @sendMessage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChatController < WebsocketRails::BaseController | |
def initialize_session | |
puts "Session Initialized\n" | |
end | |
def new_message | |
# messageという変数が送られてくる | |
puts "call new_message: #{message}" | |
broadcast_message :new_message, message |