mirror of
https://github.com/MercuryWorkshop/adrift.git
synced 2025-05-13 06:10:01 -04:00
more fmt
This commit is contained in:
parent
82a314b54f
commit
85107cbbeb
3 changed files with 87 additions and 96 deletions
|
@ -5,11 +5,10 @@ import expressWs from "express-ws";
|
||||||
import { AdriftServer, connectTracker } from "./server";
|
import { AdriftServer, connectTracker } from "./server";
|
||||||
|
|
||||||
import WebSocket from "isomorphic-ws";
|
import WebSocket from "isomorphic-ws";
|
||||||
import { answerRtc, bufferToArrayBuffer, connect } from "./rtc";
|
import { answerRtc, bufferToArrayBuffer } from "./rtc";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
|
||||||
const app = express() as unknown as expressWs.Application;
|
const app = express() as unknown as expressWs.Application;
|
||||||
expressWs(app);
|
expressWs(app);
|
||||||
|
|
||||||
|
@ -23,9 +22,6 @@ app.use((_req, res, next) => {
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.post("/connect", (req, res) => {
|
app.post("/connect", (req, res) => {
|
||||||
const data = req.body;
|
const data = req.body;
|
||||||
answerRtc(data, (d) => {
|
answerRtc(data, (d) => {
|
||||||
|
@ -51,12 +47,9 @@ app.ws("/dev-ws", (ws, _req) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
let tracker = new WebSocket("ws://localhost:17776/join");
|
let tracker = new WebSocket("ws://localhost:17776/join");
|
||||||
tracker.onerror = console.error;
|
tracker.onerror = console.error;
|
||||||
connectTracker(tracker);
|
connectTracker(tracker);
|
||||||
} catch (_) {
|
} catch (_) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
app.listen(3000, () => console.log("listening"));
|
app.listen(3000, () => console.log("listening"));
|
||||||
|
|
|
@ -76,8 +76,7 @@ export async function answerRtc(data: any, onrespond: (answer: any) => void) {
|
||||||
dataChannel.onopen = () => {
|
dataChannel.onopen = () => {
|
||||||
console.log("opened");
|
console.log("opened");
|
||||||
server = new AdriftServer((msg) => {
|
server = new AdriftServer((msg) => {
|
||||||
if (dataChannel.readyState === "open")
|
if (dataChannel.readyState === "open") dataChannel.send(msg);
|
||||||
dataChannel.send(msg)
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
dataChannel.onclose = () => {
|
dataChannel.onclose = () => {
|
||||||
|
|
|
@ -16,7 +16,6 @@ import { Readable, Writable } from "stream";
|
||||||
import { BareError, bareInitialFetch, fetchResponse, options } from "./http";
|
import { BareError, bareInitialFetch, fetchResponse, options } from "./http";
|
||||||
import { answerRtc } from "./rtc";
|
import { answerRtc } from "./rtc";
|
||||||
|
|
||||||
|
|
||||||
function bareErrorToResponse(e: BareError): {
|
function bareErrorToResponse(e: BareError): {
|
||||||
payload: HTTPResponsePayload;
|
payload: HTTPResponsePayload;
|
||||||
body: AsyncIterable<ArrayBuffer>;
|
body: AsyncIterable<ArrayBuffer>;
|
||||||
|
@ -382,6 +381,6 @@ export function connectTracker(tracker: WebSocket) {
|
||||||
answerRtc(data, (answer) => {
|
answerRtc(data, (answer) => {
|
||||||
console.log("have an answer");
|
console.log("have an answer");
|
||||||
tracker.send(JSON.stringify(answer));
|
tracker.send(JSON.stringify(answer));
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue