udn-frontend
v1.0.8
Published
TypeScript library for UDN apps
Downloads
66
Readme
udn-frontend
TypeScript library for UDN apps
Install
npm install udn-frontend
Usage
import UDNFrontend from "udn-frontend";
// setup
const UDN = new UDNFrontend();
// connect
UDN.onconnect = () => {
console.log("connected!");
};
UDN.ondisconnect = () => {
console.log("disconnected!");
};
UDN.connect("ws://192.168.0.69:1234");
UDN.disconnect();
// messages
UDN.onmessage = (data: Message) => {
console.log(data);
};
UDN.sendMessage("my-channel", "Hello, world!");
// subscribe
UDN.subscribe("my-channel");
UDN.unsubscribe("my-channel");
// mailbox
UDN.onmailboxcreate = (mailboxId: string) => {
UDN.connectMailbox(mailboxId);
}
UDN.onmailboxconnect = (mailboxId: string) => {
UDN.deleteMailbox(mailboxId);
}
UDN.onmailboxdelete = (mailboxId: string) => {
console.log("mailbox deleted");
}
UDN.requestMailbox();
Changelog
1.0.5
- add mailbox support
1.0.6
- add error handling with
connect()
- 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