eilvelia / tdl

Node.js bindings to TDLib 🥒
MIT License
394 stars 52 forks source link

Question about Module(). in the createClient function #55

Closed telion2 closed 5 years ago

telion2 commented 5 years ago

Hi, I just started trying out your package. The documentation tells me to use this function createClient (options) { return new Promise(resolve => { Module().then(module => { const tdlib = new TDLib(module) resolve(new Client(tdlib, options)) }) }) } to create a client. However Module().then(... is unresolved. Do I need the npm package "module" (https://www.npmjs.com/package/module) for it to work? If so I guess a update of the readme would be useful?

telion2 commented 5 years ago

Ah and its about the wasm (tdl-tdlib-wasm) package.

eilvelia commented 5 years ago

Module is from tdlib compiled via emscripten. You can import it using ES6modules/CJS or via the <script> tag in HTML.

For example, see the js file in this archive.

telion2 commented 5 years ago

Sorry but I'm still a bit confused. My context would be to use tdlib in angular, so basically in a browser. For this I thought I use tdl-tdlib-wasm to add tdlib to the browser. After I have read some other issues about tdlib binarys I got lost on how the whole thing is supposed to work. So the way I understand it, is that I need the tdlib binary like this one: https://github.com/ForNeVeR/tdlib.native/releases But how do I handle that binary exactly? Is Module part of it, or do I need to import it speratly? Do I just do import * as Module from 'path-to-td-binary'; ? or: import * as Module from 'path-to-js-file-you-mentioned(td_wasm.js)'; ? I mean if the binary is required, how does tdl or tdl-tdlib-wasm know where it is?

eilvelia commented 5 years ago

https://github.com/ForNeVeR/tdlib.native/releases doesn't have binaries for wasm. You can compile it yourself (instructions). In the end you'll get files like in this archive (though this one is for outdated tdlib 1.3.0, so I don't recommend using it). The js file in the archive exports Module.

or: import * as Module from 'path-to-js-file-you-mentioned(td_wasm.js)'; ?

Yes, like this. Or maybe import { Module } from 'path-to-js-file-you-mentioned(td_wasm.js)', I don't remember. See the contents of compiled js file to determine what exactly you need to import.


You can also just use the official tdweb package (github). It contains prebuilt TDLib binaries and everything you need.

telion2 commented 5 years ago

Oh wow, thank you for your fast response. I probably will just try both tdweb and this package. I saw tdweb earlier, but it had quite short documentation, so I was confused on how to use it. Thanks a lot.^^

Sparkenstein commented 4 years ago

Hey @Bannerets I think I am having the same Issue, I am trying to run tdl-wasm module, but I don't clearly understand Is tdl-tdlib-wasm not a complete wrapper around tdlib? for using tdl-tdlib-wasm do I have to import tdweb as well? I mean the wasm file from tdweb. othewise where to get this td_wasm.js file?

PS: is tdl-tdlib-wasm still in experiemental phase? I was thinking of using it

eilvelia commented 4 years ago

Hi @Sparkenstein, tdweb is not needed. To get td_wasm.js you need to compile TDLib using emscripten (script example). Also, aside of the td_wasm.js file, there should be the td_wasm.wasm binary file.

Though, you'd better use official tdweb, it's a more high-level wrapper and should be more convenient to use. It also contains prebuilt td_wasm. tdl-tdlib-wasm was created before tdweb existed.

PS: is tdl-tdlib-wasm still in experiemental phase? I was thinking of using it

Its development was paused due to the tdweb release.

The advantage of using tdl-tdlib-wasm is that you can write almost the same code both for web and for node.