UNPKG

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