Skip to content

Commit

Permalink
add custom websocket event page
Browse files Browse the repository at this point in the history
  • Loading branch information
Whipstickgostop committed Nov 5, 2023
1 parent 7fd925c commit 7a8ab3d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
12 changes: 8 additions & 4 deletions streamerbot/3.api/3.csharp/core/servers-clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ description: C# methods for Streamer.bot servers and clients
---

## Websocket Server
```csharp
void WebsocketBroadcastString(string data); // send a custom event over the websocket server
void WebsocketBroadcastJson(string data); // send a custom event over the websocket server, used for browser widgets
```

### `WebsocketBroadcastString`
Send a custom event over the Streamer.bot WebSocket server
:csharp-method{name=WebsocketBroadcastString}

### `WebsocketBroadcastJson`
Send a custom JSON event over the Streamer.bot WebSocket server
:csharp-method{name=WebsocketBroadcastJson}

## Websocket Clients
```csharp
Expand Down
5 changes: 1 addition & 4 deletions streamerbot/3.api/4.servers/1.websocket/1.events/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,4 @@ Event payloads follow the following base schema:
}
}
```
::

## Custom Events
You can utilize [C# Code](/api/csharp/core/servers-clients) to send custom WebSocket events with your own schema.
::
60 changes: 60 additions & 0 deletions streamerbot/3.api/4.servers/1.websocket/1.events/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: Custom
description: Emit custom events from the Streamer.bot WebSocket server
---

## Overview
You can enable `Custom` events with this [Subscribe](/api/servers/websocket/requests#subscribe) request:

```json [Subscribe Request]
{
"request": "Subscribe",
"id": "my-request-id",
"events": {
"General": [
"Custom"
]
},
}
```

## C# Methods
### `WebsocketBroadcastString`
Send a custom string over the Streamer.bot WebSocket server
:csharp-method{name=WebsocketBroadcastString}
::code-group
```cs [Example Request]
CPH.WebsocketBroadcastString("Hello, world!");
```
```json [Example Response]
{
"timeStamp": "2023-01-01-05T00:25:18.2696998+01:00",
"event": {
"source": "General",
"type": "Custom",
"data": "Hello, world!"
}
}
```
::

### `WebsocketBroadcastJson`
Send a custom JSON event over the Streamer.bot WebSocket server
:csharp-method{name=WebsocketBroadcastJson}
::code-group
```ts [Example Request]
CPH.WebsocketBroadcastJson("{'key': 'value'}");
```
```json [Example Response]
{
"timeStamp": "2023-01-01-05T00:25:18.2696998+01:00",
"event": {
"source": "General",
"type": "Custom",
"data": {
"key": "value"
}
}
}
```
::

0 comments on commit 7a8ab3d

Please sign in to comment.