Skip to content

Commit

Permalink
- Add overview graphic
Browse files Browse the repository at this point in the history
- Disable Redis per default locally, option to enable it
- Option to broadcast CRUD post-events to all sockets via `@websocket.broadcast.all` or `@ws.broadcast.all`
- Remove Redis broadcast for kind `ws` on message receiving
  • Loading branch information
oklemenz2 committed Jan 22, 2024
1 parent fad0c16 commit e272ca5
Show file tree
Hide file tree
Showing 12 changed files with 4,525 additions and 119 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Version 0.2.1 - 2024-01-15
## Version 0.3.0 - 2024-01-22

### Added

- Add overview graphic
- Disable Redis per default locally, option to enable it
- Option to broadcast CRUD post-events to all sockets via `@websocket.broadcast.all` or `@ws.broadcast.all`

### Fixed

- Remove Redis broadcast for kind `ws` on message receiving

## Version 0.2.0 - 2024-01-11

Expand Down
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ In browser environment implement the websocket client: **index.html**

## Documentation

### Architecture Overview

![WebSocket Overview](./docs/assets/overview.png)

### WebSocket Server

The websocket server is exposed on `cds` object implementation-independent at `cds.ws` and implementation-specific at
Expand Down Expand Up @@ -154,8 +158,9 @@ are not exposed, as the service itself is not marked as websocket protocol.
### Server Socket

Each CDS handler request context is extended to hold the current server `socket` instance of the event.
It can be accessed via `req.context.socket` or `cds.context.socket`.
Events can be directly emitted via the `socket` bypassing CDS runtime.
It can be accessed via the service websocket facade via `req.context.ws.service` or `cds.context.ws.service`.
In addition the native websocket server socket can be accessed via `req.context.ws.socket` or `cds.context.ws.socket`.
Events can be directly emitted via the native `socket`, bypassing CDS runtime, if necessary.

### Middlewares

Expand Down Expand Up @@ -258,10 +263,22 @@ CRUD events that modify entities automatically emit another event after successf
- `<entity>:delete => <entity>:deleted`: Entity instance has been deleted

Because of security concerns, it can be controlled which data of those events is broadcast,
via annotations `@websocket.broadcast` or `@ws.broadcast`.

- Propagate only key (default): `@websocket.broadcast = 'key'`, `@ws.broadcast = 'key'`
- Propagate complete entity data: `@websocket.broadcast = 'data'`, `@ws.broadcast = 'data'`
via annotations `@websocket.broadcast` or `@ws.broadcast` on entity level.

- Propagate only key via one of the following options (default, if no annotation is present):
- `@websocket.broadcast = 'key'`
- `@websocket.broadcast.content = 'key'`
- `@ws.broadcast = 'key'`
- `@ws.broadcast.content = 'key'`
- Propagate complete entity data via one of the following options:
- `@websocket.broadcast = 'data'`
- `@websocket.broadcast.content = 'data'`
- `@ws.broadcast = 'data'`
- `@ws.broadcast.content = 'data'`

Per default, this event is broadcast to every connected socket, expect the socket, that was called with the CRUD event.
To also include the triggering socket within the broadcast, this can be controlled via annotations
`@websocket.broadcast.all` or `@ws.broadcast.all` on entity level.

### Examples

Expand Down
Loading

0 comments on commit e272ca5

Please sign in to comment.