1- // Copyright 2020-2022 The MathWorks, Inc.
1+ // Copyright 2020-2023 The MathWorks, Inc.
22
33import React , { useState , useCallback , useEffect , useMemo } from 'react' ;
44import { useSelector , useDispatch } from 'react-redux' ;
@@ -14,20 +14,22 @@ import Information from '../Information';
1414import Help from '../Help' ;
1515import Error from '../Error' ;
1616import {
17- selectOverlayVisible ,
18- selectFetchStatusPeriod ,
19- selectHasFetchedServerStatus ,
20- selectLicensingProvided ,
21- selectMatlabUp ,
22- selectError ,
23- selectLoadUrl ,
24- selectIsConnectionError ,
25- selectHasFetchedEnvConfig ,
26- selectAuthEnabled ,
27- selectIsAuthenticated ,
28- selectLicensingMhlmHasEntitlements ,
29- selectIsEntitled ,
30- selectLicensingInfo ,
17+ selectOverlayVisible ,
18+ selectFetchStatusPeriod ,
19+ selectHasFetchedServerStatus ,
20+ selectLicensingProvided ,
21+ selectMatlabUp ,
22+ selectError ,
23+ selectLoadUrl ,
24+ selectIsConnectionError ,
25+ selectHasFetchedEnvConfig ,
26+ selectAuthEnabled ,
27+ selectIsAuthenticated ,
28+ selectLicensingMhlmHasEntitlements ,
29+ selectIsEntitled ,
30+ selectLicensingInfo ,
31+ selectUseMOS ,
32+ selectUseMRE ,
3133} from "../../selectors" ;
3234
3335import {
@@ -56,17 +58,34 @@ function App() {
5658 const isAuthenticated = useSelector ( selectIsAuthenticated )
5759 const authEnabled = useSelector ( selectAuthEnabled ) ;
5860 const licensingInfo = useSelector ( selectLicensingInfo ) ;
61+ const useMOS = useSelector ( selectUseMOS ) ;
62+ const useMRE = useSelector ( selectUseMRE ) ;
5963
6064 const baseUrl = useMemo ( ( ) => {
61- const url = document . URL
65+ const url = document . URL
6266 return url . split ( window . location . origin ) [ 1 ] . split ( 'index.html' ) [ 0 ]
6367 } , [ ] )
64-
65- const parseQueryParams = ( url ) => {
68+
69+ const parseQueryParams = ( url ) => {
6670 const queryParams = new URLSearchParams ( url . search ) ;
6771 return queryParams ;
6872 }
6973
74+ const fullyQualifiedUrl = useMemo ( ( ) => {
75+ // Returns the Fully Qualified URL used to load the page.
76+ const url = document . URL
77+ let baseUrlStr = url . split ( '/index.html' ) [ 0 ]
78+ return baseUrlStr ;
79+ } , [ ] )
80+
81+ const htmlToRenderMATLAB = ( ) => {
82+ let theHtmlToRenderMATLAB = useMOS ? "index-matlabonlineserver.html" : 'index-jsd-cr.html'
83+ if ( useMRE ) {
84+ theHtmlToRenderMATLAB += `?mre=${ fullyQualifiedUrl } `
85+ }
86+ return theHtmlToRenderMATLAB
87+ }
88+
7089 const toggleOverlayVisible = useCallback (
7190 ( ) => dispatch ( setOverlayVisibility ( ! overlayVisible ) ) ,
7291 [ overlayVisible , dispatch ]
@@ -137,42 +156,42 @@ function App() {
137156 // Periodic fetch server status
138157 useInterval ( ( ) => {
139158 dispatch ( fetchServerStatus ( ) ) ;
140- } , fetchStatusPeriod ) ;
159+ } , fetchStatusPeriod ) ;
141160
142161 // Load URL
143- useEffect ( ( ) => {
162+ useEffect ( ( ) => {
144163 if ( loadUrl !== null ) {
145164 window . location . href = loadUrl ;
146165 }
147166 } , [ loadUrl ] ) ;
148167
149168 useEffect ( ( ) => {
150169 const queryParams = parseQueryParams ( window . location ) ;
151- const token = queryParams . get ( "mwi_auth_token" ) ;
170+ const token = queryParams . get ( "mwi_auth_token" ) ;
152171
153- if ( token ) {
154- dispatch ( updateAuthStatus ( token ) ) ;
172+ if ( token ) {
173+ dispatch ( updateAuthStatus ( token ) ) ;
155174 }
156- window . history . replaceState ( null , '' , `${ baseUrl } index.html` ) ;
175+ window . history . replaceState ( null , '' , `${ baseUrl } index.html` ) ;
157176 } , [ dispatch , baseUrl ] ) ;
158-
177+
159178 // Display one of:
160179 // * Confirmation
161180 // * Help
162181 // * Error
163182 // * License gatherer
164183 // * License selector
165184 // * Status Information
166- let overlayContent ;
185+ let overlayContent ;
167186
168187 if ( dialog ) {
169188 // TODO Inline confirmation component build
170189 overlayContent = dialog ;
171- }
190+ }
172191 // Give precedence to token auth over licensing info ie. once after token auth is done, show licensing if not provided.
173- else if ( ( ! licensingProvided ) && hasFetchedServerStatus && ( ! authEnabled || isAuthenticated ) ) {
192+ else if ( ( ! licensingProvided ) && hasFetchedServerStatus && ( ! authEnabled || isAuthenticated ) ) {
174193 overlayContent = < LicensingGatherer role = "licensing" aria-describedby = "license-window" /> ;
175- }
194+ }
176195 // Show license selector if the user has entitlements and is not currently entitled
177196 else if ( hasEntitlements && ! isEntitled ) {
178197 overlayContent = < EntitlementSelector options = { licensingInfo . entitlements } /> ;
@@ -192,19 +211,23 @@ function App() {
192211 </ Overlay >
193212 ) : null ;
194213
214+
195215 // FIXME Until https://github.com/http-party/node-http-proxy/issues/1342
196216 // is addressed, use a direct URL in development mode. Once that is
197217 // fixed, the request will be served by the fake MATLAB Embedded Connector
198218 // process in development mode
219+
220+ // MW Internal Comment: See g2992889 for a discussion on why a FQDN is required in the MRE parameter.
221+ // MW Internal Comment: Using websocket on breaks some UI components : `./index-matlabonlineserver.html?websocket=on&mre=${fullyQualifiedUrl}`;
199222 const matlabUrl = process . env . NODE_ENV === 'development'
200223 ? 'http://localhost:31515/index-jsd-cr.html'
201- : './index-jsd-cr.html' ;
224+ : `./ ${ htmlToRenderMATLAB ( ) } ` ;
202225
203226 let matlabJsd = null ;
204- if ( matlabUp ) {
205- matlabJsd = ( ! authEnabled || isAuthenticated )
206- ? ( < MatlabJsd url = { matlabUrl } /> )
207- : < img style = { { objectFit : 'fill' } } src = { blurredBackground } alt = 'Blurred MATLAB environment' />
227+ if ( matlabUp ) {
228+ matlabJsd = ( ! authEnabled || isAuthenticated )
229+ ? ( < MatlabJsd url = { matlabUrl } /> )
230+ : < img style = { { objectFit : 'fill' } } src = { blurredBackground } alt = 'Blurred MATLAB environment' />
208231 }
209232
210233 const overlayTrigger = overlayVisible ? null : < OverlayTrigger /> ;
0 commit comments