mediasfu-shared 1.0.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/LICENSE +21 -0
- package/README.md +228 -0
- package/dist/index.cjs +7707 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +7285 -0
- package/dist/index.js +7690 -0
- package/dist/index.js.map +1 -0
- package/package.json +78 -0
- package/src/ProducerClient/producerClientEmits/createDeviceClient.ts +68 -0
- package/src/consumers/addVideosGrid.ts +18 -0
- package/src/consumers/autoAdjust.ts +100 -0
- package/src/consumers/calculateRowsAndColumns.ts +51 -0
- package/src/consumers/changeVids.ts +753 -0
- package/src/consumers/checkGrid.ts +100 -0
- package/src/consumers/checkPermission.ts +89 -0
- package/src/consumers/checkScreenShare.ts +114 -0
- package/src/consumers/closeAndResize.ts +401 -0
- package/src/consumers/compareActiveNames.ts +122 -0
- package/src/consumers/compareScreenStates.ts +117 -0
- package/src/consumers/connectIps.ts +175 -0
- package/src/consumers/connectLocalIps.ts +103 -0
- package/src/consumers/connectRecvTransport.ts +158 -0
- package/src/consumers/connectSendTransport.ts +150 -0
- package/src/consumers/connectSendTransportAudio.ts +161 -0
- package/src/consumers/connectSendTransportScreen.ts +169 -0
- package/src/consumers/connectSendTransportVideo.ts +149 -0
- package/src/consumers/consumerResume.ts +25 -0
- package/src/consumers/controlMedia.ts +118 -0
- package/src/consumers/createSendTransport.ts +312 -0
- package/src/consumers/disconnectSendTransportAudio.ts +170 -0
- package/src/consumers/disconnectSendTransportScreen.ts +130 -0
- package/src/consumers/disconnectSendTransportVideo.ts +161 -0
- package/src/consumers/dispStreams.ts +694 -0
- package/src/consumers/generatePageContent.ts +118 -0
- package/src/consumers/getEstimate.ts +124 -0
- package/src/consumers/getPipedProducersAlt.ts +96 -0
- package/src/consumers/getProducersPiped.ts +89 -0
- package/src/consumers/getVideos.ts +107 -0
- package/src/consumers/mixStreams.ts +97 -0
- package/src/consumers/onScreenChanges.ts +106 -0
- package/src/consumers/prepopulateUserMedia.ts +18 -0
- package/src/consumers/processConsumerTransports.ts +157 -0
- package/src/consumers/processConsumerTransportsAudio.ts +121 -0
- package/src/consumers/rePort.ts +123 -0
- package/src/consumers/reUpdateInter.ts +289 -0
- package/src/consumers/readjust.ts +170 -0
- package/src/consumers/receiveAllPipedTransports.ts +77 -0
- package/src/consumers/receiveRoomMessages.ts +55 -0
- package/src/consumers/reorderStreams.ts +246 -0
- package/src/consumers/requestScreenShare.ts +103 -0
- package/src/consumers/resumePauseAudioStreams.ts +174 -0
- package/src/consumers/resumePauseStreams.ts +110 -0
- package/src/consumers/resumeSendTransportAudio.ts +143 -0
- package/src/consumers/signalNewConsumerTransport.ts +179 -0
- package/src/consumers/socketReceiveMethods/joinConsumeRoom.ts +130 -0
- package/src/consumers/socketReceiveMethods/newPipeProducer.ts +138 -0
- package/src/consumers/socketReceiveMethods/producerClosed.ts +102 -0
- package/src/consumers/startShareScreen.ts +124 -0
- package/src/consumers/stopShareScreen.ts +241 -0
- package/src/consumers/streamSuccessAudio.ts +297 -0
- package/src/consumers/streamSuccessAudioSwitch.ts +315 -0
- package/src/consumers/streamSuccessScreen.ts +255 -0
- package/src/consumers/streamSuccessVideo.ts +373 -0
- package/src/consumers/switchUserAudio.ts +140 -0
- package/src/consumers/switchUserVideo.ts +201 -0
- package/src/consumers/switchUserVideoAlt.ts +331 -0
- package/src/consumers/trigger.ts +250 -0
- package/src/consumers/updateMiniCardsGrid.ts +150 -0
- package/src/consumers/updateParticipantAudioDecibels.ts +56 -0
- package/src/index.ts +119 -0
- package/src/methods/background/launchBackground.ts +16 -0
- package/src/methods/breakoutRooms/breakoutRoomUpdated.ts +161 -0
- package/src/methods/breakoutRooms/handleStartBreakout.ts +96 -0
- package/src/methods/breakoutRooms/handleStopBreakout.ts +72 -0
- package/src/methods/breakoutRooms/index.ts +4 -0
- package/src/methods/breakoutRooms/launchBreakoutRooms.ts +31 -0
- package/src/methods/coHost/launchCoHost.ts +28 -0
- package/src/methods/coHostMethods/index.ts +2 -0
- package/src/methods/coHostMethods/modifyCoHostSettings.ts +94 -0
- package/src/methods/displaySettings/index.ts +1 -0
- package/src/methods/displaySettings/launchDisplaySettings.ts +31 -0
- package/src/methods/displaySettings/modifyDisplaySettings.ts +242 -0
- package/src/methods/exit/confirmExit.ts +60 -0
- package/src/methods/exit/index.ts +2 -0
- package/src/methods/exit/launchConfirmExit.ts +29 -0
- package/src/methods/index.ts +5 -0
- package/src/methods/mediaSettings/launchMediaSettings.ts +61 -0
- package/src/methods/menu/launchMenuModal.ts +28 -0
- package/src/methods/message/index.ts +1 -0
- package/src/methods/message/launchMessages.ts +27 -0
- package/src/methods/message/sendMessage.ts +175 -0
- package/src/methods/participants/index.ts +3 -0
- package/src/methods/participants/launchParticipants.ts +25 -0
- package/src/methods/participants/messageParticipants.ts +78 -0
- package/src/methods/participants/muteParticipants.ts +79 -0
- package/src/methods/participants/removeParticipants.ts +97 -0
- package/src/methods/polls/handleCreatePoll.ts +66 -0
- package/src/methods/polls/handleEndPoll.ts +64 -0
- package/src/methods/polls/handleVotePoll.ts +76 -0
- package/src/methods/polls/index.ts +3 -0
- package/src/methods/polls/launchPoll.ts +25 -0
- package/src/methods/prejoin/handleCreateRoom.ts +441 -0
- package/src/methods/prejoin/handleJoinRoom.ts +153 -0
- package/src/methods/prejoin/index.ts +14 -0
- package/src/methods/recording/checkPauseState.ts +57 -0
- package/src/methods/recording/checkResumeState.ts +42 -0
- package/src/methods/recording/confirmRecording.ts +241 -0
- package/src/methods/recording/launchRecording.ts +114 -0
- package/src/methods/recording/recordPauseTimer.ts +52 -0
- package/src/methods/recording/recordResumeTimer.ts +92 -0
- package/src/methods/recording/recordStartTimer.ts +106 -0
- package/src/methods/recording/recordUpdateTimer.ts +49 -0
- package/src/methods/recording/startRecording.ts +268 -0
- package/src/methods/recording/stopRecording.ts +124 -0
- package/src/methods/recording/updateRecording.ts +245 -0
- package/src/methods/requests/index.ts +1 -0
- package/src/methods/requests/launchRequests.ts +25 -0
- package/src/methods/requests/respondToRequests.ts +108 -0
- package/src/methods/settings/index.ts +2 -0
- package/src/methods/settings/launchSettings.ts +25 -0
- package/src/methods/settings/modifySettings.ts +99 -0
- package/src/methods/stream/clickVideo.ts +337 -0
- package/src/methods/stream/index.ts +3 -0
- package/src/methods/stream/switchAudio.ts +73 -0
- package/src/methods/stream/switchVideo.ts +148 -0
- package/src/methods/stream/switchVideoAlt.ts +152 -0
- package/src/methods/utils/checkLimitsAndMakeRequest.ts +103 -0
- package/src/methods/utils/validateAlphanumeric.ts +41 -0
- package/src/methods/waiting/index.ts +1 -0
- package/src/methods/waiting/launchWaiting.ts +26 -0
- package/src/methods/waiting/respondToWaiting.ts +82 -0
- package/src/methods/welcome/handleWelcomeRequest.ts +189 -0
- package/src/methods/welcome/index.ts +5 -0
- package/src/methods/whiteboard/handleStartWhiteboard.ts +65 -0
- package/src/methods/whiteboard/handleStopWhiteboard.ts +48 -0
- package/src/methods/whiteboard/index.ts +4 -0
- package/src/methods/whiteboard/launchConfigureWhiteboard.ts +29 -0
- package/src/producers/producerEmits/joinConRoom.ts +153 -0
- package/src/sockets/SocketManager.ts +232 -0
- package/src/types/shared-base-types.ts +752 -0
- package/src/types/types.ts +84 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
|
|
2
|
+
import { Participant, Stream, ChangeVidsParameters, ChangeVidsType } from "../types/types";
|
|
3
|
+
|
|
4
|
+
export interface ReorderStreamsParameters extends ChangeVidsParameters {
|
|
5
|
+
allVideoStreams: (Stream | Participant)[];
|
|
6
|
+
participants: Participant[];
|
|
7
|
+
oldAllStreams: (Stream | Participant)[];
|
|
8
|
+
screenId?: string;
|
|
9
|
+
adminVidID?: string;
|
|
10
|
+
newLimitedStreams: (Stream | Participant)[];
|
|
11
|
+
newLimitedStreamsIDs: string[];
|
|
12
|
+
activeSounds: string[];
|
|
13
|
+
screenShareIDStream?: string;
|
|
14
|
+
screenShareNameStream?: string;
|
|
15
|
+
adminIDStream?: string;
|
|
16
|
+
adminNameStream?: string;
|
|
17
|
+
updateNewLimitedStreams: (streams: (Stream | Participant)[]) => void;
|
|
18
|
+
updateNewLimitedStreamsIDs: (ids: string[]) => void;
|
|
19
|
+
updateActiveSounds: (sounds: string[]) => void;
|
|
20
|
+
updateScreenShareIDStream: (id: string) => void;
|
|
21
|
+
updateScreenShareNameStream: (name: string) => void;
|
|
22
|
+
updateAdminIDStream: (id: string) => void;
|
|
23
|
+
updateAdminNameStream: (name: string) => void;
|
|
24
|
+
updateYouYouStream: (streams: (Stream | Participant)[]) => void;
|
|
25
|
+
|
|
26
|
+
// mediasfu functions
|
|
27
|
+
changeVids: ChangeVidsType;
|
|
28
|
+
getUpdatedAllParams: () => ReorderStreamsParameters;
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ReorderStreamsOptions {
|
|
33
|
+
add?: boolean;
|
|
34
|
+
screenChanged?: boolean;
|
|
35
|
+
parameters: ReorderStreamsParameters;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export type ReorderStreamsType = (options: ReorderStreamsOptions) => Promise<void>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Reorders the video streams based on the provided options and updates the UI accordingly.
|
|
43
|
+
*
|
|
44
|
+
* @param {ReorderStreamsOptions} options - The options for reordering streams.
|
|
45
|
+
* @param {boolean} [options.add=false] - Whether to add new streams or not.
|
|
46
|
+
* @param {boolean} [options.screenChanged=false] - Whether the screen has changed or not.
|
|
47
|
+
* @param {Object} options.parameters - The parameters required for reordering streams.
|
|
48
|
+
* @param {Function} options.parameters.getUpdatedAllParams - Function to get updated parameters.
|
|
49
|
+
* @param {Array} options.parameters.allVideoStreams - Array of all video streams.
|
|
50
|
+
* @param {Array} options.parameters.participants - Array of participants.
|
|
51
|
+
* @param {Array} options.parameters.oldAllStreams - Array of old streams.
|
|
52
|
+
* @param {string} options.parameters.screenId - ID of the screen.
|
|
53
|
+
* @param {string} options.parameters.adminVidID - ID of the admin video.
|
|
54
|
+
* @param {Array} options.parameters.newLimitedStreams - Array of new limited streams.
|
|
55
|
+
* @param {Array} options.parameters.newLimitedStreamsIDs - Array of new limited stream IDs.
|
|
56
|
+
* @param {Array} options.parameters.activeSounds - Array of active sounds.
|
|
57
|
+
* @param {string} options.parameters.screenShareIDStream - ID of the screen share stream.
|
|
58
|
+
* @param {string} options.parameters.screenShareNameStream - Name of the screen share stream.
|
|
59
|
+
* @param {string} options.parameters.adminIDStream - ID of the admin stream.
|
|
60
|
+
* @param {string} options.parameters.adminNameStream - Name of the admin stream.
|
|
61
|
+
* @param {Function} options.parameters.updateNewLimitedStreams - Function to update new limited streams.
|
|
62
|
+
* @param {Function} options.parameters.updateNewLimitedStreamsIDs - Function to update new limited stream IDs.
|
|
63
|
+
* @param {Function} options.parameters.updateActiveSounds - Function to update active sounds.
|
|
64
|
+
* @param {Function} options.parameters.updateScreenShareIDStream - Function to update screen share ID stream.
|
|
65
|
+
* @param {Function} options.parameters.updateScreenShareNameStream - Function to update screen share name stream.
|
|
66
|
+
* @param {Function} options.parameters.updateAdminIDStream - Function to update admin ID stream.
|
|
67
|
+
* @param {Function} options.parameters.updateAdminNameStream - Function to update admin name stream.
|
|
68
|
+
* @param {Function} options.parameters.updateYouYouStream - Function to update YouYou stream.
|
|
69
|
+
* @param {Function} options.parameters.changeVids - Function to reflect changes on the UI.
|
|
70
|
+
*
|
|
71
|
+
* @returns {Promise<void>} A promise that resolves when the reordering is complete.
|
|
72
|
+
*
|
|
73
|
+
* @throws {Error} Throws an error if there is an issue updating the streams.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* await reorderStreams({
|
|
78
|
+
* add: true,
|
|
79
|
+
* screenChanged: false,
|
|
80
|
+
* parameters: {
|
|
81
|
+
* allVideoStreams: [...],
|
|
82
|
+
* participants: [...],
|
|
83
|
+
* // additional parameters...
|
|
84
|
+
* },
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
export const reorderStreams = async ({
|
|
90
|
+
add = false,
|
|
91
|
+
screenChanged = false,
|
|
92
|
+
parameters,
|
|
93
|
+
}: ReorderStreamsOptions): Promise<void> => {
|
|
94
|
+
const { getUpdatedAllParams } = parameters;
|
|
95
|
+
parameters = getUpdatedAllParams();
|
|
96
|
+
|
|
97
|
+
let {
|
|
98
|
+
allVideoStreams,
|
|
99
|
+
participants,
|
|
100
|
+
oldAllStreams,
|
|
101
|
+
screenId,
|
|
102
|
+
adminVidID,
|
|
103
|
+
newLimitedStreams,
|
|
104
|
+
newLimitedStreamsIDs,
|
|
105
|
+
activeSounds,
|
|
106
|
+
screenShareIDStream,
|
|
107
|
+
screenShareNameStream,
|
|
108
|
+
adminIDStream,
|
|
109
|
+
adminNameStream,
|
|
110
|
+
updateNewLimitedStreams,
|
|
111
|
+
updateNewLimitedStreamsIDs,
|
|
112
|
+
updateActiveSounds,
|
|
113
|
+
updateScreenShareIDStream,
|
|
114
|
+
updateScreenShareNameStream,
|
|
115
|
+
updateAdminIDStream,
|
|
116
|
+
updateAdminNameStream,
|
|
117
|
+
updateYouYouStream,
|
|
118
|
+
|
|
119
|
+
//mediasfu functions
|
|
120
|
+
changeVids,
|
|
121
|
+
} = parameters;
|
|
122
|
+
|
|
123
|
+
// function to reorder streams on the ui
|
|
124
|
+
if (!add) {
|
|
125
|
+
newLimitedStreams = [];
|
|
126
|
+
newLimitedStreamsIDs = [];
|
|
127
|
+
activeSounds = [];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const youyou = allVideoStreams.filter((stream) => stream.producerId === "youyou");
|
|
131
|
+
const admin = participants.filter((participant) => participant.islevel === "2");
|
|
132
|
+
|
|
133
|
+
if (admin.length > 0) {
|
|
134
|
+
adminVidID = admin[0].videoID;
|
|
135
|
+
} else {
|
|
136
|
+
adminVidID = "";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (adminVidID) {
|
|
140
|
+
const adminStream = allVideoStreams.find((stream) => stream.producerId === adminVidID);
|
|
141
|
+
|
|
142
|
+
if (!add) {
|
|
143
|
+
newLimitedStreams = [...newLimitedStreams, ...youyou];
|
|
144
|
+
newLimitedStreamsIDs = [...newLimitedStreamsIDs, ...youyou.map((stream) => stream.producerId)];
|
|
145
|
+
} else {
|
|
146
|
+
const youyouStream = newLimitedStreams.find((stream) => stream.producerId === "youyou");
|
|
147
|
+
|
|
148
|
+
if (!youyouStream) {
|
|
149
|
+
newLimitedStreams = [...newLimitedStreams, ...youyou];
|
|
150
|
+
newLimitedStreamsIDs = [...newLimitedStreamsIDs, ...youyou.map((stream) => stream.producerId)];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (adminStream) {
|
|
155
|
+
adminIDStream = adminVidID;
|
|
156
|
+
|
|
157
|
+
if (!add) {
|
|
158
|
+
newLimitedStreams = [...newLimitedStreams, adminStream];
|
|
159
|
+
newLimitedStreamsIDs = [...newLimitedStreamsIDs, adminStream.producerId];
|
|
160
|
+
} else {
|
|
161
|
+
const adminStreamer = newLimitedStreams.find((stream) => stream.producerId === adminVidID);
|
|
162
|
+
|
|
163
|
+
if (!adminStreamer) {
|
|
164
|
+
newLimitedStreams = [...newLimitedStreams, adminStream];
|
|
165
|
+
newLimitedStreamsIDs = [...newLimitedStreamsIDs, adminStream.producerId];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
const oldAdminStream = oldAllStreams.find((stream) => stream.producerId === adminVidID);
|
|
170
|
+
|
|
171
|
+
if (oldAdminStream) {
|
|
172
|
+
//add it to the allVideoStream
|
|
173
|
+
|
|
174
|
+
adminIDStream = adminVidID;
|
|
175
|
+
adminNameStream = admin[0].name;
|
|
176
|
+
|
|
177
|
+
if (!add) {
|
|
178
|
+
newLimitedStreams = [...newLimitedStreams, oldAdminStream];
|
|
179
|
+
newLimitedStreamsIDs = [...newLimitedStreamsIDs, oldAdminStream.producerId];
|
|
180
|
+
} else {
|
|
181
|
+
const adminStreamer = newLimitedStreams.find((stream) => stream.producerId === adminVidID);
|
|
182
|
+
|
|
183
|
+
if (!adminStreamer) {
|
|
184
|
+
newLimitedStreams = [...newLimitedStreams, oldAdminStream];
|
|
185
|
+
newLimitedStreamsIDs = [...newLimitedStreamsIDs, oldAdminStream.producerId];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const screenParticipant = participants.filter((participant) => participant.ScreenID === screenId);
|
|
192
|
+
|
|
193
|
+
if (screenParticipant.length > 0) {
|
|
194
|
+
const screenParticipantVidID = screenParticipant[0].videoID;
|
|
195
|
+
const screenParticipantVidID_ = newLimitedStreams.filter((stream) => stream.producerId === screenParticipantVidID);
|
|
196
|
+
|
|
197
|
+
if (screenParticipantVidID_?.length < 1 && screenParticipantVidID) {
|
|
198
|
+
screenShareIDStream = screenParticipantVidID;
|
|
199
|
+
screenShareNameStream = screenParticipant[0].name;
|
|
200
|
+
const screenParticipantVidID__ = allVideoStreams.filter((stream) => stream.producerId === screenParticipantVidID);
|
|
201
|
+
newLimitedStreams = [...newLimitedStreams, ...screenParticipantVidID__];
|
|
202
|
+
newLimitedStreamsIDs = [...newLimitedStreamsIDs, ...screenParticipantVidID__.map((stream) => stream.producerId)];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
if (!add) {
|
|
207
|
+
newLimitedStreams = [...newLimitedStreams, ...youyou];
|
|
208
|
+
newLimitedStreamsIDs = [...newLimitedStreamsIDs, ...youyou.map((stream) => stream.producerId)];
|
|
209
|
+
} else {
|
|
210
|
+
const youyouStream = newLimitedStreams.find((stream) => stream.producerId === "youyou");
|
|
211
|
+
|
|
212
|
+
if (!youyouStream) {
|
|
213
|
+
newLimitedStreams = [...newLimitedStreams, ...youyou];
|
|
214
|
+
newLimitedStreamsIDs = [...newLimitedStreamsIDs, ...youyou.map((stream) => stream.producerId)];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const screenParticipant = participants.filter((participant) => participant.ScreenID === screenId);
|
|
219
|
+
|
|
220
|
+
if (screenParticipant.length > 0) {
|
|
221
|
+
const screenParticipantVidID = screenParticipant[0].videoID;
|
|
222
|
+
const screenParticipantVidID_ = newLimitedStreams.filter((stream) => stream.producerId === screenParticipantVidID);
|
|
223
|
+
|
|
224
|
+
if (screenParticipantVidID_?.length < 1 && screenParticipantVidID) {
|
|
225
|
+
screenShareIDStream = screenParticipantVidID;
|
|
226
|
+
screenShareNameStream = screenParticipant[0].name;
|
|
227
|
+
const screenParticipantVidID__ = allVideoStreams.filter((stream) => stream.producerId === screenParticipantVidID);
|
|
228
|
+
newLimitedStreams = [...newLimitedStreams, ...screenParticipantVidID__];
|
|
229
|
+
newLimitedStreamsIDs = [...newLimitedStreamsIDs, ...screenParticipantVidID__.map((stream) => stream.producerId)];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
updateNewLimitedStreams(newLimitedStreams);
|
|
235
|
+
updateNewLimitedStreamsIDs(newLimitedStreamsIDs);
|
|
236
|
+
updateActiveSounds(activeSounds);
|
|
237
|
+
updateScreenShareIDStream(screenShareIDStream!);
|
|
238
|
+
updateScreenShareNameStream(screenShareNameStream!);
|
|
239
|
+
updateAdminIDStream(adminIDStream!);
|
|
240
|
+
updateAdminNameStream(adminNameStream!);
|
|
241
|
+
updateYouYouStream(youyou);
|
|
242
|
+
|
|
243
|
+
//reflect the changes on the ui
|
|
244
|
+
await changeVids({ screenChanged, parameters });
|
|
245
|
+
};
|
|
246
|
+
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Socket } from "socket.io-client";
|
|
2
|
+
import { ShowAlert, StartShareScreenType, StartShareScreenParameters } from "../types/types";
|
|
3
|
+
|
|
4
|
+
export interface RequestScreenShareParameters extends StartShareScreenParameters {
|
|
5
|
+
socket: Socket;
|
|
6
|
+
showAlert?: ShowAlert
|
|
7
|
+
localUIMode: boolean;
|
|
8
|
+
targetResolution?: string;
|
|
9
|
+
targetResolutionHost?: string;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// mediasfu functions
|
|
13
|
+
startShareScreen: StartShareScreenType;
|
|
14
|
+
getUpdatedAllParams : () => RequestScreenShareParameters;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface RequestScreenShareOptions {
|
|
19
|
+
parameters: RequestScreenShareParameters;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Export the type definition for the function
|
|
23
|
+
export type RequestScreenShareType = (options: RequestScreenShareOptions) => Promise<void>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Requests to start screen sharing.
|
|
27
|
+
*
|
|
28
|
+
* @param {RequestScreenShareOptions} options - The options for requesting screen share.
|
|
29
|
+
* @param {Object} options.parameters - The parameters for the screen share request.
|
|
30
|
+
* @param {Socket} options.parameters.socket - The socket instance to communicate with the server.
|
|
31
|
+
* @param {Function} [options.parameters.showAlert] - Optional function to show alerts to the user.
|
|
32
|
+
* @param {boolean} options.parameters.localUIMode - Indicates if the user is in local UI mode.
|
|
33
|
+
* @param {string} [options.parameters.targetResolution] - The target resolution for screen sharing.
|
|
34
|
+
* @param {string} [options.parameters.targetResolutionHost] - The target resolution for screen sharing for the host.
|
|
35
|
+
* @param {Function} options.parameters.startShareScreen - Function to start screen sharing.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<void>} A promise that resolves when the screen share request is processed.
|
|
38
|
+
*
|
|
39
|
+
* @throws {Error} Throws an error if there is an issue during the screen share request process.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* await requestScreenShare({
|
|
44
|
+
* parameters: {
|
|
45
|
+
* socket: socketInstance,
|
|
46
|
+
* localUIMode: false,
|
|
47
|
+
* targetResolution: 'fhd',
|
|
48
|
+
* startShareScreen: startShareScreenFunction,
|
|
49
|
+
* // other parameters...
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
export async function requestScreenShare({ parameters }: RequestScreenShareOptions): Promise<void> {
|
|
56
|
+
try {
|
|
57
|
+
// Destructure parameters
|
|
58
|
+
let {
|
|
59
|
+
socket,
|
|
60
|
+
showAlert,
|
|
61
|
+
localUIMode,
|
|
62
|
+
targetResolution = 'hd',
|
|
63
|
+
targetResolutionHost = 'hd',
|
|
64
|
+
|
|
65
|
+
//mediasfu functions
|
|
66
|
+
startShareScreen,
|
|
67
|
+
} = parameters;
|
|
68
|
+
|
|
69
|
+
let targetWidth = 1280
|
|
70
|
+
let targetHeight = 720
|
|
71
|
+
|
|
72
|
+
if (targetResolution == 'qhd' || targetResolutionHost == 'qhd') {
|
|
73
|
+
targetWidth = 2560
|
|
74
|
+
targetHeight = 1440
|
|
75
|
+
} else if (targetResolution == 'fhd' || targetResolutionHost == 'fhd') {
|
|
76
|
+
targetWidth = 1920
|
|
77
|
+
targetHeight = 1080
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Check if the user is in local UI mode
|
|
81
|
+
if (localUIMode === true) {
|
|
82
|
+
await startShareScreen({ parameters });
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
socket.emit("requestScreenShare", async ({ allowScreenShare }: { allowScreenShare: boolean; }) => {
|
|
87
|
+
if (!allowScreenShare) {
|
|
88
|
+
// Send an alert to the user
|
|
89
|
+
showAlert?.({
|
|
90
|
+
message: "You are not allowed to share screen",
|
|
91
|
+
type: "danger",
|
|
92
|
+
duration: 3000,
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
await startShareScreen({ parameters: { ...parameters, targetWidth, targetHeight } });
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
} catch (error) {
|
|
99
|
+
// Handle errors during the process of requesting screen share
|
|
100
|
+
// throw new Error(`Error during requesting screen share: ${error.message}`);
|
|
101
|
+
console.log("Error during requesting screen share: ", error);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Participant, Stream, ProcessConsumerTransportsAudioType, ProcessConsumerTransportsAudioParameters, Transport, BreakoutParticipant, EventType } from '../types/types';
|
|
2
|
+
|
|
3
|
+
export interface ResumePauseAudioStreamsParameters extends ProcessConsumerTransportsAudioParameters {
|
|
4
|
+
breakoutRooms: BreakoutParticipant[][];
|
|
5
|
+
ref_participants: Participant[];
|
|
6
|
+
allAudioStreams: (Stream | Participant)[];
|
|
7
|
+
participants: Participant[];
|
|
8
|
+
islevel: string;
|
|
9
|
+
eventType: EventType;
|
|
10
|
+
consumerTransports: Transport[];
|
|
11
|
+
limitedBreakRoom: BreakoutParticipant[];
|
|
12
|
+
hostNewRoom: number;
|
|
13
|
+
member: string;
|
|
14
|
+
updateLimitedBreakRoom: (limitedBreakRoom: BreakoutParticipant[]) => void;
|
|
15
|
+
|
|
16
|
+
// mediasfu functions
|
|
17
|
+
processConsumerTransportsAudio: ProcessConsumerTransportsAudioType;
|
|
18
|
+
getUpdatedAllParams: () => ResumePauseAudioStreamsParameters;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ResumePauseAudioStreamsOptions {
|
|
23
|
+
breakRoom?: number;
|
|
24
|
+
inBreakRoom?: boolean;
|
|
25
|
+
parameters: ResumePauseAudioStreamsParameters;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Export the type definition for the function
|
|
29
|
+
export type ResumePauseAudioStreamsType = (
|
|
30
|
+
options: ResumePauseAudioStreamsOptions
|
|
31
|
+
) => Promise<void>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Resumes or pauses audio streams based on the provided options.
|
|
35
|
+
*
|
|
36
|
+
* @param {ResumePauseAudioStreamsOptions} options - The options for resuming or pausing audio streams.
|
|
37
|
+
* @param {number} [options.breakRoom=-1] - The ID of the break room.
|
|
38
|
+
* @param {boolean} [options.inBreakRoom=false] - Indicates if the participant is in a break room.
|
|
39
|
+
* @param {ResumePauseAudioStreamsParameters} options.parameters - The parameters required for processing audio streams.
|
|
40
|
+
*
|
|
41
|
+
* @returns {Promise<void>} A promise that resolves when the audio streams have been processed.
|
|
42
|
+
*
|
|
43
|
+
* @throws Will log an error message if there is an issue processing the audio streams.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* await resumePauseAudioStreams({
|
|
48
|
+
* breakRoom: 1,
|
|
49
|
+
* inBreakRoom: true,
|
|
50
|
+
* parameters: {
|
|
51
|
+
* // ...parameters here
|
|
52
|
+
* },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
export const resumePauseAudioStreams = async ({
|
|
58
|
+
breakRoom = -1,
|
|
59
|
+
inBreakRoom = false,
|
|
60
|
+
parameters,
|
|
61
|
+
}: ResumePauseAudioStreamsOptions): Promise<void> => {
|
|
62
|
+
const { getUpdatedAllParams } = parameters;
|
|
63
|
+
parameters = getUpdatedAllParams();
|
|
64
|
+
|
|
65
|
+
const {
|
|
66
|
+
breakoutRooms,
|
|
67
|
+
ref_participants,
|
|
68
|
+
allAudioStreams,
|
|
69
|
+
participants,
|
|
70
|
+
islevel,
|
|
71
|
+
eventType,
|
|
72
|
+
consumerTransports,
|
|
73
|
+
hostNewRoom,
|
|
74
|
+
member,
|
|
75
|
+
updateLimitedBreakRoom,
|
|
76
|
+
processConsumerTransportsAudio,
|
|
77
|
+
} = parameters;
|
|
78
|
+
|
|
79
|
+
let room: BreakoutParticipant[] = [];
|
|
80
|
+
let currentStreams: (Stream | Participant)[] = [];
|
|
81
|
+
// Determine the room based on breakout status
|
|
82
|
+
if (inBreakRoom && breakRoom !== -1) {
|
|
83
|
+
room = breakoutRooms[breakRoom];
|
|
84
|
+
} else {
|
|
85
|
+
room = ref_participants
|
|
86
|
+
.filter((participant) =>
|
|
87
|
+
!breakoutRooms
|
|
88
|
+
.flat()
|
|
89
|
+
.map((obj) => obj.name)
|
|
90
|
+
.includes(participant!.name)
|
|
91
|
+
)
|
|
92
|
+
.map(({ name, breakRoom }) => ({ name, breakRoom }));
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
updateLimitedBreakRoom(room);
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
let addHostAudio = false;
|
|
100
|
+
|
|
101
|
+
if (islevel !== "2" && eventType === "conference") {
|
|
102
|
+
const roomMember = breakoutRooms.find((r) =>
|
|
103
|
+
r.find((p) => p.name === member)
|
|
104
|
+
);
|
|
105
|
+
let memberBreakRoom = -1;
|
|
106
|
+
if (roomMember) {
|
|
107
|
+
memberBreakRoom = breakoutRooms.indexOf(roomMember);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (
|
|
111
|
+
(inBreakRoom && breakRoom !== hostNewRoom) ||
|
|
112
|
+
(!inBreakRoom && hostNewRoom !== -1 && hostNewRoom !== memberBreakRoom)
|
|
113
|
+
) {
|
|
114
|
+
const host = participants.find((obj) => obj.islevel === "2");
|
|
115
|
+
// Remove the host from the room
|
|
116
|
+
room = room.filter((participant) => participant.name !== host?.name);
|
|
117
|
+
} else {
|
|
118
|
+
if (
|
|
119
|
+
(inBreakRoom && breakRoom === hostNewRoom) ||
|
|
120
|
+
(!inBreakRoom && hostNewRoom === -1) ||
|
|
121
|
+
(!inBreakRoom &&
|
|
122
|
+
hostNewRoom === memberBreakRoom &&
|
|
123
|
+
memberBreakRoom !== -1)
|
|
124
|
+
) {
|
|
125
|
+
addHostAudio = true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (let participant of room) {
|
|
131
|
+
let streams = allAudioStreams.filter((stream) => {
|
|
132
|
+
if (
|
|
133
|
+
(Object.prototype.hasOwnProperty.call(stream, "producerId") && stream.producerId) ||
|
|
134
|
+
(Object.prototype.hasOwnProperty.call(stream, "audioID") && stream.audioID)
|
|
135
|
+
) {
|
|
136
|
+
let producerId = stream.producerId || stream.audioID;
|
|
137
|
+
let matchingParticipant = ref_participants.find(
|
|
138
|
+
(obj) => obj.audioID == producerId
|
|
139
|
+
);
|
|
140
|
+
return (
|
|
141
|
+
matchingParticipant && matchingParticipant.name == participant.name
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
// Return false if the stream doesn't meet the criteria
|
|
145
|
+
return false;
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
currentStreams.push(...streams);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// If webinar, add the host audio stream if it is not in the currentStreams
|
|
152
|
+
if (islevel !== "2" && (eventType === "webinar" || addHostAudio)) {
|
|
153
|
+
const host = participants.find((obj) => obj.islevel === "2");
|
|
154
|
+
const hostStream = allAudioStreams.find(
|
|
155
|
+
(obj) => obj.producerId === host?.audioID
|
|
156
|
+
);
|
|
157
|
+
if (hostStream && !currentStreams.includes(hostStream)) {
|
|
158
|
+
currentStreams.push(hostStream);
|
|
159
|
+
if (!room.map((obj) => obj.name).includes(host?.name ?? "")) {
|
|
160
|
+
room.push({ name: host?.name || "", breakRoom: -1 });
|
|
161
|
+
}
|
|
162
|
+
updateLimitedBreakRoom(room);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
await processConsumerTransportsAudio({
|
|
167
|
+
consumerTransports,
|
|
168
|
+
lStreams: currentStreams,
|
|
169
|
+
parameters,
|
|
170
|
+
});
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.log('Error in resumePauseAudioStreams:', error);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Participant, Transport, Stream } from "../types/types";
|
|
2
|
+
|
|
3
|
+
export interface ResumePauseStreamsParameters {
|
|
4
|
+
participants: Participant[];
|
|
5
|
+
dispActiveNames: string[];
|
|
6
|
+
remoteScreenStream: Stream[];
|
|
7
|
+
consumerTransports: Transport[];
|
|
8
|
+
screenId?: string;
|
|
9
|
+
islevel: string;
|
|
10
|
+
|
|
11
|
+
// mediasfu functions
|
|
12
|
+
getUpdatedAllParams: () => ResumePauseStreamsParameters;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ResumePauseStreamsOptions {
|
|
17
|
+
parameters: ResumePauseStreamsParameters;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Export the type definition for the function
|
|
21
|
+
export type ResumePauseStreamsType = (options: ResumePauseStreamsOptions) => Promise<void>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resumes or pauses streams based on the provided parameters.
|
|
25
|
+
*
|
|
26
|
+
* @param {ResumePauseStreamsOptions} options - The options for resuming or pausing streams.
|
|
27
|
+
* @param {Object} options.parameters - The parameters for the function.
|
|
28
|
+
* @param {Array} options.parameters.participants - The list of participants.
|
|
29
|
+
* @param {Array} options.parameters.dispActiveNames - The list of active display names.
|
|
30
|
+
* @param {Array} options.parameters.consumerTransports - The list of consumer transports.
|
|
31
|
+
* @param {string} [options.parameters.screenId] - The screen producer ID.
|
|
32
|
+
* @param {string} options.parameters.islevel - The level of the user.
|
|
33
|
+
*
|
|
34
|
+
* @returns {Promise<void>} A promise that resolves when the streams have been resumed or paused.
|
|
35
|
+
*
|
|
36
|
+
* @throws Will throw an error if there is an issue during the process of resuming or pausing streams.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* await resumePauseStreams({
|
|
41
|
+
* parameters: {
|
|
42
|
+
* participants: participantArray,
|
|
43
|
+
* dispActiveNames: ['user1', 'user2'],
|
|
44
|
+
* consumerTransports: transportArray,
|
|
45
|
+
* screenId: 'screen-123',
|
|
46
|
+
* islevel: '1',
|
|
47
|
+
* },
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
export async function resumePauseStreams({
|
|
53
|
+
parameters,
|
|
54
|
+
}: ResumePauseStreamsOptions): Promise<void> {
|
|
55
|
+
try {
|
|
56
|
+
// Destructure parameters
|
|
57
|
+
const { participants, dispActiveNames, consumerTransports, screenId, islevel } = parameters;
|
|
58
|
+
|
|
59
|
+
// Get the videoID of the host (islevel=2)
|
|
60
|
+
const host = participants.find((obj) => obj.islevel === "2");
|
|
61
|
+
const hostVideoID = host ? host.videoID : null;
|
|
62
|
+
|
|
63
|
+
// Get videoIDs of participants in dispActiveNames and screenproducerId
|
|
64
|
+
const videosIDs = dispActiveNames.map((name) => {
|
|
65
|
+
const participant = participants.find((obj) => obj.name === name);
|
|
66
|
+
return participant ? participant.videoID : null;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Add screenproducerId to allVideoIDs if it's not null or empty
|
|
70
|
+
if (screenId) {
|
|
71
|
+
videosIDs.push(screenId);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Add hostVideoID to allVideoIDs if it's not null or empty (only if the user is not the host)
|
|
75
|
+
if (islevel !== "2" && hostVideoID) {
|
|
76
|
+
videosIDs.push(hostVideoID);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Remove null or empty videoIDs
|
|
80
|
+
const allVideoIDs = videosIDs.filter(
|
|
81
|
+
(videoID): videoID is string => videoID !== null && videoID !== ""
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (allVideoIDs.length > 0) {
|
|
85
|
+
// Get consumer transports with producerId in allVideoIDs
|
|
86
|
+
const consumerTransportsToResume = consumerTransports.filter(
|
|
87
|
+
(transport) =>
|
|
88
|
+
allVideoIDs.includes(transport.producerId) &&
|
|
89
|
+
transport.consumer.kind !== "audio"
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Resume all consumerTransportsToResume
|
|
93
|
+
for (const transport of consumerTransportsToResume) {
|
|
94
|
+
transport.socket_.emit(
|
|
95
|
+
"consumer-resume",
|
|
96
|
+
{ serverConsumerId: transport.serverConsumerTransportId },
|
|
97
|
+
async ({ resumed }: { resumed: boolean }) => {
|
|
98
|
+
if (resumed) {
|
|
99
|
+
transport.consumer.resume();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.log("Error during resuming or pausing streams: ", error);
|
|
107
|
+
// Handle errors during the process of resuming or pausing streams
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|