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

[proposal] Can we provide WebSocket interfaces for customizing? #8

Open
bigBron opened this issue May 23, 2020 · 0 comments
Open

[proposal] Can we provide WebSocket interfaces for customizing? #8

bigBron opened this issue May 23, 2020 · 0 comments

Comments

@bigBron
Copy link

bigBron commented May 23, 2020

Hello, @kataras. the neffos.js works very well. but the coupling is too high. I want to change WebSocket. If there is an interface, I can implement it myself.

interface EventCallback {
    (evt: Event)
}

interface MsgCallback {
    (evt: MessageEvent)
}

interface WebSocket {
    Send(dat: string | ArrayBuffer);
    Close();

    OnMessage(cb: MsgCallback);
    OnOpen(cb: EventCallback);
    OnError(cb: EventCallback);
    OnClose(cb: EventCallback);
}

// WS provided by the runtime
let ws = new WS;

let adapter: WebSocket = {
    Send(dat) {
        // logger
        // ...
        ws.send(dat)
    },
    Close(): void {
        // ...
        ws.close()
    },
    OnMessage(cb) {
        // ...
        ws.onMessage(cb);
    },
    OnOpen(cb) {
        // ...
        ws.onOpen(cb);
    },
    OnError(cb) {
        // ...
        ws.onErro(cb);
    },
    OnClose(cb) {
        // ...
        ws.onClose(cb);
    }
};

neffos.SetWebsocketAdapter(adapter);
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

1 participant