async function writeFrame(
  frame,
  writer,
) {
  const payloadLength = frame.payload.byteLength;
  let header;
  const hasMask = frame.mask ? 128 : 0;
  if (frame.mask && frame.mask.byteLength !== 4) {
    throw new Error(
      "invalid mask. mask must be 4 bytes: length=" + frame.mask.byteLength,
    );
  }
  if (payloadLength < 126) {
    header = new Uint8Array([
      128 | frame.opcode,
      hasMask | payloadLength,
    ]);
  } else if (payloadLength < 65535) {
    header = new Uint8Array([
      128 | frame.opcode,
      hasMask | 126,
      payloadLength >>> 8,
      payloadLength & 255,
    ]);
  } else {
    header = new Uint8Array([
      128 | frame.opcode,
      hasMask | 127,
      ...sliceLongToBytes(payloadLength),
    ]);
  }
  if (frame.mask) {
    header = concat(header, frame.mask);
  }
  unmask(frame.payload, frame.mask);
  header = concat(header, frame.payload);
  const w = BufWriter.create(writer);
  await w.write(header);
  await w.flush();
}
/** Write websocket frame to given writer */
Write websocket frame to given writer
Write websocket frame to given writer
async function writeFrame(
  frame,
  writer,
) {
  const payloadLength = frame.payload.byteLength;
  let header;
  const hasMask = frame.mask ? 128 : 0;
  if (frame.mask && frame.mask.byteLength !== 4) {
    throw new Error(
      "invalid mask. mask must be 4 bytes: length=" + frame.mask.byteLength,
    );
  }
  if (payloadLength < 126) {
    header = new Uint8Array([
      128 | frame.opcode,
      hasMask | payloadLength,
    ]);
  } else if (payloadLength < 65535) {
    header = new Uint8Array([
      128 | frame.opcode,
      hasMask | 126,
      payloadLength >>> 8,
      payloadLength & 255,
    ]);
  } else {
    header = new Uint8Array([
      128 | frame.opcode,
      hasMask | 127,
      ...sliceLongToBytes(payloadLength),
    ]);
  }
  if (frame.mask) {
    header = concat(header, frame.mask);
  }
  unmask(frame.payload, frame.mask);
  header = concat(header, frame.payload);
  const w = BufWriter.create(writer);
  await w.write(header);
  await w.flush();
}
async function writeFrame ( frame , writer , ) { const payloadLength = frame . payload . byteLength ; let header ; const hasMask = frame . mask ? 128 : 0 ; if ( frame . mask && frame . mask . byteLength !== 4 ) { throw new Error ( "invalid mask. mask must be 4 bytes: length=" + frame . mask . byteLength , ) ; } if ( payloadLength < 126 ) { header = new Uint8Array ( [ 128 | frame . opcode , hasMask | payloadLength , ] ) ; } else if ( payloadLength < 65535 ) { header = new Uint8Array ( [ 128 | frame . opcode , hasMask | 126 , payloadLength >>> 8 , payloadLength & 255 , ] ) ; } else { header = new Uint8Array ( [ 128 | frame . opcode , hasMask | 127 , ... sliceLongToBytes ( payloadLength ) , ] ) ; } if ( frame . mask ) { header = concat ( header , frame . mask ) ; } unmask ( frame . payload , frame . mask ) ; header = concat ( header , frame . payload ) ; const w = BufWriter . create ( writer ) ; await w . write ( header ) ; await w . flush ( ) ; }
Write websocket frame to given writer
Write websocket frame to given writer