Skip to content

Commit

Permalink
📝 Document sendEvent and broadcast methods in bun API
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmoMyzrailGorynych committed Dec 23, 2024
1 parent c3a8637 commit 9b445f4
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion docs/bun-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,62 @@ await buntralino.create('/secondary.html', {
width: 400,
height: 300
});
```
```

### sendEvent(target: string, event: string, payload?: unknown): void

Sends an event to a specific named Neutralino window. This method allows you to communicate with a specific window instance by sending an event along with optional data.

Parameters:
- **target**: `string`
- The name of the window to which the event should be sent.
- **event**: `string`
- The name of the event to be sent.
- **payload**: `unknown` (optional)
- An optional data object that will be sent along with the event. This can be any JSON-serializable value.

Example:
```typescript
import * as buntralino from 'buntralino';

// Send an event to a specific Neutralino window
buntralino.sendEvent('main', 'loginSuccessful', {
username: 'Doofus3000'
});
```
Client side code:
```typescript
// Listen to events through Neutralino API:
Neutralino.events.on('loginSuccessful', e => {
const {username} = e.detail;
console.log(`Logged in as ${username}!`);
});
```

### broadcast(event: string, payload?: unknown): void

Sends an event to all currently connected Neutralino windows. This method is useful for broadcasting messages or notifications to multiple windows at once.

Parameters:
- **event**: `string`
- The name of the event to be broadcasted.
- **payload**: `unknown` (optional)
- An optional data object that will be sent along with the event. This can be any JSON-serializable value.

Example:
```typescript
import * as buntralino from 'buntralino';

// Broadcast an event to all Neutralino windows
await buntralino.broadcast('newUpdate', {
version: '1.4.2'
});
```
Client side code:
```typescript
// Listen to events through Neutralino API:
Neutralino.events.on('newUpdate', e => {
const {version} = e.detail;
console.log(`New version ${version} has been released!`);
});
```

0 comments on commit 9b445f4

Please sign in to comment.