1
- import { mountLayoutWithWebSocket } from "idom-client-react" ;
1
+ import { mountWithLayoutServer , LayoutServerInfo } from "idom-client-react" ;
2
2
3
- const LOC = window . location ;
4
- const HTTP_PROTO = LOC . protocol ;
5
- const WS_PROTO = HTTP_PROTO === "https:" ? "wss:" : "ws:" ;
6
- const IDOM_MODULES_PATH = "/_modules" ;
3
+ let didMountDebug = false ;
7
4
8
5
export function mountWidgetExample (
9
6
mountID ,
10
7
viewID ,
11
8
idomServerHost ,
12
9
useActivateButton
13
10
) {
14
- const idomUrl = "//" + ( idomServerHost || LOC . host ) ;
15
- const httpIdomUrl = HTTP_PROTO + idomUrl ;
16
- const wsIdomUrl = WS_PROTO + idomUrl ;
11
+ let idomHost , idomPort ;
12
+ if ( idomServerHost ) {
13
+ [ idomHost , idomPort ] = idomServerHost . split ( ":" , 2 ) ;
14
+ } else {
15
+ idomHost = window . location . hostname ;
16
+ idomPort = window . location . port ;
17
+ }
18
+
19
+ const serverInfo = new LayoutServerInfo ( {
20
+ host : idomHost ,
21
+ port : idomPort ,
22
+ path : "/_idom/" ,
23
+ query : `view_id=${ viewID } ` ,
24
+ secure : window . location . protocol == "https" ,
25
+ } ) ;
17
26
18
27
const mountEl = document . getElementById ( mountID ) ;
19
28
20
29
if ( ! useActivateButton ) {
21
- mountLayoutWithWebSocket (
22
- mountEl ,
23
- wsIdomUrl + `/_idom/stream?view_id=${ viewID } ` ,
24
- ( source , sourceType ) =>
25
- loadImportSource ( httpIdomUrl , source , sourceType )
26
- ) ;
30
+ mountWithLayoutServer ( mountEl , serverInfo ) ;
27
31
return ;
28
32
}
29
33
@@ -36,12 +40,7 @@ export function mountWidgetExample(
36
40
{
37
41
mountEl . removeChild ( enableWidgetButton ) ;
38
42
mountEl . setAttribute ( "class" , "interactive widget-container" ) ;
39
- mountLayoutWithWebSocket (
40
- mountEl ,
41
- wsIdomUrl + `/_idom/stream?view_id=${ viewID } ` ,
42
- ( source , sourceType ) =>
43
- loadImportSource ( httpIdomUrl , source , sourceType )
44
- ) ;
43
+ mountWithLayoutServer ( mountEl , serverInfo ) ;
45
44
}
46
45
} )
47
46
) ;
@@ -68,11 +67,3 @@ export function mountWidgetExample(
68
67
69
68
mountEl . appendChild ( enableWidgetButton ) ;
70
69
}
71
-
72
- function loadImportSource ( baseUrl , source , sourceType ) {
73
- if ( sourceType == "NAME" ) {
74
- return import ( baseUrl + IDOM_MODULES_PATH + "/" + source ) ;
75
- } else {
76
- return import ( source ) ;
77
- }
78
- }
0 commit comments