From 349535b5ceb3c8d070601189c08925a03447ba6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor?= Date: Fri, 26 Jan 2024 10:29:52 -0300 Subject: [PATCH] migrate userShareWebcam --- .../api/video-streams/server/methods.js | 2 -- .../server/methods/userShareWebcam.js | 34 ------------------- .../components/video-provider/component.jsx | 4 ++- .../components/video-provider/container.jsx | 17 +++++++++- .../ui/components/video-provider/mutations.ts | 13 +++++++ .../ui/components/video-provider/service.js | 1 + 6 files changed, 33 insertions(+), 38 deletions(-) delete mode 100644 bigbluebutton-html5/imports/api/video-streams/server/methods/userShareWebcam.js create mode 100644 bigbluebutton-html5/imports/ui/components/video-provider/mutations.ts diff --git a/bigbluebutton-html5/imports/api/video-streams/server/methods.js b/bigbluebutton-html5/imports/api/video-streams/server/methods.js index f0cc07f13b..7a33758c50 100644 --- a/bigbluebutton-html5/imports/api/video-streams/server/methods.js +++ b/bigbluebutton-html5/imports/api/video-streams/server/methods.js @@ -1,8 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import userShareWebcam from './methods/userShareWebcam'; import userUnshareWebcam from './methods/userUnshareWebcam'; Meteor.methods({ - userShareWebcam, userUnshareWebcam, }); diff --git a/bigbluebutton-html5/imports/api/video-streams/server/methods/userShareWebcam.js b/bigbluebutton-html5/imports/api/video-streams/server/methods/userShareWebcam.js deleted file mode 100644 index 82098a5ea7..0000000000 --- a/bigbluebutton-html5/imports/api/video-streams/server/methods/userShareWebcam.js +++ /dev/null @@ -1,34 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { check } from 'meteor/check'; -import Logger from '/imports/startup/server/logger'; -import RedisPubSub from '/imports/startup/server/redis'; -import { extractCredentials } from '/imports/api/common/server/helpers'; - -export default function userShareWebcam(stream) { - try { - const REDIS_CONFIG = Meteor.settings.private.redis; - const CHANNEL = REDIS_CONFIG.channels.toAkkaApps; - const EVENT_NAME = 'UserBroadcastCamStartMsg'; - const { meetingId, requesterUserId } = extractCredentials(this.userId); - - check(meetingId, String); - check(requesterUserId, String); - check(stream, String); - - Logger.info(`user sharing webcam: ${meetingId} ${requesterUserId}`); - - // const actionName = 'joinVideo'; - /* TODO throw an error if user has no permission to share webcam - if (!isAllowedTo(actionName, credentials)) { - throw new Meteor.Error('not-allowed', `You are not allowed to share webcam`); - } */ - - const payload = { - stream, - }; - - RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload); - } catch (err) { - Logger.error(`Exception while invoking method userShareWebcam ${err.stack}`); - } -} diff --git a/bigbluebutton-html5/imports/ui/components/video-provider/component.jsx b/bigbluebutton-html5/imports/ui/components/video-provider/component.jsx index cf507eabe0..1b33880864 100755 --- a/bigbluebutton-html5/imports/ui/components/video-provider/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/video-provider/component.jsx @@ -123,6 +123,7 @@ const propTypes = { currentVideoPageIndex: PropTypes.number.isRequired, totalNumberOfStreams: PropTypes.number.isRequired, isMeteorConnected: PropTypes.bool.isRequired, + playStart: PropTypes.func.isRequired, }; class VideoProvider extends Component { @@ -1153,6 +1154,7 @@ class VideoProvider extends Component { handlePlayStart(message) { const { cameraId: stream, role } = message; const peer = this.webRtcPeers[stream]; + const { playStart } = this.props; if (peer) { logger.info({ @@ -1169,7 +1171,7 @@ class VideoProvider extends Component { this.clearRestartTimers(stream); this.attachVideoStream(stream); - VideoService.playStart(stream); + playStart(stream); } else { logger.warn({ logCode: 'video_provider_playstart_no_peer', diff --git a/bigbluebutton-html5/imports/ui/components/video-provider/container.jsx b/bigbluebutton-html5/imports/ui/components/video-provider/container.jsx index f5480a3846..379bc4edec 100755 --- a/bigbluebutton-html5/imports/ui/components/video-provider/container.jsx +++ b/bigbluebutton-html5/imports/ui/components/video-provider/container.jsx @@ -1,14 +1,29 @@ import React from 'react'; import { withTracker } from 'meteor/react-meteor-data'; +import { useMutation } from '@apollo/client'; import VideoProvider from './component'; import VideoService from './service'; import { sortVideoStreams } from '/imports/ui/components/video-provider/stream-sorting'; +import { CAMERA_BROADCAST_START } from './mutations'; const { defaultSorting: DEFAULT_SORTING } = Meteor.settings.public.kurento.cameraSortingModes; const VideoProviderContainer = ({ children, ...props }) => { const { streams, isGridEnabled } = props; - return (!streams.length && !isGridEnabled ? null : {children}); + const [cameraBroadcastStart] = useMutation(CAMERA_BROADCAST_START); + + const sendUserShareWebcam = (cameraId) => { + cameraBroadcastStart({ variables: { cameraId } }); + }; + + const playStart = (cameraId) => { + if (VideoService.isLocalStream(cameraId)) { + sendUserShareWebcam(cameraId); + VideoService.joinedVideo(); + } + }; + + return (!streams.length && !isGridEnabled ? null : {children}); }; export default withTracker(({ swapLayout, ...rest }) => { diff --git a/bigbluebutton-html5/imports/ui/components/video-provider/mutations.ts b/bigbluebutton-html5/imports/ui/components/video-provider/mutations.ts new file mode 100644 index 0000000000..f5d6d7ebea --- /dev/null +++ b/bigbluebutton-html5/imports/ui/components/video-provider/mutations.ts @@ -0,0 +1,13 @@ +import { gql } from '@apollo/client'; + +export const CAMERA_BROADCAST_START = gql` + mutation CameraBroadcastStart($cameraId: String!) { + cameraBroadcastStart( + stream: $cameraId + ) + } +`; + +export default { + CAMERA_BROADCAST_START, +}; diff --git a/bigbluebutton-html5/imports/ui/components/video-provider/service.js b/bigbluebutton-html5/imports/ui/components/video-provider/service.js index 956b493022..5a1b108a28 100755 --- a/bigbluebutton-html5/imports/ui/components/video-provider/service.js +++ b/bigbluebutton-html5/imports/ui/components/video-provider/service.js @@ -1073,4 +1073,5 @@ export default { getPreloadedStream: () => videoService.getPreloadedStream(), getStats: () => videoService.getStats(), updatePeerDictionaryReference: (newRef) => videoService.updatePeerDictionaryReference(newRef), + joinedVideo: () => videoService.joinedVideo(), };