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