|
|
@@ -20,7 +20,7 @@ class TIMPresenceManager {
|
|
|
this.userId = null;
|
|
|
this.statusCallbacks = new Map(); // 存储状态变化回调
|
|
|
this.onlineStatusCache = new Map(); // 缓存在线状态
|
|
|
- this.wsUrl = 'ws://172.20.10.2:8083/ws/chat';
|
|
|
+ this.wsUrl = 'ws://localhost:8083/ws/chat';
|
|
|
|
|
|
// TIM 状态监听器引用(用于清理)
|
|
|
this.timStatusListener = null;
|
|
|
@@ -44,13 +44,13 @@ class TIMPresenceManager {
|
|
|
this.userId = userId;
|
|
|
|
|
|
if (DEBUG_WS) {
|
|
|
- console.log('🚀 ========== 初始化 tim-presence-manager ==========');
|
|
|
- console.log('🚀 用户ID:', userId);
|
|
|
- console.log('🚀 WebSocket URL:', this.wsUrl);
|
|
|
+ console.log('?? ========== 初始化 tim-presence-manager ==========');
|
|
|
+ console.log('?? 用户ID:', userId);
|
|
|
+ console.log('?? WebSocket URL:', this.wsUrl);
|
|
|
}
|
|
|
|
|
|
// 连接 WebSocket(接收服务端推送的状态变更)
|
|
|
- if (DEBUG_WS) console.log('🚀 开始连接 WebSocket...');
|
|
|
+ if (DEBUG_WS) console.log('?? 开始连接 WebSocket...');
|
|
|
this.connectWebSocket();
|
|
|
|
|
|
console.log('✅ tim-presence-manager 初始化完成(WebSocket连接中...)');
|
|
|
@@ -64,7 +64,7 @@ class TIMPresenceManager {
|
|
|
try {
|
|
|
const wsUrl = `${this.wsUrl}?userId=${this.userId}`;
|
|
|
if (DEBUG_WS) {
|
|
|
- console.log('🔌 准备连接 WebSocket:', wsUrl);
|
|
|
+ console.log('?? 准备连接 WebSocket:', wsUrl);
|
|
|
console.log(' 当前用户ID:', this.userId);
|
|
|
console.log(' WebSocket URL:', wsUrl);
|
|
|
}
|
|
|
@@ -93,7 +93,7 @@ class TIMPresenceManager {
|
|
|
// 使用 SocketTask 对象的监听器(推荐方式)
|
|
|
this.ws.onOpen((res) => {
|
|
|
if (DEBUG_WS) {
|
|
|
- console.log('🎉 ========== WebSocket 连接成功 ==========');
|
|
|
+ console.log('?? ========== WebSocket 连接成功 ==========');
|
|
|
console.log(' 响应数据:', res);
|
|
|
console.log(' 用户ID:', this.userId);
|
|
|
console.log(' 连接URL:', wsUrl);
|
|
|
@@ -120,7 +120,7 @@ class TIMPresenceManager {
|
|
|
|
|
|
// 监听消息
|
|
|
this.ws.onMessage((res) => {
|
|
|
- if (DEBUG_WS) console.log('📨 收到WebSocket消息:', res.data);
|
|
|
+ if (DEBUG_WS) console.log('?? 收到WebSocket消息:', res.data);
|
|
|
this.handleMessage(res.data);
|
|
|
});
|
|
|
|
|
|
@@ -146,7 +146,7 @@ class TIMPresenceManager {
|
|
|
// 监听关闭
|
|
|
this.ws.onClose((res) => {
|
|
|
if (DEBUG_WS) {
|
|
|
- console.log('🔌 ========== WebSocket 连接关闭 ==========');
|
|
|
+ console.log('?? ========== WebSocket 连接关闭 ==========');
|
|
|
console.log(' 关闭信息:', res);
|
|
|
console.log(' 关闭码:', res?.code);
|
|
|
console.log(' 关闭原因:', res?.reason);
|
|
|
@@ -184,7 +184,7 @@ class TIMPresenceManager {
|
|
|
|
|
|
// 监听 IM 连接状态变化
|
|
|
this.timConnectListener = (event) => {
|
|
|
- if (DEBUG_WS) console.log('📡 TIM 连接状态变更:', event.data.state);
|
|
|
+ if (DEBUG_WS) console.log('?? TIM 连接状态变更:', event.data.state);
|
|
|
|
|
|
let imStatus = 'offline';
|
|
|
|
|
|
@@ -220,7 +220,7 @@ class TIMPresenceManager {
|
|
|
|
|
|
// 监听用户状态更新事件
|
|
|
this.timStatusListener = (event) => {
|
|
|
- console.log('=== 👥 收到 TIM 用户状态更新事件 ===');
|
|
|
+ console.log('=== ?? 收到 TIM 用户状态更新事件 ===');
|
|
|
console.log(' - 事件数据:', JSON.stringify(event.data, null, 2));
|
|
|
|
|
|
const { userStatusList } = event.data;
|
|
|
@@ -290,7 +290,7 @@ class TIMPresenceManager {
|
|
|
timestamp: Date.now()
|
|
|
});
|
|
|
|
|
|
- console.log(`📤 已上报 IM 状态: ${status}`);
|
|
|
+ console.log(`?? 已上报 IM 状态: ${status}`);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -322,12 +322,12 @@ class TIMPresenceManager {
|
|
|
console.warn(' - timManager.isLogin:', timManager.isLogin);
|
|
|
|
|
|
// 使用 HTTP 轮询作为备用方案
|
|
|
- console.log('💡 启用 HTTP 轮询备用方案');
|
|
|
+ console.log('?? 启用 HTTP 轮询备用方案');
|
|
|
this.startHttpPolling(userIdList);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- console.log('📡 开始订阅用户状态...');
|
|
|
+ console.log('?? 开始订阅用户状态...');
|
|
|
console.log(' - 订阅用户列表:', userIdList);
|
|
|
console.log(' - TIM SDK 版本:', timManager.tim.VERSION);
|
|
|
|
|
|
@@ -341,7 +341,7 @@ class TIMPresenceManager {
|
|
|
|
|
|
// 订阅成功后,初始化这些用户的状态
|
|
|
if (result.data && result.data.successUserList) {
|
|
|
- console.log('📋 成功订阅的用户列表:', result.data.successUserList.length, '个');
|
|
|
+ console.log('?? 成功订阅的用户列表:', result.data.successUserList.length, '个');
|
|
|
|
|
|
result.data.successUserList.forEach(user => {
|
|
|
console.log(` - 用户 ${user.userID}:`);
|
|
|
@@ -370,7 +370,7 @@ class TIMPresenceManager {
|
|
|
|
|
|
// 如果订阅失败,启用 HTTP 轮询备用方案
|
|
|
if (error.code === 70402 || error.code === 70403) {
|
|
|
- console.log('💡 TIM 在线状态功能未开启,启用 HTTP 轮询备用方案');
|
|
|
+ console.log('?? TIM 在线状态功能未开启,启用 HTTP 轮询备用方案');
|
|
|
this.startHttpPolling(userIdList);
|
|
|
}
|
|
|
|
|
|
@@ -383,7 +383,7 @@ class TIMPresenceManager {
|
|
|
* @param {Array<String>} userIdList 用户ID列表
|
|
|
*/
|
|
|
startHttpPolling(userIdList) {
|
|
|
- console.log('🔄 启动 HTTP 轮询,间隔 30 秒');
|
|
|
+ console.log('?? 启动 HTTP 轮询,间隔 30 秒');
|
|
|
|
|
|
// 立即查询一次
|
|
|
this.pollUserStatus(userIdList);
|
|
|
@@ -401,7 +401,7 @@ class TIMPresenceManager {
|
|
|
for (const userId of userIdList) {
|
|
|
try {
|
|
|
const [err, res] = await uni.request({
|
|
|
- url: 'http://172.20.10.2:8083/api/online/checkStatus',
|
|
|
+ url: 'http://localhost:8083/api/online/checkStatus',
|
|
|
method: 'GET',
|
|
|
data: { userId }
|
|
|
});
|
|
|
@@ -429,7 +429,7 @@ class TIMPresenceManager {
|
|
|
if (this.pollingTimer) {
|
|
|
clearInterval(this.pollingTimer);
|
|
|
this.pollingTimer = null;
|
|
|
- console.log('🛑 已停止 HTTP 轮询');
|
|
|
+ console.log('?? 已停止 HTTP 轮询');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -462,7 +462,7 @@ class TIMPresenceManager {
|
|
|
switch (message.type) {
|
|
|
case 'pong': // 改为小写,匹配后端
|
|
|
// 心跳响应
|
|
|
- console.log('💓 收到心跳响应');
|
|
|
+ console.log('?? 收到心跳响应');
|
|
|
break;
|
|
|
|
|
|
case 'ONLINE':
|
|
|
@@ -499,10 +499,10 @@ class TIMPresenceManager {
|
|
|
|
|
|
this.heartbeatTimer = setInterval(() => {
|
|
|
if (this.isConnected) {
|
|
|
- console.log('💓 ========== 发送心跳PING ==========');
|
|
|
- console.log('💓 用户ID:', this.userId);
|
|
|
- console.log('💓 WebSocket连接状态:', this.isConnected);
|
|
|
- console.log('💓 发送消息:', {
|
|
|
+ console.log('?? ========== 发送心跳PING ==========');
|
|
|
+ console.log('?? 用户ID:', this.userId);
|
|
|
+ console.log('?? WebSocket连接状态:', this.isConnected);
|
|
|
+ console.log('?? 发送消息:', {
|
|
|
type: 'ping',
|
|
|
fromUserId: this.userId,
|
|
|
timestamp: Date.now()
|
|
|
@@ -514,7 +514,7 @@ class TIMPresenceManager {
|
|
|
timestamp: Date.now()
|
|
|
});
|
|
|
|
|
|
- console.log('💓 ====================================');
|
|
|
+ console.log('?? ====================================');
|
|
|
} else {
|
|
|
console.warn('⚠️ WebSocket未连接,跳过心跳');
|
|
|
}
|
|
|
@@ -589,7 +589,7 @@ class TIMPresenceManager {
|
|
|
* 通知状态变化
|
|
|
*/
|
|
|
notifyStatusChange(userId, status) {
|
|
|
- console.log(`👤 用户 ${userId} 状态变更: ${status}`);
|
|
|
+ console.log(`?? 用户 ${userId} 状态变更: ${status}`);
|
|
|
|
|
|
const callbacks = this.statusCallbacks.get(userId);
|
|
|
if (callbacks && callbacks.length > 0) {
|
|
|
@@ -620,11 +620,11 @@ class TIMPresenceManager {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- console.log('🔄 将在5秒后重连...');
|
|
|
+ console.log('?? 将在5秒后重连...');
|
|
|
this.reconnectTimer = setTimeout(() => {
|
|
|
this.reconnectTimer = null;
|
|
|
if (!this.isConnected && this.userId) {
|
|
|
- console.log('🔄 尝试重连...');
|
|
|
+ console.log('?? 尝试重连...');
|
|
|
this.connectWebSocket();
|
|
|
}
|
|
|
}, this.reconnectInterval);
|
|
|
@@ -638,7 +638,7 @@ class TIMPresenceManager {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- console.log(`📤 发送队列中的 ${this.messageQueue.length} 条消息`);
|
|
|
+ console.log(`?? 发送队列中的 ${this.messageQueue.length} 条消息`);
|
|
|
|
|
|
while (this.messageQueue.length > 0) {
|
|
|
const message = this.messageQueue.shift();
|