(item, cb, hint)
| 30 | } |
| 31 | |
| 32 | add (item, cb, hint) { |
| 33 | if (hint !== sendHints.blob) { |
| 34 | if (!this.#running) { |
| 35 | // TODO(@tsctx): support fast-path for string on running |
| 36 | if (hint === sendHints.text) { |
| 37 | // special fast-path for string |
| 38 | const { 0: head, 1: body } = WebsocketFrameSend.createFastTextFrame(item) |
| 39 | this.#socket.cork() |
| 40 | this.#socket.write(head) |
| 41 | this.#socket.write(body, cb) |
| 42 | this.#socket.uncork() |
| 43 | } else { |
| 44 | // direct writing |
| 45 | this.#socket.write(createFrame(item, hint), cb) |
| 46 | } |
| 47 | } else { |
| 48 | /** @type {SendQueueNode} */ |
| 49 | const node = { |
| 50 | promise: null, |
| 51 | callback: cb, |
| 52 | frame: createFrame(item, hint) |
| 53 | } |
| 54 | this.#queue.push(node) |
| 55 | } |
| 56 | return |
| 57 | } |
| 58 | |
| 59 | /** @type {SendQueueNode} */ |
| 60 | const node = { |
| 61 | promise: item.arrayBuffer().then((ab) => { |
| 62 | node.promise = null |
| 63 | node.frame = createFrame(ab, hint) |
| 64 | }), |
| 65 | callback: cb, |
| 66 | frame: null |
| 67 | } |
| 68 | |
| 69 | this.#queue.push(node) |
| 70 | |
| 71 | if (!this.#running) { |
| 72 | this.#run() |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | async #run () { |
| 77 | this.#running = true |
nothing calls this directly
no test coverage detected