How to use websocket-framed - 1 common examples

To help you get started, we’ve selected a few websocket-framed examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rse / apollo-client-ws / src / apollo-client-ws.js View on Github external
this.log(1, "connect: begin")

                /*  create a new WebSocket client  */
                let ws
                if (process.env.PLATFORM === "browser")
                    ws = new WebSocket(this._args.uri, this._args.opts.protocols)
                else {
                    const opts = this.hook("connect:options", "pass", {})
                    ws = new WebSocket(this._args.uri, this._args.opts.protocols, opts)
                }

                /*  configure binary transfer  */
                ws.binaryType = process.env.PLATFORM === "browser" ? "arraybuffer" : "nodebuffer"

                /*   create a new WebSocket-Framed wrapper  */
                const wsf = new WebSocketFramed(ws, this._args.opts.encoding)

                /*  react (once) on error messages  */
                const onError = (ev) => {
                    if (this._ws !== null && this._ws._explicitDisconnect)
                        return
                    this.log(1, `connect: end (connection error: ${ev.message})`)
                    ws.removeEventListener("error", onError)
                    ws._errorOnConnect = true
                    if (attempt < this._args.opts.reconnectattempts || this._args.opts.reconnectattempts === -1) {
                        this.log(2, "connection error: trigger new connect attempt " +
                            `(in ${Math.trunc(this._args.opts.reconnectdelay / 1000)}s)`)
                        setTimeout(() => {
                            /*  handle repeated connection attempts (subsequently)  */
                            connectInternal(attempt + 1)
                                .then(() => resolve())
                                .catch((err) => reject(err))

websocket-framed

Framed WebSocket Communication

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis

Popular websocket-framed functions