WebRTC-Server-Client-Datachannel
This library is a first attempt at making the RTCDataChannel a bit easier to implement in a server-client communication model.
Get Started
npm i webrtc-server-client-datachannel --save
Example
A config file that is loaded to both client and server named rtc.config.js perhaps..
moduleexportsrtcConfig = RTCPeerConnectionConf: required: video: false audio: false iceServers: urls: 'stun:stun.l.google.com:19302' optional: DtlsSrtpKeyAgreement: true RtpDataChannels: true //Apparently this may make firefox compatible. datachannels: label: "tcp" config: ordered: true maxRetransmits: 10 binaryType: "blob" label: "udp" config: ordered: false maxRetransmits: 0 binaryType: "blob"
Server side with express
const RTCServer = ;const createServer = ;const Server = ;const express = ; const rtcConfig = ; const app = ;const server = ; server; server ;
Your client can then have code like this to accept and send some strings to the RTCDatachannels:
; ; { try console; const ws = 'ws://' + "localhost" + ':8080'; await ; let pc = ws rtcConfigRTCPeerConnectionConf rtcConfigdatachannels; await pc; pctcp; pcudp; pctcp{ console; }; pcudp{ console; }; ; catch error console; } { return { ws ; ws ; };} ;
Limitations
The RTCPeerConnection is not working the same way in all browsers, and alot of it is experimental technology!
Please reply with compatability issues if you find some.
It is important that the RTCConfiguration is equal, so normally split it into a seperate file and import the same configuration to both client and server. This is due to making the datachannels negotiated beforehand. It seems this was needed for firefox to not destroy the objects after creation.