@cometchat/calls-sdk-react-native 5.0.2 → 5.0.3
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.
|
@@ -25,6 +25,7 @@ import android.os.Build;
|
|
|
25
25
|
import com.cometchat.calls.utils.CometChatLogger;
|
|
26
26
|
|
|
27
27
|
import java.util.HashSet;
|
|
28
|
+
import java.util.List;
|
|
28
29
|
import java.util.Set;
|
|
29
30
|
|
|
30
31
|
|
|
@@ -81,6 +82,8 @@ import java.util.Set;
|
|
|
81
82
|
for (AudioDeviceInfo info: deviceInfos) {
|
|
82
83
|
switch (info.getType()) {
|
|
83
84
|
case AudioDeviceInfo.TYPE_BLUETOOTH_SCO:
|
|
85
|
+
case AudioDeviceInfo.TYPE_BLE_HEADSET:
|
|
86
|
+
case AudioDeviceInfo.TYPE_BLE_SPEAKER:
|
|
84
87
|
devices.add(AudioModeModule.DEVICE_BLUETOOTH);
|
|
85
88
|
break;
|
|
86
89
|
case AudioDeviceInfo.TYPE_BUILTIN_EARPIECE:
|
|
@@ -170,6 +173,58 @@ import java.util.Set;
|
|
|
170
173
|
});
|
|
171
174
|
}
|
|
172
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Returns the {@link AudioDeviceInfo} types that can satisfy the given
|
|
178
|
+
* "DEVICE_" constant, in order of preference.
|
|
179
|
+
*/
|
|
180
|
+
private static int[] communicationDeviceTypes(String device) {
|
|
181
|
+
switch (device) {
|
|
182
|
+
case AudioModeModule.DEVICE_SPEAKER:
|
|
183
|
+
return new int[] { AudioDeviceInfo.TYPE_BUILTIN_SPEAKER };
|
|
184
|
+
case AudioModeModule.DEVICE_EARPIECE:
|
|
185
|
+
return new int[] { AudioDeviceInfo.TYPE_BUILTIN_EARPIECE };
|
|
186
|
+
case AudioModeModule.DEVICE_BLUETOOTH:
|
|
187
|
+
return new int[] {
|
|
188
|
+
AudioDeviceInfo.TYPE_BLUETOOTH_SCO,
|
|
189
|
+
AudioDeviceInfo.TYPE_BLE_HEADSET,
|
|
190
|
+
AudioDeviceInfo.TYPE_BLE_SPEAKER
|
|
191
|
+
};
|
|
192
|
+
case AudioModeModule.DEVICE_HEADPHONES:
|
|
193
|
+
return new int[] {
|
|
194
|
+
AudioDeviceInfo.TYPE_WIRED_HEADSET,
|
|
195
|
+
AudioDeviceInfo.TYPE_WIRED_HEADPHONES,
|
|
196
|
+
TYPE_USB_HEADSET,
|
|
197
|
+
TYPE_HEARING_AID
|
|
198
|
+
};
|
|
199
|
+
default:
|
|
200
|
+
return new int[0];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Sets the audio route using the modern (API 31+) communication device
|
|
206
|
+
* API. Unlike the deprecated setSpeakerphoneOn() / startBluetoothSco()
|
|
207
|
+
* calls, a setCommunicationDevice() request participates in the system's
|
|
208
|
+
* per-client route arbitration and takes precedence over stale requests
|
|
209
|
+
* left behind by other libraries in the same app.
|
|
210
|
+
*/
|
|
211
|
+
private void setCommunicationRoute(String device) {
|
|
212
|
+
List<AudioDeviceInfo> availableDevices = audioManager.getAvailableCommunicationDevices();
|
|
213
|
+
|
|
214
|
+
for (int type : communicationDeviceTypes(device)) {
|
|
215
|
+
for (AudioDeviceInfo info : availableDevices) {
|
|
216
|
+
if (info.getType() == type) {
|
|
217
|
+
if (audioManager.setCommunicationDevice(info)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
CometChatLogger.w(TAG, "setCommunicationDevice failed for type: " + type);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
CometChatLogger.w(TAG, "No available communication device for: " + device);
|
|
226
|
+
}
|
|
227
|
+
|
|
173
228
|
/**
|
|
174
229
|
* Helper method to set the output route to a Bluetooth device.
|
|
175
230
|
*
|
|
@@ -205,6 +260,11 @@ import java.util.Set;
|
|
|
205
260
|
|
|
206
261
|
@Override
|
|
207
262
|
public void setAudioRoute(String device) {
|
|
263
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
264
|
+
setCommunicationRoute(device);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
|
|
208
268
|
// Turn speaker on / off
|
|
209
269
|
audioManager.setSpeakerphoneOn(device.equals(AudioModeModule.DEVICE_SPEAKER));
|
|
210
270
|
|
|
@@ -218,8 +278,12 @@ import java.util.Set;
|
|
|
218
278
|
audioFocusLost = false;
|
|
219
279
|
audioManager.setMode(AudioManager.MODE_NORMAL);
|
|
220
280
|
audioManager.abandonAudioFocus(this);
|
|
221
|
-
|
|
222
|
-
|
|
281
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
282
|
+
audioManager.clearCommunicationDevice();
|
|
283
|
+
} else {
|
|
284
|
+
audioManager.setSpeakerphoneOn(false);
|
|
285
|
+
setBluetoothAudioRoute(false);
|
|
286
|
+
}
|
|
223
287
|
|
|
224
288
|
return true;
|
|
225
289
|
}
|
|
@@ -251,4 +315,4 @@ import java.util.Set;
|
|
|
251
315
|
|
|
252
316
|
return true;
|
|
253
317
|
}
|
|
254
|
-
}
|
|
318
|
+
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1775,9 +1775,42 @@ declare const CallAppSettingsSchema: v.ObjectSchema<{
|
|
|
1775
1775
|
readonly adminHost: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1776
1776
|
readonly clientHost: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1777
1777
|
readonly host: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1778
|
+
/**
|
|
1779
|
+
* Caller opt-out for SDK-identification telemetry. When `true`, the Calls SDK never
|
|
1780
|
+
* self-reports to `/user_sessions` (checked at the send chokepoint, so it covers both
|
|
1781
|
+
* the init session-restore path and every login-success path). Defaults to sending.
|
|
1782
|
+
*/
|
|
1783
|
+
readonly disableSdkIdentification: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
1778
1784
|
}, undefined>;
|
|
1779
1785
|
type CallAppSettings = v.InferOutput<typeof CallAppSettingsSchema>;
|
|
1780
1786
|
//#endregion
|
|
1787
|
+
//#region src/settings.d.ts
|
|
1788
|
+
interface CometChatSettings {
|
|
1789
|
+
appId: string;
|
|
1790
|
+
region: string;
|
|
1791
|
+
credentials?: {
|
|
1792
|
+
authKey?: string;
|
|
1793
|
+
};
|
|
1794
|
+
callsSDK?: {
|
|
1795
|
+
adminHost?: string | null;
|
|
1796
|
+
clientHost?: string | null;
|
|
1797
|
+
host?: string | null;
|
|
1798
|
+
disableSdkIdentification?: boolean | null;
|
|
1799
|
+
};
|
|
1800
|
+
chatSDK?: Record<string, unknown>;
|
|
1801
|
+
uiKit?: Record<string, unknown>;
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* Maps a `cometchat-settings.json` object onto the Calls SDK's own `CallAppSettings`
|
|
1805
|
+
* shape. Kept parallel to how the Chat SDK's `initFromSettings` maps the same file onto
|
|
1806
|
+
* its internal `AppSettings`: `appId`/`region` at the root, `authKey` under
|
|
1807
|
+
* `credentials`, and host overrides under the SDK-specific (`callsSDK`) section.
|
|
1808
|
+
*
|
|
1809
|
+
* The result is passed to the same valibot schema `init` uses, so validation stays
|
|
1810
|
+
* identical across both entry points.
|
|
1811
|
+
*/
|
|
1812
|
+
declare function callAppSettingsFromSettings(settings: CometChatSettings): CallAppSettings;
|
|
1813
|
+
//#endregion
|
|
1781
1814
|
//#region src/native-communication/native-to-js.native.d.ts
|
|
1782
1815
|
declare function setupNativeEventListeners(): void;
|
|
1783
1816
|
//#endregion
|
|
@@ -4386,6 +4419,34 @@ declare class CometChatCalls extends SessionMethodsCore {
|
|
|
4386
4419
|
readonly success: true;
|
|
4387
4420
|
readonly error: null;
|
|
4388
4421
|
}>;
|
|
4422
|
+
/**
|
|
4423
|
+
* Shared tail of {@link init} / {@link initFromSettings}. Both entry points validate
|
|
4424
|
+
* and map their own inputs, then hand the validated {@link CallAppSettings} here so
|
|
4425
|
+
* the post-validation work — persisting the telemetry integration source (BEFORE any
|
|
4426
|
+
* report) and firing SDK-identification once on a restored session — lives in exactly
|
|
4427
|
+
* one place and cannot drift between the two paths. The ONLY per-entry-point
|
|
4428
|
+
* difference is `integrationSource`.
|
|
4429
|
+
*/
|
|
4430
|
+
private static finalizeInit;
|
|
4431
|
+
/**
|
|
4432
|
+
* Initializes the CometChat Calls SDK from a `cometchat-settings.json` object.
|
|
4433
|
+
* Parallels the Chat SDK's `initFromSettings` (file-based init for skills-driven
|
|
4434
|
+
* integrations): it maps the shared settings shape onto the Calls SDK's own
|
|
4435
|
+
* `CallAppSettings` and then performs exactly the same work as {@link init}.
|
|
4436
|
+
* @param settings - Parsed `cometchat-settings.json` object.
|
|
4437
|
+
* @returns An object indicating success or failure with error details.
|
|
4438
|
+
*/
|
|
4439
|
+
static initFromSettings(settings: CometChatSettings): Promise<{
|
|
4440
|
+
readonly success: false;
|
|
4441
|
+
readonly error: {
|
|
4442
|
+
readonly name: "VALIDATION_ERROR";
|
|
4443
|
+
readonly message: `Invalid app settings: ${string}`;
|
|
4444
|
+
readonly timestamp: number;
|
|
4445
|
+
};
|
|
4446
|
+
} | {
|
|
4447
|
+
readonly success: true;
|
|
4448
|
+
readonly error: null;
|
|
4449
|
+
}>;
|
|
4389
4450
|
/**
|
|
4390
4451
|
* Logs in a user with their UID and an optional auth key.
|
|
4391
4452
|
* If no auth key is provided, the one from app settings is used.
|
|
@@ -4446,11 +4507,17 @@ declare class CometChatCalls extends SessionMethodsCore {
|
|
|
4446
4507
|
token: string;
|
|
4447
4508
|
}>;
|
|
4448
4509
|
private static getBaseURL;
|
|
4510
|
+
/**
|
|
4511
|
+
* SDK-identification telemetry chokepoint. Fire-and-forget, deduped, non-fatal.
|
|
4512
|
+
* Called from login success AND init()-session-restore. Sends `/user_sessions`
|
|
4513
|
+
* ONLY when the Chat SDK is absent (it otherwise handles this telemetry itself).
|
|
4514
|
+
* Never awaited on the happy path; never throws.
|
|
4515
|
+
*/
|
|
4516
|
+
private static reportSdkIdentification;
|
|
4449
4517
|
private static loginWithUID;
|
|
4450
4518
|
private static authenticateWithToken;
|
|
4451
4519
|
private static logoutInternal;
|
|
4452
4520
|
private static callGenerateTokenAPI;
|
|
4453
|
-
private static callVerifyTokenAPI;
|
|
4454
4521
|
private static getStorageKey;
|
|
4455
4522
|
private static saveUser;
|
|
4456
4523
|
private static getSavedUser;
|
package/dist/index.d.ts
CHANGED
|
@@ -1775,9 +1775,42 @@ declare const CallAppSettingsSchema: v.ObjectSchema<{
|
|
|
1775
1775
|
readonly adminHost: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1776
1776
|
readonly clientHost: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1777
1777
|
readonly host: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1778
|
+
/**
|
|
1779
|
+
* Caller opt-out for SDK-identification telemetry. When `true`, the Calls SDK never
|
|
1780
|
+
* self-reports to `/user_sessions` (checked at the send chokepoint, so it covers both
|
|
1781
|
+
* the init session-restore path and every login-success path). Defaults to sending.
|
|
1782
|
+
*/
|
|
1783
|
+
readonly disableSdkIdentification: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
1778
1784
|
}, undefined>;
|
|
1779
1785
|
type CallAppSettings = v.InferOutput<typeof CallAppSettingsSchema>;
|
|
1780
1786
|
//#endregion
|
|
1787
|
+
//#region src/settings.d.ts
|
|
1788
|
+
interface CometChatSettings {
|
|
1789
|
+
appId: string;
|
|
1790
|
+
region: string;
|
|
1791
|
+
credentials?: {
|
|
1792
|
+
authKey?: string;
|
|
1793
|
+
};
|
|
1794
|
+
callsSDK?: {
|
|
1795
|
+
adminHost?: string | null;
|
|
1796
|
+
clientHost?: string | null;
|
|
1797
|
+
host?: string | null;
|
|
1798
|
+
disableSdkIdentification?: boolean | null;
|
|
1799
|
+
};
|
|
1800
|
+
chatSDK?: Record<string, unknown>;
|
|
1801
|
+
uiKit?: Record<string, unknown>;
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* Maps a `cometchat-settings.json` object onto the Calls SDK's own `CallAppSettings`
|
|
1805
|
+
* shape. Kept parallel to how the Chat SDK's `initFromSettings` maps the same file onto
|
|
1806
|
+
* its internal `AppSettings`: `appId`/`region` at the root, `authKey` under
|
|
1807
|
+
* `credentials`, and host overrides under the SDK-specific (`callsSDK`) section.
|
|
1808
|
+
*
|
|
1809
|
+
* The result is passed to the same valibot schema `init` uses, so validation stays
|
|
1810
|
+
* identical across both entry points.
|
|
1811
|
+
*/
|
|
1812
|
+
declare function callAppSettingsFromSettings(settings: CometChatSettings): CallAppSettings;
|
|
1813
|
+
//#endregion
|
|
1781
1814
|
//#region src/native-communication/native-to-js.native.d.ts
|
|
1782
1815
|
declare function setupNativeEventListeners(): void;
|
|
1783
1816
|
//#endregion
|
|
@@ -4386,6 +4419,34 @@ declare class CometChatCalls extends SessionMethodsCore {
|
|
|
4386
4419
|
readonly success: true;
|
|
4387
4420
|
readonly error: null;
|
|
4388
4421
|
}>;
|
|
4422
|
+
/**
|
|
4423
|
+
* Shared tail of {@link init} / {@link initFromSettings}. Both entry points validate
|
|
4424
|
+
* and map their own inputs, then hand the validated {@link CallAppSettings} here so
|
|
4425
|
+
* the post-validation work — persisting the telemetry integration source (BEFORE any
|
|
4426
|
+
* report) and firing SDK-identification once on a restored session — lives in exactly
|
|
4427
|
+
* one place and cannot drift between the two paths. The ONLY per-entry-point
|
|
4428
|
+
* difference is `integrationSource`.
|
|
4429
|
+
*/
|
|
4430
|
+
private static finalizeInit;
|
|
4431
|
+
/**
|
|
4432
|
+
* Initializes the CometChat Calls SDK from a `cometchat-settings.json` object.
|
|
4433
|
+
* Parallels the Chat SDK's `initFromSettings` (file-based init for skills-driven
|
|
4434
|
+
* integrations): it maps the shared settings shape onto the Calls SDK's own
|
|
4435
|
+
* `CallAppSettings` and then performs exactly the same work as {@link init}.
|
|
4436
|
+
* @param settings - Parsed `cometchat-settings.json` object.
|
|
4437
|
+
* @returns An object indicating success or failure with error details.
|
|
4438
|
+
*/
|
|
4439
|
+
static initFromSettings(settings: CometChatSettings): Promise<{
|
|
4440
|
+
readonly success: false;
|
|
4441
|
+
readonly error: {
|
|
4442
|
+
readonly name: "VALIDATION_ERROR";
|
|
4443
|
+
readonly message: `Invalid app settings: ${string}`;
|
|
4444
|
+
readonly timestamp: number;
|
|
4445
|
+
};
|
|
4446
|
+
} | {
|
|
4447
|
+
readonly success: true;
|
|
4448
|
+
readonly error: null;
|
|
4449
|
+
}>;
|
|
4389
4450
|
/**
|
|
4390
4451
|
* Logs in a user with their UID and an optional auth key.
|
|
4391
4452
|
* If no auth key is provided, the one from app settings is used.
|
|
@@ -4446,11 +4507,17 @@ declare class CometChatCalls extends SessionMethodsCore {
|
|
|
4446
4507
|
token: string;
|
|
4447
4508
|
}>;
|
|
4448
4509
|
private static getBaseURL;
|
|
4510
|
+
/**
|
|
4511
|
+
* SDK-identification telemetry chokepoint. Fire-and-forget, deduped, non-fatal.
|
|
4512
|
+
* Called from login success AND init()-session-restore. Sends `/user_sessions`
|
|
4513
|
+
* ONLY when the Chat SDK is absent (it otherwise handles this telemetry itself).
|
|
4514
|
+
* Never awaited on the happy path; never throws.
|
|
4515
|
+
*/
|
|
4516
|
+
private static reportSdkIdentification;
|
|
4449
4517
|
private static loginWithUID;
|
|
4450
4518
|
private static authenticateWithToken;
|
|
4451
4519
|
private static logoutInternal;
|
|
4452
4520
|
private static callGenerateTokenAPI;
|
|
4453
|
-
private static callVerifyTokenAPI;
|
|
4454
4521
|
private static getStorageKey;
|
|
4455
4522
|
private static saveUser;
|
|
4456
4523
|
private static getSavedUser;
|