Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
fix: make mock muxer use abstract stream class
Browse files Browse the repository at this point in the history
Draft for now as the behaviour is slightly different
  • Loading branch information
achingbrain committed Jun 14, 2023
1 parent 9e86d57 commit 6fe01a4
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 243 deletions.
20 changes: 8 additions & 12 deletions packages/interface-mocks/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,13 @@ class MockConnection implements Connection {
const stream = await this.muxer.newStream(id)
const result = await mss.select(stream, protocols, options)

const streamWithProtocol: Stream = {
...stream,
...result.stream,
stat: {
...stream.stat,
direction: 'outbound',
protocol: result.protocol
}
}
stream.sink = result.stream.sink
stream.source = result.stream.source
stream.stat.protocol = result.protocol

this.streams.push(streamWithProtocol)
this.streams.push(stream)

return streamWithProtocol
return stream
}

addStream (stream: Stream): void {
Expand Down Expand Up @@ -136,7 +130,9 @@ export function mockConnection (maConn: MultiaddrConnection, opts: MockConnectio
mss.handle(muxedStream, registrar.getProtocols())
.then(({ stream, protocol }) => {
log('%s: incoming stream opened on %s', direction, protocol)
muxedStream = { ...muxedStream, ...stream }

muxedStream.sink = stream.sink
muxedStream.source = stream.source
muxedStream.stat.protocol = protocol

connection.addStream(muxedStream)
Expand Down
Loading

0 comments on commit 6fe01a4

Please sign in to comment.