1 | import debug = require("debug");
|
2 | import { Application, ModulesManager, PageMetaManager, Seance } from "neweb-browser";
|
3 | import { ClientPageRenderer } from "neweb-components";
|
4 | import { INITIAL_VAR, ISeanceInitialInfo } from "neweb-core";
|
5 | import Neweb = require("./common");
|
6 | if (process.env.NODE_ENV === "development") {
|
7 | debug.enable("*,-socket.io:*,-engine:*,-socket.io-client:*,-engine.io-client:*,-socket.io-client,-socket.io-parser");
|
8 | }
|
9 | import SocketIOClient = require("socket.io-client");
|
10 |
|
11 | const initial: ISeanceInitialInfo = (window as any)[INITIAL_VAR];
|
12 | const socket = SocketIOClient(window.location.protocol + "//" + window.location.host);
|
13 | const modulesManager = new ModulesManager({
|
14 | address: window.location.protocol + "//" + window.location.host + "/modules",
|
15 | modules: [{
|
16 | name: "neweb",
|
17 | version: undefined,
|
18 | type: "npm",
|
19 | content: "",
|
20 | exports: Neweb,
|
21 | },
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | ],
|
36 | });
|
37 | const app = new Application({
|
38 | modulesManager,
|
39 | });
|
40 | const pageRenderer = new ClientPageRenderer({
|
41 | app,
|
42 | rootHtmlElement: document.getElementById("root") as HTMLElement,
|
43 | });
|
44 | const pageMetaManager = new PageMetaManager();
|
45 | const seance = new Seance({
|
46 | app,
|
47 | seanceId: initial.seanceId,
|
48 | socket,
|
49 | pageRenderer,
|
50 | pageMetaManager,
|
51 | });
|
52 | const realPushState = history.pushState.bind(history);
|
53 | history.pushState = (url: string) => {
|
54 | seance.navigate(url);
|
55 | realPushState(url, "", url);
|
56 | };
|
57 | const logger = console;
|
58 | seance.initialize(initial).then(() => {
|
59 | window.dispatchEvent(new Event("neweb-seans-initialized"));
|
60 | logger.log("Initialized");
|
61 | });
|
62 | (window as any).global = window;
|