fcr-core
Version:
Core APIs for building online scenes
74 lines (64 loc) • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ROOM_NON_RETRYABLE_ERRORS = exports.ROOM_JOIN_NON_RETRYABLE_ERRORS = void 0;
exports.canRetryError = canRetryError;
exports.canRetryJoinError = canRetryJoinError;
require("core-js/modules/web.dom-collections.iterator.js");
var _imports = require("../imports");
/**
* 通用重试辅助工具
*
* 提供可复用的重试逻辑判断机制
*/
/**
* 房间相关的不可重试错误码
*/
const ROOM_NON_RETRYABLE_ERRORS = exports.ROOM_NON_RETRYABLE_ERRORS = [
// 网络相关的不可重试错误码
100050051,
// ap 探测失败
300000010,
// 加入rtc频道超时了(rtc私有化)
400000010,
// 加入web rtc频道超时了(rtc私有化)
// 房间相关的不可重试错误码
720410100,
// 房间已销毁
720404100,
// 房间不存在
732403100,
// 无加入权限,如:房间已锁定
732403101,
// 房间不存在或密码错误
730403100 // 被永久踢出房间
];
/**
* 房间加入时的所有不可重试错误码(包含网络和房间错误)
*/
const ROOM_JOIN_NON_RETRYABLE_ERRORS = exports.ROOM_JOIN_NON_RETRYABLE_ERRORS = [...ROOM_NON_RETRYABLE_ERRORS];
/**
* 判断错误是否可以重试
* @param error 错误对象
* @param nonRetryableErrorCodes 不可重试的错误代码列表
* @returns 是否可以重试
*/
function canRetryError(error, nonRetryableErrorCodes) {
// 如果不是已知的错误类型,允许重试
if (!(error instanceof _imports.FcrError)) {
return true;
}
// 获取错误代码
const errorCode = typeof error.code === 'string' ? parseInt(error.code, 10) : error.code;
// 检查是否在不可重试列表中
return !nonRetryableErrorCodes.includes(errorCode);
}
/**
* 判断加入房间错误是否可以重试
* @param error 错误对象
* @returns 是否可以重试
*/
function canRetryJoinError(error) {
return canRetryError(error, ROOM_JOIN_NON_RETRYABLE_ERRORS);
}