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,373 @@
|
|
|
1
|
+
import type { Device, Producer, ProducerOptions, RtpCodecCapability } from 'mediasoup-client/lib/types';
|
|
2
|
+
import { Socket } from "socket.io-client";
|
|
3
|
+
import { ConnectSendTransportVideoParameters, Participant, ShowAlert, CreateSendTransportParameters, ReorderStreamsParameters, SleepType, CreateSendTransportType, ConnectSendTransportVideoType, ReorderStreamsType, HParamsType, VParamsType } from "../types/types";
|
|
4
|
+
|
|
5
|
+
export interface StreamSuccessVideoParameters extends CreateSendTransportParameters, ConnectSendTransportVideoParameters, ReorderStreamsParameters {
|
|
6
|
+
socket: Socket;
|
|
7
|
+
participants: Participant[];
|
|
8
|
+
localStream: MediaStream | null;
|
|
9
|
+
transportCreated: boolean;
|
|
10
|
+
transportCreatedVideo: boolean;
|
|
11
|
+
videoAlreadyOn: boolean;
|
|
12
|
+
videoAction: boolean;
|
|
13
|
+
videoParams: ProducerOptions;
|
|
14
|
+
localStreamVideo: MediaStream | null;
|
|
15
|
+
defVideoID: string;
|
|
16
|
+
userDefaultVideoInputDevice: string;
|
|
17
|
+
params: ProducerOptions;
|
|
18
|
+
videoParamse?: ProducerOptions;
|
|
19
|
+
islevel: string;
|
|
20
|
+
member: string;
|
|
21
|
+
updateMainWindow: boolean;
|
|
22
|
+
lock_screen: boolean;
|
|
23
|
+
shared: boolean;
|
|
24
|
+
shareScreenStarted: boolean;
|
|
25
|
+
vParams: VParamsType;
|
|
26
|
+
hParams: HParamsType;
|
|
27
|
+
allowed: boolean;
|
|
28
|
+
currentFacingMode: string;
|
|
29
|
+
device: Device | null;
|
|
30
|
+
keepBackground: boolean;
|
|
31
|
+
appliedBackground: boolean;
|
|
32
|
+
videoProducer: Producer | null;
|
|
33
|
+
|
|
34
|
+
// Update functions
|
|
35
|
+
updateTransportCreatedVideo: (created: boolean) => void;
|
|
36
|
+
updateVideoAlreadyOn: (videoOn: boolean) => void;
|
|
37
|
+
updateVideoAction: (videoAction: boolean) => void;
|
|
38
|
+
updateLocalStream: (stream: MediaStream | null) => void;
|
|
39
|
+
updateLocalStreamVideo: (stream: MediaStream | null) => void;
|
|
40
|
+
updateUserDefaultVideoInputDevice: (device: string) => void;
|
|
41
|
+
updateCurrentFacingMode: (mode: string) => void;
|
|
42
|
+
updateDefVideoID: (id: string) => void;
|
|
43
|
+
updateAllowed: (allowed: boolean) => void;
|
|
44
|
+
updateUpdateMainWindow: (updateMainWindow: boolean) => void;
|
|
45
|
+
updateParticipants: (participants: Participant[]) => void;
|
|
46
|
+
updateVideoParams: (params: ProducerOptions) => void;
|
|
47
|
+
updateIsBackgroundModalVisible: (isVisible: boolean) => void;
|
|
48
|
+
updateAutoClickBackground: (autoClick: boolean) => void;
|
|
49
|
+
|
|
50
|
+
showAlert?: ShowAlert;
|
|
51
|
+
|
|
52
|
+
// Media functions
|
|
53
|
+
createSendTransport: CreateSendTransportType;
|
|
54
|
+
connectSendTransportVideo: ConnectSendTransportVideoType;
|
|
55
|
+
reorderStreams: ReorderStreamsType;
|
|
56
|
+
sleep: SleepType;
|
|
57
|
+
|
|
58
|
+
getUpdatedAllParams: () => StreamSuccessVideoParameters;
|
|
59
|
+
[key: string]: any;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface StreamSuccessVideoOptions {
|
|
63
|
+
stream: MediaStream;
|
|
64
|
+
parameters: StreamSuccessVideoParameters;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Export the type definition for the function
|
|
68
|
+
export type StreamSuccessVideoType = (options: StreamSuccessVideoOptions) => Promise<void>;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Handles the successful streaming of video by managing the local stream, updating parameters, and handling video transport.
|
|
73
|
+
*
|
|
74
|
+
* @param {StreamSuccessVideoOptions} options - The options for streaming the video.
|
|
75
|
+
* @param {MediaStream} options.stream - The media stream to be used for the video.
|
|
76
|
+
* @param {Object} options.parameters - The parameters required for streaming the video.
|
|
77
|
+
* @param {Socket} options.parameters.socket - The socket connection for communication.
|
|
78
|
+
* @param {Array<Participant>} options.parameters.participants - The list of participants in the room.
|
|
79
|
+
* @param {MediaStream | null} options.parameters.localStream - The local media stream.
|
|
80
|
+
* @param {MediaStream | null} options.parameters.localStreamVideo - The local video stream.
|
|
81
|
+
* @param {boolean} options.parameters.transportCreated - Indicates if the transport has been created.
|
|
82
|
+
* @param {boolean} options.parameters.transportCreatedVideo - Indicates if the video transport has been created.
|
|
83
|
+
* @param {boolean} options.parameters.videoAlreadyOn - Indicates if the video is already on.
|
|
84
|
+
* @param {boolean} options.parameters.videoAction - Indicates the action state of the video.
|
|
85
|
+
* @param {ProducerOptions} options.parameters.videoParams - The video parameters for the producer.
|
|
86
|
+
* @param {string} options.parameters.defVideoID - The default video device ID.
|
|
87
|
+
* @param {string} options.parameters.userDefaultVideoInputDevice - The user default video input device.
|
|
88
|
+
* @param {string} options.parameters.hostLabel - The label of the host.
|
|
89
|
+
* @param {string} options.parameters.islevel - The level of the participant.
|
|
90
|
+
* @param {string} options.parameters.member - The name of the participant.
|
|
91
|
+
* @param {boolean} options.parameters.updateMainWindow - Indicates if the main window should be updated.
|
|
92
|
+
* @param {boolean} options.parameters.lock_screen - Indicates if the screen is locked.
|
|
93
|
+
* @param {boolean} options.parameters.shared - Indicates if the screen is shared.
|
|
94
|
+
* @param {boolean} options.parameters.shareScreenStarted - Indicates if screen sharing has started.
|
|
95
|
+
* @param {VParamsType} options.parameters.vParams - Video parameters.
|
|
96
|
+
* @param {HParamsType} options.parameters.hParams - Horizontal parameters.
|
|
97
|
+
* @param {boolean} options.parameters.allowed - Indicates if the action is allowed.
|
|
98
|
+
* @param {string} options.parameters.currentFacingMode - The current facing mode of the camera.
|
|
99
|
+
* @param {Device | null} options.parameters.device - The device being used for streaming.
|
|
100
|
+
* @param {boolean} options.parameters.keepBackground - Indicates if the background should be kept.
|
|
101
|
+
* @param {boolean} options.parameters.appliedBackground - Indicates if the background has been applied.
|
|
102
|
+
* @param {Producer | null} options.parameters.videoProducer - The video producer instance.
|
|
103
|
+
* @param {Function} options.parameters.updateTransportCreatedVideo - Function to update the transport created state for video.
|
|
104
|
+
* @param {Function} options.parameters.updateVideoAlreadyOn - Function to update the video already on state.
|
|
105
|
+
* @param {Function} options.parameters.updateVideoAction - Function to update the video action state.
|
|
106
|
+
* @param {Function} options.parameters.updateLocalStream - Function to update the local stream.
|
|
107
|
+
* @param {Function} options.parameters.updateLocalStreamVideo - Function to update the local video stream.
|
|
108
|
+
* @param {Function} options.parameters.updateUserDefaultVideoInputDevice - Function to update the user default video input device.
|
|
109
|
+
* @param {Function} options.parameters.updateCurrentFacingMode - Function to update the current facing mode.
|
|
110
|
+
* @param {Function} options.parameters.updateDefVideoID - Function to update the default video device ID.
|
|
111
|
+
* @param {Function} options.parameters.updateAllowed - Function to update the allowed state.
|
|
112
|
+
* @param {Function} options.parameters.updateUpdateMainWindow - Function to update the main window state.
|
|
113
|
+
* @param {Function} options.parameters.createSendTransport - Function to create a send transport.
|
|
114
|
+
* @param {Function} options.parameters.connectSendTransportVideo - Function to connect the send transport for video.
|
|
115
|
+
* @param {Function} options.parameters.showAlert - Function to display alert messages to the user.
|
|
116
|
+
*
|
|
117
|
+
* @returns {Promise<void>} A promise that resolves when the video streaming setup is complete.
|
|
118
|
+
*
|
|
119
|
+
* @throws Will throw an error if there is an issue with streaming the video.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* await streamSuccessVideo({
|
|
124
|
+
* stream: mediaStream,
|
|
125
|
+
* parameters: {
|
|
126
|
+
* socket,
|
|
127
|
+
* participants,
|
|
128
|
+
* localStream: null,
|
|
129
|
+
* localStreamVideo: null,
|
|
130
|
+
* transportCreated: false,
|
|
131
|
+
* transportCreatedVideo: false,
|
|
132
|
+
* videoAlreadyOn: false,
|
|
133
|
+
* videoAction: false,
|
|
134
|
+
* videoParams: producerOptions,
|
|
135
|
+
* defVideoID: "default-video-id",
|
|
136
|
+
* userDefaultVideoInputDevice: "user-device-id",
|
|
137
|
+
* hostLabel: "Host",
|
|
138
|
+
* islevel: "1",
|
|
139
|
+
* member: "Participant1",
|
|
140
|
+
* lock_screen: false,
|
|
141
|
+
* shared: false,
|
|
142
|
+
* shareScreenStarted: false,
|
|
143
|
+
* vParams,
|
|
144
|
+
* hParams,
|
|
145
|
+
* allowed: true,
|
|
146
|
+
* currentFacingMode: "user",
|
|
147
|
+
* device: mediaDevice,
|
|
148
|
+
* updateTransportCreatedVideo,
|
|
149
|
+
* updateVideoAlreadyOn,
|
|
150
|
+
* updateVideoAction,
|
|
151
|
+
* updateLocalStream,
|
|
152
|
+
* updateLocalStreamVideo,
|
|
153
|
+
* updateUserDefaultVideoInputDevice,
|
|
154
|
+
* updateCurrentFacingMode,
|
|
155
|
+
* updateDefVideoID,
|
|
156
|
+
* updateAllowed,
|
|
157
|
+
* updateUpdateMainWindow,
|
|
158
|
+
* createSendTransport,
|
|
159
|
+
* connectSendTransportVideo,
|
|
160
|
+
* showAlert,
|
|
161
|
+
* },
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
export const streamSuccessVideo = async ({
|
|
168
|
+
stream,
|
|
169
|
+
parameters,
|
|
170
|
+
}: StreamSuccessVideoOptions): Promise<void> => {
|
|
171
|
+
|
|
172
|
+
let { getUpdatedAllParams } = parameters;
|
|
173
|
+
parameters = getUpdatedAllParams();
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
let {
|
|
177
|
+
socket,
|
|
178
|
+
participants,
|
|
179
|
+
localStream,
|
|
180
|
+
transportCreated,
|
|
181
|
+
transportCreatedVideo,
|
|
182
|
+
videoAlreadyOn,
|
|
183
|
+
videoAction,
|
|
184
|
+
videoParams,
|
|
185
|
+
localStreamVideo,
|
|
186
|
+
defVideoID,
|
|
187
|
+
userDefaultVideoInputDevice,
|
|
188
|
+
params,
|
|
189
|
+
videoParamse,
|
|
190
|
+
islevel,
|
|
191
|
+
member,
|
|
192
|
+
updateMainWindow,
|
|
193
|
+
lock_screen,
|
|
194
|
+
shared,
|
|
195
|
+
shareScreenStarted,
|
|
196
|
+
vParams,
|
|
197
|
+
hParams,
|
|
198
|
+
allowed,
|
|
199
|
+
currentFacingMode,
|
|
200
|
+
device,
|
|
201
|
+
|
|
202
|
+
keepBackground,
|
|
203
|
+
appliedBackground,
|
|
204
|
+
videoProducer,
|
|
205
|
+
|
|
206
|
+
updateTransportCreatedVideo,
|
|
207
|
+
updateVideoAlreadyOn,
|
|
208
|
+
updateVideoAction,
|
|
209
|
+
updateLocalStream,
|
|
210
|
+
updateLocalStreamVideo,
|
|
211
|
+
updateUserDefaultVideoInputDevice,
|
|
212
|
+
updateCurrentFacingMode,
|
|
213
|
+
updateDefVideoID,
|
|
214
|
+
updateAllowed,
|
|
215
|
+
updateUpdateMainWindow,
|
|
216
|
+
updateParticipants,
|
|
217
|
+
updateVideoParams,
|
|
218
|
+
updateIsBackgroundModalVisible,
|
|
219
|
+
updateAutoClickBackground,
|
|
220
|
+
|
|
221
|
+
//mediasfu functions
|
|
222
|
+
createSendTransport,
|
|
223
|
+
connectSendTransportVideo,
|
|
224
|
+
showAlert,
|
|
225
|
+
reorderStreams,
|
|
226
|
+
sleep,
|
|
227
|
+
} = parameters;
|
|
228
|
+
|
|
229
|
+
localStreamVideo = stream;
|
|
230
|
+
updateLocalStreamVideo(localStreamVideo);
|
|
231
|
+
|
|
232
|
+
if (localStream == null) {
|
|
233
|
+
localStream = new MediaStream([
|
|
234
|
+
localStreamVideo.getVideoTracks()[0],
|
|
235
|
+
]);
|
|
236
|
+
updateLocalStream(localStream);
|
|
237
|
+
} else {
|
|
238
|
+
// remove all video tracks that are currently in the localStream
|
|
239
|
+
localStream.getVideoTracks().forEach((track) => {
|
|
240
|
+
localStream!.removeTrack(track);
|
|
241
|
+
});
|
|
242
|
+
// add the new video track to the localStream
|
|
243
|
+
localStream.addTrack(localStreamVideo.getVideoTracks()[0]);
|
|
244
|
+
updateLocalStream(localStream);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const videoTracked = localStream.getVideoTracks()[0];
|
|
248
|
+
defVideoID = videoTracked.getSettings().deviceId || '';
|
|
249
|
+
userDefaultVideoInputDevice = defVideoID;
|
|
250
|
+
currentFacingMode = videoTracked.getSettings().facingMode || 'user';
|
|
251
|
+
|
|
252
|
+
if (defVideoID) {
|
|
253
|
+
updateDefVideoID(defVideoID);
|
|
254
|
+
}
|
|
255
|
+
if (userDefaultVideoInputDevice) {
|
|
256
|
+
updateUserDefaultVideoInputDevice(userDefaultVideoInputDevice);
|
|
257
|
+
}
|
|
258
|
+
if (currentFacingMode) {
|
|
259
|
+
updateCurrentFacingMode(currentFacingMode);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
allowed = true;
|
|
263
|
+
updateAllowed(allowed);
|
|
264
|
+
|
|
265
|
+
try {
|
|
266
|
+
if (islevel === "2") {
|
|
267
|
+
params = shared || shareScreenStarted ? vParams : hParams;
|
|
268
|
+
videoParamse = { ...params };
|
|
269
|
+
} else {
|
|
270
|
+
params = vParams;
|
|
271
|
+
videoParamse = { ...params };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
let codec = device?.rtpCapabilities?.codecs?.filter(
|
|
275
|
+
(codec: RtpCodecCapability) => codec.mimeType.toLowerCase() !== "video/vp9" && codec.kind === "video"
|
|
276
|
+
) || [];
|
|
277
|
+
|
|
278
|
+
videoParams = {
|
|
279
|
+
track: localStream.getVideoTracks()[0],
|
|
280
|
+
...videoParamse,
|
|
281
|
+
codec: codec[0],
|
|
282
|
+
};
|
|
283
|
+
updateVideoParams(videoParams);
|
|
284
|
+
|
|
285
|
+
if (keepBackground && appliedBackground) {
|
|
286
|
+
videoAlreadyOn = true;
|
|
287
|
+
updateVideoAlreadyOn(videoAlreadyOn);
|
|
288
|
+
|
|
289
|
+
updateAutoClickBackground(true);
|
|
290
|
+
updateIsBackgroundModalVisible(true);
|
|
291
|
+
await sleep({ ms: 500 });
|
|
292
|
+
updateIsBackgroundModalVisible(false);
|
|
293
|
+
updateAutoClickBackground(false);
|
|
294
|
+
} else {
|
|
295
|
+
if (!transportCreated) {
|
|
296
|
+
try {
|
|
297
|
+
await createSendTransport({
|
|
298
|
+
parameters: { ...parameters, videoParams },
|
|
299
|
+
option: "video",
|
|
300
|
+
});
|
|
301
|
+
} catch { /* Handle error */}
|
|
302
|
+
} else {
|
|
303
|
+
try {
|
|
304
|
+
videoProducer!.close();
|
|
305
|
+
await sleep({ ms: 500 });
|
|
306
|
+
} catch { /* Handle error */}
|
|
307
|
+
await connectSendTransportVideo({
|
|
308
|
+
parameters,
|
|
309
|
+
videoParams,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
} catch (error) {
|
|
314
|
+
showAlert?.({
|
|
315
|
+
message: (error as Error).message,
|
|
316
|
+
type: "danger",
|
|
317
|
+
duration: 3000,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
videoAlreadyOn = true;
|
|
322
|
+
updateVideoAlreadyOn(videoAlreadyOn);
|
|
323
|
+
|
|
324
|
+
if (videoAction === true) {
|
|
325
|
+
videoAction = false;
|
|
326
|
+
updateVideoAction(videoAction);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (islevel === "2") {
|
|
330
|
+
updateMainWindow = true;
|
|
331
|
+
updateUpdateMainWindow(updateMainWindow);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
//update the participants array to reflect the change
|
|
335
|
+
participants.forEach((participant) => {
|
|
336
|
+
if (participant.socketId == socket.id && participant.name == member) {
|
|
337
|
+
participant.videoOn = true;
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
updateParticipants(participants);
|
|
341
|
+
|
|
342
|
+
transportCreatedVideo = true;
|
|
343
|
+
updateTransportCreatedVideo(transportCreatedVideo);
|
|
344
|
+
|
|
345
|
+
//reupdate the screen display
|
|
346
|
+
if (lock_screen) {
|
|
347
|
+
await reorderStreams({
|
|
348
|
+
add: true,
|
|
349
|
+
screenChanged: true,
|
|
350
|
+
parameters: { ...parameters, videoAlreadyOn },
|
|
351
|
+
});
|
|
352
|
+
} else {
|
|
353
|
+
try {
|
|
354
|
+
await reorderStreams({
|
|
355
|
+
add: false,
|
|
356
|
+
screenChanged: true,
|
|
357
|
+
parameters: { ...parameters, videoAlreadyOn },
|
|
358
|
+
});
|
|
359
|
+
} catch { /* Handle error */}
|
|
360
|
+
}
|
|
361
|
+
} catch (error) {
|
|
362
|
+
try {
|
|
363
|
+
let { showAlert } = parameters;
|
|
364
|
+
|
|
365
|
+
showAlert?.({
|
|
366
|
+
message: (error as Error).message,
|
|
367
|
+
type: "danger",
|
|
368
|
+
duration: 3000,
|
|
369
|
+
});
|
|
370
|
+
} catch { /* Handle error */}
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ShowAlert, StreamSuccessAudioSwitchType, RequestPermissionAudioType, StreamSuccessAudioSwitchParameters } from "../types/types";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export interface SwitchUserAudioParameters extends StreamSuccessAudioSwitchParameters {
|
|
5
|
+
mediaDevices: MediaDevices;
|
|
6
|
+
userDefaultAudioInputDevice: string;
|
|
7
|
+
prevAudioInputDevice: string;
|
|
8
|
+
showAlert?: ShowAlert;
|
|
9
|
+
hasAudioPermission: boolean;
|
|
10
|
+
updateUserDefaultAudioInputDevice: (deviceId: string) => void;
|
|
11
|
+
|
|
12
|
+
// mediasfu functions
|
|
13
|
+
streamSuccessAudioSwitch: StreamSuccessAudioSwitchType;
|
|
14
|
+
requestPermissionAudio: RequestPermissionAudioType;
|
|
15
|
+
checkMediaPermission: boolean;
|
|
16
|
+
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SwitchUserAudioOptions {
|
|
21
|
+
audioPreference: string;
|
|
22
|
+
parameters: SwitchUserAudioParameters;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Export the type definition for the function
|
|
26
|
+
export type SwitchUserAudioType = (options: SwitchUserAudioOptions) => Promise<void>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Switches the user's audio input device based on the provided audio preference.
|
|
30
|
+
*
|
|
31
|
+
* @param {SwitchUserAudioOptions} options - The options for switching the user's audio input device.
|
|
32
|
+
* @param {string} options.audioPreference - The preferred audio input device ID.
|
|
33
|
+
* @param {Object} options.parameters - Additional parameters required for switching the audio input device.
|
|
34
|
+
* @param {MediaDevices} options.parameters.mediaDevices - The media devices interface for accessing user media.
|
|
35
|
+
* @param {string} options.parameters.prevAudioInputDevice - The previous audio input device ID.
|
|
36
|
+
* @param {Function} options.parameters.showAlert - Function to show alert messages.
|
|
37
|
+
* @param {boolean} options.parameters.hasAudioPermission - Flag indicating if the user has granted audio permission.
|
|
38
|
+
* @param {Function} options.parameters.updateUserDefaultAudioInputDevice - Function to update the user's default audio input device.
|
|
39
|
+
* @param {Function} options.parameters.streamSuccessAudioSwitch - Function to handle successful audio stream switch.
|
|
40
|
+
* @param {Function} options.parameters.requestPermissionAudio - Function to request audio permission from the user.
|
|
41
|
+
* @param {Function} options.parameters.checkMediaPermission - Function to check if media permission is granted.
|
|
42
|
+
*
|
|
43
|
+
* @returns {Promise<void>} A promise that resolves when the audio input device has been successfully switched.
|
|
44
|
+
*
|
|
45
|
+
* @throws Will throw an error if the audio input device cannot be accessed or if there is an unexpected error.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* await switchUserAudio({
|
|
50
|
+
* audioPreference: 'audio-device-id',
|
|
51
|
+
* parameters: {
|
|
52
|
+
* mediaDevices,
|
|
53
|
+
* prevAudioInputDevice: 'prev-audio-device-id',
|
|
54
|
+
* showAlert,
|
|
55
|
+
* hasAudioPermission,
|
|
56
|
+
* updateUserDefaultAudioInputDevice,
|
|
57
|
+
* streamSuccessAudioSwitch,
|
|
58
|
+
* requestPermissionAudio,
|
|
59
|
+
* checkMediaPermission,
|
|
60
|
+
* },
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
export async function switchUserAudio({ audioPreference, parameters }: SwitchUserAudioOptions): Promise<void> {
|
|
67
|
+
const {
|
|
68
|
+
mediaDevices,
|
|
69
|
+
prevAudioInputDevice,
|
|
70
|
+
showAlert,
|
|
71
|
+
hasAudioPermission,
|
|
72
|
+
updateUserDefaultAudioInputDevice,
|
|
73
|
+
|
|
74
|
+
// Media functions
|
|
75
|
+
streamSuccessAudioSwitch,
|
|
76
|
+
requestPermissionAudio,
|
|
77
|
+
checkMediaPermission,
|
|
78
|
+
} = parameters;
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
// Check if audio permission is granted
|
|
82
|
+
if (!hasAudioPermission) {
|
|
83
|
+
if (checkMediaPermission) {
|
|
84
|
+
const statusMic = await requestPermissionAudio();
|
|
85
|
+
if (statusMic !== "granted") {
|
|
86
|
+
showAlert?.({
|
|
87
|
+
message:
|
|
88
|
+
"Allow access to your microphone or check if your microphone is not being used by another application.",
|
|
89
|
+
type: "danger",
|
|
90
|
+
duration: 3000,
|
|
91
|
+
});
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const mediaConstraints: MediaStreamConstraints = {
|
|
98
|
+
audio: {
|
|
99
|
+
deviceId: { exact: audioPreference },
|
|
100
|
+
echoCancellation: false,
|
|
101
|
+
noiseSuppression: false,
|
|
102
|
+
autoGainControl: false,
|
|
103
|
+
},
|
|
104
|
+
video: false,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Get user media with the defined audio constraints
|
|
108
|
+
await mediaDevices
|
|
109
|
+
.getUserMedia(mediaConstraints)
|
|
110
|
+
.then(async (stream) => {
|
|
111
|
+
await streamSuccessAudioSwitch({ stream, parameters });
|
|
112
|
+
})
|
|
113
|
+
.catch((error) => {
|
|
114
|
+
console.log("Error switching audio A", error);
|
|
115
|
+
// Handle errors and revert to the previous audio input device
|
|
116
|
+
updateUserDefaultAudioInputDevice(prevAudioInputDevice);
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
showAlert?.({
|
|
120
|
+
message: "Error switching; the specified microphone could not be accessed.",
|
|
121
|
+
type: "danger",
|
|
122
|
+
duration: 3000,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
});
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.log("Error switching audio", error);
|
|
128
|
+
// Handle unexpected errors and revert to the previous audio input device
|
|
129
|
+
updateUserDefaultAudioInputDevice(prevAudioInputDevice);
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
showAlert?.({
|
|
133
|
+
message: "Error switching; the specified microphone could not be accessed.",
|
|
134
|
+
type: "danger",
|
|
135
|
+
duration: 3000,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|