@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,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 requestVoiceCallFactory = utils.apiFactory()((api, ctx, utils$1) => {
|
|
8
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
9
|
+
/**
|
|
10
|
+
* 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`).
|
|
11
|
+
*
|
|
12
|
+
* @param calleeId User ID của người nhận cuộc gọi
|
|
13
|
+
* @param options Tuỳ chọn loại cuộc gọi (`callType`), `callId` và `codec`
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function requestVoiceCall(calleeId, options = {}) {
|
|
17
|
+
if (!calleeId)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing calleeId");
|
|
19
|
+
if (!voiceCallService)
|
|
20
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
21
|
+
const callType = options.callType ?? sendVoiceCall.CallType.Audio;
|
|
22
|
+
const callId = options.callId ?? Math.floor(Math.random() * 2_000_000_000);
|
|
23
|
+
const codec = options.codec ?? "[]";
|
|
24
|
+
const params = {
|
|
25
|
+
calleeId: String(calleeId),
|
|
26
|
+
callId,
|
|
27
|
+
codec,
|
|
28
|
+
typeRequest: callType,
|
|
29
|
+
imei: ctx.imei,
|
|
30
|
+
};
|
|
31
|
+
const encryptedParams = utils$1.encodeAES(JSON.stringify(params));
|
|
32
|
+
if (!encryptedParams)
|
|
33
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt requestVoiceCall params");
|
|
34
|
+
const url = utils$1.makeURL(`${voiceCallService}/api/voicecall/requestcall`, {
|
|
35
|
+
zpw_type: 24,
|
|
36
|
+
params: encryptedParams,
|
|
37
|
+
});
|
|
38
|
+
const response = await utils$1.request(url, {
|
|
39
|
+
method: "GET",
|
|
40
|
+
});
|
|
41
|
+
const serverInfo = await utils.resolveResponse(ctx, response, (result) => {
|
|
42
|
+
const raw = result.data;
|
|
43
|
+
return typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
...serverInfo,
|
|
47
|
+
callId,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
exports.requestVoiceCallFactory = requestVoiceCallFactory;
|
|
@@ -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 ringRingGroupCallFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
8
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
9
|
+
/**
|
|
10
|
+
* Báo hiệu thiết bị đang đổ chuông cho cuộc gọi nhóm (`/api/voicecall/group/ringring`, command `12439`).
|
|
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 ringRingGroupCall(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 ringRingGroupCall params");
|
|
39
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/ringring`, {
|
|
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.ringRingGroupCallFactory = ringRingGroupCallFactory;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const ringRingVoiceCallFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
7
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
8
|
+
/**
|
|
9
|
+
* 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`).
|
|
10
|
+
*
|
|
11
|
+
* @param callerId User ID của người gọi đến
|
|
12
|
+
* @param callId ID của cuộc gọi
|
|
13
|
+
* @param options Tuỳ chọn mã trạng thái (`status`, mặc định `0`)
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function ringRingVoiceCall(callerId, callId, options = {}) {
|
|
17
|
+
if (!callerId)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing callerId");
|
|
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
|
+
callerId: String(callerId),
|
|
25
|
+
callId,
|
|
26
|
+
status: options.status ?? 0,
|
|
27
|
+
imei: ctx.imei,
|
|
28
|
+
};
|
|
29
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
30
|
+
if (!encryptedParams)
|
|
31
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt ringRingVoiceCall params");
|
|
32
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/ringring`, {
|
|
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.ringRingVoiceCallFactory = ringRingVoiceCallFactory;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 sendRequestGroupCallFactory = utils.apiFactory()((api, _ctx, utils) => {
|
|
8
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
9
|
+
/**
|
|
10
|
+
* Gửi tín hiệu mời tham gia / đổ chuông cuộc gọi nhóm (`/api/voicecall/group/request`, command `12434`).
|
|
11
|
+
*
|
|
12
|
+
* @param groupId ID của nhóm
|
|
13
|
+
* @param options Thông tin `callId`, `session`, `partners`, `callType` và `data`
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function sendRequestGroupCall(groupId, options) {
|
|
17
|
+
if (!groupId)
|
|
18
|
+
throw new ZaloApiError.ZaloApiError("Missing groupId");
|
|
19
|
+
if (!options?.callId)
|
|
20
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
21
|
+
if (!options?.session)
|
|
22
|
+
throw new ZaloApiError.ZaloApiError("Missing session");
|
|
23
|
+
if (!voiceCallService)
|
|
24
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
25
|
+
const dataStr = options.data === undefined
|
|
26
|
+
? "{}"
|
|
27
|
+
: typeof options.data === "string"
|
|
28
|
+
? options.data
|
|
29
|
+
: JSON.stringify(options.data);
|
|
30
|
+
const params = {
|
|
31
|
+
calleeId: options.calleeId ?? "",
|
|
32
|
+
callId: options.callId,
|
|
33
|
+
callType: options.callType ?? sendVoiceCall.CallType.GroupAudio,
|
|
34
|
+
data: dataStr,
|
|
35
|
+
session: options.session,
|
|
36
|
+
partners: (options.partners ?? []).map(String),
|
|
37
|
+
groupId: String(groupId),
|
|
38
|
+
};
|
|
39
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
40
|
+
if (!encryptedParams)
|
|
41
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt sendRequestGroupCall params");
|
|
42
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/request`, {
|
|
43
|
+
zpw_type: 24,
|
|
44
|
+
params: encryptedParams,
|
|
45
|
+
});
|
|
46
|
+
const response = await utils.request(url, {
|
|
47
|
+
method: "GET",
|
|
48
|
+
});
|
|
49
|
+
return utils.resolve(response);
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
exports.sendRequestGroupCallFactory = sendRequestGroupCallFactory;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const sendRequestVoiceCallFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
7
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
8
|
+
/**
|
|
9
|
+
* Gửi tín hiệu đổ chuông kèm thông tin kết nối RTP/RTCP & `extendData` (`/api/voicecall/request`, command `11301`, signal `416`).
|
|
10
|
+
*
|
|
11
|
+
* @param calleeId User ID của người nhận cuộc gọi
|
|
12
|
+
* @param options Thông tin `callId`, `session`, `rtpAddress`, `rtcpAddress`, `codec` và `extendData`
|
|
13
|
+
* @throws {ZaloApiError}
|
|
14
|
+
*/
|
|
15
|
+
return async function sendRequestVoiceCall(calleeId, options) {
|
|
16
|
+
if (!calleeId)
|
|
17
|
+
throw new ZaloApiError.ZaloApiError("Missing calleeId");
|
|
18
|
+
if (!options?.callId)
|
|
19
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
20
|
+
if (!options?.session)
|
|
21
|
+
throw new ZaloApiError.ZaloApiError("Missing session");
|
|
22
|
+
if (!voiceCallService)
|
|
23
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
24
|
+
const extendDataStr = options.extendData === undefined
|
|
25
|
+
? undefined
|
|
26
|
+
: typeof options.extendData === "string"
|
|
27
|
+
? options.extendData
|
|
28
|
+
: JSON.stringify(options.extendData);
|
|
29
|
+
const params = {
|
|
30
|
+
calleeId: String(calleeId),
|
|
31
|
+
rtcpAddress: options.rtcpAddress ?? "",
|
|
32
|
+
rtpAddress: options.rtpAddress ?? "",
|
|
33
|
+
codec: options.codec ?? "[]",
|
|
34
|
+
session: options.session,
|
|
35
|
+
callId: options.callId,
|
|
36
|
+
imei: ctx.imei,
|
|
37
|
+
};
|
|
38
|
+
if (extendDataStr) {
|
|
39
|
+
params.extendData = extendDataStr;
|
|
40
|
+
params.subCommand = options.subCommand ?? 3;
|
|
41
|
+
}
|
|
42
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
43
|
+
if (!encryptedParams)
|
|
44
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt sendRequestVoiceCall params");
|
|
45
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/request`, {
|
|
46
|
+
zpw_type: 24,
|
|
47
|
+
params: encryptedParams,
|
|
48
|
+
});
|
|
49
|
+
const response = await utils.request(url, {
|
|
50
|
+
method: "GET",
|
|
51
|
+
});
|
|
52
|
+
return utils.resolve(response);
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
exports.sendRequestVoiceCallFactory = sendRequestVoiceCallFactory;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var ZRTPPacketCodec = require('../../call-engine/ZRTPPacketCodec.cjs');
|
|
4
5
|
var utils = require('../../utils.cjs');
|
|
5
6
|
|
|
6
7
|
exports.CallType = void 0;
|
|
7
8
|
(function (CallType) {
|
|
8
9
|
CallType[CallType["Audio"] = 1] = "Audio";
|
|
9
10
|
CallType[CallType["Video"] = 3] = "Video";
|
|
11
|
+
CallType[CallType["GroupAudio"] = 5] = "GroupAudio";
|
|
12
|
+
CallType[CallType["GroupVideo"] = 6] = "GroupVideo";
|
|
10
13
|
})(exports.CallType || (exports.CallType = {}));
|
|
11
14
|
function parseServerEndpoint(addr) {
|
|
12
15
|
if (!addr)
|
|
@@ -35,7 +38,7 @@ const sendVoiceCallFactory = utils.apiFactory()((api, ctx, utils$1) => {
|
|
|
35
38
|
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
36
39
|
const callType = options.callType ?? exports.CallType.Audio;
|
|
37
40
|
const callId = options.callId ?? Math.floor(Math.random() * 2_000_000_000);
|
|
38
|
-
const codec = options.codec ??
|
|
41
|
+
const codec = options.codec ?? ZRTPPacketCodec.DEFAULT_ZALO_AUDIO_CODEC;
|
|
39
42
|
const normalizedCalleeId = String(calleeId);
|
|
40
43
|
// Step 1: Allocate call session & RTP/RTCP relay endpoints (/api/voicecall/requestcall, command 11300)
|
|
41
44
|
const step1Params = {
|
|
@@ -64,16 +67,15 @@ const sendVoiceCallFactory = utils.apiFactory()((api, ctx, utils$1) => {
|
|
|
64
67
|
const rtp = parseServerEndpoint(resolvedRtpServer);
|
|
65
68
|
const rtcp = parseServerEndpoint(resolvedRtcpServer);
|
|
66
69
|
const sessId = serverInfo?.sessId ?? `${normalizedCalleeId}_${callId}_401`;
|
|
67
|
-
const resolvedCodec = serverInfo?.codec
|
|
70
|
+
const resolvedCodec = serverInfo?.codec && serverInfo.codec !== "[]" ? serverInfo.codec : codec;
|
|
68
71
|
// Step 2: Send ringing signaling request (/api/voicecall/request, command 11301)
|
|
69
72
|
const isVideo = callType === exports.CallType.Video;
|
|
70
73
|
const extendData = JSON.stringify({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
platform: 5,
|
|
74
|
+
...ZRTPPacketCodec.buildZrtcExtendData({
|
|
75
|
+
rtpAddress: rtp.host,
|
|
76
|
+
rtcpAddress: rtcp.host,
|
|
77
|
+
isVideo,
|
|
78
|
+
}),
|
|
77
79
|
rtcpDiff: 0,
|
|
78
80
|
rtcp: [{ ip: rtcp.ip, port: rtcp.port }],
|
|
79
81
|
rtp: [{ ip: rtp.ip, port: rtp.port }],
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const shareScreenGroupCallFactory = utils.apiFactory()((api, ctx, utils) => {
|
|
7
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
8
|
+
/**
|
|
9
|
+
* Bật/tắt chia sẻ màn hình trong cuộc gọi nhóm (`/api/voicecall/group/sharescreen`, command `12044`).
|
|
10
|
+
*
|
|
11
|
+
* @param callId ID của cuộc gọi nhóm
|
|
12
|
+
* @param options Thông tin `hostCall`, `userId`, `status`, `audioState`, `videoState` và `data`
|
|
13
|
+
* @throws {ZaloApiError}
|
|
14
|
+
*/
|
|
15
|
+
return async function shareScreenGroupCall(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 ?? 1,
|
|
32
|
+
audiostate: options.audioState ?? 1,
|
|
33
|
+
videostate: options.videoState ?? 1,
|
|
34
|
+
data: dataStr,
|
|
35
|
+
};
|
|
36
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
37
|
+
if (!encryptedParams)
|
|
38
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt shareScreenGroupCall params");
|
|
39
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/group/sharescreen`, {
|
|
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.shareScreenGroupCallFactory = shareScreenGroupCallFactory;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const unholdVoiceCallFactory = utils.apiFactory()((api, _ctx, utils) => {
|
|
7
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
8
|
+
/**
|
|
9
|
+
* Gửi yêu cầu tiếp tục cuộc gọi đang tạm giữ (`/api/voicecall/unholdreq`, command `11309`, signal `413`)
|
|
10
|
+
* hoặc phản hồi tiếp tục cuộc gọi (`/api/voicecall/unholdresp`, command `11310`, signal `414`).
|
|
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 (`unholdresp`)
|
|
14
|
+
* @throws {ZaloApiError}
|
|
15
|
+
*/
|
|
16
|
+
return async function unholdVoiceCall(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 unholdVoiceCall params");
|
|
27
|
+
const endpoint = options.isResponse ? "unholdresp" : "unholdreq";
|
|
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.unholdVoiceCallFactory = unholdVoiceCallFactory;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
|
|
4
|
+
var utils = require('../../utils.cjs');
|
|
5
|
+
|
|
6
|
+
const updateCallMediaStateFactory = utils.apiFactory()((api, _ctx, utils) => {
|
|
7
|
+
const voiceCallService = api.zpwServiceMap.voice_call?.[0];
|
|
8
|
+
/**
|
|
9
|
+
* Đồng bộ trạng thái bật/tắt Camera và Microphone trong cuộc gọi 1-1 (`/api/voicecall/conf`, command `12006`).
|
|
10
|
+
* Khớp chính xác với `ZMessageSerializer::sendOnOffMicCam` (`0x100026cdc`):
|
|
11
|
+
* - Khi bật/tắt Camera (`UiOnOffCameraEvent`): `isOnCam = 1 | 0`, `isOnMic = -1`, `data = ""`
|
|
12
|
+
* - Khi bật/tắt Mic (`UiMuteEvent`): `isOnCam = -1`, `isOnMic = 1 | 0`, `data = ""`
|
|
13
|
+
*
|
|
14
|
+
* @param calleeId User ID của đối phương
|
|
15
|
+
* @param callId ID của cuộc gọi
|
|
16
|
+
* @param options Trạng thái `isOnCam`, `isOnMic` và `data` bổ sung
|
|
17
|
+
* @throws {ZaloApiError}
|
|
18
|
+
*/
|
|
19
|
+
return async function updateCallMediaState(calleeId, callId, options) {
|
|
20
|
+
if (!calleeId)
|
|
21
|
+
throw new ZaloApiError.ZaloApiError("Missing calleeId");
|
|
22
|
+
if (!callId)
|
|
23
|
+
throw new ZaloApiError.ZaloApiError("Missing callId");
|
|
24
|
+
if (!voiceCallService)
|
|
25
|
+
throw new ZaloApiError.ZaloApiError("Missing voice_call service URL in zpwServiceMap");
|
|
26
|
+
const dataStr = options.data === undefined
|
|
27
|
+
? ""
|
|
28
|
+
: typeof options.data === "string"
|
|
29
|
+
? options.data
|
|
30
|
+
: JSON.stringify(options.data);
|
|
31
|
+
const isOnCamVal = options.isOnCam === undefined
|
|
32
|
+
? -1
|
|
33
|
+
: typeof options.isOnCam === "boolean"
|
|
34
|
+
? options.isOnCam
|
|
35
|
+
? 1
|
|
36
|
+
: 0
|
|
37
|
+
: Number(options.isOnCam);
|
|
38
|
+
const isOnMicVal = options.isOnMic === undefined
|
|
39
|
+
? -1
|
|
40
|
+
: typeof options.isOnMic === "boolean"
|
|
41
|
+
? options.isOnMic
|
|
42
|
+
? 1
|
|
43
|
+
: 0
|
|
44
|
+
: Number(options.isOnMic);
|
|
45
|
+
const params = {
|
|
46
|
+
calleeId: String(calleeId),
|
|
47
|
+
callId,
|
|
48
|
+
isOnCam: isOnCamVal,
|
|
49
|
+
isOnMic: isOnMicVal,
|
|
50
|
+
data: dataStr,
|
|
51
|
+
};
|
|
52
|
+
const encryptedParams = utils.encodeAES(JSON.stringify(params));
|
|
53
|
+
if (!encryptedParams)
|
|
54
|
+
throw new ZaloApiError.ZaloApiError("Failed to encrypt updateCallMediaState params");
|
|
55
|
+
const url = utils.makeURL(`${voiceCallService}/api/voicecall/conf`, {
|
|
56
|
+
zpw_type: 24,
|
|
57
|
+
params: encryptedParams,
|
|
58
|
+
});
|
|
59
|
+
const response = await utils.request(url, {
|
|
60
|
+
method: "GET",
|
|
61
|
+
});
|
|
62
|
+
return utils.resolve(response);
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
exports.updateCallMediaStateFactory = updateCallMediaStateFactory;
|