@cloudflare/realtimekit-react-native 0.1.2-staging.4 → 0.1.2-staging.6

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.
@@ -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 | ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA | ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE);
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 = "DyteNotificationChannel";
26
- private static final String CHANNEL_NAME = "Ongoing Conference Notifications";
27
- private static final String CHANNEL_DESC = "Ongoing Conference Notifications";
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("Ongoing Meeting")
87
- .setContentText("Tap to return to the meeting")
88
- .setPriority(NotificationCompat.PRIORITY_DEFAULT)
86
+ .setContentTitle("Screen Share")
87
+ .setContentText("You are sharing your screen")
88
+ .setPriority(NotificationCompat.PRIORITY_LOW)
89
89
  .setContentIntent(pendingIntent)
90
- .setOngoing(true)
91
- .setWhen(System.currentTimeMillis())
92
- .setUsesChronometer(true)
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
  }
@@ -119,6 +119,7 @@ export default class LocalMediaHandler extends EventEmitter {
119
119
  static init(_: any): Promise<LocalMediaHandler>;
120
120
  emit(event: keyof typeof MediaEvents, ...args: any[]): boolean;
121
121
  on(event: keyof typeof MediaEvents, listener: (...args: any[]) => void): this;
122
+ removeAllListeners(event?: keyof typeof MediaEvents): this;
122
123
  }
123
124
  export interface RNLocalMediaHandler {
124
125
  new (): LocalMediaHandler;
@@ -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 (Platform.Version >= 26) {
52
- yield DyteHelper.createNotificationChannel();
53
+ if (!val) {
54
+ if (Platform.Version >= 26) {
55
+ yield DyteHelper.createNotificationChannel();
56
+ }
57
+ if (Platform.Version >= 33) {
58
+ const res = yield PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
59
+ if (res !== PermissionsAndroid.RESULTS.GRANTED) {
60
+ console.warn('Permission required for screenshare notification');
61
+ }
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) {
@@ -706,6 +720,12 @@ class LocalMediaHandler extends EventEmitter {
706
720
  return __awaiter(this, void 0, void 0, function* () {
707
721
  if (this.screenShareEnabled && Platform.OS !== 'ios') {
708
722
  this.removeScreenShareTracks();
723
+ try {
724
+ yield DyteHelper.stopService();
725
+ }
726
+ catch (e) {
727
+ console.warn('Failed to stop foreground service', e);
728
+ }
709
729
  return;
710
730
  }
711
731
  if (Platform.OS === 'ios' && this.screenShareEnabled) {
@@ -713,13 +733,16 @@ class LocalMediaHandler extends EventEmitter {
713
733
  return;
714
734
  }
715
735
  if (Platform.OS === 'android') {
716
- /* getDisplayMedia() needs to be called before configureForeground()
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());
721
736
  yield this.configureForeground();
722
- this.screenShareEnabled = true;
737
+ try {
738
+ this.setScreenShareTracks(yield LocalMediaUtils.getScreenShareTracks());
739
+ this.screenShareEnabled = true;
740
+ }
741
+ catch (e) {
742
+ console.warn('Failed to start screenshare', e);
743
+ this.screenShareEnabled = false;
744
+ yield DyteHelper.stopService();
745
+ }
723
746
  }
724
747
  if (Platform.OS === 'ios') {
725
748
  NativeModules.DyteScreensharePickerView.showScreenSharePickerView();
@@ -824,6 +847,12 @@ class LocalMediaHandler extends EventEmitter {
824
847
  destructMediaHandler() {
825
848
  return __awaiter(this, void 0, void 0, function* () {
826
849
  __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").destruct();
850
+ try {
851
+ yield DyteHelper.stopService();
852
+ }
853
+ catch (e) {
854
+ console.warn('Failed to stop foreground service', e);
855
+ }
827
856
  return this.destruct();
828
857
  });
829
858
  }
@@ -839,6 +868,12 @@ class LocalMediaHandler extends EventEmitter {
839
868
  on(event, listener) {
840
869
  return super.on(event, listener);
841
870
  }
871
+ removeAllListeners(event) {
872
+ if (event === 'SCREENSHARE_TRACK_CHANGE' || !event) {
873
+ return null;
874
+ }
875
+ return super.removeAllListeners(event);
876
+ }
842
877
  }
843
878
  _LocalMediaHandler_localMediaUtils = new WeakMap(), _LocalMediaHandler_appState = new WeakMap(), _LocalMediaHandler_appStateSubscription = new WeakMap(), _LocalMediaHandler_interval = new WeakMap();
844
879
  export default LocalMediaHandler;
@@ -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.4",
3
+ "version": "0.1.2-staging.6",
4
4
  "description": "Cloudflare RealtimeKit SDK for react native",
5
5
  "main": "lib/index.js",
6
6
  "author": "Cloudflare",