@easemob-community/callkit-vue3 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +208 -0
  3. package/dist/callkit-vue3.css +1 -0
  4. package/dist/components/EasemobChatCallKitProvider.vue.d.ts +18 -0
  5. package/dist/components/EasemobChatMiniWindow.vue.d.ts +11 -0
  6. package/dist/components/InvitationNotification.vue.d.ts +2 -0
  7. package/dist/components/multiCall/EasemobChatGroupMemberList.vue.d.ts +19 -0
  8. package/dist/components/multiCall/EasemobChatMultiCall.vue.d.ts +69 -0
  9. package/dist/components/singleCall/CallControls.vue.d.ts +18 -0
  10. package/dist/components/singleCall/CallInfoBar.vue.d.ts +5 -0
  11. package/dist/components/singleCall/EasemobChatCallStream.vue.d.ts +12 -0
  12. package/dist/components/singleCall/EasemobChatCallWaiting.vue.d.ts +10 -0
  13. package/dist/components/singleCall/EasemobChatSingleCall.vue.d.ts +28 -0
  14. package/dist/composables/useAnswerCall.d.ts +10 -0
  15. package/dist/composables/useCallKit.d.ts +2 -0
  16. package/dist/composables/useCallKitCore.d.ts +998 -0
  17. package/dist/composables/useCallKitEvents.d.ts +42 -0
  18. package/dist/composables/useDraggable.d.ts +90 -0
  19. package/dist/composables/useEndCall.d.ts +15 -0
  20. package/dist/composables/useParticipants.d.ts +15 -0
  21. package/dist/composables/useRtcService.d.ts +80 -0
  22. package/dist/config/assets.d.ts +43 -0
  23. package/dist/core/events/CallKitEventBus.d.ts +40 -0
  24. package/dist/core/events/helpers.d.ts +59 -0
  25. package/dist/core/events/types.d.ts +264 -0
  26. package/dist/core/sdk/imSDK/index.d.ts +4 -0
  27. package/dist/index.d.ts +33 -0
  28. package/dist/index.js +7806 -0
  29. package/dist/index.umd.js +72 -0
  30. package/dist/modules/groupCall/components/CallKitIcon.vue.d.ts +12 -0
  31. package/dist/modules/groupCall/components/GroupCallShell.vue.d.ts +34 -0
  32. package/dist/modules/groupCall/components/MainVideoLayout.vue.d.ts +32 -0
  33. package/dist/modules/groupCall/components/ParticipantTile.vue.d.ts +12 -0
  34. package/dist/modules/groupCall/components/VideoGrid.vue.d.ts +29 -0
  35. package/dist/modules/groupCall/components/iconRegistry.d.ts +2 -0
  36. package/dist/modules/groupCall/index.d.ts +7 -0
  37. package/dist/modules/groupCall/media/RtcMediaBridge.d.ts +26 -0
  38. package/dist/modules/groupCall/signaling/GroupCallSignalingAdapter.d.ts +29 -0
  39. package/dist/modules/groupCall/types.d.ts +37 -0
  40. package/dist/modules/groupCall/viewModel/GroupCallStore.d.ts +345 -0
  41. package/dist/modules/groupCall/viewModel/useGroupCallViewModel.d.ts +35 -0
  42. package/dist/services/CallService.d.ts +15 -0
  43. package/dist/services/RtcAdapter.d.ts +11 -0
  44. package/dist/services/RtcService.d.ts +187 -0
  45. package/dist/services/UserProfileService.d.ts +38 -0
  46. package/dist/store/callTimer.d.ts +33 -0
  47. package/dist/store/chatClient.d.ts +5335 -0
  48. package/dist/store/globalCall.d.ts +34 -0
  49. package/dist/store/index.d.ts +1 -0
  50. package/dist/store/rtcChannel.d.ts +42 -0
  51. package/dist/store/types.d.ts +50 -0
  52. package/dist/types/callstate.types.d.ts +61 -0
  53. package/dist/types/signal.types.d.ts +187 -0
  54. package/dist/types.d.ts +103 -0
  55. package/dist/utils/callUtils.d.ts +15 -0
  56. package/dist/utils/imSdkAdapter.d.ts +29 -0
  57. package/dist/utils/index.d.ts +2 -0
  58. package/dist/utils/logger.d.ts +122 -0
  59. package/dist/utils/loggerDb.d.ts +41 -0
  60. package/dist/utils/ringtone.d.ts +20 -0
  61. package/dist/vite-env.d.ts +12 -0
  62. package/package.json +60 -0
@@ -0,0 +1,42 @@
1
+ import { CallKitEventType, CallKitEventHandler, CallRecord } from '../core/events/types';
2
+ export declare function useCallKitEvents(): {
3
+ on: <T extends CallKitEventType>(event: T, handler: CallKitEventHandler<T>) => (() => void);
4
+ once: <T extends CallKitEventType>(event: T, handler: CallKitEventHandler<T>) => (() => void);
5
+ off: <T extends CallKitEventType>(event: T, handler: CallKitEventHandler<T>) => void;
6
+ onStatusChanged: (handler: CallKitEventHandler<"statusChanged">) => (() => void);
7
+ onIncomingCall: (handler: CallKitEventHandler<"incomingCall">) => (() => void);
8
+ onCallInvited: (handler: CallKitEventHandler<"callInvited">) => (() => void);
9
+ onCallStarted: (handler: CallKitEventHandler<"callStarted">) => (() => void);
10
+ onCallEnded: (handler: CallKitEventHandler<"callEnded">) => (() => void);
11
+ onCallCanceled: (handler: CallKitEventHandler<"callCanceled">) => (() => void);
12
+ onCallRefused: (handler: CallKitEventHandler<"callRefused">) => (() => void);
13
+ onCallTimeout: (handler: CallKitEventHandler<"callTimeout">) => (() => void);
14
+ onCallBusy: (handler: CallKitEventHandler<"callBusy">) => (() => void);
15
+ onSingleCallInvited: (handler: CallKitEventHandler<"singleCallInvited">) => (() => void);
16
+ onSingleCallStarted: (handler: CallKitEventHandler<"singleCallStarted">) => (() => void);
17
+ onSingleCallConnected: (handler: CallKitEventHandler<"singleCallConnected">) => (() => void);
18
+ onSingleCallEnded: (handler: CallKitEventHandler<"singleCallEnded">) => (() => void);
19
+ onSingleCallCanceled: (handler: CallKitEventHandler<"singleCallCanceled">) => (() => void);
20
+ onSingleCallRefused: (handler: CallKitEventHandler<"singleCallRefused">) => (() => void);
21
+ onSingleCallTimeout: (handler: CallKitEventHandler<"singleCallTimeout">) => (() => void);
22
+ onSingleCallBusy: (handler: CallKitEventHandler<"singleCallBusy">) => (() => void);
23
+ onGroupCallInvited: (handler: CallKitEventHandler<"groupCallInvited">) => (() => void);
24
+ onGroupCallStarted: (handler: CallKitEventHandler<"groupCallStarted">) => (() => void);
25
+ onGroupCallConnected: (handler: CallKitEventHandler<"groupCallConnected">) => (() => void);
26
+ onGroupCallEnded: (handler: CallKitEventHandler<"groupCallEnded">) => (() => void);
27
+ onGroupCallCanceled: (handler: CallKitEventHandler<"groupCallCanceled">) => (() => void);
28
+ onGroupCallRefused: (handler: CallKitEventHandler<"groupCallRefused">) => (() => void);
29
+ onGroupCallTimeout: (handler: CallKitEventHandler<"groupCallTimeout">) => (() => void);
30
+ onGroupCallBusy: (handler: CallKitEventHandler<"groupCallBusy">) => (() => void);
31
+ onParticipantJoined: (handler: CallKitEventHandler<"participantJoined">) => (() => void);
32
+ onParticipantLeft: (handler: CallKitEventHandler<"participantLeft">) => (() => void);
33
+ onCallDurationUpdated: (handler: CallKitEventHandler<"callDurationUpdated">) => (() => void);
34
+ onCallError: (handler: CallKitEventHandler<"callError">) => (() => void);
35
+ getCallRecord: () => CallRecord | null;
36
+ clearCallRecord: () => void;
37
+ _unsubscribeCallEnded: () => void;
38
+ };
39
+ /**
40
+ * useCallKitEvents 返回类型
41
+ */
42
+ export type UseCallKitEventsReturn = ReturnType<typeof useCallKitEvents>;
@@ -0,0 +1,90 @@
1
+ import { Ref, CSSProperties } from 'vue';
2
+ export interface DraggableOptions {
3
+ /** 初始 X 坐标 */
4
+ initialX?: number;
5
+ /** 初始 Y 坐标 */
6
+ initialY?: number;
7
+ /** 是否初始居中(优先级高于 initialX/initialY) */
8
+ centered?: boolean;
9
+ /** 元素宽度(用于居中和边界计算) */
10
+ width?: number;
11
+ /** 元素高度(用于居中和边界计算) */
12
+ height?: number;
13
+ /** 是否启用边界限制 */
14
+ boundary?: boolean;
15
+ /** 边界内边距(像素) */
16
+ boundaryPadding?: number;
17
+ /** 拖拽开始时回调 */
18
+ onDragStart?: () => void;
19
+ /** 拖拽结束时回调 */
20
+ onDragEnd?: () => void;
21
+ }
22
+ export interface DraggableReturn {
23
+ /** 元素引用 */
24
+ elementRef: Ref<HTMLElement | null>;
25
+ /** 是否正在拖拽 */
26
+ isDragging: Ref<boolean>;
27
+ /** 是否发生过拖拽 */
28
+ hasDragged: Ref<boolean>;
29
+ /** 当前位置(左上角坐标) */
30
+ position: Ref<{
31
+ x: number;
32
+ y: number;
33
+ }>;
34
+ /** 样式对象(用于绑定到元素) */
35
+ style: Ref<CSSProperties>;
36
+ /** 开始拖拽事件处理 */
37
+ startDrag: (e: MouseEvent | TouchEvent) => void;
38
+ /** 停止拖拽 */
39
+ stopDrag: () => void;
40
+ }
41
+ /**
42
+ * 拖拽组合式函数
43
+ * @param options - 拖拽配置选项
44
+ * @returns 拖拽相关状态和操作方法
45
+ *
46
+ * @example
47
+ * ```vue
48
+ * <template>
49
+ * <div
50
+ * ref="elementRef"
51
+ * :style="style"
52
+ * @mousedown="startDrag"
53
+ * >
54
+ * 可拖拽内容
55
+ * </div>
56
+ * </template>
57
+ *
58
+ * <script setup>
59
+ * import { useDraggable } from './useDraggable'
60
+ *
61
+ * // 居中显示
62
+ * const { elementRef, style, startDrag } = useDraggable({
63
+ * centered: true,
64
+ * width: 360,
65
+ * height: 640,
66
+ * boundary: true
67
+ * })
68
+ *
69
+ * // 固定位置
70
+ * const { elementRef, style, startDrag } = useDraggable({
71
+ * initialX: 100,
72
+ * initialY: 100,
73
+ * boundary: true
74
+ * })
75
+ * </script>
76
+ * ```
77
+ */
78
+ export declare function useDraggable(options?: DraggableOptions): DraggableReturn;
79
+ /**
80
+ * 居中定位的拖拽 Hook
81
+ * 适用于需要初始居中的弹窗类组件
82
+ * @deprecated 直接使用 useDraggable({ centered: true, width, height })
83
+ */
84
+ export declare function useCenteredDraggable(elementWidth: number, elementHeight: number, options?: Omit<DraggableOptions, 'centered' | 'width' | 'height'>): DraggableReturn;
85
+ /**
86
+ * 角落定位的拖拽 Hook
87
+ * 适用于悬浮窗、通知等组件
88
+ */
89
+ export declare function useCornerDraggable(corner: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right', elementWidth: number, elementHeight: number, offset?: number, options?: Omit<DraggableOptions, 'initialX' | 'initialY' | 'centered' | 'width' | 'height'>): DraggableReturn;
90
+ export default useDraggable;
@@ -0,0 +1,15 @@
1
+ import { HANGUP_REASON } from '../types/callstate.types';
2
+ /**
3
+ * 通话结束相关功能的组合式函数
4
+ * 信令由 callkit-core 处理,资源清理由 CallService 处理
5
+ */
6
+ export declare function useEndCall(): {
7
+ hangup: (reason?: HANGUP_REASON) => Promise<void>;
8
+ hangupCall: () => Promise<void>;
9
+ cancelCall: () => Promise<void>;
10
+ handleRemoteCancel: () => Promise<void>;
11
+ handleRemoteRefuse: () => Promise<void>;
12
+ handleAbnormalEnd: () => Promise<void>;
13
+ canHangup: () => boolean;
14
+ canCancel: () => boolean;
15
+ };
@@ -0,0 +1,15 @@
1
+ export interface Participant {
2
+ userId: string;
3
+ userName: string;
4
+ avatar?: string;
5
+ isMuted: boolean;
6
+ isInviting: boolean;
7
+ hasJoined: boolean;
8
+ }
9
+ /**
10
+ * 自动生成参与者列表的 composable
11
+ * @deprecated 旧架构已废弃,群组通话请使用 useGroupCallViewModel / GroupCallStore
12
+ */
13
+ export declare function useParticipants(currentUserId?: string): {
14
+ participants: import('vue').ComputedRef<Participant[]>;
15
+ };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * RTC服务组合式API - useRtcService
3
+ *
4
+ * 职责:
5
+ * 1. 提供组合式API访问RtcService
6
+ * 2. 管理音视频设备的生命周期
7
+ * 3. 提供类型安全的音视频操作接口
8
+ * 4. 自动处理音视频资源的清理
9
+ *
10
+ * 使用方式:
11
+ * ```typescript
12
+ * import { useRtcService } from '@easemob-community/callkit-vue3'
13
+ *
14
+ * export default {
15
+ * setup() {
16
+ * const {
17
+ * localStream,
18
+ * remoteStreams,
19
+ * isVideoEnabled,
20
+ * isAudioEnabled,
21
+ * toggleVideo,
22
+ * toggleAudio,
23
+ * switchCamera,
24
+ * switchMicrophone
25
+ * } = useRtcService()
26
+ *
27
+ * // 控制视频开关
28
+ * const handleToggleVideo = async () => {
29
+ * await toggleVideo()
30
+ * }
31
+ *
32
+ * // 监听本地流变化
33
+ * watch(() => localStream.value, (newStream) => {
34
+ * if (newStream) {
35
+ * // 显示本地视频
36
+ * }
37
+ * })
38
+ *
39
+ * // 监听远程流
40
+ * watch(() => remoteStreams.value, (streams) => {
41
+ * // 更新远程视频显示
42
+ * }, { deep: true })
43
+ * }
44
+ * }
45
+ * ```
46
+ */
47
+ export declare function useRtcService(): {
48
+ localStream: import('vue').ComputedRef<{
49
+ readonly active: boolean;
50
+ readonly id: string;
51
+ onaddtrack: ((this: MediaStream, ev: MediaStreamTrackEvent) => any) | null;
52
+ onremovetrack: ((this: MediaStream, ev: MediaStreamTrackEvent) => any) | null;
53
+ addTrack: (track: MediaStreamTrack) => void;
54
+ clone: () => MediaStream;
55
+ getAudioTracks: () => MediaStreamTrack[];
56
+ getTrackById: (trackId: string) => MediaStreamTrack | null;
57
+ getTracks: () => MediaStreamTrack[];
58
+ getVideoTracks: () => MediaStreamTrack[];
59
+ removeTrack: (track: MediaStreamTrack) => void;
60
+ addEventListener: {
61
+ <K extends keyof MediaStreamEventMap>(type: K, listener: (this: MediaStream, ev: MediaStreamEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
62
+ (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
63
+ };
64
+ removeEventListener: {
65
+ <K extends keyof MediaStreamEventMap>(type: K, listener: (this: MediaStream, ev: MediaStreamEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
66
+ (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
67
+ };
68
+ dispatchEvent: (event: Event) => boolean;
69
+ }>;
70
+ isVideoEnabled: import('vue').ComputedRef<boolean>;
71
+ isAudioEnabled: import('vue').ComputedRef<boolean>;
72
+ isConnected: import('vue').ComputedRef<boolean>;
73
+ toggleVideo: (enabled?: boolean) => Promise<boolean>;
74
+ toggleAudio: (enabled?: boolean) => Promise<boolean>;
75
+ switchCamera: (deviceId?: string) => Promise<boolean>;
76
+ switchMicrophone: (deviceId?: string) => Promise<boolean>;
77
+ getLocalStream: () => MediaStream | null;
78
+ setLocalStream: (stream: MediaStream | null) => void;
79
+ reset: () => void;
80
+ };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * CallKit 静态资源配置
3
+ *
4
+ * 提供默认的静态资源 URL,支持以下方式:
5
+ * 1. 默认使用本地资源路径(/callkit-static-assets/)
6
+ * 2. 用户通过 Props 传入自定义 URL
7
+ * 3. 使用 CDN 路径(配置 CDN_BASE_URL)
8
+ */
9
+ /**
10
+ * 背景图资源
11
+ */
12
+ export declare const DEFAULT_BACKGROUND_IMAGE: string;
13
+ /**
14
+ * 图标资源路径
15
+ */
16
+ export declare const ICONS: {
17
+ readonly MIC_ON: `${string}/icons/mic_on.svg`;
18
+ readonly MIC_OFF: `${string}/icons/mic_slash.svg`;
19
+ readonly CAMERA_ON: `${string}/icons/video_camera.svg`;
20
+ readonly CAMERA_OFF: `${string}/icons/video_camera_slash.svg`;
21
+ readonly SPEAKER_ON: `${string}/icons/speaker_wave_2.svg`;
22
+ readonly SPEAKER_OFF: `${string}/icons/speaker_xmark.svg`;
23
+ readonly PHONE_HANG: `${string}/icons/phone_hang.svg`;
24
+ readonly PHONE_PICK: `${string}/icons/phone_pick.svg`;
25
+ readonly MAXIMIZE: `${string}/icons/chevron_4_all_around.svg`;
26
+ readonly MINIMIZE: `${string}/icons/chevron_4_cluster.svg`;
27
+ readonly GRID: `${string}/icons/boxes.svg`;
28
+ readonly SHARE_SCREEN: `${string}/icons/arrow_right_square_fill.svg`;
29
+ readonly PERSON_ADD: `${string}/icons/person_add_fill.svg`;
30
+ readonly DEFAULT_AVATAR: `${string}/images/default_avatar.png`;
31
+ };
32
+ /**
33
+ * 获取带回退的资源 URL
34
+ * @param customUrl 用户自定义 URL
35
+ * @param defaultUrl 默认 URL
36
+ * @returns 最终使用的 URL
37
+ */
38
+ export declare function getAssetUrl(customUrl: string | undefined, defaultUrl: string): string;
39
+ /**
40
+ * 检查资源是否可访问(用于调试)
41
+ * @param url 资源 URL
42
+ */
43
+ export declare function checkAssetAvailable(url: string): Promise<boolean>;
@@ -0,0 +1,40 @@
1
+ import { CallKitEventType, CallKitEventPayloads, CallKitEventHandler } from './types';
2
+ /**
3
+ * CallKit 轻量级事件总线
4
+ * 职责:提供类型安全的发布/订阅机制,供 CallKit 内部模块和用户代码统一监听通话生命周期事件。
5
+ *
6
+ * 不依赖外部库(mitt/EventEmitter),内部使用 Map + Set 实现。
7
+ */
8
+ declare class CallKitEventBus {
9
+ private listeners;
10
+ /**
11
+ * 订阅事件。返回解绑函数,可在组件卸载时调用。
12
+ */
13
+ on<T extends CallKitEventType>(event: T, handler: CallKitEventHandler<T>): () => void;
14
+ /**
15
+ * 一次性订阅。触发后自动解绑。
16
+ */
17
+ once<T extends CallKitEventType>(event: T, handler: CallKitEventHandler<T>): () => void;
18
+ /**
19
+ * 取消订阅事件。
20
+ */
21
+ off<T extends CallKitEventType>(event: T, handler: CallKitEventHandler<T>): void;
22
+ /**
23
+ * 触发事件。所有错误被吞掉,避免一个 handler 异常影响其他 handler。
24
+ */
25
+ emit<T extends CallKitEventType>(event: T, payload: CallKitEventPayloads[T]): void;
26
+ /**
27
+ * 清空指定事件的所有订阅,或清空全部。
28
+ */
29
+ clear(event?: CallKitEventType): void;
30
+ /**
31
+ * 获取指定事件的订阅者数量。
32
+ */
33
+ listenerCount(event: CallKitEventType): number;
34
+ }
35
+ /**
36
+ * CallKit 全局事件总线实例
37
+ * 单例,可在 composable、store、service 中直接 import 使用。
38
+ */
39
+ export declare const callKitEventBus: CallKitEventBus;
40
+ export {};
@@ -0,0 +1,59 @@
1
+ import { CALL_TYPE } from '../../types/callstate.types';
2
+ import { CallUserRole } from './types';
3
+ /**
4
+ * 获取当前登录用户的 userId
5
+ */
6
+ export declare function getCurrentUserId(): string;
7
+ /**
8
+ * 计算 conversationId
9
+ * - 群聊:groupId
10
+ * - 单聊:对方用户ID(直接对应 IM 会话 key)
11
+ */
12
+ export declare function getConversationId(params: {
13
+ callerUserId: string;
14
+ calleeUserId?: string;
15
+ groupId?: string;
16
+ }): string;
17
+ /**
18
+ * 计算当前用户的角色
19
+ */
20
+ export declare function getLocalUserRole(params: {
21
+ callerUserId: string;
22
+ groupId?: string;
23
+ }): CallUserRole;
24
+ /**
25
+ * 判断是否为群聊类型
26
+ */
27
+ export declare function isGroupCallType(type: CALL_TYPE): boolean;
28
+ /**
29
+ * 判断消息是否已过期
30
+ * @param messageTime 消息发送时间戳(毫秒或秒)
31
+ * @param thresholdMs 过期阈值(毫秒),默认 60 秒
32
+ * @returns true 表示消息已过期
33
+ */
34
+ export declare function isMessageExpired(messageTime: number, thresholdMs?: number): boolean;
35
+ /**
36
+ * 构建基础事件公共字段
37
+ *
38
+ * @param context 通话上下文信息
39
+ * @param isLocal 是否由本端行为触发
40
+ * @returns 包含 conversationId、isLocal、localUserRole 的基础字段对象
41
+ */
42
+ export declare function buildBaseEventFields(context: {
43
+ callId: string;
44
+ channel: string;
45
+ type: CALL_TYPE;
46
+ callerUserId: string;
47
+ calleeUserId?: string;
48
+ groupId?: string;
49
+ }, isLocal: boolean): {
50
+ callId: string;
51
+ channel: string;
52
+ type: CALL_TYPE;
53
+ callerUserId: string;
54
+ calleeUserId: string;
55
+ groupId: string;
56
+ conversationId: string;
57
+ isLocal: boolean;
58
+ localUserRole: CallUserRole;
59
+ };
@@ -0,0 +1,264 @@
1
+ import { CALL_TYPE, HANGUP_REASON } from '../../types/callstate.types';
2
+ /**
3
+ * CallKit 事件类型枚举
4
+ */
5
+ export type CallKitEventType = "statusChanged" | "incomingCall" | "callInvited" | "callAccepted" | "callConnected" | "callStarted" | "callEnded" | "callCanceled" | "callRefused" | "callTimeout" | "callBusy" | "singleCallInvited" | "singleCallAccepted" | "singleCallStarted" | "singleCallConnected" | "singleCallEnded" | "singleCallCanceled" | "singleCallRefused" | "singleCallTimeout" | "singleCallBusy" | "groupCallInvited" | "groupCallAccepted" | "groupCallStarted" | "groupCallConnected" | "groupCallEnded" | "groupCallCanceled" | "groupCallRefused" | "groupCallTimeout" | "groupCallBusy" | "participantJoined" | "participantLeft" | "groupCallInit" | "participantStateChanged" | "rtcReport" | "callDurationUpdated" | "callError";
6
+ /**
7
+ * 当前用户在通话中的角色
8
+ */
9
+ export type CallUserRole = "caller" | "callee" | "participant";
10
+ /**
11
+ * 基础通话信息(事件 payload 公共字段)
12
+ */
13
+ export interface BaseCallEvent {
14
+ callId: string;
15
+ channel: string;
16
+ type: CALL_TYPE;
17
+ callerUserId: string;
18
+ calleeUserId?: string;
19
+ groupId?: string;
20
+ /** 会话 ID:单聊=对方用户ID,群聊=groupId,直接对应 IM 会话 key */
21
+ conversationId: string;
22
+ /** 是否由本端行为触发(true=本端,false=对端信令/系统) */
23
+ isLocal: boolean;
24
+ /** 当前用户在本通通话中的角色 */
25
+ localUserRole: CallUserRole;
26
+ }
27
+ /**
28
+ * 通话状态变化事件
29
+ */
30
+ export interface StatusChangedEvent extends BaseCallEvent {
31
+ from: number;
32
+ to: number;
33
+ }
34
+ /**
35
+ * 收到来电邀请事件
36
+ */
37
+ export interface IncomingCallEvent extends BaseCallEvent {
38
+ callerDevId: string;
39
+ calleeDevId?: string;
40
+ groupName?: string;
41
+ groupAvatar?: string;
42
+ invitedMembers?: string[];
43
+ }
44
+ /**
45
+ * 通话邀请已发出/收到事件(邀请阶段,UI 应显示通话窗口)
46
+ */
47
+ export interface CallInvitedEvent extends BaseCallEvent {
48
+ /** 当前用户是否是主叫方 */
49
+ isCaller: boolean;
50
+ }
51
+ /**
52
+ * 通话已接受事件
53
+ */
54
+ export interface CallAcceptedEvent extends BaseCallEvent {
55
+ /** 当前用户是否是主叫方 */
56
+ isCaller: boolean;
57
+ }
58
+ /**
59
+ * 通话开始事件
60
+ */
61
+ export interface CallConnectedEvent extends BaseCallEvent {
62
+ }
63
+ export interface CallStartedEvent extends BaseCallEvent {
64
+ /** 当前用户是否是主叫方 */
65
+ isCaller: boolean;
66
+ }
67
+ /**
68
+ * 通话结束事件
69
+ */
70
+ export interface CallEndedEvent extends BaseCallEvent {
71
+ /** 挂断原因 */
72
+ reason: HANGUP_REASON;
73
+ /** 通话时长(毫秒)。若计时器未启动则为 0 */
74
+ duration: number;
75
+ /** 挂断方的 userId(谁点的挂断)。部分 reason 如系统超时可能无此字段 */
76
+ endedBy?: string;
77
+ }
78
+ /**
79
+ * 通话取消事件
80
+ */
81
+ export interface CallCanceledEvent extends BaseCallEvent {
82
+ /** 是否是远程取消(冗余保留,等价于 !isLocal) */
83
+ isRemote: boolean;
84
+ }
85
+ /**
86
+ * 通话拒绝事件
87
+ */
88
+ export interface CallRefusedEvent extends BaseCallEvent {
89
+ /** 是否是远程拒绝(冗余保留,等价于 !isLocal) */
90
+ isRemote: boolean;
91
+ }
92
+ /**
93
+ * 通话超时事件
94
+ */
95
+ export interface CallTimeoutEvent extends BaseCallEvent {
96
+ }
97
+ /**
98
+ * 对方忙线事件
99
+ */
100
+ export interface CallBusyEvent extends BaseCallEvent {
101
+ }
102
+ /**
103
+ * 群通话成员加入事件
104
+ */
105
+ export interface ParticipantJoinedEvent {
106
+ userId: string;
107
+ callId: string;
108
+ channel: string;
109
+ groupId?: string;
110
+ /** 会话 ID,群聊=groupId */
111
+ conversationId: string;
112
+ /** 是否由本端行为触发 */
113
+ isLocal: boolean;
114
+ /** 当前用户角色 */
115
+ localUserRole: CallUserRole;
116
+ }
117
+ /**
118
+ * 群通话成员离开事件
119
+ */
120
+ export interface ParticipantLeftEvent {
121
+ userId: string;
122
+ callId: string;
123
+ channel: string;
124
+ groupId?: string;
125
+ reason?: string;
126
+ /** 会话 ID,群聊=groupId */
127
+ conversationId: string;
128
+ /** 是否由本端行为触发 */
129
+ isLocal: boolean;
130
+ /** 当前用户角色 */
131
+ localUserRole: CallUserRole;
132
+ }
133
+ /**
134
+ * 群通话初始化事件
135
+ */
136
+ export interface GroupCallInitEvent {
137
+ callId: string;
138
+ channel: string;
139
+ groupId: string;
140
+ groupName?: string;
141
+ groupAvatar?: string;
142
+ callType: CALL_TYPE;
143
+ callerUserId: string;
144
+ invitedMembers: string[];
145
+ /** 会话 ID,群聊=groupId */
146
+ conversationId: string;
147
+ /** 是否由本端行为触发 */
148
+ isLocal: boolean;
149
+ /** 当前用户角色 */
150
+ localUserRole: CallUserRole;
151
+ }
152
+ /**
153
+ * 群通话参与者状态变化事件
154
+ */
155
+ export interface ParticipantStateChangedEvent {
156
+ userId: string;
157
+ callId: string;
158
+ channel: string;
159
+ groupId?: string;
160
+ state: string;
161
+ /** 会话 ID,群聊=groupId */
162
+ conversationId: string;
163
+ /** 是否由本端行为触发 */
164
+ isLocal: boolean;
165
+ /** 当前用户角色 */
166
+ localUserRole: CallUserRole;
167
+ }
168
+ /**
169
+ * RTC 上报事件
170
+ */
171
+ export interface RtcReportEvent {
172
+ callId: string;
173
+ channel: string;
174
+ type: string;
175
+ data: any;
176
+ /** 会话 ID */
177
+ conversationId: string;
178
+ /** 是否由本端行为触发 */
179
+ isLocal: boolean;
180
+ /** 当前用户角色 */
181
+ localUserRole: CallUserRole;
182
+ }
183
+ /**
184
+ * 通话时长更新事件
185
+ */
186
+ export interface CallDurationUpdatedEvent extends BaseCallEvent {
187
+ /** 通话时长(毫秒) */
188
+ duration: number;
189
+ }
190
+ /**
191
+ * 通话错误事件
192
+ */
193
+ export interface CallErrorEvent {
194
+ type: "callError";
195
+ payload: {
196
+ /** 错误类型 */
197
+ type: string;
198
+ /** 错误信息 */
199
+ error: string;
200
+ /** 关联通话 ID */
201
+ callId?: string;
202
+ /** 额外上下文 */
203
+ context?: Record<string, any>;
204
+ };
205
+ }
206
+ /**
207
+ * 通话记录对象(供 getCallRecord API 使用)
208
+ */
209
+ export interface CallRecord {
210
+ callId: string;
211
+ conversationId: string;
212
+ chatType: "singleChat" | "groupChat";
213
+ from: string;
214
+ to: string;
215
+ status: "ended" | "refused" | "busy" | "canceled" | "timeout" | "noResponse" | "ongoing";
216
+ duration: number;
217
+ timestamp: number;
218
+ endedBy?: string;
219
+ }
220
+ /**
221
+ * 各事件对应的 payload 类型映射
222
+ */
223
+ export interface CallKitEventPayloads {
224
+ statusChanged: StatusChangedEvent;
225
+ incomingCall: IncomingCallEvent;
226
+ callInvited: CallInvitedEvent;
227
+ callAccepted: CallAcceptedEvent;
228
+ callConnected: CallConnectedEvent;
229
+ callStarted: CallStartedEvent;
230
+ callEnded: CallEndedEvent;
231
+ callCanceled: CallCanceledEvent;
232
+ callRefused: CallRefusedEvent;
233
+ callTimeout: CallTimeoutEvent;
234
+ callBusy: CallBusyEvent;
235
+ singleCallInvited: CallInvitedEvent;
236
+ singleCallAccepted: CallAcceptedEvent;
237
+ singleCallStarted: CallStartedEvent;
238
+ singleCallConnected: CallConnectedEvent;
239
+ singleCallEnded: CallEndedEvent;
240
+ singleCallCanceled: CallCanceledEvent;
241
+ singleCallRefused: CallRefusedEvent;
242
+ singleCallTimeout: CallTimeoutEvent;
243
+ singleCallBusy: CallBusyEvent;
244
+ groupCallInvited: CallInvitedEvent;
245
+ groupCallAccepted: CallAcceptedEvent;
246
+ groupCallStarted: CallStartedEvent;
247
+ groupCallConnected: CallConnectedEvent;
248
+ groupCallEnded: CallEndedEvent;
249
+ groupCallCanceled: CallCanceledEvent;
250
+ groupCallRefused: CallRefusedEvent;
251
+ groupCallTimeout: CallTimeoutEvent;
252
+ groupCallBusy: CallBusyEvent;
253
+ participantJoined: ParticipantJoinedEvent;
254
+ participantLeft: ParticipantLeftEvent;
255
+ groupCallInit: GroupCallInitEvent;
256
+ participantStateChanged: ParticipantStateChangedEvent;
257
+ rtcReport: RtcReportEvent;
258
+ callDurationUpdated: CallDurationUpdatedEvent;
259
+ callError: CallErrorEvent;
260
+ }
261
+ /**
262
+ * 事件处理器类型
263
+ */
264
+ export type CallKitEventHandler<T extends CallKitEventType> = (payload: CallKitEventPayloads[T]) => void;
@@ -0,0 +1,4 @@
1
+ import { EasemobChat as Chat, EasemobChatStatic as ChatSDKStatic } from 'easemob-websdk/Easemob-chat';
2
+ declare const ChatSDK: ChatSDKStatic;
3
+ export type { Chat, ChatSDKStatic };
4
+ export { ChatSDK };