MCPcopy
hub / github.com/socketio/socket.io / onWebTransportSession

Function onWebTransportSession

packages/engine.io/lib/server.ts:530–636  ·  view source on GitHub ↗
(session: any)

Source from the content-addressed store, hash-verified

528 }
529
530 public async onWebTransportSession(session: any) {
531 if (this.middlewares.length > 0) {
532 // middlewares expect an IncomingMessage argument, which cannot be created from the WebTransport session object
533 // see also: https://github.com/fails-components/webtransport/issues/448
534 debug(
535 "closing session since WebTransport is not compatible with middlewares",
536 );
537 return session.close();
538 }
539
540 const timeout = setTimeout(() => {
541 debug(
542 "the client failed to establish a bidirectional stream in the given period",
543 );
544 session.close();
545 }, this.opts.upgradeTimeout);
546
547 const streamReader = session.incomingBidirectionalStreams.getReader();
548 const result = await streamReader.read();
549
550 if (result.done) {
551 clearTimeout(timeout);
552 debug("session is closed");
553 return;
554 }
555
556 const stream = result.value;
557 const transformStream = createPacketDecoderStream(
558 this.opts.maxHttpBufferSize,
559 "nodebuffer",
560 );
561 const reader = stream.readable.pipeThrough(transformStream).getReader();
562
563 const closeSession = async () => {
564 try {
565 await reader.cancel();
566 } catch (e) {
567 debug(
568 "error while canceling WebTransport stream reader: %s",
569 e.message,
570 );
571 }
572 reader.releaseLock();
573 session.close();
574 };
575
576 // reading the first packet of the stream
577 const { value, done } = await reader.read();
578 clearTimeout(timeout);
579
580 if (done) {
581 debug("stream is closed");
582 reader.releaseLock();
583 return;
584 }
585
586 if (value.type !== "open") {
587 debug("invalid WebTransport handshake");

Callers

nothing calls this directly

Calls 9

debugFunction · 0.85
closeSessionFunction · 0.85
parseSessionIdFunction · 0.85
hasOwnFunction · 0.85
readMethod · 0.80
_maybeUpgradeMethod · 0.80
emitMethod · 0.65
closeMethod · 0.45

Tested by

no test coverage detected