move udn-frontend to static
This commit is contained in:
-29
@@ -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");
|
|
||||||
```
|
|
||||||
+1
-2
@@ -19,7 +19,6 @@
|
|||||||
"@types/bun": "^1.1.6",
|
"@types/bun": "^1.1.6",
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"ip": "^2.0.1",
|
"ip": "^2.0.1"
|
||||||
"udn-frontend": "^1.0.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
+77
@@ -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
|
||||||
+1
@@ -2,6 +2,7 @@ export interface Message {
|
|||||||
// subscribing to channel
|
// subscribing to channel
|
||||||
subscribeChannel?: string;
|
subscribeChannel?: string;
|
||||||
unsubscribeChannel?: string;
|
unsubscribeChannel?: string;
|
||||||
|
subscribed?: boolean; // sent by the server to confirm subscription
|
||||||
|
|
||||||
//sending message
|
//sending message
|
||||||
messageChannel?: string;
|
messageChannel?: string;
|
||||||
Generated
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "udn-frontend",
|
"name": "udn-frontend",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"description": "TypeScript library for UDN apps",
|
"description": "TypeScript library for UDN apps",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bloatless-react": "^1.2.4",
|
"bloatless-react": "^1.2.4",
|
||||||
"esbuild": "latest"
|
"esbuild": "latest",
|
||||||
|
"udn-frontend": "^1.0.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "esbuild src/index.tsx --bundle --outdir=dist"
|
"build": "esbuild src/index.tsx --bundle --outdir=dist"
|
||||||
|
|||||||
Reference in New Issue
Block a user