1.2.0 • Published 3 years ago
beakman v1.2.0
beakman
Install
npm i -S beakman
Usage
As client: pick a server and send/receive messages
import { RemoteBroker } from 'beakman'
// Base configuration for WebRtc
const rtcConfiguration = {
iceServers: [
{ urls: "stun:stun.l.google.com:19302" },
{ urls: "stun:global.stun.twilio.com:3478?transport=udp" }
]
}
// Connect to a signaling server
const broker = new RemoteBroker({
// WebRTC peer configurations
rtcConfiguration,
// signaling server url
remoteWs: 'wss://beakman-signaling.menduz.com',
// protocol to identify this app in the shared signaling server
protocol: 'my-app-v1'
})
// Wait for broker to be connected
await broker.connectedFuture;
// Get the server list
const serverListResponse = await broker.requestServerList()
const aServer = serverListResponse.getServersList().first()
// Connect to a server
const clientConnection = await broker.connect(aServer.alias)
// Listening messages FROM server
clientConnection.onDataObservable.add(message => {
console.log(`receive message: ${message} from ${aServer.alias}`)
})
await clientConnection.awaitableConnected;
// Send messages TO server
clientConnection.send('a message');
As server: host a room open for clients
import { RemoteBroker } from 'beakman'
// Connect to a signaling server
const broker = new RemoteBroker({
rtcConfiguration,
remoteWs: 'wss://beakman-signaling.menduz.com',
protocol: 'my-app-v1'
})
// Wait for broker to be connected
await broker.connectedFuture;
// Listen for new connections
await broker.listen({ name: 'server name' }, clientConnection => {
console.log('A client got connected!', clientConnection)
// Listening messages FROM client
clientConnection.onDataObservable.add(message => {
console.log(`receive message: ${message} from ${clientConnection.socketId}`)
})
await client.awaitableConnected;
// Send messages TO client
clientConnection.send('message')
})
Signaling server
There is a naive implementation of the signaling server in the folder beakman-signaling.
Cloning the folder and running npm start
is enough to run the signaling server.
Running in Node.js
Node.js works out of the box as well as the browser. To run with Node it is necessary to provide wrtc
and ws
packages.
import { RemoteBroker } from 'beakman'
const wrtc = require('wrtc')
const ws = require('ws')
// Connect to a signaling server
const broker = new RemoteBroker({
rtcConfiguration,
remoteWs: 'wss://beakman-signaling.menduz.com',
protocol: 'my-app-v1',
wrtc,
ws
})
1.2.1-20210602225142.commit-83a83fd
3 years ago
1.2.1-20210602225151.commit-892440e
3 years ago
1.2.1-20210602225136.commit-90c56fc
3 years ago
1.2.1-20210602225201.commit-7b9a6ad
3 years ago
1.2.0
4 years ago
1.1.3-20200423151801.commit-976d909
4 years ago
1.1.2
5 years ago
1.1.1
5 years ago
1.1.0
5 years ago
1.0.0
5 years ago