| | |
| | | } |
| | | } |
| | | |
| | | /* socket */ |
| | | tool.socket = { |
| | | url:'ws://116.63.155.153:83/ws/info', |
| | | websocket: null, |
| | | connectToWebSocket(token) { //建立链接 |
| | | this.websocket = new WebSocket(this.url + "?access_token=" + token); |
| | | }, |
| | | sendDataToWebSocket(data) { //发送 |
| | | if(!data) return; //没有入参不发送 |
| | | if (this.websocket.readyState === this.websocket.OPEN) { |
| | | this.websocket.send(JSON.stringify(data)); |
| | | } |
| | | // this.websocket.onmessage = function(event) { |
| | | // // 当从服务器收到消息时 |
| | | // console.error("WebSocket Error: ", event.data); |
| | | // }; |
| | | |
| | | // this.websocket.onerror = function(error) { |
| | | // // 当WebSocket连接发生错误时 |
| | | // console.error("WebSocket Error: ", error); |
| | | // }; |
| | | |
| | | // this.websocket.onclose = function(event) { |
| | | // // 当WebSocket连接关闭时 |
| | | // console.log("WebSocket is closed now."); |
| | | // // 可以在这里重试连接或其他逻辑... |
| | | // }; |
| | | return this; |
| | | } |
| | | } |
| | | /* Fullscreen */ |
| | | tool.screen = function (element) { |
| | | var isFull = !!(document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement || document.fullscreenElement); |
| | |
| | | } |
| | | } |
| | | |
| | | tool.qsStringify = function(obj) { |
| | | return Object.keys(obj).map(key => { |
| | | if (Array.isArray(obj[key])) { |
| | | return obj[key] |
| | | .map(arrayValue => `${encodeURIComponent(key)}=${encodeURIComponent(arrayValue)}`) |
| | | .join('&'); |
| | | } |
| | | return `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`; |
| | | }).join('&'); |
| | | } |
| | | |
| | | export default tool |