Skip to content

Commit 6aa42f9

Browse files
committed
feat(shared-video): Fixes showing thumb on the sharer side.
Fixes #15077.
1 parent d2ff136 commit 6aa42f9

File tree

3 files changed

+60
-37
lines changed

3 files changed

+60
-37
lines changed

react/features/shared-video/actions.any.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from './actionTypes';
1212
import { ShareVideoConfirmDialog, SharedVideoDialog } from './components';
1313
import { PLAYBACK_START, PLAYBACK_STATUSES } from './constants';
14-
import { isSharedVideoEnabled } from './functions';
14+
import { isSharedVideoEnabled, sendShareVideoCommand } from './functions';
1515

1616

1717
/**
@@ -120,12 +120,15 @@ export function playSharedVideo(videoUrl: string) {
120120
if (conference) {
121121
const localParticipant = getLocalParticipant(getState());
122122

123-
dispatch(setSharedVideoStatus({
124-
videoUrl,
123+
// we will send the command and will create local video fake participant
124+
// and start playing once we receive ourselves the command
125+
sendShareVideoCommand({
126+
conference,
127+
id: videoUrl,
128+
localParticipantId: localParticipant?.id,
125129
status: PLAYBACK_START,
126-
time: 0,
127-
ownerId: localParticipant?.id
128-
}));
130+
time: 0
131+
});
129132
}
130133
};
131134
}

react/features/shared-video/functions.ts

+28
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { IStateful } from '../base/app/types';
2+
import { IJitsiConference } from '../base/conference/reducer';
23
import { getFakeParticipants } from '../base/participants/functions';
34
import { toState } from '../base/redux/functions';
45

56
import {
67
ALLOW_ALL_URL_DOMAINS,
78
PLAYBACK_START,
89
PLAYBACK_STATUSES,
10+
SHARED_VIDEO,
911
VIDEO_PLAYER_PARTICIPANT_NAME,
1012
YOUTUBE_PLAYER_PARTICIPANT_NAME,
1113
YOUTUBE_URL_DOMAIN
@@ -146,3 +148,29 @@ export function isURLAllowedForSharedVideo(url: string,
146148

147149
return false;
148150
}
151+
152+
/**
153+
* Sends SHARED_VIDEO command.
154+
*
155+
* @param {string} id - The id of the video.
156+
* @param {string} status - The status of the shared video.
157+
* @param {JitsiConference} conference - The current conference.
158+
* @param {string} localParticipantId - The id of the local participant.
159+
* @param {string} time - The seek position of the video.
160+
* @returns {void}
161+
*/
162+
export function sendShareVideoCommand({ id, status, conference, localParticipantId = '', time, muted, volume }: {
163+
conference?: IJitsiConference; id: string; localParticipantId?: string; muted?: boolean;
164+
status: string; time: number; volume?: number;
165+
}) {
166+
conference?.sendCommandOnce(SHARED_VIDEO, {
167+
value: id,
168+
attributes: {
169+
from: localParticipantId,
170+
muted,
171+
state: status,
172+
time,
173+
volume
174+
}
175+
});
176+
}

react/features/shared-video/middleware.any.ts

+23-31
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
SHARED_VIDEO,
3131
VIDEO_PLAYER_PARTICIPANT_NAME
3232
} from './constants';
33-
import { isSharedVideoEnabled, isSharingStatus, isURLAllowedForSharedVideo } from './functions';
33+
import { isSharedVideoEnabled, isSharingStatus, isURLAllowedForSharedVideo, sendShareVideoCommand } from './functions';
3434
import logger from './logger';
3535

3636

@@ -155,6 +155,14 @@ MiddlewareRegistry.register(store => next => action => {
155155
APP.API.notifyAudioOrVideoSharingToggled(MEDIA_TYPE.VIDEO, status, ownerId);
156156
}
157157

158+
// when setting status we need to send the command for that, but not do it for the start command
159+
// as we are sending the command in playSharedVideo and setting the start status once
160+
// we receive the response, this way we will start the video at the same time when remote participants
161+
// start it, on receiving the command
162+
if (status === 'start') {
163+
break;
164+
}
165+
158166
if (localParticipantId === ownerId) {
159167
sendShareVideoCommand({
160168
conference,
@@ -224,12 +232,15 @@ function handleSharingVideoStatus(store: IStore, videoUrl: string,
224232

225233
if (oldVideoUrl && oldVideoUrl !== videoUrl) {
226234
logger.warn(
227-
`User with id: ${localParticipantId} sent videoUrl: ${videoUrl} while we are playing: ${oldVideoUrl}`);
235+
`User with id: ${from} sent videoUrl: ${videoUrl} while we are playing: ${oldVideoUrl}`);
228236

229237
return;
230238
}
231239

232-
if (state === PLAYBACK_START && !isSharingStatus(oldStatus)) {
240+
// If the video was not started (no participant) we want to create the participant
241+
// this can be triggered by start, but also by paused or playing
242+
// commands (joining late) and getting the current state
243+
if (state === PLAYBACK_START || !isSharingStatus(oldStatus)) {
233244
const youtubeId = videoUrl.match(/http/) ? false : videoUrl;
234245
const avatarURL = youtubeId ? `https://img.youtube.com/vi/${youtubeId}/0.jpg` : '';
235246

@@ -242,6 +253,15 @@ function handleSharingVideoStatus(store: IStore, videoUrl: string,
242253
}));
243254

244255
dispatch(pinParticipant(videoUrl));
256+
257+
if (localParticipantId === from) {
258+
dispatch(setSharedVideoStatus({
259+
videoUrl,
260+
status: state,
261+
time: Number(time),
262+
ownerId: localParticipantId
263+
}));
264+
}
245265
}
246266

247267
if (localParticipantId !== from) {
@@ -254,31 +274,3 @@ function handleSharingVideoStatus(store: IStore, videoUrl: string,
254274
}));
255275
}
256276
}
257-
258-
/* eslint-disable max-params */
259-
260-
/**
261-
* Sends SHARED_VIDEO command.
262-
*
263-
* @param {string} id - The id of the video.
264-
* @param {string} status - The status of the shared video.
265-
* @param {JitsiConference} conference - The current conference.
266-
* @param {string} localParticipantId - The id of the local participant.
267-
* @param {string} time - The seek position of the video.
268-
* @returns {void}
269-
*/
270-
function sendShareVideoCommand({ id, status, conference, localParticipantId = '', time, muted, volume }: {
271-
conference?: IJitsiConference; id: string; localParticipantId?: string; muted: boolean;
272-
status: string; time: number; volume: number;
273-
}) {
274-
conference?.sendCommandOnce(SHARED_VIDEO, {
275-
value: id,
276-
attributes: {
277-
from: localParticipantId,
278-
muted,
279-
state: status,
280-
time,
281-
volume
282-
}
283-
});
284-
}

0 commit comments

Comments
 (0)