Skip to content

Commit 42126d2

Browse files
committed
add mountWithLayoutServer client func
1 parent 7778b3d commit 42126d2

File tree

5 files changed

+119
-81
lines changed

5 files changed

+119
-81
lines changed

docs/source/_custom_js/package-lock.json

Lines changed: 51 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/_custom_js/src/index.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
import { mountLayoutWithWebSocket } from "idom-client-react";
1+
import { mountWithLayoutServer, LayoutServerInfo } from "idom-client-react";
22

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;
74

85
export function mountWidgetExample(
96
mountID,
107
viewID,
118
idomServerHost,
129
useActivateButton
1310
) {
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+
});
1726

1827
const mountEl = document.getElementById(mountID);
1928

2029
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);
2731
return;
2832
}
2933

@@ -36,12 +40,7 @@ export function mountWidgetExample(
3640
{
3741
mountEl.removeChild(enableWidgetButton);
3842
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);
4544
}
4645
})
4746
);
@@ -68,11 +67,3 @@ export function mountWidgetExample(
6867

6968
mountEl.appendChild(enableWidgetButton);
7069
}
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

Comments
 (0)