2025-11-05 17:04:23 -03:00

44 lines
829 B
JavaScript

function isSecure(uri) {
return uri.startsWith("https") || uri.startsWith("wss");
}
export function compare(a, b) {
let secure;
if (isSecure(a.uri) && !isSecure(b.uri)) {
secure = -1;
} else if (!isSecure(a.uri) && isSecure(b.uri)) {
secure = 1;
} else {
secure = 0;
}
if (secure !== 0) {
return secure;
}
let method;
if (a.method === b.method) {
method = 0;
} else if (a.method === "websocket") {
method = -1;
} else if (b.method === "websocket") {
method = 1;
} else if (a.method === "xbosh") {
method = -1;
} else if (b.method === "xbosh") {
method = 1;
} else if (a.method === "httppoll") {
method = -1;
} else if (b.method === "httppoll") {
method = 1;
} else {
method = 0;
}
if (method !== 0) {
return method;
}
return 0;
}