123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>100715-queue</title>
- </head>
- <body>
- <div>
- </div>
- <input id="uid" type="text" value="100715" placeholder="uid" /> <br />
- <input id="ticket" type="text" value="eyJhbGciOiJIUzI1NiJ9.eyJ0aWNrZXRfdHlwZSI6bnVsbCwidWlkIjoxMDA3MTUsInRpY2tldF9pZCI6ImQ0MGNlNDBjLWMwYzYtNGRjNC1hN2Y0LTc1MjIwYWFjZTQ0YiIsImV4cCI6MzYwMCwiY2xpZW50X2lkIjoiZXJiYW4tY2xpZW50In0.mJrvfq4VUQ9DRm0qsZm0jA6Q-h_FulsA4IxIBzDgk0o" placeholder="ticket" /> <br />
- <input type="button" value="login" onclick="login()"/><br/>
- <hr>
- <input id="roomId" type="text" value="25477895" placeholder="roomId" /> <br />
- <input type="button" value="进入房间" onclick="enterChatRoom()"/><br/>
- <hr>
- <input id="message" type="text" value="" placeholder="message" /> <br />
- <input type="button" value="发送文本消息" onclick="sendMessage()"/><br/>
- <hr>
- <hr>
- <input type="button" value="获取房间队列" onclick="fetchQueue()"/><br/>
- <hr>
- <hr>
- <input id="updateKey" type="text" value="" placeholder="updateKey" /> <br />
- <input id="updateUid" type="text" value="" placeholder="updateUid" /> <br />
- <input type="button" value="更新房间队列" onclick="updateQueue()"/><br/>
- <hr>
- <hr>
- <input id="pollKey" type="text" value="" placeholder="pollKey" /> <br />
- <input type="button" value="取出房间队列" onclick="pollQueue()"/><br/>
- <hr>
- <hr>
- <script>
- var socket = new WebSocket("ws://39.105.187.28:3006");
- socket.onopen = function(event) {
- console.log("connect suc");
- // 监听消息
- socket.onmessage = function(event) {
- console.log('Client received a message '+event.data);
- var msg = JSON.parse(event.data);
- };
- // 监听Socket的关闭
- socket.onclose = function(event) {
- console.log('Client notified socket has closed');
- };
- // 关闭Socket....
- //socket.close()
- };
- //测试登录im接口
- function login() {
- var data = {};
- data['id'] = 1;
- data['route'] = 'login';
- var req_data = {};
- req_data.page_name = 3;
- req_data.uid = document.getElementById("uid").value;
- req_data.ticket = document.getElementById("ticket").value;
- data['req_data'] = req_data;
- socket.send(JSON.stringify(data));
- }
- function enterChatRoom() {
- socket.send(JSON.stringify({
- "id":1,
- "route":"enterChatRoom",
- "req_data":{
- "room_id":document.getElementById("roomId").value
- }
- }));
- }
- function sendMessage() {
- socket.send(JSON.stringify({
- "id":1,
- "route":"sendMessage",
- "req_data":{
- "room_id":document.getElementById("roomId").value,
- "content":document.getElementById("message").value,
- }
- }));
- }
- function fetchQueue() {
- socket.send(JSON.stringify({
- "id":1,
- "route":"fetchQueue",
- "req_data":{
- "room_id":document.getElementById("roomId").value,
- }
- }));
- }
- function updateQueue() {
- socket.send(JSON.stringify({
- "id":1,
- "route":"updateQueue",
- "req_data":{
- "room_id":document.getElementById("roomId").value,
- "key":document.getElementById("updateKey").value,
- "uid":document.getElementById("updateUid").value,
- }
- }));
- }
- function pollQueue() {
- socket.send(JSON.stringify({
- "id":1,
- "route":"pollQueue",
- "req_data":{
- "room_id":document.getElementById("roomId").value,
- "key":document.getElementById("pollKey").value,
- }
- }));
- }
- function heartbeat() {
- var data = {};
- data['id'] = 1;
- data['route'] = 'heartbeat';
- var req_data = {};
- req_data.page_name = 3;
- //data['req_data'] = req_data;
- var str = JSON.stringify(data);
- socket.send(str);
- }
- setInterval(function() {heartbeat();}, 5000);
- </script>
- </body>
- </html>
-
|