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,232 @@
|
|
|
1
|
+
|
|
2
|
+
// Socket manager for media socket.
|
|
3
|
+
import { MeetingRoomParams, RecordingParams } from '../types/types';
|
|
4
|
+
import io, { Socket } from 'socket.io-client'; // Importing socket type
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Validates the provided API key or token.
|
|
8
|
+
* @param {string} value - The API key or token to validate.
|
|
9
|
+
* @returns {Promise<Boolean>} - True if the API key or token is valid, false otherwise.
|
|
10
|
+
*/
|
|
11
|
+
async function validateApiKeyToken(value: string): Promise<boolean> {
|
|
12
|
+
// API key or token must be alphanumeric and length 64
|
|
13
|
+
if (!/^[a-z0-9]{64}$/i.test(value)) {
|
|
14
|
+
throw new Error('Invalid API key or token.');
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ResponseLocalConnection {
|
|
20
|
+
socket?: Socket;
|
|
21
|
+
data?: ResponseLocalConnectionData;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ResponseLocalConnectionData {
|
|
25
|
+
socketId: string;
|
|
26
|
+
mode: string;
|
|
27
|
+
apiUserName?: string;
|
|
28
|
+
apiKey?: string;
|
|
29
|
+
allowRecord: boolean;
|
|
30
|
+
meetingRoomParams_: MeetingRoomParams;
|
|
31
|
+
recordingParams_: RecordingParams;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ConnectLocalSocketOptions {
|
|
35
|
+
link: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ConnectSocketOptions {
|
|
39
|
+
apiUserName: string;
|
|
40
|
+
apiKey?: string;
|
|
41
|
+
apiToken?: string;
|
|
42
|
+
link: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface DisconnectSocketOptions {
|
|
46
|
+
socket: Socket;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Export the type definition for the function
|
|
50
|
+
export type ConnectSocketType = (options: ConnectSocketOptions) => Promise<Socket>;
|
|
51
|
+
export type DisconnectSocketType = (options: DisconnectSocketOptions) => Promise<boolean>;
|
|
52
|
+
export type ConnectLocalSocketType = (options: ConnectLocalSocketOptions) => Promise<ResponseLocalConnection>;
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Connects to a media socket using the provided connection options.
|
|
57
|
+
*
|
|
58
|
+
* @param {ConnectSocketOptions} options - The connection options.
|
|
59
|
+
* @param {string} options.apiUserName - The API username.
|
|
60
|
+
* @param {string} [options.apiKey] - The API key (optional if apiToken is provided).
|
|
61
|
+
* @param {string} [options.apiToken] - The API token (optional if apiKey is provided).
|
|
62
|
+
* @param {string} options.link - The socket link.
|
|
63
|
+
*
|
|
64
|
+
* @returns {Promise<Socket>} A promise that resolves to the connected socket.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const options = {
|
|
69
|
+
* apiUserName: 'user123',
|
|
70
|
+
* apiKey: 'yourApiKeyHere',
|
|
71
|
+
* link: 'https://socketlink.com',
|
|
72
|
+
* };
|
|
73
|
+
*
|
|
74
|
+
* try {
|
|
75
|
+
* const socket = await connectSocket(options);
|
|
76
|
+
* console.log('Connected to socket:', socket);
|
|
77
|
+
* } catch (error) {
|
|
78
|
+
* console.error('Failed to connect to socket:', error);
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
async function connectSocket(
|
|
84
|
+
{ apiUserName, apiKey, apiToken, link }: ConnectSocketOptions,
|
|
85
|
+
): Promise<Socket> {
|
|
86
|
+
// Validate inputs
|
|
87
|
+
if (!apiUserName) {
|
|
88
|
+
throw new Error('API username required.');
|
|
89
|
+
}
|
|
90
|
+
if (!(apiKey || apiToken)) {
|
|
91
|
+
throw new Error('API key or token required.');
|
|
92
|
+
}
|
|
93
|
+
if (!link) {
|
|
94
|
+
throw new Error('Socket link required.');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Validate the API key or token
|
|
98
|
+
let useKey = false;
|
|
99
|
+
try {
|
|
100
|
+
if (apiKey && apiKey.length === 64) {
|
|
101
|
+
await validateApiKeyToken(apiKey);
|
|
102
|
+
useKey = true;
|
|
103
|
+
} else if (apiToken && apiToken.length === 64) {
|
|
104
|
+
await validateApiKeyToken(apiToken);
|
|
105
|
+
useKey = false;
|
|
106
|
+
} else {
|
|
107
|
+
throw new Error('Invalid API key or token format.');
|
|
108
|
+
}
|
|
109
|
+
} catch {
|
|
110
|
+
throw new Error('Invalid API key or token.');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let socket: Socket;
|
|
114
|
+
|
|
115
|
+
return new Promise((resolve, reject) => {
|
|
116
|
+
// Connect to socket using the link provided
|
|
117
|
+
if (useKey) {
|
|
118
|
+
socket = io(`${link}/media`, {
|
|
119
|
+
transports: ['websocket'],
|
|
120
|
+
query: {
|
|
121
|
+
apiUserName: apiUserName,
|
|
122
|
+
apiKey: apiKey!,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
socket = io(`${link}/media`, {
|
|
127
|
+
transports: ['websocket'],
|
|
128
|
+
query: {
|
|
129
|
+
apiUserName: apiUserName,
|
|
130
|
+
apiToken: apiToken!,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Handle socket connection events
|
|
136
|
+
socket.on('connection-success', ({ socketId }: { socketId: string }) => {
|
|
137
|
+
//check if link contains mediasfu.com and contains more than one c
|
|
138
|
+
let conn = 'media';
|
|
139
|
+
try {
|
|
140
|
+
if (link.includes('mediasfu.com') && (link.match(/c/g)?.length ?? 0) > 1) {
|
|
141
|
+
conn = 'consume';
|
|
142
|
+
}
|
|
143
|
+
} catch {
|
|
144
|
+
// do nothing
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
console.log(`Connected to ${conn} socket with ID: ${socketId}`);
|
|
148
|
+
resolve(socket);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
socket.on('connect_error', (error: Error) => {
|
|
152
|
+
reject(new Error('Error connecting to media socket: ' + error.message));
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Connects to a local media socket using the provided connection options.
|
|
160
|
+
*
|
|
161
|
+
* @param {ConnectLocalSocketOptions} options - The connection options.
|
|
162
|
+
* @param {string} options.link - The socket link.
|
|
163
|
+
*
|
|
164
|
+
* @returns {Promise<ResponseLocalConnection>} A promise that resolves to the connected socket and data.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const options = {
|
|
169
|
+
* link: 'http://localhost:3000',
|
|
170
|
+
* };
|
|
171
|
+
*
|
|
172
|
+
* try {
|
|
173
|
+
* const { socket, data } = await connectLocalSocket(options);
|
|
174
|
+
* console.log('Connected to socket:', socket, data);
|
|
175
|
+
* } catch (error) {
|
|
176
|
+
* console.error('Failed to connect to socket:', error);
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
async function connectLocalSocket({ link }: ConnectLocalSocketOptions): Promise<ResponseLocalConnection> {
|
|
182
|
+
if (!link) {
|
|
183
|
+
throw new Error('Socket link required.');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let socket: Socket;
|
|
187
|
+
|
|
188
|
+
return new Promise((resolve, reject) => {
|
|
189
|
+
// Connect to socket using the link provided
|
|
190
|
+
socket = io(`${link}/media`, {
|
|
191
|
+
transports: ['websocket'],
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
// Handle socket connection events
|
|
196
|
+
socket.on('connection-success', (data: ResponseLocalConnectionData) => {
|
|
197
|
+
resolve({ socket, data });
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
socket.on('connect_error', (error: Error) => {
|
|
201
|
+
reject(new Error('Error connecting to media socket: ' + error.message));
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Disconnects from the socket.
|
|
208
|
+
*
|
|
209
|
+
* @param {Socket} socket - The socket instance to disconnect.
|
|
210
|
+
* @returns {Promise<boolean>} - A promise that resolves once the socket is disconnected.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const options = { socket: socketInstance };
|
|
215
|
+
*
|
|
216
|
+
* try {
|
|
217
|
+
* const isDisconnected = await disconnectSocket(options);
|
|
218
|
+
* console.log('Disconnected:', isDisconnected);
|
|
219
|
+
* } catch (error) {
|
|
220
|
+
* console.error('Failed to disconnect:', error);
|
|
221
|
+
* }
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
async function disconnectSocket({ socket }: DisconnectSocketOptions): Promise<boolean> {
|
|
226
|
+
if (socket) {
|
|
227
|
+
socket.disconnect();
|
|
228
|
+
}
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export { connectSocket, disconnectSocket, connectLocalSocket };
|