2023-02-11 17:32:45 +00:00
|
|
|
# fedwave-chat-client
|
2023-02-11 17:35:12 +00:00
|
|
|
Basic API client for [fedwave] chat. Provides minimal functionality.
|
2023-02-11 17:32:45 +00:00
|
|
|
|
2023-02-11 17:35:12 +00:00
|
|
|
Install with:
|
|
|
|
```bash
|
|
|
|
npm install fedwave-chat-client
|
|
|
|
```
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```js
|
|
|
|
import { FedwaveChat } from 'fedwave-chat-client';
|
|
|
|
|
|
|
|
const fedwaveChat = new FedwaveChat();
|
|
|
|
|
|
|
|
/* NOTE: These are the default implementations */
|
|
|
|
|
|
|
|
// 'ms' is an array of message objects delivered by the server
|
|
|
|
fedwaveChat.rcvMessageBulk = ms => {
|
|
|
|
for( const m of ms ) {
|
|
|
|
console.log( m.message );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Global chat setting
|
|
|
|
fedwaveChat.global = true;
|
|
|
|
|
|
|
|
// Connects to chat, to the specified room, with the token
|
|
|
|
// Note: the token cannot be changed after init()
|
|
|
|
fedwaveChat.connect( 'myroom', 'chat-token', 'fedwavechatserverurl' );
|
|
|
|
|
|
|
|
fedwaveChat.sendMessage( 'Hello, world!' );
|
|
|
|
fedwaveChat.room = 'global';
|
|
|
|
fedwaveChat.sendMessage( 'Hi, global' );
|
|
|
|
|
|
|
|
fedwaveChat.sendMessage({
|
|
|
|
message: 'Hello, all',
|
|
|
|
channel: 'markpugner',
|
|
|
|
global: false,
|
|
|
|
showBadge: true
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
The API is unstable because Fedwave itself is unstable. `src/api.ts` is entirely
|
|
|
|
JSDoc annotated, so go there for documentation.
|