123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Document</title>
- </head>
- <body>
- <div>
- </div>
- <input id="uid" type="text" value="100691" placeholder="uid"/> <br/>
- <input id="ticket" type="text"
- value="eyJhbGciOiJIUzI1NiJ9.eyJ0aWNrZXRfdHlwZSI6bnVsbCwidWlkIjoxMDA2OTEsInRpY2tldF9pZCI6IjIzNzBiZjk3LTQ3MzQtNDY0OC1iMjM3LTExMWRiMTk3NTliZiIsImV4cCI6MzYwMCwiY2xpZW50X2lkIjoiZXJiYW4tY2xpZW50In0.s3S5WKIFRFaLIjpUwmS_VjBNg0RvQnQ_rD6oFxPVroQ"
- placeholder="ticket"/> <br/>
- <input type="button" value="login" onclick="login()"/><br/>
- <hr>
- <input id="publicRoomId" type="text" value="1"/><br/>
- <input type="button" value="进入大厅" onclick="enterPublicRoom()"/><br/>
- <hr>
- <input id="publicRoomMsg" type="text" value=""/><br/>
- <input type="button" value="大厅发送消息" onclick="sendPublicMsg()"/><br/>
- <hr>
- <input id="roomId" type="text" value="" 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) {
- var msg = JSON.parse(event.data);
- if ("heartbeat" == msg.route) {
- return;
- }
- console.log('Client received a message ' + 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);
- }
- function enterPublicRoom() {
- socket.send(JSON.stringify({
- "id": 1,
- "route": "enterPublicRoom",
- "req_data": {
- "room_id": document.getElementById("publicRoomId").value
- }
- }));
- }
- function sendPublicMsg() {
- console.log("======================");
- socket.send(JSON.stringify({
- "id": 1,
- "route": "sendPublicMsg",
- "req_data": {
- "room_id": document.getElementById("publicRoomId").value,
- "custom": document.getElementById("publicRoomMsg").value
- }
- }));
- }
- setInterval(function () {
- heartbeat();
- }, 5000);
- </script>
- </body>
- </html>
-
|