mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 15:00:01 -04:00
bare-mux support
This commit is contained in:
parent
8b2757b495
commit
5a8aa6698e
7 changed files with 36 additions and 16 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
static/scramjet*
|
static/scramjet*
|
||||||
|
static/bare-mux.js
|
||||||
|
static/bare-client.js
|
|
@ -17,10 +17,20 @@ const devServer = createServer({
|
||||||
plugins: [
|
plugins: [
|
||||||
copy({
|
copy({
|
||||||
resolveFrom: "cwd",
|
resolveFrom: "cwd",
|
||||||
assets: {
|
assets: [
|
||||||
|
{
|
||||||
|
from: ['./node_modules/@mercuryworkshop/bare-mux/dist/bare.cjs'],
|
||||||
|
to: ['./static/bare-mux.js'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: ['./node_modules/@mercuryworkshop/bare-as-module3/dist/bare.cjs'],
|
||||||
|
to: ['./static/bare-client.js'],
|
||||||
|
},
|
||||||
|
{
|
||||||
from: ["./dist/*"],
|
from: ["./dist/*"],
|
||||||
to: ["./static"]
|
to: ["./static"]
|
||||||
}
|
},
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
time()
|
time()
|
||||||
]
|
]
|
||||||
|
@ -28,8 +38,8 @@ const devServer = createServer({
|
||||||
static: "./static",
|
static: "./static",
|
||||||
port: 1337,
|
port: 1337,
|
||||||
proxy: (path) => {
|
proxy: (path) => {
|
||||||
if (path.startsWith("/bare")) {
|
if (path.startsWith("/bare/")) {
|
||||||
return path.replace("/bare", "http://127.0.0.1:3000")
|
return path.replace("/bare/", "http://127.0.0.1:3000/")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
injectLiveReload: false
|
injectLiveReload: false
|
||||||
|
|
|
@ -25,7 +25,8 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/static": "^7.0.3",
|
"@fastify/static": "^7.0.3",
|
||||||
"@tomphttp/bare-client": "2.2.0-alpha",
|
"@mercuryworkshop/bare-mux": "^1.1.0",
|
||||||
|
"@mercuryworkshop/bare-as-module3": "^2.2.0-alpha",
|
||||||
"@tomphttp/bare-server-node": "^2.0.3",
|
"@tomphttp/bare-server-node": "^2.0.3",
|
||||||
"concurrently": "^8.2.2",
|
"concurrently": "^8.2.2",
|
||||||
"dom-serializer": "^2.0.0",
|
"dom-serializer": "^2.0.0",
|
||||||
|
|
|
@ -4,7 +4,6 @@ declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
__scramjet$config: {
|
__scramjet$config: {
|
||||||
prefix: string;
|
prefix: string;
|
||||||
bareServer: string;
|
|
||||||
codec: Codec
|
codec: Codec
|
||||||
scramjet: {
|
scramjet: {
|
||||||
config: string;
|
config: string;
|
||||||
|
@ -19,7 +18,6 @@ declare global {
|
||||||
|
|
||||||
self.__scramjet$config = {
|
self.__scramjet$config = {
|
||||||
prefix: "/scramjet/",
|
prefix: "/scramjet/",
|
||||||
bareServer: "/bare/",
|
|
||||||
codec: self.__scramjet$codecs.plain,
|
codec: self.__scramjet$codecs.plain,
|
||||||
scramjet: {
|
scramjet: {
|
||||||
config: "/scramjet.config.js",
|
config: "/scramjet.config.js",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
importScripts("/scramjet.codecs.js");
|
importScripts("/scramjet.codecs.js");
|
||||||
importScripts("/scramjet.config.js");
|
importScripts("/scramjet.config.js");
|
||||||
importScripts("/scramjet.bundle.js");
|
importScripts("/scramjet.bundle.js");
|
||||||
import { BareClient } from "@tomphttp/bare-client";
|
import { BareClient } from "@mercuryworkshop/bare-mux";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
@ -13,7 +13,7 @@ self.ScramjetServiceWorker = class ScramjetServiceWorker {
|
||||||
client: typeof BareClient.prototype;
|
client: typeof BareClient.prototype;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.client = new BareClient(location.origin + self.__scramjet$config.bareServer);
|
this.client = new BareClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetch(event: FetchEvent) {
|
async fetch(event: FetchEvent) {
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
<title>Document</title>
|
<title>Document</title>
|
||||||
<link rel="preload" as="script" href="./scramjet.worker.js">
|
<link rel="preload" as="script" href="./scramjet.worker.js">
|
||||||
<link rel="preload" as="script" href="./scramjet.bundle.js">
|
<link rel="preload" as="script" href="./scramjet.bundle.js">
|
||||||
|
<script src="./bare-mux.js" defer></script>
|
||||||
|
<script src="./bare-client.js" defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script src="https://unpkg.com/dreamland"></script>
|
<script src="https://unpkg.com/dreamland"></script>
|
||||||
|
@ -14,20 +16,26 @@
|
||||||
<script>
|
<script>
|
||||||
function App() {
|
function App() {
|
||||||
return html`
|
return html`
|
||||||
<input placeholder="Enter URL Here" on:keydown=${e => {
|
<input placeholder="Enter URL Here" on:keydown=${async (e) => {
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter") {
|
||||||
const url = __scramjet$config.codec.encode(e.target.value);
|
const url = __scramjet$config.codec.encode(e.target.value);
|
||||||
registerSw();
|
try {
|
||||||
|
await registerSw();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
location = __scramjet$config.prefix + url;
|
location = __scramjet$config.prefix + url;
|
||||||
}
|
}
|
||||||
}} />
|
}} />
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerSw() {
|
async function registerSw() {
|
||||||
navigator.serviceWorker.register("./sw.js", {
|
await navigator.serviceWorker.register("./sw.js", {
|
||||||
scope: __scramjet$config.prefix
|
scope: __scramjet$config.prefix
|
||||||
})
|
})
|
||||||
|
let bareUrl = (location.protocol === "https:" ? "https" : "http") + "://" + location.host + "/bare/";
|
||||||
|
await BareMux.SetTransport("BareMod.BareClient", bareUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body.appendChild(h(App));
|
document.body.appendChild(h(App));
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
importScripts("./scramjet.codecs.js");
|
importScripts("./scramjet.codecs.js");
|
||||||
importScripts("./scramjet.config.js");
|
importScripts("./scramjet.config.js");
|
||||||
importScripts("./scramjet.worker.js");
|
importScripts("./scramjet.worker.js");
|
||||||
|
importScripts("./bare-client.js")
|
||||||
|
|
||||||
const scramjet = new ScramjetServiceWorker();
|
const scramjet = new ScramjetServiceWorker();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue