Streaming: parse stream channel param

This commit is contained in:
Alex Gleason
2023-05-20 23:47:31 -05:00
parent da6e31c647
commit 161c77b85d
3 changed files with 42 additions and 25 deletions

View File

@@ -1,12 +1,12 @@
import { AppController } from '@/app.ts';
import { TOKEN_REGEX } from '@/middleware/auth.ts';
import ws from '@/stream.ts';
import { streamSchema, ws } from '@/stream.ts';
import { bech32ToPubkey } from '@/utils.ts';
const streamingController: AppController = (c) => {
const upgrade = c.req.headers.get('upgrade');
const token = c.req.headers.get('sec-websocket-protocol');
const stream = c.req.query('stream');
const stream = streamSchema.optional().catch(undefined).parse(c.req.query('stream'));
if (upgrade?.toLowerCase() !== 'websocket') {
return c.text('Please use websocket protocol', 400);
@@ -32,7 +32,7 @@ const streamingController: AppController = (c) => {
socket.addEventListener('open', () => {
console.log('websocket: connection opened');
if (stream) {
ws.subscribe(conn, { name: stream });
ws.subscribe(conn, { stream });
}
});