@voipsdk/react-native-voipcloud 0.2.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.md +182 -117
- package/android/build.gradle +7 -7
- package/android/src/main/java/com/voipcloud/sdk/rn/VoipCloudModule.java +307 -208
- package/android/src/main/java/com/voipcloud/sdk/rn/internal/BridgeGuard.java +74 -0
- package/android/src/main/java/com/voipcloud/sdk/rn/internal/Events.java +7 -2
- package/android/src/main/java/com/voipcloud/sdk/rn/internal/ManagedAccount.java +49 -5
- package/android/src/main/java/com/voipcloud/sdk/rn/internal/ManagedCall.java +58 -2
- package/android/src/main/java/com/voipcloud/sdk/rn/internal/ManagedCallRegistry.java +4 -0
- package/android/src/main/libs/voipcloud-release.aar +0 -0
- package/ios/VoipCloud.mm +8 -8
- package/lib/commonjs/VoipCloud.js +33 -48
- package/lib/commonjs/VoipCloud.js.map +1 -1
- package/lib/commonjs/events.js +13 -7
- package/lib/commonjs/events.js.map +1 -1
- package/lib/commonjs/index.js +2 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeModule.js +18 -0
- package/lib/commonjs/nativeModule.js.map +1 -0
- package/lib/module/VoipCloud.js +34 -48
- package/lib/module/VoipCloud.js.map +1 -1
- package/lib/module/events.js +9 -8
- package/lib/module/events.js.map +1 -1
- package/lib/module/index.js +1 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeModule.js +13 -0
- package/lib/module/nativeModule.js.map +1 -0
- package/lib/typescript/VoipCloud.d.ts +7 -31
- package/lib/typescript/events.d.ts +6 -2
- package/lib/typescript/index.d.ts +2 -3
- package/lib/typescript/nativeModule.d.ts +7 -0
- package/lib/typescript/types.d.ts +5 -17
- package/package.json +7 -5
- package/react-native-voipcloud.podspec +7 -5
- package/src/VoipCloud.ts +42 -49
- package/src/events.ts +9 -8
- package/src/index.ts +1 -3
- package/src/nativeModule.ts +17 -0
- package/src/types.ts +5 -18
- package/lib/commonjs/License.js +0 -51
- package/lib/commonjs/License.js.map +0 -1
- package/lib/module/License.js +0 -45
- package/lib/module/License.js.map +0 -1
- package/lib/typescript/License.d.ts +0 -31
- package/src/License.ts +0 -52
package/lib/module/VoipCloud.js
CHANGED
|
@@ -1,83 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { License } from './License';
|
|
1
|
+
import { NativeVoipCloud } from './nativeModule';
|
|
3
2
|
import { on } from './events';
|
|
4
|
-
|
|
3
|
+
|
|
4
|
+
/** Thrown as Promise rejection — never crashes at import time. */
|
|
5
|
+
function rejectNotLinked() {
|
|
6
|
+
return Promise.reject(Object.assign(new Error('@voipsdk/react-native-voipcloud native module is not linked. ' + 'Install the package, rebuild the Android app ' + '(./gradlew clean assembleDebug), and ensure voipcloud-release.aar is packaged.'), {
|
|
7
|
+
code: 'VC_NOT_LINKED'
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
function callNative(fn) {
|
|
11
|
+
if (!NativeVoipCloud) return rejectNotLinked();
|
|
12
|
+
return fn();
|
|
13
|
+
}
|
|
5
14
|
|
|
6
15
|
/**
|
|
7
|
-
* Top-level VoIP SDK. Workflow:
|
|
16
|
+
* Top-level VoIP SDK for {@code @voipsdk/react-native-voipcloud}. Workflow:
|
|
8
17
|
*
|
|
9
|
-
* 1. {@link
|
|
10
|
-
* 2. {@link
|
|
11
|
-
* 3. {@link
|
|
12
|
-
* 4. {@link makeCall} / {@link answer} / {@link hangup}.
|
|
18
|
+
* 1. {@link init} — start the PJSIP endpoint.
|
|
19
|
+
* 2. {@link register} — get an `accountId` back.
|
|
20
|
+
* 3. {@link makeCall} / {@link answer} / {@link hangup}.
|
|
13
21
|
*
|
|
14
|
-
* Every method returns a Promise.
|
|
15
|
-
* Promise rejection with `code = "VC_<NAME>"` matching the
|
|
16
|
-
* `PJ_EVOIPCLOUD_*` enum from `voipcloud_errno.h`.
|
|
22
|
+
* Every method returns a Promise. Failures reject with a `VC_*` code.
|
|
17
23
|
*/
|
|
18
24
|
export const VoipCloud = {
|
|
19
|
-
// ---------------------- License ---------------------------------
|
|
20
|
-
License,
|
|
21
|
-
// ---------------------- Lifecycle -------------------------------
|
|
22
25
|
init(cfg = {}) {
|
|
23
|
-
return
|
|
26
|
+
return callNative(() => NativeVoipCloud.init(cfg ?? {}));
|
|
24
27
|
},
|
|
25
28
|
shutdown() {
|
|
26
|
-
return
|
|
29
|
+
return callNative(() => NativeVoipCloud.shutdown());
|
|
27
30
|
},
|
|
28
|
-
// ---------------------- Accounts --------------------------------
|
|
29
|
-
/** Register a new SIP account. Resolves with the account id. */
|
|
30
31
|
register(account) {
|
|
31
|
-
return
|
|
32
|
+
return callNative(() => NativeVoipCloud.register(account));
|
|
32
33
|
},
|
|
33
34
|
unregister(accountId) {
|
|
34
|
-
return
|
|
35
|
+
return callNative(() => NativeVoipCloud.unregister(accountId));
|
|
35
36
|
},
|
|
36
|
-
// ---------------------- Calls -----------------------------------
|
|
37
|
-
/** Place an outbound call. Resolves with the new callId. */
|
|
38
37
|
makeCall(accountId, destinationUri) {
|
|
39
|
-
return
|
|
38
|
+
return callNative(() => NativeVoipCloud.makeCall(accountId, destinationUri));
|
|
40
39
|
},
|
|
41
40
|
answer(callId) {
|
|
42
|
-
return
|
|
41
|
+
return callNative(() => NativeVoipCloud.answer(callId));
|
|
43
42
|
},
|
|
44
|
-
hangup(callId) {
|
|
45
|
-
return
|
|
43
|
+
hangup(callId, mode = 'normal') {
|
|
44
|
+
return callNative(() => NativeVoipCloud.hangup(callId, mode));
|
|
46
45
|
},
|
|
47
46
|
hold(callId) {
|
|
48
|
-
return
|
|
47
|
+
return callNative(() => NativeVoipCloud.hold(callId));
|
|
49
48
|
},
|
|
50
49
|
unhold(callId) {
|
|
51
|
-
return
|
|
50
|
+
return callNative(() => NativeVoipCloud.unhold(callId));
|
|
52
51
|
},
|
|
53
|
-
/**
|
|
54
|
-
* Mute / unmute the local microphone for a call. Implemented by
|
|
55
|
-
* stopping / starting the capture device's transmission to the
|
|
56
|
-
* call's active audio media — independent of `hold`. A
|
|
57
|
-
* `callMediaState` event fires after the toggle so the UI can
|
|
58
|
-
* mirror the new `isMuted` flag without polling.
|
|
59
|
-
*/
|
|
60
52
|
mute(callId, on) {
|
|
61
|
-
return
|
|
53
|
+
return callNative(() => NativeVoipCloud.mute(callId, on));
|
|
62
54
|
},
|
|
63
55
|
sendDtmf(callId, digits) {
|
|
64
|
-
return
|
|
56
|
+
return callNative(() => NativeVoipCloud.sendDtmf(callId, digits));
|
|
65
57
|
},
|
|
66
|
-
/**
|
|
67
|
-
* Blind-transfer a call (SIP REFER) to a new destination. The
|
|
68
|
-
* local leg moves to DISCONNECTED once the remote party accepts.
|
|
69
|
-
*/
|
|
70
58
|
transferCall(callId, destinationUri) {
|
|
71
|
-
return
|
|
59
|
+
return callNative(() => NativeVoipCloud.transferCall(callId, destinationUri));
|
|
72
60
|
},
|
|
73
|
-
/**
|
|
74
|
-
* End every active call. Each call still emits its own
|
|
75
|
-
* `callState` event with state=DISCONNECTED.
|
|
76
|
-
*/
|
|
77
61
|
hangupAllCalls() {
|
|
78
|
-
return
|
|
62
|
+
return callNative(() => NativeVoipCloud.hangupAllCalls());
|
|
63
|
+
},
|
|
64
|
+
reconnectCallAudio(callId) {
|
|
65
|
+
return callNative(() => NativeVoipCloud.reconnectCallAudio(callId));
|
|
79
66
|
},
|
|
80
|
-
// ---------------------- Events ----------------------------------
|
|
81
67
|
on
|
|
82
68
|
};
|
|
83
69
|
//# sourceMappingURL=VoipCloud.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["NativeVoipCloud","on","rejectNotLinked","Promise","reject","Object","assign","Error","code","callNative","fn","VoipCloud","init","cfg","shutdown","register","account","unregister","accountId","makeCall","destinationUri","answer","callId","hangup","mode","hold","unhold","mute","sendDtmf","digits","transferCall","hangupAllCalls","reconnectCallAudio"],"sourceRoot":"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.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { NativeEventEmitter
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// Lazy emitter — must point at the module to satisfy the contract
|
|
5
|
-
// NativeEventEmitter expects on RN 0.65+.
|
|
6
|
-
const emitter = Native ? new NativeEventEmitter(Native) : null;
|
|
1
|
+
import { NativeEventEmitter } from 'react-native';
|
|
2
|
+
import { NATIVE_MODULE_NAME, NativeVoipCloud } from './nativeModule';
|
|
3
|
+
const emitter = NativeVoipCloud ? new NativeEventEmitter(NativeVoipCloud) : null;
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
|
-
* Subscribe to a typed event
|
|
10
|
-
* be called from a React `useEffect`
|
|
6
|
+
* Subscribe to a typed event from {@code @voipsdk/react-native-voipcloud}.
|
|
7
|
+
* Returns a handle whose `remove()` must be called from a React `useEffect`
|
|
8
|
+
* cleanup to avoid leaks.
|
|
11
9
|
*/
|
|
12
10
|
export function on(name, callback) {
|
|
13
11
|
if (!emitter) {
|
|
@@ -20,4 +18,7 @@ export function on(name, callback) {
|
|
|
20
18
|
remove: () => sub.remove()
|
|
21
19
|
};
|
|
22
20
|
}
|
|
21
|
+
|
|
22
|
+
/** Native module name registered with React Native (for debugging). */
|
|
23
|
+
export { NATIVE_MODULE_NAME };
|
|
23
24
|
//# sourceMappingURL=events.js.map
|
package/lib/module/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","NATIVE_MODULE_NAME","NativeVoipCloud","emitter","on","name","callback","remove","sub","addListener"],"sourceRoot":"../../src","sources":["events.ts"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,cAAc;AAEjD,SAASC,kBAAkB,EAAEC,eAAe,QAAQ,gBAAgB;AAEpE,MAAMC,OAAO,GAAGD,eAAe,GAAG,IAAIF,kBAAkB,CAACE,eAAe,CAAC,GAAG,IAAI;;AAEhF;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,EAAEA,CACdC,IAAO,EACPC,QAAsC,EAC1B;EACZ,IAAI,CAACH,OAAO,EAAE;IACV,OAAO;MAAEI,MAAM,EAAEA,CAAA,KAAM,CAAC;IAAE,CAAC;EAC/B;EACA,MAAMC,GAAG,GAAGL,OAAO,CAACM,WAAW,CAACJ,IAAI,EAAEC,QAAgC,CAAC;EACvE,OAAO;IAAEC,MAAM,EAAEA,CAAA,KAAMC,GAAG,CAACD,MAAM,CAAC;EAAE,CAAC;AACzC;;AAEA;AACA,SAASN,kBAAkB","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["VoipCloud","
|
|
1
|
+
{"version":3,"names":["VoipCloud","on","addEventListener","NATIVE_MODULE_NAME"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,SAAS,QAAQ,aAAa;AACvC,SAASC,EAAE,IAAIC,gBAAgB,EAAEC,kBAAkB,QAAQ,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Native module name — must match {@code VoipCloudModule.getName()} on Android
|
|
5
|
+
* and the future iOS RCT export. Derived from npm package
|
|
6
|
+
* {@code @voipsdk/react-native-voipcloud}.
|
|
7
|
+
*/
|
|
8
|
+
export const NATIVE_MODULE_NAME = 'VoipsdkReactNativeVoipcloud';
|
|
9
|
+
export const NativeVoipCloud = NativeModules[NATIVE_MODULE_NAME];
|
|
10
|
+
if (!NativeVoipCloud) {
|
|
11
|
+
console.warn('[@voipsdk/react-native-voipcloud] Native module not linked. ' + 'Methods will reject with VC_NOT_LINKED until the app is rebuilt.');
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=nativeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","NATIVE_MODULE_NAME","NativeVoipCloud","console","warn"],"sourceRoot":"../../src","sources":["nativeModule.ts"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;;AAE5C;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,GAAG,6BAA6B;AAE/D,OAAO,MAAMC,eAAe,GAAGF,aAAa,CAACC,kBAAkB,CAAC;AAEhE,IAAI,CAACC,eAAe,EAAE;EAClBC,OAAO,CAACC,IAAI,CACR,8DAA8D,GAC9D,kEACJ,CAAC;AACL","ignoreList":[]}
|
|
@@ -1,52 +1,28 @@
|
|
|
1
1
|
import type { AccountConfig, InitConfig } from './types';
|
|
2
2
|
import { on } from './events';
|
|
3
3
|
/**
|
|
4
|
-
* Top-level VoIP SDK. Workflow:
|
|
4
|
+
* Top-level VoIP SDK for {@code @voipsdk/react-native-voipcloud}. Workflow:
|
|
5
5
|
*
|
|
6
|
-
* 1. {@link
|
|
7
|
-
* 2. {@link
|
|
8
|
-
* 3. {@link
|
|
9
|
-
* 4. {@link makeCall} / {@link answer} / {@link hangup}.
|
|
6
|
+
* 1. {@link init} — start the PJSIP endpoint.
|
|
7
|
+
* 2. {@link register} — get an `accountId` back.
|
|
8
|
+
* 3. {@link makeCall} / {@link answer} / {@link hangup}.
|
|
10
9
|
*
|
|
11
|
-
* Every method returns a Promise.
|
|
12
|
-
* Promise rejection with `code = "VC_<NAME>"` matching the
|
|
13
|
-
* `PJ_EVOIPCLOUD_*` enum from `voipcloud_errno.h`.
|
|
10
|
+
* Every method returns a Promise. Failures reject with a `VC_*` code.
|
|
14
11
|
*/
|
|
15
12
|
export declare const VoipCloud: {
|
|
16
|
-
License: {
|
|
17
|
-
set(token: string): Promise<void>;
|
|
18
|
-
status(): Promise<import("./types").LicenseStatus>;
|
|
19
|
-
stopRefresh(): Promise<void>;
|
|
20
|
-
};
|
|
21
13
|
init(cfg?: InitConfig): Promise<void>;
|
|
22
14
|
shutdown(): Promise<void>;
|
|
23
|
-
/** Register a new SIP account. Resolves with the account id. */
|
|
24
15
|
register(account: AccountConfig): Promise<number>;
|
|
25
16
|
unregister(accountId: number): Promise<void>;
|
|
26
|
-
/** Place an outbound call. Resolves with the new callId. */
|
|
27
17
|
makeCall(accountId: number, destinationUri: string): Promise<number>;
|
|
28
18
|
answer(callId: number): Promise<void>;
|
|
29
|
-
hangup(callId: number): Promise<void>;
|
|
19
|
+
hangup(callId: number, mode?: "busy" | "cancel" | "normal"): Promise<void>;
|
|
30
20
|
hold(callId: number): Promise<void>;
|
|
31
21
|
unhold(callId: number): Promise<void>;
|
|
32
|
-
/**
|
|
33
|
-
* Mute / unmute the local microphone for a call. Implemented by
|
|
34
|
-
* stopping / starting the capture device's transmission to the
|
|
35
|
-
* call's active audio media — independent of `hold`. A
|
|
36
|
-
* `callMediaState` event fires after the toggle so the UI can
|
|
37
|
-
* mirror the new `isMuted` flag without polling.
|
|
38
|
-
*/
|
|
39
22
|
mute(callId: number, on: boolean): Promise<void>;
|
|
40
23
|
sendDtmf(callId: number, digits: string): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Blind-transfer a call (SIP REFER) to a new destination. The
|
|
43
|
-
* local leg moves to DISCONNECTED once the remote party accepts.
|
|
44
|
-
*/
|
|
45
24
|
transferCall(callId: number, destinationUri: string): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* End every active call. Each call still emits its own
|
|
48
|
-
* `callState` event with state=DISCONNECTED.
|
|
49
|
-
*/
|
|
50
25
|
hangupAllCalls(): Promise<void>;
|
|
26
|
+
reconnectCallAudio(callId: number): Promise<void>;
|
|
51
27
|
on: typeof on;
|
|
52
28
|
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { EventMap, Subscription } from './types';
|
|
2
|
+
import { NATIVE_MODULE_NAME } from './nativeModule';
|
|
2
3
|
/**
|
|
3
|
-
* Subscribe to a typed event
|
|
4
|
-
* be called from a React `useEffect`
|
|
4
|
+
* Subscribe to a typed event from {@code @voipsdk/react-native-voipcloud}.
|
|
5
|
+
* Returns a handle whose `remove()` must be called from a React `useEffect`
|
|
6
|
+
* cleanup to avoid leaks.
|
|
5
7
|
*/
|
|
6
8
|
export declare function on<K extends keyof EventMap>(name: K, callback: (event: EventMap[K]) => void): Subscription;
|
|
9
|
+
/** Native module name registered with React Native (for debugging). */
|
|
10
|
+
export { NATIVE_MODULE_NAME };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { VoipCloud } from './VoipCloud';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export type { Transport, InitConfig, AccountConfig, LicenseStatus, RegistrationStateEvent, IncomingCallEvent, CallState, CallStateEvent, CallMediaStateEvent, CallHoldEvent, CallUnholdEvent, CallMuteEvent, CallDtmfSentEvent, CallTransferEvent, CallTransferStatusEvent, IncomingDtmfEvent, EventMap, Subscription, } from './types';
|
|
2
|
+
export { on as addEventListener, NATIVE_MODULE_NAME } from './events';
|
|
3
|
+
export type { Transport, InitConfig, AccountConfig, RegistrationStateEvent, IncomingCallEvent, CallState, CallStateEvent, CallMediaStateEvent, CallHoldEvent, CallUnholdEvent, CallMuteEvent, CallDtmfSentEvent, CallTransferEvent, CallTransferStatusEvent, IncomingDtmfEvent, EventMap, Subscription, } from './types';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native module name — must match {@code VoipCloudModule.getName()} on Android
|
|
3
|
+
* and the future iOS RCT export. Derived from npm package
|
|
4
|
+
* {@code @voipsdk/react-native-voipcloud}.
|
|
5
|
+
*/
|
|
6
|
+
export declare const NATIVE_MODULE_NAME = "VoipsdkReactNativeVoipcloud";
|
|
7
|
+
export declare const NativeVoipCloud: any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Public types for react-native-voipcloud.
|
|
2
|
+
* Public types for @voipsdk/react-native-voipcloud.
|
|
3
3
|
* Keep these stable across versions — they form the API contract.
|
|
4
4
|
*/
|
|
5
5
|
export type Transport = 'UDP' | 'TCP' | 'TLS';
|
|
@@ -32,22 +32,6 @@ export interface AccountConfig {
|
|
|
32
32
|
*/
|
|
33
33
|
transport: Transport;
|
|
34
34
|
}
|
|
35
|
-
export interface LicenseStatus {
|
|
36
|
-
/** True if voipcloud_license_is_valid() returned 1 at call time. */
|
|
37
|
-
valid: boolean;
|
|
38
|
-
/** Server-side label: "active" | "trial" | "suspended" | "expired" | "unset". */
|
|
39
|
-
status: string;
|
|
40
|
-
/** Customer identifier embedded in the token. */
|
|
41
|
-
customerId: string;
|
|
42
|
-
/** Concurrent-call ceiling allowed by the license. */
|
|
43
|
-
ccu: number;
|
|
44
|
-
/** Current count of active calls held by the gate. */
|
|
45
|
-
currentCalls: number;
|
|
46
|
-
/** Token expiry (unix seconds). 0 if unbounded. */
|
|
47
|
-
expiry: number;
|
|
48
|
-
/** Last clock-skew anchor pushed by the refresher (unix seconds). 0 if none yet. */
|
|
49
|
-
serverTime: number;
|
|
50
|
-
}
|
|
51
35
|
export interface RegistrationStateEvent {
|
|
52
36
|
accountId: number;
|
|
53
37
|
/** SIP response code (200 = registered, 401/407 = auth, etc.). */
|
|
@@ -62,6 +46,8 @@ export interface IncomingCallEvent {
|
|
|
62
46
|
from: string;
|
|
63
47
|
/** Local AOR. */
|
|
64
48
|
to: string;
|
|
49
|
+
/** SIP Call-ID header of the dialog (stable across systems). */
|
|
50
|
+
sipCallId?: string;
|
|
65
51
|
}
|
|
66
52
|
export type CallState = 'NULL' | 'CALLING' | 'INCOMING' | 'EARLY' | 'CONNECTING' | 'CONFIRMED' | 'DISCONNECTED';
|
|
67
53
|
export interface CallStateEvent {
|
|
@@ -69,6 +55,8 @@ export interface CallStateEvent {
|
|
|
69
55
|
state: CallState;
|
|
70
56
|
code: number;
|
|
71
57
|
reason: string;
|
|
58
|
+
/** SIP Call-ID header of the dialog (stable across systems). */
|
|
59
|
+
sipCallId?: string;
|
|
72
60
|
}
|
|
73
61
|
export interface CallMediaStateEvent {
|
|
74
62
|
callId: number;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voipsdk/react-native-voipcloud",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "React Native VoIP SDK backed by PJSIP
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Public React Native VoIP SDK backed by PJSIP (VoipCloud).",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
7
7
|
"react-native": "src/index.ts",
|
|
@@ -14,11 +14,12 @@
|
|
|
14
14
|
"ios",
|
|
15
15
|
"react-native-voipcloud.podspec",
|
|
16
16
|
"README.md",
|
|
17
|
+
"CHANGELOG.md",
|
|
17
18
|
"!**/__tests__",
|
|
18
19
|
"!**/.*"
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
|
21
|
-
"prepare": "bob build &&
|
|
22
|
+
"prepare": "bob build && tsc --project tsconfig.build.json --outDir lib/typescript --emitDeclarationOnly --declaration",
|
|
22
23
|
"build:types": "tsc --project tsconfig.build.json --outDir lib/typescript --emitDeclarationOnly --declaration",
|
|
23
24
|
"clean": "rm -rf lib",
|
|
24
25
|
"pack:tgz": "yarn pack --out ./%s-%v.tgz"
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
"license": "UNLICENSED",
|
|
43
44
|
"repository": {
|
|
44
45
|
"type": "git",
|
|
45
|
-
"url": "https://github.com/hoangdx/react-native-voipcloud.git"
|
|
46
|
+
"url": "git+https://github.com/hoangdx/react-native-voipcloud.git"
|
|
46
47
|
},
|
|
47
48
|
"bugs": {
|
|
48
49
|
"url": "https://github.com/hoangdx/react-native-voipcloud/issues"
|
|
@@ -72,5 +73,6 @@
|
|
|
72
73
|
},
|
|
73
74
|
"publishConfig": {
|
|
74
75
|
"access": "public"
|
|
75
|
-
}
|
|
76
|
+
},
|
|
77
|
+
"packageManager": "yarn@4.17.0+sha512.c2957de2f9025ab14d63b24d0d8be1f1655810e22c341042c27f7ecd017b180ec12db73d69ac366d71b304ef9f069349ce462de96f04f8f1da317f4f762c95ae"
|
|
76
78
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
require "json"
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
npm_name = package["name"]
|
|
5
|
+
pod_name = npm_name.include?("/") ? npm_name.split("/").last : npm_name
|
|
4
6
|
|
|
5
7
|
Pod::Spec.new do |s|
|
|
6
|
-
s.name =
|
|
8
|
+
s.name = pod_name
|
|
7
9
|
s.version = package["version"]
|
|
8
10
|
s.summary = package["description"]
|
|
9
|
-
s.homepage = "
|
|
10
|
-
s.license = "
|
|
11
|
-
s.authors = { "
|
|
11
|
+
s.homepage = package["homepage"]
|
|
12
|
+
s.license = package["license"]
|
|
13
|
+
s.authors = { package["author"]["name"] => package["author"]["email"] }
|
|
12
14
|
s.platforms = { :ios => "13.0" }
|
|
13
|
-
s.source = { :git => "
|
|
15
|
+
s.source = { :git => package["repository"]["url"] + ".git", :tag => "v#{s.version}" }
|
|
14
16
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
15
17
|
s.dependency "React-Core"
|
|
16
18
|
end
|
package/src/VoipCloud.ts
CHANGED
|
@@ -1,98 +1,91 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native';
|
|
2
1
|
import type { AccountConfig, InitConfig } from './types';
|
|
3
|
-
import {
|
|
2
|
+
import { NativeVoipCloud } from './nativeModule';
|
|
4
3
|
import { on } from './events';
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
/** Thrown as Promise rejection — never crashes at import time. */
|
|
6
|
+
function rejectNotLinked(): Promise<never> {
|
|
7
|
+
return Promise.reject(
|
|
8
|
+
Object.assign(
|
|
9
|
+
new Error(
|
|
10
|
+
'@voipsdk/react-native-voipcloud native module is not linked. ' +
|
|
11
|
+
'Install the package, rebuild the Android app ' +
|
|
12
|
+
'(./gradlew clean assembleDebug), and ensure voipcloud-release.aar is packaged.',
|
|
13
|
+
),
|
|
14
|
+
{ code: 'VC_NOT_LINKED' },
|
|
15
|
+
),
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function callNative<T>(fn: () => Promise<T>): Promise<T> {
|
|
20
|
+
if (!NativeVoipCloud) return rejectNotLinked();
|
|
21
|
+
return fn();
|
|
22
|
+
}
|
|
7
23
|
|
|
8
24
|
/**
|
|
9
|
-
* Top-level VoIP SDK. Workflow:
|
|
25
|
+
* Top-level VoIP SDK for {@code @voipsdk/react-native-voipcloud}. Workflow:
|
|
10
26
|
*
|
|
11
|
-
* 1. {@link
|
|
12
|
-
* 2. {@link
|
|
13
|
-
* 3. {@link
|
|
14
|
-
* 4. {@link makeCall} / {@link answer} / {@link hangup}.
|
|
27
|
+
* 1. {@link init} — start the PJSIP endpoint.
|
|
28
|
+
* 2. {@link register} — get an `accountId` back.
|
|
29
|
+
* 3. {@link makeCall} / {@link answer} / {@link hangup}.
|
|
15
30
|
*
|
|
16
|
-
* Every method returns a Promise.
|
|
17
|
-
* Promise rejection with `code = "VC_<NAME>"` matching the
|
|
18
|
-
* `PJ_EVOIPCLOUD_*` enum from `voipcloud_errno.h`.
|
|
31
|
+
* Every method returns a Promise. Failures reject with a `VC_*` code.
|
|
19
32
|
*/
|
|
20
33
|
export const VoipCloud = {
|
|
21
|
-
// ---------------------- License ---------------------------------
|
|
22
|
-
License,
|
|
23
|
-
|
|
24
|
-
// ---------------------- Lifecycle -------------------------------
|
|
25
34
|
init(cfg: InitConfig = {}): Promise<void> {
|
|
26
|
-
return
|
|
35
|
+
return callNative(() => NativeVoipCloud.init(cfg ?? {}));
|
|
27
36
|
},
|
|
28
37
|
|
|
29
38
|
shutdown(): Promise<void> {
|
|
30
|
-
return
|
|
39
|
+
return callNative(() => NativeVoipCloud.shutdown());
|
|
31
40
|
},
|
|
32
41
|
|
|
33
|
-
// ---------------------- Accounts --------------------------------
|
|
34
|
-
/** Register a new SIP account. Resolves with the account id. */
|
|
35
42
|
register(account: AccountConfig): Promise<number> {
|
|
36
|
-
return
|
|
43
|
+
return callNative(() => NativeVoipCloud.register(account));
|
|
37
44
|
},
|
|
38
45
|
|
|
39
46
|
unregister(accountId: number): Promise<void> {
|
|
40
|
-
return
|
|
47
|
+
return callNative(() => NativeVoipCloud.unregister(accountId));
|
|
41
48
|
},
|
|
42
49
|
|
|
43
|
-
// ---------------------- Calls -----------------------------------
|
|
44
|
-
/** Place an outbound call. Resolves with the new callId. */
|
|
45
50
|
makeCall(accountId: number, destinationUri: string): Promise<number> {
|
|
46
|
-
return
|
|
51
|
+
return callNative(() => NativeVoipCloud.makeCall(accountId, destinationUri));
|
|
47
52
|
},
|
|
48
53
|
|
|
49
54
|
answer(callId: number): Promise<void> {
|
|
50
|
-
return
|
|
55
|
+
return callNative(() => NativeVoipCloud.answer(callId));
|
|
51
56
|
},
|
|
52
57
|
|
|
53
|
-
hangup(callId: number): Promise<void> {
|
|
54
|
-
return
|
|
58
|
+
hangup(callId: number, mode: 'busy' | 'cancel' | 'normal' = 'normal'): Promise<void> {
|
|
59
|
+
return callNative(() => NativeVoipCloud.hangup(callId, mode));
|
|
55
60
|
},
|
|
56
61
|
|
|
57
62
|
hold(callId: number): Promise<void> {
|
|
58
|
-
return
|
|
63
|
+
return callNative(() => NativeVoipCloud.hold(callId));
|
|
59
64
|
},
|
|
60
65
|
|
|
61
66
|
unhold(callId: number): Promise<void> {
|
|
62
|
-
return
|
|
67
|
+
return callNative(() => NativeVoipCloud.unhold(callId));
|
|
63
68
|
},
|
|
64
69
|
|
|
65
|
-
/**
|
|
66
|
-
* Mute / unmute the local microphone for a call. Implemented by
|
|
67
|
-
* stopping / starting the capture device's transmission to the
|
|
68
|
-
* call's active audio media — independent of `hold`. A
|
|
69
|
-
* `callMediaState` event fires after the toggle so the UI can
|
|
70
|
-
* mirror the new `isMuted` flag without polling.
|
|
71
|
-
*/
|
|
72
70
|
mute(callId: number, on: boolean): Promise<void> {
|
|
73
|
-
return
|
|
71
|
+
return callNative(() => NativeVoipCloud.mute(callId, on));
|
|
74
72
|
},
|
|
75
73
|
|
|
76
74
|
sendDtmf(callId: number, digits: string): Promise<void> {
|
|
77
|
-
return
|
|
75
|
+
return callNative(() => NativeVoipCloud.sendDtmf(callId, digits));
|
|
78
76
|
},
|
|
79
77
|
|
|
80
|
-
/**
|
|
81
|
-
* Blind-transfer a call (SIP REFER) to a new destination. The
|
|
82
|
-
* local leg moves to DISCONNECTED once the remote party accepts.
|
|
83
|
-
*/
|
|
84
78
|
transferCall(callId: number, destinationUri: string): Promise<void> {
|
|
85
|
-
return
|
|
79
|
+
return callNative(() => NativeVoipCloud.transferCall(callId, destinationUri));
|
|
86
80
|
},
|
|
87
81
|
|
|
88
|
-
/**
|
|
89
|
-
* End every active call. Each call still emits its own
|
|
90
|
-
* `callState` event with state=DISCONNECTED.
|
|
91
|
-
*/
|
|
92
82
|
hangupAllCalls(): Promise<void> {
|
|
93
|
-
return
|
|
83
|
+
return callNative(() => NativeVoipCloud.hangupAllCalls());
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
reconnectCallAudio(callId: number): Promise<void> {
|
|
87
|
+
return callNative(() => NativeVoipCloud.reconnectCallAudio(callId));
|
|
94
88
|
},
|
|
95
89
|
|
|
96
|
-
// ---------------------- Events ----------------------------------
|
|
97
90
|
on,
|
|
98
91
|
};
|
package/src/events.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { NativeEventEmitter
|
|
1
|
+
import { NativeEventEmitter } from 'react-native';
|
|
2
2
|
import type { EventMap, Subscription } from './types';
|
|
3
|
+
import { NATIVE_MODULE_NAME, NativeVoipCloud } from './nativeModule';
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
// Lazy emitter — must point at the module to satisfy the contract
|
|
7
|
-
// NativeEventEmitter expects on RN 0.65+.
|
|
8
|
-
const emitter = Native ? new NativeEventEmitter(Native) : null;
|
|
5
|
+
const emitter = NativeVoipCloud ? new NativeEventEmitter(NativeVoipCloud) : null;
|
|
9
6
|
|
|
10
7
|
/**
|
|
11
|
-
* Subscribe to a typed event
|
|
12
|
-
* be called from a React `useEffect`
|
|
8
|
+
* Subscribe to a typed event from {@code @voipsdk/react-native-voipcloud}.
|
|
9
|
+
* Returns a handle whose `remove()` must be called from a React `useEffect`
|
|
10
|
+
* cleanup to avoid leaks.
|
|
13
11
|
*/
|
|
14
12
|
export function on<K extends keyof EventMap>(
|
|
15
13
|
name: K,
|
|
@@ -21,3 +19,6 @@ export function on<K extends keyof EventMap>(
|
|
|
21
19
|
const sub = emitter.addListener(name, callback as (e: unknown) => void);
|
|
22
20
|
return { remove: () => sub.remove() };
|
|
23
21
|
}
|
|
22
|
+
|
|
23
|
+
/** Native module name registered with React Native (for debugging). */
|
|
24
|
+
export { NATIVE_MODULE_NAME };
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export { VoipCloud } from './VoipCloud';
|
|
2
|
-
export {
|
|
3
|
-
export { on as addEventListener } from './events';
|
|
2
|
+
export { on as addEventListener, NATIVE_MODULE_NAME } from './events';
|
|
4
3
|
export type {
|
|
5
4
|
Transport,
|
|
6
5
|
InitConfig,
|
|
7
6
|
AccountConfig,
|
|
8
|
-
LicenseStatus,
|
|
9
7
|
RegistrationStateEvent,
|
|
10
8
|
IncomingCallEvent,
|
|
11
9
|
CallState,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Native module name — must match {@code VoipCloudModule.getName()} on Android
|
|
5
|
+
* and the future iOS RCT export. Derived from npm package
|
|
6
|
+
* {@code @voipsdk/react-native-voipcloud}.
|
|
7
|
+
*/
|
|
8
|
+
export const NATIVE_MODULE_NAME = 'VoipsdkReactNativeVoipcloud';
|
|
9
|
+
|
|
10
|
+
export const NativeVoipCloud = NativeModules[NATIVE_MODULE_NAME];
|
|
11
|
+
|
|
12
|
+
if (!NativeVoipCloud) {
|
|
13
|
+
console.warn(
|
|
14
|
+
'[@voipsdk/react-native-voipcloud] Native module not linked. ' +
|
|
15
|
+
'Methods will reject with VC_NOT_LINKED until the app is rebuilt.',
|
|
16
|
+
);
|
|
17
|
+
}
|