@cloudflare/realtimekit-react-native 0.1.2-staging.8 → 0.1.2

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);
@@ -13,7 +13,9 @@ class BackgroundTimer {
13
13
  delete this.callbacks[id];
14
14
  }
15
15
  else {
16
- DyteRNBackgroundTimer.backgroundTimerSetTimeout(id, this.callbacks[id].timeout);
16
+ Platform.OS === 'android'
17
+ ? DyteRNBackgroundTimer.backgroundTimerSetTimeout(id, this.callbacks[id].timeout)
18
+ : DyteRNBackgroundTimer.setTimeout(id, this.callbacks[id].timeout);
17
19
  }
18
20
  callback();
19
21
  }
@@ -21,11 +23,15 @@ class BackgroundTimer {
21
23
  }
22
24
  // Original API
23
25
  start(delay = 0) {
24
- return DyteRNBackgroundTimer.start(delay);
26
+ return Platform.OS === 'android'
27
+ ? DyteRNBackgroundTimer.backgroundTimerStart(delay)
28
+ : DyteRNBackgroundTimer.start(delay);
25
29
  }
26
30
  stop() {
27
31
  Emitter.removeAllListeners('backgroundTimer.timeout');
28
- return DyteRNBackgroundTimer.stop();
32
+ return Platform.OS === 'android'
33
+ ? DyteRNBackgroundTimer.backgroundTimerStop()
34
+ : DyteRNBackgroundTimer.stop();
29
35
  }
30
36
  runBackgroundTimer(callback, delay) {
31
37
  const EventEmitter = Platform.select({
@@ -57,7 +63,9 @@ class BackgroundTimer {
57
63
  interval: false,
58
64
  timeout,
59
65
  };
60
- DyteRNBackgroundTimer.setTimeout(timeoutId, timeout);
66
+ Platform.OS === 'android'
67
+ ? DyteRNBackgroundTimer.backgroundTimerSetTimeout(timeoutId, timeout)
68
+ : DyteRNBackgroundTimer.setTimeout(timeoutId, timeout);
61
69
  return timeoutId;
62
70
  }
63
71
  clearTimeout(timeoutId) {
@@ -74,7 +82,9 @@ class BackgroundTimer {
74
82
  interval: true,
75
83
  timeout,
76
84
  };
77
- DyteRNBackgroundTimer.backgroundTimerSetTimeout(intervalId, timeout);
85
+ Platform.OS === 'android'
86
+ ? DyteRNBackgroundTimer.backgroundTimerSetTimeout(intervalId, timeout)
87
+ : DyteRNBackgroundTimer.setTimeout(intervalId, timeout);
78
88
  return intervalId;
79
89
  }
80
90
  clearInterval(intervalId) {
@@ -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,47 +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 (e) {
821
- console.warn('Failed to stop foreground service', e);
822
- }
823
- InCallManger.stop(undefined);
824
826
  });
825
827
  }
826
- cleanUpTracks() {
827
- var _a, _b, _c, _d;
828
- (_a = this.audioTrack) === null || _a === void 0 ? void 0 : _a.stop();
829
- (_b = this.rawAudioTrack) === null || _b === void 0 ? void 0 : _b.stop();
830
- (_c = this.videoTrack) === null || _c === void 0 ? void 0 : _c.stop();
831
- (_d = this.rawVideoTrack) === null || _d === void 0 ? void 0 : _d.stop();
832
- this.destructor();
833
- }
834
- destructor() {
835
- __classPrivateFieldGet(this, _LocalMediaHandler_appStateSubscription, "f").remove();
836
- broadcastEmitter.removeAllListeners('iOS_BroadcastStarted');
837
- broadcastEmitter.removeAllListeners('iOS_BroadcastStopped');
838
- BackgroundTimer.stop();
839
- }
840
828
  removeAllTracks() {
841
829
  this.removeAudioTrack();
842
830
  this.removeVideoTrack();
843
831
  this.removeScreenShareTracks();
844
832
  }
845
833
  stopAudioTrack() {
846
- var _a, _b;
847
- (_a = this.audioTrack) === null || _a === void 0 ? void 0 : _a.stop();
848
- (_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();
849
839
  this.audioEnabled = false;
850
840
  }
851
841
  removeAudioTrack() {
@@ -865,15 +855,6 @@ class LocalMediaHandler extends EventEmitter {
865
855
  this.videoTrack = undefined;
866
856
  this.rawVideoTrack = undefined;
867
857
  }
868
- removeAllListeners(event) {
869
- if (event === 'SCREENSHARE_TRACK_CHANGE' ||
870
- event === 'DEVICE_LIST_UPDATED' ||
871
- event === 'DEVICE_CHANGE' ||
872
- !event) {
873
- return null;
874
- }
875
- return super.removeAllListeners(event);
876
- }
877
858
  }
878
859
  _LocalMediaHandler_localMediaUtils = new WeakMap(), _LocalMediaHandler_appState = new WeakMap(), _LocalMediaHandler_appStateSubscription = new WeakMap(), _LocalMediaHandler_interval = new WeakMap();
879
860
  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.8",
3
+ "version": "0.1.2",
4
4
  "description": "Cloudflare RealtimeKit SDK for react native",
5
5
  "main": "lib/index.js",
6
6
  "author": "Cloudflare",
@@ -44,7 +44,9 @@
44
44
  "react-native": "*"
45
45
  },
46
46
  "publishConfig": {
47
- "tag": "staging"
47
+ "registry": "https://registry.npmjs.org/",
48
+ "access": "public",
49
+ "tag": "latest"
48
50
  },
49
51
  "scripts": {
50
52
  "postpublish": "mv package.json.bak package.json"