zabsalahid / serialport-gsm

SerialPort-GSM is a simplified plugin for communicating with gsm modems. (Primarily for sms) (Focused in PDU mode)
MIT License
88 stars 46 forks source link

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

Open duongvanba opened 1 year ago

duongvanba commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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....

KillerJulian commented 5 months ago

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 commented 5 months ago

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

KillerJulian commented 5 months ago

@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