edoctor-sendbird-calls 1.0.1-beta.9 → 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.
@@ -1,986 +1,3 @@
1
- // // RNSendBirdCallsModule.java
2
-
3
- // package com.rnsendbirdcalls;
4
-
5
- // import android.annotation.SuppressLint;
6
- // import android.content.Context;
7
- // import android.content.Intent;
8
- // import android.content.SharedPreferences;
9
- // import android.os.Build;
10
- // import android.os.Bundle;
11
- // import android.os.Environment;
12
- // import android.util.Log;
13
-
14
- // import androidx.annotation.NonNull;
15
- // import androidx.annotation.Nullable;
16
-
17
- // import com.facebook.react.bridge.Arguments;
18
- // import com.facebook.react.bridge.Promise;
19
- // import com.facebook.react.bridge.ReactApplicationContext;
20
- // import com.facebook.react.bridge.ReactContext;
21
- // import com.facebook.react.bridge.ReactContextBaseJavaModule;
22
- // import com.facebook.react.bridge.ReactMethod;
23
- // import com.facebook.react.bridge.ReadableMap;
24
- // import com.facebook.react.bridge.WritableArray;
25
- // import com.facebook.react.bridge.WritableMap;
26
- // import com.facebook.react.modules.core.DeviceEventManagerModule;
27
- // import com.sendbird.calls.AcceptParams;
28
- // import com.sendbird.calls.AuthenticateParams;
29
- // import com.sendbird.calls.CallOptions;
30
- // import com.sendbird.calls.DialParams;
31
- // import com.sendbird.calls.DirectCall;
32
- // import com.sendbird.calls.DirectCallUser;
33
- // import com.sendbird.calls.RecordingOptions;
34
- // import com.sendbird.calls.SendBirdCall;
35
- // import com.sendbird.calls.SendBirdException;
36
- // import com.sendbird.calls.handler.DirectCallListener;
37
- // import com.sendbird.calls.handler.RecordingListener;
38
- // import com.sendbird.calls.handler.SendBirdCallListener;
39
-
40
- // import org.jetbrains.annotations.NotNull;
41
-
42
- // import java.io.File;
43
- // import java.util.ArrayList;
44
- // import java.util.Arrays;
45
- // import java.util.HashMap;
46
- // import java.util.List;
47
- // import java.util.Map;
48
- // import java.util.Objects;
49
- // import java.util.UUID;
50
-
51
- // public class RNSendBirdCallsModule extends ReactContextBaseJavaModule {
52
-
53
- // private static ReactApplicationContext mContext;
54
- // private static String TAG = "RNSendBirdCalls";
55
-
56
- // static Boolean IS_CALL_ACCEPTED = false;
57
- // static Boolean IS_CALL_CONNECTED = false;
58
- // private static Boolean IS_INITIAL = false;
59
- // private static Boolean IS_SEND_EVENT_RINGING = false;
60
- // private static ArrayList<String> JS_EVENTS = new ArrayList<String>();
61
- // private static ArrayList<String> EVENTS = new ArrayList<String>(
62
- // Arrays.asList(
63
- // "onRinging",
64
- // "onCallDidAccept",
65
- // "onConnected",
66
- // "onEnded",
67
- // "onReconnected",
68
- // "onReconnecting",
69
- // "onRemoteAudioSettingsChanged",
70
- // "onRemoteVideoSettingsChanged",
71
- // "onRecordingSucceeded",
72
- // "onRecordingFailed"
73
- // )
74
- // );
75
-
76
- // static DirectCall CALL_ACTIVE = null;
77
-
78
- // public RNSendBirdCallsModule(ReactApplicationContext reactContext) {
79
- // super(reactContext);
80
- // this.mContext = reactContext;
81
- // }
82
-
83
- // @Override
84
- // public String getName() {
85
- // return TAG;
86
- // }
87
-
88
- // private static WritableMap getParamDirectCall(@NotNull DirectCall directCall) {
89
- // WritableMap params = Arguments.createMap();
90
-
91
- // WritableMap callerMap = Arguments.createMap();
92
- // WritableMap calleeMap = Arguments.createMap();
93
- // WritableMap customItems = Arguments.createMap();
94
-
95
- // if (directCall.getCustomItems().get("appointmentScheduleId") != null) {
96
- // customItems.putString("appointmentScheduleId", directCall.getCustomItems().get("appointmentScheduleId"));
97
- // }
98
-
99
- // if (directCall.getCustomItems().get("eClinicId") != null) {
100
- // customItems.putString("eClinicId", directCall.getCustomItems().get("eClinicId"));
101
- // }
102
-
103
- // DirectCallUser caller = directCall.getCaller();
104
- // if (caller.getUserId() != null) callerMap.putString("userId", caller.getUserId());
105
- // if (caller.getNickname() != null) callerMap.putString("nickname", caller.getNickname());
106
- // if (caller.getProfileUrl() != null) callerMap.putString("profileUrl", caller.getProfileUrl());
107
-
108
- // DirectCallUser callee = directCall.getCallee();
109
- // if (callee.getUserId() != null) calleeMap.putString("userId", callee.getUserId());
110
- // if (callee.getNickname() != null) calleeMap.putString("nickname", callee.getNickname());
111
- // if (callee.getProfileUrl() != null) calleeMap.putString("profileUrl", callee.getProfileUrl());
112
-
113
- // params.putMap("callee", calleeMap);
114
- // params.putMap("caller", callerMap);
115
- // params.putMap("customItems", customItems);
116
-
117
- // String callId = directCall.getCallId();
118
- // if (callId != null) params.putString("callId", callId);
119
- // else params.putString("callId", "");
120
-
121
- // float duration = directCall.getDuration();
122
- // if (duration > 0) params.putDouble("duration", directCall.getDuration());
123
- // else params.putDouble("duration", 0);
124
-
125
- // Boolean isVideoCall = directCall.isVideoCall();
126
- // Boolean isRemoteAudioEnabled = directCall.isRemoteAudioEnabled();
127
- // Boolean isLocalAudioEnabled = directCall.isLocalAudioEnabled();
128
-
129
- // Boolean isRemoteVideoEnabled = directCall.isRemoteVideoEnabled();
130
- // Boolean isLocalVideoEnabled = directCall.isLocalVideoEnabled();
131
-
132
- // if (isVideoCall != null) params.putBoolean("isVideoCall", isVideoCall);
133
- // if (isRemoteAudioEnabled != null)
134
- // params.putBoolean("isRemoteAudioEnabled", isRemoteAudioEnabled);
135
- // if (isLocalAudioEnabled != null) params.putBoolean("isLocalAudioEnabled", isLocalAudioEnabled);
136
- // if (isRemoteVideoEnabled != null)
137
- // params.putBoolean("isRemoteVideoEnabled", isRemoteVideoEnabled);
138
- // if (isLocalVideoEnabled != null) params.putBoolean("isLocalVideoEnabled", isLocalVideoEnabled);
139
-
140
- // return params;
141
- // }
142
-
143
- // @SuppressLint("WrongConstant")
144
- // public static void configureInNative(Context appContext, String appId) {
145
- // Log.w(TAG, "SendBirdCall initial");
146
- // if (IS_INITIAL) {
147
- // Log.w(TAG, "SendBirdCall is initial ready");
148
- // return;
149
- // }
150
-
151
- // if (SendBirdCall.init(appContext, appId)) {
152
- // Log.d(TAG, "configureInNative: SUCCESS");
153
- // SendBirdCall.removeAllListeners();
154
- // SendBirdCall.removeAllRecordingListeners();
155
- // String UNIQUE_HANDLER_ID = UUID.randomUUID().toString();
156
- // SendBirdCall.addListener(UNIQUE_HANDLER_ID, new SendBirdCallListener() {
157
- // @Override
158
- // public void onRinging(@NotNull DirectCall call) {
159
- // Log.i(TAG, "onRinging");
160
-
161
- // int ongoingCallCount = SendBirdCall.getOngoingCallCount();
162
- // if (ongoingCallCount >= 2) {
163
- // call.end();
164
- // return;
165
- // }
166
-
167
- // handleListenerSendBirdCall(call);
168
- // if (JS_EVENTS.contains("onRinging")) {
169
- // sendEvent(mContext, "onRinging", call);
170
- // IS_SEND_EVENT_RINGING = true;
171
- // }
172
-
173
- // }
174
- // });
175
- // String UNIQUE_ID = UUID.randomUUID().toString();
176
-
177
- // SendBirdCall.addRecordingListener(UNIQUE_ID, new RecordingListener() {
178
- // @Override
179
- // public void onRecordingSucceeded(@NotNull DirectCall directCall, @NotNull String recorderId, @NotNull RecordingOptions recordingOptions, @NotNull String outputFilePath) {
180
- // if (!EVENTS.contains("onRecordingSucceeded")) return;
181
- // WritableMap params = Arguments.createMap();
182
- // params.putString("outputFilePath", outputFilePath);
183
- // mContext
184
- // .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
185
- // .emit("onRecordingSucceeded", params);
186
- // }
187
-
188
- // @Override
189
- // public void onRecordingFailed(@NotNull DirectCall directCall, @NotNull String recorderId, @NotNull SendBirdException e) {
190
- // if (!EVENTS.contains("onRecordingFailed")) return;
191
- // WritableMap params = Arguments.createMap();
192
- // params.putString("errorCode", String.valueOf(e.getCode()));
193
- // params.putString("errorMessage", String.valueOf(e.getMessage()));
194
- // mContext
195
- // .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
196
- // .emit("onRecordingFailed", params);
197
- // }
198
- // });
199
-
200
- // int ringing = appContext.getResources().getIdentifier("ringing", "raw", appContext.getPackageName());
201
- // int connecting = appContext.getResources().getIdentifier("connecting", "raw", appContext.getPackageName());
202
- // int connected = appContext.getResources().getIdentifier("connected", "raw", appContext.getPackageName());
203
- // setUpSoundEffects(
204
- // ringing,
205
- // connecting,
206
- // connected,
207
- // connected
208
- // );
209
- // IS_INITIAL = true;
210
- // }
211
- // }
212
-
213
- // @ReactMethod
214
- // public void initSendBird(String appId, Promise promise) {
215
- // IS_INITIAL = false;
216
- // Context appContext = mContext.getApplicationContext();
217
- // WritableMap result = Arguments.createMap();
218
- // if (SendBirdCall.init(appContext, appId)) {
219
- // Log.d(TAG, "configureInNative: SUCCESS");
220
- // SendBirdCall.removeAllListeners();
221
- // SendBirdCall.removeAllRecordingListeners();
222
- // String UNIQUE_HANDLER_ID = UUID.randomUUID().toString();
223
- // SendBirdCall.addListener(UNIQUE_HANDLER_ID, new SendBirdCallListener() {
224
- // @Override
225
- // public void onRinging(@NotNull DirectCall call) {
226
- // Log.i(TAG, "onRinging");
227
-
228
- // int ongoingCallCount = SendBirdCall.getOngoingCallCount();
229
- // if (ongoingCallCount >= 2) {
230
- // call.end();
231
- // return;
232
- // }
233
-
234
- // handleListenerSendBirdCall(call);
235
- // if (JS_EVENTS.contains("onRinging")) {
236
- // sendEvent(mContext, "onRinging", call);
237
- // IS_SEND_EVENT_RINGING = true;
238
- // }
239
-
240
- // }
241
- // });
242
- // String UNIQUE_ID = UUID.randomUUID().toString();
243
-
244
- // SendBirdCall.addRecordingListener(UNIQUE_ID, new RecordingListener() {
245
- // @Override
246
- // public void onRecordingSucceeded(@NotNull DirectCall directCall, @NotNull String recorderId, @NotNull RecordingOptions recordingOptions, @NotNull String outputFilePath) {
247
- // if (!EVENTS.contains("onRecordingSucceeded")) return;
248
- // WritableMap params = Arguments.createMap();
249
- // params.putString("outputFilePath", outputFilePath);
250
- // mContext
251
- // .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
252
- // .emit("onRecordingSucceeded", params);
253
- // }
254
-
255
- // @Override
256
- // public void onRecordingFailed(@NotNull DirectCall directCall, @NotNull String recorderId, @NotNull SendBirdException e) {
257
- // if (!EVENTS.contains("onRecordingFailed")) return;
258
- // WritableMap params = Arguments.createMap();
259
- // params.putString("errorCode", String.valueOf(e.getCode()));
260
- // params.putString("errorMessage", String.valueOf(e.getMessage()));
261
- // mContext
262
- // .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
263
- // .emit("onRecordingFailed", params);
264
- // }
265
- // });
266
-
267
- // int ringing = appContext.getResources().getIdentifier("ringing", "raw", appContext.getPackageName());
268
- // int connecting = appContext.getResources().getIdentifier("connecting", "raw", appContext.getPackageName());
269
- // int connected = appContext.getResources().getIdentifier("connected", "raw", appContext.getPackageName());
270
- // setUpSoundEffects(
271
- // ringing,
272
- // connecting,
273
- // connected,
274
- // connected
275
- // );
276
- // IS_INITIAL = true;
277
- // result.putBoolean("succeeded", true);
278
- // } else {
279
- // result.putBoolean("succeeded", false);
280
- // }
281
- // promise.resolve(result);
282
- // }
283
-
284
- // @ReactMethod
285
- // public void authenticate(String userId, String accessToken, Promise promise) {
286
- // try {
287
- // AuthenticateParams params = new AuthenticateParams(userId).setAccessToken(accessToken);
288
- // SendBirdCall.authenticate(params, (user, e) -> {
289
- // WritableMap result = Arguments.createMap();
290
- // if (e == null) {
291
- // // The user has been authenticated successfully and is connected to Sendbird server
292
- // result.putBoolean("succeeded", true);
293
- // result.putString("userId", user.getUserId());
294
- // result.putString("nickname", user.getNickname());
295
- // Log.d(TAG, "authenticate: " + user.getNickname());
296
- // } else {
297
- // result.putBoolean("succeeded", false);
298
- // result.putString("errorCode", String.valueOf(e.getCode()));
299
- // result.putString("errorMessage", e.getMessage());
300
- // Log.d(TAG, "authenticate: " + e.getMessage());
301
- // }
302
- // promise.resolve(result);
303
- // });
304
- // } catch (Exception e) {
305
- // WritableMap result = Arguments.createMap();
306
- // result.putBoolean("succeeded", false);
307
- // result.putString("errorMessage", String.valueOf(e.getMessage()));
308
- // promise.resolve(result);
309
- // }
310
- // }
311
-
312
- // @ReactMethod
313
- // public void deAuthenticate(Promise promise) {
314
- // SendBirdCall.deauthenticate(e -> {
315
- // Log.d(TAG, "deAuthen");
316
- // WritableMap result = Arguments.createMap();
317
- // if (e == null) {
318
- // result.putBoolean("succeeded", true);
319
- // } else {
320
- // result.putBoolean("succeeded", false);
321
- // result.putString("errorCode", String.valueOf(e.getCode()));
322
- // result.putString("errorMessage", String.valueOf(e.getMessage()));
323
- // }
324
- // promise.resolve(result);
325
- // });
326
- // }
327
-
328
- // @ReactMethod
329
- // public void shareStorage(String appId) {
330
- // if (appId.isEmpty()) {
331
- // return;
332
- // }
333
- // SharedPreferences shareReference = mContext.getApplicationContext().getSharedPreferences("EDOCTOR_NATIVE", Context.MODE_PRIVATE);
334
- // SharedPreferences.Editor editor = shareReference.edit();
335
- // editor.putString("ANDROID_APP_ID", appId);
336
- // editor.apply();
337
- // }
338
-
339
- // public static String getAppId(Context context) {
340
- // SharedPreferences shareReference = context.getSharedPreferences("EDOCTOR_NATIVE", Context.MODE_PRIVATE);
341
- // return shareReference.getString("ANDROID_APP_ID", "");
342
- // }
343
-
344
- // @ReactMethod
345
- // public void getCall(String callId, Promise promise) {
346
- // DirectCall mdirectCall = SendBirdCall.getCall(callId);
347
- // if (mdirectCall != null) {
348
- // WritableMap callInfo = getParamDirectCall(mdirectCall);
349
- // callInfo.putBoolean("succeeded", true);
350
- // promise.resolve(callInfo);
351
- // } else {
352
- // WritableMap result = Arguments.createMap();
353
- // result.putBoolean("succeeded", false);
354
- // result.putString("errorMessage", "Cuộc gọi không tồn tại");
355
- // promise.resolve(result);
356
- // }
357
- // }
358
-
359
- // @ReactMethod
360
- // public void registerPushToken(String token, Promise promise) {
361
- // if (SendBirdCall.getCurrentUser() != null) {
362
- // SendBirdCall.registerPushToken(token, false, e -> {
363
- // if (e != null) {
364
- // Log.i("RNSendBirdCalls", "registerPushToken => e: " + e.getMessage());
365
- // WritableMap result = Arguments.createMap();
366
- // result.putBoolean("succeeded", false);
367
- // result.putString("errorCode", String.valueOf(e.getCode()));
368
- // result.putString("errorMessage", String.valueOf(e.getMessage()));
369
- // promise.resolve(result);
370
- // } else {
371
- // WritableMap result = Arguments.createMap();
372
- // result.putBoolean("succeeded", true);
373
- // promise.resolve(result);
374
- // }
375
- // });
376
- // }
377
- // }
378
-
379
- // @ReactMethod
380
- // public void unregisterPushToken(String token, Promise promise) {
381
- // if (SendBirdCall.getCurrentUser() != null) {
382
- // SendBirdCall.unregisterPushToken(token, e -> {
383
- // WritableMap result = Arguments.createMap();
384
- // if (e == null) {
385
- // result.putBoolean("succeeded", true);
386
- // } else {
387
- // result.putBoolean("succeeded", false);
388
- // result.putString("errorCode", String.valueOf(e.getCode()));
389
- // result.putString("errorMessage", String.valueOf(e.getMessage()));
390
- // }
391
- // promise.resolve(result);
392
- // });
393
- // } else {
394
- // WritableMap result = Arguments.createMap();
395
- // result.putBoolean("succeeded", false);
396
- // promise.resolve(result);
397
- // }
398
- // }
399
-
400
- // @ReactMethod
401
- // public void startRecording(String fileName, boolean isRemote, Promise promise) {
402
- // try {
403
- // File myDir = new File(mContext.getApplicationContext().getFilesDir().getAbsolutePath() + "/records");
404
- // if (!myDir.exists()) {
405
- // myDir.mkdirs();
406
- // }
407
- // RecordingOptions options;
408
- // if (isRemote) {
409
- // options = new RecordingOptions(RecordingOptions.RecordingType.LOCAL_AUDIO_REMOTE_AUDIO_AND_VIDEO, myDir.getAbsolutePath(), fileName);
410
- // } else {
411
- // options = new RecordingOptions(RecordingOptions.RecordingType.LOCAL_AUDIO_AND_VIDEO_REMOTE_AUDIO, myDir.getAbsolutePath(), fileName);
412
- // }
413
- // CALL_ACTIVE.startRecording(options, (recordingId, e) -> {
414
- // WritableMap result = Arguments.createMap();
415
- // if (e == null) {
416
- // result.putBoolean("succeeded", true);
417
- // result.putString("recordingId", recordingId);
418
- // Log.d(TAG, "recordingId: " + recordingId);
419
- // } else {
420
- // result.putBoolean("succeeded", false);
421
- // result.putString("errorCode", String.valueOf(e.getCode()));
422
- // result.putString("errorMessage", String.valueOf(e.getMessage()));
423
- // Log.d(TAG, "errorMessage: " + String.valueOf(e.getMessage()));
424
-
425
- // }
426
-
427
- // promise.resolve(result);
428
- // });
429
- // } catch (Exception e) {
430
- // WritableMap result = Arguments.createMap();
431
- // result.putBoolean("succeeded", false);
432
- // result.putString("errorMessage", e.getMessage());
433
- // promise.resolve(result);
434
- // }
435
- // }
436
-
437
- // @ReactMethod
438
- // public void stopRecording(String recordingId, Promise promise) {
439
- // Log.d(TAG, "stopRecording: " + recordingId);
440
- // if (CALL_ACTIVE == null) {
441
- // WritableMap result = Arguments.createMap();
442
- // result.putBoolean("succeeded", false);
443
- // result.putString("errorMessage", "Cuộc gọi không tồn tại");
444
- // promise.resolve(result);
445
- // }
446
- // boolean succeeded = CALL_ACTIVE.stopRecording(recordingId);
447
- // WritableMap result = Arguments.createMap();
448
- // result.putBoolean("succeeded", succeeded);
449
- // promise.resolve(result);
450
- // }
451
-
452
- // @ReactMethod
453
- // public void dial(String calleeId, boolean isVideoCall, boolean isVideoEnable, boolean isAudioEnable, String appointmentScheduleId, String eClinicId, Promise promise) {
454
- // Log.d(TAG, "dial");
455
-
456
- // int ongoingCallCount = SendBirdCall.getOngoingCallCount();
457
- // if (ongoingCallCount > 0) {
458
- // return;
459
- // }
460
-
461
- // CallOptions callOptions = new CallOptions().setVideoEnabled(isVideoEnable).setAudioEnabled(isAudioEnable);
462
- // Map<String, String> customItems = new HashMap<>();
463
- // customItems.put("appointmentScheduleId", appointmentScheduleId);
464
- // customItems.put("eClinicId", eClinicId);
465
-
466
- // DialParams dialParams = new DialParams(calleeId);
467
- // dialParams.setVideoCall(isVideoCall);
468
- // dialParams.setCallOptions(callOptions);
469
- // dialParams.setCustomItems(customItems);
470
-
471
- // DirectCall mDirectCall = SendBirdCall.dial(dialParams, (call, e) -> {
472
- // if (e != null) {
473
- // Log.d(TAG, "dial: " + e.getMessage());
474
- // WritableMap result = Arguments.createMap();
475
- // result.putBoolean("succeeded", false);
476
- // result.putString("errorCode", String.valueOf(e.getCode()));
477
- // result.putString("errorMessage", String.valueOf(e.getMessage()));
478
- // promise.resolve(result);
479
- // return;
480
- // }
481
- // WritableMap params = Arguments.createMap();
482
- // params.putBoolean("succeeded", true);
483
- // params.putString("callId", call.getCallId());
484
- // params.putString("caller", call.getCaller().getUserId());
485
- // params.putString("callee", call.getCallee().getUserId());
486
- // promise.resolve(params);
487
- // });
488
-
489
- // if (mDirectCall != null) {
490
- // handleListenerSendBirdCall(mDirectCall);
491
- // }
492
- // }
493
-
494
- // @ReactMethod
495
- // public void muteMicrophone(Promise promise) {
496
- // Log.i(TAG, "muteMicrophone");
497
- // if (CALL_ACTIVE == null) {
498
- // WritableMap result = Arguments.createMap();
499
- // result.putBoolean("succeeded", false);
500
- // result.putString("errorMessage", "Cuộc gọi không tồn tại");
501
- // promise.resolve(result);
502
- // }
503
- // ;
504
- // boolean succeeded = CALL_ACTIVE.muteMicrophone();
505
- // WritableMap result = Arguments.createMap();
506
- // result.putBoolean("succeeded", succeeded);
507
- // promise.resolve(result);
508
- // }
509
-
510
- // @ReactMethod
511
- // public void unmuteMicrophone(Promise promise) {
512
- // Log.i(TAG, "unmuteMicrophone");
513
- // if (CALL_ACTIVE == null) {
514
- // WritableMap result = Arguments.createMap();
515
- // result.putBoolean("succeeded", false);
516
- // result.putString("errorMessage", "Cuộc gọi không tồn tại");
517
- // promise.resolve(result);
518
- // }
519
- // ;
520
- // boolean succeeded = CALL_ACTIVE.unmuteMicrophone();
521
- // WritableMap result = Arguments.createMap();
522
- // result.putBoolean("succeeded", succeeded);
523
- // promise.resolve(result);
524
- // }
525
-
526
- // @ReactMethod
527
- // public void startVideo(Promise promise) {
528
- // Log.i(TAG, "startVideo");
529
- // if (CALL_ACTIVE == null) {
530
- // WritableMap result = Arguments.createMap();
531
- // result.putBoolean("succeeded", false);
532
- // result.putString("errorMessage", "Cuộc gọi không tồn tại");
533
- // promise.resolve(result);
534
- // }
535
- // ;
536
- // try {
537
- // CALL_ACTIVE.startVideo();
538
- // WritableMap result = Arguments.createMap();
539
- // result.putBoolean("succeeded", true);
540
- // promise.resolve(result);
541
- // } catch (Exception e) {
542
- // WritableMap result = Arguments.createMap();
543
- // result.putBoolean("succeeded", false);
544
- // result.putString("errorMessage", e.getMessage());
545
- // promise.resolve(result);
546
- // }
547
- // }
548
-
549
- // @ReactMethod
550
- // public void stopVideo(Promise promise) {
551
- // Log.i(TAG, "stopVideo");
552
- // if (CALL_ACTIVE == null) {
553
- // WritableMap result = Arguments.createMap();
554
- // result.putBoolean("succeeded", false);
555
- // result.putString("errorMessage", "Cuộc gọi không tồn tại");
556
- // promise.resolve(result);
557
- // }
558
- // ;
559
- // try {
560
- // CALL_ACTIVE.stopVideo();
561
- // WritableMap result = Arguments.createMap();
562
- // result.putBoolean("succeeded", true);
563
- // promise.resolve(result);
564
- // } catch (Exception e) {
565
- // WritableMap result = Arguments.createMap();
566
- // result.putBoolean("succeeded", false);
567
- // result.putString("errorMessage", e.getMessage());
568
- // promise.resolve(result);
569
- // }
570
- // }
571
-
572
- // @ReactMethod
573
- // public void switchCamera(Promise promise) {
574
- // Log.i(TAG, "switchCamera");
575
- // if (CALL_ACTIVE == null) {
576
- // WritableMap result = Arguments.createMap();
577
- // result.putBoolean("succeeded", false);
578
- // result.putString("errorMessage", "Cuộc gọi không tồn tại");
579
- // promise.resolve(result);
580
- // }
581
- // ;
582
- // CALL_ACTIVE.switchCamera(e -> {
583
- // WritableMap result = Arguments.createMap();
584
- // if (e != null) {
585
- // result.putBoolean("succeeded", false);
586
- // result.putString("errorCode", String.valueOf(e.getCode()));
587
- // result.putString("errorMessage", String.valueOf(e.getMessage()));
588
- // } else {
589
- // result.putBoolean("succeeded", true);
590
- // }
591
- // promise.resolve(result);
592
- // });
593
- // }
594
-
595
- // @ReactMethod
596
- // public void endCall(Promise promise) {
597
- // Log.i(TAG, "endCall");
598
- // if (CALL_ACTIVE != null) {
599
- // IS_CALL_ACCEPTED = false;
600
- // IS_CALL_CONNECTED = false;
601
- // WritableMap params = Arguments.createMap();
602
- // params.putString("callId", CALL_ACTIVE.getCallId());
603
- // params.putString("caller", CALL_ACTIVE.getCaller().getUserId());
604
- // params.putString("callee", CALL_ACTIVE.getCallee().getUserId());
605
- // params.putString("duration", String.valueOf(CALL_ACTIVE.getDuration()));
606
- // try {
607
- // CALL_ACTIVE.end();
608
- // promise.resolve(params);
609
- // } catch (Exception e) {
610
- // WritableMap result = Arguments.createMap();
611
- // result.putBoolean("succeeded", false);
612
- // result.putString("errorMessage", e.getMessage());
613
- // promise.resolve(result);
614
- // }
615
- // } else {
616
- // WritableMap result = Arguments.createMap();
617
- // result.putBoolean("succeeded", false);
618
- // result.putString("errorMessage", "Cuộc gọi không tồn tại");
619
- // promise.resolve(result);
620
- // }
621
- // }
622
-
623
- // @ReactMethod
624
- // public void acceptCall(String callId, boolean isVideoEnable, boolean isAudioEnable, Promise promise) {
625
- // Log.i(TAG, "acceptCall");
626
- // try {
627
- // DirectCall mDirectCall = SendBirdCall.getCall(callId);
628
- // if (mDirectCall != null) {
629
- // handleListenerSendBirdCall(mDirectCall);
630
- // CallOptions callOptions = new CallOptions().setVideoEnabled(isVideoEnable).setAudioEnabled(isAudioEnable);
631
- // mDirectCall.accept(new AcceptParams().setCallOptions(callOptions));
632
- // IS_CALL_ACCEPTED = true;
633
- // WritableMap result = Arguments.createMap();
634
- // result.putBoolean("succeeded", true);
635
- // promise.resolve(result);
636
- // }
637
- // } catch (Exception e) {
638
- // WritableMap result = Arguments.createMap();
639
- // result.putBoolean("succeeded", false);
640
- // result.putString("errorMessage", "Cuộc gọi không tồn tại");
641
- // promise.resolve(result);
642
- // }
643
- // }
644
-
645
- // @ReactMethod
646
- // public void endIncomingCallNeedAuthentication(String callId, Promise promise) {
647
- // Log.i(TAG, "endIncomingCallNeedAuthentication");
648
- // try {
649
- // DirectCall mDirectCall = SendBirdCall.getCall(callId);
650
- // DirectCallUser callee = mDirectCall.getCallee();
651
- // AuthenticateParams params = new AuthenticateParams(callee.getUserId());
652
- // SendBirdCall.authenticate(params, (user, e) -> {
653
- // if (e == null) {
654
- // if (mDirectCall != null) {
655
- // mDirectCall.end();
656
- // IS_CALL_ACCEPTED = false;
657
- // IS_CALL_CONNECTED = false;
658
- // WritableMap result = Arguments.createMap();
659
- // result.putBoolean("succeeded", true);
660
- // promise.resolve(result);
661
- // }
662
- // } else {
663
- // WritableMap result = Arguments.createMap();
664
- // result.putBoolean("succeeded", false);
665
- // result.putString("errorCode", String.valueOf(e.getCode()));
666
- // result.putString("errorMessage", String.valueOf(e.getMessage()));
667
- // promise.resolve(result);
668
- // }
669
- // });
670
- // } catch (Exception e) {
671
- // WritableMap result = Arguments.createMap();
672
- // result.putBoolean("succeeded", false);
673
- // result.putString("errorMessage", e.getMessage());
674
- // promise.resolve(result);
675
- // }
676
- // }
677
-
678
- // @ReactMethod
679
- // public void acceptIncomingCallNeedAuthentication(String callId, boolean isVideoEnable, boolean isAudioEnable, Promise promise) {
680
- // Log.i(TAG, "acceptIncomingCallNeedAuthentication");
681
- // try {
682
- // DirectCall mDirectCall = SendBirdCall.getCall(callId);
683
- // DirectCallUser callee = mDirectCall.getCallee();
684
- // AuthenticateParams params = new AuthenticateParams(callee.getUserId());
685
- // SendBirdCall.authenticate(params, (user, e) -> {
686
- // if (e == null) {
687
- // if (mDirectCall != null) {
688
- // handleListenerSendBirdCall(mDirectCall);
689
- // CallOptions callOptions = new CallOptions().setVideoEnabled(isVideoEnable).setAudioEnabled(isAudioEnable);
690
- // mDirectCall.accept(new AcceptParams().setCallOptions(callOptions));
691
- // IS_CALL_ACCEPTED = true;
692
- // WritableMap result = Arguments.createMap();
693
- // result.putBoolean("succeeded", true);
694
- // promise.resolve(result);
695
- // }
696
- // } else {
697
- // WritableMap result = Arguments.createMap();
698
- // result.putBoolean("succeeded", false);
699
- // result.putString("errorCode", String.valueOf(e.getCode()));
700
- // result.putString("errorMessage", String.valueOf(e.getMessage()));
701
- // promise.resolve(result);
702
- // }
703
- // });
704
- // } catch (Exception e) {
705
- // WritableMap result = Arguments.createMap();
706
- // result.putBoolean("succeeded", false);
707
- // result.putString("errorMessage", e.getMessage());
708
- // promise.resolve(result);
709
- // }
710
- // }
711
-
712
- // @ReactMethod
713
- // public void getOngoingCalls(Promise promise) {
714
- // List<DirectCall> directCall = SendBirdCall.getOngoingCalls();
715
- // WritableArray resultData = Arguments.createArray();
716
- // if (directCall != null && directCall.isEmpty() == false) {
717
- // for (int i = 0; i < directCall.size(); i++) {
718
- // WritableMap item = getParamDirectCall(directCall.get(i));
719
- // if (item != null) {
720
- // resultData.pushMap(item);
721
- // }
722
- // }
723
- // promise.resolve(resultData);
724
- // } else {
725
- // promise.resolve(null);
726
- // }
727
- // }
728
-
729
- // @ReactMethod
730
- // public void getCallInfo(Promise promise) {
731
- // if (CALL_ACTIVE == null) {
732
- // promise.resolve(null);
733
- // } else {
734
- // DirectCall mdirectCall = SendBirdCall.getCall(CALL_ACTIVE.getCallId());
735
- // if (mdirectCall == null) promise.resolve(null);
736
- // else {
737
- // Log.d(TAG, "getCallInfo: " + mdirectCall);
738
- // DirectCallUser callee = mdirectCall.getCallee();
739
- // DirectCallUser caller = mdirectCall.getCaller();
740
- // }
741
- // }
742
- // }
743
-
744
- // @ReactMethod
745
- // public void wakeAppIncomingCall(ReadableMap params) {
746
- // Log.d(TAG, "wakeAppIncomingCall: ");
747
- // Bundle bundle = Arguments.toBundle(params);
748
- // Intent intent = new Intent(mContext.getApplicationContext(), VoIPService.class);
749
- // intent.putExtras(bundle);
750
- // if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
751
- // mContext.getApplicationContext().startForegroundService(intent);
752
- // } else {
753
- // mContext.getApplicationContext().startService(intent);
754
- // }
755
- // }
756
-
757
- // @ReactMethod
758
- // public void navigateMainApp(ReadableMap params) {
759
- // Log.d(TAG, "navigateMainApp: ");
760
- // Bundle bundle = Arguments.toBundle(params);
761
- // SharedUtils.navigateMainApp(mContext.getApplicationContext(), bundle);
762
- // }
763
-
764
- // @ReactMethod
765
- // public void finishLockedScreenUI() {
766
- // Objects.requireNonNull(mContext.getCurrentActivity()).finish();
767
- // }
768
-
769
- // @ReactMethod
770
- // public void getDeviceLocked(Promise promise) {
771
- // try {
772
- // boolean isLocked = SharedUtils.getDeviceLocked(mContext.getApplicationContext());
773
- // WritableMap result = Arguments.createMap();
774
- // result.putBoolean("succeeded", true);
775
- // result.putBoolean("isLocked", isLocked);
776
- // promise.resolve(result);
777
- // } catch (RuntimeException e) {
778
- // WritableMap result = Arguments.createMap();
779
- // result.putBoolean("succeeded", false);
780
- // result.putString("errorMessage", e.getMessage());
781
- // promise.resolve(result);
782
- // }
783
- // }
784
-
785
- // @ReactMethod
786
- // public void cancelComingCallNotification() {
787
- // // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) return;
788
- // SharedUtils.cancelComingCallNotification();
789
- // }
790
-
791
- // @ReactMethod
792
- // public void isAppInForeground(Promise promise) {
793
- // try {
794
- // boolean isInForeground = SharedUtils.isAppInForeground(mContext.getApplicationContext());
795
- // WritableMap result = Arguments.createMap();
796
- // result.putBoolean("succeeded", true);
797
- // result.putBoolean("isInForeground", isInForeground);
798
- // promise.resolve(result);
799
- // } catch (RuntimeException e) {
800
- // WritableMap result = Arguments.createMap();
801
- // result.putBoolean("succeeded", false);
802
- // result.putString("errorMessage", e.getMessage());
803
- // promise.resolve(result);
804
- // }
805
- // }
806
-
807
- // @ReactMethod
808
- // public void setNativeEvent(String event) {
809
- // JS_EVENTS.add(event);
810
- // if (event.contains("onRinging")
811
- // && IS_SEND_EVENT_RINGING == false
812
- // && IS_CALL_ACCEPTED == false
813
- // && IS_CALL_CONNECTED == false
814
- // && CALL_ACTIVE != null) {
815
- // sendEvent(mContext, "onRinging", CALL_ACTIVE);
816
- // IS_SEND_EVENT_RINGING = true;
817
- // }
818
- // // if(event.contains("onCallDidAccept")
819
- // // && IS_CALL_ACCEPTED == true
820
- // // && IS_CALL_CONNECTED == false
821
- // // && CALL_ACTIVE != null ){
822
- // // sendEvent(mContext, "onConnected", CALL_ACTIVE);
823
- // // IS_CALL_CONNECTED = true;
824
- // // }
825
- // }
826
-
827
- // @ReactMethod
828
- // public void removeNativeEvent(String event) {
829
- // JS_EVENTS.remove(event);
830
- // }
831
-
832
- // @ReactMethod
833
- // public void removeAllEvents() {
834
- // SendBirdCall.removeAllListeners();
835
- // SendBirdCall.removeAllRecordingListeners();
836
- // }
837
-
838
- // @ReactMethod
839
- // public void endAllCalls(Promise promise) {
840
- // try {
841
- // List<DirectCall> directCall = SendBirdCall.getOngoingCalls();
842
- // if (!directCall.isEmpty()) {
843
- // for (int i = 0; i < directCall.size(); i++) {
844
- // directCall.get(i).end();
845
- // }
846
- // }
847
- // WritableMap result = Arguments.createMap();
848
- // result.putBoolean("succeeded", true);
849
- // promise.resolve(result);
850
- // } catch (RuntimeException e) {
851
- // WritableMap result = Arguments.createMap();
852
- // result.putBoolean("succeeded", false);
853
- // result.putString("errorMessage", e.getMessage());
854
- // promise.resolve(result);
855
- // }
856
- // }
857
-
858
- // public static void endCalls() {
859
- // try {
860
- // List<DirectCall> directCall = SendBirdCall.getOngoingCalls();
861
- // if (!directCall.isEmpty()) {
862
- // for (int i = 0; i < directCall.size(); i++) {
863
- // directCall.get(i).end();
864
- // }
865
- // }
866
- // } catch (RuntimeException e) {
867
- // Log.d(TAG, "endCalls: " + e);
868
- // }
869
- // }
870
-
871
- // private boolean contains(ArrayList array, String value) {
872
- // for (int i = 0; i < array.size(); i++) {
873
- // if (array.get(i).equals(value)) {
874
- // return true;
875
- // }
876
- // }
877
- // return false;
878
- // }
879
-
880
-
881
- // private static void handleListenerSendBirdCall(DirectCall mDirectCall) {
882
- // if (mDirectCall == null) return;
883
- // CALL_ACTIVE = mDirectCall;
884
- // mDirectCall.setListener(new DirectCallListener() {
885
- // @Override
886
- // public void onEstablished(@NotNull DirectCall directCall) {
887
- // //Remote user accepted the call.
888
- // Log.i(TAG, "onEstablished");
889
- // sendEvent(mContext, "onCallDidAccept", directCall);
890
- // }
891
-
892
- // @Override
893
- // public void onConnected(@NotNull DirectCall directCall) {
894
- // Log.i(TAG, "onConnected");
895
- // WritableMap params = Arguments.createMap();
896
- // sendEvent(mContext, "onConnected", directCall);
897
- // }
898
-
899
- // @Override
900
- // public void onEnded(@NotNull DirectCall directCall) {
901
- // Log.i(TAG, "onEnded");
902
- // sendEvent(mContext, "onEnded", directCall);
903
- // IS_CALL_ACCEPTED = false;
904
- // IS_CALL_CONNECTED = false;
905
- // CALL_ACTIVE = null;
906
- // }
907
-
908
- // @Override
909
- // public void onReconnected(@NonNull DirectCall directCall) {
910
- // Log.i(TAG, "onReconnected");
911
- // sendEvent(mContext, "onReconnected", directCall);
912
- // }
913
-
914
- // @Override
915
- // public void onReconnecting(@NonNull DirectCall directCall) {
916
- // Log.i(TAG, "onReconnecting");
917
- // sendEvent(mContext, "onReconnecting", directCall);
918
- // }
919
-
920
- // @Override
921
- // public void onRemoteAudioSettingsChanged(DirectCall directCall) {
922
- // Log.i(TAG, "onRemoteAudioSettingsChanged");
923
- // sendEvent(mContext, "onRemoteAudioSettingsChanged", directCall);
924
- // }
925
-
926
- // @Override
927
- // public void onRemoteVideoSettingsChanged(DirectCall directCall) {
928
- // sendEvent(mContext, "onRemoteVideoSettingsChanged", directCall);
929
- // }
930
-
931
- // });
932
- // }
933
-
934
- // public static void sendEvent(ReactContext reactContext, String eventName, DirectCall directCall) {
935
- // if (!EVENTS.contains(eventName)) return;
936
- // WritableMap params = getParamDirectCall(directCall);
937
- // reactContext
938
- // .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
939
- // .emit(eventName, params);
940
- // }
941
-
942
- // public static void onMessageReceived(Context context, Map<String, String> data) {
943
- // int ringing = context.getResources().getIdentifier("ringing", "raw", context.getPackageName());
944
- // int connecting = context.getResources().getIdentifier("connecting", "raw", context.getPackageName());
945
- // int connected = context.getResources().getIdentifier("connected", "raw", context.getPackageName());
946
- // setUpSoundEffects(
947
- // ringing,
948
- // connecting,
949
- // connected,
950
- // connected
951
- // );
952
- // SendBirdCall.handleFirebaseMessageData(data);
953
- // }
954
-
955
- // public static void onNewToken(String token) {
956
- // if (SendBirdCall.getCurrentUser() != null) {
957
- // SendBirdCall.registerPushToken(token, false, e -> {
958
- // if (e != null) {
959
- // Log.i("RNSendBirdCalls", "[FirebaseMessagingService] onNewToken() => e: " + e.getMessage());
960
- // }
961
- // });
962
- // }
963
- // }
964
-
965
- // static public void setUpSoundEffects(
966
- // @Nullable Integer ringingId,
967
- // @Nullable Integer dialing,
968
- // @Nullable Integer connectingId,
969
- // @Nullable Integer connectedId
970
- // ) {
971
- // if (ringingId != null)
972
- // SendBirdCall.Options.addDirectCallSound(SendBirdCall.SoundType.RINGING, ringingId);
973
- // if (dialing != null)
974
- // SendBirdCall.Options.addDirectCallSound(SendBirdCall.SoundType.DIALING, dialing);
975
- // if (connectingId != null)
976
- // SendBirdCall.Options.addDirectCallSound(SendBirdCall.SoundType.RECONNECTING, connectingId);
977
- // if (connectedId != null)
978
- // SendBirdCall.Options.addDirectCallSound(SendBirdCall.SoundType.RECONNECTED, connectedId);
979
- // SendBirdCall.Options.setDirectCallDialingSoundOnWhenSilentOrVibrateMode(true);
980
- // }
981
- // }
982
-
983
-
984
1
  package com.rnsendbirdcalls;
985
2
 
986
3
  import android.annotation.SuppressLint;