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

Commit

Permalink
fix: update interfaces (#160)
Browse files Browse the repository at this point in the history
Updates to the latest libp2p interfaces
  • Loading branch information
achingbrain authored Feb 21, 2022
1 parent 0137b94 commit 43db1cb
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import { createStream } from './stream.js'
import { toString as uint8ArrayToString } from 'uint8arrays'
import { trackedMap } from '@libp2p/tracked-map'
import { logger } from '@libp2p/logger'
import type { AbortOptions } from '@libp2p/interfaces'
import type { Sink } from 'it-stream-types'
import type { Muxer } from '@libp2p/interfaces/stream-muxer'
import type { Muxer, MuxerOptions } from '@libp2p/interfaces/stream-muxer'
import type { Stream } from '@libp2p/interfaces/connection'
import type { ComponentMetricsTracker } from '@libp2p/interfaces/metrics'
import each from 'it-foreach'
Expand Down Expand Up @@ -39,9 +38,7 @@ export interface MplexStream extends Stream {
source: Pushable<Uint8Array>
}

export interface MplexOptions extends AbortOptions {
onStream?: (...args: any[]) => void
onStreamEnd?: (...args: any[]) => void
export interface MplexOptions extends MuxerOptions {
maxMsgSize?: number
metrics?: ComponentMetricsTracker
}
Expand Down Expand Up @@ -207,28 +204,7 @@ export class Mplex implements Muxer {
}
}
const source = pushableV<Message>({ onEnd })
/*
const p = pipe(
source,
source => each(source, (msgs) => {
if (log.enabled) {
msgs.forEach(msg => {
log('outgoing message', printMessage(msg))
})
}
}),
source => encode(source),
source => each(source, (buf) => {
console.info('outgoing', uint8ArrayToString(buf, 'base64'))
})
)
return Object.assign(p, {
push: source.push,
end: source.end,
return: source.return
})
*/

return Object.assign(encode(source), {
push: source.push,
end: source.end,
Expand All @@ -247,8 +223,8 @@ export class Mplex implements Muxer {
if (message.type === MessageTypes.NEW_STREAM) {
const stream = this._newReceiverStream({ id, name: uint8ArrayToString(message.data instanceof Uint8Array ? message.data : message.data.slice()) })

if (this._options.onStream != null) {
this._options.onStream(stream)
if (this._options.onIncomingStream != null) {
this._options.onIncomingStream(stream)
}

return
Expand Down

0 comments on commit 43db1cb

Please sign in to comment.