var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
const Router = require('koa-router');
const mlink = require('../../link');
const WebsocketTerminal = mlink.Terminal.WebsocketTerminal;
const inspectorHub = mlink.Hub.get('proxy.inspector');
const proxyNativeHub = mlink.Hub.get('proxy.native');
const proxyDebuggerHub = mlink.Hub.get('page.debugger');
const runtimeWorkerHub = mlink.Hub.get('runtime.worker');
const entryHub = mlink.Hub.get('page.entry');
const wsRouter = Router();
wsRouter.all('/page/entry', (ctx, next) => __awaiter(this, void 0, void 0, function* () {
    const terminal = new WebsocketTerminal(ctx.websocket);
    entryHub.join(terminal, false);
    yield next();
}));
wsRouter.all('/debugProxy/inspector/:channelId', (ctx, next) => __awaiter(this, void 0, void 0, function* () {
    const terminal = new WebsocketTerminal(ctx.websocket);
    terminal.channelId = ctx.params.channelId;
    inspectorHub.join(terminal, false);
    yield next();
}));
wsRouter.all('/debugProxy/debugger/:channelId', (ctx, next) => __awaiter(this, void 0, void 0, function* () {
    const terminal = new WebsocketTerminal(ctx.websocket);
    terminal.channelId = ctx.params.channelId;
    proxyDebuggerHub.join(terminal, true);
    yield next();
}));
wsRouter.all('/debugProxy/runtime/:channelId', (ctx, next) => __awaiter(this, void 0, void 0, function* () {
    const terminal = new WebsocketTerminal(ctx.websocket);
    terminal.channelId = ctx.params.channelId;
    runtimeWorkerHub.join(terminal, true);
    yield next();
}));
wsRouter.all('/debugProxy/native/:channelId', (ctx, next) => __awaiter(this, void 0, void 0, function* () {
    const terminal = new WebsocketTerminal(ctx.websocket);
    terminal.channelId = ctx.params.channelId;
    proxyNativeHub.join(terminal, true);
    yield next();
}));
module.exports = wsRouter;
