index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. export const API_BASE_URL = "wss://sxbv2-socket.4dkankan.com";
  2. // export const API_BASE_URL = "ws://192.168.0.76:14001";
  3. // ws://192.168.20.18:14000
  4. // wss://sxb-socket.4dkankan.com
  5. // 88888888
  6. export const VIDEO_BASE_URL = "https://houseoss.4dkankan.com/";
  7. export const CDN_URL = "https://culture.4dage.com/air_show/resource";
  8. export let app = {
  9. id: "13750062488",
  10. longtime: null,
  11. websocket: null,
  12. is_connect_ok: null,
  13. is_send_msg: null,
  14. noOperationTimeout: 60,
  15. send(msg) {
  16. if (!app.websocket) {
  17. return
  18. }
  19. if (msg === "request") {
  20. app.websocket.emit(msg + " " + this.id);
  21. } else if (msg === "close") {
  22. app.websocket.emit({
  23. data: msg + " 0"
  24. });
  25. } else {
  26. if (app.is_connect_ok == null) {
  27. app.websocket.emit({
  28. data: "request " + this.id
  29. });
  30. }
  31. setTimeout(function () {
  32. app.websocket.emit({
  33. data: msg
  34. });
  35. }, 300);
  36. }
  37. },
  38. emitEvent: {
  39. close() {
  40. app.websocket && app.websocket.emit('Close', 'close', function (data) {
  41. console.log(data, 'close');
  42. })
  43. },
  44. request(cb = null, authorCode = null) {
  45. console.log('-------',app.id,authorCode);
  46. app.websocket.emit('Request', `${app.id}#${authorCode}`, function (data) {
  47. cb && cb(data)
  48. })
  49. },
  50. switchMachine(scene) {
  51. console.log('点击切换场景',scene);
  52. app.websocket.emit('Switch', scene, function (data) {
  53. console.log(data, scene);
  54. })
  55. },
  56. Photo(photo, cb = null) {
  57. app.websocket.emit('Photo', photo, function (data) {
  58. console.log(data, photo);
  59. cb && cb(data)
  60. })
  61. },
  62. Video(video, cb = null) {
  63. app.websocket.emit('Video', video, function (data) {
  64. console.log(data, video);
  65. cb && cb(data)
  66. })
  67. },
  68. },
  69. showLoading: function () {
  70. return (() => {
  71. wx.showLoading({
  72. mask: true,
  73. title: "加载中",
  74. });
  75. })();
  76. },
  77. hideLoading: function () {
  78. return (() => {
  79. try {
  80. wx.hideLoading();
  81. } catch (error) {}
  82. })();
  83. },
  84. showAlert(msg, comfirm, confirmText = '确定') {
  85. if (comfirm) {
  86. return (() => {
  87. wx.showModal({
  88. title: "提示",
  89. confirmText,
  90. content: msg,
  91. showCancel: false,
  92. success(res) {
  93. if (res.confirm) {
  94. comfirm();
  95. }
  96. },
  97. });
  98. })();
  99. }
  100. return (() => {
  101. wx.showModal({
  102. title: "提示",
  103. showCancel: false,
  104. content: msg,
  105. success() {},
  106. });
  107. })();
  108. },
  109. sendCheck() {
  110. console.log(this.is_connect, this.is_connect_ok, this.is_other_used);
  111. if (!this.is_connect) {
  112. this.hideLoading()
  113. app.showAlert("服务器连接失败,请重新连接", () => {
  114. app.emitEvent.request();
  115. }, '重新连接');
  116. return false;
  117. } else if (this.is_connect_ok === false) {
  118. this.hideLoading()
  119. app.showAlert("服务器已断开,请重新连接", () => {
  120. setTimeout(() => {
  121. wx.showLoading({
  122. title: "重新连接...",
  123. mask: true
  124. });
  125. });
  126. setTimeout(() => {
  127. app.emitEvent.request();
  128. }, 1000);
  129. }, '重新连接');
  130. return false;
  131. } else if (this.is_other_used) {
  132. this.hideLoading()
  133. app.showAlert("当前画屏正在被使用,请稍后", () => {
  134. app.emitEvent.request();
  135. });
  136. return false;
  137. }
  138. this.is_send_msg = true;
  139. return true;
  140. },
  141. checkOperationTimeout(stop,cb=()=>{}) {
  142. this.operationTimer && clearTimeout(this.operationTimer);
  143. this.operationTimer = null;
  144. if (stop) {
  145. // 暂停检测
  146. return;
  147. }
  148. this.operationTimer = setTimeout(function () {
  149. this.is_other_used = true
  150. this.is_connect_ok = false
  151. app.checkOperationTimeout(true);
  152. cb()
  153. }, (this.noOperationTimeout || 120) * 1000);
  154. },
  155. };