@signalwire/js 3.7.1-dev.202201311747.da5ddf5.0 → 3.9.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.
- package/dist/core/src/BaseComponent.d.ts +25 -12
- package/dist/core/src/BaseComponent.d.ts.map +1 -1
- package/dist/core/src/BaseJWTSession.d.ts +1 -0
- package/dist/core/src/BaseJWTSession.d.ts.map +1 -1
- package/dist/core/src/BaseSession.d.ts +3 -0
- package/dist/core/src/BaseSession.d.ts.map +1 -1
- package/dist/core/src/chat/BaseChat.d.ts +3 -5
- package/dist/core/src/chat/BaseChat.d.ts.map +1 -1
- package/dist/core/src/chat/ChatMember.d.ts +6 -0
- package/dist/core/src/chat/ChatMember.d.ts.map +1 -1
- package/dist/core/src/chat/ChatMessage.d.ts +9 -0
- package/dist/core/src/chat/ChatMessage.d.ts.map +1 -1
- package/dist/core/src/chat/index.d.ts +1 -0
- package/dist/core/src/chat/index.d.ts.map +1 -1
- package/dist/core/src/chat/methods.d.ts +18 -15
- package/dist/core/src/chat/methods.d.ts.map +1 -1
- package/dist/core/src/chat/workers.d.ts +2 -1
- package/dist/core/src/chat/workers.d.ts.map +1 -1
- package/dist/core/src/index.d.ts +3 -3
- package/dist/core/src/index.d.ts.map +1 -1
- package/dist/core/src/redux/actions.d.ts +6 -4
- package/dist/core/src/redux/actions.d.ts.map +1 -1
- package/dist/core/src/redux/features/pubSub/pubSubSaga.d.ts.map +1 -1
- package/dist/core/src/redux/features/session/sessionSlice.d.ts +5 -5
- package/dist/core/src/redux/index.d.ts +4 -1
- package/dist/core/src/redux/index.d.ts.map +1 -1
- package/dist/core/src/redux/interfaces.d.ts +4 -3
- package/dist/core/src/redux/interfaces.d.ts.map +1 -1
- package/dist/core/src/redux/rootReducer.d.ts +1 -1
- package/dist/core/src/redux/rootSaga.d.ts +16 -7
- package/dist/core/src/redux/rootSaga.d.ts.map +1 -1
- package/dist/core/src/rooms/methods.d.ts +45 -22
- package/dist/core/src/rooms/methods.d.ts.map +1 -1
- package/dist/core/src/testUtils.d.ts +4 -1
- package/dist/core/src/testUtils.d.ts.map +1 -1
- package/dist/core/src/types/chat.d.ts +11 -6
- package/dist/core/src/types/chat.d.ts.map +1 -1
- package/dist/core/src/types/index.d.ts +1 -0
- package/dist/core/src/types/index.d.ts.map +1 -1
- package/dist/core/src/types/video.d.ts +2 -0
- package/dist/core/src/types/video.d.ts.map +1 -1
- package/dist/core/src/types/videoLayout.d.ts +2 -0
- package/dist/core/src/types/videoLayout.d.ts.map +1 -1
- package/dist/core/src/types/videoMember.d.ts +10 -1
- package/dist/core/src/types/videoMember.d.ts.map +1 -1
- package/dist/core/src/types/videoRoomSession.d.ts +1 -3
- package/dist/core/src/types/videoRoomSession.d.ts.map +1 -1
- package/dist/core/src/utils/constants.d.ts +1 -0
- package/dist/core/src/utils/constants.d.ts.map +1 -1
- package/dist/core/src/utils/index.d.ts +5 -1
- package/dist/core/src/utils/index.d.ts.map +1 -1
- package/dist/core/src/utils/interfaces.d.ts +17 -8
- package/dist/core/src/utils/interfaces.d.ts.map +1 -1
- package/dist/core/src/utils/proxyUtils.d.ts +5 -0
- package/dist/core/src/utils/proxyUtils.d.ts.map +1 -1
- package/dist/index.esm.js +188 -52
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +231 -103
- package/dist/index.js.map +3 -3
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/js/src/BaseRoomSession.d.ts +7 -0
- package/dist/js/src/BaseRoomSession.d.ts.map +1 -1
- package/dist/js/src/JWTSession.d.ts.map +1 -1
- package/dist/js/src/RoomSession.d.ts.map +1 -1
- package/dist/js/src/RoomSession.docs.d.ts +21 -8
- package/dist/js/src/RoomSession.docs.d.ts.map +1 -1
- package/dist/js/src/chat/Client.d.ts +37 -3
- package/dist/js/src/chat/Client.d.ts.map +1 -1
- package/dist/js/src/chat/Client.docs.d.ts +238 -0
- package/dist/js/src/chat/Client.docs.d.ts.map +1 -0
- package/dist/js/src/chat/index.d.ts +5 -0
- package/dist/js/src/chat/index.d.ts.map +1 -1
- package/dist/js/src/index.d.ts +13 -9
- package/dist/js/src/index.d.ts.map +1 -1
- package/dist/js/src/testUtils.d.ts +8 -2
- package/dist/js/src/testUtils.d.ts.map +1 -1
- package/dist/js/src/utils/interfaces.d.ts +18 -2
- package/dist/js/src/utils/interfaces.d.ts.map +1 -1
- package/dist/js/src/video/memberListUpdatedWorker.d.ts +14 -0
- package/dist/js/src/video/memberListUpdatedWorker.d.ts.map +1 -0
- package/dist/js/src/video/workers.d.ts +2 -0
- package/dist/js/src/video/workers.d.ts.map +1 -0
- package/dist/js/src/video.d.ts +3 -3
- package/dist/js/src/video.d.ts.map +1 -1
- package/dist/js/src/webrtc.d.ts +1 -1
- package/dist/js/src/webrtc.d.ts.map +1 -1
- package/dist/js/tsconfig.build.tsbuildinfo +1 -1
- package/dist/webrtc/src/BaseConnection.d.ts.map +1 -1
- package/dist/webrtc/src/index.d.ts +1 -1
- package/dist/webrtc/src/index.d.ts.map +1 -1
- package/dist/webrtc/src/utils/deviceHelpers.d.ts +45 -0
- package/dist/webrtc/src/utils/deviceHelpers.d.ts.map +1 -1
- package/dist/webrtc/src/utils/interfaces.d.ts +3 -0
- package/dist/webrtc/src/utils/interfaces.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/BaseRoomSession.test.ts +2 -2
- package/src/BaseRoomSession.ts +26 -1
- package/src/RoomSession.docs.ts +61 -13
- package/src/RoomSession.ts +18 -4
- package/src/chat/Client.docs.ts +259 -0
- package/src/chat/Client.ts +37 -10
- package/src/chat/index.ts +10 -0
- package/src/index.ts +14 -10
- package/src/utils/interfaces.ts +25 -2
- package/src/video/memberListUpdatedWorker.ts +217 -0
- package/src/video/workers.ts +1 -0
- package/src/video.ts +3 -2
- package/src/webrtc.ts +1 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sagaEffects,
|
|
3
|
+
SagaIterator,
|
|
4
|
+
SDKWorker,
|
|
5
|
+
toSyntheticEvent,
|
|
6
|
+
validateEventsToSubscribe,
|
|
7
|
+
toInternalEventName,
|
|
8
|
+
PubSubChannel,
|
|
9
|
+
InternalVideoMemberEntity,
|
|
10
|
+
InternalVideoMemberUpdatedEvent,
|
|
11
|
+
VideoMemberJoinedEvent,
|
|
12
|
+
VideoMemberLeftEvent,
|
|
13
|
+
VideoMemberUpdatedEvent,
|
|
14
|
+
InternalVideoRoomJoinedEvent,
|
|
15
|
+
MapToPubSubShape,
|
|
16
|
+
} from '@signalwire/core'
|
|
17
|
+
import type { RoomSession } from '../RoomSession'
|
|
18
|
+
import type { VideoMemberListUpdatedParams } from '../utils/interfaces'
|
|
19
|
+
|
|
20
|
+
const noop = () => {}
|
|
21
|
+
|
|
22
|
+
const EXTERNAL_MEMBER_LIST_UPDATED_EVENT = 'video.memberList.updated'
|
|
23
|
+
|
|
24
|
+
const INTERNAL_MEMBER_LIST_UPDATED_EVENT = toInternalEventName({
|
|
25
|
+
event: EXTERNAL_MEMBER_LIST_UPDATED_EVENT,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const SYNTHETIC_MEMBER_LIST_UPDATED_EVENT = toSyntheticEvent(
|
|
29
|
+
INTERNAL_MEMBER_LIST_UPDATED_EVENT
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* List of action types this worker cares about.
|
|
34
|
+
*/
|
|
35
|
+
type MemberListUpdatedTargetActions = MapToPubSubShape<
|
|
36
|
+
| InternalVideoRoomJoinedEvent
|
|
37
|
+
| InternalVideoMemberUpdatedEvent
|
|
38
|
+
| VideoMemberJoinedEvent
|
|
39
|
+
| VideoMemberLeftEvent
|
|
40
|
+
| VideoMemberUpdatedEvent
|
|
41
|
+
>
|
|
42
|
+
|
|
43
|
+
const MEMBER_LIST_EVENTS: Array<MemberListUpdatedTargetActions['type']> = [
|
|
44
|
+
/** Alias to `video.room.subscribed` */
|
|
45
|
+
'video.room.joined',
|
|
46
|
+
'video.member.joined',
|
|
47
|
+
'video.member.left',
|
|
48
|
+
'video.member.updated',
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
type MemberList = Map<string, InternalVideoMemberEntity>
|
|
52
|
+
|
|
53
|
+
const isMemberListEvent = (
|
|
54
|
+
event: string
|
|
55
|
+
): event is MemberListUpdatedTargetActions['type'] => {
|
|
56
|
+
// @ts-expect-error
|
|
57
|
+
return MEMBER_LIST_EVENTS.includes(event)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const getMemberListEventsToSubscribe = (subscriptions: MemberListUpdatedTargetActions['type'][]) => {
|
|
61
|
+
return validateEventsToSubscribe(MEMBER_LIST_EVENTS).filter((event) => {
|
|
62
|
+
return !subscriptions.includes(event)
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const shouldHandleMemberList = (subscriptions: string[]) => {
|
|
67
|
+
return subscriptions.some((event) =>
|
|
68
|
+
event.includes(INTERNAL_MEMBER_LIST_UPDATED_EVENT)
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const getMembersFromAction = (action: MemberListUpdatedTargetActions) => {
|
|
73
|
+
if (action.type === 'video.room.joined') {
|
|
74
|
+
return action.payload.room_session.members
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return [action.payload.member]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const getUpdatedMembers = ({
|
|
81
|
+
action,
|
|
82
|
+
memberList,
|
|
83
|
+
}: {
|
|
84
|
+
action: MemberListUpdatedTargetActions
|
|
85
|
+
memberList: MemberList
|
|
86
|
+
}) => {
|
|
87
|
+
const actionMembers = getMembersFromAction(action)
|
|
88
|
+
|
|
89
|
+
switch (action.type) {
|
|
90
|
+
case 'video.member.left':
|
|
91
|
+
actionMembers.forEach((member: InternalVideoMemberEntity) => {
|
|
92
|
+
memberList.delete(member.id)
|
|
93
|
+
})
|
|
94
|
+
break
|
|
95
|
+
default:
|
|
96
|
+
actionMembers.forEach((member: InternalVideoMemberEntity) => {
|
|
97
|
+
memberList.set(member.id, member)
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return Array.from(memberList.values())
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const initMemberListSubscriptions = (
|
|
105
|
+
room: RoomSession,
|
|
106
|
+
subscriptions: MemberListUpdatedTargetActions['type'][]
|
|
107
|
+
) => {
|
|
108
|
+
const events = getMemberListEventsToSubscribe(subscriptions)
|
|
109
|
+
|
|
110
|
+
events.forEach((event) => {
|
|
111
|
+
/**
|
|
112
|
+
* Params to `subscribe` come from the event handlers
|
|
113
|
+
* the user has attached so to make sure we subscribe to
|
|
114
|
+
* all the appropiate events needed for
|
|
115
|
+
* `memberList.updated` to work, we must subscribe to
|
|
116
|
+
* the required events. We don't need to act upon the
|
|
117
|
+
* event (that's why we attach a `noop`), just to
|
|
118
|
+
* register it (`subscribe` gets its values from
|
|
119
|
+
* `BaseComponent.getSubscriptions`, which gets
|
|
120
|
+
* populated by each of the event handlers the user
|
|
121
|
+
* attached).
|
|
122
|
+
*/
|
|
123
|
+
room.once(event as any, noop)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* This handler will act as a simple bridge between
|
|
128
|
+
* synthetic events and external events.
|
|
129
|
+
*/
|
|
130
|
+
const eventBridgeHandler = ({ members }: VideoMemberListUpdatedParams) => {
|
|
131
|
+
// @ts-expect-error
|
|
132
|
+
room.emit(EXTERNAL_MEMBER_LIST_UPDATED_EVENT, { members })
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// @ts-expect-error
|
|
136
|
+
room.on(SYNTHETIC_MEMBER_LIST_UPDATED_EVENT, eventBridgeHandler)
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Any events attached by the saga should be specified
|
|
140
|
+
* here so it can be cleaned up when needed.
|
|
141
|
+
*/
|
|
142
|
+
const cleanup = () => {
|
|
143
|
+
// @ts-expect-error
|
|
144
|
+
room.off(SYNTHETIC_MEMBER_LIST_UPDATED_EVENT, eventBridgeHandler)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
cleanup,
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function* membersListUpdatedWatcher({
|
|
153
|
+
pubSubChannel,
|
|
154
|
+
}: {
|
|
155
|
+
pubSubChannel: PubSubChannel
|
|
156
|
+
}): SagaIterator {
|
|
157
|
+
const memberList: MemberList = new Map()
|
|
158
|
+
|
|
159
|
+
function* worker(pubSubAction: MemberListUpdatedTargetActions) {
|
|
160
|
+
const roomSessionId =
|
|
161
|
+
pubSubAction.type === 'video.room.joined'
|
|
162
|
+
? pubSubAction.payload.room_session.id
|
|
163
|
+
: pubSubAction.payload.room_session_id
|
|
164
|
+
|
|
165
|
+
const members = getUpdatedMembers({ action: pubSubAction, memberList })
|
|
166
|
+
const memberListPayload = {
|
|
167
|
+
/**
|
|
168
|
+
* At this point it's needed to send the
|
|
169
|
+
* `room_session_id` so the pubSubSaga can properly
|
|
170
|
+
* infer the namespace for emitting the events to the
|
|
171
|
+
* appropiate room.
|
|
172
|
+
*/
|
|
173
|
+
room_session_id: roomSessionId,
|
|
174
|
+
members,
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// TODO: add typings
|
|
178
|
+
yield sagaEffects.put(pubSubChannel, {
|
|
179
|
+
type: SYNTHETIC_MEMBER_LIST_UPDATED_EVENT as any,
|
|
180
|
+
payload: memberListPayload as any,
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
while (true) {
|
|
185
|
+
const pubSubAction: MemberListUpdatedTargetActions = yield sagaEffects.take(
|
|
186
|
+
pubSubChannel,
|
|
187
|
+
({ type }: any) => {
|
|
188
|
+
return isMemberListEvent(type)
|
|
189
|
+
}
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
yield sagaEffects.fork(worker, pubSubAction)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export const memberListUpdatedWorker: SDKWorker<RoomSession> =
|
|
197
|
+
function* membersChangedWorker({
|
|
198
|
+
channels: { pubSubChannel },
|
|
199
|
+
instance,
|
|
200
|
+
}): SagaIterator {
|
|
201
|
+
// @ts-expect-error
|
|
202
|
+
const subscriptions = instance.getSubscriptions()
|
|
203
|
+
|
|
204
|
+
if (!shouldHandleMemberList(subscriptions)) {
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const { cleanup } = initMemberListSubscriptions(instance, subscriptions)
|
|
209
|
+
|
|
210
|
+
yield sagaEffects.fork(membersListUpdatedWatcher, {
|
|
211
|
+
pubSubChannel,
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
instance.once('destroy', () => {
|
|
215
|
+
cleanup()
|
|
216
|
+
})
|
|
217
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./memberListUpdatedWorker"
|
package/src/video.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { createRoomObject, Room } from './createRoomObject'
|
|
|
2
2
|
import { createClient } from './createClient'
|
|
3
3
|
import { joinRoom } from './joinRoom'
|
|
4
4
|
import { MakeRoomOptions } from './Client'
|
|
5
|
-
import { RoomSession } from './RoomSession'
|
|
5
|
+
import { RoomSession, RoomSessionOptions } from './RoomSession'
|
|
6
6
|
import { RoomSessionDevice, RoomDevice } from './RoomSessionDevice'
|
|
7
7
|
import {
|
|
8
8
|
RoomSessionScreenShare,
|
|
@@ -23,7 +23,7 @@ export {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** @ignore */
|
|
26
|
-
export type { MakeRoomOptions }
|
|
26
|
+
export type { MakeRoomOptions, RoomSessionOptions }
|
|
27
27
|
|
|
28
28
|
/** @ignore */
|
|
29
29
|
export type {
|
|
@@ -33,6 +33,7 @@ export type {
|
|
|
33
33
|
DeprecatedMemberUpdatableProps,
|
|
34
34
|
DeprecatedVideoMemberHandlerParams,
|
|
35
35
|
VideoMemberHandlerParams,
|
|
36
|
+
VideoMemberListUpdatedParams,
|
|
36
37
|
} from './utils/interfaces'
|
|
37
38
|
|
|
38
39
|
export type { CreateRoomObjectOptions } from './createRoomObject'
|