@softtynet/zca-js 2.3.4 → 2.3.6

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 (129) hide show
  1. package/README.md +47 -11
  2. package/dist/apis/call/addUserGroupCall.d.ts +11 -0
  3. package/dist/apis/call/addUserGroupCall.js +48 -0
  4. package/dist/apis/call/answerAckVoiceCall.d.ts +5 -0
  5. package/dist/apis/call/answerAckVoiceCall.js +38 -0
  6. package/dist/apis/call/answerGroupCall.d.ts +10 -0
  7. package/dist/apis/call/answerGroupCall.js +45 -0
  8. package/dist/apis/call/answerVoiceCall.d.ts +11 -0
  9. package/dist/apis/call/answerVoiceCall.js +50 -0
  10. package/dist/apis/call/broadcastGroupCallState.d.ts +10 -0
  11. package/dist/apis/call/broadcastGroupCallState.js +45 -0
  12. package/dist/apis/call/cancelGroupCall.d.ts +10 -0
  13. package/dist/apis/call/cancelGroupCall.js +45 -0
  14. package/dist/apis/call/cancelVoiceCall.d.ts +1 -1
  15. package/dist/apis/call/cancelVoiceCall.js +5 -1
  16. package/dist/apis/call/createController.d.ts +7 -0
  17. package/dist/apis/call/createController.js +9 -0
  18. package/dist/apis/call/createRtcSession.d.ts +8 -0
  19. package/dist/apis/call/createRtcSession.js +10 -0
  20. package/dist/apis/call/endGroupCall.d.ts +10 -0
  21. package/dist/apis/call/endGroupCall.js +45 -0
  22. package/dist/apis/call/finishGroupCall.d.ts +12 -0
  23. package/dist/apis/call/finishGroupCall.js +47 -0
  24. package/dist/apis/call/getGroupCallState.d.ts +3 -0
  25. package/dist/apis/call/getGroupCallState.js +38 -0
  26. package/dist/apis/call/holdVoiceCall.d.ts +5 -0
  27. package/dist/apis/call/holdVoiceCall.js +34 -0
  28. package/dist/apis/call/joinGroupCall.d.ts +11 -0
  29. package/dist/apis/call/joinGroupCall.js +46 -0
  30. package/dist/apis/call/logEndVoiceCall.d.ts +8 -0
  31. package/dist/apis/call/logEndVoiceCall.js +46 -0
  32. package/dist/apis/call/notifyGroupCall.d.ts +9 -0
  33. package/dist/apis/call/notifyGroupCall.js +44 -0
  34. package/dist/apis/call/pingGroupCall.d.ts +10 -0
  35. package/dist/apis/call/pingGroupCall.js +45 -0
  36. package/dist/apis/call/requestAudioToVideoCall.d.ts +5 -0
  37. package/dist/apis/call/requestAudioToVideoCall.js +37 -0
  38. package/dist/apis/call/requestGroupCall.d.ts +9 -0
  39. package/dist/apis/call/requestGroupCall.js +46 -0
  40. package/dist/apis/call/requestShareScreenCall.d.ts +5 -0
  41. package/dist/apis/call/requestShareScreenCall.js +37 -0
  42. package/dist/apis/call/requestVoiceCall.d.ts +10 -0
  43. package/dist/apis/call/requestVoiceCall.js +47 -0
  44. package/dist/apis/call/ringRingGroupCall.d.ts +10 -0
  45. package/dist/apis/call/ringRingGroupCall.js +45 -0
  46. package/dist/apis/call/ringRingVoiceCall.d.ts +5 -0
  47. package/dist/apis/call/ringRingVoiceCall.js +38 -0
  48. package/dist/apis/call/sendRequestGroupCall.d.ts +11 -0
  49. package/dist/apis/call/sendRequestGroupCall.js +48 -0
  50. package/dist/apis/call/sendRequestVoiceCall.d.ts +11 -0
  51. package/dist/apis/call/sendRequestVoiceCall.js +51 -0
  52. package/dist/apis/call/sendVoiceCall.d.ts +8 -1
  53. package/dist/apis/call/sendVoiceCall.js +10 -8
  54. package/dist/apis/call/shareScreenGroupCall.d.ts +10 -0
  55. package/dist/apis/call/shareScreenGroupCall.js +45 -0
  56. package/dist/apis/call/unholdVoiceCall.d.ts +5 -0
  57. package/dist/apis/call/unholdVoiceCall.js +34 -0
  58. package/dist/apis/call/updateCallMediaState.d.ts +7 -0
  59. package/dist/apis/call/updateCallMediaState.js +61 -0
  60. package/dist/apis/sync/downloadTransferSync.js +19 -1
  61. package/dist/apis.d.ts +81 -0
  62. package/dist/apis.js +135 -0
  63. package/dist/call-engine/ZRTPPacketCodec.d.ts +262 -0
  64. package/dist/call-engine/ZRTPPacketCodec.js +506 -0
  65. package/dist/call-engine/ZaloCallController.d.ts +134 -0
  66. package/dist/call-engine/ZaloCallController.js +638 -0
  67. package/dist/call-engine/ZaloCallTransport.d.ts +83 -0
  68. package/dist/call-engine/ZaloCallTransport.js +259 -0
  69. package/dist/call-engine/ZaloRtcSession.d.ts +609 -0
  70. package/dist/call-engine/ZaloRtcSession.js +2939 -0
  71. package/dist/call-engine/ZaloSrtpSession.d.ts +80 -0
  72. package/dist/call-engine/ZaloSrtpSession.js +278 -0
  73. package/dist/call-engine/index.d.ts +18 -0
  74. package/dist/call-engine/index.js +24 -0
  75. package/dist/cjs/apis/call/addUserGroupCall.cjs +53 -0
  76. package/dist/cjs/apis/call/answerAckVoiceCall.cjs +43 -0
  77. package/dist/cjs/apis/call/answerGroupCall.cjs +50 -0
  78. package/dist/cjs/apis/call/answerVoiceCall.cjs +55 -0
  79. package/dist/cjs/apis/call/broadcastGroupCallState.cjs +50 -0
  80. package/dist/cjs/apis/call/cancelGroupCall.cjs +50 -0
  81. package/dist/cjs/apis/call/cancelVoiceCall.cjs +5 -1
  82. package/dist/cjs/apis/call/createController.cjs +14 -0
  83. package/dist/cjs/apis/call/createRtcSession.cjs +15 -0
  84. package/dist/cjs/apis/call/endGroupCall.cjs +50 -0
  85. package/dist/cjs/apis/call/finishGroupCall.cjs +52 -0
  86. package/dist/cjs/apis/call/getGroupCallState.cjs +43 -0
  87. package/dist/cjs/apis/call/holdVoiceCall.cjs +39 -0
  88. package/dist/cjs/apis/call/joinGroupCall.cjs +51 -0
  89. package/dist/cjs/apis/call/logEndVoiceCall.cjs +51 -0
  90. package/dist/cjs/apis/call/notifyGroupCall.cjs +49 -0
  91. package/dist/cjs/apis/call/pingGroupCall.cjs +50 -0
  92. package/dist/cjs/apis/call/requestAudioToVideoCall.cjs +42 -0
  93. package/dist/cjs/apis/call/requestGroupCall.cjs +51 -0
  94. package/dist/cjs/apis/call/requestShareScreenCall.cjs +42 -0
  95. package/dist/cjs/apis/call/requestVoiceCall.cjs +52 -0
  96. package/dist/cjs/apis/call/ringRingGroupCall.cjs +50 -0
  97. package/dist/cjs/apis/call/ringRingVoiceCall.cjs +43 -0
  98. package/dist/cjs/apis/call/sendRequestGroupCall.cjs +53 -0
  99. package/dist/cjs/apis/call/sendRequestVoiceCall.cjs +56 -0
  100. package/dist/cjs/apis/call/sendVoiceCall.cjs +10 -8
  101. package/dist/cjs/apis/call/shareScreenGroupCall.cjs +50 -0
  102. package/dist/cjs/apis/call/unholdVoiceCall.cjs +39 -0
  103. package/dist/cjs/apis/call/updateCallMediaState.cjs +66 -0
  104. package/dist/cjs/apis/sync/downloadTransferSync.cjs +19 -1
  105. package/dist/cjs/apis.cjs +135 -0
  106. package/dist/cjs/call-engine/ZRTPPacketCodec.cjs +525 -0
  107. package/dist/cjs/call-engine/ZaloCallController.cjs +643 -0
  108. package/dist/cjs/call-engine/ZaloCallTransport.cjs +265 -0
  109. package/dist/cjs/call-engine/ZaloRtcSession.cjs +2945 -0
  110. package/dist/cjs/call-engine/ZaloSrtpSession.cjs +287 -0
  111. package/dist/cjs/constants/protocol.cjs +1 -1
  112. package/dist/cjs/crypto/aes.cjs +3 -1
  113. package/dist/cjs/crypto/zdb-cipher.cjs +10 -3
  114. package/dist/cjs/index.cjs +61 -11
  115. package/dist/cjs/models/CallEvent.cjs +95 -1
  116. package/dist/cjs/realtime/handlers/control.handler.cjs +17 -3
  117. package/dist/cjs/realtime/listener.cjs +19 -0
  118. package/dist/constants/protocol.d.ts +1 -1
  119. package/dist/constants/protocol.js +1 -1
  120. package/dist/crypto/aes.js +3 -1
  121. package/dist/crypto/zdb-cipher.js +10 -3
  122. package/dist/index.d.ts +32 -4
  123. package/dist/index.js +2 -0
  124. package/dist/models/CallEvent.d.ts +15 -0
  125. package/dist/models/CallEvent.js +95 -1
  126. package/dist/realtime/handlers/control.handler.js +17 -3
  127. package/dist/realtime/listener.d.ts +5 -0
  128. package/dist/realtime/listener.js +19 -0
  129. package/package.json +2 -1
@@ -0,0 +1,38 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../../utils.js";
3
+ import { CallType } from "./sendVoiceCall.js";
4
+ export const getGroupCallStateFactory = apiFactory()((api, _ctx, utils) => {
5
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
6
+ /**
7
+ * Lấy trạng thái hiện tại của cuộc gọi nhóm (`/api/voicecall/group/state`, command `12445`).
8
+ *
9
+ * @param callId ID của cuộc gọi nhóm
10
+ * @param hostCall User ID hoặc Group ID chủ trì cuộc gọi (`hostCall`)
11
+ * @param callType Loại cuộc gọi nhóm (`CallType.GroupAudio = 5` hoặc `CallType.GroupVideo = 6`)
12
+ * @throws {ZaloApiError}
13
+ */
14
+ return async function getGroupCallState(callId, hostCall, callType = CallType.GroupAudio) {
15
+ if (!callId)
16
+ throw new ZaloApiError("Missing callId");
17
+ if (!hostCall)
18
+ throw new ZaloApiError("Missing hostCall");
19
+ if (!voiceCallService)
20
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
21
+ const params = {
22
+ callId,
23
+ hostCall: String(hostCall),
24
+ callType,
25
+ };
26
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
27
+ if (!encryptedParams)
28
+ throw new ZaloApiError("Failed to encrypt getGroupCallState params");
29
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/state`, {
30
+ zpw_type: 24,
31
+ params: encryptedParams,
32
+ });
33
+ const response = await utils.request(url, {
34
+ method: "GET",
35
+ });
36
+ return utils.resolve(response);
37
+ };
38
+ });
@@ -0,0 +1,5 @@
1
+ export type HoldVoiceCallOptions = {
2
+ isResponse?: boolean;
3
+ };
4
+ export type HoldVoiceCallResponse = Record<string, unknown>;
5
+ export declare const holdVoiceCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (toId: string, options?: HoldVoiceCallOptions) => Promise<HoldVoiceCallResponse>;
@@ -0,0 +1,34 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../../utils.js";
3
+ export const holdVoiceCallFactory = apiFactory()((api, _ctx, utils) => {
4
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
5
+ /**
6
+ * Gửi yêu cầu tạm giữ cuộc gọi (`/api/voicecall/holdreq`, command `11307`, signal `411`)
7
+ * hoặc phản hồi tạm giữ cuộc gọi (`/api/voicecall/holdresp`, command `11308`, signal `412`).
8
+ *
9
+ * @param toId User ID của đối phương trong cuộc gọi
10
+ * @param options Đặt `isResponse = true` nếu là gói phản hồi (`holdresp`)
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function holdVoiceCall(toId, options = {}) {
14
+ if (!toId)
15
+ throw new ZaloApiError("Missing toId");
16
+ if (!voiceCallService)
17
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
18
+ const params = {
19
+ toId: String(toId),
20
+ };
21
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
22
+ if (!encryptedParams)
23
+ throw new ZaloApiError("Failed to encrypt holdVoiceCall params");
24
+ const endpoint = options.isResponse ? "holdresp" : "holdreq";
25
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/${endpoint}`, {
26
+ zpw_type: 24,
27
+ params: encryptedParams,
28
+ });
29
+ const response = await utils.request(url, {
30
+ method: "GET",
31
+ });
32
+ return utils.resolve(response);
33
+ };
34
+ });
@@ -0,0 +1,11 @@
1
+ export type JoinGroupCallOptions = {
2
+ userId?: string;
3
+ hostCall: string;
4
+ status?: number;
5
+ srcJoinCall?: number;
6
+ audioState?: number;
7
+ videoState?: number;
8
+ data?: string | Record<string, unknown>;
9
+ };
10
+ export type JoinGroupCallResponse = Record<string, unknown>;
11
+ export declare const joinGroupCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (callId: number, options: JoinGroupCallOptions) => Promise<JoinGroupCallResponse>;
@@ -0,0 +1,46 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../../utils.js";
3
+ export const joinGroupCallFactory = apiFactory()((api, ctx, utils) => {
4
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
5
+ /**
6
+ * Tham gia vào một cuộc gọi nhóm đang diễn ra (`/api/voicecall/group/join`, command `12043`).
7
+ *
8
+ * @param callId ID của cuộc gọi nhóm
9
+ * @param options Thông tin `hostCall`, `userId`, `status`, `srcJoinCall`, `audioState`, `videoState` và `data`
10
+ * @throws {ZaloApiError}
11
+ */
12
+ return async function joinGroupCall(callId, options) {
13
+ if (!callId)
14
+ throw new ZaloApiError("Missing callId");
15
+ if (!options?.hostCall)
16
+ throw new ZaloApiError("Missing hostCall");
17
+ if (!voiceCallService)
18
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
19
+ const dataStr = options.data === undefined
20
+ ? "{}"
21
+ : typeof options.data === "string"
22
+ ? options.data
23
+ : JSON.stringify(options.data);
24
+ const params = {
25
+ userId: String(options.userId ?? ctx.uid),
26
+ callId,
27
+ hostCall: String(options.hostCall),
28
+ status: options.status ?? 0,
29
+ srcJoinCall: options.srcJoinCall ?? 0,
30
+ audiostate: options.audioState ?? 1,
31
+ videostate: options.videoState ?? 0,
32
+ data: dataStr,
33
+ };
34
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
35
+ if (!encryptedParams)
36
+ throw new ZaloApiError("Failed to encrypt joinGroupCall params");
37
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/join`, {
38
+ zpw_type: 24,
39
+ params: encryptedParams,
40
+ });
41
+ const response = await utils.request(url, {
42
+ method: "GET",
43
+ });
44
+ return utils.resolve(response);
45
+ };
46
+ });
@@ -0,0 +1,8 @@
1
+ export type LogEndVoiceCallOptions = {
2
+ status?: number;
3
+ logData?: string | Record<string, unknown>;
4
+ duration?: number;
5
+ role?: boolean | number;
6
+ };
7
+ export type LogEndVoiceCallResponse = Record<string, unknown>;
8
+ export declare const logEndVoiceCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (partnerId: string, callId: number, options?: LogEndVoiceCallOptions) => Promise<LogEndVoiceCallResponse>;
@@ -0,0 +1,46 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../../utils.js";
3
+ export const logEndVoiceCallFactory = apiFactory()((api, ctx, utils) => {
4
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
5
+ /**
6
+ * Gửi báo cáo thống kê chất lượng / kết thúc cuộc gọi (`/api/voicecall/logendcall`, command `11311`, signal `406`).
7
+ *
8
+ * @param partnerId User ID của đối phương
9
+ * @param callId ID của cuộc gọi
10
+ * @param options Thông tin `status`, `duration`, `role` và `logData`
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function logEndVoiceCall(partnerId, callId, options = {}) {
14
+ if (!partnerId)
15
+ throw new ZaloApiError("Missing partnerId");
16
+ if (!callId)
17
+ throw new ZaloApiError("Missing callId");
18
+ if (!voiceCallService)
19
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
20
+ const logdata = options.logData === undefined
21
+ ? "{}"
22
+ : typeof options.logData === "string"
23
+ ? options.logData
24
+ : JSON.stringify(options.logData);
25
+ const params = {
26
+ call_id: callId,
27
+ partner_id: String(partnerId),
28
+ status: options.status ?? 0,
29
+ logdata,
30
+ duration: options.duration ?? 0,
31
+ role: options.role ?? true,
32
+ imei: ctx.imei,
33
+ };
34
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
35
+ if (!encryptedParams)
36
+ throw new ZaloApiError("Failed to encrypt logEndVoiceCall params");
37
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/logendcall`, {
38
+ zpw_type: 24,
39
+ params: encryptedParams,
40
+ });
41
+ const response = await utils.request(url, {
42
+ method: "GET",
43
+ });
44
+ return utils.resolve(response);
45
+ };
46
+ });
@@ -0,0 +1,9 @@
1
+ import { CallType } from "./sendVoiceCall.js";
2
+ export type NotifyGroupCallOptions = {
3
+ hostCall: string;
4
+ callType?: CallType | number;
5
+ status?: number;
6
+ data?: string | Record<string, unknown>;
7
+ };
8
+ export type NotifyGroupCallResponse = Record<string, unknown>;
9
+ export declare const notifyGroupCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (callId: number, options: NotifyGroupCallOptions) => Promise<NotifyGroupCallResponse>;
@@ -0,0 +1,44 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../../utils.js";
3
+ import { CallType } from "./sendVoiceCall.js";
4
+ export const notifyGroupCallFactory = apiFactory()((api, _ctx, utils) => {
5
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
6
+ /**
7
+ * Gửi thông báo sự kiện trong cuộc gọi nhóm (`/api/voicecall/group/notify`, command `12447`).
8
+ *
9
+ * @param callId ID của cuộc gọi nhóm
10
+ * @param options Thông tin `hostCall`, `callType`, `status` và `data`
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function notifyGroupCall(callId, options) {
14
+ if (!callId)
15
+ throw new ZaloApiError("Missing callId");
16
+ if (!options?.hostCall)
17
+ throw new ZaloApiError("Missing hostCall");
18
+ if (!voiceCallService)
19
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
20
+ const dataStr = options.data === undefined
21
+ ? "{}"
22
+ : typeof options.data === "string"
23
+ ? options.data
24
+ : JSON.stringify(options.data);
25
+ const params = {
26
+ callId,
27
+ hostCall: String(options.hostCall),
28
+ callType: options.callType ?? CallType.GroupAudio,
29
+ status: options.status ?? 0,
30
+ data: dataStr,
31
+ };
32
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
33
+ if (!encryptedParams)
34
+ throw new ZaloApiError("Failed to encrypt notifyGroupCall params");
35
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/notify`, {
36
+ zpw_type: 24,
37
+ params: encryptedParams,
38
+ });
39
+ const response = await utils.request(url, {
40
+ method: "GET",
41
+ });
42
+ return utils.resolve(response);
43
+ };
44
+ });
@@ -0,0 +1,10 @@
1
+ export type PingGroupCallOptions = {
2
+ hostCall: string;
3
+ userId?: string;
4
+ callState?: number;
5
+ audioState?: number;
6
+ videoState?: number;
7
+ params?: string | Record<string, unknown>;
8
+ };
9
+ export type PingGroupCallResponse = Record<string, unknown>;
10
+ export declare const pingGroupCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (callId: number, options: PingGroupCallOptions) => Promise<PingGroupCallResponse>;
@@ -0,0 +1,45 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../../utils.js";
3
+ export const pingGroupCallFactory = apiFactory()((api, ctx, utils) => {
4
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
5
+ /**
6
+ * Gửi gói tin heartbeat (ping) duy trì kết nối cuộc gọi nhóm (`/api/voicecall/group/ping`, command `12097`).
7
+ *
8
+ * @param callId ID của cuộc gọi nhóm
9
+ * @param options Thông tin `hostCall`, `userId`, `callState`, `audioState`, `videoState` và `params`
10
+ * @throws {ZaloApiError}
11
+ */
12
+ return async function pingGroupCall(callId, options) {
13
+ if (!callId)
14
+ throw new ZaloApiError("Missing callId");
15
+ if (!options?.hostCall)
16
+ throw new ZaloApiError("Missing hostCall");
17
+ if (!voiceCallService)
18
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
19
+ const paramsStr = options.params === undefined
20
+ ? "{}"
21
+ : typeof options.params === "string"
22
+ ? options.params
23
+ : JSON.stringify(options.params);
24
+ const payload = {
25
+ callId,
26
+ hostCall: String(options.hostCall),
27
+ userId: String(options.userId ?? ctx.uid),
28
+ callstate: options.callState ?? 1,
29
+ audiostate: options.audioState ?? 1,
30
+ videostate: options.videoState ?? 0,
31
+ params: paramsStr,
32
+ };
33
+ const encryptedParams = utils.encodeAES(JSON.stringify(payload));
34
+ if (!encryptedParams)
35
+ throw new ZaloApiError("Failed to encrypt pingGroupCall params");
36
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/ping`, {
37
+ zpw_type: 24,
38
+ params: encryptedParams,
39
+ });
40
+ const response = await utils.request(url, {
41
+ method: "GET",
42
+ });
43
+ return utils.resolve(response);
44
+ };
45
+ });
@@ -0,0 +1,5 @@
1
+ export type RequestAudioToVideoCallOptions = {
2
+ status?: number;
3
+ };
4
+ export type RequestAudioToVideoCallResponse = Record<string, unknown>;
5
+ export declare const requestAudioToVideoCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (uidTo: string, callId: number, options?: RequestAudioToVideoCallOptions) => Promise<RequestAudioToVideoCallResponse>;
@@ -0,0 +1,37 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../../utils.js";
3
+ export const requestAudioToVideoCallFactory = apiFactory()((api, _ctx, utils) => {
4
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
5
+ /**
6
+ * Gửi yêu cầu chuyển đổi cuộc gọi thoại đang diễn ra sang cuộc gọi video (`/api/voicecall/requestaudio2video`, command `12056`).
7
+ *
8
+ * @param uidTo User ID của đối phương
9
+ * @param callId ID của cuộc gọi
10
+ * @param options Trạng thái yêu cầu (`status`, mặc định `1`)
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function requestAudioToVideoCall(uidTo, callId, options = {}) {
14
+ if (!uidTo)
15
+ throw new ZaloApiError("Missing uidTo");
16
+ if (!callId)
17
+ throw new ZaloApiError("Missing callId");
18
+ if (!voiceCallService)
19
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
20
+ const params = {
21
+ uidTo: String(uidTo),
22
+ callId,
23
+ status: options.status ?? 1,
24
+ };
25
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
26
+ if (!encryptedParams)
27
+ throw new ZaloApiError("Failed to encrypt requestAudioToVideoCall params");
28
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/requestaudio2video`, {
29
+ zpw_type: 24,
30
+ params: encryptedParams,
31
+ });
32
+ const response = await utils.request(url, {
33
+ method: "GET",
34
+ });
35
+ return utils.resolve(response);
36
+ };
37
+ });
@@ -0,0 +1,9 @@
1
+ import { CallType } from "./sendVoiceCall.js";
2
+ export type RequestGroupCallOptions = {
3
+ callId?: number;
4
+ typeRequest?: CallType | number;
5
+ data?: string | Record<string, unknown>;
6
+ partners: string[];
7
+ };
8
+ export type RequestGroupCallResponse = Record<string, unknown>;
9
+ export declare const requestGroupCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (groupId: string, options: RequestGroupCallOptions) => Promise<RequestGroupCallResponse>;
@@ -0,0 +1,46 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../../utils.js";
3
+ import { CallType } from "./sendVoiceCall.js";
4
+ export const requestGroupCallFactory = apiFactory()((api, _ctx, utils) => {
5
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
6
+ /**
7
+ * Xin cấp phát phiên gọi nhóm (Group Call) và máy chủ relay (`/api/voicecall/group/requestcall`, command `12433`).
8
+ *
9
+ * @param groupId ID của nhóm
10
+ * @param options Danh sách `partners`, `callId`, `typeRequest` (`CallType.GroupAudio = 5` hoặc `CallType.GroupVideo = 6`) và `data`
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function requestGroupCall(groupId, options) {
14
+ if (!groupId)
15
+ throw new ZaloApiError("Missing groupId");
16
+ if (!options?.partners || !Array.isArray(options.partners)) {
17
+ throw new ZaloApiError("Missing partners array");
18
+ }
19
+ if (!voiceCallService)
20
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
21
+ const callId = options.callId ?? Math.floor(Math.random() * 2_000_000_000);
22
+ const dataStr = options.data === undefined
23
+ ? "{}"
24
+ : typeof options.data === "string"
25
+ ? options.data
26
+ : JSON.stringify(options.data);
27
+ const params = {
28
+ groupId: String(groupId),
29
+ callId,
30
+ typeRequest: options.typeRequest ?? CallType.GroupAudio,
31
+ data: dataStr,
32
+ partners: options.partners.map(String),
33
+ };
34
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
35
+ if (!encryptedParams)
36
+ throw new ZaloApiError("Failed to encrypt requestGroupCall params");
37
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/requestcall`, {
38
+ zpw_type: 24,
39
+ params: encryptedParams,
40
+ });
41
+ const response = await utils.request(url, {
42
+ method: "GET",
43
+ });
44
+ return utils.resolve(response);
45
+ };
46
+ });
@@ -0,0 +1,5 @@
1
+ export type RequestShareScreenCallOptions = {
2
+ status?: number;
3
+ };
4
+ export type RequestShareScreenCallResponse = Record<string, unknown>;
5
+ export declare const requestShareScreenCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (uidTo: string, callId: number, options?: RequestShareScreenCallOptions) => Promise<RequestShareScreenCallResponse>;
@@ -0,0 +1,37 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../../utils.js";
3
+ export const requestShareScreenCallFactory = apiFactory()((api, _ctx, utils) => {
4
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
5
+ /**
6
+ * Gửi tín hiệu bật/tắt chia sẻ màn hình trong cuộc gọi 1-1 (`/api/voicecall/requestsharescreen`, command `12064`).
7
+ *
8
+ * @param uidTo User ID của đối phương
9
+ * @param callId ID của cuộc gọi
10
+ * @param options Trạng thái chia sẻ màn hình (`status`: `1` bật, `0` tắt)
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function requestShareScreenCall(uidTo, callId, options = {}) {
14
+ if (!uidTo)
15
+ throw new ZaloApiError("Missing uidTo");
16
+ if (!callId)
17
+ throw new ZaloApiError("Missing callId");
18
+ if (!voiceCallService)
19
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
20
+ const params = {
21
+ uidTo: String(uidTo),
22
+ callId,
23
+ status: options.status ?? 1,
24
+ };
25
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
26
+ if (!encryptedParams)
27
+ throw new ZaloApiError("Failed to encrypt requestShareScreenCall params");
28
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/requestsharescreen`, {
29
+ zpw_type: 24,
30
+ params: encryptedParams,
31
+ });
32
+ const response = await utils.request(url, {
33
+ method: "GET",
34
+ });
35
+ return utils.resolve(response);
36
+ };
37
+ });
@@ -0,0 +1,10 @@
1
+ import { CallType, type RequestCallServerInfo } from "./sendVoiceCall.js";
2
+ export type RequestVoiceCallOptions = {
3
+ callType?: CallType;
4
+ callId?: number;
5
+ codec?: string;
6
+ };
7
+ export type RequestVoiceCallResponse = RequestCallServerInfo & {
8
+ callId: number;
9
+ };
10
+ export declare const requestVoiceCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (calleeId: string, options?: RequestVoiceCallOptions) => Promise<RequestVoiceCallResponse>;
@@ -0,0 +1,47 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory, resolveResponse } from "../../utils.js";
3
+ import { CallType } from "./sendVoiceCall.js";
4
+ export const requestVoiceCallFactory = apiFactory()((api, ctx, utils) => {
5
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
6
+ /**
7
+ * Xin cấp phát phiên gọi thoại / video và máy chủ relay RTP/RTCP (`/api/voicecall/requestcall`, command `11300`, signal `401`).
8
+ *
9
+ * @param calleeId User ID của người nhận cuộc gọi
10
+ * @param options Tuỳ chọn loại cuộc gọi (`callType`), `callId` và `codec`
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function requestVoiceCall(calleeId, options = {}) {
14
+ if (!calleeId)
15
+ throw new ZaloApiError("Missing calleeId");
16
+ if (!voiceCallService)
17
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
18
+ const callType = options.callType ?? CallType.Audio;
19
+ const callId = options.callId ?? Math.floor(Math.random() * 2_000_000_000);
20
+ const codec = options.codec ?? "[]";
21
+ const params = {
22
+ calleeId: String(calleeId),
23
+ callId,
24
+ codec,
25
+ typeRequest: callType,
26
+ imei: ctx.imei,
27
+ };
28
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
29
+ if (!encryptedParams)
30
+ throw new ZaloApiError("Failed to encrypt requestVoiceCall params");
31
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/requestcall`, {
32
+ zpw_type: 24,
33
+ params: encryptedParams,
34
+ });
35
+ const response = await utils.request(url, {
36
+ method: "GET",
37
+ });
38
+ const serverInfo = await resolveResponse(ctx, response, (result) => {
39
+ const raw = result.data;
40
+ return typeof raw === "string" ? JSON.parse(raw) : raw;
41
+ });
42
+ return {
43
+ ...serverInfo,
44
+ callId,
45
+ };
46
+ };
47
+ });
@@ -0,0 +1,10 @@
1
+ import { CallType } from "./sendVoiceCall.js";
2
+ export type RingRingGroupCallOptions = {
3
+ calleeId?: string;
4
+ callType?: CallType | number;
5
+ hostCall: string;
6
+ data?: string | Record<string, unknown>;
7
+ partners?: string[];
8
+ };
9
+ export type RingRingGroupCallResponse = Record<string, unknown>;
10
+ export declare const ringRingGroupCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (callId: number, options: RingRingGroupCallOptions) => Promise<RingRingGroupCallResponse>;
@@ -0,0 +1,45 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../../utils.js";
3
+ import { CallType } from "./sendVoiceCall.js";
4
+ export const ringRingGroupCallFactory = apiFactory()((api, ctx, utils) => {
5
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
6
+ /**
7
+ * Báo hiệu thiết bị đang đổ chuông cho cuộc gọi nhóm (`/api/voicecall/group/ringring`, command `12439`).
8
+ *
9
+ * @param callId ID của cuộc gọi nhóm
10
+ * @param options Thông tin `hostCall`, `calleeId`, `callType`, `partners` và `data`
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function ringRingGroupCall(callId, options) {
14
+ if (!callId)
15
+ throw new ZaloApiError("Missing callId");
16
+ if (!options?.hostCall)
17
+ throw new ZaloApiError("Missing hostCall");
18
+ if (!voiceCallService)
19
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
20
+ const dataStr = options.data === undefined
21
+ ? "{}"
22
+ : typeof options.data === "string"
23
+ ? options.data
24
+ : JSON.stringify(options.data);
25
+ const params = {
26
+ calleeId: String(options.calleeId ?? ctx.uid),
27
+ callId,
28
+ callType: options.callType ?? CallType.GroupAudio,
29
+ hostCall: String(options.hostCall),
30
+ data: dataStr,
31
+ partners: (options.partners ?? []).map(String),
32
+ };
33
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
34
+ if (!encryptedParams)
35
+ throw new ZaloApiError("Failed to encrypt ringRingGroupCall params");
36
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/ringring`, {
37
+ zpw_type: 24,
38
+ params: encryptedParams,
39
+ });
40
+ const response = await utils.request(url, {
41
+ method: "GET",
42
+ });
43
+ return utils.resolve(response);
44
+ };
45
+ });
@@ -0,0 +1,5 @@
1
+ export type RingRingVoiceCallOptions = {
2
+ status?: number;
3
+ };
4
+ export type RingRingVoiceCallResponse = Record<string, unknown>;
5
+ export declare const ringRingVoiceCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (callerId: string, callId: number, options?: RingRingVoiceCallOptions) => Promise<RingRingVoiceCallResponse>;
@@ -0,0 +1,38 @@
1
+ import { ZaloApiError } from "../../Errors/ZaloApiError.js";
2
+ import { apiFactory } from "../../utils.js";
3
+ export const ringRingVoiceCallFactory = apiFactory()((api, ctx, utils) => {
4
+ const voiceCallService = api.zpwServiceMap.voice_call?.[0];
5
+ /**
6
+ * Báo hiệu thiết bị của người nhận đang đổ chuông cho người gọi (`/api/voicecall/ringring`, command `11302`, signal `407`).
7
+ *
8
+ * @param callerId User ID của người gọi đến
9
+ * @param callId ID của cuộc gọi
10
+ * @param options Tuỳ chọn mã trạng thái (`status`, mặc định `0`)
11
+ * @throws {ZaloApiError}
12
+ */
13
+ return async function ringRingVoiceCall(callerId, callId, options = {}) {
14
+ if (!callerId)
15
+ throw new ZaloApiError("Missing callerId");
16
+ if (!callId)
17
+ throw new ZaloApiError("Missing callId");
18
+ if (!voiceCallService)
19
+ throw new ZaloApiError("Missing voice_call service URL in zpwServiceMap");
20
+ const params = {
21
+ callerId: String(callerId),
22
+ callId,
23
+ status: options.status ?? 0,
24
+ imei: ctx.imei,
25
+ };
26
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
27
+ if (!encryptedParams)
28
+ throw new ZaloApiError("Failed to encrypt ringRingVoiceCall params");
29
+ const url = utils.makeURL(`${voiceCallService}/api/voicecall/ringring`, {
30
+ zpw_type: 24,
31
+ params: encryptedParams,
32
+ });
33
+ const response = await utils.request(url, {
34
+ method: "GET",
35
+ });
36
+ return utils.resolve(response);
37
+ };
38
+ });
@@ -0,0 +1,11 @@
1
+ import { CallType } from "./sendVoiceCall.js";
2
+ export type SendRequestGroupCallOptions = {
3
+ calleeId?: string;
4
+ callId: number;
5
+ callType?: CallType | number;
6
+ data?: string | Record<string, unknown>;
7
+ session: string;
8
+ partners: string[];
9
+ };
10
+ export type SendRequestGroupCallResponse = Record<string, unknown>;
11
+ export declare const sendRequestGroupCallFactory: (ctx: import("../../context.js").ContextBase, api: import("../../apis.js").API) => (groupId: string, options: SendRequestGroupCallOptions) => Promise<SendRequestGroupCallResponse>;