mirror of
https://github.com/MercuryWorkshop/adrift.git
synced 2025-05-12 22:00:02 -04:00
add websocket support to AdriftClient
This commit is contained in:
parent
f5e0c4202e
commit
7f5234998b
15 changed files with 552 additions and 36 deletions
|
@ -55,6 +55,7 @@
|
|||
|
||||
let connection = new Connection(transport);
|
||||
let bare = new AdriftBareClient(connection);
|
||||
console.log(setBareClientImplementation);
|
||||
setBareClientImplementation(bare);
|
||||
ready = true;
|
||||
}
|
||||
|
@ -128,9 +129,12 @@
|
|||
|
||||
function visitURL(url: string) {
|
||||
if (!import.meta.env.VITE_ADRIFT_SINGLEFILE) {
|
||||
let path =
|
||||
(dynamic && `/service/route?url=${url}`) ||
|
||||
`${__uv$config.prefix}${__uv$config.encodeUrl(url)}`;
|
||||
let path = dynamic
|
||||
? `/service/route?url=${url}`
|
||||
: `${__uv$config.prefix}${__uv$config.encodeUrl(url)}`;
|
||||
console.log(dynamic);
|
||||
console.log(path);
|
||||
|
||||
proxyIframe.src = path;
|
||||
} else {
|
||||
let bare = new BareClient();
|
||||
|
@ -152,6 +156,36 @@
|
|||
}
|
||||
|
||||
(window as any).bare = new BareClient();
|
||||
|
||||
(window as any).a = (_) => {
|
||||
let socket = bare.createWebSocket();
|
||||
|
||||
socket.onopen = function (e) {
|
||||
alert("[open] Connection established");
|
||||
alert("Sending to server");
|
||||
socket.send("My name is John");
|
||||
};
|
||||
|
||||
socket.onmessage = function (event) {
|
||||
alert(`[message] Data received from server: ${event.data}`);
|
||||
};
|
||||
|
||||
socket.onclose = function (event) {
|
||||
if (event.wasClean) {
|
||||
alert(
|
||||
`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`
|
||||
);
|
||||
} else {
|
||||
// e.g. server process killed or network down
|
||||
// event.code is usually 1006 in this case
|
||||
alert("[close] Connection died");
|
||||
}
|
||||
};
|
||||
|
||||
socket.onerror = function (error) {
|
||||
alert(`[error]`);
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
{#if ready}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue