UNPKG

code-workshop-kit

Version:
41 lines 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.changeParticipantUrlMiddleware = void 0; const CwkStateSingleton_1 = require("../utils/CwkStateSingleton"); const verifyJWT_1 = require("../utils/verifyJWT"); const changeParticipantUrlMiddleware = (dir) => async (ctx, next) => { const fromIFrame = ctx.header['sec-fetch-dest'] === 'iframe'; await next(); if (ctx.status === 200 && ctx.response.is('html') && !fromIFrame) { const { state } = CwkStateSingleton_1.cwkState; const authToken = ctx.cookies.get('cwk_auth_token'); if (authToken) { const authed = verifyJWT_1.verifyJWT(dir, authToken, ctx); const followModeConnections = state.wsConnections && state.wsConnections['follow-mode']; if (authed && typeof authed !== 'string' && authed.username === CwkStateSingleton_1.cwkState.state.followModeInitiatedBy) { if (state.adminConfig && state.adminConfig.followMode && state.wss && state.wsConnections && followModeConnections) { // Send URL update message to all connections, which excludes follow mode initiator that changes the url // The websocket message is sent before the follow mode intiator has loaded the new page and established a new WS connection for (const entry of followModeConnections) { const [, connection] = entry; connection.send(JSON.stringify({ type: 'update-url', data: ctx.url, byAdmin: CwkStateSingleton_1.cwkState.state.followModeInitiatedBy, })); } } } } state.previousAdminUrl = ctx.url; CwkStateSingleton_1.cwkState.state = state; } }; exports.changeParticipantUrlMiddleware = changeParticipantUrlMiddleware; //# sourceMappingURL=change-participant-url-middleware.js.map