mirror of
https://github.com/MercuryWorkshop/adrift.git
synced 2025-05-12 05:50:00 -04:00
fix broken packages, part 2
This commit is contained in:
parent
f63588cd78
commit
2b32ab71bc
20 changed files with 6 additions and 19705 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -3,6 +3,7 @@ dist.js
|
||||||
dist.js.map
|
dist.js.map
|
||||||
dist.html
|
dist.html
|
||||||
*/dist/
|
*/dist/
|
||||||
|
dist/
|
||||||
vite.config.js.timestamp-*
|
vite.config.js.timestamp-*
|
||||||
vite.config.ts.timestamp-*
|
vite.config.ts.timestamp-*
|
||||||
admin-creds.json
|
admin-creds.json
|
||||||
|
@ -10,4 +11,4 @@ server/config.json
|
||||||
.firebaserrc
|
.firebaserrc
|
||||||
.firebase
|
.firebase
|
||||||
.env
|
.env
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
node_modules
|
node_modules
|
||||||
|
*/dist/
|
||||||
dist.js
|
dist.js
|
||||||
dist.js.map
|
dist.js.map
|
||||||
dist.html
|
dist.html
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/uuid": "^9.0.2",
|
"@types/uuid": "^9.0.2",
|
||||||
"@mercuryworkshop/bare-client-custom": "file:../bare-client-custom",
|
"@mercuryworkshop/bare-client-custom": "file:../bare-client-custom",
|
||||||
|
"@mercuryworkshop/adrift": "workspace*",
|
||||||
"firebase": "^10.1.0",
|
"firebase": "^10.1.0",
|
||||||
"protocol": "workspace:*",
|
"protocol": "workspace:*",
|
||||||
"uuid": "^9.0.0",
|
"uuid": "^9.0.0",
|
||||||
|
|
8
dist/Transport.d.ts
vendored
8
dist/Transport.d.ts
vendored
|
@ -1,8 +0,0 @@
|
||||||
export declare abstract class Transport {
|
|
||||||
onopen: () => void;
|
|
||||||
onclose: () => void;
|
|
||||||
ondata: (data: ArrayBuffer) => void;
|
|
||||||
constructor(onopen: () => void, onclose: () => void);
|
|
||||||
abstract send(data: ArrayBuffer): void;
|
|
||||||
abstract close(): void;
|
|
||||||
}
|
|
18625
dist/client.cjs
vendored
18625
dist/client.cjs
vendored
File diff suppressed because it is too large
Load diff
659
dist/client.mjs
vendored
659
dist/client.mjs
vendored
|
@ -1,659 +0,0 @@
|
||||||
var __defProp = Object.defineProperty;
|
|
||||||
var __export = (target, all) => {
|
|
||||||
for (var name in all)
|
|
||||||
__defProp(target, name, { get: all[name], enumerable: true });
|
|
||||||
};
|
|
||||||
|
|
||||||
// client/src/AdriftClient.ts
|
|
||||||
import {
|
|
||||||
Client
|
|
||||||
} from "@mercuryworkshop/bare-client-custom";
|
|
||||||
import { MAX_CHUNK_SIZE } from "protocol";
|
|
||||||
var NULL_BODY_STATUSES = [101, 103, 204, 205, 304];
|
|
||||||
function createBodyStream(body, arrayBufferImpl) {
|
|
||||||
if (body === null || typeof body === "undefined")
|
|
||||||
return null;
|
|
||||||
if (typeof body === "string") {
|
|
||||||
body = new TextEncoder().encode(body);
|
|
||||||
}
|
|
||||||
if (window.ArrayBuffer.isView(body)) {
|
|
||||||
body = body.buffer.slice(
|
|
||||||
body.byteOffset,
|
|
||||||
body.byteOffset + body.byteLength
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (body instanceof window.ArrayBuffer) {
|
|
||||||
if (body.byteLength == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
let remaining = body;
|
|
||||||
return new ReadableStream({
|
|
||||||
type: "bytes",
|
|
||||||
pull: (controller) => {
|
|
||||||
if (remaining.byteLength <= 0) {
|
|
||||||
return controller.close();
|
|
||||||
}
|
|
||||||
const current = remaining.slice(0, MAX_CHUNK_SIZE);
|
|
||||||
remaining = remaining.slice(MAX_CHUNK_SIZE);
|
|
||||||
controller.enqueue(new Uint8Array(current));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (body instanceof FormData) {
|
|
||||||
throw new Error("formdata todo");
|
|
||||||
}
|
|
||||||
const transformer = () => new TransformStream({
|
|
||||||
transform: async (chunk, controller) => {
|
|
||||||
if (typeof chunk === "string") {
|
|
||||||
chunk = new TextEncoder().encode(chunk);
|
|
||||||
}
|
|
||||||
if (chunk instanceof Blob) {
|
|
||||||
chunk = await chunk.arrayBuffer();
|
|
||||||
}
|
|
||||||
if (window.ArrayBuffer.isView(chunk)) {
|
|
||||||
chunk = chunk.buffer.slice(
|
|
||||||
chunk.byteOffset,
|
|
||||||
chunk.byteOffset + chunk.byteLength
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!(chunk instanceof window.ArrayBuffer)) {
|
|
||||||
console.error({ chunk });
|
|
||||||
throw new Error("Invalid type read from body stream: " + chunk);
|
|
||||||
}
|
|
||||||
let current = null;
|
|
||||||
let remaining = chunk;
|
|
||||||
do {
|
|
||||||
current = remaining.slice(0, MAX_CHUNK_SIZE);
|
|
||||||
remaining = remaining.slice(MAX_CHUNK_SIZE);
|
|
||||||
controller.enqueue(new Uint8Array(current));
|
|
||||||
} while (remaining.byteLength > 0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (body instanceof ReadableStream) {
|
|
||||||
return body.pipeThrough(transformer());
|
|
||||||
}
|
|
||||||
if (body instanceof Blob) {
|
|
||||||
return body.stream().pipeThrough(transformer());
|
|
||||||
}
|
|
||||||
throw new Error("Unexpected body type: " + body);
|
|
||||||
}
|
|
||||||
var AdriftBareClient = class extends Client {
|
|
||||||
constructor(connection) {
|
|
||||||
super();
|
|
||||||
this.connection = connection;
|
|
||||||
}
|
|
||||||
async request(method, requestHeaders, body, remote, cache, duplex, signal, arrayBufferImpl) {
|
|
||||||
const bodyStream = createBodyStream(body, arrayBufferImpl);
|
|
||||||
let { payload, body: respRawBody } = await this.connection.httprequest(
|
|
||||||
{
|
|
||||||
method,
|
|
||||||
requestHeaders,
|
|
||||||
remote
|
|
||||||
},
|
|
||||||
bodyStream
|
|
||||||
);
|
|
||||||
const headers = new Headers();
|
|
||||||
for (const [header, values] of Object.entries(payload.headers)) {
|
|
||||||
for (const value of values) {
|
|
||||||
headers.append(header, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let respBody = respRawBody;
|
|
||||||
if (respBody.byteLength == 0 || NULL_BODY_STATUSES.includes(payload.status)) {
|
|
||||||
respBody = null;
|
|
||||||
}
|
|
||||||
return new Response(respBody, {
|
|
||||||
status: payload.status,
|
|
||||||
statusText: payload.statusText,
|
|
||||||
headers
|
|
||||||
});
|
|
||||||
}
|
|
||||||
connect(remote, protocols, getRequestHeaders, onMeta, onReadyState, webSocketImpl, arrayBufferImpl) {
|
|
||||||
console.log(arguments);
|
|
||||||
const ws = new webSocketImpl("wss:null", protocols);
|
|
||||||
let initalCloseHappened = false;
|
|
||||||
ws.addEventListener("close", (e) => {
|
|
||||||
if (!initalCloseHappened) {
|
|
||||||
onReadyState(WebSocket.CONNECTING);
|
|
||||||
e.stopImmediatePropagation();
|
|
||||||
initalCloseHappened = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let initialErrorHappened = false;
|
|
||||||
ws.addEventListener("error", (e) => {
|
|
||||||
if (!initialErrorHappened) {
|
|
||||||
onReadyState(WebSocket.CONNECTING);
|
|
||||||
e.stopImmediatePropagation();
|
|
||||||
initialErrorHappened = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
protocols = Array.from(protocols);
|
|
||||||
let { send, close } = this.connection.wsconnect(
|
|
||||||
remote,
|
|
||||||
protocols,
|
|
||||||
(protocol) => {
|
|
||||||
onReadyState(WebSocket.OPEN);
|
|
||||||
ws.__defineGetter__("protocol", () => {
|
|
||||||
return protocol;
|
|
||||||
});
|
|
||||||
ws.dispatchEvent(new Event("open"));
|
|
||||||
},
|
|
||||||
(code, reason, wasClean) => {
|
|
||||||
onReadyState(WebSocket.CLOSED);
|
|
||||||
ws.dispatchEvent(new CloseEvent("close", { code, reason, wasClean }));
|
|
||||||
},
|
|
||||||
async (stream, isBinary) => {
|
|
||||||
let data = await new Response(
|
|
||||||
stream
|
|
||||||
).arrayBuffer();
|
|
||||||
data.__proto__ = arrayBufferImpl.prototype;
|
|
||||||
if (!isBinary) {
|
|
||||||
try {
|
|
||||||
data = new TextDecoder().decode(data);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ws.dispatchEvent(new MessageEvent("message", { data }));
|
|
||||||
},
|
|
||||||
(message) => {
|
|
||||||
console.log({ message });
|
|
||||||
ws.dispatchEvent(new ErrorEvent("error", { message }));
|
|
||||||
},
|
|
||||||
arrayBufferImpl,
|
|
||||||
arrayBufferImpl.prototype.constructor.constructor("return __uv$location")().origin
|
|
||||||
);
|
|
||||||
ws.send = (data) => {
|
|
||||||
send(data);
|
|
||||||
};
|
|
||||||
ws.close = (code, reason) => {
|
|
||||||
close(code, reason);
|
|
||||||
onReadyState(WebSocket.CLOSING);
|
|
||||||
};
|
|
||||||
return ws;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// client/src/Connection.ts
|
|
||||||
import {
|
|
||||||
C2SRequestTypes,
|
|
||||||
C2S_HELLO,
|
|
||||||
PROTOCOL_VERSION,
|
|
||||||
S2CRequestTypes,
|
|
||||||
S2C_HELLO_ERR,
|
|
||||||
S2C_HELLO_OK
|
|
||||||
} from "protocol";
|
|
||||||
ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
|
|
||||||
const reader = this.getReader();
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
const { done, value } = await reader.read();
|
|
||||||
if (done)
|
|
||||||
return;
|
|
||||||
yield value;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
reader.releaseLock();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var Connection = class _Connection {
|
|
||||||
constructor(transport) {
|
|
||||||
this.transport = transport;
|
|
||||||
this.initialized = false;
|
|
||||||
this.requestCallbacks = {};
|
|
||||||
this.openRequestStreams = {};
|
|
||||||
this.openingSockets = {};
|
|
||||||
this.openSockets = {};
|
|
||||||
this.wsMsgStreams = {};
|
|
||||||
this.counter = 0;
|
|
||||||
transport.ondata = _Connection.uninitializedError;
|
|
||||||
}
|
|
||||||
static uninitializedError() {
|
|
||||||
throw new Error("Connection not initialized");
|
|
||||||
}
|
|
||||||
async initialize() {
|
|
||||||
const onDataPromise = () => {
|
|
||||||
return new Promise((res) => {
|
|
||||||
this.transport.ondata = res;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
this.transport.send(new TextEncoder().encode(C2S_HELLO + PROTOCOL_VERSION));
|
|
||||||
const msg = await onDataPromise();
|
|
||||||
const msgText = new TextDecoder().decode(msg);
|
|
||||||
if (msgText === S2C_HELLO_OK) {
|
|
||||||
this.transport.ondata = this.ondata.bind(this);
|
|
||||||
this.initialized = true;
|
|
||||||
} else if (msgText.startsWith(S2C_HELLO_ERR)) {
|
|
||||||
const expectedVersion = msgText.slice(S2C_HELLO_ERR.length);
|
|
||||||
throw new Error(
|
|
||||||
`We are running protocol version ${PROTOCOL_VERSION}, but server expected ${expectedVersion}`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
throw new Error("Unexpected server hello response");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nextSeq() {
|
|
||||||
return ++this.counter;
|
|
||||||
}
|
|
||||||
ondata(data) {
|
|
||||||
if (!this.initialized)
|
|
||||||
return;
|
|
||||||
let cursor = 0;
|
|
||||||
const view = new DataView(data);
|
|
||||||
let requestID = view.getUint16(cursor);
|
|
||||||
cursor += 2;
|
|
||||||
let requestType = view.getUint8(cursor);
|
|
||||||
cursor += 1;
|
|
||||||
const msgText = () => new TextDecoder().decode(data.slice(cursor));
|
|
||||||
const msgJSON = () => JSON.parse(msgText());
|
|
||||||
switch (requestType) {
|
|
||||||
case S2CRequestTypes.HTTPResponseStart:
|
|
||||||
const payload = msgJSON();
|
|
||||||
const stream = new ReadableStream({
|
|
||||||
start: (controller) => {
|
|
||||||
this.openRequestStreams[requestID] = controller;
|
|
||||||
},
|
|
||||||
pull: (controller) => {
|
|
||||||
},
|
|
||||||
cancel: () => {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.requestCallbacks[requestID]({ payload, body: stream });
|
|
||||||
delete this.requestCallbacks[requestID];
|
|
||||||
break;
|
|
||||||
case S2CRequestTypes.HTTPResponseChunk:
|
|
||||||
this.openRequestStreams[requestID]?.enqueue(
|
|
||||||
new Uint8Array(data.slice(cursor))
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case S2CRequestTypes.HTTPResponseEnd:
|
|
||||||
this.openRequestStreams[requestID]?.close();
|
|
||||||
delete this.openRequestStreams[requestID];
|
|
||||||
break;
|
|
||||||
case S2CRequestTypes.WSOpen: {
|
|
||||||
const socketMeta = this.openingSockets[requestID];
|
|
||||||
if (!socketMeta)
|
|
||||||
return;
|
|
||||||
const payload2 = msgJSON();
|
|
||||||
delete this.openingSockets[requestID];
|
|
||||||
this.openSockets[requestID] = socketMeta;
|
|
||||||
setTimeout(() => socketMeta.onopen(payload2.protocol));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case S2CRequestTypes.WSBinaryStart:
|
|
||||||
case S2CRequestTypes.WSTextStart: {
|
|
||||||
const socketMeta = this.openSockets[requestID];
|
|
||||||
if (!socketMeta)
|
|
||||||
return;
|
|
||||||
const stream2 = new ReadableStream({
|
|
||||||
start: (controller) => {
|
|
||||||
this.wsMsgStreams[requestID] = controller;
|
|
||||||
},
|
|
||||||
pull: (constroller) => {
|
|
||||||
},
|
|
||||||
cancel: () => {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
setTimeout(
|
|
||||||
() => socketMeta.onmessage(
|
|
||||||
stream2,
|
|
||||||
requestType === S2CRequestTypes.WSBinaryStart ? true : requestType === S2CRequestTypes.WSTextStart ? false : (() => {
|
|
||||||
throw new Error("unreachable");
|
|
||||||
})()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case S2CRequestTypes.WSDataChunk: {
|
|
||||||
const stream2 = this.wsMsgStreams[requestID];
|
|
||||||
stream2?.enqueue(new Uint8Array(data.slice(cursor)));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case S2CRequestTypes.WSDataEnd: {
|
|
||||||
const stream2 = this.wsMsgStreams[requestID];
|
|
||||||
stream2?.close();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case S2CRequestTypes.WSClose: {
|
|
||||||
const socketMeta = this.openingSockets[requestID] || this.openSockets[requestID];
|
|
||||||
if (!socketMeta)
|
|
||||||
return;
|
|
||||||
const payload2 = msgJSON();
|
|
||||||
setTimeout(
|
|
||||||
() => socketMeta.onclose(
|
|
||||||
payload2.code || 1005,
|
|
||||||
payload2.reason || "",
|
|
||||||
"wasClean" in payload2 ? Boolean(payload2.wasClean) : false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
delete this.openingSockets[requestID];
|
|
||||||
delete this.openSockets[requestID];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case S2CRequestTypes.WSError: {
|
|
||||||
const socketMeta = this.openingSockets[requestID] || this.openSockets[requestID];
|
|
||||||
if (!socketMeta)
|
|
||||||
return;
|
|
||||||
const payload2 = msgJSON();
|
|
||||||
setTimeout(() => socketMeta.onerror(payload2.message));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async send(requestID, type, data) {
|
|
||||||
if (!this.initialized) {
|
|
||||||
_Connection.uninitializedError();
|
|
||||||
}
|
|
||||||
let header = new window.ArrayBuffer(2 + 1);
|
|
||||||
let view = new DataView(header);
|
|
||||||
let cursor = 0;
|
|
||||||
view.setUint16(cursor, requestID);
|
|
||||||
cursor += 2;
|
|
||||||
view.setUint8(cursor, type);
|
|
||||||
cursor += 1;
|
|
||||||
let buf = header;
|
|
||||||
if (data) {
|
|
||||||
buf = await new Blob([header, data]).arrayBuffer();
|
|
||||||
}
|
|
||||||
this.transport.send(buf);
|
|
||||||
}
|
|
||||||
httprequest(data, body) {
|
|
||||||
if (!this.initialized) {
|
|
||||||
_Connection.uninitializedError();
|
|
||||||
}
|
|
||||||
const payload = { ...data, hasBody: Boolean(body) };
|
|
||||||
let json = JSON.stringify(payload);
|
|
||||||
return new Promise(async (resolve) => {
|
|
||||||
let seq = this.nextSeq();
|
|
||||||
this.requestCallbacks[seq] = resolve;
|
|
||||||
await this.send(seq, C2SRequestTypes.HTTPRequestStart, new Blob([json]));
|
|
||||||
if (payload.hasBody) {
|
|
||||||
for await (const chunk of body) {
|
|
||||||
await this.send(
|
|
||||||
seq,
|
|
||||||
C2SRequestTypes.HTTPRequestChunk,
|
|
||||||
new Uint8Array(chunk)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
await this.send(seq, C2SRequestTypes.HTTPRequestEnd);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
wsconnect(url, protocols, onopen, onclose, onmessage, onerror, arrayBufferImpl, host) {
|
|
||||||
if (!this.initialized) {
|
|
||||||
_Connection.uninitializedError();
|
|
||||||
}
|
|
||||||
const payload = { url: url.toString(), protocols, host };
|
|
||||||
const payloadJSON = JSON.stringify(payload);
|
|
||||||
let seq = this.nextSeq();
|
|
||||||
const closeWithError = () => onclose(1006, "", false);
|
|
||||||
this.send(
|
|
||||||
seq,
|
|
||||||
C2SRequestTypes.WSOpen,
|
|
||||||
new TextEncoder().encode(payloadJSON)
|
|
||||||
).catch((e) => {
|
|
||||||
console.error(e);
|
|
||||||
closeWithError();
|
|
||||||
});
|
|
||||||
this.openingSockets[seq] = {
|
|
||||||
onopen,
|
|
||||||
onmessage,
|
|
||||||
onclose,
|
|
||||||
onerror
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
send: (data) => {
|
|
||||||
if (!this.openSockets[seq]) {
|
|
||||||
throw new Error("send on closed socket");
|
|
||||||
}
|
|
||||||
const cleanup = (e) => {
|
|
||||||
console.error(e);
|
|
||||||
delete this.openSockets[seq];
|
|
||||||
};
|
|
||||||
if (typeof data === "string") {
|
|
||||||
this.send(
|
|
||||||
seq,
|
|
||||||
C2SRequestTypes.WSSendText,
|
|
||||||
new TextEncoder().encode(data)
|
|
||||||
).catch(cleanup);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (data instanceof arrayBufferImpl) {
|
|
||||||
this.send(seq, C2SRequestTypes.WSSendBinary, data).catch(cleanup);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (arrayBufferImpl.isView(data)) {
|
|
||||||
this.send(
|
|
||||||
seq,
|
|
||||||
C2SRequestTypes.WSSendBinary,
|
|
||||||
data.buffer.slice(
|
|
||||||
data.byteOffset,
|
|
||||||
data.byteOffset + data.byteLength
|
|
||||||
)
|
|
||||||
).catch(cleanup);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.error({ data });
|
|
||||||
throw new Error("Unexpected type passed to send");
|
|
||||||
},
|
|
||||||
close: (code, reason) => {
|
|
||||||
const payload2 = { code, reason };
|
|
||||||
const payloadJSON2 = JSON.stringify(payload2);
|
|
||||||
this.send(
|
|
||||||
seq,
|
|
||||||
C2SRequestTypes.WSClose,
|
|
||||||
new TextEncoder().encode(payloadJSON2)
|
|
||||||
).catch((e) => {
|
|
||||||
console.error(e);
|
|
||||||
});
|
|
||||||
delete this.openSockets[seq];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// client/src/DevWsTransport.ts
|
|
||||||
import { Transport as Transport2 } from "protocol";
|
|
||||||
var DevWsTransport = class extends Transport2 {
|
|
||||||
constructor(onopen, onclose) {
|
|
||||||
super(onopen, onclose);
|
|
||||||
this.ws = new WebSocket("ws://localhost:3000/dev-ws");
|
|
||||||
this.ws.binaryType = "arraybuffer";
|
|
||||||
this.ws.onopen = onopen;
|
|
||||||
this.ws.onclose = onclose;
|
|
||||||
this.ws.onmessage = this.onmessage.bind(this);
|
|
||||||
}
|
|
||||||
onmessage(msg) {
|
|
||||||
if (msg.data instanceof window.ArrayBuffer) {
|
|
||||||
this.ondata(msg.data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
send(data) {
|
|
||||||
this.ws.send(data);
|
|
||||||
}
|
|
||||||
close() {
|
|
||||||
this.ws.close();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// client/src/RTCTransport.ts
|
|
||||||
import { Transport as Transport3 } from "protocol";
|
|
||||||
var rtcConf = {
|
|
||||||
iceServers: [
|
|
||||||
{
|
|
||||||
urls: "stun:stun.l.google.com:19302"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
var RTCTransport = class extends Transport3 {
|
|
||||||
constructor(onopen, onclose, onconnectionstatechange, onsignalingstatechange, onicegatheringstatechange) {
|
|
||||||
super(onopen, onclose);
|
|
||||||
this.onopen = onopen;
|
|
||||||
this.onclose = onclose;
|
|
||||||
this.onconnectionstatechange = onconnectionstatechange;
|
|
||||||
this.onsignalingstatechange = onsignalingstatechange;
|
|
||||||
this.onicegatheringstatechange = onicegatheringstatechange;
|
|
||||||
this.peer = new RTCPeerConnection(rtcConf);
|
|
||||||
this.peer.onconnectionstatechange = onconnectionstatechange;
|
|
||||||
this.peer.onsignalingstatechange = onsignalingstatechange;
|
|
||||||
this.peer.oniceconnectionstatechange = (event) => {
|
|
||||||
console.log("ICE connection state:", this.peer.iceConnectionState);
|
|
||||||
if (this.peer.iceConnectionState == "disconnected" || this.peer.iceConnectionState == "failed") {
|
|
||||||
console.log("disconnected");
|
|
||||||
onclose();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.peer.onicegatheringstatechange = onicegatheringstatechange;
|
|
||||||
this.dataChannel = this.peer.createDataChannel("host-server");
|
|
||||||
this.dataChannel.onopen = onopen;
|
|
||||||
this.dataChannel.binaryType = "arraybuffer";
|
|
||||||
this.dataChannel.onclose = onclose;
|
|
||||||
this.dataChannel.onmessage = async (event) => {
|
|
||||||
let buf = event.data;
|
|
||||||
this.ondata(buf);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
send(data) {
|
|
||||||
this.dataChannel.send(data);
|
|
||||||
}
|
|
||||||
close() {
|
|
||||||
this.dataChannel.close();
|
|
||||||
}
|
|
||||||
async createOffer() {
|
|
||||||
const localCandidates = [];
|
|
||||||
let readyPromise = new Promise((resolve, reject) => {
|
|
||||||
this.peer.onicecandidate = async (event) => {
|
|
||||||
if (event.candidate) {
|
|
||||||
localCandidates.push(event.candidate);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve({ offer, localCandidates });
|
|
||||||
};
|
|
||||||
});
|
|
||||||
const offer = await this.peer.createOffer();
|
|
||||||
await this.peer.setLocalDescription(offer);
|
|
||||||
return readyPromise;
|
|
||||||
}
|
|
||||||
async answer(answer, candidates) {
|
|
||||||
await this.peer.setRemoteDescription(answer);
|
|
||||||
for (let candidate of candidates) {
|
|
||||||
await this.peer.addIceCandidate(candidate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// client/src/SignalFirebase.ts
|
|
||||||
var SignalFirebase_exports = {};
|
|
||||||
__export(SignalFirebase_exports, {
|
|
||||||
signalAccount: () => signalAccount,
|
|
||||||
signalSwarm: () => signalSwarm
|
|
||||||
});
|
|
||||||
import {
|
|
||||||
getDatabase,
|
|
||||||
onValue,
|
|
||||||
ref,
|
|
||||||
set,
|
|
||||||
remove,
|
|
||||||
goOffline
|
|
||||||
} from "firebase/database";
|
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
import { getAuth } from "firebase/auth";
|
|
||||||
async function signalSwarm(offer) {
|
|
||||||
let id = uuid();
|
|
||||||
const db = getDatabase();
|
|
||||||
let reff = ref(db, `/swarm/${id}`);
|
|
||||||
set(reff, offer);
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
onValue(reff, (snapshot) => {
|
|
||||||
const text = snapshot.val();
|
|
||||||
if (!text)
|
|
||||||
return;
|
|
||||||
let data = JSON.parse(text);
|
|
||||||
console.log("<", data);
|
|
||||||
if (data.error) {
|
|
||||||
reject(new Error(data.error));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!(data && data.answer && data.candidates))
|
|
||||||
return;
|
|
||||||
remove(reff);
|
|
||||||
resolve(data);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
async function signalAccount(offer) {
|
|
||||||
let auth = getAuth();
|
|
||||||
if (!auth.currentUser)
|
|
||||||
throw new Error("not signed in");
|
|
||||||
const db = getDatabase();
|
|
||||||
let peer = ref(db, `/peers/${auth.currentUser.uid}`);
|
|
||||||
set(peer, offer);
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
onValue(peer, async (snapshot) => {
|
|
||||||
const str = snapshot.val();
|
|
||||||
if (str) {
|
|
||||||
let data = JSON.parse(str);
|
|
||||||
if (data && data.answer && data.candidates) {
|
|
||||||
remove(peer);
|
|
||||||
resolve(data);
|
|
||||||
goOffline(db);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// client/src/index.ts
|
|
||||||
function downloadShortcut(name, title) {
|
|
||||||
let a = document.createElement("a");
|
|
||||||
a.href = "data:text/plain;base64," + btoa(`
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>${title}</title>
|
|
||||||
<style>
|
|
||||||
body,
|
|
||||||
html {
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
width: 100vw;
|
|
||||||
height: 100vh;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
iframe {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<iframe src="${location.href}" />
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
`);
|
|
||||||
console.log(a.href);
|
|
||||||
a.download = name;
|
|
||||||
a.click();
|
|
||||||
}
|
|
||||||
export {
|
|
||||||
AdriftBareClient,
|
|
||||||
Connection,
|
|
||||||
DevWsTransport,
|
|
||||||
RTCTransport,
|
|
||||||
SignalFirebase_exports as SignalFirebase,
|
|
||||||
downloadShortcut
|
|
||||||
};
|
|
8
dist/client/src/AdriftClient.d.ts
vendored
8
dist/client/src/AdriftClient.d.ts
vendored
|
@ -1,8 +0,0 @@
|
||||||
import { BareHeaders, BareResponse, Client, GetRequestHeadersCallback, MetaCallback, ReadyStateCallback, WebSocketImpl } from "@mercuryworkshop/bare-client-custom";
|
|
||||||
import { Connection } from "./Connection";
|
|
||||||
export declare class AdriftBareClient extends Client {
|
|
||||||
private connection;
|
|
||||||
constructor(connection: Connection);
|
|
||||||
request(method: string, requestHeaders: BareHeaders, body: BodyInit | null, remote: URL, cache: string | undefined, duplex: string | undefined, signal: AbortSignal | undefined, arrayBufferImpl: ArrayBufferConstructor): Promise<BareResponse>;
|
|
||||||
connect(remote: URL, protocols: string | string[], getRequestHeaders: GetRequestHeadersCallback, onMeta: MetaCallback, onReadyState: ReadyStateCallback, webSocketImpl: WebSocketImpl, arrayBufferImpl: ArrayBufferConstructor): WebSocket;
|
|
||||||
}
|
|
36
dist/client/src/Connection.d.ts
vendored
36
dist/client/src/Connection.d.ts
vendored
|
@ -1,36 +0,0 @@
|
||||||
import { C2SRequestType, HTTPResponsePayload, ProtoBareHeaders, Transport } from "protocol";
|
|
||||||
type OpenWSMeta = {
|
|
||||||
onopen: (protocol: string) => void;
|
|
||||||
onclose: (code: number, reason: string, wasClean: boolean) => void;
|
|
||||||
onmessage: (data: ReadableStream, isBinary: boolean) => void;
|
|
||||||
onerror: (message: string) => void;
|
|
||||||
};
|
|
||||||
export declare class Connection {
|
|
||||||
transport: Transport;
|
|
||||||
initialized: boolean;
|
|
||||||
requestCallbacks: Record<number, Function>;
|
|
||||||
openRequestStreams: Record<number, ReadableStreamDefaultController<any>>;
|
|
||||||
openingSockets: Record<number, OpenWSMeta>;
|
|
||||||
openSockets: Record<number, OpenWSMeta>;
|
|
||||||
wsMsgStreams: Record<number, ReadableStreamDefaultController<any>>;
|
|
||||||
counter: number;
|
|
||||||
static uninitializedError(): void;
|
|
||||||
constructor(transport: Transport);
|
|
||||||
initialize(): Promise<void>;
|
|
||||||
nextSeq(): number;
|
|
||||||
ondata(data: ArrayBuffer): void;
|
|
||||||
send(requestID: number, type: C2SRequestType, data?: ArrayBuffer | Blob): Promise<void>;
|
|
||||||
httprequest(data: {
|
|
||||||
method: string;
|
|
||||||
requestHeaders: ProtoBareHeaders;
|
|
||||||
remote: URL;
|
|
||||||
}, body: ReadableStream<ArrayBuffer | Uint8Array> | null): Promise<{
|
|
||||||
payload: HTTPResponsePayload;
|
|
||||||
body: ArrayBuffer;
|
|
||||||
}>;
|
|
||||||
wsconnect(url: URL, protocols: string | string[], onopen: (protocol: string) => void, onclose: (code: number, reason: string, wasClean: boolean) => void, onmessage: (data: ReadableStream, isBinary: boolean) => void, onerror: (message: string) => void, arrayBufferImpl: ArrayBufferConstructor, host: string): {
|
|
||||||
send: (data: any) => void;
|
|
||||||
close: (code?: number, reason?: string) => void;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
export {};
|
|
8
dist/client/src/DevWsTransport.d.ts
vendored
8
dist/client/src/DevWsTransport.d.ts
vendored
|
@ -1,8 +0,0 @@
|
||||||
import { Transport } from "protocol";
|
|
||||||
export declare class DevWsTransport extends Transport {
|
|
||||||
ws: WebSocket;
|
|
||||||
constructor(onopen: () => void, onclose: () => void);
|
|
||||||
onmessage(msg: MessageEvent<any>): void;
|
|
||||||
send(data: ArrayBuffer): void;
|
|
||||||
close(): void;
|
|
||||||
}
|
|
23
dist/client/src/RTCTransport.d.ts
vendored
23
dist/client/src/RTCTransport.d.ts
vendored
|
@ -1,23 +0,0 @@
|
||||||
import { Transport } from "protocol";
|
|
||||||
export type Offer = {
|
|
||||||
offer: any;
|
|
||||||
localCandidates: any;
|
|
||||||
};
|
|
||||||
export type Answer = {
|
|
||||||
answer: any;
|
|
||||||
candidates: any;
|
|
||||||
};
|
|
||||||
export declare class RTCTransport extends Transport {
|
|
||||||
onopen: () => void;
|
|
||||||
onclose: () => void;
|
|
||||||
onconnectionstatechange: () => void;
|
|
||||||
onsignalingstatechange: () => void;
|
|
||||||
onicegatheringstatechange: () => void;
|
|
||||||
peer: RTCPeerConnection;
|
|
||||||
dataChannel: RTCDataChannel;
|
|
||||||
constructor(onopen: () => void, onclose: () => void, onconnectionstatechange: () => void, onsignalingstatechange: () => void, onicegatheringstatechange: () => void);
|
|
||||||
send(data: ArrayBuffer): void;
|
|
||||||
close(): void;
|
|
||||||
createOffer(): Promise<Promise<Offer>>;
|
|
||||||
answer(answer: any, candidates: any): Promise<void>;
|
|
||||||
}
|
|
3
dist/client/src/SignalFirebase.d.ts
vendored
3
dist/client/src/SignalFirebase.d.ts
vendored
|
@ -1,3 +0,0 @@
|
||||||
import { Answer } from "./RTCTransport";
|
|
||||||
export declare function signalSwarm(offer: string): Promise<Answer>;
|
|
||||||
export declare function signalAccount(offer: string): Promise<Answer>;
|
|
6
dist/client/src/index.d.ts
vendored
6
dist/client/src/index.d.ts
vendored
|
@ -1,6 +0,0 @@
|
||||||
export { AdriftBareClient } from "./AdriftClient";
|
|
||||||
export { Connection } from "./Connection";
|
|
||||||
export { DevWsTransport } from "./DevWsTransport";
|
|
||||||
export { RTCTransport } from "./RTCTransport";
|
|
||||||
export * as SignalFirebase from "./SignalFirebase";
|
|
||||||
export declare function downloadShortcut(name: string, title: string): void;
|
|
58
dist/index.d.ts
vendored
58
dist/index.d.ts
vendored
|
@ -1,58 +0,0 @@
|
||||||
export type ObjectValues<T> = T[keyof T];
|
|
||||||
export declare const C2SRequestTypes: {
|
|
||||||
readonly HTTPRequestStart: 0;
|
|
||||||
readonly HTTPRequestChunk: 1;
|
|
||||||
readonly HTTPRequestEnd: 2;
|
|
||||||
readonly WSOpen: 3;
|
|
||||||
readonly WSClose: 4;
|
|
||||||
readonly WSSendText: 5;
|
|
||||||
readonly WSSendBinary: 6;
|
|
||||||
};
|
|
||||||
export type C2SRequestType = ObjectValues<typeof C2SRequestTypes>;
|
|
||||||
export declare const S2CRequestTypes: {
|
|
||||||
readonly HTTPResponseStart: 0;
|
|
||||||
readonly HTTPResponseChunk: 1;
|
|
||||||
readonly HTTPResponseEnd: 2;
|
|
||||||
readonly WSOpen: 3;
|
|
||||||
readonly WSClose: 4;
|
|
||||||
readonly WSTextStart: 5;
|
|
||||||
readonly WSBinaryStart: 6;
|
|
||||||
readonly WSDataChunk: 7;
|
|
||||||
readonly WSDataEnd: 8;
|
|
||||||
readonly WSError: 9;
|
|
||||||
};
|
|
||||||
export type S2CRequestType = ObjectValues<typeof S2CRequestTypes>;
|
|
||||||
export type ProtoBareHeaders = Record<string, string | string[]>;
|
|
||||||
export type HTTPRequestPayload = {
|
|
||||||
method: string;
|
|
||||||
requestHeaders: ProtoBareHeaders;
|
|
||||||
remote: URL;
|
|
||||||
hasBody: boolean;
|
|
||||||
};
|
|
||||||
export type HTTPResponsePayload = {
|
|
||||||
status: number;
|
|
||||||
statusText: string;
|
|
||||||
headers: ProtoBareHeaders;
|
|
||||||
};
|
|
||||||
export type C2SWSOpenPayload = {
|
|
||||||
url: string;
|
|
||||||
protocols: string | string[];
|
|
||||||
host: string;
|
|
||||||
};
|
|
||||||
export type S2CWSOpenPayload = {
|
|
||||||
protocol: string;
|
|
||||||
};
|
|
||||||
export type WSClosePayload = {
|
|
||||||
code: number;
|
|
||||||
reason: string;
|
|
||||||
wasClean: boolean;
|
|
||||||
};
|
|
||||||
export type WSErrorPayload = {
|
|
||||||
message: string;
|
|
||||||
};
|
|
||||||
export declare const MAX_CHUNK_SIZE: number;
|
|
||||||
export declare const S2C_HELLO_OK = ":3";
|
|
||||||
export declare const C2S_HELLO = "haiii ";
|
|
||||||
export declare const S2C_HELLO_ERR = ":< ";
|
|
||||||
export declare const PROTOCOL_VERSION = "3.0";
|
|
||||||
export { Transport } from "./Transport";
|
|
69
dist/protocol.cjs
vendored
69
dist/protocol.cjs
vendored
|
@ -1,69 +0,0 @@
|
||||||
var __defProp = Object.defineProperty;
|
|
||||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
||||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
||||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
||||||
var __export = (target, all) => {
|
|
||||||
for (var name in all)
|
|
||||||
__defProp(target, name, { get: all[name], enumerable: true });
|
|
||||||
};
|
|
||||||
var __copyProps = (to, from, except, desc) => {
|
|
||||||
if (from && typeof from === "object" || typeof from === "function") {
|
|
||||||
for (let key of __getOwnPropNames(from))
|
|
||||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
||||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
||||||
}
|
|
||||||
return to;
|
|
||||||
};
|
|
||||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
||||||
|
|
||||||
// protocol/src/index.ts
|
|
||||||
var src_exports = {};
|
|
||||||
__export(src_exports, {
|
|
||||||
C2SRequestTypes: () => C2SRequestTypes,
|
|
||||||
C2S_HELLO: () => C2S_HELLO,
|
|
||||||
MAX_CHUNK_SIZE: () => MAX_CHUNK_SIZE,
|
|
||||||
PROTOCOL_VERSION: () => PROTOCOL_VERSION,
|
|
||||||
S2CRequestTypes: () => S2CRequestTypes,
|
|
||||||
S2C_HELLO_ERR: () => S2C_HELLO_ERR,
|
|
||||||
S2C_HELLO_OK: () => S2C_HELLO_OK,
|
|
||||||
Transport: () => Transport
|
|
||||||
});
|
|
||||||
module.exports = __toCommonJS(src_exports);
|
|
||||||
|
|
||||||
// protocol/src/Transport.ts
|
|
||||||
var Transport = class {
|
|
||||||
constructor(onopen, onclose) {
|
|
||||||
this.onopen = onopen;
|
|
||||||
this.onclose = onclose;
|
|
||||||
}
|
|
||||||
ondata = () => {
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// protocol/src/index.ts
|
|
||||||
var C2SRequestTypes = {
|
|
||||||
HTTPRequestStart: 0,
|
|
||||||
HTTPRequestChunk: 1,
|
|
||||||
HTTPRequestEnd: 2,
|
|
||||||
WSOpen: 3,
|
|
||||||
WSClose: 4,
|
|
||||||
WSSendText: 5,
|
|
||||||
WSSendBinary: 6
|
|
||||||
};
|
|
||||||
var S2CRequestTypes = {
|
|
||||||
HTTPResponseStart: 0,
|
|
||||||
HTTPResponseChunk: 1,
|
|
||||||
HTTPResponseEnd: 2,
|
|
||||||
WSOpen: 3,
|
|
||||||
WSClose: 4,
|
|
||||||
WSTextStart: 5,
|
|
||||||
WSBinaryStart: 6,
|
|
||||||
WSDataChunk: 7,
|
|
||||||
WSDataEnd: 8,
|
|
||||||
WSError: 9
|
|
||||||
};
|
|
||||||
var MAX_CHUNK_SIZE = 12 * 1024;
|
|
||||||
var S2C_HELLO_OK = ":3";
|
|
||||||
var C2S_HELLO = "haiii ";
|
|
||||||
var S2C_HELLO_ERR = ":< ";
|
|
||||||
var PROTOCOL_VERSION = "3.0";
|
|
47
dist/protocol.mjs
vendored
47
dist/protocol.mjs
vendored
|
@ -1,47 +0,0 @@
|
||||||
// protocol/src/Transport.ts
|
|
||||||
var Transport = class {
|
|
||||||
constructor(onopen, onclose) {
|
|
||||||
this.onopen = onopen;
|
|
||||||
this.onclose = onclose;
|
|
||||||
}
|
|
||||||
ondata = () => {
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// protocol/src/index.ts
|
|
||||||
var C2SRequestTypes = {
|
|
||||||
HTTPRequestStart: 0,
|
|
||||||
HTTPRequestChunk: 1,
|
|
||||||
HTTPRequestEnd: 2,
|
|
||||||
WSOpen: 3,
|
|
||||||
WSClose: 4,
|
|
||||||
WSSendText: 5,
|
|
||||||
WSSendBinary: 6
|
|
||||||
};
|
|
||||||
var S2CRequestTypes = {
|
|
||||||
HTTPResponseStart: 0,
|
|
||||||
HTTPResponseChunk: 1,
|
|
||||||
HTTPResponseEnd: 2,
|
|
||||||
WSOpen: 3,
|
|
||||||
WSClose: 4,
|
|
||||||
WSTextStart: 5,
|
|
||||||
WSBinaryStart: 6,
|
|
||||||
WSDataChunk: 7,
|
|
||||||
WSDataEnd: 8,
|
|
||||||
WSError: 9
|
|
||||||
};
|
|
||||||
var MAX_CHUNK_SIZE = 12 * 1024;
|
|
||||||
var S2C_HELLO_OK = ":3";
|
|
||||||
var C2S_HELLO = "haiii ";
|
|
||||||
var S2C_HELLO_ERR = ":< ";
|
|
||||||
var PROTOCOL_VERSION = "3.0";
|
|
||||||
export {
|
|
||||||
C2SRequestTypes,
|
|
||||||
C2S_HELLO,
|
|
||||||
MAX_CHUNK_SIZE,
|
|
||||||
PROTOCOL_VERSION,
|
|
||||||
S2CRequestTypes,
|
|
||||||
S2C_HELLO_ERR,
|
|
||||||
S2C_HELLO_OK,
|
|
||||||
Transport
|
|
||||||
};
|
|
8
dist/protocol/src/Transport.d.ts
vendored
8
dist/protocol/src/Transport.d.ts
vendored
|
@ -1,8 +0,0 @@
|
||||||
export declare abstract class Transport {
|
|
||||||
onopen: () => void;
|
|
||||||
onclose: () => void;
|
|
||||||
ondata: (data: ArrayBuffer) => void;
|
|
||||||
constructor(onopen: () => void, onclose: () => void);
|
|
||||||
abstract send(data: ArrayBuffer): void;
|
|
||||||
abstract close(): void;
|
|
||||||
}
|
|
58
dist/protocol/src/index.d.ts
vendored
58
dist/protocol/src/index.d.ts
vendored
|
@ -1,58 +0,0 @@
|
||||||
export type ObjectValues<T> = T[keyof T];
|
|
||||||
export declare const C2SRequestTypes: {
|
|
||||||
readonly HTTPRequestStart: 0;
|
|
||||||
readonly HTTPRequestChunk: 1;
|
|
||||||
readonly HTTPRequestEnd: 2;
|
|
||||||
readonly WSOpen: 3;
|
|
||||||
readonly WSClose: 4;
|
|
||||||
readonly WSSendText: 5;
|
|
||||||
readonly WSSendBinary: 6;
|
|
||||||
};
|
|
||||||
export type C2SRequestType = ObjectValues<typeof C2SRequestTypes>;
|
|
||||||
export declare const S2CRequestTypes: {
|
|
||||||
readonly HTTPResponseStart: 0;
|
|
||||||
readonly HTTPResponseChunk: 1;
|
|
||||||
readonly HTTPResponseEnd: 2;
|
|
||||||
readonly WSOpen: 3;
|
|
||||||
readonly WSClose: 4;
|
|
||||||
readonly WSTextStart: 5;
|
|
||||||
readonly WSBinaryStart: 6;
|
|
||||||
readonly WSDataChunk: 7;
|
|
||||||
readonly WSDataEnd: 8;
|
|
||||||
readonly WSError: 9;
|
|
||||||
};
|
|
||||||
export type S2CRequestType = ObjectValues<typeof S2CRequestTypes>;
|
|
||||||
export type ProtoBareHeaders = Record<string, string | string[]>;
|
|
||||||
export type HTTPRequestPayload = {
|
|
||||||
method: string;
|
|
||||||
requestHeaders: ProtoBareHeaders;
|
|
||||||
remote: URL;
|
|
||||||
hasBody: boolean;
|
|
||||||
};
|
|
||||||
export type HTTPResponsePayload = {
|
|
||||||
status: number;
|
|
||||||
statusText: string;
|
|
||||||
headers: ProtoBareHeaders;
|
|
||||||
};
|
|
||||||
export type C2SWSOpenPayload = {
|
|
||||||
url: string;
|
|
||||||
protocols: string | string[];
|
|
||||||
host: string;
|
|
||||||
};
|
|
||||||
export type S2CWSOpenPayload = {
|
|
||||||
protocol: string;
|
|
||||||
};
|
|
||||||
export type WSClosePayload = {
|
|
||||||
code: number;
|
|
||||||
reason: string;
|
|
||||||
wasClean: boolean;
|
|
||||||
};
|
|
||||||
export type WSErrorPayload = {
|
|
||||||
message: string;
|
|
||||||
};
|
|
||||||
export declare const MAX_CHUNK_SIZE: number;
|
|
||||||
export declare const S2C_HELLO_OK = ":3";
|
|
||||||
export declare const C2S_HELLO = "haiii ";
|
|
||||||
export declare const S2C_HELLO_ERR = ":< ";
|
|
||||||
export declare const PROTOCOL_VERSION = "3.0";
|
|
||||||
export { Transport } from "./Transport";
|
|
54
dist/tracker-list.cjs
vendored
54
dist/tracker-list.cjs
vendored
|
@ -1,54 +0,0 @@
|
||||||
var __defProp = Object.defineProperty;
|
|
||||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
||||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
||||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
||||||
var __export = (target, all) => {
|
|
||||||
for (var name in all)
|
|
||||||
__defProp(target, name, { get: all[name], enumerable: true });
|
|
||||||
};
|
|
||||||
var __copyProps = (to, from, except, desc) => {
|
|
||||||
if (from && typeof from === "object" || typeof from === "function") {
|
|
||||||
for (let key of __getOwnPropNames(from))
|
|
||||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
||||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
||||||
}
|
|
||||||
return to;
|
|
||||||
};
|
|
||||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
||||||
|
|
||||||
// tracker-list/src/index.ts
|
|
||||||
var src_exports = {};
|
|
||||||
__export(src_exports, {
|
|
||||||
default: () => src_default
|
|
||||||
});
|
|
||||||
module.exports = __toCommonJS(src_exports);
|
|
||||||
var trackers = {
|
|
||||||
"us-central-1": {
|
|
||||||
firebase: {
|
|
||||||
apiKey: "AIzaSyCs1LOqsbrAjymIcjvbKxPhFQWXlSPiLTs",
|
|
||||||
authDomain: "adrift-6c1f6.firebaseapp.com",
|
|
||||||
projectId: "adrift-6c1f6",
|
|
||||||
storageBucket: "adrift-6c1f6.appspot.com",
|
|
||||||
messagingSenderId: "175846512414",
|
|
||||||
appId: "1:175846512414:web:5c6e06d231ab58e9029b0f",
|
|
||||||
measurementId: "G-L0P2EF6Q72"
|
|
||||||
},
|
|
||||||
tracker: "wss://lb1.mercurywork.shop",
|
|
||||||
description: "the official central tracker"
|
|
||||||
},
|
|
||||||
"rafftracker": {
|
|
||||||
firebase: {
|
|
||||||
apiKey: "AIzaSyDkcda0r-gdiJoTQ7EbOL9q7-NBQwiKlPg",
|
|
||||||
authDomain: "rafftracker.firebaseapp.com",
|
|
||||||
databaseURL: "https://rafftracker-default-rtdb.firebaseio.com",
|
|
||||||
projectId: "rafftracker",
|
|
||||||
storageBucket: "rafftracker.appspot.com",
|
|
||||||
messagingSenderId: "994948039014",
|
|
||||||
appId: "1:994948039014:web:f96970aa4f626e969dc8a7",
|
|
||||||
measurementId: "G-PD96ZKX31D"
|
|
||||||
},
|
|
||||||
tracker: "wss://rafftracker.mercurywork.shop",
|
|
||||||
description: "a second official backup tracker"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var src_default = trackers;
|
|
34
dist/tracker-list.mjs
vendored
34
dist/tracker-list.mjs
vendored
|
@ -1,34 +0,0 @@
|
||||||
// tracker-list/src/index.ts
|
|
||||||
var trackers = {
|
|
||||||
"us-central-1": {
|
|
||||||
firebase: {
|
|
||||||
apiKey: "AIzaSyCs1LOqsbrAjymIcjvbKxPhFQWXlSPiLTs",
|
|
||||||
authDomain: "adrift-6c1f6.firebaseapp.com",
|
|
||||||
projectId: "adrift-6c1f6",
|
|
||||||
storageBucket: "adrift-6c1f6.appspot.com",
|
|
||||||
messagingSenderId: "175846512414",
|
|
||||||
appId: "1:175846512414:web:5c6e06d231ab58e9029b0f",
|
|
||||||
measurementId: "G-L0P2EF6Q72"
|
|
||||||
},
|
|
||||||
tracker: "wss://lb1.mercurywork.shop",
|
|
||||||
description: "the official central tracker"
|
|
||||||
},
|
|
||||||
"rafftracker": {
|
|
||||||
firebase: {
|
|
||||||
apiKey: "AIzaSyDkcda0r-gdiJoTQ7EbOL9q7-NBQwiKlPg",
|
|
||||||
authDomain: "rafftracker.firebaseapp.com",
|
|
||||||
databaseURL: "https://rafftracker-default-rtdb.firebaseio.com",
|
|
||||||
projectId: "rafftracker",
|
|
||||||
storageBucket: "rafftracker.appspot.com",
|
|
||||||
messagingSenderId: "994948039014",
|
|
||||||
appId: "1:994948039014:web:f96970aa4f626e969dc8a7",
|
|
||||||
measurementId: "G-PD96ZKX31D"
|
|
||||||
},
|
|
||||||
tracker: "wss://rafftracker.mercurywork.shop",
|
|
||||||
description: "a second official backup tracker"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var src_default = trackers;
|
|
||||||
export {
|
|
||||||
src_default as default
|
|
||||||
};
|
|
|
@ -4,6 +4,8 @@ const { build } = require("esbuild");
|
||||||
let makeAllPackagesExternalPlugin = {
|
let makeAllPackagesExternalPlugin = {
|
||||||
name: 'make-all-packages-external',
|
name: 'make-all-packages-external',
|
||||||
setup(build) {
|
setup(build) {
|
||||||
|
|
||||||
|
build.onResolve({ filter: /protocol/ }, args => ({ external: false }))
|
||||||
let filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/ // Must not start with "/" or "./" or "../"
|
let filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/ // Must not start with "/" or "./" or "../"
|
||||||
build.onResolve({ filter }, args => ({ path: args.path, external: true }))
|
build.onResolve({ filter }, args => ({ path: args.path, external: true }))
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue