Nerixyz / instagram_mqtt

Realtime and Push Notification (FBNS) support for the instagram-private-api
MIT License
244 stars 49 forks source link

TypeError: stream.on is not a function #81

Closed callmearta closed 3 years ago

callmearta commented 3 years ago

Hi, I've been trying for couple hours now to get your library working. I'm using instagram-private-api and it's working fine and returns direct messages and everything. Although when i try to use your library this happens:

/src/node_modules/eventemitter3/index.js:181 TypeError: stream.on is not a function
    at destroyer (internal/streams/pipeline.js:27)
    at internal/streams/pipeline.js:88
    at Array.map (<anonymous>)
    at Function.pipeline (internal/streams/pipeline.js:85)
    at MQTToTClient.createPipeline (mqtt.client.ts:167)
    at MQTToTClient._connect (mqtt.client.ts:150)
    at async MQTToTClient.connect (mqtt.client.ts:157)

I'm using this line to wrap the IgApiClient:

withFbnsAndRealtime(new IgApiClient())

Could you help me out please? Also I'm using electron, maybe there's something happening in there.

Nerixyz commented 3 years ago

Which Node version are you on?

callmearta commented 3 years ago

14.15.0 I also upgraded node to 16.2.0 but still had no luck. Currently i installed version 0.2.16 of your lib and there's not this error anymore but i still can't get it working :)) It's giving me this error on version 0.2.16:

mqtt.client.ts:399 Uncaught (in promise) TypeError: Illegal invocation
    at MQTToTClient.setConnected (mqtt.client.ts:399)
    at MQTToTClient.handlePacket (mqtt.client.ts:328)
Nerixyz commented 3 years ago

Then what's your code?

Also make sure you turn on debugging.

callmearta commented 3 years ago
Screen Shot 2021-06-01 at 16 43 49

This is the screenshot of the error. also i tried using debugging but no more information came out of it. So i think something goes wrong before it reaches your lib to debug it. Are the examples up to date with latest version of instagram-private-api? I think maybe there's something happening. this is my code:


const = withFbnsAndRealtime(new IgApiClient());
ig.state.generateDevice(username);
  await ig.simulate.preLoginFlow();
...LoginThings....
ig.realtime.on('error', console.error);
  ig.realtime.on('receive', console.log);
  await ig.realtime.connect();
Nerixyz commented 3 years ago

Are you running this in the browser or the background process?

callmearta commented 3 years ago

I'm running it in react wrapped in electron js so it should be running in browser. Although i can't see the request in network tab

Nerixyz commented 3 years ago

This library relies on node-streams, so you can't run it in the browser. Furthermore, it uses raw TCP/TLS to connect to Instagram which the browser just cannot do.

callmearta commented 3 years ago

Let me check to assure. At the time being thank you for responding. I think it's running under node because it's request is not visible in networks tab

callmearta commented 3 years ago

@Nerixyz I checked it and it's running under node not browser. Still getting this error when using latest version of your package:

index.js:181 TypeError: stream.on is not a function
    at destroyer (internal/streams/pipeline.js:27)
    at internal/streams/pipeline.js:88
    at Array.map (<anonymous>)
    at Function.pipeline (internal/streams/pipeline.js:85)
    at MQTToTClient.createPipeline (mqtt.client.js:110)
    at MQTToTClient._connect (mqtt.client.js:95)
    at async MQTToTClient.connect (mqtt.client.js:100)
Nerixyz commented 3 years ago

Did you try it in vanilla-node?

callmearta commented 3 years ago

@Nerixyz No. I tried to test your own example but couldn't get it working because of no babel or webpack. Still that old version doesn't throw this error. But also that one doesn't work. I've been stuck for almost 7 hours now :))

Nerixyz commented 3 years ago

because of no babel or webpack

You don't need babel or webpack. You just need typescript. Just do npm i instagram_mqtt instagram-private-api edit some constants and run it.

callmearta commented 3 years ago

I did what you said and it works. Then why doesn't it work when it's wrapped in electron?

callmearta commented 3 years ago

Yea there's definitely something wrong with wrapping in electron. do you have any suggestions to use MQTT like Instagram web direct so it can be used in web browsers?

Nerixyz commented 3 years ago

14.15.0

That's wrong. You've used Node 12 (See this run on node 12; the next run on node 14 was sucessful)

callmearta commented 3 years ago
Screen Shot 2021-06-01 at 19 52 58

@Nerixyz It says 14.15.0 mate. Also i've tried installing node again.

Nerixyz commented 3 years ago

It says 14.15.0 mate. Also i've tried installing node again.

Yeah but there's no version of Node 14 where there's a call to stream.on (the stacktrace you sent) on line 27 in internal/streams/pipeline.js.

callmearta commented 3 years ago

Finally!!!!!! Thank you mate. The problem was the fact that electron had packed it's own version of Node and was using version 12.8! I didn't know it does such a thing. Finally after 12 hours :)) Thanks again

F145h commented 3 years ago

thanks for you answers. electron@12 is fine!