MCPcopy
hub / github.com/di-sukharev/opencommit / constructor

Method constructor

out/cli.cjs:63612–63664  ·  view source on GitHub ↗

* @param {string} url * @param {string|string[]} protocols

(url2, protocols = [])

Source from the content-addressed store, hash-verified

63610 };
63611 #bufferedAmount = 0;
63612 #protocol = "";
63613 #extensions = "";
63614 /**
63615 * @param {string} url
63616 * @param {string|string[]} protocols
63617 */
63618 constructor(url2, protocols = []) {
63619 super();
63620 webidl.argumentLengthCheck(arguments, 1, { header: "WebSocket constructor" });
63621 if (!experimentalWarned) {
63622 experimentalWarned = true;
63623 process.emitWarning("WebSockets are experimental, expect them to change at any time.", {
63624 code: "UNDICI-WS"
63625 });
63626 }
63627 const options = webidl.converters["DOMString or sequence<DOMString> or WebSocketInit"](protocols);
63628 url2 = webidl.converters.USVString(url2);
63629 protocols = options.protocols;
63630 const baseURL = getGlobalOrigin();
63631 let urlRecord;
63632 try {
63633 urlRecord = new URL(url2, baseURL);
63634 } catch (e3) {
63635 throw new DOMException3(e3, "SyntaxError");
63636 }
63637 if (urlRecord.protocol === "http:") {
63638 urlRecord.protocol = "ws:";
63639 } else if (urlRecord.protocol === "https:") {
63640 urlRecord.protocol = "wss:";
63641 }
63642 if (urlRecord.protocol !== "ws:" && urlRecord.protocol !== "wss:") {
63643 throw new DOMException3(
63644 `Expected a ws: or wss: protocol, got ${urlRecord.protocol}`,
63645 "SyntaxError"
63646 );
63647 }
63648 if (urlRecord.hash || urlRecord.href.endsWith("#")) {
63649 throw new DOMException3("Got fragment", "SyntaxError");
63650 }
63651 if (typeof protocols === "string") {
63652 protocols = [protocols];
63653 }
63654 if (protocols.length !== new Set(protocols.map((p4) => p4.toLowerCase())).size) {
63655 throw new DOMException3("Invalid Sec-WebSocket-Protocol value", "SyntaxError");
63656 }
63657 if (protocols.length > 0 && !protocols.every((p4) => isValidSubprotocol(p4))) {
63658 throw new DOMException3("Invalid Sec-WebSocket-Protocol value", "SyntaxError");
63659 }
63660 this[kWebSocketURL] = new URL(urlRecord.href);
63661 this[kController] = establishWebSocketConnection(
63662 urlRecord,
63663 protocols,
63664 this,
63665 (response) => this.#onConnectionEstablished(response),
63666 options
63667 );

Callers

nothing calls this directly

Calls 6

getGlobalOriginFunction · 0.85
isValidSubprotocolFunction · 0.85
endsWithMethod · 0.80
toLowerCaseMethod · 0.80

Tested by

no test coverage detected