index.js 3.9 KB

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