1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>100715</title>
- </head>
- <body>
- <div>
- </div>
- <input id="uid" type="text" value="100073" placeholder="uid" /> <br />
- <input id="ticket" type="text" value="eyJhbGciOiJIUzI1NiJ9.eyJ0aWNrZXRfdHlwZSI6bnVsbCwidWlkIjoxMDAwNzMsInRpY2tldF9pZCI6IjgxODkxYjc1LTZhNzItNDQzZC1hMzZlLTg0ZTAxMTAwNTgzMCIsImV4cCI6MzYwMCwiY2xpZW50X2lkIjoiZXJiYW4tY2xpZW50In0.keIb2ggUoalCM93TfT0f9OYRbw2NqzYJbP8aISrfKiw" placeholder="ticket" /> <br />
- <input type="button" value="login" onclick="login()"/><br/>
- <hr>
- <input id="roomId" type="text" value="25458929" 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>
- <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 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>
-
|