@signalwire/js 3.12.0 → 3.12.1

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 (61) hide show
  1. package/dist/core/src/BaseComponent.d.ts +3 -1
  2. package/dist/core/src/BaseComponent.d.ts.map +1 -1
  3. package/dist/core/src/RPCMessages/VertoMessages.d.ts +8 -0
  4. package/dist/core/src/RPCMessages/VertoMessages.d.ts.map +1 -1
  5. package/dist/core/src/index.d.ts +1 -0
  6. package/dist/core/src/index.d.ts.map +1 -1
  7. package/dist/core/src/redux/features/session/sessionSaga.d.ts.map +1 -1
  8. package/dist/core/src/redux/features/session/sessionSelectors.d.ts +1 -0
  9. package/dist/core/src/redux/features/session/sessionSelectors.d.ts.map +1 -1
  10. package/dist/core/src/redux/features/session/sessionSlice.d.ts +65 -0
  11. package/dist/core/src/redux/features/session/sessionSlice.d.ts.map +1 -1
  12. package/dist/core/src/redux/interfaces.d.ts +2 -1
  13. package/dist/core/src/redux/interfaces.d.ts.map +1 -1
  14. package/dist/core/src/redux/rootReducer.d.ts +16 -0
  15. package/dist/core/src/redux/rootReducer.d.ts.map +1 -1
  16. package/dist/core/src/rooms/RoomSessionPlayback.d.ts +3 -0
  17. package/dist/core/src/rooms/RoomSessionPlayback.d.ts.map +1 -1
  18. package/dist/core/src/rooms/methods.d.ts +3 -0
  19. package/dist/core/src/rooms/methods.d.ts.map +1 -1
  20. package/dist/core/src/testUtils.d.ts.map +1 -1
  21. package/dist/core/src/types/common.d.ts +11 -0
  22. package/dist/core/src/types/common.d.ts.map +1 -1
  23. package/dist/core/src/types/videoPlayback.d.ts +5 -0
  24. package/dist/core/src/types/videoPlayback.d.ts.map +1 -1
  25. package/dist/core/src/types/videoRoomSession.d.ts +1 -0
  26. package/dist/core/src/types/videoRoomSession.d.ts.map +1 -1
  27. package/dist/core/src/utils/interfaces.d.ts +7 -5
  28. package/dist/core/src/utils/interfaces.d.ts.map +1 -1
  29. package/dist/index.esm.js +82 -3
  30. package/dist/index.esm.js.map +3 -3
  31. package/dist/index.js +80 -3
  32. package/dist/index.js.map +3 -3
  33. package/dist/index.umd.js +2 -2
  34. package/dist/index.umd.js.map +1 -1
  35. package/dist/js/src/BaseRoomSession.d.ts +5 -0
  36. package/dist/js/src/BaseRoomSession.d.ts.map +1 -1
  37. package/dist/js/src/RoomSession.d.ts +2 -2
  38. package/dist/js/src/RoomSession.d.ts.map +1 -1
  39. package/dist/js/src/RoomSession.docs.d.ts +21 -0
  40. package/dist/js/src/RoomSession.docs.d.ts.map +1 -1
  41. package/dist/js/src/features/mediaElements/mediaElementsSagas.d.ts.map +1 -1
  42. package/dist/js/src/utils/interfaces.d.ts +4 -0
  43. package/dist/js/src/utils/interfaces.d.ts.map +1 -1
  44. package/dist/js/src/utils/roomSession.d.ts +13 -0
  45. package/dist/js/src/utils/roomSession.d.ts.map +1 -0
  46. package/dist/js/src/utils/videoElement.d.ts +1 -0
  47. package/dist/js/src/utils/videoElement.d.ts.map +1 -1
  48. package/dist/js/tsconfig.build.tsbuildinfo +1 -1
  49. package/dist/webrtc/src/BaseConnection.d.ts +8 -0
  50. package/dist/webrtc/src/BaseConnection.d.ts.map +1 -1
  51. package/dist/webrtc/src/utils/interfaces.d.ts +2 -0
  52. package/dist/webrtc/src/utils/interfaces.d.ts.map +1 -1
  53. package/dist/webrtc/src/utils/webrtcHelpers.native.d.ts.map +1 -1
  54. package/package.json +3 -3
  55. package/src/BaseRoomSession.ts +4 -1
  56. package/src/RoomSession.docs.ts +20 -0
  57. package/src/RoomSession.ts +60 -3
  58. package/src/features/mediaElements/mediaElementsSagas.ts +10 -0
  59. package/src/utils/interfaces.ts +5 -0
  60. package/src/utils/roomSession.ts +54 -0
  61. package/src/utils/videoElement.ts +3 -0
@@ -1,10 +1,22 @@
1
- import { UserOptions, AssertSameType, getLogger } from '@signalwire/core'
1
+ import {
2
+ UserOptions,
3
+ AssertSameType,
4
+ getLogger,
5
+ Authorization,
6
+ } from '@signalwire/core'
2
7
  import { createClient } from './createClient'
3
- import type { MakeRoomOptions } from './Client'
4
8
  import { BaseRoomSession } from './BaseRoomSession'
5
- import { RoomSessionDocs } from './RoomSession.docs'
9
+ import {
10
+ getJoinAudienceMediaParams,
11
+ isValidJoinAudienceMediaParams,
12
+ } from './utils/roomSession'
13
+ import type { MakeRoomOptions } from './Client'
14
+ import type { RoomSessionDocs } from './RoomSession.docs'
15
+ import type { RoomSessionJoinAudienceParams } from './utils/interfaces'
6
16
 
7
17
  const VIDEO_CONSTRAINTS: MediaTrackConstraints = {
18
+ width: { ideal: 1280, min: 320 },
19
+ height: { ideal: 720, min: 180 },
8
20
  aspectRatio: { ideal: 16 / 9 },
9
21
  }
10
22
 
@@ -149,8 +161,53 @@ export const RoomSession = function (roomOptions: RoomSessionOptions) {
149
161
  })
150
162
  }
151
163
 
164
+ const joinAudience = (params?: RoomSessionJoinAudienceParams) => {
165
+ return new Promise(async (resolve, reject) => {
166
+ try {
167
+ // @ts-expect-error
168
+ room.attachPreConnectWorkers()
169
+
170
+ const session = await client.connect()
171
+
172
+ // @ts-expect-error
173
+ const authState: Authorization = session._sessionAuthState
174
+ const mediaOptions = getJoinAudienceMediaParams({
175
+ authState,
176
+ ...params,
177
+ })
178
+
179
+ if (!isValidJoinAudienceMediaParams(mediaOptions)) {
180
+ await session.disconnect()
181
+ return reject(
182
+ new Error(
183
+ '[joinAudience] Either (or both) `audio` and `video` must be `true` when calling this method.'
184
+ )
185
+ )
186
+ }
187
+
188
+ // @ts-expect-error
189
+ room.updateMediaOptions(mediaOptions)
190
+
191
+ room.once('room.subscribed', (payload) => {
192
+ // @ts-expect-error
193
+ room.attachOnSubscribedWorkers(payload)
194
+ resolve(room)
195
+ })
196
+
197
+ await room.join()
198
+ } catch (error) {
199
+ getLogger().error('RoomSession JoinAudience', error)
200
+ // Disconnect the underlay client in case of media/signaling errors
201
+ client.disconnect()
202
+
203
+ reject(error)
204
+ }
205
+ })
206
+ }
207
+
152
208
  const interceptors = {
153
209
  join,
210
+ joinAudience,
154
211
  } as const
155
212
 
156
213
  return new Proxy<Omit<RoomSession, 'new'>>(room, {
@@ -42,6 +42,8 @@ export const makeVideoElementSaga = ({
42
42
  * Instead of querying the `document`, let's use our `layerMap`.
43
43
  */
44
44
  const localOverlay: LocalOverlay = {
45
+ // Each `layout.changed` event will update `status`
46
+ status: 'hidden',
45
47
  get id() {
46
48
  return addSDKPrefix(room.memberId)
47
49
  },
@@ -67,6 +69,9 @@ export const makeVideoElementSaga = ({
67
69
  if (!this.domElement) {
68
70
  return getLogger().warn('Missing localOverlay to show')
69
71
  }
72
+ if (this.status === 'hidden') {
73
+ return getLogger().info('localOverlay not visible')
74
+ }
70
75
  this.domElement.style.opacity = '1'
71
76
  },
72
77
  }
@@ -161,6 +166,11 @@ export const makeAudioElementSaga = ({ speakerId }: { speakerId?: string }) => {
161
166
  instance: room,
162
167
  runSaga,
163
168
  }: CustomSagaParams<RoomSessionConnection>): SagaIterator {
169
+ if (typeof Audio === 'undefined') {
170
+ getLogger().warn('`Audio` is not supported on this environment.')
171
+ return
172
+ }
173
+
164
174
  try {
165
175
  const audioEl = new Audio()
166
176
  let audioTask: Task | undefined
@@ -202,3 +202,8 @@ export interface RoomSessionDeviceMethods
202
202
 
203
203
  export interface RoomScreenShareMethods
204
204
  extends RoomMemberSelfMethodsInterface {}
205
+
206
+ export interface RoomSessionJoinAudienceParams {
207
+ audio?: boolean
208
+ video?: boolean
209
+ }
@@ -0,0 +1,54 @@
1
+ import { getLogger } from '@signalwire/core'
2
+ import type { Authorization } from '@signalwire/core'
3
+ import type { RoomSessionJoinAudienceParams } from './interfaces'
4
+
5
+ // `joinAudience` utils
6
+ const getJoinAudienceMediaParams = ({
7
+ authState,
8
+ audio = true,
9
+ video = true,
10
+ }: RoomSessionJoinAudienceParams & {
11
+ authState: Authorization
12
+ }) => {
13
+ const getMediaValue = ({
14
+ remote,
15
+ local,
16
+ kind,
17
+ }: {
18
+ remote?: boolean
19
+ local?: boolean
20
+ kind: 'audio' | 'video'
21
+ }) => {
22
+ if (!remote && local) {
23
+ getLogger().warn(
24
+ `[joinAudience] ${kind} is currently not allowed on this room.`
25
+ )
26
+ }
27
+
28
+ return !!(remote && local)
29
+ }
30
+
31
+ return {
32
+ audio: false,
33
+ video: false,
34
+ negotiateAudio: getMediaValue({
35
+ remote: authState.audio_allowed,
36
+ local: audio,
37
+ kind: 'audio',
38
+ }),
39
+ negotiateVideo: getMediaValue({
40
+ remote: authState.video_allowed,
41
+ local: video,
42
+ kind: 'video',
43
+ }),
44
+ }
45
+ }
46
+
47
+ const isValidJoinAudienceMediaParams = (
48
+ options: Record<string, boolean | undefined>
49
+ ) => {
50
+ // At least one value must be true
51
+ return Object.values(options).some(Boolean)
52
+ }
53
+
54
+ export { getJoinAudienceMediaParams, isValidJoinAudienceMediaParams }
@@ -70,6 +70,7 @@ const _buildLayer = ({ location }: { location: InternalVideoLayoutLayer }) => {
70
70
 
71
71
  export interface LocalOverlay {
72
72
  readonly id: string
73
+ status: 'hidden' | 'visible'
73
74
  domElement: HTMLDivElement | undefined
74
75
  hide(): void
75
76
  show(): void
@@ -95,6 +96,8 @@ const makeLayoutChangedHandler =
95
96
  const location = layers.find(({ member_id }) => member_id === myMemberId)
96
97
 
97
98
  let myLayer = localOverlay.domElement
99
+ // Update localOverlay.status if a location has been found
100
+ localOverlay.status = location ? 'visible' : 'hidden'
98
101
  if (!location) {
99
102
  getLogger().debug('Location not found')
100
103
  if (myLayer) {