Sha256: 2ffdf67f7e23471a75da0f8af3df6641dd12a1eb79e0053d07c948b699b6e4b5

Contents?: true

Size: 828 Bytes

Versions: 35

Compression:

Stored size: 828 Bytes

Contents

var io = new WebSocketIO().connect();

io.on("chat", function(data){
  var m = $("<li>").text(data.name + " : " +data.message);
  $("#chat #timeline").prepend(m);
});

io.on("connect", function(session){
  console.log("connect!! "+session);
  $("#chat #btn_send").click(post);
  $("#chat #message").keydown(function(e){
    if(e.keyCode == 13) post();
  });
});

io.on("disconnect", function(session){
  console.log("disconnect!!");
});

io.on("*", function(event, data){ // catch all events
  console.log(event + " - " + JSON.stringify(data));
});

io.on("error", function(err){
  console.error(err);
});

var post = function(){
  var name = $("#chat #name").val();
  var message = $("#chat #message").val();
  if(message.length < 1) return;
  io.push("chat", {name: name, message: message});
  $("#chat #message").val("");
};

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
sinatra-websocketio-0.4.1 sample/public/js/index.js
sinatra-websocketio-0.4.0 sample/public/js/index.js
sinatra-websocketio-0.3.9 sample/public/js/index.js
sinatra-websocketio-0.3.7 sample/public/js/index.js
sinatra-websocketio-0.3.6 sample/public/js/index.js
sinatra-websocketio-0.3.5 sample/public/js/index.js
sinatra-websocketio-0.3.4 sample/public/js/index.js
sinatra-websocketio-0.3.3 sample/public/js/index.js
sinatra-websocketio-0.3.2 sample/public/js/index.js
sinatra-websocketio-0.3.1 sample/public/js/index.js
sinatra-websocketio-0.3.0 sample/public/js/index.js
sinatra-websocketio-0.2.9 sample/public/js/index.js
sinatra-websocketio-0.2.8 sample/public/js/index.js
sinatra-websocketio-0.2.7 sample/public/js/index.js
sinatra-websocketio-0.2.6 sample/public/js/index.js
sinatra-websocketio-0.2.5 sample/public/js/index.js
sinatra-websocketio-0.2.4 sample/public/js/index.js
sinatra-websocketio-0.2.3 sample/public/js/index.js
sinatra-websocketio-0.2.2 sample/public/js/index.js
sinatra-websocketio-0.2.1 sample/public/js/index.js