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.6.0 sample/public/js/index.js
sinatra-cometio-0.5.9 sample/public/js/index.js
sinatra-cometio-0.5.8 sample/public/js/index.js
sinatra-cometio-0.5.7 sample/public/js/index.js
sinatra-cometio-0.5.6 sample/public/js/index.js
sinatra-cometio-0.5.5 sample/public/js/index.js
sinatra-cometio-0.5.4 sample/public/js/index.js
sinatra-cometio-0.5.3 sample/public/js/index.js
sinatra-cometio-0.5.2 sample/public/js/index.js
sinatra-cometio-0.5.1 sample/public/js/index.js
sinatra-cometio-0.5.0 sample/public/js/index.js
sinatra-cometio-0.4.3 sample/public/js/index.js
sinatra-cometio-0.4.2 sample/public/js/index.js
sinatra-cometio-0.4.1 sample/public/js/index.js
sinatra-cometio-0.4.0 sample/public/js/index.js
sinatra-cometio-0.3.9 sample/public/js/index.js
sinatra-cometio-0.3.8 sample/public/js/index.js
sinatra-cometio-0.3.7 sample/public/js/index.js
sinatra-cometio-0.3.6 sample/public/js/index.js
sinatra-cometio-0.3.5 sample/public/js/index.js