From 93b222ee38117ad969a0bb0294878da9c026f890 Mon Sep 17 00:00:00 2001 From: 13405411873 <1994398261@qq.com> Date: Sat, 9 Nov 2024 18:09:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=B5=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/orderSocket.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 utils/orderSocket.js diff --git a/utils/orderSocket.js b/utils/orderSocket.js new file mode 100644 index 0000000..42a0db5 --- /dev/null +++ b/utils/orderSocket.js @@ -0,0 +1,33 @@ + import { startSocketConnect } from '../main.js' + import config from '@/config' + export function connect(userId) { + var socketTask = uni.connectSocket({ + url: config.wsUrl+'/websocket/inspection/'+userId, + success(res) { + }, + fail(err) { + } + } + ); + return socketTask; + } + + export function sendSocketMessage(SocketTask) { + if(SocketTask){ + SocketTask.send({ + data: 'keep connect', + success: res => { + }, + fail: err => { + startSocketConnect(uni.getStorageSync('userId')) + }, + }); + }else{ + startSocketConnect(uni.getStorageSync('userId')) + } + } + + + export function closeSocket(SocketTask) { + SocketTask.close() + } \ No newline at end of file