@@ -37,8 +37,6 @@ export abstract class MultiplexingStream implements IDisposableObservable {
3737 /** The default window size used for new channels that do not specify a value for ChannelOptions.ChannelReceivingWindowSize. */
3838 readonly defaultChannelReceivingWindowSize : number
3939
40- protected readonly formatter : MultiplexingStreamFormatter
41-
4240 protected get disposalToken ( ) {
4341 return this . disposalTokenSource . token
4442 }
@@ -99,7 +97,7 @@ export abstract class MultiplexingStream implements IDisposableObservable {
9997 const handshakeResult = await formatter . readHandshakeAsync ( writeHandshakeData , cancellationToken )
10098 formatter . isOdd = handshakeResult . isOdd
10199
102- return new MultiplexingStreamClass ( stream , handshakeResult . isOdd , options )
100+ return new MultiplexingStreamClass ( formatter , handshakeResult . isOdd , options )
103101 }
104102
105103 /**
@@ -120,7 +118,7 @@ export abstract class MultiplexingStream implements IDisposableObservable {
120118 throw new Error ( `Protocol major version ${ options . protocolMajorVersion } is not supported. Try CreateAsync instead.` )
121119 }
122120
123- return new MultiplexingStreamClass ( stream , undefined , options )
121+ return new MultiplexingStreamClass ( formatter , undefined , options )
124122 }
125123
126124 /**
@@ -176,22 +174,13 @@ export abstract class MultiplexingStream implements IDisposableObservable {
176174
177175 private disposalTokenSource = CancellationToken . create ( )
178176
179- protected constructor ( stream : NodeJS . ReadWriteStream , private readonly isOdd : boolean | undefined , options : MultiplexingStreamOptions ) {
177+ protected constructor (
178+ protected readonly formatter : MultiplexingStreamFormatter ,
179+ private readonly isOdd : boolean | undefined ,
180+ options : MultiplexingStreamOptions
181+ ) {
180182 this . defaultChannelReceivingWindowSize = options . defaultChannelReceivingWindowSize ?? MultiplexingStream . recommendedDefaultChannelReceivingWindowSize
181183 this . protocolMajorVersion = options . protocolMajorVersion ?? 1
182- const formatter : MultiplexingStreamFormatter | undefined =
183- options . protocolMajorVersion === 1
184- ? new MultiplexingStreamV1Formatter ( stream )
185- : options . protocolMajorVersion === 2
186- ? new MultiplexingStreamV2Formatter ( stream )
187- : options . protocolMajorVersion === 3
188- ? new MultiplexingStreamV3Formatter ( stream )
189- : undefined
190- if ( formatter === undefined ) {
191- throw new Error ( `Unsupported major protocol version: ${ options . protocolMajorVersion } ` )
192- }
193- formatter . isOdd = isOdd
194- this . formatter = formatter
195184
196185 if ( options . seededChannels ) {
197186 for ( let i = 0 ; i < options . seededChannels . length ; i ++ ) {
@@ -534,8 +523,8 @@ export class MultiplexingStreamClass extends MultiplexingStream {
534523 protected lastOfferedChannelId : number
535524 private readonly sendingSemaphore = new Semaphore ( 1 )
536525
537- constructor ( stream : NodeJS . ReadWriteStream , isOdd : boolean | undefined , options : MultiplexingStreamOptions ) {
538- super ( stream , isOdd , options )
526+ constructor ( formatter : MultiplexingStreamFormatter , isOdd : boolean | undefined , options : MultiplexingStreamOptions ) {
527+ super ( formatter , isOdd , options )
539528
540529 this . lastOfferedChannelId = isOdd ? - 1 : 0 // the first channel created should be 1 or 2
541530 this . lastOfferedChannelId += options . seededChannels ?. length ?? 0
0 commit comments