@cloudflare/realtimekit-react-native 0.1.2-staging.10 → 0.1.2-staging.11

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.
@@ -181,8 +181,7 @@ RCT_EXPORT_METHOD(chooseAudioRoute: (NSString *)audioRoute Promise:(RCTPromiseR
181
181
  if (![_userSelectedAudioRoute isEqualToString:_currentAudioRoute]) {
182
182
  if ([audioRoute isEqual: @"SPEAKER_PHONE"] || [audioRoute isEqualToString:@"speaker"]) {
183
183
  _forceSpeakerOn = 1;
184
- [self updateAudioRoute];
185
- success = true;
184
+ success = [self routeAudioFromSpeakerphone];
186
185
  } else if ([audioRoute isEqualToString:@"WIRED_HEADSET"] || [audioRoute isEqualToString:@"wired"]) {
187
186
  _forceSpeakerOn = 0;
188
187
  success = [self routeAudioFromEarpiece];
@@ -286,8 +285,19 @@ RCT_EXPORT_METHOD(setSpeakerphoneOn:(BOOL)enable)
286
285
  }
287
286
 
288
287
  - (BOOL)routeAudioFromBluetooth {
288
+ BOOL success;
289
289
  NSError *error = nil;
290
290
  _audioSession = [AVAudioSession sharedInstance];
291
+ success = [_audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
292
+ withOptions:AVAudioSessionCategoryOptionAllowBluetooth
293
+ error:&error];
294
+ if (!success) {
295
+ NSLog(@"📕 Cannot set category due to error: %@", error);
296
+ }
297
+ success = [_audioSession setMode:AVAudioSessionModeVoiceChat error: &error];
298
+ if (!success) {
299
+ NSLog(@"📕 Cannot set mode due to error: %@", error);
300
+ }
291
301
  for (AVAudioSessionPortDescription* input in [_audioSession availableInputs]) {
292
302
  if ([[input portType] isEqualToString:AVAudioSessionPortBluetoothHFP] ||
293
303
  [[input portType] isEqualToString:AVAudioSessionPortBluetoothA2DP] ||
@@ -351,7 +361,7 @@ RCT_EXPORT_METHOD(setSpeakerphoneOn:(BOOL)enable)
351
361
  @try {
352
362
  success = [_audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
353
363
  withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
354
- error:nil];
364
+ error:&error];
355
365
  if (!success) {
356
366
  NSLog(@"📕 Cannot set category due to error: %@", error);
357
367
  }
@@ -639,11 +649,6 @@ RCT_EXPORT_METHOD(isBluetoothHeadsetConnected: (RCTPromiseResolveBlock) resolve
639
649
  [self audioSessionSetMode:audioMode
640
650
  callerMemo:NSStringFromSelector(_cmd)];
641
651
 
642
- @try {
643
- [self sendEventWithName:@"onAudioDeviceChanged" body:@{@"devices": audioMode}];
644
- } @catch (NSException *exception) {
645
- NSLog(@"Error sending event 'onAudioDeviceChanged': %@", exception.reason);
646
- }
647
652
  // NSLog(@"👨‍💻 RNInCallManager.updateAudioRoute() audio mode has changed to %@", audioMode);
648
653
  return true;
649
654
  } else {
@@ -962,60 +967,63 @@ RCT_EXPORT_METHOD(isBluetoothHeadsetConnected: (RCTPromiseResolveBlock) resolve
962
967
  // NSLog(@"🧑‍💻 RNInCallManager.AudioRouteChange.Reason: NewDeviceAvailable");
963
968
  if ([self checkAudioRoute:@[AVAudioSessionPortHeadsetMic]
964
969
  routeType:@"input"]) {
965
- _forceSpeakerOn = 0;
970
+ self->_forceSpeakerOn = 0;
966
971
  @try {
967
972
  [self sendEventWithName:@"onAudioDeviceChanged"
968
973
  body:@{
969
974
  @"availableAudioDeviceList": @"[speaker, earpiece, wired]",
970
- @"selectedAudioDevice": AVAudioSessionPortHeadsetMic,
975
+ @"selectedAudioDevice": @"wired",
971
976
  }];
972
977
  } @catch (NSException *exception) {
973
978
  NSLog(@"Error sending event 'onAudioDeviceChanged' (HeadsetMic): %@", exception.reason);
974
979
  }
975
980
  } else if ([self checkAudioRoute:@[AVAudioSessionPortHeadphones]
976
981
  routeType:@"output"]) {
977
- _forceSpeakerOn = 0;
982
+ self->_forceSpeakerOn = 0;
978
983
  @try {
979
984
  [self sendEventWithName:@"onAudioDeviceChanged"
980
985
  body:@{
981
986
  @"availableAudioDeviceList": @"[speaker, earpiece, wired]",
982
- @"selectedAudioDevice": AVAudioSessionPortHeadphones,
987
+ @"selectedAudioDevice": @"wired",
983
988
  }];
984
989
  } @catch (NSException *exception) {
985
990
  NSLog(@"Error sending event 'onAudioDeviceChanged' (Headphones): %@", exception.reason);
986
991
  }
987
992
  } else if ([self checkAudioRoute:@[AVAudioSessionPortBluetoothHFP]
988
993
  routeType:@"input"]) {
989
- _forceSpeakerOn = 0;
994
+ self->_forceSpeakerOn = 0;
995
+ [self routeAudioFromBluetooth];
990
996
  @try {
991
997
  [self sendEventWithName:@"onAudioDeviceChanged"
992
998
  body:@{
993
999
  @"availableAudioDeviceList": @"[speaker, earpiece, bluetooth]",
994
- @"selectedAudioDevice": AVAudioSessionPortBluetoothHFP,
1000
+ @"selectedAudioDevice": @"bluetooth",
995
1001
  }];
996
1002
  } @catch (NSException *exception) {
997
1003
  NSLog(@"Error sending event 'onAudioDeviceChanged' (BluetoothHFP): %@", exception.reason);
998
1004
  }
999
1005
  } else if ([self checkAudioRoute:@[AVAudioSessionPortBluetoothA2DP]
1000
1006
  routeType:@"input"]) {
1001
- _forceSpeakerOn = 0;
1007
+ self->_forceSpeakerOn = 0;
1008
+ [self routeAudioFromBluetooth];
1002
1009
  @try {
1003
1010
  [self sendEventWithName:@"onAudioDeviceChanged"
1004
1011
  body:@{
1005
1012
  @"availableAudioDeviceList": @"[speaker, earpiece, bluetooth]",
1006
- @"selectedAudioDevice": AVAudioSessionPortBluetoothA2DP,
1013
+ @"selectedAudioDevice": @"bluetooth",
1007
1014
  }];
1008
1015
  } @catch (NSException *exception) {
1009
1016
  NSLog(@"Error sending event 'onAudioDeviceChanged' (BluetoothA2DP): %@", exception.reason);
1010
1017
  }
1011
1018
  } else if ([self checkAudioRoute:@[AVAudioSessionPortBluetoothLE]
1012
1019
  routeType:@"input"]) {
1013
- _forceSpeakerOn = 0;
1020
+ self->_forceSpeakerOn = 0;
1021
+ [self routeAudioFromBluetooth];
1014
1022
  @try {
1015
1023
  [self sendEventWithName:@"onAudioDeviceChanged"
1016
1024
  body:@{
1017
1025
  @"availableAudioDeviceList": @"[speaker, earpiece, bluetooth]",
1018
- @"selectedAudioDevice": AVAudioSessionPortBluetoothLE,
1026
+ @"selectedAudioDevice": @"bluetooth",
1019
1027
  }];
1020
1028
  } @catch (NSException *exception) {
1021
1029
  NSLog(@"Error sending event 'onAudioDeviceChanged' (BluetoothLE): %@", exception.reason);
@@ -112,14 +112,11 @@ export default class LocalMediaHandler extends EventEmitter {
112
112
  on(event: keyof typeof MediaEvents, listener: (...args: any[]) => void): this;
113
113
  destruct(): void;
114
114
  destructMediaHandler(): Promise<void>;
115
- cleanUpTracks(): void;
116
- destructor(): void;
117
115
  removeAllTracks(): void;
118
116
  private stopAudioTrack;
119
117
  removeAudioTrack(): void;
120
118
  private stopVideoTrack;
121
119
  removeVideoTrack(): void;
122
- removeAllListeners(event?: keyof typeof MediaEvents): this;
123
120
  }
124
121
  export interface RNLocalMediaHandler {
125
122
  new (): LocalMediaHandler;
@@ -805,45 +805,37 @@ class LocalMediaHandler extends EventEmitter {
805
805
  return super.on(event, listener);
806
806
  }
807
807
  destruct() {
808
- this.destructMediaHandler();
808
+ // TODO: Do not remove native broadcast listeners when going OFF_STAGE in webinar
809
+ // this.#localMediaUtils.destruct();
810
+ if (Platform.OS === 'android')
811
+ __classPrivateFieldGet(this, _LocalMediaHandler_appStateSubscription, "f").remove();
812
+ BackgroundTimer.stop();
813
+ try {
814
+ if (Platform.OS === 'android')
815
+ DyteHelper.stopService();
816
+ }
817
+ catch (_err) { }
818
+ InCallManger.stop(undefined);
819
+ // NOTE: This is a no-op, it's functions are handled in web-core
820
+ // this.destructMediaHandler();
809
821
  }
810
822
  destructMediaHandler() {
811
823
  return __awaiter(this, void 0, void 0, function* () {
812
824
  this.removeAllTracks();
813
825
  this.removeAllListeners();
814
- this.cleanUpTracks();
815
- __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").destruct();
816
- try {
817
- if (Platform.OS === 'android')
818
- yield DyteHelper.stopService();
819
- }
820
- catch (_err) { }
821
- InCallManger.stop(undefined);
822
826
  });
823
827
  }
824
- cleanUpTracks() {
825
- var _a, _b, _c, _d;
826
- (_a = this.audioTrack) === null || _a === void 0 ? void 0 : _a.stop();
827
- (_b = this.rawAudioTrack) === null || _b === void 0 ? void 0 : _b.stop();
828
- (_c = this.videoTrack) === null || _c === void 0 ? void 0 : _c.stop();
829
- (_d = this.rawVideoTrack) === null || _d === void 0 ? void 0 : _d.stop();
830
- this.destructor();
831
- }
832
- destructor() {
833
- if (Platform.OS === 'android')
834
- __classPrivateFieldGet(this, _LocalMediaHandler_appStateSubscription, "f").remove();
835
- // TODO: Remove native broadcast listeners for group_call & not for webinar
836
- BackgroundTimer.stop();
837
- }
838
828
  removeAllTracks() {
839
829
  this.removeAudioTrack();
840
830
  this.removeVideoTrack();
841
831
  this.removeScreenShareTracks();
842
832
  }
843
833
  stopAudioTrack() {
844
- var _a, _b;
845
- (_a = this.audioTrack) === null || _a === void 0 ? void 0 : _a.stop();
846
- (_b = this.audioTrack) === null || _b === void 0 ? void 0 : _b.release();
834
+ var _a, _b, _c, _d;
835
+ (_a = this.rawAudioTrack) === null || _a === void 0 ? void 0 : _a.stop();
836
+ (_b = this.audioTrack) === null || _b === void 0 ? void 0 : _b.stop();
837
+ (_c = this.rawAudioTrack) === null || _c === void 0 ? void 0 : _c.release();
838
+ (_d = this.audioTrack) === null || _d === void 0 ? void 0 : _d.release();
847
839
  this.audioEnabled = false;
848
840
  }
849
841
  removeAudioTrack() {
@@ -857,21 +849,13 @@ class LocalMediaHandler extends EventEmitter {
857
849
  (_b = this.videoTrack) === null || _b === void 0 ? void 0 : _b.stop();
858
850
  (_c = this.rawVideoTrack) === null || _c === void 0 ? void 0 : _c.release();
859
851
  (_d = this.videoTrack) === null || _d === void 0 ? void 0 : _d.release();
852
+ this.videoEnabled = false;
860
853
  }
861
854
  removeVideoTrack() {
862
855
  this.stopVideoTrack();
863
856
  this.videoTrack = undefined;
864
857
  this.rawVideoTrack = undefined;
865
858
  }
866
- removeAllListeners(event) {
867
- if (event === 'SCREENSHARE_TRACK_CHANGE' ||
868
- event === 'DEVICE_LIST_UPDATED' ||
869
- event === 'DEVICE_CHANGE' ||
870
- !event) {
871
- return null;
872
- }
873
- return super.removeAllListeners(event);
874
- }
875
859
  }
876
860
  _LocalMediaHandler_localMediaUtils = new WeakMap(), _LocalMediaHandler_appState = new WeakMap(), _LocalMediaHandler_appStateSubscription = new WeakMap(), _LocalMediaHandler_interval = new WeakMap();
877
861
  export default LocalMediaHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/realtimekit-react-native",
3
- "version": "0.1.2-staging.10",
3
+ "version": "0.1.2-staging.11",
4
4
  "description": "Cloudflare RealtimeKit SDK for react native",
5
5
  "main": "lib/index.js",
6
6
  "author": "Cloudflare",