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,118 @@
|
|
|
1
|
+
import { Participant, Stream, DispStreamsType, DispStreamsParameters } from '../types/types';
|
|
2
|
+
|
|
3
|
+
export interface GeneratePageContentParameters extends DispStreamsParameters {
|
|
4
|
+
paginatedStreams: (Participant | Stream)[][];
|
|
5
|
+
currentUserPage: number;
|
|
6
|
+
updateMainWindow: boolean;
|
|
7
|
+
updateCurrentUserPage: (page: number) => void;
|
|
8
|
+
updateUpdateMainWindow: (flag: boolean) => void;
|
|
9
|
+
|
|
10
|
+
// mediasfu functions
|
|
11
|
+
dispStreams: DispStreamsType;
|
|
12
|
+
getUpdatedAllParams: () => GeneratePageContentParameters;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface GeneratePageContentOptions {
|
|
17
|
+
page: number | string;
|
|
18
|
+
parameters: GeneratePageContentParameters;
|
|
19
|
+
breakRoom?: number;
|
|
20
|
+
inBreakRoom?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Export the type definition for the function
|
|
24
|
+
export type GeneratePageContentType = (options: GeneratePageContentOptions) => Promise<void>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generates the content for a specific page.
|
|
28
|
+
*
|
|
29
|
+
* @param {GeneratePageContentOptions} options - The options for generating page content.
|
|
30
|
+
* @param {number | string} options.page - The page number to generate content for.
|
|
31
|
+
* @param {GeneratePageContentParameters} options.parameters - The parameters required for generating content.
|
|
32
|
+
* @param {Array} options.parameters.paginatedStreams - The streams to be paginated.
|
|
33
|
+
* @param {number} options.parameters.currentUserPage - The current page of the user.
|
|
34
|
+
* @param {Function} options.parameters.updateMainWindow - Function to update the main window flag.
|
|
35
|
+
* @param {Function} options.parameters.updateCurrentUserPage - Function to update the current user page.
|
|
36
|
+
* @param {Function} options.parameters.updateUpdateMainWindow - Function to update the main window update flag.
|
|
37
|
+
* @param {Function} options.parameters.dispStreams - Function to display streams for the specified page.
|
|
38
|
+
* @param {number} [options.breakRoom=-1] - The break room identifier.
|
|
39
|
+
* @param {boolean} [options.inBreakRoom=false] - Flag indicating if the user is in a break room.
|
|
40
|
+
*
|
|
41
|
+
* @returns {Promise<void>} A promise that resolves when the content generation is complete.
|
|
42
|
+
*
|
|
43
|
+
* @throws {Error} Throws an error if content generation fails.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const options = {
|
|
47
|
+
* page: 1,
|
|
48
|
+
* parameters: {
|
|
49
|
+
* paginatedStreams: [[stream1, stream2], [stream3, stream4]], // Example paginated streams
|
|
50
|
+
* currentUserPage: 0,
|
|
51
|
+
* updateMainWindow: true,
|
|
52
|
+
* updateCurrentUserPage: (page) => console.log('Current user page updated to:', page),
|
|
53
|
+
* updateUpdateMainWindow: (flag) => console.log('Main window update flag:', flag),
|
|
54
|
+
* dispStreams: async ({ lStreams, ind }) => {
|
|
55
|
+
* console.log(`Displaying streams for page ${ind}:`, lStreams);
|
|
56
|
+
* },
|
|
57
|
+
* },
|
|
58
|
+
* breakRoom: 1,
|
|
59
|
+
* inBreakRoom: false,
|
|
60
|
+
* };
|
|
61
|
+
*
|
|
62
|
+
* generatePageContent(options)
|
|
63
|
+
* .then(() => {
|
|
64
|
+
* console.log('Page content generated successfully');
|
|
65
|
+
* })
|
|
66
|
+
* .catch((error) => {
|
|
67
|
+
* console.error('Error generating page content:', error);
|
|
68
|
+
* });
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
export async function generatePageContent({
|
|
72
|
+
page,
|
|
73
|
+
parameters,
|
|
74
|
+
breakRoom = -1,
|
|
75
|
+
inBreakRoom = false,
|
|
76
|
+
}: GeneratePageContentOptions): Promise<void> {
|
|
77
|
+
try {
|
|
78
|
+
// Destructure parameters
|
|
79
|
+
let {
|
|
80
|
+
paginatedStreams,
|
|
81
|
+
currentUserPage,
|
|
82
|
+
updateMainWindow,
|
|
83
|
+
|
|
84
|
+
updateCurrentUserPage,
|
|
85
|
+
updateUpdateMainWindow,
|
|
86
|
+
|
|
87
|
+
//mediasfu functions
|
|
88
|
+
dispStreams,
|
|
89
|
+
} = parameters;
|
|
90
|
+
|
|
91
|
+
// Convert page to an integer
|
|
92
|
+
page = typeof page === "string" ? parseInt(page) : page;
|
|
93
|
+
|
|
94
|
+
// Update current user page
|
|
95
|
+
currentUserPage = page;
|
|
96
|
+
updateCurrentUserPage(currentUserPage);
|
|
97
|
+
|
|
98
|
+
// Update main window flag
|
|
99
|
+
updateMainWindow = true;
|
|
100
|
+
updateUpdateMainWindow(updateMainWindow);
|
|
101
|
+
|
|
102
|
+
// Display streams for the specified page
|
|
103
|
+
await dispStreams({
|
|
104
|
+
lStreams: paginatedStreams[page],
|
|
105
|
+
ind: page,
|
|
106
|
+
parameters,
|
|
107
|
+
breakRoom,
|
|
108
|
+
inBreakRoom,
|
|
109
|
+
});
|
|
110
|
+
} catch (error) {
|
|
111
|
+
// Handle errors during content generation
|
|
112
|
+
if (error instanceof Error) {
|
|
113
|
+
console.log("Error generating page content:", error.message);
|
|
114
|
+
} else {
|
|
115
|
+
console.log("Error generating page content:", error);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { CalculateRowsAndColumnsType, EventType } from "../types/types";
|
|
2
|
+
|
|
3
|
+
export interface GetEstimateParameters {
|
|
4
|
+
fixedPageLimit: number;
|
|
5
|
+
screenPageLimit: number;
|
|
6
|
+
shareScreenStarted: boolean;
|
|
7
|
+
shared?: boolean;
|
|
8
|
+
eventType: EventType;
|
|
9
|
+
removeAltGrid: boolean;
|
|
10
|
+
isWideScreen: boolean;
|
|
11
|
+
isMediumScreen: boolean;
|
|
12
|
+
updateRemoveAltGrid: (value: boolean) => void;
|
|
13
|
+
|
|
14
|
+
// mediaSfu functions
|
|
15
|
+
calculateRowsAndColumns: CalculateRowsAndColumnsType;
|
|
16
|
+
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface GetEstimateOptions {
|
|
21
|
+
n: number;
|
|
22
|
+
parameters: GetEstimateParameters;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Export the type definition for the function
|
|
26
|
+
export type GetEstimateType = (options: GetEstimateOptions) => [number, number, number];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Estimates the number of rows and columns for a given set of parameters.
|
|
30
|
+
*
|
|
31
|
+
* @param {GetEstimateOptions} options - The options for the estimation.
|
|
32
|
+
* @param {number} options.n - The number of items to estimate for.
|
|
33
|
+
* @param {GetEstimateParameters} options.parameters - The parameters for the estimation.
|
|
34
|
+
* @param {number} options.parameters.fixedPageLimit - The fixed page limit.
|
|
35
|
+
* @param {number} options.parameters.screenPageLimit - The screen page limit.
|
|
36
|
+
* @param {boolean} options.parameters.shareScreenStarted - Indicates if screen sharing has started.
|
|
37
|
+
* @param {boolean} [options.parameters.shared] - Indicates if sharing is active.
|
|
38
|
+
* @param {string} options.parameters.eventType - The type of event (e.g., "chat", "conference").
|
|
39
|
+
* @param {boolean} options.parameters.removeAltGrid - Indicates if the alternate grid should be removed.
|
|
40
|
+
* @param {boolean} options.parameters.isWideScreen - Indicates if the screen is wide.
|
|
41
|
+
* @param {boolean} options.parameters.isMediumScreen - Indicates if the screen is medium-sized.
|
|
42
|
+
* @param {Function} options.parameters.updateRemoveAltGrid - Function to update the removeAltGrid parameter.
|
|
43
|
+
* @param {Function} options.parameters.calculateRowsAndColumns - Function to calculate rows and columns.
|
|
44
|
+
*
|
|
45
|
+
* @returns {[number, number, number]} An array containing the estimated number of items, rows, and columns.
|
|
46
|
+
*
|
|
47
|
+
* @throws Will log an error message if an error occurs during estimation.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const options = {
|
|
51
|
+
* n: 10,
|
|
52
|
+
* parameters: {
|
|
53
|
+
* fixedPageLimit: 5,
|
|
54
|
+
* screenPageLimit: 8,
|
|
55
|
+
* shareScreenStarted: false,
|
|
56
|
+
* shared: false,
|
|
57
|
+
* eventType: 'conference',
|
|
58
|
+
* removeAltGrid: false,
|
|
59
|
+
* isWideScreen: true,
|
|
60
|
+
* isMediumScreen: false,
|
|
61
|
+
* updateRemoveAltGrid: (value) => console.log('Remove Alt Grid:', value),
|
|
62
|
+
* calculateRowsAndColumns: ({ n }) => [3, 4], // Example implementation
|
|
63
|
+
* },
|
|
64
|
+
* };
|
|
65
|
+
*
|
|
66
|
+
* const estimate = getEstimate(options);
|
|
67
|
+
* console.log('Estimated:', estimate); // Output: Estimated: [10, 3, 4]
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
export function getEstimate({ n, parameters }: GetEstimateOptions): [number, number, number] {
|
|
71
|
+
try {
|
|
72
|
+
// Destructure parameters
|
|
73
|
+
let {
|
|
74
|
+
fixedPageLimit,
|
|
75
|
+
screenPageLimit,
|
|
76
|
+
shareScreenStarted,
|
|
77
|
+
shared,
|
|
78
|
+
eventType,
|
|
79
|
+
removeAltGrid,
|
|
80
|
+
isWideScreen,
|
|
81
|
+
isMediumScreen,
|
|
82
|
+
updateRemoveAltGrid,
|
|
83
|
+
|
|
84
|
+
//mediaSfu functions
|
|
85
|
+
calculateRowsAndColumns,
|
|
86
|
+
} = parameters;
|
|
87
|
+
|
|
88
|
+
// Calculate rows and columns
|
|
89
|
+
const [rows, cols] = calculateRowsAndColumns({ n });
|
|
90
|
+
|
|
91
|
+
// Check conditions for removing alt grid
|
|
92
|
+
if (
|
|
93
|
+
n < fixedPageLimit ||
|
|
94
|
+
((shareScreenStarted || shared) && n < screenPageLimit + 1)
|
|
95
|
+
) {
|
|
96
|
+
removeAltGrid = true;
|
|
97
|
+
updateRemoveAltGrid(removeAltGrid);
|
|
98
|
+
|
|
99
|
+
// Return estimated values based on screen width
|
|
100
|
+
if (!(isMediumScreen || isWideScreen)) {
|
|
101
|
+
return eventType === "chat" ||
|
|
102
|
+
(eventType === "conference" && !(shareScreenStarted || shared))
|
|
103
|
+
? [n, n, 1]
|
|
104
|
+
: [n, 1, n];
|
|
105
|
+
} else {
|
|
106
|
+
return eventType === "chat" ||
|
|
107
|
+
(eventType === "conference" && !(shareScreenStarted || shared))
|
|
108
|
+
? [n, 1, n]
|
|
109
|
+
: [n, n, 1];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return [rows * cols, rows, cols];
|
|
114
|
+
} catch (error) {
|
|
115
|
+
// Handle errors during estimation
|
|
116
|
+
if (error instanceof Error) {
|
|
117
|
+
console.log("Error estimating rows and columns:", error.message);
|
|
118
|
+
} else {
|
|
119
|
+
console.log("Error estimating rows and columns:", error);
|
|
120
|
+
}
|
|
121
|
+
return [0, 0, 0];
|
|
122
|
+
// throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Socket } from "socket.io-client";
|
|
2
|
+
import { SignalNewConsumerTransportParameters, SignalNewConsumerTransportType } from '../types/types';
|
|
3
|
+
|
|
4
|
+
export interface GetPipedProducersAltParameters extends SignalNewConsumerTransportParameters {
|
|
5
|
+
member: string;
|
|
6
|
+
|
|
7
|
+
// mediasfu functions
|
|
8
|
+
signalNewConsumerTransport: SignalNewConsumerTransportType;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface GetPipedProducersAltOptions {
|
|
13
|
+
community?: boolean;
|
|
14
|
+
nsock: Socket;
|
|
15
|
+
islevel: string;
|
|
16
|
+
parameters: GetPipedProducersAltParameters;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Export the type definition for the function
|
|
20
|
+
export type GetPipedProducersAltType = (options: GetPipedProducersAltOptions) => Promise<void>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves piped producers and signals new consumer transport for each retrieved producer.
|
|
24
|
+
*
|
|
25
|
+
* @param {GetPipedProducersAltOptions} options - The options for retrieving piped producers.
|
|
26
|
+
* @param {boolean} options.community - A flag indicating if the room is a community edition room.
|
|
27
|
+
* @param {Socket} options.nsock - The WebSocket instance used for communication.
|
|
28
|
+
* @param {string} options.islevel - A flag indicating the level of the request.
|
|
29
|
+
* @param {GetPipedProducersAltParameters} options.parameters - Additional parameters for the request.
|
|
30
|
+
* @param {string} options.parameters.member - The member identifier.
|
|
31
|
+
* @param {Function} options.parameters.signalNewConsumerTransport - A function to signal new consumer transport.
|
|
32
|
+
*
|
|
33
|
+
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
34
|
+
*
|
|
35
|
+
* @throws {Error} If an error occurs during the process of retrieving producers.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const options = {
|
|
39
|
+
* community: false,
|
|
40
|
+
* nsock: socketInstance,
|
|
41
|
+
* islevel: '1',
|
|
42
|
+
* parameters: {
|
|
43
|
+
* member: 'memberId',
|
|
44
|
+
* signalNewConsumerTransport: async ({ nsock, remoteProducerId, islevel, parameters }) => {
|
|
45
|
+
* // Implementation for signaling new consumer transport
|
|
46
|
+
* },
|
|
47
|
+
* },
|
|
48
|
+
* };
|
|
49
|
+
*
|
|
50
|
+
* getPipedProducersAlt(options)
|
|
51
|
+
* .then(() => {
|
|
52
|
+
* console.log('Successfully retrieved piped producers');
|
|
53
|
+
* })
|
|
54
|
+
* .catch((error) => {
|
|
55
|
+
* console.error('Error retrieving piped producers:', error);
|
|
56
|
+
* });
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
export const getPipedProducersAlt = async ({
|
|
60
|
+
community = false,
|
|
61
|
+
nsock,
|
|
62
|
+
islevel,
|
|
63
|
+
parameters,
|
|
64
|
+
}: GetPipedProducersAltOptions): Promise<void> => {
|
|
65
|
+
try {
|
|
66
|
+
// Destructure parameters
|
|
67
|
+
const { member, signalNewConsumerTransport } = parameters;
|
|
68
|
+
|
|
69
|
+
const emitName = community ? "getProducersAlt" : "getProducersPipedAlt";
|
|
70
|
+
|
|
71
|
+
// Emit request to get piped producers using WebSocket
|
|
72
|
+
await nsock.emit(
|
|
73
|
+
emitName,
|
|
74
|
+
{ islevel, member },
|
|
75
|
+
async (producerIds: string[]) => {
|
|
76
|
+
// Check if producers are retrieved
|
|
77
|
+
if (producerIds.length > 0) {
|
|
78
|
+
// Signal new consumer transport for each retrieved producer
|
|
79
|
+
await Promise.all(
|
|
80
|
+
producerIds.map((id) =>
|
|
81
|
+
signalNewConsumerTransport({
|
|
82
|
+
nsock,
|
|
83
|
+
remoteProducerId: id,
|
|
84
|
+
islevel,
|
|
85
|
+
parameters,
|
|
86
|
+
})
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
// Handle errors during the process of retrieving producers
|
|
94
|
+
console.log("Error getting piped producers:", (error as Error).message);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Socket } from "socket.io-client";
|
|
2
|
+
import { SignalNewConsumerTransportParameters, SignalNewConsumerTransportType } from "../types/types";
|
|
3
|
+
export interface GetProducersPipedParameters extends SignalNewConsumerTransportParameters {
|
|
4
|
+
member: string;
|
|
5
|
+
|
|
6
|
+
// mediasfu functions
|
|
7
|
+
signalNewConsumerTransport: SignalNewConsumerTransportType,
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface GetProducersPipedOptions {
|
|
12
|
+
nsock: Socket;
|
|
13
|
+
islevel: string;
|
|
14
|
+
parameters: GetProducersPipedParameters;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Export the type definition for the function
|
|
18
|
+
export type GetProducersPipedType = (options: GetProducersPipedOptions) => Promise<void>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves piped producers and signals new consumer transport for each retrieved producer.
|
|
22
|
+
*
|
|
23
|
+
* @param {GetProducersPipedOptions} options - The options for getting piped producers.
|
|
24
|
+
* @param {Socket} options.nsock - The WebSocket instance used for communication.
|
|
25
|
+
* @param {string} options.islevel - A flag indicating the level of the operation.
|
|
26
|
+
* @param {GetProducersPipedParameters} options.parameters - Additional parameters for the operation.
|
|
27
|
+
* @param {string} options.parameters.member - The member identifier.
|
|
28
|
+
* @param {Function} options.parameters.signalNewConsumerTransport - The function to signal new consumer transport.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
31
|
+
*
|
|
32
|
+
* @throws {Error} If an error occurs during the process of retrieving producers.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const options = {
|
|
36
|
+
* nsock: socketInstance,
|
|
37
|
+
* islevel: '1',
|
|
38
|
+
* parameters: {
|
|
39
|
+
* member: 'memberId',
|
|
40
|
+
* signalNewConsumerTransport: async ({ remoteProducerId, islevel, nsock, parameters }) => {
|
|
41
|
+
* // Implementation for signaling new consumer transport
|
|
42
|
+
* },
|
|
43
|
+
* },
|
|
44
|
+
* };
|
|
45
|
+
*
|
|
46
|
+
* getProducersPiped(options)
|
|
47
|
+
* .then(() => {
|
|
48
|
+
* console.log('Successfully retrieved piped producers');
|
|
49
|
+
* })
|
|
50
|
+
* .catch((error) => {
|
|
51
|
+
* console.error('Error retrieving piped producers:', error);
|
|
52
|
+
* });
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
export const getProducersPiped = async ({
|
|
56
|
+
nsock,
|
|
57
|
+
islevel,
|
|
58
|
+
parameters,
|
|
59
|
+
}: GetProducersPipedOptions): Promise<void> => {
|
|
60
|
+
try {
|
|
61
|
+
// Destructure parameters
|
|
62
|
+
const { member, signalNewConsumerTransport } = parameters;
|
|
63
|
+
|
|
64
|
+
// Emit request to get piped producers using WebSocket
|
|
65
|
+
await nsock.emit(
|
|
66
|
+
"getProducersPipedAlt",
|
|
67
|
+
{ islevel, member },
|
|
68
|
+
async (producerIds: string[]) => {
|
|
69
|
+
// Check if producers are retrieved
|
|
70
|
+
if (producerIds.length > 0) {
|
|
71
|
+
// Signal new consumer transport for each retrieved producer
|
|
72
|
+
await Promise.all(
|
|
73
|
+
producerIds.map((id) =>
|
|
74
|
+
signalNewConsumerTransport({
|
|
75
|
+
remoteProducerId: id,
|
|
76
|
+
islevel,
|
|
77
|
+
nsock,
|
|
78
|
+
parameters,
|
|
79
|
+
})
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
// Handle errors during the process of retrieving producers
|
|
87
|
+
console.log("Error getting piped producers:", (error as Error).message);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Stream, Participant } from "../types/types";
|
|
2
|
+
export interface GetVideosOptions {
|
|
3
|
+
participants: Participant[];
|
|
4
|
+
allVideoStreams: (Stream | Participant)[];
|
|
5
|
+
oldAllStreams: (Stream | Participant)[];
|
|
6
|
+
adminVidID?: string;
|
|
7
|
+
updateAllVideoStreams: (streams: (Stream | Participant)[]) => void;
|
|
8
|
+
updateOldAllStreams: (streams: (Stream | Participant)[]) => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Export the type definition for the function
|
|
12
|
+
export type GetVideosType = (options: GetVideosOptions) => Promise<void>;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Asynchronously processes and updates video streams by filtering out the admin's video stream.
|
|
17
|
+
*
|
|
18
|
+
* @param {GetVideosOptions} options - The options for getting videos.
|
|
19
|
+
* @param {Participant[]} options.participants - The list of participants.
|
|
20
|
+
* @param {(Stream | Participant)[]} options.allVideoStreams - The list of all video streams.
|
|
21
|
+
* @param {(Stream | Participant)[]} options.oldAllStreams - The list of old video streams.
|
|
22
|
+
* @param {string} [options.adminVidID] - The ID of the admin's video stream.
|
|
23
|
+
* @param {Function} options.updateAllVideoStreams - Function to update the state variable for all video streams.
|
|
24
|
+
* @param {Function} options.updateOldAllStreams - Function to update the state variable for old video streams.
|
|
25
|
+
*
|
|
26
|
+
* @returns {Promise<void>} A promise that resolves when the video streams have been processed and updated.
|
|
27
|
+
*
|
|
28
|
+
* @throws {Error} Throws an error if an issue occurs while processing the streams.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const options = {
|
|
32
|
+
* participants: participantList,
|
|
33
|
+
* allVideoStreams: allStreams,
|
|
34
|
+
* oldAllStreams: oldStreams,
|
|
35
|
+
* adminVidID: 'admin-video-id',
|
|
36
|
+
* updateAllVideoStreams: (streams) => {
|
|
37
|
+
* console.log('All video streams updated:', streams);
|
|
38
|
+
* },
|
|
39
|
+
* updateOldAllStreams: (streams) => {
|
|
40
|
+
* console.log('Old video streams updated:', streams);
|
|
41
|
+
* },
|
|
42
|
+
* };
|
|
43
|
+
*
|
|
44
|
+
* getVideos(options)
|
|
45
|
+
* .then(() => {
|
|
46
|
+
* console.log('Video streams processed successfully');
|
|
47
|
+
* })
|
|
48
|
+
* .catch((error) => {
|
|
49
|
+
* console.error('Error processing video streams:', error);
|
|
50
|
+
* });
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
export async function getVideos({
|
|
54
|
+
participants,
|
|
55
|
+
allVideoStreams,
|
|
56
|
+
oldAllStreams,
|
|
57
|
+
adminVidID,
|
|
58
|
+
updateAllVideoStreams,
|
|
59
|
+
updateOldAllStreams,
|
|
60
|
+
}: GetVideosOptions): Promise<void> {
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
|
|
64
|
+
// Filter out the admin's video stream and update state variables
|
|
65
|
+
let admin = participants.filter(
|
|
66
|
+
(participant) => participant.islevel === "2"
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (admin.length > 0) {
|
|
70
|
+
adminVidID = admin[0].videoID;
|
|
71
|
+
|
|
72
|
+
if (adminVidID != null && adminVidID !== "") {
|
|
73
|
+
let oldAllStreams_: (Stream | Participant)[] = [];
|
|
74
|
+
|
|
75
|
+
// Check if the length of oldAllStreams is greater than 0
|
|
76
|
+
if (oldAllStreams.length > 0) {
|
|
77
|
+
oldAllStreams_ = oldAllStreams;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Filter out admin's video stream from oldAllStreams
|
|
81
|
+
oldAllStreams = allVideoStreams.filter(
|
|
82
|
+
(streame) => streame.producerId === adminVidID
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// If no admin's video stream found, revert to the previous state
|
|
86
|
+
if (oldAllStreams.length < 1) {
|
|
87
|
+
oldAllStreams = oldAllStreams_;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Update the state variable for old video streams
|
|
91
|
+
updateOldAllStreams(oldAllStreams);
|
|
92
|
+
|
|
93
|
+
// Filter out admin's video stream from allVideoStreams
|
|
94
|
+
allVideoStreams = allVideoStreams.filter(
|
|
95
|
+
(streame) => streame.producerId !== adminVidID
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
// Update the state variable for all video streams
|
|
99
|
+
updateAllVideoStreams(allVideoStreams);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
// Handle errors during the process of updating video streams
|
|
104
|
+
console.log("Error updating video streams:", (error as Error).message);
|
|
105
|
+
// throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Stream, Participant } from "../types/types";
|
|
2
|
+
|
|
3
|
+
export interface MixStreamsOptions {
|
|
4
|
+
alVideoStreams: (Stream | Participant)[];
|
|
5
|
+
non_alVideoStreams: Participant[];
|
|
6
|
+
ref_participants: (Stream | Participant)[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Export the type definition for the function
|
|
10
|
+
export type MixStreamsType = (options: MixStreamsOptions) => Promise<(Stream | Participant)[]>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Mixes video and audio streams and participants based on specified parameters.
|
|
14
|
+
*
|
|
15
|
+
* @param {MixStreamsOptions} options - The options for mixing streams.
|
|
16
|
+
* @param {Array} options.alVideoStreams - The list of audio and video streams to mix.
|
|
17
|
+
* @param {Array} options.non_alVideoStreams - The list of non-audio and video streams to mix.
|
|
18
|
+
* @param {Array} options.ref_participants - The list of reference participants to mix.
|
|
19
|
+
* @returns {Promise<Array>} A promise that resolves with the mixed streams.
|
|
20
|
+
* @throws Will throw an error if there is an issue mixing the streams.
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const mixedStreams = await mixStreams({
|
|
24
|
+
* alVideoStreams: [stream1, stream2],
|
|
25
|
+
* non_alVideoStreams: [participant1, participant2],
|
|
26
|
+
* ref_participants: [participant1, participant2],
|
|
27
|
+
* });
|
|
28
|
+
* console.log('Mixed streams:', mixedStreams);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export async function mixStreams({
|
|
34
|
+
alVideoStreams,
|
|
35
|
+
non_alVideoStreams,
|
|
36
|
+
ref_participants,
|
|
37
|
+
}: MixStreamsOptions): Promise<(Stream | Participant)[]> {
|
|
38
|
+
try {
|
|
39
|
+
|
|
40
|
+
const mixedStreams: (Stream | Participant)[] = [];
|
|
41
|
+
|
|
42
|
+
// Find "youyou" or "youyouyou" stream
|
|
43
|
+
const youyouStream = alVideoStreams.find(
|
|
44
|
+
(obj) => obj.producerId === "youyou" || obj.producerId === "youyouyou"
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
let remainingAlVideoStreams = alVideoStreams.filter(
|
|
48
|
+
(obj) => obj.producerId !== "youyou" && obj.producerId !== "youyouyou"
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// Separate unmuted and muted streams
|
|
52
|
+
const unmutedAlVideoStreams = remainingAlVideoStreams.filter((obj) => {
|
|
53
|
+
const participant = ref_participants.find(
|
|
54
|
+
(p) => p.videoID === obj.producerId
|
|
55
|
+
);
|
|
56
|
+
return !obj.muted && participant && participant.muted === false;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const mutedAlVideoStreams = remainingAlVideoStreams.filter((obj) => {
|
|
60
|
+
const participant = ref_participants.find(
|
|
61
|
+
(p) => p.videoID === obj.producerId
|
|
62
|
+
);
|
|
63
|
+
return obj.muted || (participant && participant.muted === true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const nonAlVideoStreams = [...non_alVideoStreams]; // Create a copy of non_alVideoStreams
|
|
67
|
+
|
|
68
|
+
// Add unmutedAlVideoStreams to mixedStreams
|
|
69
|
+
mixedStreams.push(...unmutedAlVideoStreams);
|
|
70
|
+
|
|
71
|
+
// Interleave the mutedAlVideoStreams and nonAlVideoStreams
|
|
72
|
+
let nonAlIndex = 0;
|
|
73
|
+
for (let i = 0; i < mutedAlVideoStreams.length; i++) {
|
|
74
|
+
if (nonAlIndex < nonAlVideoStreams.length) {
|
|
75
|
+
mixedStreams.push(nonAlVideoStreams[nonAlIndex]);
|
|
76
|
+
nonAlIndex++;
|
|
77
|
+
}
|
|
78
|
+
mixedStreams.push(mutedAlVideoStreams[i]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Handle remaining nonAlVideoStreams (if any)
|
|
82
|
+
for (let i = nonAlIndex; i < nonAlVideoStreams.length; i++) {
|
|
83
|
+
mixedStreams.push(nonAlVideoStreams[i]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Unshift 'youyou' or 'youyouyou' stream to mixedStreams
|
|
87
|
+
if (youyouStream) {
|
|
88
|
+
mixedStreams.unshift(youyouStream);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return mixedStreams;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
// Handle errors during the process of mixing streams
|
|
94
|
+
console.log("Error mixing streams:", (error as Error).message);
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|