mediasfu-shared 1.0.1 → 1.0.3
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 -21
- package/README.md +103 -222
- package/dist/index.cjs +7634 -2180
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4203 -273
- package/dist/index.js +7663 -2209
- package/dist/index.js.map +1 -1
- package/package.json +96 -78
- package/src/ProducerClient/producerClientEmits/joinRoomClient.ts +57 -0
- package/src/ProducerClient/producerClientEmits/updateRoomParametersClient.ts +401 -0
- package/src/consumers/addVideosGrid.ts +3 -2
- package/src/consumers/changeVids.ts +111 -41
- package/src/consumers/checkPermission.ts +35 -1
- package/src/consumers/connectIps.ts +3 -1
- package/src/consumers/connectLocalIps.ts +3 -1
- package/src/consumers/connectRecvTransport.ts +96 -1
- package/src/consumers/consumerResume.ts +2 -2
- package/src/consumers/dispStreams.ts +83 -37
- package/src/consumers/frameworkConsumerContract.ts +6 -0
- package/src/consumers/generatePageContent.ts +24 -10
- package/src/consumers/getPipedProducersAlt.ts +112 -16
- package/src/consumers/gridLayout/addVideosGrid.engine.ts +42 -0
- package/src/consumers/gridLayout/prepopulateUserMedia.engine.ts +444 -0
- package/src/consumers/mixStreams.ts +45 -14
- package/src/consumers/onScreenChanges.ts +25 -10
- package/src/consumers/prepopulateUserMedia.ts +3 -2
- package/src/consumers/processConsumerTransports.ts +68 -23
- package/src/consumers/processConsumerTransportsAudio.ts +146 -17
- package/src/consumers/reUpdateInter.ts +61 -21
- package/src/consumers/readjust.ts +30 -14
- package/src/consumers/reorderStreams.ts +76 -42
- package/src/consumers/resumePauseAudioStreams.ts +66 -17
- package/src/consumers/resumePauseStreams.ts +53 -10
- package/src/consumers/socketReceiveMethods/joinConsumeRoom.ts +8 -0
- package/src/consumers/socketReceiveMethods/newPipeProducer.ts +114 -0
- package/src/consumers/socketReceiveMethods/producerClosed.ts +13 -0
- package/src/consumers/streamSuccessScreen.ts +2 -2
- package/src/consumers/streamSuccessVideo.ts +5 -0
- package/src/consumers/translationConsumerSwitch.ts +321 -0
- package/src/index.ts +85 -1
- package/src/methods/coHostMethods/modifyCoHostSettings.ts +9 -9
- package/src/methods/displaySettings/modifyDisplaySettings.ts +5 -0
- package/src/methods/index.ts +66 -0
- package/src/methods/message/sendMessage.ts +12 -29
- package/src/methods/panelists/focusPanelists.ts +83 -0
- package/src/methods/panelists/index.ts +3 -0
- package/src/methods/panelists/launchPanelists.ts +13 -0
- package/src/methods/panelists/updatePanelists.ts +135 -0
- package/src/methods/permissions/index.ts +3 -0
- package/src/methods/permissions/launchPermissions.ts +13 -0
- package/src/methods/permissions/updateParticipantPermission.ts +127 -0
- package/src/methods/permissions/updatePermissionConfig.ts +52 -0
- package/src/methods/polls/pollUpdated.ts +88 -0
- package/src/methods/recording/confirmRecording.ts +15 -12
- package/src/methods/recording/recordResumeTimer.ts +2 -2
- package/src/methods/recording/recordStartTimer.ts +2 -2
- package/src/methods/recording/timeLeftRecording.ts +25 -0
- package/src/methods/requests/hostRequestResponse.ts +158 -0
- package/src/methods/settings/modifySettings.ts +17 -17
- package/src/methods/socketReceive/allMembers.ts +450 -0
- package/src/methods/socketReceive/allMembersRest.ts +480 -0
- package/src/methods/socketReceive/allWaitingRoomMembers.ts +35 -0
- package/src/methods/socketReceive/banParticipant.ts +73 -0
- package/src/methods/socketReceive/controlMediaHost.ts +280 -0
- package/src/methods/socketReceive/disconnect.ts +40 -0
- package/src/methods/socketReceive/disconnectUserSelf.ts +56 -0
- package/src/methods/socketReceive/getDomains.ts +112 -0
- package/src/methods/socketReceive/meetingEnded.ts +49 -0
- package/src/methods/socketReceive/meetingStillThere.ts +26 -0
- package/src/methods/socketReceive/panelistReceiveMethods.ts +195 -0
- package/src/methods/socketReceive/participantRequested.ts +48 -0
- package/src/methods/socketReceive/permissionReceiveMethods.ts +59 -0
- package/src/methods/socketReceive/personJoined.ts +35 -0
- package/src/methods/socketReceive/producerMediaClosed.ts +223 -0
- package/src/methods/socketReceive/producerMediaPaused.ts +267 -0
- package/src/methods/socketReceive/producerMediaResumed.ts +157 -0
- package/src/methods/socketReceive/reInitiateRecording.ts +53 -0
- package/src/methods/socketReceive/receiveMessage.ts +117 -0
- package/src/methods/socketReceive/recordingNotice.ts +286 -0
- package/src/methods/socketReceive/roomRecordParams.ts +122 -0
- package/src/methods/socketReceive/screenProducerId.ts +61 -0
- package/src/methods/socketReceive/startRecords.ts +46 -0
- package/src/methods/socketReceive/stoppedRecording.ts +44 -0
- package/src/methods/socketReceive/translationReceiveMethods.ts +581 -0
- package/src/methods/socketReceive/updateConsumingDomains.ts +128 -0
- package/src/methods/socketReceive/updateMediaSettings.ts +45 -0
- package/src/methods/socketReceive/updatedCoHost.ts +75 -0
- package/src/methods/socketReceive/userWaiting.ts +45 -0
- package/src/methods/stream/clickAudio.ts +380 -0
- package/src/methods/stream/clickChat.ts +36 -0
- package/src/methods/stream/clickScreenShare.ts +173 -0
- package/src/methods/stream/clickVideo.ts +28 -6
- package/src/methods/stream/index.ts +1 -0
- package/src/methods/utils/SoundPlayer.ts +31 -0
- package/src/methods/utils/checkLimitsAndMakeRequest.ts +156 -2
- package/src/methods/utils/createResponseJoinRoom.ts +47 -0
- package/src/methods/utils/createRoomOnMediaSFU.ts +160 -0
- package/src/methods/utils/formatNumber.ts +42 -0
- package/src/methods/utils/generateRandomMessages.ts +70 -0
- package/src/methods/utils/generateRandomParticipants.ts +100 -0
- package/src/methods/utils/generateRandomPolls.ts +43 -0
- package/src/methods/utils/generateRandomRequestList.ts +51 -0
- package/src/methods/utils/generateRandomWaitingRoomList.ts +17 -0
- package/src/methods/utils/getModalPosition.ts +23 -0
- package/src/methods/utils/getOverlayPosition.ts +37 -0
- package/src/methods/utils/initialValuesState.ts +405 -0
- package/src/methods/utils/joinRoomOnMediaSFU.ts +124 -0
- package/src/methods/utils/liveSubtitle.ts +107 -0
- package/src/methods/utils/meetingTimeRemaining.ts +33 -0
- package/src/methods/utils/meetingTimer/startMeetingProgressTimer.ts +72 -0
- package/src/methods/utils/producer/aParams.ts +10 -0
- package/src/methods/utils/producer/hParams.ts +26 -0
- package/src/methods/utils/producer/screenParams.ts +13 -0
- package/src/methods/utils/producer/vParams.ts +26 -0
- package/src/methods/utils/producer/videoCaptureConstraints.ts +65 -0
- package/src/methods/utils/resolveMediaSFURoomApi.ts +28 -0
- package/src/methods/utils/sleep.ts +24 -0
- package/src/methods/utils/translationLanguages.ts +308 -0
- package/src/methods/utils/webrtc.ts +44 -0
- package/src/methods/welcome/handleWelcomeRequest.ts +11 -2
- package/src/methods/welcome/index.ts +5 -1
- package/src/methods/whiteboard/captureCanvasStream.ts +128 -0
- package/src/producers/producerEmits/joinConRoom.ts +2 -2
- package/src/producers/producerEmits/joinLocalRoom.ts +240 -0
- package/src/producers/producerEmits/joinRoom.ts +129 -0
- package/src/types/shared-base-types.ts +14 -3
- package/src/types/types.ts +255 -0
|
@@ -1,78 +1,146 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { Stream, Participant,
|
|
3
|
+
import { Stream, Participant, AudioDecibels, EventType } from "../types/types";
|
|
4
|
+
|
|
5
|
+
interface ChangeVidsStreamLike {
|
|
6
|
+
producerId?: string | null;
|
|
7
|
+
audioID?: string | null;
|
|
8
|
+
name?: string;
|
|
9
|
+
muted?: boolean | null;
|
|
10
|
+
stream?: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ChangeVidsParticipantLike {
|
|
14
|
+
name: string;
|
|
15
|
+
islevel?: string | null;
|
|
16
|
+
videoID?: string | null;
|
|
17
|
+
audioID?: string | null;
|
|
18
|
+
muted?: boolean | null;
|
|
19
|
+
breakRoom?: number | null;
|
|
20
|
+
stream?: unknown;
|
|
21
|
+
}
|
|
4
22
|
|
|
5
|
-
|
|
23
|
+
interface BreakoutParticipantLike {
|
|
24
|
+
name: string;
|
|
25
|
+
breakRoom?: number | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface AudioDecibelLike {
|
|
29
|
+
name: string;
|
|
30
|
+
averageLoudness?: number | null;
|
|
31
|
+
}
|
|
6
32
|
|
|
7
|
-
|
|
33
|
+
type BooleanUpdater = (value: boolean) => void;
|
|
34
|
+
type NumberUpdater = (value: number) => void;
|
|
35
|
+
type StringListUpdater = (names: string[]) => void;
|
|
36
|
+
|
|
37
|
+
type EntryArrayUpdater<TEntry> = {
|
|
38
|
+
bivarianceHack: (entries: TEntry[]) => void;
|
|
39
|
+
}["bivarianceHack"];
|
|
40
|
+
|
|
41
|
+
type EntryMatrixUpdater<TEntry> = {
|
|
42
|
+
bivarianceHack: (entries: TEntry[][]) => void;
|
|
43
|
+
}["bivarianceHack"];
|
|
44
|
+
|
|
45
|
+
type MixStreamsInvoker<TEntry, TParticipant> = (options: {
|
|
46
|
+
alVideoStreams: TEntry[];
|
|
47
|
+
non_alVideoStreams: TParticipant[];
|
|
48
|
+
ref_participants: TEntry[];
|
|
49
|
+
}) => Promise<TEntry[]>;
|
|
50
|
+
|
|
51
|
+
type DispStreamsInvoker = (options: {
|
|
52
|
+
lStreams: any[];
|
|
53
|
+
ind: number;
|
|
54
|
+
auto?: boolean;
|
|
55
|
+
parameters: any;
|
|
56
|
+
breakRoom?: number;
|
|
57
|
+
inBreakRoom?: boolean;
|
|
58
|
+
ChatSkip?: boolean;
|
|
59
|
+
forChatCard?: any;
|
|
60
|
+
forChatID?: any;
|
|
61
|
+
}) => Promise<void>;
|
|
62
|
+
|
|
63
|
+
export interface ChangeVidsParameters<
|
|
64
|
+
TStream extends ChangeVidsStreamLike = Stream,
|
|
65
|
+
TParticipant extends ChangeVidsParticipantLike = Participant,
|
|
66
|
+
TBreakoutParticipant extends BreakoutParticipantLike = BreakoutParticipantLike,
|
|
67
|
+
TAudioDecibel extends AudioDecibelLike = AudioDecibels,
|
|
68
|
+
TMediaHandle = unknown,
|
|
69
|
+
> {
|
|
70
|
+
|
|
71
|
+
allVideoStreams: (TStream | TParticipant)[];
|
|
8
72
|
p_activeNames: string[];
|
|
9
73
|
activeNames: string[];
|
|
10
74
|
dispActiveNames: string[];
|
|
11
75
|
shareScreenStarted: boolean;
|
|
12
76
|
shared: boolean;
|
|
13
|
-
newLimitedStreams: (
|
|
14
|
-
non_alVideoStreams:
|
|
15
|
-
ref_participants:
|
|
16
|
-
participants:
|
|
77
|
+
newLimitedStreams: (TStream | TParticipant)[];
|
|
78
|
+
non_alVideoStreams: TParticipant[];
|
|
79
|
+
ref_participants: TParticipant[];
|
|
80
|
+
participants: TParticipant[];
|
|
17
81
|
eventType: EventType;
|
|
18
82
|
islevel: string;
|
|
19
83
|
member: string;
|
|
20
84
|
sortAudioLoudness: boolean;
|
|
21
|
-
audioDecibels:
|
|
22
|
-
mixed_alVideoStreams: (
|
|
23
|
-
non_alVideoStreams_muted:
|
|
85
|
+
audioDecibels: TAudioDecibel[];
|
|
86
|
+
mixed_alVideoStreams: (TStream | TParticipant)[];
|
|
87
|
+
non_alVideoStreams_muted: TParticipant[];
|
|
24
88
|
remoteProducerId?: string;
|
|
25
|
-
localStreamVideo:
|
|
26
|
-
oldAllStreams: (
|
|
89
|
+
localStreamVideo: TMediaHandle | null;
|
|
90
|
+
oldAllStreams: (TStream | TParticipant)[];
|
|
27
91
|
screenPageLimit: number;
|
|
28
92
|
meetingDisplayType: string;
|
|
29
93
|
meetingVideoOptimized: boolean;
|
|
30
94
|
recordingVideoOptimized: boolean;
|
|
31
95
|
recordingDisplayType: "video" | "media" | "all";
|
|
32
|
-
paginatedStreams: (
|
|
96
|
+
paginatedStreams: (TStream | TParticipant)[][];
|
|
33
97
|
itemPageLimit: number;
|
|
34
98
|
doPaginate: boolean;
|
|
35
99
|
prevDoPaginate: boolean;
|
|
36
100
|
currentUserPage: number;
|
|
37
|
-
breakoutRooms:
|
|
101
|
+
breakoutRooms: TBreakoutParticipant[][];
|
|
38
102
|
hostNewRoom: number;
|
|
39
103
|
breakOutRoomStarted: boolean;
|
|
40
104
|
breakOutRoomEnded: boolean;
|
|
41
|
-
virtualStream:
|
|
105
|
+
virtualStream: TMediaHandle | null;
|
|
42
106
|
mainRoomsLength: number;
|
|
43
107
|
memberRoom: number;
|
|
44
|
-
updateP_activeNames:
|
|
45
|
-
updateActiveNames:
|
|
46
|
-
updateDispActiveNames:
|
|
47
|
-
updateNewLimitedStreams:
|
|
48
|
-
updateNon_alVideoStreams:
|
|
49
|
-
updateRef_participants:
|
|
50
|
-
updateSortAudioLoudness:
|
|
51
|
-
updateMixed_alVideoStreams:
|
|
52
|
-
updateNon_alVideoStreams_muted:
|
|
53
|
-
updatePaginatedStreams:
|
|
54
|
-
updateDoPaginate:
|
|
55
|
-
updatePrevDoPaginate:
|
|
56
|
-
updateCurrentUserPage:
|
|
57
|
-
updateNumberPages:
|
|
58
|
-
updateMainRoomsLength:
|
|
59
|
-
updateMemberRoom:
|
|
108
|
+
updateP_activeNames: StringListUpdater;
|
|
109
|
+
updateActiveNames: StringListUpdater;
|
|
110
|
+
updateDispActiveNames: StringListUpdater;
|
|
111
|
+
updateNewLimitedStreams: EntryArrayUpdater<TStream | TParticipant>;
|
|
112
|
+
updateNon_alVideoStreams: EntryArrayUpdater<TParticipant>;
|
|
113
|
+
updateRef_participants: EntryArrayUpdater<TParticipant>;
|
|
114
|
+
updateSortAudioLoudness: BooleanUpdater;
|
|
115
|
+
updateMixed_alVideoStreams: EntryArrayUpdater<TStream | TParticipant>;
|
|
116
|
+
updateNon_alVideoStreams_muted: EntryArrayUpdater<TParticipant>;
|
|
117
|
+
updatePaginatedStreams: EntryMatrixUpdater<TStream | TParticipant>;
|
|
118
|
+
updateDoPaginate: BooleanUpdater;
|
|
119
|
+
updatePrevDoPaginate: BooleanUpdater;
|
|
120
|
+
updateCurrentUserPage: NumberUpdater;
|
|
121
|
+
updateNumberPages: NumberUpdater;
|
|
122
|
+
updateMainRoomsLength: NumberUpdater;
|
|
123
|
+
updateMemberRoom: NumberUpdater;
|
|
60
124
|
|
|
61
125
|
// mediasfu functions
|
|
62
|
-
mixStreams:
|
|
63
|
-
dispStreams:
|
|
64
|
-
getUpdatedAllParams: () => ChangeVidsParameters
|
|
126
|
+
mixStreams: MixStreamsInvoker<TStream | TParticipant, TParticipant>;
|
|
127
|
+
dispStreams: DispStreamsInvoker;
|
|
128
|
+
getUpdatedAllParams: () => ChangeVidsParameters<TStream, TParticipant, TBreakoutParticipant, TAudioDecibel, TMediaHandle>;
|
|
65
129
|
[key: string]: any;
|
|
66
130
|
|
|
67
131
|
}
|
|
68
132
|
|
|
69
|
-
export interface ChangeVidsOptions
|
|
133
|
+
export interface ChangeVidsOptions<
|
|
134
|
+
TParameters extends ChangeVidsParameters<any, any, any, any, any> = ChangeVidsParameters,
|
|
135
|
+
> {
|
|
70
136
|
screenChanged?: boolean;
|
|
71
|
-
parameters:
|
|
137
|
+
parameters: TParameters;
|
|
72
138
|
}
|
|
73
139
|
|
|
74
140
|
// Export the type definition for the function
|
|
75
|
-
export type ChangeVidsType =
|
|
141
|
+
export type ChangeVidsType = <
|
|
142
|
+
TParameters extends ChangeVidsParameters<any, any, any, any, any> = ChangeVidsParameters,
|
|
143
|
+
>(options: ChangeVidsOptions<TParameters>) => Promise<void>;
|
|
76
144
|
|
|
77
145
|
/**
|
|
78
146
|
* Asynchronously changes the video streams based on the provided options.
|
|
@@ -210,9 +278,11 @@ export type ChangeVidsType = (options: ChangeVidsOptions) => Promise<void>;
|
|
|
210
278
|
* });
|
|
211
279
|
*/
|
|
212
280
|
|
|
213
|
-
export const changeVids = async
|
|
214
|
-
|
|
215
|
-
|
|
281
|
+
export const changeVids = async <
|
|
282
|
+
TParameters extends ChangeVidsParameters<any, any, any, any, any> = ChangeVidsParameters,
|
|
283
|
+
>({ screenChanged = false, parameters }: ChangeVidsOptions<TParameters>): Promise<void> => {
|
|
284
|
+
const { getUpdatedAllParams } = parameters;
|
|
285
|
+
const updatedParameters = getUpdatedAllParams() as TParameters;
|
|
216
286
|
|
|
217
287
|
let {
|
|
218
288
|
allVideoStreams,
|
|
@@ -270,7 +340,7 @@ export const changeVids = async ({ screenChanged = false, parameters }: ChangeVi
|
|
|
270
340
|
updateMemberRoom,
|
|
271
341
|
mixStreams,
|
|
272
342
|
dispStreams,
|
|
273
|
-
} =
|
|
343
|
+
} = updatedParameters;
|
|
274
344
|
|
|
275
345
|
try {
|
|
276
346
|
let alVideoStreams = [...allVideoStreams];
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { PermissionConfig } from '../methods/permissions/updatePermissionConfig';
|
|
2
|
+
|
|
1
3
|
export interface CheckPermissionOptions {
|
|
2
4
|
audioSetting: string;
|
|
3
5
|
videoSetting: string;
|
|
4
6
|
screenshareSetting: string;
|
|
5
7
|
chatSetting: string;
|
|
6
8
|
permissionType: 'audioSetting' | 'videoSetting' | 'screenshareSetting' | 'chatSetting';
|
|
9
|
+
permissionConfig?: PermissionConfig | null;
|
|
10
|
+
participantLevel?: string;
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
// Export the type definition for the function
|
|
@@ -39,9 +43,39 @@ export type CheckPermissionType = (options: CheckPermissionOptions) => Promise<n
|
|
|
39
43
|
* });
|
|
40
44
|
*/
|
|
41
45
|
|
|
42
|
-
export async function checkPermission({
|
|
46
|
+
export async function checkPermission({
|
|
47
|
+
permissionType,
|
|
48
|
+
audioSetting,
|
|
49
|
+
videoSetting,
|
|
50
|
+
screenshareSetting,
|
|
51
|
+
chatSetting,
|
|
52
|
+
permissionConfig,
|
|
53
|
+
participantLevel,
|
|
54
|
+
}: CheckPermissionOptions) {
|
|
43
55
|
try {
|
|
44
56
|
|
|
57
|
+
const permissionTypeToCapability: Record<string, keyof import('../methods/permissions/updatePermissionConfig').PermissionCapabilities> = {
|
|
58
|
+
audioSetting: 'useMic',
|
|
59
|
+
videoSetting: 'useCamera',
|
|
60
|
+
screenshareSetting: 'useScreen',
|
|
61
|
+
chatSetting: 'useChat',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (permissionConfig && participantLevel && participantLevel !== '2') {
|
|
65
|
+
const levelKey = `level${participantLevel}` as 'level0' | 'level1';
|
|
66
|
+
const levelConfig = permissionConfig[levelKey];
|
|
67
|
+
|
|
68
|
+
if (levelConfig) {
|
|
69
|
+
const capability = permissionTypeToCapability[permissionType];
|
|
70
|
+
if (capability) {
|
|
71
|
+
const configValue = levelConfig[capability];
|
|
72
|
+
if (configValue === 'allow') return 0;
|
|
73
|
+
if (configValue === 'approval') return 1;
|
|
74
|
+
return 2;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
45
79
|
// PermissionType is audioSetting, videoSetting, screenshareSetting, chatSetting
|
|
46
80
|
// Perform a switch case to check for the permissionType and return the response
|
|
47
81
|
switch (permissionType) {
|
|
@@ -125,13 +125,15 @@ export const connectIps = async ({
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
// Handle new pipe producer event
|
|
128
|
-
remote_sock.on("new-pipe-producer", async ({ producerId, islevel }: { producerId: string; islevel: string }) => {
|
|
128
|
+
remote_sock.on("new-pipe-producer", async ({ producerId, islevel, isTranslation, translationMeta }: { producerId: string; islevel: string; isTranslation?: boolean; translationMeta?: { speakerId: string; speakerName: string; language: string; originalProducerId?: string; isSpeakerControlled?: boolean } }) => {
|
|
129
129
|
if (newProducerMethod) {
|
|
130
130
|
await newProducerMethod({
|
|
131
131
|
producerId,
|
|
132
132
|
islevel,
|
|
133
133
|
nsock: remote_sock,
|
|
134
134
|
parameters,
|
|
135
|
+
isTranslation,
|
|
136
|
+
translationMeta,
|
|
135
137
|
});
|
|
136
138
|
}
|
|
137
139
|
});
|
|
@@ -76,13 +76,15 @@ export const connectLocalIps = async ({
|
|
|
76
76
|
|
|
77
77
|
// Connect to the remote socket using socket.io-client
|
|
78
78
|
// Handle new pipe producer event
|
|
79
|
-
socket.on("new-producer", async ({ producerId, islevel }: { producerId: string; islevel: string }) => {
|
|
79
|
+
socket.on("new-producer", async ({ producerId, islevel, isTranslation, translationMeta }: { producerId: string; islevel: string; isTranslation?: boolean; translationMeta?: { speakerId: string; speakerName: string; language: string; originalProducerId?: string } }) => {
|
|
80
80
|
if (newProducerMethod) {
|
|
81
81
|
await newProducerMethod({
|
|
82
82
|
producerId,
|
|
83
83
|
islevel,
|
|
84
84
|
nsock: socket,
|
|
85
85
|
parameters,
|
|
86
|
+
isTranslation,
|
|
87
|
+
translationMeta,
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
90
|
});
|
|
@@ -1,6 +1,84 @@
|
|
|
1
1
|
import { Socket } from "socket.io-client";
|
|
2
|
-
import { ConsumerResumeType, ConsumerResumeParameters, Transport as TransportType } from "../types/types";
|
|
2
|
+
import { ConsumerResumeType, ConsumerResumeParameters, Transport as TransportType, Participant } from "../types/types";
|
|
3
3
|
import type { Consumer, Device, Transport } from "mediasoup-client/lib/types";
|
|
4
|
+
|
|
5
|
+
interface SpeakerTranslationState {
|
|
6
|
+
speakerId: string;
|
|
7
|
+
speakerName: string;
|
|
8
|
+
inputLanguage: string;
|
|
9
|
+
outputLanguage: string;
|
|
10
|
+
originalProducerId: string;
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const getSpeakerNameForProducerId = (
|
|
15
|
+
producerId: string,
|
|
16
|
+
parameters: Record<string, any>,
|
|
17
|
+
): string | undefined => {
|
|
18
|
+
const participants = parameters.participants as Participant[] | undefined;
|
|
19
|
+
const participant = participants?.find((candidate) => candidate.audioID === producerId);
|
|
20
|
+
|
|
21
|
+
if (participant?.name) {
|
|
22
|
+
return participant.name;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const audStreamName = (parameters.audStreamNames as Array<{ producerId?: string; name?: string }> | undefined)
|
|
26
|
+
?.find((stream) => stream.producerId === producerId && typeof stream.name === 'string');
|
|
27
|
+
if (audStreamName?.name) {
|
|
28
|
+
return audStreamName.name;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (parameters.allAudioStreams as Array<{ producerId?: string; name?: string }> | undefined)
|
|
32
|
+
?.find((stream) => stream.producerId === producerId && typeof stream.name === 'string')
|
|
33
|
+
?.name;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const isOriginalAudioSuppressedByTranslation = (
|
|
37
|
+
producerId: string,
|
|
38
|
+
parameters: Record<string, any>,
|
|
39
|
+
): boolean => {
|
|
40
|
+
const activeTranslationProducerIds = parameters.activeTranslationProducerIds as Set<string> | undefined;
|
|
41
|
+
if (activeTranslationProducerIds?.has(producerId)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const speakerTranslationStates = parameters.speakerTranslationStates as
|
|
46
|
+
| Map<string, SpeakerTranslationState>
|
|
47
|
+
| undefined;
|
|
48
|
+
|
|
49
|
+
if (!speakerTranslationStates?.size) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const speakerName = getSpeakerNameForProducerId(producerId, parameters);
|
|
54
|
+
|
|
55
|
+
if (speakerName) {
|
|
56
|
+
const speakerState = speakerTranslationStates.get(speakerName);
|
|
57
|
+
if (speakerState?.enabled) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return Array.from(speakerTranslationStates.values()).some((speakerState) => {
|
|
63
|
+
if (!speakerState?.enabled) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (speakerState.originalProducerId === producerId) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!speakerName) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
speakerState.speakerId === speakerName ||
|
|
77
|
+
speakerState.speakerName === speakerName
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
4
82
|
interface Params {
|
|
5
83
|
id: string;
|
|
6
84
|
producerId: string;
|
|
@@ -14,6 +92,7 @@ export interface ConnectRecvTransportParameters extends ConsumerResumeParameters
|
|
|
14
92
|
device: Device | null;
|
|
15
93
|
consumerTransports: TransportType[];
|
|
16
94
|
updateConsumerTransports: (transports: TransportType[]) => void;
|
|
95
|
+
speakerTranslationStates?: Map<string, SpeakerTranslationState>;
|
|
17
96
|
|
|
18
97
|
// mediasfu functions
|
|
19
98
|
consumerResume: ConsumerResumeType;
|
|
@@ -137,6 +216,22 @@ export const connectRecvTransport = async ({
|
|
|
137
216
|
nsock,
|
|
138
217
|
consumer,
|
|
139
218
|
});
|
|
219
|
+
|
|
220
|
+
if (params.kind === 'audio') {
|
|
221
|
+
try {
|
|
222
|
+
const updatedParams = parameters.getUpdatedAllParams();
|
|
223
|
+
if (isOriginalAudioSuppressedByTranslation(remoteProducerId, updatedParams)) {
|
|
224
|
+
consumer.pause();
|
|
225
|
+
nsock.emit(
|
|
226
|
+
'consumer-pause',
|
|
227
|
+
{ serverConsumerId: params.serverConsumerId },
|
|
228
|
+
() => {},
|
|
229
|
+
);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
} catch {
|
|
233
|
+
}
|
|
234
|
+
}
|
|
140
235
|
} catch (error) {
|
|
141
236
|
// Handle error
|
|
142
237
|
console.log("consumerResume error", error);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// This is a React component in the original and not needed for the shared package
|
|
3
3
|
|
|
4
4
|
import { Socket } from 'socket.io-client';
|
|
5
|
+
import { createFrameworkConsumerContractError } from './frameworkConsumerContract';
|
|
5
6
|
|
|
6
7
|
export interface ConsumerResumeParameters {
|
|
7
8
|
[key: string]: any;
|
|
@@ -20,6 +21,5 @@ export interface ConsumerResumeOptions {
|
|
|
20
21
|
export type ConsumerResumeType = (options: ConsumerResumeOptions) => Promise<void>;
|
|
21
22
|
|
|
22
23
|
export const consumerResume: ConsumerResumeType = async () => {
|
|
23
|
-
|
|
24
|
-
console.warn('consumerResume called on shared package - should be implemented in framework package');
|
|
24
|
+
throw createFrameworkConsumerContractError('consumerResume');
|
|
25
25
|
};
|
|
@@ -1,15 +1,52 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Stream, Participant, Transport,
|
|
3
|
-
ProcessConsumerTransportsParameters, ProcessConsumerTransportsType, ResumePauseStreamsParameters, ResumePauseStreamsType, ReadjustParameters, ReadjustType, AddVideosGridType, AddVideosGridParameters, GetEstimateType, CheckGridType, ResumePauseAudioStreamsParameters, ResumePauseAudioStreamsType, GetEstimateParameters,
|
|
2
|
+
Stream, Participant, Transport,
|
|
4
3
|
EventType
|
|
5
4
|
} from "../types/types";
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
interface DispStreamEntryLike<TMediaStream = MediaStream> {
|
|
7
|
+
producerId?: string | null;
|
|
8
|
+
audioID?: string | null;
|
|
9
|
+
id?: string | null;
|
|
10
|
+
name?: string | null;
|
|
11
|
+
muted?: boolean | null;
|
|
12
|
+
stream?: TMediaStream | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface DispParticipantLike<TMediaStream = MediaStream> extends DispStreamEntryLike<TMediaStream> {
|
|
16
|
+
name: string;
|
|
17
|
+
islevel?: string | null;
|
|
18
|
+
videoID?: string | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type StreamCollectionUpdater<TEntry> = {
|
|
22
|
+
bivarianceHack: (streams: TEntry[]) => void;
|
|
23
|
+
}["bivarianceHack"];
|
|
24
|
+
|
|
25
|
+
type OpaqueAsyncInvoker = {
|
|
26
|
+
bivarianceHack: (options: any) => Promise<any>;
|
|
27
|
+
}["bivarianceHack"];
|
|
28
|
+
|
|
29
|
+
type EstimateResult = [unknown, number, number, ...unknown[]];
|
|
30
|
+
|
|
31
|
+
type OpaqueEstimateInvoker = {
|
|
32
|
+
bivarianceHack: (options: any) => EstimateResult;
|
|
33
|
+
}["bivarianceHack"];
|
|
34
|
+
|
|
35
|
+
type OpaqueCheckGridInvoker = {
|
|
36
|
+
bivarianceHack: (options: any) => Promise<any> | any;
|
|
37
|
+
}["bivarianceHack"];
|
|
38
|
+
|
|
39
|
+
export interface DispStreamsParameters<
|
|
40
|
+
TStream extends DispStreamEntryLike<any> = Stream,
|
|
41
|
+
TParticipant extends DispParticipantLike<any> = Participant,
|
|
42
|
+
TTransport = Transport,
|
|
43
|
+
TMediaStream = MediaStream,
|
|
44
|
+
> {
|
|
45
|
+
consumerTransports: TTransport[];
|
|
46
|
+
streamNames: TStream[];
|
|
47
|
+
audStreamNames: TStream[];
|
|
48
|
+
participants: TParticipant[];
|
|
49
|
+
ref_participants: TParticipant[];
|
|
13
50
|
recordingDisplayType: 'video' | 'media' | 'all';
|
|
14
51
|
recordingVideoOptimized: boolean;
|
|
15
52
|
meetingDisplayType: string;
|
|
@@ -24,7 +61,7 @@ export interface DispStreamsParameters extends PrepopulateUserMediaParameters, R
|
|
|
24
61
|
shared: boolean;
|
|
25
62
|
shareScreenStarted: boolean;
|
|
26
63
|
shareEnded: boolean;
|
|
27
|
-
oldAllStreams: (
|
|
64
|
+
oldAllStreams: (TStream | TParticipant)[];
|
|
28
65
|
updateMainWindow: boolean;
|
|
29
66
|
remoteProducerId?: string;
|
|
30
67
|
activeNames: string[];
|
|
@@ -33,53 +70,59 @@ export interface DispStreamsParameters extends PrepopulateUserMediaParameters, R
|
|
|
33
70
|
nForReadjustRecord: number;
|
|
34
71
|
first_round: boolean;
|
|
35
72
|
lock_screen: boolean;
|
|
36
|
-
chatRefStreams: (
|
|
73
|
+
chatRefStreams: (TStream | TParticipant)[];
|
|
37
74
|
eventType: EventType;
|
|
38
75
|
islevel: string;
|
|
39
|
-
localStreamVideo:
|
|
76
|
+
localStreamVideo: TMediaStream | null;
|
|
40
77
|
|
|
41
78
|
breakOutRoomStarted: boolean;
|
|
42
79
|
breakOutRoomEnded: boolean;
|
|
43
80
|
keepBackground: boolean;
|
|
44
|
-
virtualStream:
|
|
81
|
+
virtualStream: TMediaStream | null;
|
|
45
82
|
|
|
46
83
|
updateActiveNames: (names: string[]) => void;
|
|
47
84
|
updateDispActiveNames: (names: string[]) => void;
|
|
48
|
-
updateLStreams:
|
|
49
|
-
updateChatRefStreams:
|
|
85
|
+
updateLStreams: StreamCollectionUpdater<TStream | TParticipant>;
|
|
86
|
+
updateChatRefStreams: StreamCollectionUpdater<TStream | TParticipant>;
|
|
50
87
|
updateNForReadjustRecord: (n: number) => void;
|
|
51
88
|
updateUpdateMainWindow: (value: boolean) => void;
|
|
52
89
|
updateShowMiniView: (value: boolean) => void;
|
|
53
90
|
|
|
54
91
|
// mediasfu functions
|
|
55
|
-
prepopulateUserMedia:
|
|
56
|
-
rePort:
|
|
57
|
-
processConsumerTransports:
|
|
58
|
-
resumePauseStreams:
|
|
59
|
-
readjust:
|
|
60
|
-
addVideosGrid:
|
|
61
|
-
getEstimate:
|
|
62
|
-
checkGrid:
|
|
63
|
-
resumePauseAudioStreams:
|
|
64
|
-
|
|
65
|
-
getUpdatedAllParams: () => DispStreamsParameters
|
|
92
|
+
prepopulateUserMedia: OpaqueAsyncInvoker;
|
|
93
|
+
rePort: OpaqueAsyncInvoker;
|
|
94
|
+
processConsumerTransports: OpaqueAsyncInvoker;
|
|
95
|
+
resumePauseStreams: OpaqueAsyncInvoker;
|
|
96
|
+
readjust: OpaqueAsyncInvoker;
|
|
97
|
+
addVideosGrid: OpaqueAsyncInvoker;
|
|
98
|
+
getEstimate: OpaqueEstimateInvoker;
|
|
99
|
+
checkGrid: OpaqueCheckGridInvoker;
|
|
100
|
+
resumePauseAudioStreams: OpaqueAsyncInvoker;
|
|
101
|
+
|
|
102
|
+
getUpdatedAllParams: () => DispStreamsParameters<TStream, TParticipant, TTransport, TMediaStream>;
|
|
66
103
|
[key: string]: any;
|
|
67
104
|
}
|
|
68
105
|
|
|
69
|
-
export interface DispStreamsOptions
|
|
70
|
-
|
|
106
|
+
export interface DispStreamsOptions<
|
|
107
|
+
TParameters extends DispStreamsParameters<any, any, any, any> = DispStreamsParameters,
|
|
108
|
+
> {
|
|
109
|
+
lStreams: TParameters extends DispStreamsParameters<infer TStream, infer TParticipant, any, any>
|
|
110
|
+
? (TStream | TParticipant)[]
|
|
111
|
+
: (Stream | Participant)[];
|
|
71
112
|
ind: number;
|
|
72
113
|
auto?: boolean;
|
|
73
114
|
ChatSkip?: boolean;
|
|
74
115
|
forChatCard?: any;
|
|
75
116
|
forChatID?: any;
|
|
76
|
-
parameters:
|
|
117
|
+
parameters: TParameters;
|
|
77
118
|
breakRoom?: number;
|
|
78
119
|
inBreakRoom?: boolean;
|
|
79
120
|
}
|
|
80
121
|
|
|
81
122
|
// Export the type definition for the function
|
|
82
|
-
export type DispStreamsType =
|
|
123
|
+
export type DispStreamsType = <
|
|
124
|
+
TParameters extends DispStreamsParameters<any, any, any, any> = DispStreamsParameters,
|
|
125
|
+
>(options: DispStreamsOptions<TParameters>) => Promise<void>;
|
|
83
126
|
|
|
84
127
|
/**
|
|
85
128
|
* Function to display streams based on various parameters and conditions.
|
|
@@ -173,7 +216,9 @@ export type DispStreamsType = (options: DispStreamsOptions) => Promise<void>;
|
|
|
173
216
|
* });
|
|
174
217
|
*/
|
|
175
218
|
|
|
176
|
-
export async function dispStreams
|
|
219
|
+
export async function dispStreams<
|
|
220
|
+
TParameters extends DispStreamsParameters<any, any, any, any> = DispStreamsParameters,
|
|
221
|
+
>({
|
|
177
222
|
lStreams,
|
|
178
223
|
ind,
|
|
179
224
|
auto = false,
|
|
@@ -182,11 +227,12 @@ export async function dispStreams({
|
|
|
182
227
|
parameters,
|
|
183
228
|
breakRoom = -1,
|
|
184
229
|
inBreakRoom = false,
|
|
185
|
-
}: DispStreamsOptions): Promise<void> {
|
|
230
|
+
}: DispStreamsOptions<TParameters>): Promise<void> {
|
|
186
231
|
// Function to display streams
|
|
187
232
|
|
|
188
|
-
|
|
189
|
-
|
|
233
|
+
const { getUpdatedAllParams } = parameters;
|
|
234
|
+
const updatedParameters = getUpdatedAllParams() as TParameters;
|
|
235
|
+
parameters = updatedParameters;
|
|
190
236
|
|
|
191
237
|
let {
|
|
192
238
|
consumerTransports,
|
|
@@ -547,11 +593,11 @@ export async function dispStreams({
|
|
|
547
593
|
}
|
|
548
594
|
|
|
549
595
|
if (eventType == "broadcast") {
|
|
550
|
-
lStreams = lStreams_;
|
|
596
|
+
lStreams = lStreams_ as typeof lStreams;
|
|
551
597
|
updateLStreams(lStreams);
|
|
552
598
|
} else if (eventType == "chat") {
|
|
553
599
|
if (forChatID != null) {
|
|
554
|
-
lStreams = chatRefStreams;
|
|
600
|
+
lStreams = chatRefStreams as typeof lStreams;
|
|
555
601
|
updateLStreams(lStreams);
|
|
556
602
|
} else {
|
|
557
603
|
updateShowMiniView(false);
|
|
@@ -581,7 +627,7 @@ export async function dispStreams({
|
|
|
581
627
|
//remove any stream with name of host.name
|
|
582
628
|
lStreams = lStreams.filter((stream) => {
|
|
583
629
|
return stream.name != host.name;
|
|
584
|
-
});
|
|
630
|
+
}) as typeof lStreams;
|
|
585
631
|
|
|
586
632
|
lStreams.push(streame);
|
|
587
633
|
}
|
|
@@ -598,7 +644,7 @@ export async function dispStreams({
|
|
|
598
644
|
return (
|
|
599
645
|
stream.producerId != "youyou" && stream.producerId != "youyouyou"
|
|
600
646
|
);
|
|
601
|
-
});
|
|
647
|
+
}) as typeof lStreams;
|
|
602
648
|
|
|
603
649
|
if (youyou) {
|
|
604
650
|
lStreams.push(youyou);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const createFrameworkConsumerContractError = (consumerName: string): Error => {
|
|
2
|
+
return new Error(
|
|
3
|
+
`${consumerName} is a render-coupled consumer helper and has no shared runtime implementation. ` +
|
|
4
|
+
`Inject the framework-specific ${consumerName} implementation instead of calling the shared fallback export.`
|
|
5
|
+
);
|
|
6
|
+
};
|