mafintosh / signalhub

Simple signalling server that can be used to coordinate handshaking with webrtc or other fun stuff.
MIT License
667 stars 97 forks source link

TypeError: through.obj is not a function #43

Open samjgorman opened 2 years ago

samjgorman commented 2 years ago

I'm having trouble avoiding this typeerror when calling hub.subscribe('channel-name'). Using in an Electron Forge project with Typescript + Webpack templates. Running signalhub v4.9.0 on node v14.9.0. Installed from npm install signalhub.

Here's a code snippet that causes the issue.

const hub = signalhub('tool', [
  'http://localhost:8080/'
])

async function sighub() {
  hub.subscribe('my-channel').on('data', function (message) {
    console.log('new message received', message)
  })

async function driver(){
   sighub()
}
TypeError: through.obj is not a function
    at SignalHub.subscribe (/Users/samgorman/src/p2p-tool/src/app/.webpack/main/index.js:28252:26)
    at _callee2$ (/Users/samgorman/src/p2p-tool/src/app/.webpack/main/index.js:45312:26)
    at tryCatch (/Users/samgorman/src/p2p-tool/src/app/.webpack/main/index.js:24221:40)
    at Generator.invoke [as _invoke] (/Users/samgorman/src/p2p-tool/src/app/.webpack/main/index.js:24450:22)
    at Generator.prototype.<computed> [as next] (/Users/samgorman/src/p2p-tool/src/app/.webpack/main/index.js:24273:21)
    at asyncGeneratorStep (/Users/samgorman/src/p2p-tool/src/app/.webpack/main/index.js:12:24)
    at _next (/Users/samgorman/src/p2p-tool/src/app/.webpack/main/index.js:34:9)
    at /Users/samgorman/src/p2p-tool/src/app/.webpack/main/index.js:41:7
    at new Promise (<anonymous>)
    at /Users/samgorman/src/p2p-tool/src/app/.webpack/main/index.js:30:12

Believe this is related to line 43 of index.js in the signalhub codebase.

  var subscriber
  if (streams.length === 1) {
    subscriber = streams[0]
  } else {
    subscriber = through.obj()

Any tips appreciated, especially whether you think this may be an issue related to signalhub or something out of scope with Electron, etc. Thank you!