@@ -5,9 +5,12 @@ import { Dropdown } from 'office-ui-fabric-react/lib/Dropdown';
55// CallCaption react function component
66const CallCaption = ( { call } ) => {
77 const [ captionsFeature , setCaptionsFeature ] = useState ( call . feature ( Features . Captions ) ) ;
8+ const [ capabilitiesFeature , setCapabilitiesFeature ] = useState ( call . feature ( Features . Capabilities ) ) ;
89 const [ captions , setCaptions ] = useState ( captionsFeature . captions ) ;
910 const [ currentSpokenLanguage , setCurrentSpokenLanguage ] = useState ( captions . activeSpokenLanguage ) ;
10- const [ currentCaptionLanguage , setCurrentCaptionLanguage ] = useState ( captions . activeCaptionLanguage ) ;
11+ const [ currentCaptionLanguage , setCurrentCaptionLanguage ] = useState ( null ) ;
12+ let captionLanguageCurrent = null ;
13+
1114
1215 useEffect ( ( ) => {
1316 try {
@@ -23,7 +26,7 @@ const CallCaption = ({ call }) => {
2326 captions . off ( 'CaptionsActiveChanged' , captionsActiveHandler ) ;
2427 captions . off ( 'CaptionsReceived' , captionsReceivedHandler ) ;
2528 captions . off ( 'SpokenLanguageChanged' , activeSpokenLanguageHandler ) ;
26- if ( captions . captionsType === 'TeamsCaptions' ) {
29+ if ( captions . kind === 'TeamsCaptions' && capabilitiesFeature . capabilities . setCaptionLanguage ?. isPresent ) {
2730 captions . off ( 'CaptionLanguageChanged' , activeCaptionLanguageHandler ) ;
2831 }
2932 } ;
@@ -37,7 +40,12 @@ const CallCaption = ({ call }) => {
3740 captions . on ( 'CaptionsActiveChanged' , captionsActiveHandler ) ;
3841 captions . on ( 'CaptionsReceived' , captionsReceivedHandler ) ;
3942 captions . on ( 'SpokenLanguageChanged' , activeSpokenLanguageHandler ) ;
40- if ( captions . captionsType === 'TeamsCaptions' ) {
43+ capabilitiesFeature . on ( 'CapabilitiesChanged' , ( value ) => {
44+ if ( value . newValue . setCaptionLanguage ) {
45+ setCapabilitiesFeature ( call . feature ( Features . Capabilities ) ) ;
46+ }
47+ } ) ;
48+ if ( captions . kind === 'TeamsCaptions' && capabilitiesFeature . capabilities . setCaptionLanguage ?. isPresent ) {
4149 captions . on ( 'CaptionLanguageChanged' , activeCaptionLanguageHandler ) ;
4250 }
4351 } catch ( e ) {
@@ -55,46 +63,49 @@ const CallCaption = ({ call }) => {
5563
5664 const captionsActiveHandler = ( ) => {
5765 console . log ( 'CaptionsActiveChanged: ' , captions . isCaptionsFeatureActive ) ;
66+ setCurrentSpokenLanguage ( captions . activeSpokenLanguage ) ;
67+ setCurrentCaptionLanguage ( captions . activeCaptionLanguage ) ;
5868 }
5969 const activeSpokenLanguageHandler = ( ) => {
6070 setCurrentSpokenLanguage ( captions . activeSpokenLanguage ) ;
6171 }
6272 const activeCaptionLanguageHandler = ( ) => {
6373 setCurrentCaptionLanguage ( captions . activeCaptionLanguage ) ;
74+ captionLanguageCurrent = captions . activeCaptionLanguage ;
6475 }
6576
6677 const captionsReceivedHandler = ( captionData ) => {
67- let mri = '' ;
68- if ( captionData . speaker . identifier . kind === 'communicationUser' ) {
69- mri = captionData . speaker . identifier . communicationUserId ;
70- } else if ( captionData . speaker . identifier . kind === 'microsoftTeamsUser' ) {
71- mri = captionData . speaker . identifier . microsoftTeamsUserId ;
72- } else if ( captionData . speaker . identifier . kind === ' phoneNumber' ) {
73- mri = captionData . speaker . identifier . phoneNumber ;
74- }
75-
76- let captionAreasContainer = document . getElementById ( 'captionsArea' ) ;
77- const newClassName = `prefix ${ mri . replace ( / : / g , '' ) . replace ( / - / g , '' ) . replace ( / \+ / g , '' ) } `;
78- const captionText = ` ${ captionData . timestamp . toUTCString ( ) }
79- ${ captionData . speaker . displayName } : ${ captionData . captionText ?? captionData . spokenText } ` ;
80-
81- let foundCaptionContainer = captionAreasContainer . querySelector ( `. ${ newClassName } [isNotFinal='true']` ) ;
82- if ( ! foundCaptionContainer ) {
83- let captionContainer = document . createElement ( 'div ') ;
84- captionContainer . setAttribute ( 'isNotFinal' , 'true' ) ;
85- captionContainer . style [ 'borderBottom ' ] = '1px solid ' ;
86- captionContainer . style [ 'whiteSpace' ] = 'pre-line' ;
87- captionContainer . textContent = captionText ;
88- captionContainer . classList . add ( newClassName ) ;
89- captionContainer . classList . add ( 'caption-item' )
90-
91- captionAreasContainer . appendChild ( captionContainer ) ;
92-
93- } else {
94- foundCaptionContainer . textContent = captionText ;
95-
96- if ( captionData . resultType === 'Final' ) {
97- foundCaptionContainer . setAttribute ( 'isNotFinal' , 'false' ) ;
78+ if ( ! captionLanguageCurrent || captionLanguageCurrent === captionData . captionLanguage ) {
79+ let mri = '' ;
80+ switch ( captionData . speaker . identifier . kind ) {
81+ case 'communicationUser' : { mri = captionData . speaker . identifier . communicationUserId ; break ; }
82+ case 'microsoftTeamsUser' : { mri = captionData . speaker . identifier . microsoftTeamsUserId ; break ; }
83+ case 'phoneNumber' : { mri = captionData . speaker . identifier . phoneNumber ; break ; }
84+ }
85+ let captionAreasContainer = document . getElementById ( 'captionsArea' ) ;
86+ const newClassName = `prefix ${ mri . replace ( / : / g , '' ) . replace ( / - / g , '' ) . replace ( / \+ / g , '' ) } ` ;
87+ const captionText = ` ${ captionData . timestamp . toUTCString ( ) }
88+ ${ captionData . speaker . displayName ?? mri } : ${ captionData . captionText ?? captionData . spokenText } ` ;
89+
90+ let foundCaptionContainer = captionAreasContainer . querySelector ( `. ${ newClassName } [isNotFinal='true']` ) ;
91+
92+ if ( ! foundCaptionContainer ) {
93+ let captionContainer = document . createElement ( 'div' ) ;
94+ captionContainer . setAttribute ( 'isNotFinal' , 'true ') ;
95+ captionContainer . style [ 'borderBottom' ] = '1px solid' ;
96+ captionContainer . style [ 'whiteSpace ' ] = 'pre-line ' ;
97+ captionContainer . textContent = captionText ;
98+ captionContainer . classList . add ( newClassName ) ;
99+ captionContainer . classList . add ( 'caption-item' )
100+
101+ captionAreasContainer . appendChild ( captionContainer ) ;
102+
103+ } else {
104+ foundCaptionContainer . textContent = captionText ;
105+
106+ if ( captionData . resultType === 'Final' ) {
107+ foundCaptionContainer . setAttribute ( 'isNotFinal' , 'false' ) ;
108+ }
98109 }
99110 }
100111 } ;
@@ -113,7 +124,7 @@ const CallCaption = ({ call }) => {
113124 onChange = { spokenLanguageSelectionChanged }
114125 label = { 'Spoken Language' }
115126 options = { keyedSupportedSpokenLanguages }
116- styles = { { label : { color : '#edebe9' } , dropdown : { width : 100 } } }
127+ styles = { { label : { color : '#edebe9' } , dropdown : { width : 100 } , root : { paddingBottom : '1rem' } } }
117128 />
118129 }
119130
@@ -131,14 +142,14 @@ const CallCaption = ({ call }) => {
131142 onChange = { captionLanguageSelectionChanged }
132143 label = { 'Caption Language' }
133144 options = { keyedSupportedCaptionLanguages }
134- styles = { { label : { color : '#edebe9' } , dropdown : { width : 100 , overflow : 'scroll' } } }
145+ styles = { { label : { color : '#edebe9' } , dropdown : { width : 100 , overflow : 'scroll' } , root : { paddingBottom : '1rem' } } }
135146 />
136147 }
137148
138149 return (
139150 < >
140151 { captions && < SpokenLanguageDropdown /> }
141- { captions && captions . captionsType === 'TeamsCaptions' && < CaptionLanguageDropdown /> }
152+ { captions && captions . kind === 'TeamsCaptions' && capabilitiesFeature . capabilities . setCaptionLanguage ?. isPresent && < CaptionLanguageDropdown /> }
142153 < div className = "scrollable-captions-container" >
143154 < div id = "captionsArea" className = "captions-area" >
144155 </ div >
0 commit comments