公共模块回调接口 JCommonCallback

定义了菊风云通信服务的主要回调事件 通过实现此接口来接收和处理各种系统事件通知,如登录状态变更、消息接收和错误通知等

interface JCommonCallback {
    onLogin?: (result: boolean, reason: JClientReason) => void;
    onLogout?: (reason: JClientReason) => void;
    onOnlineMessageSendResult?: (result: boolean, operatorId: number) => void;
    onOnlineMessageReceived?: (message: string, userId: string) => void;
    onMessageInCallReceived?: (
        type: string,
        content: string,
        fromUserId: string,
    ) => void;
    onUploadFileResult?: (fileName: string, response: string) => void;
    onUploadFileError?: (fileName: string, error: Error) => void;
    onError?: (errorCode: string, errorCodeDetail: string) => void;
    onViewEvent?: (viewEvent: TALK_END_CLICK) => boolean;
}

Properties

onLogin?: (result: boolean, reason: JClientReason) => void

登录结果回调

Type declaration

    • (result: boolean, reason: JClientReason): void
    • Parameters

      • result: boolean

        登录结果

      • reason: JClientReason

        登录失败原因

      Returns void

当用户尝试登录系统后,此方法会被调用以通知登录结果

  • 当result为true时,表示登录成功
  • 当result为false时,表示登录失败,具体原因在reason参数中指明

JClientReason 可能的错误原因枚举

onLogout?: (reason: JClientReason) => void

登出结果回调

Type declaration

当用户登出系统后,此方法会被调用以通知登出的原因 无论是主动登出还是被动登出(如会话过期、网络断开等),都会触发此回调

JClientReason 可能的登出原因枚举

onOnlineMessageSendResult?: (result: boolean, operatorId: number) => void

在线消息发送结果回调

Type declaration

    • (result: boolean, operatorId: number): void
    • Parameters

      • result: boolean

        发送结果是否成功

      • operatorId: number

        操作ID,与发送消息时返回的ID对应

      Returns void

当用户发送在线消息后,此方法会被调用以通知消息发送结果

  • 当result为true时,表示消息发送成功
  • 当result为false时,表示消息发送失败
  • operatorId对应 JRTCClient#sendOnlineMessage 的返回值,用于关联发送请求和结果
onOnlineMessageReceived?: (message: string, userId: string) => void

收到在线消息回调

Type declaration

    • (message: string, userId: string): void
    • Parameters

      • message: string

        接收到的消息内容

      • userId: string

        消息发送者的用户ID

      Returns void

当收到其他用户发送的在线消息时,此方法会被调用 通过此回调可以接收到其他用户发送的文本消息内容和发送者信息

onMessageInCallReceived?: (
    type: string,
    content: string,
    fromUserId: string,
) => void

接收通话中消息回调

Type declaration

    • (type: string, content: string, fromUserId: string): void
    • Parameters

      • type: string

        消息类型

      • content: string

        消息内容

      • fromUserId: string

        消息发送者的用户ID

      Returns void

当在通话过程中收到消息时,此方法会被调用 用于接收通话中的即时消息,如文本聊天、控制指令等

onUploadFileResult?: (fileName: string, response: string) => void

文件上传成功回调

Type declaration

    • (fileName: string, response: string): void
    • Parameters

      • fileName: string

        上传成功的文件名

      • response: string

        服务器返回的响应内容

      Returns void

当文件上传成功后,此方法会被调用 文件上传成功后,服务器会返回相关信息,如文件访问URL等,通过response参数返回

onUploadFileError?: (fileName: string, error: Error) => void

文件上传失败回调

Type declaration

    • (fileName: string, error: Error): void
    • Parameters

      • fileName: string

        上传失败的文件名

      • error: Error

        上传失败的错误信息

      Returns void

当文件上传失败时,此方法会被调用 文件上传过程中若发生错误,会通过此回调通知上传失败原因

onError?: (errorCode: string, errorCodeDetail: string) => void

错误事件回调

Type declaration

    • (errorCode: string, errorCodeDetail: string): void
    • Parameters

      • errorCode: string

        错误码

      • errorCodeDetail: string

        错误详细描述

      Returns void

当系统发生错误时,此方法会被调用以提供错误信息

  • 该接口主要用于问题定位和调试
  • 请勿在业务逻辑中依赖此回调,因为部分错误码可能存在不合理情况
  • errorCode包含根因码,可用于快速定位问题类型
onViewEvent?: (viewEvent: TALK_END_CLICK) => boolean

UI事件通知回调

Type declaration

当UI层发生特定事件时,此方法会被调用

  • 返回true表示该事件由应用外部处理,插件内部无需处理
  • 返回false表示由插件内部进行默认处理

JViewEvent 可能的UI事件类型枚举