UNPKG

@tencentcloud/roomkit-web-vue3

Version:

<h1 align="center"> TUIRoomKit</h1> Conference (TUIRoomKit) is a product suitable for multi-person audio and video conversation scenarios such as business meetings, webinars, and online education. By integrating this product, you can add room management,

196 lines (195 loc) 7.03 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); import { TUIErrorCode } from "@tencentcloud/tuiroom-engine-js"; import { EventType } from "../types.mjs"; import { isElectron } from "../../utils/environment.mjs"; class ErrorHandler { constructor(service) { __publicField(this, "service"); __publicField(this, "handlerMap", { createRoom: this.handleCreateRoomError.bind(this), enterRoom: this.handleEnterRoomError.bind(this), onError: this.handleOnError.bind(this) }); __publicField(this, "mediaDeviceErrorHandler", null); this.service = service; } handleError(error, functionName) { this.handlerMap[functionName] && this.handlerMap[functionName](error); } handleEnterRoomError(error) { if (error.code === TUIErrorCode.ERR_NEED_PASSWORD) { this.service.emit(EventType.ROOM_NEED_PASSWORD, error.code); return; } if (error.code === TUIErrorCode.ERR_WRONG_PASSWORD) { this.service.emit(EventType.ROOM_NOTICE_MESSAGE, { type: "error", message: this.service.t("Wrong password") }); return; } let message = ""; switch (error.code) { case TUIErrorCode.ERR_ROOM_ID_NOT_EXIST: message = "The room does not exist, please confirm the room number or create a room!"; break; default: message = "Failed to enter the meeting"; } this.service.emit(EventType.ROOM_NOTICE_MESSAGE_BOX, { title: this.service.t("Note"), message: this.service.t(message), confirmButtonText: this.service.t("Sure"), callback: async () => { this.service.emit(EventType.ROOM_ERROR, { code: error.code, message: error.message }); this.service.roomStore.reset(); } }); } handleCreateRoomError(error) { this.service.emit(EventType.ROOM_NOTICE_MESSAGE_BOX, { title: this.service.t("Note"), message: this.service.t("Failed to initiate meeting"), confirmButtonText: this.service.t("Sure"), callback: async () => { this.service.emit(EventType.ROOM_ERROR, { code: error.code, message: error.message }); this.service.resetStore(); } }); } handleOnError(error) { if (error.message === "enter trtc room failed , error code : -1") { this.service.emit(EventType.ROOM_NOTICE_MESSAGE_BOX, { type: "warning", message: this.service.t("Failed to enter the meeting"), callback: () => { this.service.emit(EventType.ROOM_ERROR, { code: error.code, message: error.message }); this.service.resetStore(); } }); } if (error.code && String(error.code).indexOf("-11") === 0) { if (!this.mediaDeviceErrorHandler) { this.mediaDeviceErrorHandler = new MediaDeviceErrorHandler( this.service ); } this.mediaDeviceErrorHandler.handleError(error); } } } class MediaDeviceErrorHandler { constructor(service) { __publicField(this, "service"); this.service = service; } getMediaDeviceErrorTitle(deviceType) { return this.service.t("Unable to use the device", { deviceType: this.service.t(deviceType) }); } getMediaDeviceErrorMsg(deviceType) { return this.service.t( "media device failed to open, please check the media device and try again", { deviceType: this.service.t(deviceType) } ); } getMediaDeviceNotAuthorizedMsg(deviceType) { return this.service.t( "The current device is not authorized, please allow access to the device permissions", { deviceType: this.service.t(deviceType) } ); } getMediaDeviceOccupiedMsg(deviceType) { return this.service.t( "The current device is occupied by other apps, try to close other apps or change the device", { deviceType: this.service.t(deviceType) } ); } getTurnOnDevicePrivilegesTitle(deviceType) { return this.service.t("Turn on device privileges", { deviceType: this.service.t(deviceType) }); } getTurnOnDevicePrivilegesMsg(deviceType) { return this.service.t( 'You can go to "System Preferences - Security & Privacy - Device" to enable device permissions', { deviceType: this.service.t(deviceType) } ); } handleError(error) { let mediaType; let mediaErrorTitle = ""; let mediaErrorMsg = ""; let cancelButtonText = ""; let confirmButtonText = ""; let callback = null; switch (error.code) { case TUIErrorCode.ERR_CAMERA_START_FAILED: case TUIErrorCode.ERR_MICROPHONE_START_FAILED: mediaType = error.code === TUIErrorCode.ERR_CAMERA_START_FAILED ? "camera" : "microphone"; mediaErrorTitle = this.getMediaDeviceErrorTitle(mediaType); mediaErrorMsg = this.getMediaDeviceErrorMsg(mediaType); break; case TUIErrorCode.ERR_CAMERA_NOT_AUTHORIZED: case TUIErrorCode.ERR_MICROPHONE_NOT_AUTHORIZED: mediaType = error.code === TUIErrorCode.ERR_CAMERA_NOT_AUTHORIZED ? "camera" : "microphone"; if (isElectron) { mediaErrorTitle = this.getTurnOnDevicePrivilegesTitle(mediaType); mediaErrorMsg = this.getTurnOnDevicePrivilegesMsg(mediaType); cancelButtonText = this.service.t("Cancel"); confirmButtonText = this.service.t("Go to Settings"); callback = (action) => { if (action === "confirm") { this.goToPermissionSettings(mediaType); } }; } else { mediaErrorTitle = this.getMediaDeviceErrorTitle(mediaType); mediaErrorMsg = this.getMediaDeviceNotAuthorizedMsg(mediaType); } break; case TUIErrorCode.ERR_CAMERA_OCCUPIED: case TUIErrorCode.ERR_MICROPHONE_OCCUPIED: mediaType = error.code === TUIErrorCode.ERR_CAMERA_OCCUPIED ? "camera" : "microphone"; mediaErrorTitle = this.getMediaDeviceErrorTitle(mediaType); mediaErrorMsg = this.getMediaDeviceOccupiedMsg(mediaType); break; } if (mediaErrorMsg) { this.service.emit(EventType.ROOM_NOTICE_MESSAGE_BOX, { type: "error", title: mediaErrorTitle, message: mediaErrorMsg, cancelButtonText, confirmButtonText: confirmButtonText || this.service.t("I got it"), callback }); } } goToPermissionSettings(deviceType) { const shell = { openExternal: Function }; const privacyTypeObj = { camera: "Privacy_Camera", microphone: "Privacy_Microphone", screenShare: "Privacy_ScreenCapture" }; shell.openExternal( `x-apple.systempreferences:com.apple.preference.security?${privacyTypeObj[deviceType]}` ); } } export { ErrorHandler };