fix(backend): send use poll on attempted sse connection establishing

This commit is contained in:
2026-09-07 14:13:37 +02:00
parent 68bbfa7896
commit 18bdf82bcf
5 changed files with 23 additions and 8 deletions
+1 -1
View File
@@ -76,7 +76,7 @@ const run = () => {
// Load extra routes
devtoken.routes( app, foss );
room.routes( app, foss );
room.routes( app, foss, config );
user.routes( app, foss );
+9 -2
View File
@@ -1,10 +1,13 @@
import {
Config
} from '../../dtype/config';
import express from 'express';
import {
generateToken
} from '../../token';
import rooms from '.';
export const sseMiddleware = ( kind: 'client' | 'trackingClient' ) => {
export const sseMiddleware = ( kind: 'client' | 'trackingClient', config?: Config ) => {
return ( request: express.Request, response: express.Response ) => {
if ( typeof request.params.id !== 'string' )
return response.sendStatus( 400 );
@@ -20,7 +23,11 @@ export const sseMiddleware = ( kind: 'client' | 'trackingClient' ) => {
} );
response.status( 200 );
response.flushHeaders();
response.write( 'data: connected\n\n' );
if ( kind === 'trackingClient' || config?.clientMode === 'poll' )
response.write( 'data: use-poll\n\n' );
else
response.write( 'data: connected\n\n' );
const token = generateToken( 20 );
+3 -1
View File
@@ -4,7 +4,9 @@ import {
} from '../../sdk';
import express from 'express';
const cache = {};
const cache: {
[key: string]: boolean
} = {};
export const getOwnershipManager = ( foss: boolean ) => {
const storeSdk = getStoreSdk( foss );
+5 -2
View File
@@ -1,3 +1,6 @@
import {
Config
} from '../../dtype/config';
import express from 'express';
import {
getLoginSdk
@@ -9,12 +12,12 @@ import rooms from '../../manager/rooms';
import tracking from './tracking';
import update from './update';
const routes = ( app: express.Application, foss: boolean ) => {
const routes = ( app: express.Application, foss: boolean, config: Config ) => {
const sdk = getLoginSdk( foss );
const ownership = getOwnershipManager( foss );
tracking.routes( app, foss );
update.routes( app, foss );
update.routes( app, foss, config );
app.get(
'/room/create',
+5 -2
View File
@@ -1,3 +1,6 @@
import {
Config
} from '../../dtype/config';
import bodyParser from 'body-parser';
import corsManager from '../../corsManager';
import express from 'express';
@@ -10,11 +13,11 @@ import {
sseMiddleware
} from '../../manager/rooms/sse';
const routes = ( app: express.Application, foss: boolean ) => {
const routes = ( app: express.Application, foss: boolean, config: Config ) => {
const sdk = getLoginSdk( foss );
// FIXME: Here, if not in sse mode, simply close the connection after sending 'poll'
app.get( '/room/:id/connect', corsManager.middleware( false ), sseMiddleware( 'client' ) );
app.get( '/room/:id/connect', corsManager.middleware( false ), sseMiddleware( 'client', config ) );
app.get( '/room/:id/poll', corsManager.middleware( false ), ( request: express.Request, response: express.Response ) => {
if ( typeof request.params.id !== 'string' )