5
0
Fork 0
Beep backend handling WebRTC Selective Forwarding Units
 
 
Go to file
Daniel Lim 930bdabb55 Fix #8 assign to nil map 2019-08-31 11:20:28 +08:00
backend-protobuf@10e363e61b fix: Hardcode ICE servers 2019-07-27 16:37:23 +08:00
.env Check backend-permissions to join conversations. Fixes #2 2019-07-03 09:04:15 +08:00
.gitignore Initial logic 2019-06-24 13:05:36 +08:00
.gitmodules Dispatch Bite and Store to NATs. Fixes #4 2019-06-27 06:55:46 +08:00
Dockerfile HELP ME 2019-07-27 18:42:25 +08:00
README.md Check backend-permissions to join conversations. Fixes #2 2019-07-03 09:04:15 +08:00
go.mod Dispatch Bite and Store to NATs. Fixes #4 2019-06-27 06:55:46 +08:00
go.sum Dispatch Bite and Store to NATs. Fixes #4 2019-06-27 06:55:46 +08:00
main.go Fix #8 assign to nil map 2019-08-31 11:20:28 +08:00

README.md

backend-webrtc

Beep backend handling WebRTC Selective Forwarding Units (SFUs). Pushes bites (chunks of audio) to NATS. Checks backend-permissions for user's permission to join the conversation.

The security of this service is handled by backend-auth called by traefik.

Environment variables

Supply environment variables by either exporting them or editing .env.

ENV Description Default
LISTEN Host and port to listen on :80
NATS Host and port of NATs nats://localhost:4222
PERMISSIONS_HOST URL of backend-permissions http://permissions

API

All endpoints require a populated X-User-Claim header from backend-auth.

Contents
New Connection
Join Conversation

New Connection

GET /connect

Creates a new WebRTC peer connection with the server. Connection gets upgraded to a websocket through which signalling occurs before it is closed once the peer connection is established. Please supply the token via GET querystring since Websockets do not support Auth headers.

Example (Javascript)

const wsuri = `wss:\/\/localhost:80/connect`;

let localSDP = '';
let remoteSDP = '';

const socket = new WebSocket(wsuri);
socket.onmessage = (e) => {
  remoteSDP = e.data;
  try {
    pc.setRemoteDescription(new RTCSessionDescription({ type: 'answer', sdp: remoteSDP });
  } catch(e) {
    console.error(e);
  }
};

const pc = new RTCPeerConnection({
  iceServers: [
    {
      urls: 'stun:stun.l.google.com:19302',
    },
  ],
});
pc.onicecandidate = (e) => {
  if (e.candidate === null) {
    localSDP = pc.localDescription.sdp;
    socket.send(localSDP);
  }
};

navigator.mediaDevices
         .getUserMedia({ audio: true })
         .then((stream) => {
           for (const track of stream.getAudioTracks()) {
             pc.addTrack(track);
           }
           pc.createOffer()
             .then((d) => {
               p.setLocalDescription(d);
             })
             .catch((e) => console.error(e));
         })
         .catch((e) => console.error(e));

pc.ontrack = (event) => {
  // Do stuff with event.streams
};

Errors

Code Description
400 Error parsing X-User-Claims header
500 Error establishing WebRTC connection

Join Conversation

POST /join/:conversationid

Signify a user's intention to join a conversation.

Params

Name Type Description
conversationid String ID of conversation to be joined

Success (200 OK)

Empty body

Errors

Code Description
400 Error parsing X-User-Claims header
401 backend-permissions denied permission to join conversation