Files

74 lines
1.3 KiB
Markdown
Raw Permalink Normal View History

2024-07-08 13:07:15 +02:00
# 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();
2024-07-08 23:34:16 +02:00
// connect
2024-07-08 13:07:15 +02:00
UDN.onconnect = () => {
console.log("connected!");
};
UDN.ondisconnect = () => {
console.log("disconnected!");
};
2024-07-08 23:34:16 +02:00
UDN.connect("ws://192.168.0.69:1234");
UDN.disconnect();
// messages
2024-07-08 13:07:15 +02:00
UDN.onmessage = (data: Message) => {
console.log(data);
};
2024-07-08 23:34:16 +02:00
UDN.sendMessage("my-channel", "Hello, world!");
2024-07-08 13:07:15 +02:00
2024-07-08 23:34:16 +02:00
// subscribe
2024-07-08 13:07:15 +02:00
UDN.subscribe("my-channel");
UDN.unsubscribe("my-channel");
2024-07-08 21:13:56 +02:00
2024-07-08 23:34:16 +02:00
// mailbox
2024-07-09 00:30:57 +02:00
UDN.onmailboxcreate = (mailboxId: string) => {
2024-07-08 23:34:16 +02:00
UDN.connectMailbox(mailboxId);
2024-07-08 13:07:15 +02:00
}
2024-07-08 23:34:16 +02:00
UDN.onmailboxconnect = (mailboxId: string) => {
UDN.deleteMailbox(mailboxId);
2024-07-08 13:07:15 +02:00
}
2024-07-09 00:30:57 +02:00
UDN.onmailboxdelete = (mailboxId: string) => {
console.log("mailbox deleted");
}
2024-07-08 13:07:15 +02:00
2024-07-08 23:34:16 +02:00
UDN.requestMailbox();
```
2024-07-09 00:30:57 +02:00
# Changelog
## 1.0.5
- add mailbox support
## 1.0.6
- add error handling with `connect()`
2026-10-12 20:38:04 +02:00
- add `onmailboxdelete` listener
## 1.0.7
- add `uuid` property to Message
## 1.0.8
- fix bug where messages would be considered sent even if the WebSocket is not ready
## 1.0.9
- send confirmation to server that a message was received, necessary for mailboxes to function safely