@cometchat/calls-sdk-react-native 4.4.2-beta.1 → 5.0.0-beta.2
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 +85 -19
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.9/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +13 -12
- package/android/src/main/AndroidManifest.xml +15 -6
- package/android/src/main/java/com/callingv5/AudioDeviceHandlerConnectionService.java +185 -0
- package/android/src/main/java/com/callingv5/AudioDeviceHandlerGeneric.java +254 -0
- package/android/src/main/java/com/{CometChatCalls → callingv5}/AudioModeModule.java +93 -56
- package/android/src/main/java/com/callingv5/ConnectionService.java +451 -0
- package/android/src/main/java/com/callingv5/KeepAwakeModule.java +53 -0
- package/android/src/main/java/com/callingv5/MyAppPackage.java +35 -0
- package/android/src/main/java/com/callingv5/RNConnectionService.java +244 -0
- package/android/src/main/java/com/callingv5/ToastModule.java +29 -0
- package/android/src/main/java/com/callingv5/utils/CometChatLogger.java +88 -0
- package/cometchat-calls-sdk-react-native.podspec +9 -10
- package/dist/index.d.mts +4066 -0
- package/dist/index.d.ts +4066 -9
- package/dist/index.js +11116 -132
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +11085 -0
- package/dist/index.mjs.map +1 -0
- package/dist/polyfills/RTCPeerConnection.js +19 -0
- package/dist/polyfills/Storage.js +192 -0
- package/dist/polyfills/browser.js +337 -0
- package/dist/polyfills/index.js +1 -0
- package/dist/polyfills/ipv6utils.js +197 -0
- package/dist/polyfills/webrtc.js +11 -0
- package/ios/{JitsiAudioSession+Private.h → Audio/CometChatAudioSession+Private.h} +2 -3
- package/ios/{LogUtils.h → Audio/CometChatAudioSession.h} +9 -6
- package/ios/{JitsiAudioSession.m → Audio/CometChatAudioSession.m} +4 -3
- package/ios/{AudioMode.m → Modules/AudioMode.m} +15 -49
- package/ios/Modules/KeepAwake.h +4 -0
- package/ios/Modules/KeepAwake.m +29 -0
- package/package.json +24 -110
- package/LICENSE.md +0 -3
- package/android/src/main/java/com/CometChatCalls/AudioDeviceHandlerGeneric.java +0 -213
- package/android/src/main/java/com/CometChatCalls/AudioDeviceHandlerLegacy.java +0 -213
- package/android/src/main/java/com/CometChatCalls/BluetoothHeadsetMonitor.java +0 -187
- package/android/src/main/java/com/CometChatCalls/CallNotificationService.java +0 -93
- package/android/src/main/java/com/CometChatCalls/CallNotificationServiceModule.java +0 -48
- package/android/src/main/java/com/CometChatCalls/CometChatCallsPackage.java +0 -56
- package/android/src/main/java/com/CometChatCalls/CometChatCommonModule.java +0 -48
- package/android/src/main/java/com/CometChatCalls/PictureInPictureModule.java +0 -133
- package/android/src/main/res/drawable-mdpi/callingcomponent_icons_headphones_pluged.png +0 -0
- package/dist/CometChatErrorConstants.d.ts +0 -124
- package/dist/Constants.d.ts +0 -724
- package/dist/Helper copy.d.ts +0 -1
- package/dist/Helper.d.ts +0 -7
- package/dist/api/APIHandler.d.ts +0 -42
- package/dist/api/endpoints.d.ts +0 -7
- package/dist/api/helper.d.ts +0 -69
- package/dist/api/index.d.ts +0 -2
- package/dist/constants/CallConstants.d.ts +0 -136
- package/dist/constants/index.d.ts +0 -1
- package/dist/defaultCallsettings.d.ts +0 -2
- package/dist/models/CallAppSettings.d.ts +0 -42
- package/dist/models/CallGroup.d.ts +0 -14
- package/dist/models/CallLog.d.ts +0 -276
- package/dist/models/CallLogFilterParams.d.ts +0 -97
- package/dist/models/CallSettings.d.ts +0 -330
- package/dist/models/CallUser.d.ts +0 -14
- package/dist/models/CometChatCallLogs.d.ts +0 -193
- package/dist/models/CometChatCalls.d.ts +0 -110
- package/dist/models/CometChatCallsComponent.d.ts +0 -13
- package/dist/models/CometChatCallsComponentCore.d.ts +0 -18
- package/dist/models/CometChatCallsException.d.ts +0 -7
- package/dist/models/CometChatPresenterComponent.d.ts +0 -13
- package/dist/models/ErrorModel.d.ts +0 -11
- package/dist/models/Listner.d.ts +0 -69
- package/dist/models/ListnerHandler.d.ts +0 -10
- package/dist/models/MessageComponent.d.ts +0 -7
- package/dist/models/Participant.d.ts +0 -184
- package/dist/models/PresenterSettings.d.ts +0 -208
- package/dist/models/RTCUser.d.ts +0 -18
- package/dist/models/Recording.d.ts +0 -86
- package/dist/models/index.d.ts +0 -9
- package/dist/types/ICallAppSettings.d.ts +0 -6
- package/dist/types/ICallSettings.d.ts +0 -61
- package/dist/types/RTCUser.d.ts +0 -6
- package/dist/types/callEvents.d.ts +0 -54
- package/dist/types/common.d.ts +0 -18
- package/dist/types/index.d.ts +0 -2
- package/ios/AudioMode.h +0 -11
- package/ios/CometChatCommonModule.h +0 -6
- package/ios/CometChatCommonModule.m +0 -29
- package/ios/JitsiAudioSession.h +0 -17
- package/ios/react-native-calls2.xcodeproj/project.pbxproj +0 -269
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
package com.cometchat.calls;
|
|
2
|
+
|
|
3
|
+
import android.content.ComponentName;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.net.Uri;
|
|
6
|
+
import android.os.Build;
|
|
7
|
+
import android.os.Bundle;
|
|
8
|
+
import android.telecom.CallAudioState;
|
|
9
|
+
import android.telecom.Connection;
|
|
10
|
+
import android.telecom.ConnectionRequest;
|
|
11
|
+
import android.telecom.DisconnectCause;
|
|
12
|
+
import android.telecom.PhoneAccount;
|
|
13
|
+
import android.telecom.PhoneAccountHandle;
|
|
14
|
+
import android.telecom.TelecomManager;
|
|
15
|
+
import android.telecom.VideoProfile;
|
|
16
|
+
|
|
17
|
+
import androidx.annotation.RequiresApi;
|
|
18
|
+
|
|
19
|
+
import com.cometchat.calls.utils.CometChatLogger;
|
|
20
|
+
import com.facebook.react.bridge.Promise;
|
|
21
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
22
|
+
import com.facebook.react.bridge.WritableNativeMap;
|
|
23
|
+
|
|
24
|
+
import java.util.ArrayList;
|
|
25
|
+
import java.util.HashMap;
|
|
26
|
+
import java.util.List;
|
|
27
|
+
import java.util.Map;
|
|
28
|
+
import java.util.Objects;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Jitsi Meet implementation of {@link ConnectionService}. At the time of this
|
|
32
|
+
* writing it implements only the outgoing call scenario.
|
|
33
|
+
*
|
|
34
|
+
* NOTE the class needs to be public, but is not part of the SDK API and should
|
|
35
|
+
* never be used directly.
|
|
36
|
+
*
|
|
37
|
+
* @author Pawel Domas
|
|
38
|
+
*/
|
|
39
|
+
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
40
|
+
public class ConnectionService extends android.telecom.ConnectionService {
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Tag used for logging.
|
|
44
|
+
*/
|
|
45
|
+
static final String TAG = "JitsiConnectionService";
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The extra added to the {@link ConnectionImpl} and
|
|
49
|
+
* {@link ConnectionRequest} which stores the {@link PhoneAccountHandle}
|
|
50
|
+
* created for the call.
|
|
51
|
+
*/
|
|
52
|
+
static final String EXTRA_PHONE_ACCOUNT_HANDLE
|
|
53
|
+
= "org.jitsi.meet.sdk.connection_service.PHONE_ACCOUNT_HANDLE";
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Connections mapped by call UUID.
|
|
57
|
+
*/
|
|
58
|
+
static private final Map<String, ConnectionImpl> connections
|
|
59
|
+
= new HashMap<>();
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The start call Promises mapped by call UUID.
|
|
63
|
+
*/
|
|
64
|
+
static private final HashMap<String, Promise> startCallPromises
|
|
65
|
+
= new HashMap<>();
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Aborts all ongoing connections. This is a last resort mechanism which forces all resources to
|
|
69
|
+
* be freed on the system in case of fatal error.
|
|
70
|
+
*/
|
|
71
|
+
static void abortConnections() {
|
|
72
|
+
for (ConnectionImpl connection: getConnections()) {
|
|
73
|
+
connection.onAbort();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Adds {@link ConnectionImpl} to the list.
|
|
79
|
+
*
|
|
80
|
+
* @param connection - {@link ConnectionImpl}
|
|
81
|
+
*/
|
|
82
|
+
static void addConnection(ConnectionImpl connection) {
|
|
83
|
+
connections.put(connection.getCallUUID(), connection);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Returns all {@link ConnectionImpl} instances held in this list.
|
|
88
|
+
*
|
|
89
|
+
* @return a list of {@link ConnectionImpl}.
|
|
90
|
+
*/
|
|
91
|
+
static List<ConnectionImpl> getConnections() {
|
|
92
|
+
return new ArrayList<>(connections.values());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @return {@code true} if running a Samsung device.
|
|
97
|
+
*/
|
|
98
|
+
static boolean isSamsungDevice() {
|
|
99
|
+
return Build.MANUFACTURER.toLowerCase().contains("samsung");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Registers a start call promise.
|
|
104
|
+
*
|
|
105
|
+
* @param uuid - the call UUID to which the start call promise belongs to.
|
|
106
|
+
* @param promise - the Promise instance to be stored for later use.
|
|
107
|
+
*/
|
|
108
|
+
static void registerStartCallPromise(String uuid, Promise promise) {
|
|
109
|
+
startCallPromises.put(uuid, promise);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Removes {@link ConnectionImpl} from the list.
|
|
114
|
+
*
|
|
115
|
+
* @param connection - {@link ConnectionImpl}
|
|
116
|
+
*/
|
|
117
|
+
static void removeConnection(ConnectionImpl connection) {
|
|
118
|
+
connections.remove(connection.getCallUUID());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Used to adjusts the connection's state to
|
|
123
|
+
* {@link Connection#STATE_ACTIVE}.
|
|
124
|
+
*
|
|
125
|
+
* @param callUUID the call UUID which identifies the connection.
|
|
126
|
+
* @return Whether the connection was set as active or not.
|
|
127
|
+
*/
|
|
128
|
+
static boolean setConnectionActive(String callUUID) {
|
|
129
|
+
ConnectionImpl connection = connections.get(callUUID);
|
|
130
|
+
|
|
131
|
+
if (connection != null) {
|
|
132
|
+
connection.setActive();
|
|
133
|
+
return true;
|
|
134
|
+
} else {
|
|
135
|
+
CometChatLogger.w(TAG, "setConnectionActive - no connection for UUID: " + callUUID);
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Used to adjusts the connection's state to
|
|
142
|
+
* {@link Connection#STATE_DISCONNECTED}.
|
|
143
|
+
*
|
|
144
|
+
* @param callUUID the call UUID which identifies the connection.
|
|
145
|
+
* @param cause disconnection reason.
|
|
146
|
+
*/
|
|
147
|
+
static void setConnectionDisconnected(String callUUID, DisconnectCause cause) {
|
|
148
|
+
ConnectionImpl connection = connections.get(callUUID);
|
|
149
|
+
|
|
150
|
+
if (connection != null) {
|
|
151
|
+
if (isSamsungDevice()) {
|
|
152
|
+
// Required to release the audio focus correctly.
|
|
153
|
+
connection.setOnHold();
|
|
154
|
+
// Prevents from including in the native phone calls history
|
|
155
|
+
connection.setConnectionProperties(
|
|
156
|
+
Connection.PROPERTY_SELF_MANAGED
|
|
157
|
+
| Connection.PROPERTY_IS_EXTERNAL_CALL);
|
|
158
|
+
}
|
|
159
|
+
// Note that the connection is not removed from the list here, but
|
|
160
|
+
// in ConnectionImpl's state changed callback. It's a safer
|
|
161
|
+
// approach, because in case the app would crash on the JavaScript
|
|
162
|
+
// side the calls would be cleaned up by the system they would still
|
|
163
|
+
// be removed from the ConnectionList.
|
|
164
|
+
connection.setDisconnected(cause);
|
|
165
|
+
connection.destroy();
|
|
166
|
+
} else {
|
|
167
|
+
CometChatLogger.e(TAG, "endCall no connection for UUID: " + callUUID);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Unregisters a start call promise. Must be called after the Promise is
|
|
173
|
+
* rejected or resolved.
|
|
174
|
+
*
|
|
175
|
+
* @param uuid the call UUID which identifies the call to which the promise
|
|
176
|
+
* belongs to.
|
|
177
|
+
* @return the unregistered Promise instance or <tt>null</tt> if there
|
|
178
|
+
* wasn't any for the given call UUID.
|
|
179
|
+
*/
|
|
180
|
+
static Promise unregisterStartCallPromise(String uuid) {
|
|
181
|
+
return startCallPromises.remove(uuid);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Used to adjusts the call's state.
|
|
186
|
+
*
|
|
187
|
+
* @param callUUID the call UUID which identifies the connection.
|
|
188
|
+
* @param callState a map which carries the properties to be modified. See
|
|
189
|
+
* "KEY_*" constants in {@link ConnectionImpl} for the list of keys.
|
|
190
|
+
*/
|
|
191
|
+
static void updateCall(String callUUID, ReadableMap callState) {
|
|
192
|
+
ConnectionImpl connection = connections.get(callUUID);
|
|
193
|
+
|
|
194
|
+
if (connection != null) {
|
|
195
|
+
if (callState.hasKey(ConnectionImpl.KEY_HAS_VIDEO)) {
|
|
196
|
+
boolean hasVideo
|
|
197
|
+
= callState.getBoolean(ConnectionImpl.KEY_HAS_VIDEO);
|
|
198
|
+
|
|
199
|
+
CometChatLogger.i(TAG, "updateCall: " + callUUID + " hasVideo: " + hasVideo);
|
|
200
|
+
connection.setVideoState(
|
|
201
|
+
hasVideo
|
|
202
|
+
? VideoProfile.STATE_BIDIRECTIONAL
|
|
203
|
+
: VideoProfile.STATE_AUDIO_ONLY);
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
CometChatLogger.e(TAG, "updateCall no connection for UUID: " + callUUID);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@Override
|
|
211
|
+
public Connection onCreateOutgoingConnection(
|
|
212
|
+
PhoneAccountHandle accountHandle, ConnectionRequest request) {
|
|
213
|
+
ConnectionImpl connection = new ConnectionImpl();
|
|
214
|
+
|
|
215
|
+
connection.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
|
|
216
|
+
connection.setAddress(
|
|
217
|
+
request.getAddress(),
|
|
218
|
+
TelecomManager.PRESENTATION_UNKNOWN);
|
|
219
|
+
connection.setExtras(request.getExtras());
|
|
220
|
+
|
|
221
|
+
connection.setAudioModeIsVoip(true);
|
|
222
|
+
|
|
223
|
+
// NOTE there's a time gap between the placeCall and this callback when
|
|
224
|
+
// things could get out of sync, but they are put back in sync once
|
|
225
|
+
// the startCall Promise is resolved below. That's because on
|
|
226
|
+
// the JavaScript side there's a logic to sync up in .then() callback.
|
|
227
|
+
connection.setVideoState(request.getVideoState());
|
|
228
|
+
|
|
229
|
+
Bundle moreExtras = new Bundle();
|
|
230
|
+
|
|
231
|
+
moreExtras.putParcelable(
|
|
232
|
+
EXTRA_PHONE_ACCOUNT_HANDLE,
|
|
233
|
+
Objects.requireNonNull(request.getAccountHandle(), "accountHandle"));
|
|
234
|
+
connection.putExtras(moreExtras);
|
|
235
|
+
|
|
236
|
+
addConnection(connection);
|
|
237
|
+
|
|
238
|
+
Promise startCallPromise
|
|
239
|
+
= unregisterStartCallPromise(connection.getCallUUID());
|
|
240
|
+
|
|
241
|
+
if (startCallPromise != null) {
|
|
242
|
+
CometChatLogger.d(TAG, "onCreateOutgoingConnection " + connection.getCallUUID());
|
|
243
|
+
startCallPromise.resolve(null);
|
|
244
|
+
} else {
|
|
245
|
+
CometChatLogger.e(TAG, "onCreateOutgoingConnection - no start call Promise for UUID: " + connection.getCallUUID());
|
|
246
|
+
connection.setDisconnected(new DisconnectCause(DisconnectCause.ERROR));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return connection;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
@Override
|
|
253
|
+
public Connection onCreateIncomingConnection(
|
|
254
|
+
PhoneAccountHandle accountHandle, ConnectionRequest request) {
|
|
255
|
+
throw new RuntimeException("Not implemented");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@Override
|
|
259
|
+
public void onCreateIncomingConnectionFailed(
|
|
260
|
+
PhoneAccountHandle accountHandle, ConnectionRequest request) {
|
|
261
|
+
throw new RuntimeException("Not implemented");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
@Override
|
|
265
|
+
public void onCreateOutgoingConnectionFailed(
|
|
266
|
+
PhoneAccountHandle accountHandle, ConnectionRequest request) {
|
|
267
|
+
PhoneAccountHandle theAccountHandle = request.getAccountHandle();
|
|
268
|
+
String callUUID = theAccountHandle.getId();
|
|
269
|
+
|
|
270
|
+
CometChatLogger.d(TAG, "onCreateOutgoingConnectionFailed " + callUUID);
|
|
271
|
+
|
|
272
|
+
if (callUUID != null) {
|
|
273
|
+
Promise startCallPromise = unregisterStartCallPromise(callUUID);
|
|
274
|
+
|
|
275
|
+
if (startCallPromise != null) {
|
|
276
|
+
startCallPromise.reject(
|
|
277
|
+
"CREATE_OUTGOING_CALL_FAILED",
|
|
278
|
+
"The request has been denied by the system");
|
|
279
|
+
} else {
|
|
280
|
+
CometChatLogger.e(TAG, "onCreateOutgoingConnectionFailed - no start call Promise for UUID: " + callUUID);
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
CometChatLogger.e(TAG, "onCreateOutgoingConnectionFailed - callUUID is null");
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
unregisterPhoneAccount(theAccountHandle);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private void unregisterPhoneAccount(PhoneAccountHandle phoneAccountHandle) {
|
|
290
|
+
TelecomManager telecom = getSystemService(TelecomManager.class);
|
|
291
|
+
if (telecom != null) {
|
|
292
|
+
if (phoneAccountHandle != null) {
|
|
293
|
+
telecom.unregisterPhoneAccount(phoneAccountHandle);
|
|
294
|
+
} else {
|
|
295
|
+
CometChatLogger.e(TAG, "unregisterPhoneAccount - account handle is null");
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
CometChatLogger.e(TAG, "unregisterPhoneAccount - telecom is null");
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Registers new {@link PhoneAccountHandle}.
|
|
304
|
+
*
|
|
305
|
+
* @param context the current Android context.
|
|
306
|
+
* @param address the phone account's address. At the time of this writing
|
|
307
|
+
* it's the call handle passed from the Java Script side.
|
|
308
|
+
* @param callUUID the call's UUID for which the account is to be created.
|
|
309
|
+
* It will be used as the account's id.
|
|
310
|
+
* @return {@link PhoneAccountHandle} described by the given arguments.
|
|
311
|
+
*/
|
|
312
|
+
static PhoneAccountHandle registerPhoneAccount(
|
|
313
|
+
Context context, Uri address, String callUUID) {
|
|
314
|
+
PhoneAccountHandle phoneAccountHandle
|
|
315
|
+
= new PhoneAccountHandle(
|
|
316
|
+
new ComponentName(context, ConnectionService.class),
|
|
317
|
+
callUUID);
|
|
318
|
+
|
|
319
|
+
PhoneAccount.Builder builder
|
|
320
|
+
= PhoneAccount.builder(phoneAccountHandle, address.toString())
|
|
321
|
+
.setAddress(address)
|
|
322
|
+
.setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED |
|
|
323
|
+
PhoneAccount.CAPABILITY_VIDEO_CALLING |
|
|
324
|
+
PhoneAccount.CAPABILITY_SUPPORTS_VIDEO_CALLING)
|
|
325
|
+
.addSupportedUriScheme(PhoneAccount.SCHEME_SIP);
|
|
326
|
+
|
|
327
|
+
PhoneAccount account = builder.build();
|
|
328
|
+
|
|
329
|
+
TelecomManager telecomManager
|
|
330
|
+
= context.getSystemService(TelecomManager.class);
|
|
331
|
+
telecomManager.registerPhoneAccount(account);
|
|
332
|
+
|
|
333
|
+
return phoneAccountHandle;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Connection implementation for Jitsi Meet's {@link ConnectionService}.
|
|
338
|
+
*
|
|
339
|
+
* @author Pawel Domas
|
|
340
|
+
*/
|
|
341
|
+
class ConnectionImpl extends Connection {
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The constant which defines the key for the "has video" property.
|
|
345
|
+
* The key is used in the map which carries the call's state passed as
|
|
346
|
+
* the argument of the {@link RNConnectionService#updateCall} method.
|
|
347
|
+
*/
|
|
348
|
+
static final String KEY_HAS_VIDEO = "hasVideo";
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Called when system wants to disconnect the call.
|
|
352
|
+
*
|
|
353
|
+
* {@inheritDoc}
|
|
354
|
+
*/
|
|
355
|
+
@Override
|
|
356
|
+
public void onDisconnect() {
|
|
357
|
+
CometChatLogger.i(TAG, "onDisconnect " + getCallUUID());
|
|
358
|
+
WritableNativeMap data = new WritableNativeMap();
|
|
359
|
+
data.putString("callUUID", getCallUUID());
|
|
360
|
+
RNConnectionService.getInstance().emitEvent(
|
|
361
|
+
"org.jitsi.meet:features/connection_service#disconnect",
|
|
362
|
+
data);
|
|
363
|
+
// The JavaScript side will not go back to the native with
|
|
364
|
+
// 'endCall', so the Connection must be removed immediately.
|
|
365
|
+
setConnectionDisconnected(
|
|
366
|
+
getCallUUID(),
|
|
367
|
+
new DisconnectCause(DisconnectCause.LOCAL));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Called when system wants to abort the call.
|
|
372
|
+
*
|
|
373
|
+
* {@inheritDoc}
|
|
374
|
+
*/
|
|
375
|
+
@Override
|
|
376
|
+
public void onAbort() {
|
|
377
|
+
CometChatLogger.i(TAG, "onAbort " + getCallUUID());
|
|
378
|
+
WritableNativeMap data = new WritableNativeMap();
|
|
379
|
+
data.putString("callUUID", getCallUUID());
|
|
380
|
+
RNConnectionService.getInstance().emitEvent(
|
|
381
|
+
"org.jitsi.meet:features/connection_service#abort",
|
|
382
|
+
data);
|
|
383
|
+
// The JavaScript side will not go back to the native with
|
|
384
|
+
// 'endCall', so the Connection must be removed immediately.
|
|
385
|
+
setConnectionDisconnected(
|
|
386
|
+
getCallUUID(),
|
|
387
|
+
new DisconnectCause(DisconnectCause.CANCELED));
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
@Override
|
|
391
|
+
public void onHold() {
|
|
392
|
+
// What ?! Android will still call this method even if we do not add
|
|
393
|
+
// the HOLD capability, so do the same thing as on abort.
|
|
394
|
+
// TODO implement HOLD
|
|
395
|
+
CometChatLogger.w(TAG, "onHold " + getCallUUID() + " - HOLD is not supported, aborting the call...");
|
|
396
|
+
this.onAbort();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Called when there's change to the call audio state. Either by
|
|
401
|
+
* the system after the connection is initialized or in response to
|
|
402
|
+
* {@link #setAudioRoute(int)}.
|
|
403
|
+
*
|
|
404
|
+
* @param state the new {@link CallAudioState}
|
|
405
|
+
*/
|
|
406
|
+
@Override
|
|
407
|
+
public void onCallAudioStateChanged(CallAudioState state) {
|
|
408
|
+
CometChatLogger.d(TAG, "onCallAudioStateChanged: " + state);
|
|
409
|
+
RNConnectionService module = RNConnectionService.getInstance();
|
|
410
|
+
if (module != null) {
|
|
411
|
+
module.onCallAudioStateChange(state);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Unregisters the account when the call is disconnected.
|
|
417
|
+
*
|
|
418
|
+
* @param state - the new connection's state.
|
|
419
|
+
*/
|
|
420
|
+
@Override
|
|
421
|
+
public void onStateChanged(int state) {
|
|
422
|
+
CometChatLogger.d(TAG, "onStateChanged: " + Connection.stateToString(state) + " " + getCallUUID());
|
|
423
|
+
|
|
424
|
+
if (state == STATE_DISCONNECTED) {
|
|
425
|
+
removeConnection(this);
|
|
426
|
+
unregisterPhoneAccount(getPhoneAccountHandle());
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Retrieves the UUID of the call associated with this connection.
|
|
432
|
+
*
|
|
433
|
+
* @return call UUID
|
|
434
|
+
*/
|
|
435
|
+
String getCallUUID() {
|
|
436
|
+
return getPhoneAccountHandle().getId();
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
private PhoneAccountHandle getPhoneAccountHandle() {
|
|
440
|
+
return getExtras().getParcelable(
|
|
441
|
+
ConnectionService.EXTRA_PHONE_ACCOUNT_HANDLE);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
@Override
|
|
445
|
+
public String toString() {
|
|
446
|
+
return String.format(
|
|
447
|
+
"ConnectionImpl[address=%s, uuid=%s]@%d",
|
|
448
|
+
getAddress(), getCallUUID(), hashCode());
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
package com.cometchat.calls;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.view.WindowManager;
|
|
5
|
+
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
10
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
11
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
12
|
+
|
|
13
|
+
public class KeepAwakeModule extends ReactContextBaseJavaModule {
|
|
14
|
+
private static final String TAG = KeepAwakeModule.class.getSimpleName();
|
|
15
|
+
|
|
16
|
+
public KeepAwakeModule(@NonNull ReactApplicationContext reactContext) {
|
|
17
|
+
super(reactContext);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@NonNull
|
|
21
|
+
@Override
|
|
22
|
+
public String getName() {
|
|
23
|
+
return "KeepAwakeModule";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@ReactMethod
|
|
27
|
+
public void activateKeepAwake() {
|
|
28
|
+
UiThreadUtil.runOnUiThread(new Runnable() {
|
|
29
|
+
@Override
|
|
30
|
+
public void run() {
|
|
31
|
+
Activity currentActivity = getCurrentActivity();
|
|
32
|
+
if (currentActivity != null) {
|
|
33
|
+
currentActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
34
|
+
android.util.Log.d(TAG, "Keep awake activated");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@ReactMethod
|
|
41
|
+
public void deactivateKeepAwake() {
|
|
42
|
+
UiThreadUtil.runOnUiThread(new Runnable() {
|
|
43
|
+
@Override
|
|
44
|
+
public void run() {
|
|
45
|
+
Activity currentActivity = getCurrentActivity();
|
|
46
|
+
if (currentActivity != null) {
|
|
47
|
+
currentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
48
|
+
android.util.Log.d(TAG, "Keep awake deactivated");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package com.cometchat.calls;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage;
|
|
4
|
+
import com.facebook.react.bridge.NativeModule;
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
7
|
+
|
|
8
|
+
import java.util.ArrayList;
|
|
9
|
+
import java.util.Collections;
|
|
10
|
+
import java.util.List;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
public class MyAppPackage implements ReactPackage {
|
|
14
|
+
|
|
15
|
+
@Override
|
|
16
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
17
|
+
return Collections.emptyList();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Override
|
|
21
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
22
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
23
|
+
|
|
24
|
+
modules.add(new AudioModeModule(reactContext));
|
|
25
|
+
modules.add(new KeepAwakeModule(reactContext));
|
|
26
|
+
modules.add(new ToastModule(reactContext));
|
|
27
|
+
|
|
28
|
+
if (AudioModeModule.useConnectionService()) {
|
|
29
|
+
modules.add(new RNConnectionService(reactContext));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return modules;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|