forked from yythlj/gogame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
88 lines (82 loc) · 2.95 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>game Demo</title>
</head>
<body>
<div id="container">
<ul>
<li v-for="msg in messages">[<span style="color:red;">{{msg.name}}</span>]{{msg.content}}</li>
</ul>
<div class="controls">
<input type="text" v-model="nickname">
<input type="text" v-model="inputMessage">
<input type="button" v-on:click="updatepwdMessage" value="updatepwd">
<input type="button" v-on:click="sendMessage" value="Send">
<input type="button" v-on:click="loginMessage" value="login">
<input type="button" v-on:click="joinMessage" value="join">
</div>
</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js" type="text/javascript"></script>
<!--[starx websocket library](https://github.com/topfreegames/pitaya-client-websocket)-->
<script src="protocol.js" type="text/javascript"></script>
<script src="starx-wsclient.js" type="text/javascript"></script>
<script>
var v = new Vue({
el: "#container",
data: {
nickname:'guest' + Date.now(),
inputMessage:'',
messages: []
},
methods: {
sendMessage: function () {
console.log("sendMessage");
starx.notify('room.message', {name: this.nickname, content: this.inputMessage});
},
updatepwdMessage: function () {
console.log("updatepwdMessage");
starx.request('login.updatepwd', {account_name: this.nickname, pwd_md5: this.inputMessage}, onLogin);
},
loginMessage: function () {
console.log("loginMessage");
starx.request('login.login', {account_name: this.nickname, pwd_md5: this.inputMessage}, onLogin);
},
joinMessage: function () {
console.log("joinMessage");
starx.request("room.join", {}, join);
}
}
});
var onMessage = function (msg) {
v.messages.push(msg)
};
var join = function (data) {
console.log(data);
if(data.code === 0) {
v.messages.push({name:'system', content:data.result});
starx.on('onMessage', onMessage)
}
};
var onNewUser = function (data) {
console.log(data);
v.messages.push({name:'system', content:data.content});
};
var onMembers = function (data) {
console.log(data);
v.messages.push({name:'system', content: "members: "+data.members});
};
var onLogin = function (data) {
console.log(data);
v.messages.push({name:'system', content: "login res: "+data.code+data.result});
};
starx.init({host: '127.0.0.1', port: 3850, path: '/'}, function () {
console.log("initialized");
starx.on("room.onNewUser", onNewUser);
starx.on("room.onMembers", onMembers);
starx.on("login.login", onLogin);
})
</script>
</body>
</html>