index.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <html>
  2. <head>
  3. <meta charset='UTF-8'>
  4. <title>socket.io客户端</title>
  5. <script src="./js/socket.io.js"></script>
  6. </head>
  7. <body>
  8. <button id='send'>发送消息到服务器</button>
  9. <div>
  10. <h3>服务器响应的消息:</h3>
  11. <i id='msg'></i>
  12. </div>
  13. <script>
  14. // 'http://47.115.43.159:3000'
  15. var socket = io('http://47.115.43.159:3000',{
  16. path: '/test',
  17. query: {
  18. customerId: 'user_001',
  19. agentId: 'user_002',
  20. role:'customer',
  21. nickName: '测试1',
  22. myHeadUrl: 'http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg'
  23. }
  24. });
  25. socket.on('vr_request', function (data) {
  26. console.log(data);
  27. });
  28. socket.on('action', function (data) {
  29. console.log('--acticon--',data);
  30. });
  31. socket.on('vr_response', function (data) {
  32. let res = data
  33. console.log(`${res.customerId}: ${res.content}`);
  34. });
  35. var send = document.querySelector('#send');
  36. send.addEventListener('click', function () {
  37. socket.emit('getJson', {
  38. customerId:'user_001',
  39. agentId: 'user_002',
  40. nickName: '测试1',
  41. myHeadUrl: 'http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg',
  42. content:{
  43. json:'t1',
  44. json1:'t2',
  45. json2:'t3',
  46. action:'action'
  47. }
  48. })
  49. })
  50. </script>
  51. </body>
  52. </html>