tinode / tinode-js

Tinode javascript bindings
Apache License 2.0
52 stars 42 forks source link

node js compatibility #28

Closed b1f6c1c4 closed 1 year ago

b1f6c1c4 commented 4 years ago

This paragraph causes the following error in nodejs: Error: XMLHttpRequest is not defined (503)

I recommend using axios for this.

or-else commented 4 years ago

XMLHttpRequest is used only in long polling. Long polling is a fallback mechanism when websockets are not available. Given that you fully control your node environment, you can always include a websocket provider and consequently long polling won't ever be needed. Have you provided a websocket implementation as suggested? https://github.com/tinode/tinode-js/blob/master/README.md#node-js-compatibility

or-else commented 4 years ago

Actually XMLHttpRequest is also used in file uploads, so I suppose it needs to be polyfilled too. And URL.createObjectUrl() needs to be polyfilled. I'll make the changes in the SDK.

or-else commented 4 years ago

OK, I've updated the SDK to allow polyfilling of XMLHttpRequest too and added instructions how to do it.

The URL.createObjectURL is still not polyfilled and I don't have time to work on it right now. We do not use this code under Node. You are welcome to send a pull request.

b1f6c1c4 commented 4 years ago

Related: https://github.com/nodejs/node/issues/16167

or-else commented 4 years ago

A full replacement is great, but a workaround would be sufficient too. Maybe an alternative way of downloading when createObjectURL is not available. Or maybe have createObjectURL return a data URL https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs

or-else commented 1 year ago

The original issue with XMLHttpRequest has been resolved. The createObjectURL was added in Node v16.7.0.

Let's close this issue as it is no longer clear what's exactly missing. Please file a new issue if something is still broken when running in Node environment.