index.js 3.8 KB

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