11import * as React from 'react' ;
22import * as ReactDOM from 'react-dom/client' ;
33import { ActionButtonDropdownOption , BbbPluginSdk , FloatingWindow } from 'bigbluebutton-html-plugin-sdk' ;
4+ import { defineMessages } from 'react-intl' ;
5+ import { useI18n } from '../common/hooks' ;
46import Pip from '../plugin-pip/component' ;
57import { useVideoStreams } from '../plugin-pip/components/cameras/hooks' ;
68import { useScreenshare } from '../plugin-pip/components/screenshare/hooks' ;
@@ -10,13 +12,25 @@ import styles from './stylesheet';
1012
1113const isPipSupported = 'documentPictureInPicture' in window ;
1214
15+ const intlMessages = defineMessages ( {
16+ activate : {
17+ id : 'plugin.pip.activate' ,
18+ defaultMessage : 'Activate PiP Window' ,
19+ } ,
20+ deactivate : {
21+ id : 'plugin.pip.deactivate' ,
22+ defaultMessage : 'Deactivate PiP Window' ,
23+ } ,
24+ } ) ;
25+
1326interface MainComponentProps {
1427 pluginUuid : string ;
1528}
1629
1730function MainComponent ( { pluginUuid } : MainComponentProps ) : React . ReactNode {
1831 BbbPluginSdk . initialize ( pluginUuid ) ;
1932 const pluginApi = BbbPluginSdk . getPluginApi ( pluginUuid ) ;
33+ const { intl } = useI18n ( pluginApi ) ;
2034 const pipActiveRef = React . useRef ( JSON . parse ( localStorage . getItem ( 'pip-plugin-active' ) ) ) ;
2135 const pipWindowRef = React . useRef < Window | null > ( null ) ;
2236 const hasMediaRef = React . useRef ( false ) ;
@@ -33,17 +47,19 @@ function MainComponent({ pluginUuid }: MainComponentProps): React.ReactNode {
3347 const amISharingWebcam = Boolean ( currentUser ?. cameras ?. length ) ;
3448
3549 if ( isPipSupported ) {
50+ const activateLabel = intl ?. formatMessage ( intlMessages . activate ) || 'Activate PiP Window' ;
51+ const deactivateLabel = intl ?. formatMessage ( intlMessages . deactivate ) || 'Deactivate PiP Window' ;
3652 pluginApi . setActionButtonDropdownItems ( [
3753 new ActionButtonDropdownOption ( {
3854 allowed : true ,
3955 icon : pipActive ? 'desktop_off' : 'desktop' ,
40- label : pipActive ? 'Deactivate PiP Window' : 'Activate PiP Window' ,
56+ label : pipActive ? deactivateLabel : activateLabel ,
4157 onClick : ( ) => {
4258 pipActiveRef . current = ! pipActiveRef . current ;
4359 localStorage . setItem ( 'pip-plugin-active' , JSON . stringify ( pipActiveRef . current ) ) ;
4460 setPipActive ( pipActiveRef . current ) ;
4561 } ,
46- tooltip : pipActive ? 'Deactivate PiP Window' : 'Activate PiP Window' ,
62+ tooltip : pipActive ? deactivateLabel : activateLabel ,
4763 } ) ,
4864 ] ) ;
4965 }
@@ -101,6 +117,7 @@ function MainComponent({ pluginUuid }: MainComponentProps): React.ReactNode {
101117 < Pip
102118 pluginApi = { pluginApi }
103119 pipWindow = { pipWindow }
120+ intl = { intl }
104121 /> ,
105122 ) ;
106123
@@ -135,7 +152,7 @@ function MainComponent({ pluginUuid }: MainComponentProps): React.ReactNode {
135152 // @ts -expect-error This media action may not be supported by all major browsers.
136153 navigator . mediaSession . setActionHandler ( 'enterpictureinpicture' , null ) ;
137154 } ;
138- } , [ ] ) ;
155+ } , [ intl , pluginApi ] ) ;
139156
140157 React . useEffect ( ( ) => {
141158 if ( ! isPipSupported || ! pipActive ) return undefined ;
@@ -165,15 +182,15 @@ function MainComponent({ pluginUuid }: MainComponentProps): React.ReactNode {
165182 const rect = actionsButton . getBoundingClientRect ( ) ;
166183 pluginApi . setFloatingWindows ( [
167184 new FloatingWindow ( {
168- id : 'focus-warning' ,
185+ id : 'plugin-pip- focus-warning' ,
169186 top : rect . top - 90 ,
170187 left : rect . left + ( rect . width / 2 ) - 181 ,
171188 movable : true ,
172189 backgroundColor : 'transparent' ,
173190 boxShadow : 'none' ,
174191 contentFunction : ( element : HTMLElement ) => {
175192 const root = ReactDOM . createRoot ( element ) ;
176- root . render ( < FocusWarning /> ) ;
193+ root . render ( < FocusWarning intl = { intl } /> ) ;
177194 return root ;
178195 } ,
179196 } ) ,
0 commit comments