You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngs/examples/cluster/master/web/index.html

83 lines
2.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chat 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="balance">
<input type="text" v-model="inputMessage">
<input type="button" v-on:click="sendMessage" value="Send">
</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/lonnng/nano-client-websocket)-->
<script src="protocol.js" type="text/javascript"></script>
<script src="starx-wsclient.js" type="text/javascript"></script>
<script>
var nickname = 'guest' + Date.now();
var v = new Vue({
el: "#container",
data: {
nickname: nickname,
inputMessage:'',
messages: [],
balance: 1000,
},
methods: {
sendMessage: function () {
console.log(this.inputMessage);
starx.notify('RoomService.SyncMessage', {name: this.nickname, content: this.inputMessage});
this.inputMessage = '';
}
}
});
var onMessage = function (msg) {
console.log(msg);
v.messages.push(msg)
};
var onNewUser = function (data) {
console.log(data);
v.messages.push({name:'system', content:data.content});
};
var onBalance = function (data) {
console.log(data);
v.balance = data.currentBalance;
};
var onMembers = function (data) {
console.log(data);
v.messages.push({name:'system', content: "members: "+data.members});
};
var login = function (data) {
console.log(data);
if(data.code === 0) {
v.messages.push({name:'system', content:data.result});
starx.on('onMessage', onMessage)
}
};
// gate address
var gateHost = "127.0.0.1";
var gatePort = 34590;
starx.init({host: gateHost, port: gatePort, path: '/nano'}, function () {
console.log("initialized");
starx.on("onNewUser", onNewUser);
starx.on("onMembers", onMembers);
starx.on("onBalance", onBalance);
starx.request("BindService.Login", {"nickname": nickname}, login);
})
</script>
</body>
</html>