123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- export const API_BASE_URL = "wss://sxb-socket.4dkankan.com";
- // ws://192.168.0.134:7015
- // wss://4dart.4dage.com/4dart
- // 88888888
- export const VIDEO_BASE_URL = "https://houseoss.4dkankan.com/";
- export const CDN_URL = "https://culture.4dage.com/air_show/resource";
- // https://culture.4dage.com/air_show/resource/images/lunbo2.jpg",
- export let app = {
- id: "18538303230",
- longtime:null,
- websocket: null,
- is_connect_ok: null,
- is_send_msg: null,
- noOperationTimeout: 35,
-
- send(msg) {
- if (!app.websocket) {
- return
- }
- if (msg === "request") {
- app.websocket.emit(msg + " " + this.id);
- } else if (msg === "close") {
- app.websocket.emit({ data: msg + " 0" });
- } else {
- if (app.is_connect_ok == null) {
- app.websocket.emit({ data: "request " + this.id });
- }
- setTimeout(function () {
- app.websocket.emit({ data: msg });
- }, 300);
- }
- },
- emitEvent:{
- close(){
- app.websocket.emit('Close','close',function (data) {
- console.log(data,'close');
- })
- },
- request(cb=null){
- app.websocket.emit('Request',app.id,function (data) {
- cb && cb(data)
- })
- },
- switchMachine(scene){
- app.websocket.emit('Switch',scene,function (data) {
- console.log(data,scene);
- })
- },
- Photo(photo,cb=null){
- app.websocket.emit('Photo',photo+app.id,function (data) {
- console.log(data,photo+app.id);
- cb && cb(data)
- })
- },
- Video(video,cb=null){
- app.websocket.emit('Video',video+app.id,function (data) {
- console.log(data,video+app.id);
- cb && cb(data)
- })
- },
- },
- showLoading: function () {
- return (() => {
- wx.showLoading({
- mask: true,
- title: "加载中",
- });
- })();
- },
- hideLoading: function () {
- return (() => {
- try {
- wx.hideLoading();
- } catch (error) {}
- })();
- },
- showAlert(msg, comfirm,confirmText='确定') {
- if (comfirm) {
- return (() => {
- wx.showModal({
- title: "提示",
- confirmText,
- content: msg,
- showCancel: false,
- success(res) {
- if (res.confirm) {
- comfirm();
- }
- },
- });
- })();
- }
- return (() => {
- wx.showModal({
- title: "提示",
- showCancel: false,
- content: msg,
- success() {},
- });
- })();
- },
- sendCheck() {
- console.log(this.is_connect,this.is_connect_ok,this.is_other_used);
-
- if (!this.is_connect) {
- this.hideLoading()
- app.showAlert("服务器连接失败,请重新连接", () => {
- app.emitEvent.request();
- },'重新连接');
- return false;
- } else if (this.is_connect_ok === false) {
- this.hideLoading()
- app.showAlert("服务器已断开,请重新连接", () => {
- setTimeout(() => {
- wx.showLoading({
- title: "重新连接...",
- mask: true
- });
- });
- setTimeout(() => {
- app.emitEvent.request();
- }, 1000);
- },'重新连接');
- return false;
- } else if (this.is_other_used) {
- this.hideLoading()
- app.showAlert("当前画屏正在被使用,请稍后", () => {
- app.emitEvent.request();
- });
- return false;
- }
- this.is_send_msg = true;
- return true;
- },
-
- checkOperationTimeout(stop) {
- this.operationTimer && clearTimeout(this.operationTimer);
- this.operationTimer = null;
- if (stop) {
- // 暂停检测
- return;
- }
- this.operationTimer = setTimeout(function () {
- if (app.is_connect_ok) {
- app.emitEvent.close();
- this.is_other_used = true
- this.is_connect_ok = false
- app.checkOperationTimeout(true);
- app.showAlert("抱歉,因您长时间使用,让下一位小伙伴体验吧");
- }
- }, (this.noOperationTimeout || 120) * 1000);
- },
- };
|