mirror of
https://github.com/janishutz/MusicPlayer.git
synced 2026-09-10 14:25:24 +02:00
fix(backend): send use poll on attempted sse connection establishing
This commit is contained in:
+1
-1
@@ -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 );
|
||||
|
||||
|
||||
|
||||
@@ -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,6 +23,10 @@ export const sseMiddleware = ( kind: 'client' | 'trackingClient' ) => {
|
||||
} );
|
||||
response.status( 200 );
|
||||
response.flushHeaders();
|
||||
|
||||
if ( kind === 'trackingClient' || config?.clientMode === 'poll' )
|
||||
response.write( 'data: use-poll\n\n' );
|
||||
else
|
||||
response.write( 'data: connected\n\n' );
|
||||
|
||||
const token = generateToken( 20 );
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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' )
|
||||
|
||||
Reference in New Issue
Block a user