Sha256: 69c7d8268bc506cf155d9a1572b4a5feff01fc8a540b9a623e8360330a868f4e

Contents?: true

Size: 749 Bytes

Versions: 28

Compression:

Stored size: 749 Bytes

Contents

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

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

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

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("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

28 entries across 28 versions & 1 rubygems

Version Path
sinatra-cometio-0.3.4 sample/public/js/index.js
sinatra-cometio-0.3.3 sample/public/js/index.js
sinatra-cometio-0.3.2 sample/public/js/index.js
sinatra-cometio-0.3.1 sample/public/js/index.js
sinatra-cometio-0.3.0 sample/public/js/index.js
sinatra-cometio-0.2.0 sample/public/js/index.js
sinatra-cometio-0.1.9 sample/public/js/index.js
sinatra-cometio-0.1.8 sample/public/js/index.js