import { startSocketConnect } from '../main.js' import config from '@/config' export function connect(driverId) { var socketTask = uni.connectSocket({ url: config.wsUrl+'/websocket/rescueDriver/'+driverId, success(res) { }, fail(err) { } } ); return socketTask; } export function sendSocketMessage(SocketTask) { if(SocketTask){ console.log("进入定位1"); uni.getLocation({ type: 'wgs84', isHighAccuracy: true , success: (res) => { console.log("进入定位2",res,SocketTask); let data = { longitude:res.longitude, latitude:res.latitude, positionInfo:res.address, hegit:res.altitude, } SocketTask.send({ data: JSON.stringify(data), success: res => { }, fail: err => { console.log("定位socket链接异常 重新链接",uni.getStorageSync('driverInfo')) startSocketConnect(uni.getStorageSync('driverInfo')) }, }); }, fail: (err) => { console.log('sb',err); } }); }else{ startSocketConnect(uni.getStorageSync('driverInfo')) } } export function closeSocket(SocketTask) { SocketTask.close() }