@livekit/react-native 2.1.1 → 2.3.0

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.
Files changed (110) hide show
  1. package/README.md +15 -6
  2. package/android/build.gradle +1 -1
  3. package/android/gradle/wrapper/gradle-wrapper.properties +3 -1
  4. package/android/gradlew +29 -14
  5. package/android/gradlew.bat +19 -16
  6. package/android/src/main/java/com/livekit/reactnative/LiveKitReactNative.kt +14 -1
  7. package/android/src/main/java/com/livekit/reactnative/LivekitReactNativeModule.kt +10 -0
  8. package/android/src/main/java/com/livekit/reactnative/video/SimulcastVideoEncoderFactoryWrapper.kt +2 -2
  9. package/android/src/main/java/org/webrtc/audio/WebRtcAudioTrackHelper.kt +20 -0
  10. package/lib/commonjs/audio/AudioManager.js +4 -27
  11. package/lib/commonjs/audio/AudioManager.js.map +1 -1
  12. package/lib/commonjs/audio/AudioSession.js +55 -23
  13. package/lib/commonjs/audio/AudioSession.js.map +1 -1
  14. package/lib/commonjs/components/LiveKitRoom.js +3 -6
  15. package/lib/commonjs/components/LiveKitRoom.js.map +1 -1
  16. package/lib/commonjs/components/VideoTrack.js +30 -66
  17. package/lib/commonjs/components/VideoTrack.js.map +1 -1
  18. package/lib/commonjs/components/VideoView.js +32 -63
  19. package/lib/commonjs/components/VideoView.js.map +1 -1
  20. package/lib/commonjs/components/ViewPortDetector.js +15 -62
  21. package/lib/commonjs/components/ViewPortDetector.js.map +1 -1
  22. package/lib/commonjs/hooks.js +6 -63
  23. package/lib/commonjs/hooks.js.map +1 -1
  24. package/lib/commonjs/index.js +10 -85
  25. package/lib/commonjs/index.js.map +1 -1
  26. package/lib/commonjs/logger.js +4 -14
  27. package/lib/commonjs/logger.js.map +1 -1
  28. package/lib/commonjs/polyfills/EncoderDecoderTogether.min.js +105 -0
  29. package/lib/commonjs/polyfills/EncoderDecoderTogether.min.js.map +1 -0
  30. package/lib/commonjs/useParticipant.js +5 -13
  31. package/lib/commonjs/useParticipant.js.map +1 -1
  32. package/lib/commonjs/useRoom.js +17 -33
  33. package/lib/commonjs/useRoom.js.map +1 -1
  34. package/lib/module/audio/AudioManager.js +3 -17
  35. package/lib/module/audio/AudioManager.js.map +1 -1
  36. package/lib/module/audio/AudioSession.js +54 -16
  37. package/lib/module/audio/AudioSession.js.map +1 -1
  38. package/lib/module/components/LiveKitRoom.js +1 -0
  39. package/lib/module/components/LiveKitRoom.js.map +1 -1
  40. package/lib/module/components/VideoTrack.js +18 -44
  41. package/lib/module/components/VideoTrack.js.map +1 -1
  42. package/lib/module/components/VideoView.js +18 -42
  43. package/lib/module/components/VideoView.js.map +1 -1
  44. package/lib/module/components/ViewPortDetector.js +13 -54
  45. package/lib/module/components/ViewPortDetector.js.map +1 -1
  46. package/lib/module/hooks.js +1 -2
  47. package/lib/module/hooks.js.map +1 -1
  48. package/lib/module/index.js +6 -24
  49. package/lib/module/index.js.map +1 -1
  50. package/lib/module/logger.js +2 -6
  51. package/lib/module/logger.js.map +1 -1
  52. package/lib/module/polyfills/EncoderDecoderTogether.min.js +105 -0
  53. package/lib/module/polyfills/EncoderDecoderTogether.min.js.map +1 -0
  54. package/lib/module/useParticipant.js +5 -11
  55. package/lib/module/useParticipant.js.map +1 -1
  56. package/lib/module/useRoom.js +17 -30
  57. package/lib/module/useRoom.js.map +1 -1
  58. package/lib/typescript/babel.config.d.ts +1 -0
  59. package/lib/typescript/docs/assets/icons.d.ts +0 -0
  60. package/lib/typescript/docs/assets/main.d.ts +0 -0
  61. package/lib/typescript/docs/assets/navigation.d.ts +0 -0
  62. package/lib/typescript/docs/assets/search.d.ts +0 -0
  63. package/lib/typescript/lib/commonjs/audio/AudioManager.d.ts +10 -0
  64. package/lib/typescript/lib/commonjs/audio/AudioSession.d.ts +33 -0
  65. package/lib/typescript/lib/commonjs/components/LiveKitRoom.d.ts +20 -0
  66. package/lib/typescript/lib/commonjs/components/VideoTrack.d.ts +8 -0
  67. package/lib/typescript/lib/commonjs/components/VideoView.d.ts +14 -0
  68. package/lib/typescript/lib/commonjs/components/ViewPortDetector.d.ts +30 -0
  69. package/lib/typescript/lib/commonjs/hooks.d.ts +29 -0
  70. package/lib/typescript/lib/commonjs/index.d.ts +10 -0
  71. package/lib/typescript/lib/commonjs/logger.d.ts +8 -0
  72. package/lib/typescript/lib/commonjs/useParticipant.d.ts +14 -0
  73. package/lib/typescript/lib/commonjs/useRoom.d.ts +16 -0
  74. package/lib/typescript/lib/module/audio/AudioManager.d.ts +9 -0
  75. package/lib/typescript/lib/module/audio/AudioSession.d.ts +31 -0
  76. package/lib/typescript/lib/module/components/LiveKitRoom.d.ts +22 -0
  77. package/lib/typescript/lib/module/components/VideoTrack.d.ts +9 -0
  78. package/lib/typescript/lib/module/components/VideoView.d.ts +9 -0
  79. package/lib/typescript/lib/module/components/ViewPortDetector.d.ts +29 -0
  80. package/lib/typescript/lib/module/hooks.d.ts +1 -0
  81. package/lib/typescript/lib/module/index.d.ts +18 -0
  82. package/lib/typescript/lib/module/logger.d.ts +8 -0
  83. package/lib/typescript/lib/module/polyfills/EncoderDecoderTogether.min.d.ts +0 -0
  84. package/lib/typescript/lib/module/useParticipant.d.ts +13 -0
  85. package/lib/typescript/lib/module/useRoom.d.ts +15 -0
  86. package/lib/typescript/scripts/bootstrap.d.ts +1 -0
  87. package/lib/typescript/{audio → src/audio}/AudioSession.d.ts +7 -9
  88. package/lib/typescript/{components → src/components}/LiveKitRoom.d.ts +1 -1
  89. package/lib/typescript/{components → src/components}/VideoTrack.d.ts +2 -2
  90. package/lib/typescript/{components → src/components}/VideoView.d.ts +3 -3
  91. package/lib/typescript/{components → src/components}/ViewPortDetector.d.ts +3 -3
  92. package/lib/typescript/src/hooks.d.ts +3 -0
  93. package/lib/typescript/src/index.d.ts +20 -0
  94. package/lib/typescript/{logger.d.ts → src/logger.d.ts} +2 -2
  95. package/lib/typescript/src/polyfills/EncoderDecoderTogether.min.d.ts +0 -0
  96. package/lib/typescript/{useRoom.d.ts → src/useRoom.d.ts} +1 -1
  97. package/package.json +22 -19
  98. package/src/audio/AudioSession.ts +0 -2
  99. package/src/components/LiveKitRoom.tsx +1 -1
  100. package/src/components/VideoTrack.tsx +7 -2
  101. package/src/components/VideoView.tsx +8 -3
  102. package/src/components/ViewPortDetector.tsx +4 -4
  103. package/src/hooks.ts +12 -9
  104. package/src/index.tsx +11 -9
  105. package/src/polyfills/EncoderDecoderTogether.min.js +6 -0
  106. package/src/useRoom.ts +1 -1
  107. package/lib/typescript/hooks.d.ts +0 -2
  108. package/lib/typescript/index.d.ts +0 -19
  109. /package/lib/typescript/{audio → src/audio}/AudioManager.d.ts +0 -0
  110. /package/lib/typescript/{useParticipant.d.ts → src/useParticipant.d.ts} +0 -0
@@ -5,19 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.sortParticipants = sortParticipants;
7
7
  exports.useRoom = useRoom;
8
-
9
8
  var _livekitClient = require("livekit-client");
10
-
11
9
  var _react = require("react");
12
-
13
10
  /** @deprecated wrap your components in a <LiveKitRoom> component instead and use more granular hooks to track state you're interested in */
14
11
  function useRoom(room, options) {
15
- var _options$sortParticip;
16
-
17
12
  const [error] = (0, _react.useState)();
18
13
  const [participants, setParticipants] = (0, _react.useState)([]);
19
14
  const [audioTracks, setAudioTracks] = (0, _react.useState)([]);
20
- const sortFunc = (_options$sortParticip = options === null || options === void 0 ? void 0 : options.sortParticipants) !== null && _options$sortParticip !== void 0 ? _options$sortParticip : sortParticipants;
15
+ const sortFunc = (options === null || options === void 0 ? void 0 : options.sortParticipants) ?? sortParticipants;
21
16
  (0, _react.useEffect)(() => {
22
17
  const onParticipantsChanged = () => {
23
18
  const remotes = Array.from(room.remoteParticipants.values());
@@ -26,15 +21,12 @@ function useRoom(room, options) {
26
21
  sortFunc(newParticipants, room.localParticipant);
27
22
  setParticipants(newParticipants);
28
23
  };
29
-
30
24
  const onSubscribedTrackChanged = track => {
31
25
  // ordering may have changed, re-sort
32
26
  onParticipantsChanged();
33
-
34
27
  if (track && track.kind !== _livekitClient.Track.Kind.Audio) {
35
28
  return;
36
29
  }
37
-
38
30
  const tracks = [];
39
31
  room.remoteParticipants.forEach(p => {
40
32
  p.audioTrackPublications.forEach(pub => {
@@ -45,17 +37,16 @@ function useRoom(room, options) {
45
37
  });
46
38
  setAudioTracks(tracks);
47
39
  };
48
-
49
40
  const onConnectionStateChanged = state => {
50
41
  if (state === _livekitClient.ConnectionState.Connected) {
51
42
  onParticipantsChanged();
52
43
  }
53
44
  };
54
-
55
45
  room.once(_livekitClient.RoomEvent.Disconnected, () => {
56
46
  room.off(_livekitClient.RoomEvent.ParticipantConnected, onParticipantsChanged).off(_livekitClient.RoomEvent.ParticipantDisconnected, onParticipantsChanged).off(_livekitClient.RoomEvent.ActiveSpeakersChanged, onParticipantsChanged).off(_livekitClient.RoomEvent.TrackSubscribed, onSubscribedTrackChanged).off(_livekitClient.RoomEvent.TrackUnsubscribed, onSubscribedTrackChanged).off(_livekitClient.RoomEvent.LocalTrackPublished, onParticipantsChanged).off(_livekitClient.RoomEvent.LocalTrackUnpublished, onParticipantsChanged).off(_livekitClient.RoomEvent.AudioPlaybackStatusChanged, onParticipantsChanged).off(_livekitClient.RoomEvent.ConnectionStateChanged, onConnectionStateChanged);
57
47
  });
58
- room.on(_livekitClient.RoomEvent.ConnectionStateChanged, onConnectionStateChanged).on(_livekitClient.RoomEvent.Reconnected, onParticipantsChanged).on(_livekitClient.RoomEvent.ParticipantConnected, onParticipantsChanged).on(_livekitClient.RoomEvent.ParticipantDisconnected, onParticipantsChanged).on(_livekitClient.RoomEvent.ActiveSpeakersChanged, onParticipantsChanged).on(_livekitClient.RoomEvent.TrackSubscribed, onSubscribedTrackChanged).on(_livekitClient.RoomEvent.TrackUnsubscribed, onSubscribedTrackChanged).on(_livekitClient.RoomEvent.LocalTrackPublished, onParticipantsChanged).on(_livekitClient.RoomEvent.LocalTrackUnpublished, onParticipantsChanged) // trigger a state change by re-sorting participants
48
+ room.on(_livekitClient.RoomEvent.ConnectionStateChanged, onConnectionStateChanged).on(_livekitClient.RoomEvent.Reconnected, onParticipantsChanged).on(_livekitClient.RoomEvent.ParticipantConnected, onParticipantsChanged).on(_livekitClient.RoomEvent.ParticipantDisconnected, onParticipantsChanged).on(_livekitClient.RoomEvent.ActiveSpeakersChanged, onParticipantsChanged).on(_livekitClient.RoomEvent.TrackSubscribed, onSubscribedTrackChanged).on(_livekitClient.RoomEvent.TrackUnsubscribed, onSubscribedTrackChanged).on(_livekitClient.RoomEvent.LocalTrackPublished, onParticipantsChanged).on(_livekitClient.RoomEvent.LocalTrackUnpublished, onParticipantsChanged)
49
+ // trigger a state change by re-sorting participants
59
50
  .on(_livekitClient.RoomEvent.AudioPlaybackStatusChanged, onParticipantsChanged);
60
51
  onSubscribedTrackChanged();
61
52
  return () => {
@@ -68,6 +59,7 @@ function useRoom(room, options) {
68
59
  audioTracks
69
60
  };
70
61
  }
62
+
71
63
  /**
72
64
  * Default sort for participants, it'll order participants by:
73
65
  * 1. dominant speaker (speaker with the loudest audio level)
@@ -76,57 +68,49 @@ function useRoom(room, options) {
76
68
  * 4. participants with video on
77
69
  * 5. by joinedAt
78
70
  */
79
-
80
-
81
71
  function sortParticipants(participants, localParticipant) {
82
72
  participants.sort((a, b) => {
83
- var _a$joinedAt$getTime, _a$joinedAt, _b$joinedAt$getTime, _b$joinedAt;
84
-
73
+ var _a$joinedAt, _b$joinedAt;
85
74
  // loudest speaker first
86
75
  if (a.isSpeaking && b.isSpeaking) {
87
76
  return b.audioLevel - a.audioLevel;
88
- } // speaker goes first
89
-
77
+ }
90
78
 
79
+ // speaker goes first
91
80
  if (a.isSpeaking !== b.isSpeaking) {
92
81
  if (a.isSpeaking) {
93
82
  return -1;
94
83
  } else {
95
84
  return 1;
96
85
  }
97
- } // last active speaker first
98
-
86
+ }
99
87
 
88
+ // last active speaker first
100
89
  if (a.lastSpokeAt !== b.lastSpokeAt) {
101
- var _a$lastSpokeAt$getTim, _a$lastSpokeAt, _b$lastSpokeAt$getTim, _b$lastSpokeAt;
102
-
103
- const aLast = (_a$lastSpokeAt$getTim = (_a$lastSpokeAt = a.lastSpokeAt) === null || _a$lastSpokeAt === void 0 ? void 0 : _a$lastSpokeAt.getTime()) !== null && _a$lastSpokeAt$getTim !== void 0 ? _a$lastSpokeAt$getTim : 0;
104
- const bLast = (_b$lastSpokeAt$getTim = (_b$lastSpokeAt = b.lastSpokeAt) === null || _b$lastSpokeAt === void 0 ? void 0 : _b$lastSpokeAt.getTime()) !== null && _b$lastSpokeAt$getTim !== void 0 ? _b$lastSpokeAt$getTim : 0;
90
+ var _a$lastSpokeAt, _b$lastSpokeAt;
91
+ const aLast = ((_a$lastSpokeAt = a.lastSpokeAt) === null || _a$lastSpokeAt === void 0 ? void 0 : _a$lastSpokeAt.getTime()) ?? 0;
92
+ const bLast = ((_b$lastSpokeAt = b.lastSpokeAt) === null || _b$lastSpokeAt === void 0 ? void 0 : _b$lastSpokeAt.getTime()) ?? 0;
105
93
  return bLast - aLast;
106
- } // video on
107
-
94
+ }
108
95
 
96
+ // video on
109
97
  const aVideo = a.videoTrackPublications.size > 0;
110
98
  const bVideo = b.videoTrackPublications.size > 0;
111
-
112
99
  if (aVideo !== bVideo) {
113
100
  if (aVideo) {
114
101
  return -1;
115
102
  } else {
116
103
  return 1;
117
104
  }
118
- } // joinedAt
119
-
105
+ }
120
106
 
121
- return ((_a$joinedAt$getTime = (_a$joinedAt = a.joinedAt) === null || _a$joinedAt === void 0 ? void 0 : _a$joinedAt.getTime()) !== null && _a$joinedAt$getTime !== void 0 ? _a$joinedAt$getTime : 0) - ((_b$joinedAt$getTime = (_b$joinedAt = b.joinedAt) === null || _b$joinedAt === void 0 ? void 0 : _b$joinedAt.getTime()) !== null && _b$joinedAt$getTime !== void 0 ? _b$joinedAt$getTime : 0);
107
+ // joinedAt
108
+ return (((_a$joinedAt = a.joinedAt) === null || _a$joinedAt === void 0 ? void 0 : _a$joinedAt.getTime()) ?? 0) - (((_b$joinedAt = b.joinedAt) === null || _b$joinedAt === void 0 ? void 0 : _b$joinedAt.getTime()) ?? 0);
122
109
  });
123
-
124
110
  if (localParticipant) {
125
111
  const localIdx = participants.indexOf(localParticipant);
126
-
127
112
  if (localIdx >= 0) {
128
113
  participants.splice(localIdx, 1);
129
-
130
114
  if (participants.length > 0) {
131
115
  participants.splice(1, 0, localParticipant);
132
116
  } else {
@@ -1 +1 @@
1
- {"version":3,"sources":["useRoom.ts"],"names":["useRoom","room","options","error","participants","setParticipants","audioTracks","setAudioTracks","sortFunc","sortParticipants","onParticipantsChanged","remotes","Array","from","remoteParticipants","values","newParticipants","localParticipant","push","onSubscribedTrackChanged","track","kind","Track","Kind","Audio","tracks","forEach","p","audioTrackPublications","pub","audioTrack","onConnectionStateChanged","state","ConnectionState","Connected","once","RoomEvent","Disconnected","off","ParticipantConnected","ParticipantDisconnected","ActiveSpeakersChanged","TrackSubscribed","TrackUnsubscribed","LocalTrackPublished","LocalTrackUnpublished","AudioPlaybackStatusChanged","ConnectionStateChanged","on","Reconnected","disconnect","sort","a","b","isSpeaking","audioLevel","lastSpokeAt","aLast","getTime","bLast","aVideo","videoTrackPublications","size","bVideo","joinedAt","localIdx","indexOf","splice","length"],"mappings":";;;;;;;;AAAA;;AAUA;;AAeA;AACO,SAASA,OAAT,CAAiBC,IAAjB,EAA6BC,OAA7B,EAA+D;AAAA;;AACpE,QAAM,CAACC,KAAD,IAAU,sBAAhB;AACA,QAAM,CAACC,YAAD,EAAeC,eAAf,IAAkC,qBAAwB,EAAxB,CAAxC;AACA,QAAM,CAACC,WAAD,EAAcC,cAAd,IAAgC,qBAAuB,EAAvB,CAAtC;AAEA,QAAMC,QAAQ,4BAAGN,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEO,gBAAZ,yEAAgCA,gBAA9C;AAEA,wBAAU,MAAM;AACd,UAAMC,qBAAqB,GAAG,MAAM;AAClC,YAAMC,OAAO,GAAGC,KAAK,CAACC,IAAN,CAAWZ,IAAI,CAACa,kBA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AAjB;;AACA,QAAIgD,QAAQ,IAAI,CAAhB,EAAmB;AACjB7D,MAAAA,YAAY,CAAC+D,MAAb,CAAoBF,QAApB,EAA8B,CAA9B;;AACA,UAAI7D,YAAY,CAACgE,MAAb,GAAsB,CAA1B,EAA6B;AAC3BhE,QAAAA,YAAY,CAAC+D,MAAb,CAAoB,CAApB,EAAuB,CAAvB,EAA0BlD,gBAA1B;AACD,OAFD,MAEO;AACLb,QAAAA,YAAY,CAACc,IAAb,CAAkBD,gBAAlB;AACD;AACF;AACF;AACF","sourcesContent":["import {\n AudioTrack,\n ConnectionState,\n LocalParticipant,\n Participant,\n RemoteTrack,\n Room,\n RoomEvent,\n Track,\n} from 'livekit-client';\nimport { useEffect, useState } from 'react';\n\nexport interface RoomState {\n room?: Room;\n /* all participants in the room, including the local participant. */\n participants: Participant[];\n /* all subscribed audio tracks in the room, not including local participant. */\n audioTracks: AudioTrack[];\n error?: Error;\n}\n\nexport interface RoomOptions {\n sortParticipants?: (participants: Participant[]) => void;\n}\n\n/** @deprecated wrap your components in a <LiveKitRoom> component instead and use more granular hooks to track state you're interested in */\nexport function useRoom(room: Room, options?: RoomOptions): RoomState {\n const [error] = useState<Error>();\n const [participants, setParticipants] = useState<Participant[]>([]);\n const [audioTracks, setAudioTracks] = useState<AudioTrack[]>([]);\n\n const sortFunc = options?.sortParticipants ?? sortParticipants;\n\n useEffect(() => {\n const onParticipantsChanged = () => {\n const remotes = Array.from(room.remoteParticipants.values());\n const newParticipants: Participant[] = [room.localParticipant];\n newParticipants.push(...remotes);\n sortFunc(newParticipants, room.localParticipant);\n setParticipants(newParticipants);\n };\n const onSubscribedTrackChanged = (track?: RemoteTrack) => {\n // ordering may have changed, re-sort\n onParticipantsChanged();\n if (track && track.kind !== Track.Kind.Audio) {\n return;\n }\n const tracks: AudioTrack[] = [];\n room.remoteParticipants.forEach((p) => {\n p.audioTrackPublications.forEach((pub) => {\n if (pub.audioTrack) {\n tracks.push(pub.audioTrack);\n }\n });\n });\n setAudioTracks(tracks);\n };\n\n const onConnectionStateChanged = (state: ConnectionState) => {\n if (state === ConnectionState.Connected) {\n onParticipantsChanged();\n }\n };\n\n room.once(RoomEvent.Disconnected, () => {\n room\n .off(RoomEvent.ParticipantConnected, onParticipantsChanged)\n .off(RoomEvent.ParticipantDisconnected, onParticipantsChanged)\n .off(RoomEvent.ActiveSpeakersChanged, onParticipantsChanged)\n .off(RoomEvent.TrackSubscribed, onSubscribedTrackChanged)\n .off(RoomEvent.TrackUnsubscribed, onSubscribedTrackChanged)\n .off(RoomEvent.LocalTrackPublished, onParticipantsChanged)\n .off(RoomEvent.LocalTrackUnpublished, onParticipantsChanged)\n .off(RoomEvent.AudioPlaybackStatusChanged, onParticipantsChanged)\n .off(RoomEvent.ConnectionStateChanged, onConnectionStateChanged);\n });\n room\n .on(RoomEvent.ConnectionStateChanged, onConnectionStateChanged)\n .on(RoomEvent.Reconnected, onParticipantsChanged)\n .on(RoomEvent.ParticipantConnected, onParticipantsChanged)\n .on(RoomEvent.ParticipantDisconnected, onParticipantsChanged)\n .on(RoomEvent.ActiveSpeakersChanged, onParticipantsChanged)\n .on(RoomEvent.TrackSubscribed, onSubscribedTrackChanged)\n .on(RoomEvent.TrackUnsubscribed, onSubscribedTrackChanged)\n .on(RoomEvent.LocalTrackPublished, onParticipantsChanged)\n .on(RoomEvent.LocalTrackUnpublished, onParticipantsChanged)\n // trigger a state change by re-sorting participants\n .on(RoomEvent.AudioPlaybackStatusChanged, onParticipantsChanged);\n\n onSubscribedTrackChanged();\n\n return () => {\n room.disconnect();\n };\n }, [room, sortFunc]);\n\n return {\n error,\n participants,\n audioTracks,\n };\n}\n\n/**\n * Default sort for participants, it'll order participants by:\n * 1. dominant speaker (speaker with the loudest audio level)\n * 2. local participant\n * 3. other speakers that are recently active\n * 4. participants with video on\n * 5. by joinedAt\n */\nexport function sortParticipants(\n participants: Participant[],\n localParticipant?: LocalParticipant\n) {\n participants.sort((a, b) => {\n // loudest speaker first\n if (a.isSpeaking && b.isSpeaking) {\n return b.audioLevel - a.audioLevel;\n }\n\n // speaker goes first\n if (a.isSpeaking !== b.isSpeaking) {\n if (a.isSpeaking) {\n return -1;\n } else {\n return 1;\n }\n }\n\n // last active speaker first\n if (a.lastSpokeAt !== b.lastSpokeAt) {\n const aLast = a.lastSpokeAt?.getTime() ?? 0;\n const bLast = b.lastSpokeAt?.getTime() ?? 0;\n return bLast - aLast;\n }\n\n // video on\n const aVideo = a.videoTrackPublications.size > 0;\n const bVideo = b.videoTrackPublications.size > 0;\n if (aVideo !== bVideo) {\n if (aVideo) {\n return -1;\n } else {\n return 1;\n }\n }\n\n // joinedAt\n return (a.joinedAt?.getTime() ?? 0) - (b.joinedAt?.getTime() ?? 0);\n });\n\n if (localParticipant) {\n const localIdx = participants.indexOf(localParticipant);\n if (localIdx >= 0) {\n participants.splice(localIdx, 1);\n if (participants.length > 0) {\n participants.splice(1, 0, localParticipant);\n } else {\n participants.push(localParticipant);\n }\n }\n }\n}\n"]}
1
+ {"version":3,"names":["_livekitClient","require","_react","useRoom","room","options","error","useState","participants","setParticipants","audioTracks","setAudioTracks","sortFunc","sortParticipants","useEffect","onParticipantsChanged","remotes","Array","from","remoteParticipants","values","newParticipants","localParticipant","push","onSubscribedTrackChanged","track","kind","Track","Kind","Audio","tracks","forEach","p","audioTrackPublications","pub","audioTrack","onConnectionStateChanged","state","ConnectionState","Connected","once","RoomEvent","Disconnected","off","ParticipantConnected","ParticipantDisconnected","ActiveSpeakersChanged","TrackSubscribed","TrackUnsubscribed","LocalTrackPublished","LocalTrackUnpublished","AudioPlaybackStatusChanged","ConnectionStateChanged","on","Reconnected","disconnect","sort","a","b","_a$joinedAt","_b$joinedAt","isSpeaking","audioLevel","lastSpokeAt","_a$lastSpokeAt","_b$lastSpokeAt","aLast","getTime","bLast","aVideo","videoTrackPublications","size","bVideo","joinedAt","localIdx","indexOf","splice","length"],"sources":["useRoom.ts"],"sourcesContent":["import {\n type AudioTrack,\n ConnectionState,\n LocalParticipant,\n Participant,\n RemoteTrack,\n Room,\n RoomEvent,\n Track,\n} from 'livekit-client';\nimport { useEffect, useState } from 'react';\n\nexport interface RoomState {\n room?: Room;\n /* all participants in the room, including the local participant. */\n participants: Participant[];\n /* all subscribed audio tracks in the room, not including local participant. */\n audioTracks: AudioTrack[];\n error?: Error;\n}\n\nexport interface RoomOptions {\n sortParticipants?: (participants: Participant[]) => void;\n}\n\n/** @deprecated wrap your components in a <LiveKitRoom> component instead and use more granular hooks to track state you're interested in */\nexport function useRoom(room: Room, options?: RoomOptions): RoomState {\n const [error] = useState<Error>();\n const [participants, setParticipants] = useState<Participant[]>([]);\n const [audioTracks, setAudioTracks] = useState<AudioTrack[]>([]);\n\n const sortFunc = options?.sortParticipants ?? sortParticipants;\n\n useEffect(() => {\n const onParticipantsChanged = () => {\n const remotes = Array.from(room.remoteParticipants.values());\n const newParticipants: Participant[] = [room.localParticipant];\n newParticipants.push(...remotes);\n sortFunc(newParticipants, room.localParticipant);\n setParticipants(newParticipants);\n };\n const onSubscribedTrackChanged = (track?: RemoteTrack) => {\n // ordering may have changed, re-sort\n onParticipantsChanged();\n if (track && track.kind !== Track.Kind.Audio) {\n return;\n }\n const tracks: AudioTrack[] = [];\n room.remoteParticipants.forEach((p) => {\n p.audioTrackPublications.forEach((pub) => {\n if (pub.audioTrack) {\n tracks.push(pub.audioTrack);\n }\n });\n });\n setAudioTracks(tracks);\n };\n\n const onConnectionStateChanged = (state: ConnectionState) => {\n if (state === ConnectionState.Connected) {\n onParticipantsChanged();\n }\n };\n\n room.once(RoomEvent.Disconnected, () => {\n room\n .off(RoomEvent.ParticipantConnected, onParticipantsChanged)\n .off(RoomEvent.ParticipantDisconnected, onParticipantsChanged)\n .off(RoomEvent.ActiveSpeakersChanged, onParticipantsChanged)\n .off(RoomEvent.TrackSubscribed, onSubscribedTrackChanged)\n .off(RoomEvent.TrackUnsubscribed, onSubscribedTrackChanged)\n .off(RoomEvent.LocalTrackPublished, onParticipantsChanged)\n .off(RoomEvent.LocalTrackUnpublished, onParticipantsChanged)\n .off(RoomEvent.AudioPlaybackStatusChanged, onParticipantsChanged)\n .off(RoomEvent.ConnectionStateChanged, onConnectionStateChanged);\n });\n room\n .on(RoomEvent.ConnectionStateChanged, onConnectionStateChanged)\n .on(RoomEvent.Reconnected, onParticipantsChanged)\n .on(RoomEvent.ParticipantConnected, onParticipantsChanged)\n .on(RoomEvent.ParticipantDisconnected, onParticipantsChanged)\n .on(RoomEvent.ActiveSpeakersChanged, onParticipantsChanged)\n .on(RoomEvent.TrackSubscribed, onSubscribedTrackChanged)\n .on(RoomEvent.TrackUnsubscribed, onSubscribedTrackChanged)\n .on(RoomEvent.LocalTrackPublished, onParticipantsChanged)\n .on(RoomEvent.LocalTrackUnpublished, onParticipantsChanged)\n // trigger a state change by re-sorting participants\n .on(RoomEvent.AudioPlaybackStatusChanged, onParticipantsChanged);\n\n onSubscribedTrackChanged();\n\n return () => {\n room.disconnect();\n };\n }, [room, sortFunc]);\n\n return {\n error,\n participants,\n audioTracks,\n };\n}\n\n/**\n * Default sort for participants, it'll order participants by:\n * 1. dominant speaker (speaker with the loudest audio level)\n * 2. local participant\n * 3. other speakers that are recently active\n * 4. participants with video on\n * 5. by joinedAt\n */\nexport function sortParticipants(\n participants: Participant[],\n localParticipant?: LocalParticipant\n) {\n participants.sort((a, b) => {\n // loudest speaker first\n if (a.isSpeaking && b.isSpeaking) {\n return b.audioLevel - a.audioLevel;\n }\n\n // speaker goes first\n if (a.isSpeaking !== b.isSpeaking) {\n if (a.isSpeaking) {\n return -1;\n } else {\n return 1;\n }\n }\n\n // last active speaker first\n if (a.lastSpokeAt !== b.lastSpokeAt) {\n const aLast = a.lastSpokeAt?.getTime() ?? 0;\n const bLast = b.lastSpokeAt?.getTime() ?? 0;\n return bLast - aLast;\n }\n\n // video on\n const aVideo = a.videoTrackPublications.size > 0;\n const bVideo = b.videoTrackPublications.size > 0;\n if (aVideo !== bVideo) {\n if (aVideo) {\n return -1;\n } else {\n return 1;\n }\n }\n\n // joinedAt\n return (a.joinedAt?.getTime() ?? 0) - (b.joinedAt?.getTime() ?? 0);\n });\n\n if (localParticipant) {\n const localIdx = participants.indexOf(localParticipant);\n if (localIdx >= 0) {\n participants.splice(localIdx, 1);\n if (participants.length > 0) {\n participants.splice(1, 0, localParticipant);\n } else {\n participants.push(localParticipant);\n }\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAUA,IAAAC,MAAA,GAAAD,OAAA;AAeA;AACO,SAASE,OAAOA,CAACC,IAAU,EAAEC,OAAqB,EAAa;EACpE,MAAM,CAACC,KAAK,CAAC,GAAG,IAAAC,eAAQ,EAAQ,CAAC;EACjC,MAAM,CAACC,YAAY,EAAEC,eAAe,CAAC,GAAG,IAAAF,eAAQ,EAAgB,EAAE,CAAC;EACnE,MAAM,CAACG,WAAW,EAAEC,cAAc,CAAC,GAAG,IAAAJ,eAAQ,EAAe,EAAE,CAAC;EAEhE,MAAMK,QAAQ,GAAG,CAAAP,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEQ,gBAAgB,KAAIA,gBAAgB;EAE9D,IAAAC,gBAAS,EAAC,MAAM;IACd,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;MAClC,MAAMC,OAAO,GAAGC,KAAK,CAACC,IAAI,CAACd,IAAI,CAACe,kBAAkB,CAACC,MAAM,CAAC,CAAC,CAAC;MAC5D,MAAMC,eAA8B,GAAG,CAACjB,IAAI,CAACkB,gBAAgB,CAAC;MAC9DD,eAAe,CAACE,IAAI,CAAC,GAAGP,OAAO,CAAC;MAChCJ,QAAQ,CAACS,eAAe,EAAEjB,IAAI,CAACkB,gBAAgB,CAAC;MAChDb,eAAe,CAACY,eAAe,CAAC;IAClC,CAAC;IACD,MAAMG,wBAAwB,GAAIC,KAAmB,IAAK;MACxD;MACAV,qBAAqB,CAAC,CAAC;MACvB,IAAIU,KAAK,IAAIA,KAAK,CAACC,IAAI,KAAKC,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ACoE,MAAM,CAACF,QAAQ,EAAE,CAAC,CAAC;MAChC,IAAIlE,YAAY,CAACqE,MAAM,GAAG,CAAC,EAAE;QAC3BrE,YAAY,CAACoE,MAAM,CAAC,CAAC,EAAE,CAAC,EAAEtD,gBAAgB,CAAC;MAC7C,CAAC,MAAM;QACLd,YAAY,CAACe,IAAI,CAACD,gBAAgB,CAAC;MACrC;IACF;EACF;AACF","ignoreList":[]}
@@ -3,6 +3,7 @@ import { Platform } from 'react-native';
3
3
  import { RoomEvent } from 'livekit-client';
4
4
  import AudioSession, { getDefaultAppleAudioConfigurationForMode } from './AudioSession';
5
5
  import { log } from '..';
6
+
6
7
  /**
7
8
  * Handles setting the appropriate AVAudioSession options automatically
8
9
  * depending on the audio track states of the Room.
@@ -11,10 +12,7 @@ import { log } from '..';
11
12
  * @param preferSpeakerOutput
12
13
  * @param onConfigureNativeAudio A custom method for determining options used.
13
14
  */
14
-
15
- export function useIOSAudioManagement(room) {
16
- let preferSpeakerOutput = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
17
- let onConfigureNativeAudio = arguments.length > 2 ? arguments[2] : undefined;
15
+ export function useIOSAudioManagement(room, preferSpeakerOutput = true, onConfigureNativeAudio) {
18
16
  const [localTrackCount, setLocalTrackCount] = useState(0);
19
17
  const [remoteTrackCount, setRemoteTrackCount] = useState(0);
20
18
  const trackState = useMemo(() => computeAudioTrackState(localTrackCount, remoteTrackCount), [localTrackCount, remoteTrackCount]);
@@ -23,7 +21,6 @@ export function useIOSAudioManagement(room) {
23
21
  setLocalTrackCount(getLocalAudioTrackCount(room));
24
22
  setRemoteTrackCount(getRemoteAudioTrackCount(room));
25
23
  };
26
-
27
24
  recalculateTrackCounts();
28
25
  room.on(RoomEvent.Connected, recalculateTrackCounts);
29
26
  return () => {
@@ -34,31 +31,24 @@ export function useIOSAudioManagement(room) {
34
31
  if (Platform.OS !== 'ios') {
35
32
  return () => {};
36
33
  }
37
-
38
34
  let onLocalPublished = () => {
39
35
  setLocalTrackCount(localTrackCount + 1);
40
36
  };
41
-
42
37
  let onLocalUnpublished = () => {
43
38
  if (localTrackCount - 1 < 0) {
44
39
  log.warn('mismatched local audio track count! attempted to reduce track count below zero.');
45
40
  }
46
-
47
41
  setLocalTrackCount(Math.max(localTrackCount - 1, 0));
48
42
  };
49
-
50
43
  let onRemotePublished = () => {
51
44
  setRemoteTrackCount(remoteTrackCount + 1);
52
45
  };
53
-
54
46
  let onRemoteUnpublished = () => {
55
47
  if (remoteTrackCount - 1 < 0) {
56
48
  log.warn('mismatched remote audio track count! attempted to reduce track count below zero.');
57
49
  }
58
-
59
50
  setRemoteTrackCount(Math.max(remoteTrackCount - 1, 0));
60
51
  };
61
-
62
52
  room.on(RoomEvent.LocalTrackPublished, onLocalPublished).on(RoomEvent.LocalTrackUnpublished, onLocalUnpublished).on(RoomEvent.TrackPublished, onRemotePublished).on(RoomEvent.TrackUnpublished, onRemoteUnpublished);
63
53
  return () => {
64
54
  room.off(RoomEvent.LocalTrackPublished, onLocalPublished).off(RoomEvent.LocalTrackUnpublished, onLocalUnpublished).off(RoomEvent.TrackPublished, onRemotePublished).off(RoomEvent.TrackUnpublished, onRemoteUnpublished);
@@ -68,13 +58,11 @@ export function useIOSAudioManagement(room) {
68
58
  if (Platform.OS !== 'ios') {
69
59
  return;
70
60
  }
71
-
72
- let configFunc = onConfigureNativeAudio !== null && onConfigureNativeAudio !== void 0 ? onConfigureNativeAudio : getDefaultAppleAudioConfigurationForMode;
61
+ let configFunc = onConfigureNativeAudio ?? getDefaultAppleAudioConfigurationForMode;
73
62
  let audioConfig = configFunc(trackState, preferSpeakerOutput);
74
63
  AudioSession.setAppleAudioConfiguration(audioConfig);
75
64
  }, [trackState, onConfigureNativeAudio, preferSpeakerOutput]);
76
65
  }
77
-
78
66
  function computeAudioTrackState(localTracks, remoteTracks) {
79
67
  if (localTracks > 0 && remoteTracks > 0) {
80
68
  return 'localAndRemote';
@@ -86,11 +74,9 @@ function computeAudioTrackState(localTracks, remoteTracks) {
86
74
  return 'none';
87
75
  }
88
76
  }
89
-
90
77
  function getLocalAudioTrackCount(room) {
91
78
  return room.localParticipant.audioTrackPublications.size;
92
79
  }
93
-
94
80
  function getRemoteAudioTrackCount(room) {
95
81
  var audioTracks = 0;
96
82
  room.remoteParticipants.forEach(participant => {
@@ -1 +1 @@
1
- {"version":3,"sources":["AudioManager.ts"],"names":["useState","useEffect","useMemo","Platform","RoomEvent","AudioSession","getDefaultAppleAudioConfigurationForMode","log","useIOSAudioManagement","room","preferSpeakerOutput","onConfigureNativeAudio","localTrackCount","setLocalTrackCount","remoteTrackCount","setRemoteTrackCount","trackState","computeAudioTrackState","recalculateTrackCounts","getLocalAudioTrackCount","getRemoteAudioTrackCount","on","Connected","off","OS","onLocalPublished","onLocalUnpublished","warn","Math","max","onRemotePublished","onRemoteUnpublished","LocalTrackPublished","LocalTrackUnpublished","TrackPublished","TrackUnpublished","configFunc","audioConfig","setAppleAudioConfiguration","localTracks","remoteTracks","localParticipant","audioTrackPublications","size","audioTracks","remoteParticipants","forEach","participant"],"mappings":"AAAA,SAASA,QAAT,EAAmBC,SAAnB,EAA8BC,OAA9B,QAA6C,OAA7C;AACA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,SAAT,QAAgC,gBAAhC;AACA,OAAOC,YAAP,IACEC,wCADF,QAIO,gBAJP;AAKA,SAASC,GAAT,QAAoB,IAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,qBAAT,CACLC,IADK,EAOL;AAAA,MALAC,mBAKA,uEAL+B,IAK/B;AAAA,MAJAC,sBAIA;AACA,QAAM,CAACC,eAAD,EAAkBC,kBAAlB,IAAwCb,QAAQ,CAAC,CAAD,CAAtD;AACA,QAAM,CAACc,gBAAD,EAAmBC,mBAAnB,IAA0Cf,QAAQ,CAAC,CAAD,CAAxD;AACA,QAAMgB,UAAU,GAAGd,OAAO,CACxB,MAAMe,sBAAsB,CAACL,eAAD,EAAkBE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,EAAyC;AACvC,WAAO,gBAAP;AACD,GAFD,MAEO,IAAID,WAAW,GAAG,CAAd,IAAmBC,YAAY,KAAK,CAAxC,EAA2C;AAChD,WAAO,WAAP;AACD,GAFM,MAEA,IAAID,WAAW,KAAK,CAAhB,IAAqBC,YAAY,GAAG,CAAxC,EAA2C;AAChD,WAAO,YAAP;AACD,GAFM,MAEA;AACL,WAAO,MAAP;AACD;AACF;;AAED,SAASrB,uBAAT,CAAiCV,IAAjC,EAAqD;AACnD,SAAOA,IAAI,CAACgC,gBAAL,CAAsBC,sBAAtB,CAA6CC,IAApD;AACD;;AAED,SAASvB,wBAAT,CAAkCX,IAAlC,EAAsD;AACpD,MAAImC,WAAW,GAAG,CAAlB;AACAnC,EAAAA,IAAI,CAACoC,kBAAL,CAAwBC,OAAxB,CAAiCC,WAAD,IAAiB;AAC/CH,IAAAA,WAAW,IAAIG,WAAW,CAACL,sBAAZ,CAAmCC,IAAlD;AACD,GAFD;AAIA,SAAOC,WAAP;AACD","sourcesContent":["import { useState, useEffect, useMemo } from 'react';\nimport { Platform } from 'react-native';\nimport { RoomEvent, Room } from 'livekit-client';\nimport AudioSession, {\n getDefaultAppleAudioConfigurationForMode,\n type AppleAudioConfiguration,\n type AudioTrackState,\n} from './AudioSession';\nimport { log } from '..';\n\n/**\n * Handles setting the appropriate AVAudioSession options automatically\n * depending on the audio track states of the Room.\n *\n * @param room\n * @param preferSpeakerOutput\n * @param onConfigureNativeAudio A custom method for determining options used.\n */\nexport function useIOSAudioManagement(\n room: Room,\n preferSpeakerOutput: boolean = true,\n onConfigureNativeAudio?: (\n trackState: AudioTrackState,\n preferSpeakerOutput: boolean\n ) => AppleAudioConfiguration\n) {\n const [localTrackCount, setLocalTrackCount] = useState(0);\n const [remoteTrackCount, setRemoteTrackCount] = useState(0);\n const trackState = useMemo(\n () => computeAudioTrackState(localTrackCount, remoteTrackCount),\n [localTrackCount, remoteTrackCount]\n );\n\n useEffect(() => {\n let recalculateTrackCounts = () => {\n setLocalTrackCount(getLocalAudioTrackCount(room));\n setRemoteTrackCount(getRemoteAudioTrackCount(room));\n };\n\n recalculateTrackCounts();\n\n room.on(RoomEvent.Connected, recalculateTrackCounts);\n\n return () => {\n room.off(RoomEvent.Connected, recalculateTrackCounts);\n };\n }, [room]);\n useEffect(() => {\n if (Platform.OS !== 'ios') {\n return () => {};\n }\n\n let onLocalPublished = () => {\n setLocalTrackCount(localTrackCount + 1);\n };\n let onLocalUnpublished = () => {\n if (localTrackCount - 1 < 0) {\n log.warn(\n 'mismatched local audio track count! attempted to reduce track count below zero.'\n );\n }\n setLocalTrackCount(Math.max(localTrackCount - 1, 0));\n };\n let onRemotePublished = () => {\n setRemoteTrackCount(remoteTrackCount + 1);\n };\n let onRemoteUnpublished = () => {\n if (remoteTrackCount - 1 < 0) {\n log.warn(\n 'mismatched remote audio track count! attempted to reduce track count below zero.'\n );\n }\n setRemoteTrackCount(Math.max(remoteTrackCount - 1, 0));\n };\n\n room\n .on(RoomEvent.LocalTrackPublished, onLocalPublished)\n .on(RoomEvent.LocalTrackUnpublished, onLocalUnpublished)\n .on(RoomEvent.TrackPublished, onRemotePublished)\n .on(RoomEvent.TrackUnpublished, onRemoteUnpublished);\n\n return () => {\n room\n .off(RoomEvent.LocalTrackPublished, onLocalPublished)\n .off(RoomEvent.LocalTrackUnpublished, onLocalUnpublished)\n .off(RoomEvent.TrackPublished, onRemotePublished)\n .off(RoomEvent.TrackUnpublished, onRemoteUnpublished);\n };\n }, [room, localTrackCount, remoteTrackCount]);\n\n useEffect(() => {\n if (Platform.OS !== 'ios') {\n return;\n }\n\n let configFunc =\n onConfigureNativeAudio ?? getDefaultAppleAudioConfigurationForMode;\n let audioConfig = configFunc(trackState, preferSpeakerOutput);\n AudioSession.setAppleAudioConfiguration(audioConfig);\n }, [trackState, onConfigureNativeAudio, preferSpeakerOutput]);\n}\n\nfunction computeAudioTrackState(\n localTracks: number,\n remoteTracks: number\n): AudioTrackState {\n if (localTracks > 0 && remoteTracks > 0) {\n return 'localAndRemote';\n } else if (localTracks > 0 && remoteTracks === 0) {\n return 'localOnly';\n } else if (localTracks === 0 && remoteTracks > 0) {\n return 'remoteOnly';\n } else {\n return 'none';\n }\n}\n\nfunction getLocalAudioTrackCount(room: Room): number {\n return room.localParticipant.audioTrackPublications.size;\n}\n\nfunction getRemoteAudioTrackCount(room: Room): number {\n var audioTracks = 0;\n room.remoteParticipants.forEach((participant) => {\n audioTracks += participant.audioTrackPublications.size;\n });\n\n return audioTracks;\n}\n"]}
1
+ {"version":3,"names":["useState","useEffect","useMemo","Platform","RoomEvent","AudioSession","getDefaultAppleAudioConfigurationForMode","log","useIOSAudioManagement","room","preferSpeakerOutput","onConfigureNativeAudio","localTrackCount","setLocalTrackCount","remoteTrackCount","setRemoteTrackCount","trackState","computeAudioTrackState","recalculateTrackCounts","getLocalAudioTrackCount","getRemoteAudioTrackCount","on","Connected","off","OS","onLocalPublished","onLocalUnpublished","warn","Math","max","onRemotePublished","onRemoteUnpublished","LocalTrackPublished","LocalTrackUnpublished","TrackPublished","TrackUnpublished","configFunc","audioConfig","setAppleAudioConfiguration","localTracks","remoteTracks","localParticipant","audioTrackPublications","size","audioTracks","remoteParticipants","forEach","participant"],"sources":["AudioManager.ts"],"sourcesContent":["import { useState, useEffect, useMemo } from 'react';\nimport { Platform } from 'react-native';\nimport { RoomEvent, Room } from 'livekit-client';\nimport AudioSession, {\n getDefaultAppleAudioConfigurationForMode,\n type AppleAudioConfiguration,\n type AudioTrackState,\n} from './AudioSession';\nimport { log } from '..';\n\n/**\n * Handles setting the appropriate AVAudioSession options automatically\n * depending on the audio track states of the Room.\n *\n * @param room\n * @param preferSpeakerOutput\n * @param onConfigureNativeAudio A custom method for determining options used.\n */\nexport function useIOSAudioManagement(\n room: Room,\n preferSpeakerOutput: boolean = true,\n onConfigureNativeAudio?: (\n trackState: AudioTrackState,\n preferSpeakerOutput: boolean\n ) => AppleAudioConfiguration\n) {\n const [localTrackCount, setLocalTrackCount] = useState(0);\n const [remoteTrackCount, setRemoteTrackCount] = useState(0);\n const trackState = useMemo(\n () => computeAudioTrackState(localTrackCount, remoteTrackCount),\n [localTrackCount, remoteTrackCount]\n );\n\n useEffect(() => {\n let recalculateTrackCounts = () => {\n setLocalTrackCount(getLocalAudioTrackCount(room));\n setRemoteTrackCount(getRemoteAudioTrackCount(room));\n };\n\n recalculateTrackCounts();\n\n room.on(RoomEvent.Connected, recalculateTrackCounts);\n\n return () => {\n room.off(RoomEvent.Connected, recalculateTrackCounts);\n };\n }, [room]);\n useEffect(() => {\n if (Platform.OS !== 'ios') {\n return () => {};\n }\n\n let onLocalPublished = () => {\n setLocalTrackCount(localTrackCount + 1);\n };\n let onLocalUnpublished = () => {\n if (localTrackCount - 1 < 0) {\n log.warn(\n 'mismatched local audio track count! attempted to reduce track count below zero.'\n );\n }\n setLocalTrackCount(Math.max(localTrackCount - 1, 0));\n };\n let onRemotePublished = () => {\n setRemoteTrackCount(remoteTrackCount + 1);\n };\n let onRemoteUnpublished = () => {\n if (remoteTrackCount - 1 < 0) {\n log.warn(\n 'mismatched remote audio track count! attempted to reduce track count below zero.'\n );\n }\n setRemoteTrackCount(Math.max(remoteTrackCount - 1, 0));\n };\n\n room\n .on(RoomEvent.LocalTrackPublished, onLocalPublished)\n .on(RoomEvent.LocalTrackUnpublished, onLocalUnpublished)\n .on(RoomEvent.TrackPublished, onRemotePublished)\n .on(RoomEvent.TrackUnpublished, onRemoteUnpublished);\n\n return () => {\n room\n .off(RoomEvent.LocalTrackPublished, onLocalPublished)\n .off(RoomEvent.LocalTrackUnpublished, onLocalUnpublished)\n .off(RoomEvent.TrackPublished, onRemotePublished)\n .off(RoomEvent.TrackUnpublished, onRemoteUnpublished);\n };\n }, [room, localTrackCount, remoteTrackCount]);\n\n useEffect(() => {\n if (Platform.OS !== 'ios') {\n return;\n }\n\n let configFunc =\n onConfigureNativeAudio ?? getDefaultAppleAudioConfigurationForMode;\n let audioConfig = configFunc(trackState, preferSpeakerOutput);\n AudioSession.setAppleAudioConfiguration(audioConfig);\n }, [trackState, onConfigureNativeAudio, preferSpeakerOutput]);\n}\n\nfunction computeAudioTrackState(\n localTracks: number,\n remoteTracks: number\n): AudioTrackState {\n if (localTracks > 0 && remoteTracks > 0) {\n return 'localAndRemote';\n } else if (localTracks > 0 && remoteTracks === 0) {\n return 'localOnly';\n } else if (localTracks === 0 && remoteTracks > 0) {\n return 'remoteOnly';\n } else {\n return 'none';\n }\n}\n\nfunction getLocalAudioTrackCount(room: Room): number {\n return room.localParticipant.audioTrackPublications.size;\n}\n\nfunction getRemoteAudioTrackCount(room: Room): number {\n var audioTracks = 0;\n room.remoteParticipants.forEach((participant) => {\n audioTracks += participant.audioTrackPublications.size;\n });\n\n return audioTracks;\n}\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AACpD,SAASC,QAAQ,QAAQ,cAAc;AACvC,SAASC,SAAS,QAAc,gBAAgB;AAChD,OAAOC,YAAY,IACjBC,wCAAwC,QAGnC,gBAAgB;AACvB,SAASC,GAAG,QAAQ,IAAI;;AAExB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,IAAU,EACVC,mBAA4B,GAAG,IAAI,EACnCC,sBAG4B,EAC5B;EACA,MAAM,CAACC,eAAe,EAAEC,kBAAkB,CAAC,GAAGb,QAAQ,CAAC,CAAC,CAAC;EACzD,MAAM,CAACc,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGf,QAAQ,CAAC,CAAC,CAAC;EAC3D,MAAMgB,UAAU,GAAGd,OAAO,CACxB,MAAMe,sBAAsB,CAACL,eAAe,EAAEE,gBAAgB,CAAC,EAC/D,CAACF,eAAe,EAAEE,gBAAgB,CACpC,CAAC;EAEDb,SAAS,CAAC,MAAM;IACd,IAAIiB,sBAAsB,GAAGA,CAAA,KAAM;MACjCL,kBAAkB,CAACM,uBAAuB,CAACV,IAAI,CAAC,CAAC;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ACF;AAEA,SAASrB,uBAAuBA,CAACV,IAAU,EAAU;EACnD,OAAOA,IAAI,CAACgC,gBAAgB,CAACC,sBAAsB,CAACC,IAAI;AAC1D;AAEA,SAASvB,wBAAwBA,CAACX,IAAU,EAAU;EACpD,IAAImC,WAAW,GAAG,CAAC;EACnBnC,IAAI,CAACoC,kBAAkB,CAACC,OAAO,CAAEC,WAAW,IAAK;IAC/CH,WAAW,IAAIG,WAAW,CAACL,sBAAsB,CAACC,IAAI;EACxD,CAAC,CAAC;EAEF,OAAOC,WAAW;AACpB","ignoreList":[]}
@@ -1,5 +1,6 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
1
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
3
4
  import { NativeModules, Platform } from 'react-native';
4
5
  const LINKING_ERROR = `The package '@livekit/react-native' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
5
6
  ios: "- You have run 'pod install'\n",
@@ -9,8 +10,8 @@ const LivekitReactNative = NativeModules.LivekitReactNative ? NativeModules.Live
9
10
  get() {
10
11
  throw new Error(LINKING_ERROR);
11
12
  }
12
-
13
13
  });
14
+
14
15
  /**
15
16
  * Configuration for the underlying AudioSession.
16
17
  *
@@ -31,8 +32,6 @@ const LivekitReactNative = NativeModules.LivekitReactNative ? NativeModules.Live
31
32
  *
32
33
  * See {@link AndroidAudioTypePresets} for pre-configured values.
33
34
  *
34
- * NOTE: If `audioTypeOptions` is set, this must also be reflected in your android MainApplication setup.
35
- *
36
35
  * ----
37
36
  * iOS
38
37
  *
@@ -59,9 +58,7 @@ export const AndroidAudioTypePresets = {
59
58
  audioAttributesContentType: 'unknown'
60
59
  }
61
60
  };
62
- export function getDefaultAppleAudioConfigurationForMode(mode) {
63
- let preferSpeakerOutput = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
64
-
61
+ export function getDefaultAppleAudioConfigurationForMode(mode, preferSpeakerOutput = true) {
65
62
  if (mode === 'remoteOnly') {
66
63
  return {
67
64
  audioCategory: 'playback',
@@ -75,7 +72,6 @@ export function getDefaultAppleAudioConfigurationForMode(mode) {
75
72
  audioMode: preferSpeakerOutput ? 'videoChat' : 'voiceChat'
76
73
  };
77
74
  }
78
-
79
75
  return {
80
76
  audioCategory: 'soloAmbient',
81
77
  audioCategoryOptions: [],
@@ -83,19 +79,52 @@ export function getDefaultAppleAudioConfigurationForMode(mode) {
83
79
  };
84
80
  }
85
81
  export default class AudioSession {}
86
-
82
+ /**
83
+ * Applies the provided audio configuration to the underlying AudioSession.
84
+ *
85
+ * Must be called prior to connecting to a Room for the configuration to apply correctly.
86
+ *
87
+ * See also useIOSAudioManagement for automatic configuration of iOS audio options.
88
+ */
87
89
  _defineProperty(AudioSession, "configureAudio", async config => {
88
90
  await LivekitReactNative.configureAudio(config);
89
91
  });
90
-
92
+ /**
93
+ * Starts an AudioSession.
94
+ */
91
95
  _defineProperty(AudioSession, "startAudioSession", async () => {
92
96
  await LivekitReactNative.startAudioSession();
93
97
  });
94
-
98
+ /**
99
+ * Stops the existing AudioSession.
100
+ */
95
101
  _defineProperty(AudioSession, "stopAudioSession", async () => {
96
102
  await LivekitReactNative.stopAudioSession();
97
103
  });
98
-
104
+ /**
105
+ * Gets the available audio outputs for use with {@link selectAudioOutput}.
106
+ *
107
+ * {@link startAudioSession} must be called prior to using this method.
108
+ *
109
+ * For Android, will return if available:
110
+ * * "speaker"
111
+ * * "earpiece"
112
+ * * "headset"
113
+ * * "bluetooth"
114
+ *
115
+ * ----
116
+ *
117
+ * For iOS, due to OS limitations, the only available types are:
118
+ * * "default" - Use default iOS audio routing
119
+ * * "force_speaker" - Force audio output through speaker
120
+ *
121
+ * See also {@link showAudioRoutePicker} to display a route picker that
122
+ * can choose between other audio devices (i.e. headset/bluetooth/airplay),
123
+ * or use a library like `react-native-avroutepicker` for a native platform
124
+ * control.
125
+ *
126
+ * @returns the available audio output types
127
+ */
99
128
  _defineProperty(AudioSession, "getAudioOutputs", async () => {
100
129
  if (Platform.OS === 'ios') {
101
130
  return ['default', 'force_speaker'];
@@ -105,17 +134,26 @@ _defineProperty(AudioSession, "getAudioOutputs", async () => {
105
134
  return [];
106
135
  }
107
136
  });
108
-
137
+ /**
138
+ * Select the provided audio output if available.
139
+ *
140
+ * {@link startAudioSession} must be called prior to using this method.
141
+ *
142
+ * @param deviceId A deviceId retrieved from {@link getAudioOutputs}
143
+ */
109
144
  _defineProperty(AudioSession, "selectAudioOutput", async deviceId => {
110
145
  await LivekitReactNative.selectAudioOutput(deviceId);
111
146
  });
112
-
147
+ /**
148
+ * iOS only, requires iOS 11+.
149
+ *
150
+ * Displays an AVRoutePickerView for the user to choose their audio output.
151
+ */
113
152
  _defineProperty(AudioSession, "showAudioRoutePicker", async () => {
114
153
  if (Platform.OS === 'ios') {
115
154
  await LivekitReactNative.showAudioRoutePicker();
116
155
  }
117
156
  });
118
-
119
157
  _defineProperty(AudioSession, "setAppleAudioConfiguration", async config => {
120
158
  if (Platform.OS === 'ios') {
121
159
  await LivekitReactNative.setAppleAudioConfiguration(config);
@@ -1 +1 @@
1
- {"version":3,"sources":["AudioSession.ts"],"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","LivekitReactNative","Proxy","get","Error","AndroidAudioTypePresets","communication","manageAudioFocus","audioMode","audioFocusMode","audioStreamType","audioAttributesUsageType","audioAttributesContentType","media","getDefaultAppleAudioConfigurationForMode","mode","preferSpeakerOutput","audioCategory","audioCategoryOptions","AudioSession","config","configureAudio","startAudioSession","stopAudioSession","OS","getAudioOutputs","deviceId","selectAudioOutput","showAudioRoutePicker","setAppleAudioConfiguration"],"mappings":";;AAAA,SAASA,aAAT,EAAwBC,QAAxB,QAAwC,cAAxC;AACA,MAAMC,aAAa,GAChB,gFAAD,GACAD,QAAQ,CAACE,MAAT,CAAgB;AAAEC,EAAAA,GAAG,EAAE,gCAAP;AAAyCC,EAAAA,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;AAMA,MAAMC,kBAAkB,GAAGN,aAAa,CAACM,kBAAd,GACvBN,aAAa,CAACM,kBADS,GAEvB,IAAIC,KAAJ,CACE,EADF,EAEE;AACEC,EAAAA,GAAG,GAAG;AACJ,UAAM,IAAIC,KAAJ,CAAUP,aAAV,CAAN;AACD;;AAHH,CAFF,CAFJ;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA6GA,OAAO,MAAMQ,uBASZ,GAAG;AACFC,EAAAA,aAAa,EAAE;AACbC,IAAAA,gBAAgB,EAAE,IADL;AAEbC,IAAAA,SAAS,EAAE,iBAFE;AAGbC,IAAAA,cAAc,EAAE,MAHH;AAIbC,IAAAA,eAAe,EAAE,WAJJ;AAKbC,IAAAA,wBAAwB,EAAE,oBALb;AAMbC,IAAAA,0BAA0B,EAAE;AANf,GADb;AASFC,EAAAA,KAAK,EAAE;AACLN,IAAAA,gBAAgB,EAAE,IADb;AAELC,IAAAA,SAAS,EAAE,QAFN;AAGLC,IAAAA,cAAc,EAAE,MAHX;AAILC,IAAAA,eAAe,EAAE,OAJZ;AAKLC,IAAAA,wBAAwB,EAAE,OALrB;AAMLC,IAAAA,0BAA0B,EAAE;AANvB;AATL,CATG;AAmEP,OAAO,SAASE,wCAAT,CACLC,IADK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ACrD,QAAMzB,kBAAkB,CAAC0B,iBAAnB,CAAqCD,QAArC,CAAN;AACD,C;;gBArEkBP,Y,0BA4EW,YAAY;AACxC,MAAIvB,QAAQ,CAAC4B,EAAT,KAAgB,KAApB,EAA2B;AACzB,UAAMvB,kBAAkB,CAAC2B,oBAAnB,EAAN;AACD;AACF,C;;gBAhFkBT,Y,gCAkFiB,MAClCC,MADkC,IAE/B;AACH,MAAIxB,QAAQ,CAAC4B,EAAT,KAAgB,KAApB,EAA2B;AACzB,UAAMvB,kBAAkB,CAAC4B,0BAAnB,CAA8CT,MAA9C,CAAN;AACD;AACF,C","sourcesContent":["import { NativeModules, Platform } from 'react-native';\nconst LINKING_ERROR =\n `The package '@livekit/react-native' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst LivekitReactNative = NativeModules.LivekitReactNative\n ? NativeModules.LivekitReactNative\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\n/**\n * Configuration for the underlying AudioSession.\n *\n * ----\n * Android specific options:\n *\n * * preferredOutputList - The preferred order in which to automatically select an audio output.\n * This is ignored when an output is manually selected with {@link AudioSession.selectAudioOutput}.\n *\n * By default, the order is set to:\n * 1. `\"bluetooth\"\n * 2. `\"headset\"``\n * 3. `\"speaker\"`\n * 4. `\"earpiece\"`\n *\n * * audioTypeOptions - An {@link AndroidAudioTypeOptions} object which provides the\n * audio options to use on Android.\n *\n * See {@link AndroidAudioTypePresets} for pre-configured values.\n *\n * NOTE: If `audioTypeOptions` is set, this must also be reflected in your android MainApplication setup.\n *\n * ----\n * iOS\n *\n * * defaultOutput - The default preferred output to use when a wired headset or bluetooth output is unavailable.\n *\n * By default, this is set to `\"speaker\"`\n */\nexport type AudioConfiguration = {\n android?: {\n preferredOutputList?: ('speaker' | 'earpiece' | 'headset' | 'bluetooth')[];\n audioTypeOptions: AndroidAudioTypeOptions;\n };\n ios?: {\n defaultOutput?: 'speaker' | 'earpiece';\n };\n};\n\nexport type AndroidAudioTypeOptions = {\n /**\n * Whether LiveKit should handle managing the audio focus or not.\n *\n * Defaults to true.\n */\n manageAudioFocus?: boolean;\n\n /**\n * Corresponds to {@link https://developer.android.com/reference/android/media/AudioManager#setMode(int)}\n *\n * Defaults to 'inCommunication'.\n */\n audioMode?:\n | 'normal'\n | 'callScreening'\n | 'inCall'\n | 'inCommunication'\n | 'ringtone';\n\n /**\n * Corresponds to the duration hint when requesting audio focus.\n *\n * Defaults to 'gain'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#AUDIOFOCUS_GAIN}\n */\n audioFocusMode?:\n | 'gain'\n | 'gainTransient'\n | 'gainTransientExclusive'\n | 'gainTransientMayDuck';\n\n /**\n * Corresponds to Android's AudioAttributes usage type.\n *\n * Defaults to 'voiceCommunication'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesUsageType?:\n | 'alarm'\n | 'assistanceAccessibility'\n | 'assistanceNavigationGuidance'\n | 'assistanceSonification'\n | 'assistant'\n | 'game'\n | 'media'\n | 'notification'\n | 'notificationEvent'\n | 'notificationRingtone'\n | 'unknown'\n | 'voiceCommunication'\n | 'voiceCommunicationSignalling';\n\n /**\n * Corresponds to Android's AndroidAttributes content type.\n *\n * Defaults to 'speech'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesContentType?:\n | 'movie'\n | 'music'\n | 'sonification'\n | 'speech'\n | 'unknown';\n\n /**\n * Corresponds to the stream type when requesting audio focus. Used on pre-O devices.\n *\n * Defaults to 'voiceCall'\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#STREAM_VOICE_CALL}\n */\n audioStreamType?:\n | 'accessibility'\n | 'alarm'\n | 'dtmf'\n | 'music'\n | 'notification'\n | 'ring'\n | 'system'\n | 'voiceCall';\n\n /**\n * On certain Android devices, audio routing does not function properly and\n * bluetooth microphones will not work unless audio mode is set to\n * `inCommunication` or `inCall`. Audio routing is turned off those cases.\n *\n * If this set to true, will attempt to do audio routing regardless of audio mode.\n *\n * Defaults to false.\n */\n forceHandleAudioRouting?: boolean;\n};\n\nexport const AndroidAudioTypePresets: {\n /**\n * A pre-configured AndroidAudioConfiguration for voice communication.\n */\n communication: AndroidAudioTypeOptions;\n /**\n * A pre-configured AndroidAudioConfiguration for media playback.\n */\n media: AndroidAudioTypeOptions;\n} = {\n communication: {\n manageAudioFocus: true,\n audioMode: 'inCommunication',\n audioFocusMode: 'gain',\n audioStreamType: 'voiceCall',\n audioAttributesUsageType: 'voiceCommunication',\n audioAttributesContentType: 'speech',\n },\n media: {\n manageAudioFocus: true,\n audioMode: 'normal',\n audioFocusMode: 'gain',\n audioStreamType: 'music',\n audioAttributesUsageType: 'media',\n audioAttributesContentType: 'unknown',\n },\n} as const;\n\nexport type AppleAudioMode =\n | 'default'\n | 'gameChat'\n | 'measurement'\n | 'moviePlayback'\n | 'spokenAudio'\n | 'videoChat'\n | 'videoRecording'\n | 'voiceChat'\n | 'voicePrompt';\n\nexport type AppleAudioCategory =\n | 'soloAmbient'\n | 'playback'\n | 'record'\n | 'playAndRecord'\n | 'multiRoute';\n\nexport type AppleAudioCategoryOption =\n | 'mixWithOthers'\n | 'duckOthers'\n | 'interruptSpokenAudioAndMixWithOthers'\n | 'allowBluetooth'\n | 'allowBluetoothA2DP'\n | 'allowAirPlay'\n | 'defaultToSpeaker';\n\nexport type AppleAudioConfiguration = {\n audioCategory?: AppleAudioCategory;\n audioCategoryOptions?: AppleAudioCategoryOption[];\n audioMode?: AppleAudioMode;\n};\n\nexport type AudioTrackState =\n | 'none'\n | 'remoteOnly'\n | 'localOnly'\n | 'localAndRemote';\n\nexport function getDefaultAppleAudioConfigurationForMode(\n mode: AudioTrackState,\n preferSpeakerOutput: boolean = true\n): AppleAudioConfiguration {\n if (mode === 'remoteOnly') {\n return {\n audioCategory: 'playback',\n audioCategoryOptions: ['mixWithOthers'],\n audioMode: 'spokenAudio',\n };\n } else if (mode === 'localAndRemote' || mode === 'localOnly') {\n return {\n audioCategory: 'playAndRecord',\n audioCategoryOptions: ['allowBluetooth', 'mixWithOthers'],\n audioMode: preferSpeakerOutput ? 'videoChat' : 'voiceChat',\n };\n }\n\n return {\n audioCategory: 'soloAmbient',\n audioCategoryOptions: [],\n audioMode: 'default',\n };\n}\n\nexport default class AudioSession {\n /**\n * Applies the provided audio configuration to the underlying AudioSession.\n *\n * Must be called prior to connecting to a Room for the configuration to apply correctly.\n *\n * See also useIOSAudioManagement for automatic configuration of iOS audio options.\n */\n static configureAudio = async (config: AudioConfiguration) => {\n await LivekitReactNative.configureAudio(config);\n };\n\n /**\n * Starts an AudioSession.\n */\n static startAudioSession = async () => {\n await LivekitReactNative.startAudioSession();\n };\n\n /**\n * Stops the existing AudioSession.\n */\n static stopAudioSession = async () => {\n await LivekitReactNative.stopAudioSession();\n };\n\n /**\n * Gets the available audio outputs for use with {@link selectAudioOutput}.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * For Android, will return if available:\n * * \"speaker\"\n * * \"earpiece\"\n * * \"headset\"\n * * \"bluetooth\"\n *\n * ----\n *\n * For iOS, due to OS limitations, the only available types are:\n * * \"default\" - Use default iOS audio routing\n * * \"force_speaker\" - Force audio output through speaker\n *\n * See also {@link showAudioRoutePicker} to display a route picker that\n * can choose between other audio devices (i.e. headset/bluetooth/airplay),\n * or use a library like `react-native-avroutepicker` for a native platform\n * control.\n *\n * @returns the available audio output types\n */\n static getAudioOutputs = async (): Promise<string[]> => {\n if (Platform.OS === 'ios') {\n return ['default', 'force_speaker'];\n } else if (Platform.OS === 'android') {\n return (await LivekitReactNative.getAudioOutputs()) as string[];\n } else {\n return [];\n }\n };\n\n /**\n * Select the provided audio output if available.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * @param deviceId A deviceId retrieved from {@link getAudioOutputs}\n */\n static selectAudioOutput = async (deviceId: string) => {\n await LivekitReactNative.selectAudioOutput(deviceId);\n };\n\n /**\n * iOS only, requires iOS 11+.\n *\n * Displays an AVRoutePickerView for the user to choose their audio output.\n */\n static showAudioRoutePicker = async () => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.showAudioRoutePicker();\n }\n };\n\n static setAppleAudioConfiguration = async (\n config: AppleAudioConfiguration\n ) => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.setAppleAudioConfiguration(config);\n }\n };\n}\n"]}
1
+ {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","LivekitReactNative","Proxy","get","Error","AndroidAudioTypePresets","communication","manageAudioFocus","audioMode","audioFocusMode","audioStreamType","audioAttributesUsageType","audioAttributesContentType","media","getDefaultAppleAudioConfigurationForMode","mode","preferSpeakerOutput","audioCategory","audioCategoryOptions","AudioSession","_defineProperty","config","configureAudio","startAudioSession","stopAudioSession","OS","getAudioOutputs","deviceId","selectAudioOutput","showAudioRoutePicker","setAppleAudioConfiguration"],"sources":["AudioSession.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\nconst LINKING_ERROR =\n `The package '@livekit/react-native' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst LivekitReactNative = NativeModules.LivekitReactNative\n ? NativeModules.LivekitReactNative\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\n/**\n * Configuration for the underlying AudioSession.\n *\n * ----\n * Android specific options:\n *\n * * preferredOutputList - The preferred order in which to automatically select an audio output.\n * This is ignored when an output is manually selected with {@link AudioSession.selectAudioOutput}.\n *\n * By default, the order is set to:\n * 1. `\"bluetooth\"\n * 2. `\"headset\"``\n * 3. `\"speaker\"`\n * 4. `\"earpiece\"`\n *\n * * audioTypeOptions - An {@link AndroidAudioTypeOptions} object which provides the\n * audio options to use on Android.\n *\n * See {@link AndroidAudioTypePresets} for pre-configured values.\n *\n * ----\n * iOS\n *\n * * defaultOutput - The default preferred output to use when a wired headset or bluetooth output is unavailable.\n *\n * By default, this is set to `\"speaker\"`\n */\nexport type AudioConfiguration = {\n android?: {\n preferredOutputList?: ('speaker' | 'earpiece' | 'headset' | 'bluetooth')[];\n audioTypeOptions: AndroidAudioTypeOptions;\n };\n ios?: {\n defaultOutput?: 'speaker' | 'earpiece';\n };\n};\n\nexport type AndroidAudioTypeOptions = {\n /**\n * Whether LiveKit should handle managing the audio focus or not.\n *\n * Defaults to true.\n */\n manageAudioFocus?: boolean;\n\n /**\n * Corresponds to {@link https://developer.android.com/reference/android/media/AudioManager#setMode(int)}\n *\n * Defaults to 'inCommunication'.\n */\n audioMode?:\n | 'normal'\n | 'callScreening'\n | 'inCall'\n | 'inCommunication'\n | 'ringtone';\n\n /**\n * Corresponds to the duration hint when requesting audio focus.\n *\n * Defaults to 'gain'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#AUDIOFOCUS_GAIN}\n */\n audioFocusMode?:\n | 'gain'\n | 'gainTransient'\n | 'gainTransientExclusive'\n | 'gainTransientMayDuck';\n\n /**\n * Corresponds to Android's AudioAttributes usage type.\n *\n * Defaults to 'voiceCommunication'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesUsageType?:\n | 'alarm'\n | 'assistanceAccessibility'\n | 'assistanceNavigationGuidance'\n | 'assistanceSonification'\n | 'assistant'\n | 'game'\n | 'media'\n | 'notification'\n | 'notificationEvent'\n | 'notificationRingtone'\n | 'unknown'\n | 'voiceCommunication'\n | 'voiceCommunicationSignalling';\n\n /**\n * Corresponds to Android's AndroidAttributes content type.\n *\n * Defaults to 'speech'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesContentType?:\n | 'movie'\n | 'music'\n | 'sonification'\n | 'speech'\n | 'unknown';\n\n /**\n * Corresponds to the stream type when requesting audio focus. Used on pre-O devices.\n *\n * Defaults to 'voiceCall'\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#STREAM_VOICE_CALL}\n */\n audioStreamType?:\n | 'accessibility'\n | 'alarm'\n | 'dtmf'\n | 'music'\n | 'notification'\n | 'ring'\n | 'system'\n | 'voiceCall';\n\n /**\n * On certain Android devices, audio routing does not function properly and\n * bluetooth microphones will not work unless audio mode is set to\n * `inCommunication` or `inCall`. Audio routing is turned off those cases.\n *\n * If this set to true, will attempt to do audio routing regardless of audio mode.\n *\n * Defaults to false.\n */\n forceHandleAudioRouting?: boolean;\n};\n\nexport const AndroidAudioTypePresets: {\n /**\n * A pre-configured AndroidAudioConfiguration for voice communication.\n */\n communication: AndroidAudioTypeOptions;\n /**\n * A pre-configured AndroidAudioConfiguration for media playback.\n */\n media: AndroidAudioTypeOptions;\n} = {\n communication: {\n manageAudioFocus: true,\n audioMode: 'inCommunication',\n audioFocusMode: 'gain',\n audioStreamType: 'voiceCall',\n audioAttributesUsageType: 'voiceCommunication',\n audioAttributesContentType: 'speech',\n },\n media: {\n manageAudioFocus: true,\n audioMode: 'normal',\n audioFocusMode: 'gain',\n audioStreamType: 'music',\n audioAttributesUsageType: 'media',\n audioAttributesContentType: 'unknown',\n },\n} as const;\n\nexport type AppleAudioMode =\n | 'default'\n | 'gameChat'\n | 'measurement'\n | 'moviePlayback'\n | 'spokenAudio'\n | 'videoChat'\n | 'videoRecording'\n | 'voiceChat'\n | 'voicePrompt';\n\nexport type AppleAudioCategory =\n | 'soloAmbient'\n | 'playback'\n | 'record'\n | 'playAndRecord'\n | 'multiRoute';\n\nexport type AppleAudioCategoryOption =\n | 'mixWithOthers'\n | 'duckOthers'\n | 'interruptSpokenAudioAndMixWithOthers'\n | 'allowBluetooth'\n | 'allowBluetoothA2DP'\n | 'allowAirPlay'\n | 'defaultToSpeaker';\n\nexport type AppleAudioConfiguration = {\n audioCategory?: AppleAudioCategory;\n audioCategoryOptions?: AppleAudioCategoryOption[];\n audioMode?: AppleAudioMode;\n};\n\nexport type AudioTrackState =\n | 'none'\n | 'remoteOnly'\n | 'localOnly'\n | 'localAndRemote';\n\nexport function getDefaultAppleAudioConfigurationForMode(\n mode: AudioTrackState,\n preferSpeakerOutput: boolean = true\n): AppleAudioConfiguration {\n if (mode === 'remoteOnly') {\n return {\n audioCategory: 'playback',\n audioCategoryOptions: ['mixWithOthers'],\n audioMode: 'spokenAudio',\n };\n } else if (mode === 'localAndRemote' || mode === 'localOnly') {\n return {\n audioCategory: 'playAndRecord',\n audioCategoryOptions: ['allowBluetooth', 'mixWithOthers'],\n audioMode: preferSpeakerOutput ? 'videoChat' : 'voiceChat',\n };\n }\n\n return {\n audioCategory: 'soloAmbient',\n audioCategoryOptions: [],\n audioMode: 'default',\n };\n}\n\nexport default class AudioSession {\n /**\n * Applies the provided audio configuration to the underlying AudioSession.\n *\n * Must be called prior to connecting to a Room for the configuration to apply correctly.\n *\n * See also useIOSAudioManagement for automatic configuration of iOS audio options.\n */\n static configureAudio = async (config: AudioConfiguration) => {\n await LivekitReactNative.configureAudio(config);\n };\n\n /**\n * Starts an AudioSession.\n */\n static startAudioSession = async () => {\n await LivekitReactNative.startAudioSession();\n };\n\n /**\n * Stops the existing AudioSession.\n */\n static stopAudioSession = async () => {\n await LivekitReactNative.stopAudioSession();\n };\n\n /**\n * Gets the available audio outputs for use with {@link selectAudioOutput}.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * For Android, will return if available:\n * * \"speaker\"\n * * \"earpiece\"\n * * \"headset\"\n * * \"bluetooth\"\n *\n * ----\n *\n * For iOS, due to OS limitations, the only available types are:\n * * \"default\" - Use default iOS audio routing\n * * \"force_speaker\" - Force audio output through speaker\n *\n * See also {@link showAudioRoutePicker} to display a route picker that\n * can choose between other audio devices (i.e. headset/bluetooth/airplay),\n * or use a library like `react-native-avroutepicker` for a native platform\n * control.\n *\n * @returns the available audio output types\n */\n static getAudioOutputs = async (): Promise<string[]> => {\n if (Platform.OS === 'ios') {\n return ['default', 'force_speaker'];\n } else if (Platform.OS === 'android') {\n return (await LivekitReactNative.getAudioOutputs()) as string[];\n } else {\n return [];\n }\n };\n\n /**\n * Select the provided audio output if available.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * @param deviceId A deviceId retrieved from {@link getAudioOutputs}\n */\n static selectAudioOutput = async (deviceId: string) => {\n await LivekitReactNative.selectAudioOutput(deviceId);\n };\n\n /**\n * iOS only, requires iOS 11+.\n *\n * Displays an AVRoutePickerView for the user to choose their audio output.\n */\n static showAudioRoutePicker = async () => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.showAudioRoutePicker();\n }\n };\n\n static setAppleAudioConfiguration = async (\n config: AppleAudioConfiguration\n ) => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.setAppleAudioConfiguration(config);\n }\n };\n}\n"],"mappings":";;;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,MAAMC,aAAa,GACjB,gFAAgF,GAChFD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,6CAA6C;AAE/C,MAAMC,kBAAkB,GAAGN,aAAa,CAACM,kBAAkB,GACvDN,aAAa,CAACM,kBAAkB,GAChC,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA6GA,OAAO,MAAMQ,uBASZ,GAAG;EACFC,aAAa,EAAE;IACbC,gBAAgB,EAAE,IAAI;IACtBC,SAAS,EAAE,iBAAiB;IAC5BC,cAAc,EAAE,MAAM;IACtBC,eA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AAC;AAC7C,CAAC;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAvBEJ,eAAA,CA1BmBD,YAAY,qBAkDN,YAA+B;EACtD,IAAIvB,QAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC;EACrC,CAAC,MAAM,IAAI7B,QAAQ,CAAC6B,EAAE,KAAK,SAAS,EAAE;IACpC,OAAQ,MAAMxB,kBAAkB,CAACyB,eAAe,CAAC,CAAC;EACpD,CAAC,MAAM;IACL,OAAO,EAAE;EACX;AACF,CAAC;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AANEN,eAAA,CA5DmBD,YAAY,uBAmEJ,MAAOQ,QAAgB,IAAK;EACrD,MAAM1B,kBAAkB,CAAC2B,iBAAiB,CAACD,QAAQ,CAAC;AACtD,CAAC;AAED;AACF;AACA;AACA;AACA;AAJEP,eAAA,CAvEmBD,YAAY,0BA4ED,YAAY;EACxC,IAAIvB,QAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,MAAMxB,kBAAkB,CAAC4B,oBAAoB,CAAC,CAAC;EACjD;AACF,CAAC;AAAAT,eAAA,CAhFkBD,YAAY,gCAkFK,MAClCE,MAA+B,IAC5B;EACH,IAAIzB,QAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,MAAMxB,kBAAkB,CAAC6B,0BAA0B,CAACT,MAAM,CAAC;EAC7D;AACF,CAAC","ignoreList":[]}
@@ -1,5 +1,6 @@
1
1
  import { LKFeatureContext, RoomContext, useLiveKitRoom } from '@livekit/components-react';
2
2
  import * as React from 'react';
3
+
3
4
  /** @public */
4
5
 
5
6
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["LiveKitRoom.tsx"],"names":["LKFeatureContext","RoomContext","useLiveKitRoom","React","LiveKitRoom","props","room","featureFlags","children"],"mappings":"AAAA,SAEEA,gBAFF,EAGEC,WAHF,EAIEC,cAJF,QAKO,2BALP;AAcA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AAEA;;AAuEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAT,CAAqBC,KAArB,EAAuE;AAC5E,QAAM;AAAEC,IAAAA;AAAF,MAAWJ,cAAc,CAACG,KAAD,CAA/B;AACA,sBACE,0CACGC,IAAI,iBACH,oBAAC,WAAD,CAAa,QAAb;AAAsB,IAAA,KAAK,EAAEA;AAA7B,kBACE,oBAAC,gBAAD,CAAkB,QAAlB;AAA2B,IAAA,KAAK,EAAED,KAAK,CAACE;AAAxC,KACGF,KAAK,CAACG,QADT,CADF,CAFJ,CADF;AAWD","sourcesContent":["import {\n FeatureFlags,\n LKFeatureContext,\n RoomContext,\n useLiveKitRoom,\n} from '@livekit/components-react';\nimport type {\n AudioCaptureOptions,\n RoomConnectOptions,\n RoomOptions,\n ScreenShareCaptureOptions,\n VideoCaptureOptions,\n} from 'livekit-client';\nimport type { MediaDeviceFailure, Room } from 'livekit-client';\nimport * as React from 'react';\n\n/** @public */\nexport interface LiveKitRoomProps {\n /**\n * URL to the LiveKit server.\n * For example: `wss://<domain>.livekit.cloud`\n * To simplify the implementation, `undefined` is also accepted as an intermediate value, but only with a valid string url can the connection be established.\n */\n serverUrl: string | undefined;\n /**\n * A user specific access token for a client to authenticate to the room.\n * This token is necessary to establish a connection to the room.\n * To simplify the implementation, `undefined` is also accepted as an intermediate value, but only with a valid string token can the connection be established.\n *\n * @see https://docs.livekit.io/cloud/project-management/keys-and-tokens/#generating-access-tokens\n */\n token: string | undefined;\n /**\n * Publish audio immediately after connecting to your LiveKit room.\n * @defaultValue `false`\n * @see https://docs.livekit.io/client-sdk-js/interfaces/AudioCaptureOptions.html\n */\n audio?: AudioCaptureOptions | boolean;\n /**\n * Publish video immediately after connecting to your LiveKit room.\n * @defaultValue `false`\n * @see https://docs.livekit.io/client-sdk-js/interfaces/VideoCaptureOptions.html\n */\n video?: VideoCaptureOptions | boolean;\n /**\n * Publish screen share immediately after connecting to your LiveKit room.\n * @defaultValue `false`\n * @see https://docs.livekit.io/client-sdk-js/interfaces/ScreenShareCaptureOptions.html\n */\n screen?: ScreenShareCaptureOptions | boolean;\n /**\n * If set to true a connection to LiveKit room is initiated.\n * @defaultValue `false`\n */\n connect?: boolean;\n /**\n * Options for when creating a new room.\n * When you pass your own room instance to this component, these options have no effect.\n * Instead, set the options directly in the room instance.\n *\n * @see https://docs.livekit.io/client-sdk-js/interfaces/RoomOptions.html\n */\n options?: RoomOptions;\n /**\n * Define options how to connect to the LiveKit server.\n *\n * @see https://docs.livekit.io/client-sdk-js/interfaces/RoomConnectOptions.html\n */\n connectOptions?: RoomConnectOptions;\n onConnected?: () => void;\n onDisconnected?: () => void;\n onError?: (error: Error) => void;\n onMediaDeviceFailure?: (failure?: MediaDeviceFailure) => void;\n onEncryptionError?: (error: Error) => void;\n /**\n * Optional room instance.\n * By passing your own room instance you overwrite the `options` parameter,\n * make sure to set the options directly on the room instance itself.\n */\n room?: Room;\n\n simulateParticipants?: number | undefined;\n\n /** @experimental */\n featureFlags?: FeatureFlags | undefined;\n}\n\n/**\n * The `LiveKitRoom` component provides the room context to all its child components.\n * It is generally the starting point of your LiveKit app and the root of the LiveKit component tree.\n * It provides the room state as a React context to all child components, so you don't have to pass it yourself.\n *\n * @example\n * ```tsx\n * <LiveKitRoom\n * token='<livekit-token>'\n * serverUrl='<url-to-livekit-server>'\n * connect={true}\n * >\n * ...\n * </LiveKitRoom>\n * ```\n * @public\n */\nexport function LiveKitRoom(props: React.PropsWithChildren<LiveKitRoomProps>) {\n const { room } = useLiveKitRoom(props);\n return (\n <>\n {room && (\n <RoomContext.Provider value={room}>\n <LKFeatureContext.Provider value={props.featureFlags}>\n {props.children}\n </LKFeatureContext.Provider>\n </RoomContext.Provider>\n )}\n </>\n );\n}\n"]}
1
+ {"version":3,"names":["LKFeatureContext","RoomContext","useLiveKitRoom","React","LiveKitRoom","props","room","createElement","Fragment","Provider","value","featureFlags","children"],"sources":["LiveKitRoom.tsx"],"sourcesContent":["import {\n type FeatureFlags,\n LKFeatureContext,\n RoomContext,\n useLiveKitRoom,\n} from '@livekit/components-react';\nimport type {\n AudioCaptureOptions,\n RoomConnectOptions,\n RoomOptions,\n ScreenShareCaptureOptions,\n VideoCaptureOptions,\n} from 'livekit-client';\nimport type { MediaDeviceFailure, Room } from 'livekit-client';\nimport * as React from 'react';\n\n/** @public */\nexport interface LiveKitRoomProps {\n /**\n * URL to the LiveKit server.\n * For example: `wss://<domain>.livekit.cloud`\n * To simplify the implementation, `undefined` is also accepted as an intermediate value, but only with a valid string url can the connection be established.\n */\n serverUrl: string | undefined;\n /**\n * A user specific access token for a client to authenticate to the room.\n * This token is necessary to establish a connection to the room.\n * To simplify the implementation, `undefined` is also accepted as an intermediate value, but only with a valid string token can the connection be established.\n *\n * @see https://docs.livekit.io/cloud/project-management/keys-and-tokens/#generating-access-tokens\n */\n token: string | undefined;\n /**\n * Publish audio immediately after connecting to your LiveKit room.\n * @defaultValue `false`\n * @see https://docs.livekit.io/client-sdk-js/interfaces/AudioCaptureOptions.html\n */\n audio?: AudioCaptureOptions | boolean;\n /**\n * Publish video immediately after connecting to your LiveKit room.\n * @defaultValue `false`\n * @see https://docs.livekit.io/client-sdk-js/interfaces/VideoCaptureOptions.html\n */\n video?: VideoCaptureOptions | boolean;\n /**\n * Publish screen share immediately after connecting to your LiveKit room.\n * @defaultValue `false`\n * @see https://docs.livekit.io/client-sdk-js/interfaces/ScreenShareCaptureOptions.html\n */\n screen?: ScreenShareCaptureOptions | boolean;\n /**\n * If set to true a connection to LiveKit room is initiated.\n * @defaultValue `false`\n */\n connect?: boolean;\n /**\n * Options for when creating a new room.\n * When you pass your own room instance to this component, these options have no effect.\n * Instead, set the options directly in the room instance.\n *\n * @see https://docs.livekit.io/client-sdk-js/interfaces/RoomOptions.html\n */\n options?: RoomOptions;\n /**\n * Define options how to connect to the LiveKit server.\n *\n * @see https://docs.livekit.io/client-sdk-js/interfaces/RoomConnectOptions.html\n */\n connectOptions?: RoomConnectOptions;\n onConnected?: () => void;\n onDisconnected?: () => void;\n onError?: (error: Error) => void;\n onMediaDeviceFailure?: (failure?: MediaDeviceFailure) => void;\n onEncryptionError?: (error: Error) => void;\n /**\n * Optional room instance.\n * By passing your own room instance you overwrite the `options` parameter,\n * make sure to set the options directly on the room instance itself.\n */\n room?: Room;\n\n simulateParticipants?: number | undefined;\n\n /** @experimental */\n featureFlags?: FeatureFlags | undefined;\n}\n\n/**\n * The `LiveKitRoom` component provides the room context to all its child components.\n * It is generally the starting point of your LiveKit app and the root of the LiveKit component tree.\n * It provides the room state as a React context to all child components, so you don't have to pass it yourself.\n *\n * @example\n * ```tsx\n * <LiveKitRoom\n * token='<livekit-token>'\n * serverUrl='<url-to-livekit-server>'\n * connect={true}\n * >\n * ...\n * </LiveKitRoom>\n * ```\n * @public\n */\nexport function LiveKitRoom(props: React.PropsWithChildren<LiveKitRoomProps>) {\n const { room } = useLiveKitRoom(props);\n return (\n <>\n {room && (\n <RoomContext.Provider value={room}>\n <LKFeatureContext.Provider value={props.featureFlags}>\n {props.children}\n </LKFeatureContext.Provider>\n </RoomContext.Provider>\n )}\n </>\n );\n}\n"],"mappings":"AAAA,SAEEA,gBAAgB,EAChBC,WAAW,EACXC,cAAc,QACT,2BAA2B;AASlC,OAAO,KAAKC,KAAK,MAAM,OAAO;;AAE9B;;AAuEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CAACC,KAAgD,EAAE;EAC5E,MAAM;IAAEC;EAAK,CAAC,GAAGJ,cAAc,CAACG,KAAK,CAAC;EACtC,oBACEF,KAAA,CAAAI,aAAA,CAAAJ,KAAA,CAAAK,QAAA,QACGF,IAAI,iBACHH,KAAA,CAAAI,aAAA,CAACN,WAAW,CAACQ,QAAQ;IAACC,KAAK,EAAEJ;EAAK,gBAChCH,KAAA,CAAAI,aAAA,CAACP,gBAAgB,CAACS,QAAQ;IAACC,KAAK,EAAEL,KAAK,CAACM;EAAa,GAClDN,KAAK,CAACO,QACkB,CACP,CAExB,CAAC;AAEP","ignoreList":[]}