@softtynet/zca-js 2.3.4 → 2.3.5
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.
- package/README.md +47 -11
- package/dist/apis/call/addUserGroupCall.d.ts +11 -0
- package/dist/apis/call/addUserGroupCall.js +48 -0
- package/dist/apis/call/answerAckVoiceCall.d.ts +5 -0
- package/dist/apis/call/answerAckVoiceCall.js +38 -0
- package/dist/apis/call/answerGroupCall.d.ts +10 -0
- package/dist/apis/call/answerGroupCall.js +45 -0
- package/dist/apis/call/answerVoiceCall.d.ts +11 -0
- package/dist/apis/call/answerVoiceCall.js +50 -0
- package/dist/apis/call/broadcastGroupCallState.d.ts +10 -0
- package/dist/apis/call/broadcastGroupCallState.js +45 -0
- package/dist/apis/call/cancelGroupCall.d.ts +10 -0
- package/dist/apis/call/cancelGroupCall.js +45 -0
- package/dist/apis/call/cancelVoiceCall.d.ts +1 -1
- package/dist/apis/call/cancelVoiceCall.js +5 -1
- package/dist/apis/call/createController.d.ts +7 -0
- package/dist/apis/call/createController.js +9 -0
- package/dist/apis/call/createRtcSession.d.ts +8 -0
- package/dist/apis/call/createRtcSession.js +10 -0
- package/dist/apis/call/endGroupCall.d.ts +10 -0
- package/dist/apis/call/endGroupCall.js +45 -0
- package/dist/apis/call/finishGroupCall.d.ts +12 -0
- package/dist/apis/call/finishGroupCall.js +47 -0
- package/dist/apis/call/getGroupCallState.d.ts +3 -0
- package/dist/apis/call/getGroupCallState.js +38 -0
- package/dist/apis/call/holdVoiceCall.d.ts +5 -0
- package/dist/apis/call/holdVoiceCall.js +34 -0
- package/dist/apis/call/joinGroupCall.d.ts +11 -0
- package/dist/apis/call/joinGroupCall.js +46 -0
- package/dist/apis/call/logEndVoiceCall.d.ts +8 -0
- package/dist/apis/call/logEndVoiceCall.js +46 -0
- package/dist/apis/call/notifyGroupCall.d.ts +9 -0
- package/dist/apis/call/notifyGroupCall.js +44 -0
- package/dist/apis/call/pingGroupCall.d.ts +10 -0
- package/dist/apis/call/pingGroupCall.js +45 -0
- package/dist/apis/call/requestAudioToVideoCall.d.ts +5 -0
- package/dist/apis/call/requestAudioToVideoCall.js +37 -0
- package/dist/apis/call/requestGroupCall.d.ts +9 -0
- package/dist/apis/call/requestGroupCall.js +46 -0
- package/dist/apis/call/requestShareScreenCall.d.ts +5 -0
- package/dist/apis/call/requestShareScreenCall.js +37 -0
- package/dist/apis/call/requestVoiceCall.d.ts +10 -0
- package/dist/apis/call/requestVoiceCall.js +47 -0
- package/dist/apis/call/ringRingGroupCall.d.ts +10 -0
- package/dist/apis/call/ringRingGroupCall.js +45 -0
- package/dist/apis/call/ringRingVoiceCall.d.ts +5 -0
- package/dist/apis/call/ringRingVoiceCall.js +38 -0
- package/dist/apis/call/sendRequestGroupCall.d.ts +11 -0
- package/dist/apis/call/sendRequestGroupCall.js +48 -0
- package/dist/apis/call/sendRequestVoiceCall.d.ts +11 -0
- package/dist/apis/call/sendRequestVoiceCall.js +51 -0
- package/dist/apis/call/sendVoiceCall.d.ts +8 -1
- package/dist/apis/call/sendVoiceCall.js +10 -8
- package/dist/apis/call/shareScreenGroupCall.d.ts +10 -0
- package/dist/apis/call/shareScreenGroupCall.js +45 -0
- package/dist/apis/call/unholdVoiceCall.d.ts +5 -0
- package/dist/apis/call/unholdVoiceCall.js +34 -0
- package/dist/apis/call/updateCallMediaState.d.ts +7 -0
- package/dist/apis/call/updateCallMediaState.js +61 -0
- package/dist/apis.d.ts +81 -0
- package/dist/apis.js +135 -0
- package/dist/call-engine/ZRTPPacketCodec.d.ts +262 -0
- package/dist/call-engine/ZRTPPacketCodec.js +506 -0
- package/dist/call-engine/ZaloCallController.d.ts +134 -0
- package/dist/call-engine/ZaloCallController.js +638 -0
- package/dist/call-engine/ZaloCallTransport.d.ts +83 -0
- package/dist/call-engine/ZaloCallTransport.js +233 -0
- package/dist/call-engine/ZaloRtcSession.d.ts +609 -0
- package/dist/call-engine/ZaloRtcSession.js +2931 -0
- package/dist/call-engine/ZaloSrtpSession.d.ts +80 -0
- package/dist/call-engine/ZaloSrtpSession.js +278 -0
- package/dist/call-engine/index.d.ts +18 -0
- package/dist/call-engine/index.js +24 -0
- package/dist/cjs/apis/call/addUserGroupCall.cjs +53 -0
- package/dist/cjs/apis/call/answerAckVoiceCall.cjs +43 -0
- package/dist/cjs/apis/call/answerGroupCall.cjs +50 -0
- package/dist/cjs/apis/call/answerVoiceCall.cjs +55 -0
- package/dist/cjs/apis/call/broadcastGroupCallState.cjs +50 -0
- package/dist/cjs/apis/call/cancelGroupCall.cjs +50 -0
- package/dist/cjs/apis/call/cancelVoiceCall.cjs +5 -1
- package/dist/cjs/apis/call/createController.cjs +14 -0
- package/dist/cjs/apis/call/createRtcSession.cjs +15 -0
- package/dist/cjs/apis/call/endGroupCall.cjs +50 -0
- package/dist/cjs/apis/call/finishGroupCall.cjs +52 -0
- package/dist/cjs/apis/call/getGroupCallState.cjs +43 -0
- package/dist/cjs/apis/call/holdVoiceCall.cjs +39 -0
- package/dist/cjs/apis/call/joinGroupCall.cjs +51 -0
- package/dist/cjs/apis/call/logEndVoiceCall.cjs +51 -0
- package/dist/cjs/apis/call/notifyGroupCall.cjs +49 -0
- package/dist/cjs/apis/call/pingGroupCall.cjs +50 -0
- package/dist/cjs/apis/call/requestAudioToVideoCall.cjs +42 -0
- package/dist/cjs/apis/call/requestGroupCall.cjs +51 -0
- package/dist/cjs/apis/call/requestShareScreenCall.cjs +42 -0
- package/dist/cjs/apis/call/requestVoiceCall.cjs +52 -0
- package/dist/cjs/apis/call/ringRingGroupCall.cjs +50 -0
- package/dist/cjs/apis/call/ringRingVoiceCall.cjs +43 -0
- package/dist/cjs/apis/call/sendRequestGroupCall.cjs +53 -0
- package/dist/cjs/apis/call/sendRequestVoiceCall.cjs +56 -0
- package/dist/cjs/apis/call/sendVoiceCall.cjs +10 -8
- package/dist/cjs/apis/call/shareScreenGroupCall.cjs +50 -0
- package/dist/cjs/apis/call/unholdVoiceCall.cjs +39 -0
- package/dist/cjs/apis/call/updateCallMediaState.cjs +66 -0
- package/dist/cjs/apis.cjs +135 -0
- package/dist/cjs/call-engine/ZRTPPacketCodec.cjs +525 -0
- package/dist/cjs/call-engine/ZaloCallController.cjs +643 -0
- package/dist/cjs/call-engine/ZaloCallTransport.cjs +239 -0
- package/dist/cjs/call-engine/ZaloRtcSession.cjs +2937 -0
- package/dist/cjs/call-engine/ZaloSrtpSession.cjs +287 -0
- package/dist/cjs/constants/protocol.cjs +1 -1
- package/dist/cjs/index.cjs +61 -11
- package/dist/cjs/models/CallEvent.cjs +95 -1
- package/dist/cjs/realtime/handlers/control.handler.cjs +17 -3
- package/dist/cjs/realtime/listener.cjs +19 -0
- package/dist/constants/protocol.d.ts +1 -1
- package/dist/constants/protocol.js +1 -1
- package/dist/index.d.ts +32 -4
- package/dist/index.js +2 -0
- package/dist/models/CallEvent.d.ts +15 -0
- package/dist/models/CallEvent.js +95 -1
- package/dist/realtime/handlers/control.handler.js +17 -3
- package/dist/realtime/listener.d.ts +5 -0
- package/dist/realtime/listener.js +19 -0
- package/package.json +2 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
var sendVoiceCall = require('./sendVoiceCall.cjs');
|
|
6
|
+
|
|
7
|
+
const cancelGroupCallFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
8
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
9
|
+
/**
|
|
10
|
+
* Từ chối / Huỷ lời mời tham gia cuộc gọi nhóm (`/api/voicecall/group/cancel`, command `12437`).
|
|
11
|
+
*
|
|
12
|
+
* @param callId ID của cuộc gọi nhóm
|
|
13
|
+
* @param options Thông tin `hostCall`, `calleeId`, `callType`, `partners` và `data`
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function cancelGroupCall(callId, options) {
|
|
17
|
+
if (!callId)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
19
|
+
if (!options?.hostCall)
|
|
20
|
+
throw new ZaloApiError.ZaloApiError("Missing hostCall");
|
|
21
|
+
if (!voiceCallService)
|
|
22
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
23
|
+
const dataStr = options.data === undefined
|
|
24
|
+
? "{}"
|
|
25
|
+
: typeof options.data === "string"
|
|
26
|
+
? options.data
|
|
27
|
+
: JSON.stringify(options.data);
|
|
28
|
+
const params = {
|
|
29
|
+
calleeId: String(options.calleeId ?? ctx.uid),
|
|
30
|
+
callId,
|
|
31
|
+
callType: options.callType ?? sendVoiceCall.CallType.GroupAudio,
|
|
32
|
+
hostCall: String(options.hostCall),
|
|
33
|
+
data: dataStr,
|
|
34
|
+
partners: (options.partners ?? []).map(String),
|
|
35
|
+
};
|
|
36
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
37
|
+
if (!encryptedParams)
|
|
38
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt cancelGroupCall params");
|
|
39
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/cancel`, {
|
|
40
|
+
zpw_type: 24,
|
|
41
|
+
params: encryptedParams,
|
|
42
|
+
});
|
|
43
|
+
const response = await utils.request(url, {
|
|
44
|
+
method: "GET",
|
|
45
|
+
});
|
|
46
|
+
return utils.resolve(response);
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
exports.cancelGroupCallFactory = cancelGroupCallFactory;
|
|
@@ -21,10 +21,14 @@ const cancelVoiceCallFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
|
21
21
|
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
22
22
|
if (!voiceCallService)
|
|
23
23
|
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
24
|
+
const rawCallType = options.callType ?? sendVoiceCall.CallType.Audio;
|
|
25
|
+
// Khớp với ZMessageSerializer::sendCancelCall (0x100026acc): callType = (callType != 1 ? 1 : 0)
|
|
26
|
+
// Cho phép truyền trực tiếp 0 (Audio) hoặc 1 (Video), hoặc CallType.Audio (1) -> 0, CallType.Video (3) -> 1
|
|
27
|
+
const normalizedCallType = rawCallType === 0 || rawCallType === sendVoiceCall.CallType.Audio ? 0 : 1;
|
|
24
28
|
const params = {
|
|
25
29
|
callerId: String(calleeId),
|
|
26
30
|
callId,
|
|
27
|
-
callType:
|
|
31
|
+
callType: normalizedCallType,
|
|
28
32
|
status: options.status ?? 0,
|
|
29
33
|
imei: ctx.imei,
|
|
30
34
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloCallController = require('../../call-engine/ZaloCallController.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Khởi tạo bộ điều phối cuộc gọi thuần TypeScript `ZaloCallController` (tích hợp `ZaloRtcSession` và kênh IPC `ZaloCallTransport`).
|
|
7
|
+
*/
|
|
8
|
+
function createControllerFactory(_ctx, api) {
|
|
9
|
+
return function createController(options = {}) {
|
|
10
|
+
return new ZaloCallController.ZaloCallController(api, options);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.createControllerFactory = createControllerFactory;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloRtcSession = require('../../call-engine/ZaloRtcSession.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Khởi tạo phiên gọi Thoại & Video thuần TypeScript / Node.js (`ZaloRtcSession` — UDP `ZRTPPacket` + `SRTP`)
|
|
7
|
+
* hoạt động độc lập 100% trên Worker / Server / Desktop / Mobile Bridge mà không cần cài đặt Zalo PC.
|
|
8
|
+
*/
|
|
9
|
+
function createRtcSessionFactory(_ctx, api) {
|
|
10
|
+
return function createRtcSession(options = {}) {
|
|
11
|
+
return new ZaloRtcSession.ZaloRtcSession(api, options);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.createRtcSessionFactory = createRtcSessionFactory;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
var sendVoiceCall = require('./sendVoiceCall.cjs');
|
|
6
|
+
|
|
7
|
+
const endGroupCallFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
8
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
9
|
+
/**
|
|
10
|
+
* Rời khỏi hoặc kết thúc cuộc gọi nhóm (`/api/voicecall/group/endcall`, command `12438`).
|
|
11
|
+
*
|
|
12
|
+
* @param callId ID của cuộc gọi nhóm
|
|
13
|
+
* @param options Thông tin `hostCall`, `calleeId`, `callType`, `partners` và `data`
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function endGroupCall(callId, options) {
|
|
17
|
+
if (!callId)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
19
|
+
if (!options?.hostCall)
|
|
20
|
+
throw new ZaloApiError.ZaloApiError("Missing hostCall");
|
|
21
|
+
if (!voiceCallService)
|
|
22
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
23
|
+
const dataStr = options.data === undefined
|
|
24
|
+
? "{}"
|
|
25
|
+
: typeof options.data === "string"
|
|
26
|
+
? options.data
|
|
27
|
+
: JSON.stringify(options.data);
|
|
28
|
+
const params = {
|
|
29
|
+
calleeId: String(options.calleeId ?? ctx.uid),
|
|
30
|
+
callId,
|
|
31
|
+
callType: options.callType ?? sendVoiceCall.CallType.GroupAudio,
|
|
32
|
+
hostCall: String(options.hostCall),
|
|
33
|
+
data: dataStr,
|
|
34
|
+
partners: (options.partners ?? []).map(String),
|
|
35
|
+
};
|
|
36
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
37
|
+
if (!encryptedParams)
|
|
38
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt endGroupCall params");
|
|
39
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/endcall`, {
|
|
40
|
+
zpw_type: 24,
|
|
41
|
+
params: encryptedParams,
|
|
42
|
+
});
|
|
43
|
+
const response = await utils.request(url, {
|
|
44
|
+
method: "GET",
|
|
45
|
+
});
|
|
46
|
+
return utils.resolve(response);
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
exports.endGroupCallFactory = endGroupCallFactory;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
var sendVoiceCall = require('./sendVoiceCall.cjs');
|
|
6
|
+
|
|
7
|
+
const finishGroupCallFactory = utils.apiFactory()((api, _ctx, utils) => {
|
|
8
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
9
|
+
/**
|
|
10
|
+
* Gửi báo cáo hoàn tất / kết thúc phiên gọi nhóm (`/api/voicecall/group/finish`, command `12446`).
|
|
11
|
+
*
|
|
12
|
+
* @param callId ID của cuộc gọi nhóm
|
|
13
|
+
* @param options Thông tin `hostCall`, `duration`, `joinTime`, `status`, `partners` và `data`
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function finishGroupCall(callId, options) {
|
|
17
|
+
if (!callId)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
19
|
+
if (!options?.hostCall)
|
|
20
|
+
throw new ZaloApiError.ZaloApiError("Missing hostCall");
|
|
21
|
+
if (!voiceCallService)
|
|
22
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
23
|
+
const dataStr = options.data === undefined
|
|
24
|
+
? "{}"
|
|
25
|
+
: typeof options.data === "string"
|
|
26
|
+
? options.data
|
|
27
|
+
: JSON.stringify(options.data);
|
|
28
|
+
const params = {
|
|
29
|
+
callId,
|
|
30
|
+
callType: options.callType ?? sendVoiceCall.CallType.GroupAudio,
|
|
31
|
+
data: dataStr,
|
|
32
|
+
duration: options.duration ?? 0,
|
|
33
|
+
hostCall: String(options.hostCall),
|
|
34
|
+
partners: (options.partners ?? []).map(String),
|
|
35
|
+
status: options.status ?? 0,
|
|
36
|
+
joinTime: options.joinTime ?? 0,
|
|
37
|
+
};
|
|
38
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
39
|
+
if (!encryptedParams)
|
|
40
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt finishGroupCall params");
|
|
41
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/finish`, {
|
|
42
|
+
zpw_type: 24,
|
|
43
|
+
params: encryptedParams,
|
|
44
|
+
});
|
|
45
|
+
const response = await utils.request(url, {
|
|
46
|
+
method: "GET",
|
|
47
|
+
});
|
|
48
|
+
return utils.resolve(response);
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
exports.finishGroupCallFactory = finishGroupCallFactory;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
var sendVoiceCall = require('./sendVoiceCall.cjs');
|
|
6
|
+
|
|
7
|
+
const getGroupCallStateFactory = utils.apiFactory()((api, _ctx, utils) => {
|
|
8
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
9
|
+
/**
|
|
10
|
+
* Lấy trạng thái hiện tại của cuộc gọi nhóm (`/api/voicecall/group/state`, command `12445`).
|
|
11
|
+
*
|
|
12
|
+
* @param callId ID của cuộc gọi nhóm
|
|
13
|
+
* @param hostCall User ID hoặc Group ID chủ trì cuộc gọi (`hostCall`)
|
|
14
|
+
* @param callType Loại cuộc gọi nhóm (`CallType.GroupAudio = 5` hoặc `CallType.GroupVideo = 6`)
|
|
15
|
+
* @throws {ZaloApiError}
|
|
16
|
+
*/
|
|
17
|
+
return async function getGroupCallState(callId, hostCall, callType = sendVoiceCall.CallType.GroupAudio) {
|
|
18
|
+
if (!callId)
|
|
19
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
20
|
+
if (!hostCall)
|
|
21
|
+
throw new ZaloApiError.ZaloApiError("Missing hostCall");
|
|
22
|
+
if (!voiceCallService)
|
|
23
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
24
|
+
const params = {
|
|
25
|
+
callId,
|
|
26
|
+
hostCall: String(hostCall),
|
|
27
|
+
callType,
|
|
28
|
+
};
|
|
29
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
30
|
+
if (!encryptedParams)
|
|
31
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt getGroupCallState params");
|
|
32
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/state`, {
|
|
33
|
+
zpw_type: 24,
|
|
34
|
+
params: encryptedParams,
|
|
35
|
+
});
|
|
36
|
+
const response = await utils.request(url, {
|
|
37
|
+
method: "GET",
|
|
38
|
+
});
|
|
39
|
+
return utils.resolve(response);
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
exports.getGroupCallStateFactory = getGroupCallStateFactory;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const holdVoiceCallFactory = utils.apiFactory()((api, _ctx, utils) => {
|
|
7
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
8
|
+
/**
|
|
9
|
+
* Gửi yêu cầu tạm giữ cuộc gọi (`/api/voicecall/holdreq`, command `11307`, signal `411`)
|
|
10
|
+
* hoặc phản hồi tạm giữ cuộc gọi (`/api/voicecall/holdresp`, command `11308`, signal `412`).
|
|
11
|
+
*
|
|
12
|
+
* @param toId User ID của đối phương trong cuộc gọi
|
|
13
|
+
* @param options Đặt `isResponse = true` nếu là gói phản hồi (`holdresp`)
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function holdVoiceCall(toId, options = {}) {
|
|
17
|
+
if (!toId)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing toId");
|
|
19
|
+
if (!voiceCallService)
|
|
20
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
21
|
+
const params = {
|
|
22
|
+
toId: String(toId),
|
|
23
|
+
};
|
|
24
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
25
|
+
if (!encryptedParams)
|
|
26
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt holdVoiceCall params");
|
|
27
|
+
const endpoint = options.isResponse ? "holdresp" : "holdreq";
|
|
28
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/${endpoint}`, {
|
|
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
|
+
});
|
|
38
|
+
|
|
39
|
+
exports.holdVoiceCallFactory = holdVoiceCallFactory;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const joinGroupCallFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
7
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
8
|
+
/**
|
|
9
|
+
* Tham gia vào một cuộc gọi nhóm đang diễn ra (`/api/voicecall/group/join`, command `12043`).
|
|
10
|
+
*
|
|
11
|
+
* @param callId ID của cuộc gọi nhóm
|
|
12
|
+
* @param options Thông tin `hostCall`, `userId`, `status`, `srcJoinCall`, `audioState`, `videoState` và `data`
|
|
13
|
+
* @throws {ZaloApiError}
|
|
14
|
+
*/
|
|
15
|
+
return async function joinGroupCall(callId, options) {
|
|
16
|
+
if (!callId)
|
|
17
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
18
|
+
if (!options?.hostCall)
|
|
19
|
+
throw new ZaloApiError.ZaloApiError("Missing hostCall");
|
|
20
|
+
if (!voiceCallService)
|
|
21
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
22
|
+
const dataStr = options.data === undefined
|
|
23
|
+
? "{}"
|
|
24
|
+
: typeof options.data === "string"
|
|
25
|
+
? options.data
|
|
26
|
+
: JSON.stringify(options.data);
|
|
27
|
+
const params = {
|
|
28
|
+
userId: String(options.userId ?? ctx.uid),
|
|
29
|
+
callId,
|
|
30
|
+
hostCall: String(options.hostCall),
|
|
31
|
+
status: options.status ?? 0,
|
|
32
|
+
srcJoinCall: options.srcJoinCall ?? 0,
|
|
33
|
+
audiostate: options.audioState ?? 1,
|
|
34
|
+
videostate: options.videoState ?? 0,
|
|
35
|
+
data: dataStr,
|
|
36
|
+
};
|
|
37
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
38
|
+
if (!encryptedParams)
|
|
39
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt joinGroupCall params");
|
|
40
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/join`, {
|
|
41
|
+
zpw_type: 24,
|
|
42
|
+
params: encryptedParams,
|
|
43
|
+
});
|
|
44
|
+
const response = await utils.request(url, {
|
|
45
|
+
method: "GET",
|
|
46
|
+
});
|
|
47
|
+
return utils.resolve(response);
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
exports.joinGroupCallFactory = joinGroupCallFactory;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const logEndVoiceCallFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
7
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
8
|
+
/**
|
|
9
|
+
* 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`).
|
|
10
|
+
*
|
|
11
|
+
* @param partnerId User ID của đối phương
|
|
12
|
+
* @param callId ID của cuộc gọi
|
|
13
|
+
* @param options Thông tin `status`, `duration`, `role` và `logData`
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function logEndVoiceCall(partnerId, callId, options = {}) {
|
|
17
|
+
if (!partnerId)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing partnerId");
|
|
19
|
+
if (!callId)
|
|
20
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
21
|
+
if (!voiceCallService)
|
|
22
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
23
|
+
const logdata = options.logData === undefined
|
|
24
|
+
? "{}"
|
|
25
|
+
: typeof options.logData === "string"
|
|
26
|
+
? options.logData
|
|
27
|
+
: JSON.stringify(options.logData);
|
|
28
|
+
const params = {
|
|
29
|
+
call_id: callId,
|
|
30
|
+
partner_id: String(partnerId),
|
|
31
|
+
status: options.status ?? 0,
|
|
32
|
+
logdata,
|
|
33
|
+
duration: options.duration ?? 0,
|
|
34
|
+
role: options.role ?? true,
|
|
35
|
+
imei: ctx.imei,
|
|
36
|
+
};
|
|
37
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
38
|
+
if (!encryptedParams)
|
|
39
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt logEndVoiceCall params");
|
|
40
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/logendcall`, {
|
|
41
|
+
zpw_type: 24,
|
|
42
|
+
params: encryptedParams,
|
|
43
|
+
});
|
|
44
|
+
const response = await utils.request(url, {
|
|
45
|
+
method: "GET",
|
|
46
|
+
});
|
|
47
|
+
return utils.resolve(response);
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
exports.logEndVoiceCallFactory = logEndVoiceCallFactory;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
var sendVoiceCall = require('./sendVoiceCall.cjs');
|
|
6
|
+
|
|
7
|
+
const notifyGroupCallFactory = utils.apiFactory()((api, _ctx, utils) => {
|
|
8
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
9
|
+
/**
|
|
10
|
+
* Gửi thông báo sự kiện trong cuộc gọi nhóm (`/api/voicecall/group/notify`, command `12447`).
|
|
11
|
+
*
|
|
12
|
+
* @param callId ID của cuộc gọi nhóm
|
|
13
|
+
* @param options Thông tin `hostCall`, `callType`, `status` và `data`
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function notifyGroupCall(callId, options) {
|
|
17
|
+
if (!callId)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
19
|
+
if (!options?.hostCall)
|
|
20
|
+
throw new ZaloApiError.ZaloApiError("Missing hostCall");
|
|
21
|
+
if (!voiceCallService)
|
|
22
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
23
|
+
const dataStr = options.data === undefined
|
|
24
|
+
? "{}"
|
|
25
|
+
: typeof options.data === "string"
|
|
26
|
+
? options.data
|
|
27
|
+
: JSON.stringify(options.data);
|
|
28
|
+
const params = {
|
|
29
|
+
callId,
|
|
30
|
+
hostCall: String(options.hostCall),
|
|
31
|
+
callType: options.callType ?? sendVoiceCall.CallType.GroupAudio,
|
|
32
|
+
status: options.status ?? 0,
|
|
33
|
+
data: dataStr,
|
|
34
|
+
};
|
|
35
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
36
|
+
if (!encryptedParams)
|
|
37
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt notifyGroupCall params");
|
|
38
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/notify`, {
|
|
39
|
+
zpw_type: 24,
|
|
40
|
+
params: encryptedParams,
|
|
41
|
+
});
|
|
42
|
+
const response = await utils.request(url, {
|
|
43
|
+
method: "GET",
|
|
44
|
+
});
|
|
45
|
+
return utils.resolve(response);
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
exports.notifyGroupCallFactory = notifyGroupCallFactory;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const pingGroupCallFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
7
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
8
|
+
/**
|
|
9
|
+
* 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`).
|
|
10
|
+
*
|
|
11
|
+
* @param callId ID của cuộc gọi nhóm
|
|
12
|
+
* @param options Thông tin `hostCall`, `userId`, `callState`, `audioState`, `videoState` và `params`
|
|
13
|
+
* @throws {ZaloApiError}
|
|
14
|
+
*/
|
|
15
|
+
return async function pingGroupCall(callId, options) {
|
|
16
|
+
if (!callId)
|
|
17
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
18
|
+
if (!options?.hostCall)
|
|
19
|
+
throw new ZaloApiError.ZaloApiError("Missing hostCall");
|
|
20
|
+
if (!voiceCallService)
|
|
21
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
22
|
+
const paramsStr = options.params === undefined
|
|
23
|
+
? "{}"
|
|
24
|
+
: typeof options.params === "string"
|
|
25
|
+
? options.params
|
|
26
|
+
: JSON.stringify(options.params);
|
|
27
|
+
const payload = {
|
|
28
|
+
callId,
|
|
29
|
+
hostCall: String(options.hostCall),
|
|
30
|
+
userId: String(options.userId ?? ctx.uid),
|
|
31
|
+
callstate: options.callState ?? 1,
|
|
32
|
+
audiostate: options.audioState ?? 1,
|
|
33
|
+
videostate: options.videoState ?? 0,
|
|
34
|
+
params: paramsStr,
|
|
35
|
+
};
|
|
36
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(payload));
|
|
37
|
+
if (!encryptedParams)
|
|
38
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt pingGroupCall params");
|
|
39
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/ping`, {
|
|
40
|
+
zpw_type: 24,
|
|
41
|
+
params: encryptedParams,
|
|
42
|
+
});
|
|
43
|
+
const response = await utils.request(url, {
|
|
44
|
+
method: "GET",
|
|
45
|
+
});
|
|
46
|
+
return utils.resolve(response);
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
exports.pingGroupCallFactory = pingGroupCallFactory;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const requestAudioToVideoCallFactory = utils.apiFactory()((api, _ctx, utils) => {
|
|
7
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
8
|
+
/**
|
|
9
|
+
* 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`).
|
|
10
|
+
*
|
|
11
|
+
* @param uidTo User ID của đối phương
|
|
12
|
+
* @param callId ID của cuộc gọi
|
|
13
|
+
* @param options Trạng thái yêu cầu (`status`, mặc định `1`)
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function requestAudioToVideoCall(uidTo, callId, options = {}) {
|
|
17
|
+
if (!uidTo)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing uidTo");
|
|
19
|
+
if (!callId)
|
|
20
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
21
|
+
if (!voiceCallService)
|
|
22
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
23
|
+
const params = {
|
|
24
|
+
uidTo: String(uidTo),
|
|
25
|
+
callId,
|
|
26
|
+
status: options.status ?? 1,
|
|
27
|
+
};
|
|
28
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
29
|
+
if (!encryptedParams)
|
|
30
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt requestAudioToVideoCall params");
|
|
31
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/requestaudio2video`, {
|
|
32
|
+
zpw_type: 24,
|
|
33
|
+
params: encryptedParams,
|
|
34
|
+
});
|
|
35
|
+
const response = await utils.request(url, {
|
|
36
|
+
method: "GET",
|
|
37
|
+
});
|
|
38
|
+
return utils.resolve(response);
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
exports.requestAudioToVideoCallFactory = requestAudioToVideoCallFactory;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
var sendVoiceCall = require('./sendVoiceCall.cjs');
|
|
6
|
+
|
|
7
|
+
const requestGroupCallFactory = utils.apiFactory()((api, _ctx, utils) => {
|
|
8
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
9
|
+
/**
|
|
10
|
+
* Xin cấp phát phiên gọi nhóm (Group Call) và máy chủ relay (`/api/voicecall/group/requestcall`, command `12433`).
|
|
11
|
+
*
|
|
12
|
+
* @param groupId ID của nhóm
|
|
13
|
+
* @param options Danh sách `partners`, `callId`, `typeRequest` (`CallType.GroupAudio = 5` hoặc `CallType.GroupVideo = 6`) và `data`
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function requestGroupCall(groupId, options) {
|
|
17
|
+
if (!groupId)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing groupId");
|
|
19
|
+
if (!options?.partners || !Array.isArray(options.partners)) {
|
|
20
|
+
throw new ZaloApiError.ZaloApiError("Missing partners array");
|
|
21
|
+
}
|
|
22
|
+
if (!voiceCallService)
|
|
23
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
24
|
+
const callId = options.callId ?? Math.floor(Math.random() * 2_000_000_000);
|
|
25
|
+
const dataStr = options.data === undefined
|
|
26
|
+
? "{}"
|
|
27
|
+
: typeof options.data === "string"
|
|
28
|
+
? options.data
|
|
29
|
+
: JSON.stringify(options.data);
|
|
30
|
+
const params = {
|
|
31
|
+
groupId: String(groupId),
|
|
32
|
+
callId,
|
|
33
|
+
typeRequest: options.typeRequest ?? sendVoiceCall.CallType.GroupAudio,
|
|
34
|
+
data: dataStr,
|
|
35
|
+
partners: options.partners.map(String),
|
|
36
|
+
};
|
|
37
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
38
|
+
if (!encryptedParams)
|
|
39
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt requestGroupCall params");
|
|
40
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/requestcall`, {
|
|
41
|
+
zpw_type: 24,
|
|
42
|
+
params: encryptedParams,
|
|
43
|
+
});
|
|
44
|
+
const response = await utils.request(url, {
|
|
45
|
+
method: "GET",
|
|
46
|
+
});
|
|
47
|
+
return utils.resolve(response);
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
exports.requestGroupCallFactory = requestGroupCallFactory;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const requestShareScreenCallFactory = utils.apiFactory()((api, _ctx, utils) => {
|
|
7
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
8
|
+
/**
|
|
9
|
+
* 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`).
|
|
10
|
+
*
|
|
11
|
+
* @param uidTo User ID của đối phương
|
|
12
|
+
* @param callId ID của cuộc gọi
|
|
13
|
+
* @param options Trạng thái chia sẻ màn hình (`status`: `1` bật, `0` tắt)
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function requestShareScreenCall(uidTo, callId, options = {}) {
|
|
17
|
+
if (!uidTo)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing uidTo");
|
|
19
|
+
if (!callId)
|
|
20
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
21
|
+
if (!voiceCallService)
|
|
22
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
23
|
+
const params = {
|
|
24
|
+
uidTo: String(uidTo),
|
|
25
|
+
callId,
|
|
26
|
+
status: options.status ?? 1,
|
|
27
|
+
};
|
|
28
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
29
|
+
if (!encryptedParams)
|
|
30
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt requestShareScreenCall params");
|
|
31
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/requestsharescreen`, {
|
|
32
|
+
zpw_type: 24,
|
|
33
|
+
params: encryptedParams,
|
|
34
|
+
});
|
|
35
|
+
const response = await utils.request(url, {
|
|
36
|
+
method: "GET",
|
|
37
|
+
});
|
|
38
|
+
return utils.resolve(response);
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
exports.requestShareScreenCallFactory = requestShareScreenCallFactory;
|