1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import {
- ApiModel
- } from './utils/api';
- App({
- onLaunch() {},
- initSocket() {
- return;
- let that = this;
- this.globalData.SocketTask = wx.connectSocket({
- url: 'ws://121.37.152.76:8080/yos/webSocket/' + wx.getStorageSync('userMsg').token,
- complete: (res) => {
- console.log(res)
- }
- })
- this.globalData.SocketTask.onOpen(function (res) {
- console.log('WebSocket连接已打开!readyState=' + that.globalData.SocketTask.readyState);
- that.globalData.socketEstablish = true;
- })
- this.globalData.SocketTask.onMessage(function (res) {
- that.globalData.callback(res)
- })
- this.globalData.SocketTask.onError(function (res) {
- console.log('readyState=' + that.globalData.SocketTask.readyState)
- setTimeout(() => {
- that.initSocket()
- }, 1000)
- })
- this.globalData.SocketTask.onClose(function (res) {
- console.log('WebSocket连接已关闭!readyState=' + that.globalData.SocketTask.readyState)
- if (that.globalData.socketEstablish == false) {
- setTimeout(() => {
- that.initSocket()
- }, 1000)
- } else {
- that.globalData.socketEstablish = false;
- }
- })
- },
- globalData: {
- http: new ApiModel(), //接口文件
- queryPer: require("./utils/queryPermissions"), //权限查询
- socketEstablish: false, //是否已经建立socket
- SocketTask: '',
- callback: function () {},
- },
- })
|