-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
37 lines (30 loc) · 839 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var socket = io.connect('http://linda-server.herokuapp.com:80');
var linda = new Linda().connect(socket);
var ts = linda.tuplespace('chatroom01');
linda.io.on('connect', function(){
print('socket.io connect!!');
ts.watch({type:"chat"}, function(err, tuple){
if(err) return;
print(tuple.data.user + " : " + tuple.data.message);
});
});
$(function(){
$("#btn_post").click(post);
$("#input_message").keydown(function(e){
if(e.keyCode == 13) post();
});
});
var post = function(){
var tuple = {
type: "chat",
user: $("#input_user").val(),
message: $("#input_message").val()
};
$("#input_message").val('');
ts.write(tuple);
};
var print = function(msg){
// console.log(msg);
if(typeof msg === 'object') msg = JSON.stringify(msg);
$("#log").prepend( $("<li>").text(msg).fadeIn(400) );
};