]> Dogcows Code - chaz/chatty/blob - root/tt/chat/view.tt
add comet support for real-time chatting
[chaz/chatty] / root / tt / chat / view.tt
1 [% META title = 'Live' -%]
2 [% BLOCK js_include -%]
3 <script type="text/javascript" src="http://data.chatty.com/meteor.js"></script>
4 [% END -%]
5 [% BLOCK js -%]
6 Meteor.hostid = '' + Math.floor(999*Math.random());
7 Meteor.host = "data."+location.hostname;
8 Meteor.registerEventCallback("process", addMessage);
9 Meteor.registerEventCallback("eof", function() {
10 addMessage("** stream closed **");
11 });
12 Meteor.registerEventCallback("reset", function() {
13 addMessage("** stream reset **");
14 });
15 Meteor.registerEventCallback("changemode", function(mode) {
16 addMessage("** mode changed to "+mode+" **");
17 });
18 Meteor.joinChannel("[% room.id %]", 5);
19 Meteor.mode = 'stream';
20 Meteor.connect();
21
22 function addMessage(line) {
23 $("#chat").append("<p>"+line+"</p>");
24 $("#chat").stop().animate({scrollTop:$("#chat").prop("scrollHeight")}, 350);
25 };
26
27 $("#submit").click(function(e) {
28 $.getJSON("", {msg: $("#msg").val()},
29 function(data) {
30 });
31 $("#msg").val("");
32 e.preventDefault();
33 });
34 $("#msg").focus();
35 [% END -%]
36 <h1>Room: [% room.name %]</h1>
37 <div id="chat" style="height: 300px; overflow: auto"></div>
38 <form id="chat_send">
39 <i>Say your thing:</i>
40 <input id="msg" type="input"></input>
41 <input id="submit" type="submit" value="Send"></input>
42 <form>
This page took 0.03554 seconds and 4 git commands to generate.