@cloudflare/realtimekit-react-native 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +83 -0
- package/RealtimeKitCore.podspec +19 -0
- package/android/build.gradle +58 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/src/main/AndroidManifest.xml +23 -0
- package/android/src/main/java/com/reactnativecore/BackgroundTimer/RNBackgroundTimer.java +97 -0
- package/android/src/main/java/com/reactnativecore/Constants.java +14 -0
- package/android/src/main/java/com/reactnativecore/CoreModule.java +49 -0
- package/android/src/main/java/com/reactnativecore/CorePackage.java +34 -0
- package/android/src/main/java/com/reactnativecore/DyteHelperModule.java +268 -0
- package/android/src/main/java/com/reactnativecore/DyteHolder.java +7 -0
- package/android/src/main/java/com/reactnativecore/ForegroundService.java +48 -0
- package/android/src/main/java/com/reactnativecore/NotificationHelper.java +127 -0
- package/android/src/main/java/com/reactnativecore/RNPermissionsModule.java +226 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/AppRTCBluetoothManager.java +637 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/AppRTCProximitySensor.java +133 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/AppRTCUtils.java +41 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/InCallManagerModule.java +1881 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/InCallProximityManager.java +162 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/InCallWakeLockUtils.java +116 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/ThreadUtils.java +39 -0
- package/app.plugin.js +1 -0
- package/ios/BroadcastEventEmitter.h +11 -0
- package/ios/BroadcastEventEmitter.m +72 -0
- package/ios/Core.h +5 -0
- package/ios/Core.m +28 -0
- package/ios/Core.xcodeproj/project.pbxproj +287 -0
- package/ios/DyteRNBackgroundTimer.h +22 -0
- package/ios/DyteRNBackgroundTimer.m +90 -0
- package/ios/DyteRNPermissionHandlerNotifications.h +17 -0
- package/ios/DyteRNPermissionHandlerNotifications.m +127 -0
- package/ios/DyteRNPermissions.h +50 -0
- package/ios/DyteRNPermissions.m +275 -0
- package/ios/DyteScreensharePickerView.h +8 -0
- package/ios/DyteScreensharePickerView.m +27 -0
- package/ios/PrivacyInfo.xcprivacy +60 -0
- package/ios/RNInCallManager.h +16 -0
- package/ios/RNInCallManager.m +1354 -0
- package/ios/permissions/DyteRNPermissionHandlerBluetoothPeripheral.h +4 -0
- package/ios/permissions/DyteRNPermissionHandlerBluetoothPeripheral.m +87 -0
- package/ios/permissions/DyteRNPermissionHandlerCamera.h +5 -0
- package/ios/permissions/DyteRNPermissionHandlerCamera.m +38 -0
- package/ios/permissions/DyteRNPermissionHandlerMicrophone.h +5 -0
- package/ios/permissions/DyteRNPermissionHandlerMicrophone.m +34 -0
- package/ios/permissions/DyteRNPermissionHandlerPhotoLibrary.h +8 -0
- package/ios/permissions/DyteRNPermissionHandlerPhotoLibrary.m +70 -0
- package/ios/screenshare/DyteDarwinNotificationCenter.swift +21 -0
- package/ios/screenshare/DyteScreenshareAtomic.swift +29 -0
- package/ios/screenshare/DyteScreenshareHandler.swift +103 -0
- package/ios/screenshare/DyteScreenshareUploader.swift +139 -0
- package/ios/screenshare/DyteSocketConnection.swift +190 -0
- package/lib/BackgroundHandler.d.ts +20 -0
- package/lib/BackgroundHandler.js +87 -0
- package/lib/LocalMediaError.d.ts +4 -0
- package/lib/LocalMediaError.js +6 -0
- package/lib/LocalMediaHandler.d.ts +118 -0
- package/lib/LocalMediaHandler.js +853 -0
- package/lib/LocalMediaInterfaces.d.ts +76 -0
- package/lib/LocalMediaInterfaces.js +1 -0
- package/lib/LocalMediaUtils.d.ts +93 -0
- package/lib/LocalMediaUtils.js +276 -0
- package/lib/NativeAudioManager.d.ts +16 -0
- package/lib/NativeAudioManager.js +93 -0
- package/lib/PermissionHandler.d.ts +34 -0
- package/lib/PermissionHandler.js +179 -0
- package/lib/ReactContext.d.ts +42 -0
- package/lib/ReactContext.js +96 -0
- package/lib/ReactHooks.d.ts +11 -0
- package/lib/ReactHooks.js +73 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +40 -0
- package/lib/utils/crypto.d.ts +17 -0
- package/lib/utils/crypto.js +82 -0
- package/package.json +51 -4
- package/plugin/build/withDyte.d.ts +25 -0
- package/plugin/build/withDyte.js +100 -0
- package/plugin/src/withDyte.ts +150 -0
- package/plugin/tsconfig.json +10 -0
- package/plugin/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2017 Henry Lin @zxcpoiu
|
|
3
|
+
*
|
|
4
|
+
* Permission to use, copy, modify, and distribute this software for any
|
|
5
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
6
|
+
* copyright notice and this permission notice appear in all copies.
|
|
7
|
+
*
|
|
8
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
9
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
10
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
11
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
12
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
13
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
14
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
package com.reactnativecore.incallmanager;
|
|
18
|
+
|
|
19
|
+
import android.content.Context;
|
|
20
|
+
import android.hardware.Sensor;
|
|
21
|
+
import android.hardware.SensorManager;
|
|
22
|
+
import android.os.PowerManager;
|
|
23
|
+
import android.os.PowerManager.WakeLock;
|
|
24
|
+
import android.util.Log;
|
|
25
|
+
|
|
26
|
+
import java.lang.reflect.Field;
|
|
27
|
+
import java.lang.reflect.Method;
|
|
28
|
+
import java.lang.Runnable;
|
|
29
|
+
|
|
30
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
31
|
+
|
|
32
|
+
import com.reactnativecore.incallmanager.AppRTCProximitySensor;
|
|
33
|
+
|
|
34
|
+
public class InCallProximityManager {
|
|
35
|
+
private static final String TAG = "dytesdk:InCallProximity";
|
|
36
|
+
|
|
37
|
+
private WakeLock mProximityLock = null;
|
|
38
|
+
private Method mPowerManagerRelease;
|
|
39
|
+
private boolean proximitySupported = false;
|
|
40
|
+
private AppRTCProximitySensor proximitySensor = null;
|
|
41
|
+
|
|
42
|
+
/** Construction */
|
|
43
|
+
static InCallProximityManager create(Context context, final InCallManagerModule inCallManager) {
|
|
44
|
+
return new InCallProximityManager(context, inCallManager);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private InCallProximityManager(Context context, final InCallManagerModule inCallManager) {
|
|
48
|
+
// Log.d(TAG, "InCallProximityManager");
|
|
49
|
+
checkProximitySupport(context);
|
|
50
|
+
if (proximitySupported) {
|
|
51
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
52
|
+
proximitySensor = AppRTCProximitySensor.create(context, () -> {
|
|
53
|
+
inCallManager.onProximitySensorChangedState(proximitySensor.sensorReportsNearState());
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private void checkProximitySupport(Context context) {
|
|
60
|
+
SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
|
61
|
+
if (sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) == null) {
|
|
62
|
+
proximitySupported = false;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
67
|
+
|
|
68
|
+
proximitySupported = true;
|
|
69
|
+
|
|
70
|
+
// --- Check if PROXIMITY_SCREEN_OFF_WAKE_LOCK is implemented.
|
|
71
|
+
try {
|
|
72
|
+
boolean _proximitySupported = false;
|
|
73
|
+
Field field = PowerManager.class.getDeclaredField("PROXIMITY_SCREEN_OFF_WAKE_LOCK");
|
|
74
|
+
int proximityScreenOffWakeLock = (Integer) field.get(null);
|
|
75
|
+
|
|
76
|
+
if (android.os.Build.VERSION.SDK_INT < 17) {
|
|
77
|
+
Method method = powerManager.getClass().getDeclaredMethod("getSupportedWakeLockFlags");
|
|
78
|
+
int powerManagerSupportedFlags = (Integer) method.invoke(powerManager);
|
|
79
|
+
_proximitySupported = ((powerManagerSupportedFlags & proximityScreenOffWakeLock) != 0x0);
|
|
80
|
+
} else {
|
|
81
|
+
// --- android 4.2+
|
|
82
|
+
Method method = powerManager.getClass().getDeclaredMethod("isWakeLockLevelSupported", int.class);
|
|
83
|
+
_proximitySupported = (Boolean) method.invoke(powerManager, proximityScreenOffWakeLock);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (_proximitySupported) {
|
|
87
|
+
mProximityLock = powerManager.newWakeLock(proximityScreenOffWakeLock, TAG);
|
|
88
|
+
mProximityLock.setReferenceCounted(false);
|
|
89
|
+
}
|
|
90
|
+
} catch (Exception e) {
|
|
91
|
+
// Log.d(TAG, "Failed to get proximity screen locker. exception: ", e);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (mProximityLock != null) {
|
|
95
|
+
// Log.d(TAG, "use native screen locker...");
|
|
96
|
+
try {
|
|
97
|
+
mPowerManagerRelease = mProximityLock.getClass().getDeclaredMethod("release", int.class);
|
|
98
|
+
} catch (Exception e) {
|
|
99
|
+
// Log.d(TAG, "failed to get proximity screen locker: `release()`. exception: ", e);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
// Log.d(TAG, "fallback to old school screen locker...");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public boolean start() {
|
|
107
|
+
if (!proximitySupported) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
111
|
+
proximitySensor.start();
|
|
112
|
+
});
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public void stop() {
|
|
117
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
118
|
+
proximitySensor.stop();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public boolean isProximitySupported() {
|
|
123
|
+
return proximitySupported;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public boolean isProximityWakeLockSupported() {
|
|
127
|
+
return mProximityLock != null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public boolean getProximityIsNear() {
|
|
131
|
+
return (proximitySupported) ? proximitySensor.sensorReportsNearState() : false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public void acquireProximityWakeLock() {
|
|
135
|
+
if (!isProximityWakeLockSupported()) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
synchronized (mProximityLock) {
|
|
139
|
+
if (!mProximityLock.isHeld()) {
|
|
140
|
+
// Log.d(TAG, "acquireProximityWakeLock()");
|
|
141
|
+
mProximityLock.acquire();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public void releaseProximityWakeLock(final boolean waitForNoProximity) {
|
|
147
|
+
if (!isProximityWakeLockSupported()) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
synchronized (mProximityLock) {
|
|
151
|
+
if (mProximityLock.isHeld()) {
|
|
152
|
+
try {
|
|
153
|
+
int flags = waitForNoProximity ? PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY : 0;
|
|
154
|
+
mPowerManagerRelease.invoke(mProximityLock, flags);
|
|
155
|
+
// Log.d(TAG, "releaseProximityWakeLock()");
|
|
156
|
+
} catch (Exception e) {
|
|
157
|
+
// Log.e(TAG, "failed to release proximity lock. e: ", e);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2017 Henry Lin @zxcpoiu
|
|
3
|
+
*
|
|
4
|
+
* Permission to use, copy, modify, and distribute this software for any
|
|
5
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
6
|
+
* copyright notice and this permission notice appear in all copies.
|
|
7
|
+
*
|
|
8
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
9
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
10
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
11
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
12
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
13
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
14
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
package com.reactnativecore.incallmanager;
|
|
18
|
+
|
|
19
|
+
import android.content.Context;
|
|
20
|
+
import android.os.PowerManager;
|
|
21
|
+
import android.os.PowerManager.WakeLock;
|
|
22
|
+
import android.util.Log;
|
|
23
|
+
|
|
24
|
+
public class InCallWakeLockUtils {
|
|
25
|
+
private static final String TAG = "dytesdk:InCallWakeLock";
|
|
26
|
+
|
|
27
|
+
private PowerManager mPowerManager;
|
|
28
|
+
|
|
29
|
+
private WakeLock mFullLock = null;
|
|
30
|
+
private WakeLock mPokeFullLock = null;
|
|
31
|
+
private WakeLock mPartialLock = null;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
public InCallWakeLockUtils(Context context) {
|
|
35
|
+
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
36
|
+
|
|
37
|
+
mFullLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, TAG);
|
|
38
|
+
mFullLock.setReferenceCounted(false);
|
|
39
|
+
|
|
40
|
+
mPartialLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
|
41
|
+
mPartialLock.setReferenceCounted(false);
|
|
42
|
+
|
|
43
|
+
mPokeFullLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, TAG);
|
|
44
|
+
mPokeFullLock.setReferenceCounted(false);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private boolean _acquireWakeLock(WakeLock lock) {
|
|
48
|
+
return _acquireWakeLock(lock, 0);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private boolean _acquireWakeLock(WakeLock lock, long timeout) {
|
|
52
|
+
synchronized (lock) {
|
|
53
|
+
if (!lock.isHeld()) {
|
|
54
|
+
if (timeout > 0) {
|
|
55
|
+
lock.acquire(timeout);
|
|
56
|
+
} else {
|
|
57
|
+
lock.acquire();
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private boolean _releaseWakeLock(WakeLock lock) {
|
|
66
|
+
synchronized (lock) {
|
|
67
|
+
if (lock.isHeld()) {
|
|
68
|
+
lock.release();
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public boolean acquireFullWakeLock() {
|
|
76
|
+
boolean sta = _acquireWakeLock(mFullLock);
|
|
77
|
+
// Log.d(TAG, "acquireFullWakeLock(). sta=" + sta);
|
|
78
|
+
return sta;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public boolean releaseFullWakeLock() {
|
|
82
|
+
boolean sta = _releaseWakeLock(mFullLock);
|
|
83
|
+
// Log.d(TAG, "releaseFullWakeLock(). sta=" + sta);
|
|
84
|
+
return sta;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public boolean acquirePokeFullWakeLock() {
|
|
88
|
+
boolean sta = _acquireWakeLock(mPokeFullLock);
|
|
89
|
+
// Log.d(TAG, "acquirePokeFullWakeLock(). sta=" + sta);
|
|
90
|
+
return sta;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public boolean releasePokeFullWakeLock() {
|
|
94
|
+
boolean sta = _releaseWakeLock(mPokeFullLock);
|
|
95
|
+
// Log.d(TAG, "releasePokeFullWakeLock(). sta=" + sta);
|
|
96
|
+
return sta;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public boolean acquirePartialWakeLock() {
|
|
100
|
+
boolean sta = _acquireWakeLock(mPartialLock);
|
|
101
|
+
// Log.d(TAG, "acquirePartialWakeLock(). sta=" + sta);
|
|
102
|
+
return sta;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public boolean releasePartialWakeLock() {
|
|
106
|
+
boolean sta = _releaseWakeLock(mPartialLock);
|
|
107
|
+
// Log.d(TAG, "releasePartialWakeLock(). sta=" + sta);
|
|
108
|
+
return sta;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public boolean acquirePokeFullWakeLockReleaseAfter(long timeout) {
|
|
112
|
+
boolean sta = _acquireWakeLock(mPokeFullLock, timeout);
|
|
113
|
+
// Log.d(TAG, String.format("acquirePokeFullWakeLockReleaseAfter() timeout=%s, sta=%s", timeout, sta));
|
|
114
|
+
return sta;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed by a BSD-style license
|
|
5
|
+
* that can be found in the LICENSE file in the root of the source
|
|
6
|
+
* tree. An additional intellectual property rights grant can be found
|
|
7
|
+
* in the file PATENTS. All contributing project authors may
|
|
8
|
+
* be found in the AUTHORS file in the root of the source tree.
|
|
9
|
+
*/
|
|
10
|
+
package com.reactnativecore.incallmanager;
|
|
11
|
+
import android.os.Looper;
|
|
12
|
+
import androidx.annotation.Nullable;
|
|
13
|
+
public class ThreadUtils {
|
|
14
|
+
/**
|
|
15
|
+
* Utility class to be used for checking that a method is called on the correct thread.
|
|
16
|
+
*/
|
|
17
|
+
public static class ThreadChecker {
|
|
18
|
+
@Nullable private Thread thread = Thread.currentThread();
|
|
19
|
+
public void checkIsOnValidThread() {
|
|
20
|
+
if (thread == null) {
|
|
21
|
+
thread = Thread.currentThread();
|
|
22
|
+
}
|
|
23
|
+
if (Thread.currentThread() != thread) {
|
|
24
|
+
throw new IllegalStateException("Wrong thread");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
public void detachThread() {
|
|
28
|
+
thread = null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Throws exception if called from other than main thread.
|
|
33
|
+
*/
|
|
34
|
+
public static void checkIsOnMainThread() {
|
|
35
|
+
if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
|
|
36
|
+
throw new IllegalStateException("Not on main thread!");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./plugin/build/withDyte');
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#import "BroadcastEventEmitter.h"
|
|
2
|
+
#import <React/RCTLog.h>
|
|
3
|
+
|
|
4
|
+
// Define the notification names
|
|
5
|
+
NSString *const BroadcastStartedNotification = @"iOS_BroadcastStarted";
|
|
6
|
+
NSString *const BroadcastStoppedNotification = @"iOS_BroadcastStopped";
|
|
7
|
+
|
|
8
|
+
@implementation BroadcastEventEmitter
|
|
9
|
+
|
|
10
|
+
RCT_EXPORT_MODULE();
|
|
11
|
+
|
|
12
|
+
- (instancetype)init {
|
|
13
|
+
self = [super init];
|
|
14
|
+
if (self) {
|
|
15
|
+
// Listen for the broadcast started notification
|
|
16
|
+
CFNotificationCenterAddObserver(
|
|
17
|
+
CFNotificationCenterGetDarwinNotifyCenter(),
|
|
18
|
+
(__bridge const void *)(self),
|
|
19
|
+
broadcastEventCallback,
|
|
20
|
+
(__bridge CFStringRef)BroadcastStartedNotification,
|
|
21
|
+
NULL,
|
|
22
|
+
CFNotificationSuspensionBehaviorDeliverImmediately
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// Listen for the broadcast stopped notification
|
|
26
|
+
CFNotificationCenterAddObserver(
|
|
27
|
+
CFNotificationCenterGetDarwinNotifyCenter(),
|
|
28
|
+
(__bridge const void *)(self),
|
|
29
|
+
broadcastEventCallback,
|
|
30
|
+
(__bridge CFStringRef)BroadcastStoppedNotification,
|
|
31
|
+
NULL,
|
|
32
|
+
CFNotificationSuspensionBehaviorDeliverImmediately
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return self;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Callback for Darwin notifications
|
|
39
|
+
void broadcastEventCallback(CFNotificationCenterRef center,
|
|
40
|
+
void *observer,
|
|
41
|
+
CFNotificationName name,
|
|
42
|
+
const void *object,
|
|
43
|
+
CFDictionaryRef userInfo) {
|
|
44
|
+
BroadcastEventEmitter *eventEmitter = (__bridge BroadcastEventEmitter *)observer;
|
|
45
|
+
[eventEmitter handleNotification:name];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Handle incoming notifications and send events to React Native
|
|
49
|
+
- (void)handleNotification:(CFNotificationName)name {
|
|
50
|
+
NSString *eventName = (__bridge NSString *)name;
|
|
51
|
+
[self sendEventWithName:eventName body:nil];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Declare the supported event names
|
|
55
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
56
|
+
return @[BroadcastStartedNotification, BroadcastStoppedNotification];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Ensure setup happens on the main queue
|
|
60
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
61
|
+
return YES;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Remove observers on deallocation
|
|
65
|
+
- (void)dealloc {
|
|
66
|
+
CFNotificationCenterRemoveEveryObserver(
|
|
67
|
+
CFNotificationCenterGetDarwinNotifyCenter(),
|
|
68
|
+
(__bridge const void *)(self)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@end
|
package/ios/Core.h
ADDED
package/ios/Core.m
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#import "Core.h"
|
|
2
|
+
|
|
3
|
+
@implementation Core
|
|
4
|
+
|
|
5
|
+
RCT_EXPORT_MODULE()
|
|
6
|
+
|
|
7
|
+
// Example method
|
|
8
|
+
// See // https://reactnative.dev/docs/native-modules-ios
|
|
9
|
+
RCT_REMAP_METHOD(multiply,
|
|
10
|
+
multiplyWithA:(nonnull NSNumber*)a withB:(nonnull NSNumber*)b
|
|
11
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
12
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
13
|
+
{
|
|
14
|
+
NSNumber *result = @([a floatValue] * [b floatValue]);
|
|
15
|
+
|
|
16
|
+
resolve(result);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString*, getRandomBase64:(NSUInteger)byteLength) {
|
|
20
|
+
NSMutableData *data = [NSMutableData dataWithLength:byteLength];
|
|
21
|
+
int result = SecRandomCopyBytes(kSecRandomDefault, byteLength, data.mutableBytes);
|
|
22
|
+
if (result != errSecSuccess) {
|
|
23
|
+
@throw([NSException exceptionWithName:@"NO_RANDOM_BYTES" reason:@"Failed to aquire secure random bytes" userInfo:nil]);
|
|
24
|
+
}
|
|
25
|
+
return [data base64EncodedStringWithOptions:0];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@end
|