diff --git a/bun.lockb b/bun.lockb index cf27889..960a7e8 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/node_modules/udn-frontend/README.md b/node_modules/udn-frontend/README.md deleted file mode 100644 index ef0a112..0000000 --- a/node_modules/udn-frontend/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# udn-frontend -TypeScript library for [UDN](https://github.com/marlon-erler/universal-decentralized-network) apps - -# Install -`npm install udn-frontend` - -# Usage -```TypeScript -import UDNFrontend from "udn-frontend"; - -// setup -const UDN = new UDNFrontend(); -UDN.onconnect = () => { - console.log("connected!"); -}; -UDN.ondisconnect = () => { - console.log("disconnected!"); -}; -UDN.onmessage = (data) => { - console.log(data); -}; - -// do stuff -UDN.connect("ws://192.168.0.69:1234"); - -UDN.subscribe("my-channel"); -UDN.sendMessage("my-channel", "Hello, world!"); -UDN.unsubscribe("my-channel"); -``` \ No newline at end of file diff --git a/package.json b/package.json index 9c5cda8..7668d66 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "@types/bun": "^1.1.6", "colors": "^1.4.0", "express": "^4.19.2", - "ip": "^2.0.1", - "udn-frontend": "^1.0.1" + "ip": "^2.0.1" } } diff --git a/static/bun.lockb b/static/bun.lockb index 70622ae..6bdac98 100755 Binary files a/static/bun.lockb and b/static/bun.lockb differ diff --git a/node_modules/udn-frontend/LICENSE b/static/node_modules/udn-frontend/LICENSE similarity index 100% rename from node_modules/udn-frontend/LICENSE rename to static/node_modules/udn-frontend/LICENSE diff --git a/static/node_modules/udn-frontend/README.md b/static/node_modules/udn-frontend/README.md new file mode 100644 index 0000000..c4875ac --- /dev/null +++ b/static/node_modules/udn-frontend/README.md @@ -0,0 +1,77 @@ +# udn-frontend + +TypeScript library for [UDN](https://github.com/marlon-erler/universal-decentralized-network) apps + +# Install + +`npm install udn-frontend` + +# Usage + +```TypeScript +import UDNFrontend from "udn-frontend"; + +// setup +const UDN = new UDNFrontend(); +UDN.onconnect = () => { + console.log("connected!"); +}; +UDN.ondisconnect = () => { + console.log("disconnected!"); +}; +UDN.onmessage = (data: Message) => { + console.log(data); +}; + +// do stuff +UDN.connect("ws://192.168.0.69:1234"); + +UDN.subscribe("my-channel"); +UDN.sendMessage("my-channel", "Hello, world!"); +UDN.unsubscribe("my-channel"); +``` + +# Type Reference + +```TypeScript +export interface Message { + // subscribing to channel + subscribeChannel?: string; + unsubscribeChannel?: string; + subscribed?: boolean; // sent by the server to confirm subscription + + //sending message + messageChannel?: string; + messageBody?: string; +} + +export default class UDNFrontend { + private ws: WebSocket | undefined; + + // handlers + private connectionHandler = () => {}; + private disconnectionHandler = () => {}; + private messageHandler = (data: Message) => {}; + + // init + set onconnect(handler: () => void); + set ondisconnect(handler: () => void); + set onmessage(handler: (data: Message) => void); + + // methods + connect(address: string): void; + sendMessage(channel: string, body: string): boolean; // true if message is sent + subscribe(channel: string): boolean; // true if request is sent, NOT inherently when subscribed + unsubscribe(channel: string): boolean; // true if request is sent, NOT inherently when unsubscribed +} +``` + +# Changelog + +## 1.0.1 + +- minor fixes + +## 1.0.2 + +- minor fixes diff --git a/node_modules/udn-frontend/index.ts b/static/node_modules/udn-frontend/index.ts similarity index 96% rename from node_modules/udn-frontend/index.ts rename to static/node_modules/udn-frontend/index.ts index 3b38e43..dd5bce3 100644 --- a/node_modules/udn-frontend/index.ts +++ b/static/node_modules/udn-frontend/index.ts @@ -2,6 +2,7 @@ export interface Message { // subscribing to channel subscribeChannel?: string; unsubscribeChannel?: string; + subscribed?: boolean; // sent by the server to confirm subscription //sending message messageChannel?: string; diff --git a/node_modules/udn-frontend/package.json b/static/node_modules/udn-frontend/package.json similarity index 95% rename from node_modules/udn-frontend/package.json rename to static/node_modules/udn-frontend/package.json index 81566fb..54e8b86 100644 --- a/node_modules/udn-frontend/package.json +++ b/static/node_modules/udn-frontend/package.json @@ -1,6 +1,6 @@ { "name": "udn-frontend", - "version": "1.0.1", + "version": "1.0.2", "description": "TypeScript library for UDN apps", "main": "index.ts", "scripts": { diff --git a/static/package.json b/static/package.json index 845797b..2c9591b 100644 --- a/static/package.json +++ b/static/package.json @@ -1,7 +1,8 @@ { "dependencies": { "bloatless-react": "^1.2.4", - "esbuild": "latest" + "esbuild": "latest", + "udn-frontend": "^1.0.2" }, "scripts": { "build": "esbuild src/index.tsx --bundle --outdir=dist"