@cometchat/calls-sdk-react-native 4.0.0-beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +27 -0
  2. package/android/build.gradle +20 -0
  3. package/android/src/main/AndroidManifest.xml +8 -0
  4. package/android/src/main/java/com/CometChatCalls/AudioDeviceHandlerGeneric.java +213 -0
  5. package/android/src/main/java/com/CometChatCalls/AudioDeviceHandlerLegacy.java +213 -0
  6. package/android/src/main/java/com/CometChatCalls/AudioModeModule.java +456 -0
  7. package/android/src/main/java/com/CometChatCalls/BluetoothHeadsetMonitor.java +174 -0
  8. package/android/src/main/java/com/CometChatCalls/CometChatCallsPackage.java +45 -0
  9. package/cometchat-calls-sdk-react-native.podspec +21 -0
  10. package/dist/CometChatErrorConstants.d.ts +124 -0
  11. package/dist/Constants.d.ts +720 -0
  12. package/dist/Helper copy.d.ts +1 -0
  13. package/dist/Helper.d.ts +7 -0
  14. package/dist/api/APIHandler.d.ts +6 -0
  15. package/dist/api/endpoints.d.ts +6 -0
  16. package/dist/api/helper.d.ts +63 -0
  17. package/dist/api/index.d.ts +2 -0
  18. package/dist/constants/CallConstants.d.ts +136 -0
  19. package/dist/constants/index.d.ts +1 -0
  20. package/dist/defaultCallsettings.d.ts +2 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.js +128 -0
  23. package/dist/models/CallAppSettings.d.ts +42 -0
  24. package/dist/models/CallSettings.d.ts +316 -0
  25. package/dist/models/CometChatCalls.d.ts +89 -0
  26. package/dist/models/CometChatCallsComponent.d.ts +13 -0
  27. package/dist/models/CometChatCallsComponentCore.d.ts +18 -0
  28. package/dist/models/CometChatCallsException.d.ts +7 -0
  29. package/dist/models/CometChatPresenterComponent.d.ts +13 -0
  30. package/dist/models/ErrorModel.d.ts +11 -0
  31. package/dist/models/Listner.d.ts +64 -0
  32. package/dist/models/ListnerHandler.d.ts +10 -0
  33. package/dist/models/MessageComponent.d.ts +7 -0
  34. package/dist/models/PresenterSettings.d.ts +194 -0
  35. package/dist/models/RTCUser.d.ts +18 -0
  36. package/dist/models/index.d.ts +7 -0
  37. package/dist/types/ICallAppSettings.d.ts +6 -0
  38. package/dist/types/ICallSettings.d.ts +60 -0
  39. package/dist/types/RTCUser.d.ts +6 -0
  40. package/dist/types/callEvents.d.ts +53 -0
  41. package/dist/types/common.d.ts +17 -0
  42. package/dist/types/index.d.ts +2 -0
  43. package/ios/AudioMode.h +11 -0
  44. package/ios/AudioMode.m +403 -0
  45. package/ios/JitsiAudioSession+Private.h +25 -0
  46. package/ios/JitsiAudioSession.h +17 -0
  47. package/ios/JitsiAudioSession.m +34 -0
  48. package/ios/LogUtils.h +23 -0
  49. package/ios/react-native-calls2.xcodeproj/project.pbxproj +269 -0
  50. package/package.json +122 -0
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ <div style="width:100%">
2
+ <div style="width:100%">
3
+ <div style="width:50%; display:inline-block">
4
+ <a href="https://www.cometchat.com/">
5
+ <p align="center">
6
+ <img style="text-align:center" width="180" height="180" alt="" src="https://avatars2.githubusercontent.com/u/45484907?s=200&v=4">
7
+ </p>
8
+ </a>
9
+ </div>
10
+ </div>
11
+ </br>
12
+ </br>
13
+ </div>
14
+
15
+ # CometChat React Native Calls SDK
16
+
17
+ CometChat Pro enables you to add voice, video & text chat for your website & app.
18
+
19
+ 📝 Please refer to our [Developer Documentation](https://www.cometchat.com/docs/home/welcome) for more information on how to configure the CometChat Pro SDK and implement various features using the same.
20
+
21
+ <hr/>
22
+
23
+ ## Contact :mailbox:
24
+
25
+ Contact us via real time support present in [CometChat Dashboard.](https://app.cometchat.io/)
26
+
27
+ <hr/>
@@ -0,0 +1,20 @@
1
+ apply plugin: 'com.android.library'
2
+
3
+ def safeExtGet(prop, fallback) {
4
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
5
+ }
6
+
7
+ android {
8
+ compileSdkVersion safeExtGet('compileSdkVersion', 28)
9
+
10
+ defaultConfig {
11
+ minSdkVersion safeExtGet('minSdkVersion', 16)
12
+ targetSdkVersion safeExtGet('targetSdkVersion', 28)
13
+ versionCode 1
14
+ versionName "1.0"
15
+ }
16
+ }
17
+
18
+ dependencies {
19
+ implementation 'com.facebook.react:react-native:+'
20
+ }
@@ -0,0 +1,8 @@
1
+
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.CometChatCalls">
3
+ <uses-permission android:name="android.permission.INTERNET" />
4
+ <uses-permission android:name="android.permission.CAMERA" />
5
+ <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
6
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
7
+ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
8
+ </manifest>
@@ -0,0 +1,213 @@
1
+ package com.CometChatCalls;
2
+ import android.annotation.TargetApi;
3
+ import android.media.AudioDeviceInfo;
4
+ import android.media.AudioManager;
5
+ import android.os.Build;
6
+ import android.util.Log;
7
+
8
+ import java.util.HashSet;
9
+ import java.util.Set;
10
+
11
+
12
+
13
+ /**
14
+ * {@link AudioModeModule.AudioDeviceHandlerInterface} module implementing device handling for
15
+ * all post-M Android versions. This handler can be used on any Android versions >= M, but by
16
+ * default it's only used on versions < O, since versions >= O use ConnectionService, but it
17
+ * can be disabled.
18
+ */
19
+ @TargetApi(Build.VERSION_CODES.M)
20
+ class AudioDeviceHandlerGeneric implements
21
+ AudioModeModule.AudioDeviceHandlerInterface,
22
+ AudioManager.OnAudioFocusChangeListener {
23
+
24
+ private final static String TAG = AudioDeviceHandlerGeneric.class.getSimpleName();
25
+
26
+ /**
27
+ * Reference to the main {@code AudioModeModule}.
28
+ */
29
+ private AudioModeModule module;
30
+
31
+ /**
32
+ * Constant defining a USB headset. Only available on API level >= 26.
33
+ * The value of: AudioDeviceInfo.TYPE_USB_HEADSET
34
+ */
35
+ private static final int TYPE_USB_HEADSET = 22;
36
+
37
+ /**
38
+ * Indicator that we have lost audio focus.
39
+ */
40
+ private boolean audioFocusLost = false;
41
+
42
+ /**
43
+ * {@link AudioManager} instance used to interact with the Android audio
44
+ * subsystem.
45
+ */
46
+ private AudioManager audioManager;
47
+
48
+ /**
49
+ * {@link Runnable} for running audio device detection the main thread.
50
+ * This is only used on Android >= M.
51
+ */
52
+ private final Runnable onAudioDeviceChangeRunner = new Runnable() {
53
+ @Override
54
+ public void run() {
55
+ Set<String> devices = new HashSet<>();
56
+ AudioDeviceInfo[] deviceInfos = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
57
+
58
+ for (AudioDeviceInfo info: deviceInfos) {
59
+ switch (info.getType()) {
60
+ case AudioDeviceInfo.TYPE_BLUETOOTH_SCO:
61
+ devices.add(AudioModeModule.DEVICE_BLUETOOTH);
62
+ break;
63
+ case AudioDeviceInfo.TYPE_BUILTIN_EARPIECE:
64
+ devices.add(AudioModeModule.DEVICE_EARPIECE);
65
+ break;
66
+ case AudioDeviceInfo.TYPE_BUILTIN_SPEAKER:
67
+ devices.add(AudioModeModule.DEVICE_SPEAKER);
68
+ break;
69
+ case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
70
+ case AudioDeviceInfo.TYPE_WIRED_HEADSET:
71
+ case TYPE_USB_HEADSET:
72
+ devices.add(AudioModeModule.DEVICE_HEADPHONES);
73
+ break;
74
+ }
75
+ }
76
+
77
+ module.replaceDevices(devices);
78
+
79
+ Log.i(TAG , " Available audio devices: " + devices.toString());
80
+
81
+ module.updateAudioRoute();
82
+ }
83
+ };
84
+
85
+ private final android.media.AudioDeviceCallback audioDeviceCallback =
86
+ new android.media.AudioDeviceCallback() {
87
+ @Override
88
+ public void onAudioDevicesAdded(
89
+ AudioDeviceInfo[] addedDevices) {
90
+ Log.d(TAG , " Audio devices added");
91
+ onAudioDeviceChange();
92
+ }
93
+
94
+ @Override
95
+ public void onAudioDevicesRemoved(
96
+ AudioDeviceInfo[] removedDevices) {
97
+ Log.d(TAG , " Audio devices removed");
98
+ onAudioDeviceChange();
99
+ }
100
+ };
101
+
102
+ public AudioDeviceHandlerGeneric(AudioManager audioManager) {
103
+ this.audioManager = audioManager;
104
+ }
105
+
106
+ /**
107
+ * Helper method to trigger an audio route update when devices change. It
108
+ * makes sure the operation is performed on the audio thread.
109
+ */
110
+ private void onAudioDeviceChange() {
111
+ module.runInAudioThread(onAudioDeviceChangeRunner);
112
+ }
113
+
114
+ /**
115
+ * {@link AudioManager.OnAudioFocusChangeListener} interface method. Called
116
+ * when the audio focus of the system is updated.
117
+ *
118
+ * @param focusChange - The type of focus change.
119
+ */
120
+ @Override
121
+ public void onAudioFocusChange(final int focusChange) {
122
+ module.runInAudioThread(new Runnable() {
123
+ @Override
124
+ public void run() {
125
+ switch (focusChange) {
126
+ case AudioManager.AUDIOFOCUS_GAIN: {
127
+ Log.d(TAG , " Audio focus gained");
128
+ // Some other application potentially stole our audio focus
129
+ // temporarily. Restore our mode.
130
+ if (audioFocusLost) {
131
+ module.updateAudioRoute();
132
+ }
133
+ audioFocusLost = false;
134
+ break;
135
+ }
136
+ case AudioManager.AUDIOFOCUS_LOSS:
137
+ case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
138
+ case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: {
139
+ Log.d(TAG , " Audio focus lost");
140
+ audioFocusLost = true;
141
+ break;
142
+ }
143
+ }
144
+ }
145
+ });
146
+ }
147
+
148
+ /**
149
+ * Helper method to set the output route to a Bluetooth device.
150
+ *
151
+ * @param enabled true if Bluetooth should use used, false otherwise.
152
+ */
153
+ private void setBluetoothAudioRoute(boolean enabled) {
154
+ if (enabled) {
155
+ audioManager.startBluetoothSco();
156
+ audioManager.setBluetoothScoOn(true);
157
+ } else {
158
+ audioManager.setBluetoothScoOn(false);
159
+ audioManager.stopBluetoothSco();
160
+ }
161
+ }
162
+
163
+ @Override
164
+ public void start(AudioModeModule audioModeModule) {
165
+ Log.i("Using " , TAG + " as the audio device handler");
166
+
167
+ module = audioModeModule;
168
+
169
+ // Setup runtime device change detection.
170
+ audioManager.registerAudioDeviceCallback(audioDeviceCallback, null);
171
+
172
+ // Do an initial detection.
173
+ onAudioDeviceChange();
174
+ }
175
+
176
+ @Override
177
+ public void stop() {
178
+ audioManager.unregisterAudioDeviceCallback(audioDeviceCallback);
179
+ }
180
+
181
+ @Override
182
+ public void setAudioRoute(String device) {
183
+ // Turn speaker on / off
184
+ audioManager.setSpeakerphoneOn(device.equals(AudioModeModule.DEVICE_SPEAKER));
185
+
186
+ // Turn bluetooth on / off
187
+ setBluetoothAudioRoute(device.equals(AudioModeModule.DEVICE_BLUETOOTH));
188
+ }
189
+
190
+ @Override
191
+ public boolean setMode(int mode) {
192
+ if (mode == AudioModeModule.DEFAULT) {
193
+ audioFocusLost = false;
194
+ audioManager.setMode(AudioManager.MODE_NORMAL);
195
+ audioManager.abandonAudioFocus(this);
196
+ audioManager.setSpeakerphoneOn(false);
197
+ setBluetoothAudioRoute(false);
198
+
199
+ return true;
200
+ }
201
+
202
+ audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
203
+ audioManager.setMicrophoneMute(false);
204
+
205
+ if (audioManager.requestAudioFocus(this, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN)
206
+ == AudioManager.AUDIOFOCUS_REQUEST_FAILED) {
207
+ Log.w(TAG , " Audio focus request failed");
208
+ return false;
209
+ }
210
+
211
+ return true;
212
+ }
213
+ }
@@ -0,0 +1,213 @@
1
+ package com.CometChatCalls;
2
+
3
+ import android.content.BroadcastReceiver;
4
+ import android.content.Context;
5
+ import android.content.Intent;
6
+ import android.content.IntentFilter;
7
+ import android.content.pm.PackageManager;
8
+ import android.media.AudioManager;
9
+ import android.util.Log;
10
+
11
+
12
+ /**
13
+ * {@link AudioModeModule.AudioDeviceHandlerInterface} module implementing device handling for
14
+ * legacy (pre-M) Android versions.
15
+ */
16
+ class AudioDeviceHandlerLegacy implements
17
+ AudioModeModule.AudioDeviceHandlerInterface,
18
+ AudioManager.OnAudioFocusChangeListener,
19
+ BluetoothHeadsetMonitor.Listener {
20
+
21
+ private final static String TAG = AudioDeviceHandlerLegacy.class.getSimpleName();
22
+
23
+ /**
24
+ * Reference to the main {@code AudioModeModule}.
25
+ */
26
+ private AudioModeModule module;
27
+
28
+ /**
29
+ * Indicator that we have lost audio focus.
30
+ */
31
+ private boolean audioFocusLost = false;
32
+
33
+ /**
34
+ * {@link AudioManager} instance used to interact with the Android audio
35
+ * subsystem.
36
+ */
37
+ private AudioManager audioManager;
38
+
39
+ /**
40
+ * {@link BluetoothHeadsetMonitor} for detecting Bluetooth device changes in
41
+ * old (< M) Android versions.
42
+ */
43
+ private BluetoothHeadsetMonitor bluetoothHeadsetMonitor;
44
+
45
+ public AudioDeviceHandlerLegacy(AudioManager audioManager) {
46
+ this.audioManager = audioManager;
47
+ }
48
+
49
+ /**
50
+ * Helper method to trigger an audio route update when Bluetooth devices are
51
+ * connected / disconnected.
52
+ */
53
+ @Override
54
+ public void onBluetoothDeviceChange(final boolean deviceAvailable) {
55
+ module.runInAudioThread(new Runnable() {
56
+ @Override
57
+ public void run() {
58
+ if (deviceAvailable) {
59
+ module.addDevice(AudioModeModule.DEVICE_BLUETOOTH);
60
+ } else {
61
+ module.removeDevice(AudioModeModule.DEVICE_BLUETOOTH);
62
+ }
63
+
64
+ module.updateAudioRoute();
65
+ }
66
+ });
67
+ }
68
+
69
+ /**
70
+ * Helper method to trigger an audio route update when a headset is plugged
71
+ * or unplugged.
72
+ */
73
+ private void onHeadsetDeviceChange() {
74
+ module.runInAudioThread(new Runnable() {
75
+ @Override
76
+ public void run() {
77
+ // XXX: isWiredHeadsetOn is not deprecated when used just for
78
+ // knowing if there is a wired headset connected, regardless of
79
+ // audio being routed to it.
80
+ //noinspection deprecation
81
+ if (audioManager.isWiredHeadsetOn()) {
82
+ module.addDevice(AudioModeModule.DEVICE_HEADPHONES);
83
+ } else {
84
+ module.removeDevice(AudioModeModule.DEVICE_HEADPHONES);
85
+ }
86
+
87
+ module.updateAudioRoute();
88
+ }
89
+ });
90
+ }
91
+
92
+ /**
93
+ * {@link AudioManager.OnAudioFocusChangeListener} interface method. Called
94
+ * when the audio focus of the system is updated.
95
+ *
96
+ * @param focusChange - The type of focus change.
97
+ */
98
+ @Override
99
+ public void onAudioFocusChange(final int focusChange) {
100
+ module.runInAudioThread(new Runnable() {
101
+ @Override
102
+ public void run() {
103
+ switch (focusChange) {
104
+ case AudioManager.AUDIOFOCUS_GAIN: {
105
+ Log.d(TAG , " Audio focus gained");
106
+ // Some other application potentially stole our audio focus
107
+ // temporarily. Restore our mode.
108
+ if (audioFocusLost) {
109
+ module.updateAudioRoute();
110
+ }
111
+ audioFocusLost = false;
112
+ break;
113
+ }
114
+ case AudioManager.AUDIOFOCUS_LOSS:
115
+ case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
116
+ case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: {
117
+ Log.d(TAG , " Audio focus lost");
118
+ audioFocusLost = true;
119
+ break;
120
+ }
121
+ }
122
+ }
123
+ });
124
+ }
125
+
126
+ /**
127
+ * Helper method to set the output route to a Bluetooth device.
128
+ *
129
+ * @param enabled true if Bluetooth should use used, false otherwise.
130
+ */
131
+ private void setBluetoothAudioRoute(boolean enabled) {
132
+ if (enabled) {
133
+ audioManager.startBluetoothSco();
134
+ audioManager.setBluetoothScoOn(true);
135
+ } else {
136
+ audioManager.setBluetoothScoOn(false);
137
+ audioManager.stopBluetoothSco();
138
+ }
139
+ }
140
+
141
+ @Override
142
+ public void start(AudioModeModule audioModeModule) {
143
+ Log.i( TAG , " as the audio device handler");
144
+
145
+ module = audioModeModule;
146
+ Context context = module.getContext();
147
+
148
+ // Setup runtime device change detection.
149
+ //
150
+
151
+ // Detect changes in wired headset connections.
152
+ IntentFilter wiredHeadSetFilter = new IntentFilter(AudioManager.ACTION_HEADSET_PLUG);
153
+ BroadcastReceiver wiredHeadsetReceiver = new BroadcastReceiver() {
154
+ @Override
155
+ public void onReceive(Context context, Intent intent) {
156
+ Log.d(TAG , " Wired headset added / removed");
157
+ onHeadsetDeviceChange();
158
+ }
159
+ };
160
+ context.registerReceiver(wiredHeadsetReceiver, wiredHeadSetFilter);
161
+
162
+ // Detect Bluetooth device changes.
163
+ bluetoothHeadsetMonitor = new BluetoothHeadsetMonitor(context, this);
164
+
165
+ // On Android < M, detect if we have an earpiece.
166
+ PackageManager pm = context.getPackageManager();
167
+ if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
168
+ module.addDevice(AudioModeModule.DEVICE_EARPIECE);
169
+ }
170
+
171
+ // Always assume there is a speaker.
172
+ module.addDevice(AudioModeModule.DEVICE_SPEAKER);
173
+ }
174
+
175
+ @Override
176
+ public void stop() {
177
+ bluetoothHeadsetMonitor.stop();
178
+ bluetoothHeadsetMonitor = null;
179
+ }
180
+
181
+ @Override
182
+ public void setAudioRoute(String device) {
183
+ // Turn speaker on / off
184
+ audioManager.setSpeakerphoneOn(device.equals(AudioModeModule.DEVICE_SPEAKER));
185
+
186
+ // Turn bluetooth on / off
187
+ setBluetoothAudioRoute(device.equals(AudioModeModule.DEVICE_BLUETOOTH));
188
+ }
189
+
190
+ @Override
191
+ public boolean setMode(int mode) {
192
+ if (mode == AudioModeModule.DEFAULT) {
193
+ audioFocusLost = false;
194
+ audioManager.setMode(AudioManager.MODE_NORMAL);
195
+ audioManager.abandonAudioFocus(this);
196
+ audioManager.setSpeakerphoneOn(false);
197
+ setBluetoothAudioRoute(false);
198
+
199
+ return true;
200
+ }
201
+
202
+ audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
203
+ audioManager.setMicrophoneMute(false);
204
+
205
+ if (audioManager.requestAudioFocus(this, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN)
206
+ == AudioManager.AUDIOFOCUS_REQUEST_FAILED) {
207
+ Log.w(TAG , " Audio focus request failed");
208
+ return false;
209
+ }
210
+
211
+ return true;
212
+ }
213
+ }