-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
40 lines (39 loc) · 1009 Bytes
/
index.html
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
38
39
40
<head>
<script src="./lhttp-client.js"></script>
<script src="./vue.min.js"></script>
</head>
<body id="chat">
<ul>
<li v-for="m in messages">
{{m}}
</li>
</ul>
<input v-model="message"> <button v-on:click="send">Send</button>
</body>
<script type="text/javascript">
var lhttp_client = new Lhttp("ws://localhost:8081/");
new Vue({
el:"#chat",
data:{
messages:[]
},
methods:{
send:function(){
lhttp_client.context.publish("chatroom", "chat", null, this.message);
this.message = "";
}
},
created:function() {
var _this = this;
lhttp_client.on_message = function(context) {
console.log("on message: " + context.getBody());
if (context.getBody() != "") {
_this.messages.push(context.getBody());
}
}
}
})
lhttp_client.on_open = function(context) {
context.subscribe("chatroom", "chat", null, "");
}
</script>