Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we use web serial port on browser instead running nodejs #109

Open
duongvanba opened this issue Aug 9, 2022 · 7 comments
Open

Can we use web serial port on browser instead running nodejs #109

duongvanba opened this issue Aug 9, 2022 · 7 comments

Comments

@duongvanba
Copy link

I want to use this library in my reactjs project which use Web Serial API, i think we don't need nodejs anymore
So can you help me
https://github.com/nathanjel/serialport-binding-web-serial-api
Thank you

@zabsalahid
Copy link
Owner

I'm thinking about it.
Browser support On 29th Dec 2020, Web Serial API is supported in modern Chromium based browsers, that is Chrome, Edge, Opera and of course Chromium.
But upgrading this package would require a lot of work. And also, I don't have any GSM modules at the moment.

@Apollon77
Copy link
Contributor

i think we don't need nodejs anymore

I think this is nt that true ;-))) But interesting.

Maybe I look into it when I finally find time for my GSM project

@duongvanba
Copy link
Author

duongvanba commented Aug 9, 2022

I found this package

import Modem from 'web-serial-gsm'

async function list_messages_from_gsm_modem() {
    const port = await navigator.serial.requestPort()
    console.log({ port })
    if (port) {
        const modem = new Modem(port)
        try {
            await port.open({ baudRate: 19200 })
            modem.startReader();
            await modem.startWriter()
            await modem.boot()
        } catch (e) {
        }
        const messages = await modem.listMessages()
        console.log({ messages })
        return messages
    }
}

I tested and it worked, amazing haha

@Xsmael
Copy link

Xsmael commented Dec 15, 2022

I found this package

import Modem from 'web-serial-gsm'

async function list_messages_from_gsm_modem() {
    const port = await navigator.serial.requestPort()
    console.log({ port })
    if (port) {
        const modem = new Modem(port)
        try {
            await port.open({ baudRate: 19200 })
            modem.startReader();
            await modem.startWriter()
            await modem.boot()
        } catch (e) {
        }
        const messages = await modem.listMessages()
        console.log({ messages })
        return messages
    }
}

I tested and it worked, amazing haha

Nice catch! i was also looking for this!
But unfortunately there is 0 documentation on it, like how to send Messages, wait for new messages, run USSD, AT commands and so on....

@JulianWowra
Copy link

In my refactor of this repository, the use of different communication channels via Communicator is provided. I have already tried to implement a communicator for WebSerial. See more.

However, I am unsure about the best way to provide a TypeScript library for both NodeJS and the Web.
Feel free to help me with a pullrequest.

Greetings Julian

@Apollon77
Copy link
Contributor

@KillerJulian SImply proide cros compiled for CJS and ESM 8second fr browsers) ... works good, I do that in other projects

@JulianWowra
Copy link

@KillerJulian SImply proide cros compiled for CJS and ESM 8second fr browsers) ... works good, I do that in other projects

I don't think that will be enough. The SerialPort dependency must certainly be made an optional dependency. Also, polyfills will probably be needed to use the dependencies provided by NodeJS like "events". A bundler would certainly not be a bad option. However, I think that the choice of bundler and polyfills should be left to the user.

I think the topic needs a little more discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants