@cloudflare/realtimekit-react-native 0.1.2-staging.5 → 0.1.2-staging.7
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/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/reactnativecore/DyteHelperModule.java +1 -0
- package/android/src/main/java/com/reactnativecore/ForegroundService.java +1 -1
- package/android/src/main/java/com/reactnativecore/NotificationHelper.java +11 -12
- package/lib/LocalMediaHandler.d.ts +1 -0
- package/lib/LocalMediaHandler.js +49 -12
- package/lib/LocalMediaUtils.js +0 -1
- package/package.json +2 -2
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30"/>
|
|
7
7
|
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
|
|
8
8
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
|
|
9
|
+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
|
9
10
|
<uses-permission android:name="android.permission.CAMERA"/>
|
|
10
11
|
<uses-permission android:name="android.permission.INTERNET"/>
|
|
11
12
|
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
|
|
@@ -134,6 +134,7 @@ public class DyteHelperModule extends ReactContextBaseJavaModule {
|
|
|
134
134
|
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
|
135
135
|
if ((ForegroundService.class).getName().equals(service.service.getClassName())) {
|
|
136
136
|
promise.resolve(true);
|
|
137
|
+
return;
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
promise.resolve(false);
|
|
@@ -28,7 +28,7 @@ public class ForegroundService extends Service {
|
|
|
28
28
|
if (notification != null) {
|
|
29
29
|
try {
|
|
30
30
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
31
|
-
startForeground(notificationHelper.NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
|
|
31
|
+
startForeground(notificationHelper.NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION);
|
|
32
32
|
} else {
|
|
33
33
|
startForeground(notificationHelper.NOTIFICATION_ID, notification);
|
|
34
34
|
}
|
|
@@ -22,9 +22,9 @@ import java.util.Random;
|
|
|
22
22
|
|
|
23
23
|
class NotificationHelper {
|
|
24
24
|
public static final int NOTIFICATION_ID = new Random().nextInt(99999) + 10000;
|
|
25
|
-
private static final String CHANNEL_ID = "
|
|
26
|
-
private static final String CHANNEL_NAME = "
|
|
27
|
-
private static final String CHANNEL_DESC = "
|
|
25
|
+
private static final String CHANNEL_ID = "RealtimeKitNotificationChannel";
|
|
26
|
+
private static final String CHANNEL_NAME = "Screen Sharing";
|
|
27
|
+
private static final String CHANNEL_DESC = "Screen Sharing";
|
|
28
28
|
|
|
29
29
|
private static NotificationHelper instance = null;
|
|
30
30
|
private NotificationManager mNotificationManager;
|
|
@@ -83,18 +83,17 @@ class NotificationHelper {
|
|
|
83
83
|
|
|
84
84
|
builder
|
|
85
85
|
.setCategory(NotificationCompat.CATEGORY_CALL)
|
|
86
|
-
.setContentTitle("
|
|
87
|
-
.setContentText("
|
|
88
|
-
.setPriority(NotificationCompat.
|
|
86
|
+
.setContentTitle("Screen Share")
|
|
87
|
+
.setContentText("You are sharing your screen")
|
|
88
|
+
.setPriority(NotificationCompat.PRIORITY_LOW)
|
|
89
89
|
.setContentIntent(pendingIntent)
|
|
90
|
-
.setOngoing(
|
|
91
|
-
.
|
|
92
|
-
.
|
|
93
|
-
.setAutoCancel(false)
|
|
90
|
+
.setOngoing(false)
|
|
91
|
+
.setUsesChronometer(false)
|
|
92
|
+
.setAutoCancel(true)
|
|
94
93
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
95
94
|
.setOnlyAlertOnce(true)
|
|
96
|
-
.setSmallIcon(appIconResId)
|
|
97
|
-
|
|
95
|
+
.setSmallIcon(appIconResId)
|
|
96
|
+
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE);
|
|
98
97
|
if(largeIcon != null){
|
|
99
98
|
builder.setLargeIcon(largeIcon);
|
|
100
99
|
}
|
package/lib/LocalMediaHandler.js
CHANGED
|
@@ -22,7 +22,7 @@ var _LocalMediaHandler_localMediaUtils, _LocalMediaHandler_appState, _LocalMedia
|
|
|
22
22
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
23
23
|
import { EventEmitter } from 'events';
|
|
24
24
|
import LocalMediaUtils from './LocalMediaUtils';
|
|
25
|
-
import { AppState, NativeEventEmitter, NativeModules, Platform, } from 'react-native';
|
|
25
|
+
import { AppState, NativeEventEmitter, NativeModules, PermissionsAndroid, Platform, } from 'react-native';
|
|
26
26
|
import BackgroundTimer from './BackgroundHandler';
|
|
27
27
|
import InCallManger from './NativeAudioManager';
|
|
28
28
|
import { setupPermissions } from './PermissionHandler';
|
|
@@ -47,12 +47,26 @@ function checkIfAudioTrackIsSilent(track) {
|
|
|
47
47
|
class LocalMediaHandler extends EventEmitter {
|
|
48
48
|
configureForeground() {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (Platform.OS !== 'android')
|
|
51
|
+
return;
|
|
50
52
|
const val = yield DyteHelper.isForegroundServiceRunning();
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
+
if (!val) {
|
|
54
|
+
if (Platform.Version >= 33) {
|
|
55
|
+
const res = yield PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
|
|
56
|
+
if (res !== PermissionsAndroid.RESULTS.GRANTED) {
|
|
57
|
+
console.warn('Permission required for screenshare notification');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (Platform.Version >= 26) {
|
|
61
|
+
yield DyteHelper.createNotificationChannel();
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
yield DyteHelper.startService();
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
console.warn('Failed to start foreground service', e);
|
|
68
|
+
}
|
|
53
69
|
}
|
|
54
|
-
if (!val)
|
|
55
|
-
yield DyteHelper.startService();
|
|
56
70
|
});
|
|
57
71
|
}
|
|
58
72
|
constructor(localMediaUtils) {
|
|
@@ -61,6 +75,7 @@ class LocalMediaHandler extends EventEmitter {
|
|
|
61
75
|
_LocalMediaHandler_appState.set(this, void 0);
|
|
62
76
|
_LocalMediaHandler_appStateSubscription.set(this, void 0);
|
|
63
77
|
_LocalMediaHandler_interval.set(this, void 0);
|
|
78
|
+
this._pendingScreenShare = false;
|
|
64
79
|
this._handleAppStateChange = (nextAppState) => {
|
|
65
80
|
// console.log('App state changed to : ', nextAppState);
|
|
66
81
|
if (__classPrivateFieldGet(this, _LocalMediaHandler_appState, "f").match(/inactive|background/) &&
|
|
@@ -78,7 +93,9 @@ class LocalMediaHandler extends EventEmitter {
|
|
|
78
93
|
}
|
|
79
94
|
else {
|
|
80
95
|
if (__classPrivateFieldGet(this, _LocalMediaHandler_interval, "f") === null) {
|
|
81
|
-
this.
|
|
96
|
+
if (this.screenShareEnabled || this._pendingScreenShare) {
|
|
97
|
+
this.configureForeground();
|
|
98
|
+
}
|
|
82
99
|
}
|
|
83
100
|
__classPrivateFieldSet(this, _LocalMediaHandler_interval, BackgroundTimer.setInterval(() => { }, 1000), "f");
|
|
84
101
|
__classPrivateFieldSet(this, _LocalMediaHandler_appState, nextAppState, "f");
|
|
@@ -706,6 +723,12 @@ class LocalMediaHandler extends EventEmitter {
|
|
|
706
723
|
return __awaiter(this, void 0, void 0, function* () {
|
|
707
724
|
if (this.screenShareEnabled && Platform.OS !== 'ios') {
|
|
708
725
|
this.removeScreenShareTracks();
|
|
726
|
+
try {
|
|
727
|
+
yield DyteHelper.stopService();
|
|
728
|
+
}
|
|
729
|
+
catch (e) {
|
|
730
|
+
console.warn('Failed to stop foreground service', e);
|
|
731
|
+
}
|
|
709
732
|
return;
|
|
710
733
|
}
|
|
711
734
|
if (Platform.OS === 'ios' && this.screenShareEnabled) {
|
|
@@ -713,13 +736,21 @@ class LocalMediaHandler extends EventEmitter {
|
|
|
713
736
|
return;
|
|
714
737
|
}
|
|
715
738
|
if (Platform.OS === 'android') {
|
|
716
|
-
|
|
717
|
-
This is because we need to get user permission starting foreground service in Android >=14
|
|
718
|
-
1. createScreenCaptureIntent() -> startForeground()
|
|
719
|
-
*/
|
|
720
|
-
this.setScreenShareTracks(yield LocalMediaUtils.getScreenShareTracks());
|
|
739
|
+
this._pendingScreenShare = true;
|
|
721
740
|
yield this.configureForeground();
|
|
722
|
-
|
|
741
|
+
try {
|
|
742
|
+
this.setScreenShareTracks(yield LocalMediaUtils.getScreenShareTracks());
|
|
743
|
+
this.screenShareEnabled = true;
|
|
744
|
+
}
|
|
745
|
+
catch (e) {
|
|
746
|
+
console.warn('Failed to start screenshare', e);
|
|
747
|
+
this.screenShareEnabled = false;
|
|
748
|
+
yield DyteHelper.stopService();
|
|
749
|
+
this._pendingScreenShare = false;
|
|
750
|
+
}
|
|
751
|
+
finally {
|
|
752
|
+
this._pendingScreenShare = false;
|
|
753
|
+
}
|
|
723
754
|
}
|
|
724
755
|
if (Platform.OS === 'ios') {
|
|
725
756
|
NativeModules.DyteScreensharePickerView.showScreenSharePickerView();
|
|
@@ -824,6 +855,12 @@ class LocalMediaHandler extends EventEmitter {
|
|
|
824
855
|
destructMediaHandler() {
|
|
825
856
|
return __awaiter(this, void 0, void 0, function* () {
|
|
826
857
|
__classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").destruct();
|
|
858
|
+
try {
|
|
859
|
+
yield DyteHelper.stopService();
|
|
860
|
+
}
|
|
861
|
+
catch (e) {
|
|
862
|
+
console.warn('Failed to stop foreground service', e);
|
|
863
|
+
}
|
|
827
864
|
return this.destruct();
|
|
828
865
|
});
|
|
829
866
|
}
|
package/lib/LocalMediaUtils.js
CHANGED
|
@@ -178,7 +178,6 @@ class LocalMediaUtils {
|
|
|
178
178
|
* is made: https://github.com/microsoft/TypeScript/issues/33232
|
|
179
179
|
*/
|
|
180
180
|
const stream = (yield mediaDevices.getDisplayMedia());
|
|
181
|
-
// console.log('Screenshare stream: ', stream.getVideoTracks());
|
|
182
181
|
return {
|
|
183
182
|
video: stream.getVideoTracks()[0],
|
|
184
183
|
audio: stream.getAudioTracks()[0],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/realtimekit-react-native",
|
|
3
|
-
"version": "0.1.2-staging.
|
|
3
|
+
"version": "0.1.2-staging.7",
|
|
4
4
|
"description": "Cloudflare RealtimeKit SDK for react native",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Cloudflare",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"android"
|
|
39
39
|
],
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@cloudflare/react-native-webrtc": "~114.0.
|
|
41
|
+
"@cloudflare/react-native-webrtc": "~114.0.18",
|
|
42
42
|
"@expo/config-plugins": "*",
|
|
43
43
|
"react": "*",
|
|
44
44
|
"react-native": "*"
|