https://github.com/shiukaheng/webtopics
⚡️WebTopics — Real-time topics and services for web apps
https://github.com/shiukaheng/webtopics
real-time ros2 socket-io synchronization visualization websocket zod
Last synced: 2 months ago
JSON representation
⚡️WebTopics — Real-time topics and services for web apps
- Host: GitHub
- URL: https://github.com/shiukaheng/webtopics
- Owner: shiukaheng
- Created: 2023-02-04T01:23:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-28T21:45:21.000Z (about 3 years ago)
- Last Synced: 2025-06-28T21:08:04.002Z (12 months ago)
- Topics: real-time, ros2, socket-io, synchronization, visualization, websocket, zod
- Language: TypeScript
- Homepage:
- Size: 527 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ⚡️ WebTopics
Typed pub / sub, request / responses for web apps using Socket.io and Zod, inspired by ROS.
[[ Documentation ]](https://shiukaheng.github.io/WebTopics/)
## Features
### Typed and validated topics and services via Zod
```typescript
const SensorTopic = createTopic("sensor", z.object({
"temperature": z.number(),
"humidity": z.number()
}))
client.pub(SensorTopic, {temperature: 20, humidity: "50%"}) // Error: Expected number, received string
```
### Collaborative topics
```typescript
client1.pub(channel, {a: "1"})
client2.pub(channel, {b: "2"}) // New state merged on old by default
client3.sub(channel, (value) => {
console.log(value) // {a: "1", b: "2"}
})
client2.pub(channel, {b: "2"}, true) // Or publishing as an overwrite
// client 3 receives: {b: "2"}
```
### Async service calls
```typescript
const AdditionService = createService("add",
// Request schema
z.object({
"a": z.number(),
"b": z.number()
}),
// Response schema
z.number()
)
...
// Call service
const result = await client.req(AdditionService, someClientID, {a: 1, b: 2}) // Promise
```
### Packagable channels for easy sharing between client and server
```typescript
export const AdditionService = createService("add",
z.object({
"a": z.number(),
"b": z.number()
}),
z.number()
)
export const SensorTopic = createTopic("sensor", z.object({
"temperature": z.number(),
"humidity": z.number()
}))
...
// Client and server can share the same channels from an external package
import {AdditionService, SensorTopic} from "channels"
```