https://github.com/openpeeps/libdatachannel-nim
Nim bindings for Libdatachannel ⚡️ A standalone WebRTC Data Channels, WebRTC Media Transport, and WebSockets library
https://github.com/openpeeps/libdatachannel-nim
bindings libdatachannel livestream media messaging nim nim-lang openpeeps webrtc webrtc-video websockets
Last synced: about 1 month ago
JSON representation
Nim bindings for Libdatachannel ⚡️ A standalone WebRTC Data Channels, WebRTC Media Transport, and WebSockets library
- Host: GitHub
- URL: https://github.com/openpeeps/libdatachannel-nim
- Owner: openpeeps
- Created: 2025-03-31T08:03:01.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-13T11:25:01.000Z (9 months ago)
- Last Synced: 2025-09-13T13:47:29.472Z (9 months ago)
- Topics: bindings, libdatachannel, livestream, media, messaging, nim, nim-lang, openpeeps, webrtc, webrtc-video, websockets
- Language: Nim
- Homepage: https://openpeeps.github.io/libdatachannel-nim/
- Size: 89.8 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Nim language 👑 bindings for Libdatachannel
A standalone WebRTC Data Channels, WebRTC Media Transport, and WebSockets
nimble install libdatachannel
## 😍 Key Features
- [x] Lightweight WebRTC Data Channel/Media Transport
- [x] Fast Server/Client WebSockets
- [x] High-level API in Nim style!
- [x] Low-level bindings `libdatachannel`
## Build the library
First, you will need to build [libdatachannel](https://libdatachannel.org/) from [GitHub source](https://github.com/paullouisageneau/libdatachannel). See [Building instructions](https://github.com/paullouisageneau/libdatachannel/blob/master/BUILDING.md)
## Examples
### WebSocket Example
**WebSocket Server**
This is a simple WebSocket server that listens for incoming connections and echoes back any messages it receives.
```nim
from std/os implement sleep
import libdatachannel/websockets
proc connectionCallback(wsserver: cint, ws: cint, userPtr: pointer) {.cdecl.} =
proc wsMessageCallback(ws: cint, msg: cstring, size: cint, userPtr: pointer) =
echo "Message from client ", $msg
ws.message(msg) # echo the message back
discard rtcSetMessageCallback(ws, wsMessageCallback)
# send a welcome message
ws.message("Welcome to WebSocket Server!")
let wss = newWebSocketServer(port = Port(1234))
wss.startServer(connectionCallback)
while true:
sleep(1000)
```
**WebSocket Client**
```nim
from std/os implement sleep
import libdatachannel/websockets
let client = newWebSocketClient("ws://127.0.0.1:1234")
client.listen(onMessage) do(ws: cint, message: cstring, size: cint, userPtr: pointer):
echo $message
sleep(500)
while true:
wsclient.send("Hello from client!")
sleep(1000)
```
### Peer Connection
_todo_
### ❤ Contributions & Support
- 🐛 Found a bug? [Create a new Issue](https://github.com/openpeeps/libdatachannel-nim/issues)
- 👋 Wanna help? [Fork it!](https://github.com/openpeeps/libdatachannel-nim/fork)
- 😎 [Get €20 in cloud credits from Hetzner](https://hetzner.cloud/?ref=Hm0mYGM9NxZ4)
### 🎩 License
MIT license. [Made by Humans from OpenPeeps](https://github.com/openpeeps).
Copyright © 2025 OpenPeeps & Contributors — All rights reserved.