Browse Source

feat(shared-video): Fixes showing thumb on the sharer side.

Fixes #15077.
factor2
damencho 9 months ago
parent
commit
6aa42f9850

+ 9
- 6
react/features/shared-video/actions.any.ts View File

@@ -11,7 +11,7 @@ import {
11 11
 } from './actionTypes';
12 12
 import { ShareVideoConfirmDialog, SharedVideoDialog } from './components';
13 13
 import { PLAYBACK_START, PLAYBACK_STATUSES } from './constants';
14
-import { isSharedVideoEnabled } from './functions';
14
+import { isSharedVideoEnabled, sendShareVideoCommand } from './functions';
15 15
 
16 16
 
17 17
 /**
@@ -120,12 +120,15 @@ export function playSharedVideo(videoUrl: string) {
120 120
         if (conference) {
121 121
             const localParticipant = getLocalParticipant(getState());
122 122
 
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,
125 129
                 status: PLAYBACK_START,
126
-                time: 0,
127
-                ownerId: localParticipant?.id
128
-            }));
130
+                time: 0
131
+            });
129 132
         }
130 133
     };
131 134
 }

+ 28
- 0
react/features/shared-video/functions.ts View File

@@ -1,4 +1,5 @@
1 1
 import { IStateful } from '../base/app/types';
2
+import { IJitsiConference } from '../base/conference/reducer';
2 3
 import { getFakeParticipants } from '../base/participants/functions';
3 4
 import { toState } from '../base/redux/functions';
4 5
 
@@ -6,6 +7,7 @@ import {
6 7
     ALLOW_ALL_URL_DOMAINS,
7 8
     PLAYBACK_START,
8 9
     PLAYBACK_STATUSES,
10
+    SHARED_VIDEO,
9 11
     VIDEO_PLAYER_PARTICIPANT_NAME,
10 12
     YOUTUBE_PLAYER_PARTICIPANT_NAME,
11 13
     YOUTUBE_URL_DOMAIN
@@ -146,3 +148,29 @@ export function isURLAllowedForSharedVideo(url: string,
146 148
 
147 149
     return false;
148 150
 }
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
+}

+ 23
- 31
react/features/shared-video/middleware.any.ts View File

@@ -30,7 +30,7 @@ import {
30 30
     SHARED_VIDEO,
31 31
     VIDEO_PLAYER_PARTICIPANT_NAME
32 32
 } from './constants';
33
-import { isSharedVideoEnabled, isSharingStatus, isURLAllowedForSharedVideo } from './functions';
33
+import { isSharedVideoEnabled, isSharingStatus, isURLAllowedForSharedVideo, sendShareVideoCommand } from './functions';
34 34
 import logger from './logger';
35 35
 
36 36
 
@@ -155,6 +155,14 @@ MiddlewareRegistry.register(store => next => action => {
155 155
             APP.API.notifyAudioOrVideoSharingToggled(MEDIA_TYPE.VIDEO, status, ownerId);
156 156
         }
157 157
 
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
+
158 166
         if (localParticipantId === ownerId) {
159 167
             sendShareVideoCommand({
160 168
                 conference,
@@ -224,12 +232,15 @@ function handleSharingVideoStatus(store: IStore, videoUrl: string,
224 232
 
225 233
     if (oldVideoUrl && oldVideoUrl !== videoUrl) {
226 234
         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}`);
228 236
 
229 237
         return;
230 238
     }
231 239
 
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)) {
233 244
         const youtubeId = videoUrl.match(/http/) ? false : videoUrl;
234 245
         const avatarURL = youtubeId ? `https://img.youtube.com/vi/${youtubeId}/0.jpg` : '';
235 246
 
@@ -242,6 +253,15 @@ function handleSharingVideoStatus(store: IStore, videoUrl: string,
242 253
         }));
243 254
 
244 255
         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
+        }
245 265
     }
246 266
 
247 267
     if (localParticipantId !== from) {
@@ -254,31 +274,3 @@ function handleSharingVideoStatus(store: IStore, videoUrl: string,
254 274
         }));
255 275
     }
256 276
 }
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
-}

Loading…
Cancel
Save