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