| | |
| | | import Taro from '@tarojs/taro'; |
| | | import { getOrCreateLocalId, getStorage } from './tools'; |
| | | import { getStorage } from './tools'; |
| | | import { _UID } from '../constants/api'; |
| | | |
| | | type MessageCallback = (data: any) => void; |
| | |
| | | this.url = url; |
| | | console.log(`正在连接 WebSocket: ${url}`); |
| | | |
| | | const uid = await getStorage(_UID) || await getOrCreateLocalId(); |
| | | const uid = await getStorage(_UID) || '-1'; |
| | | const task = Taro.connectSocket({ |
| | | header: { |
| | | 'XP-Uid': uid.toString(), |
| | | 'XP-Uid': 1 || uid.toString(), |
| | | }, |
| | | url: this.url, |
| | | success: () => { }, |
| | |
| | | this.isConnected = true; |
| | | this.reconnectAttempts = 0; |
| | | this.startHeartbeat(); |
| | | const uid = await getStorage(_UID) || await getOrCreateLocalId(); |
| | | this.send({ type: 'auth', appUserId: uid, timestamp: Date.now() }); |
| | | const uid = await getStorage(_UID) || '-1'; |
| | | this.send({ type: 'auth', appUserId: '12345678', timestamp: Date.now() }); |
| | | this.notifyListeners('open', { status: 'connected' }); |
| | | }); |
| | | |