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
|
// Load extra routes
|
||||||
devtoken.routes( app, foss );
|
devtoken.routes( app, foss );
|
||||||
room.routes( app, foss );
|
room.routes( app, foss, config );
|
||||||
user.routes( app, foss );
|
user.routes( app, foss );
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
|
import {
|
||||||
|
Config
|
||||||
|
} from '../../dtype/config';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import {
|
import {
|
||||||
generateToken
|
generateToken
|
||||||
} from '../../token';
|
} from '../../token';
|
||||||
import rooms from '.';
|
import rooms from '.';
|
||||||
|
|
||||||
export const sseMiddleware = ( kind: 'client' | 'trackingClient' ) => {
|
export const sseMiddleware = ( kind: 'client' | 'trackingClient', config?: Config ) => {
|
||||||
return ( request: express.Request, response: express.Response ) => {
|
return ( request: express.Request, response: express.Response ) => {
|
||||||
if ( typeof request.params.id !== 'string' )
|
if ( typeof request.params.id !== 'string' )
|
||||||
return response.sendStatus( 400 );
|
return response.sendStatus( 400 );
|
||||||
@@ -20,7 +23,11 @@ export const sseMiddleware = ( kind: 'client' | 'trackingClient' ) => {
|
|||||||
} );
|
} );
|
||||||
response.status( 200 );
|
response.status( 200 );
|
||||||
response.flushHeaders();
|
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 );
|
const token = generateToken( 20 );
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import {
|
|||||||
} from '../../sdk';
|
} from '../../sdk';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
|
|
||||||
const cache = {};
|
const cache: {
|
||||||
|
[key: string]: boolean
|
||||||
|
} = {};
|
||||||
|
|
||||||
export const getOwnershipManager = ( foss: boolean ) => {
|
export const getOwnershipManager = ( foss: boolean ) => {
|
||||||
const storeSdk = getStoreSdk( foss );
|
const storeSdk = getStoreSdk( foss );
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import {
|
||||||
|
Config
|
||||||
|
} from '../../dtype/config';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import {
|
import {
|
||||||
getLoginSdk
|
getLoginSdk
|
||||||
@@ -9,12 +12,12 @@ import rooms from '../../manager/rooms';
|
|||||||
import tracking from './tracking';
|
import tracking from './tracking';
|
||||||
import update from './update';
|
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 sdk = getLoginSdk( foss );
|
||||||
const ownership = getOwnershipManager( foss );
|
const ownership = getOwnershipManager( foss );
|
||||||
|
|
||||||
tracking.routes( app, foss );
|
tracking.routes( app, foss );
|
||||||
update.routes( app, foss );
|
update.routes( app, foss, config );
|
||||||
|
|
||||||
app.get(
|
app.get(
|
||||||
'/room/create',
|
'/room/create',
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import {
|
||||||
|
Config
|
||||||
|
} from '../../dtype/config';
|
||||||
import bodyParser from 'body-parser';
|
import bodyParser from 'body-parser';
|
||||||
import corsManager from '../../corsManager';
|
import corsManager from '../../corsManager';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
@@ -10,11 +13,11 @@ import {
|
|||||||
sseMiddleware
|
sseMiddleware
|
||||||
} from '../../manager/rooms/sse';
|
} from '../../manager/rooms/sse';
|
||||||
|
|
||||||
const routes = ( app: express.Application, foss: boolean ) => {
|
const routes = ( app: express.Application, foss: boolean, config: Config ) => {
|
||||||
const sdk = getLoginSdk( foss );
|
const sdk = getLoginSdk( foss );
|
||||||
|
|
||||||
// FIXME: Here, if not in sse mode, simply close the connection after sending 'poll'
|
// 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 ) => {
|
app.get( '/room/:id/poll', corsManager.middleware( false ), ( request: express.Request, response: express.Response ) => {
|
||||||
if ( typeof request.params.id !== 'string' )
|
if ( typeof request.params.id !== 'string' )
|
||||||
|
|||||||
Reference in New Issue
Block a user