All Projects → 3mcd → web-udp

3mcd / web-udp

Licence: other
Establish client/server and P2P UDP-like channels in the browser

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to web-udp

Kcp
⚡ KCP - A Fast and Reliable ARQ Protocol
Stars: ✭ 10,473 (+24255.81%)
Mutual labels:  udp, rtc
packetdrill
packetdrill with UDPLite and SCTP support and bug fixes for FreeBSD
Stars: ✭ 37 (-13.95%)
Mutual labels:  udp, sctp
asyncio-socks-server
A SOCKS proxy server implemented with the powerful python cooperative concurrency framework asyncio.
Stars: ✭ 154 (+258.14%)
Mutual labels:  udp
sctp
SCTP library for the Go programming language
Stars: ✭ 98 (+127.91%)
Mutual labels:  sctp
Socketify
Raw TCP and UDP Sockets API on Desktop Browsers
Stars: ✭ 67 (+55.81%)
Mutual labels:  udp
doq-proxy
DNS-over-QUIC to UDP Proxy
Stars: ✭ 57 (+32.56%)
Mutual labels:  udp
anyHouse
高仿 ClubHouse,语音直播、语聊房、高音质、极速上麦,开源 ClubHouse,实现了Clubhouse的上麦,下麦,邀请,语音音量提示等功能。
Stars: ✭ 177 (+311.63%)
Mutual labels:  rtc
udp2raw
A Tunnel which Turns UDP Traffic into Encrypted UDP/FakeTCP/ICMP Traffic by using Raw Socket,helps you Bypass UDP FireWalls(or Unstable UDP Environment)
Stars: ✭ 5,256 (+12123.26%)
Mutual labels:  udp
dpdk
A comprehensive rust binding for DPDK allowing high speed userspace networking across 256 cores and 32 NICs
Stars: ✭ 30 (-30.23%)
Mutual labels:  udp
twjitm-core
采用Netty信息加载实现长连接实时通讯系统,客户端可以值任何场景,支持实时http通讯、webSocket通讯、tcp协议通讯、和udp协议通讯、广播协议等 通过http协议,rpc协议。 采用自定义网络数据包结构, 实现自定义网络栈。
Stars: ✭ 98 (+127.91%)
Mutual labels:  udp
freeswitch-docker
Dockerfile for freeswitch
Stars: ✭ 40 (-6.98%)
Mutual labels:  rtc
ComputerNetworks-unipd2018
Tips and resources to easily pass the "Computer Networks" practical exam ("Reti di calcolatori") in Padua
Stars: ✭ 21 (-51.16%)
Mutual labels:  udp
libdvbtee
dvbtee: a digital television streamer / parser / service information aggregator supporting various interfaces including telnet CLI & http control
Stars: ✭ 65 (+51.16%)
Mutual labels:  udp
DatagramTunneler
Simple C++ cross-platform client/server app forwarding UDP datagrams through a TCP connection.
Stars: ✭ 116 (+169.77%)
Mutual labels:  udp
quickstart-calls-directcall-ios
iOS sample for Direct Call of Sendbird Calls, guiding you to build a real-time voice and video calls quickly and easily.
Stars: ✭ 13 (-69.77%)
Mutual labels:  rtc
netty-raknet
A reliable and high performance RakNet library designed with strict Netty patterns.
Stars: ✭ 24 (-44.19%)
Mutual labels:  udp
kcp-conn
No description or website provided.
Stars: ✭ 24 (-44.19%)
Mutual labels:  udp
MCP7940
Arduino Library to access the MCP7940M, MCP7940N and MCP7940x Real-Time chips
Stars: ✭ 29 (-32.56%)
Mutual labels:  rtc
Magician
Magician is a small HTTP service package based on Netty that makes it very easy to start an http service, and also supports WebSocket, using annotated configuration Handler, If you want to develop an http service with netty but find it cumbersome, then Magician may help you.
Stars: ✭ 97 (+125.58%)
Mutual labels:  udp
otrchat
😈 An end-to-end encrypted chat system based on the OTR protocol
Stars: ✭ 18 (-58.14%)
Mutual labels:  udp

web-udp

web-udp is a library used to establish unreliable data channels in Node/browser environments. The key goal of this project to provide a small, stable API that anyone can use to work with real-time data on the web.

The library is currently implemented as an abstraction on top of unordered and unreliable RTCDataChannels. Since WebRTC is a dependency, a WebSocket based signaling server is included with the package to facilitate connections between clients. Client/server connections are available with the help of the wrtc package.

API

Signal<T>.subscribe(subscriber: T => any)
Signal<T>.unsubscribe(subscriber: T => any)

Client(options?: { url?: string })
Client.connect(to?: string = "__MASTER__", options?: {
  binaryType?: "arraybuffer" | "blob",
  maxRetransmits?: number,
  maxPacketLifeTime?: number,
  metadata?: any,
  UNSAFE_ordered?: boolean
}): Promise<Connection>
Client.route(): Promise<string>
Client.connections: Signal<Connection>

Connection.send(message: any): void
Connection.close(): void
Connection.closed: Signal
Connection.errors: Signal<{ err: string }>
Connection.messages: Signal<any>
Connection.metadata: any

// Node
Server({ server: http.Server, keepAlivePeriod?: number = 30000 })
Server.client(): Client
Server.connections: Signal<Connection>

Installation

npm i @web-udp/client
npm i @web-udp/server

Examples

Client/Server

Below is a simple example of a ping server:

// client.js

import { Client } from "@web-udp/client"

async function main() {
  const udp = new Client()
  const connection = await udp.connect()

  connection.send("ping")
  connection.messages.subscribe(console.log)
}
// server.js

const server = require("http").createServer()
const { Server } = require("@web-udp/server")

const udp = new Server({ server })

udp.connections.subscribe(connection => {
  connection.messages.subscribe(message => {
    if (message === "ping") {
      connection.send("pong")
    }
  })

  connection.closed.subscribe(() => console.log("A connection closed."))

  connection.errors.subscribe(err => console.log(err))
})

server.listen(8000)

Metadata

The metadata option in Client.connect is used to send arbitrary handshake data immediately after establishing a connection. When a new connection is opened, the remote client can access this data on the metadata property of the connection object without having to subscribe to the remote client's messages. This data is sent over a secure RTCDataChannel, making it a good candidate for sensitive data like passwords.

In the below example, a server can handle authentication before subscribing to the client's messages:

// client.js

const connection = await udp.connect({
  metadata: {
    credentials: {
      username: "foo",
      password: "bar",
    },
  },
})
// server.js

udp.connections.subscribe(connection => {
  let user

  try {
    user = await fakeAuth.login(connection.metadata.credentials)
  } catch (err) {
    // Authentication failed, close connection immediately.
    connection.send(fakeProtocol.loginFailure())
    connection.close()
    return
  }
  // The user authenticated successfully.
  connection.send(fakeProtocol.loginSuccess(user))
  connection.messages.subscribe(...)
})

P2P

Of course this library also supports peer-to-peer communication. The below example demonstrates two clients connected to eachother in the same browser tab. The example could be easily adapted to two machines, but the users' identities would have to be exchanged at the application level since web-udp doesn't doesn't provide rooms or peer brokering out of the box.

<!-- index.html -->

<script src="/node_modules/@web-udp/client/dist/index.js"></script>
<script src="client.js"></script>
// client.js

async function main() {
  const left = new Udp.Client()
  const right = new Udp.Client()
  const route = await left.route()
  const connection = await right.connect(route)

  left.connections.subscribe(connection =>
    connection.messages.subscribe(console.log),
  )

  connection.send("HELLO")
}
// server.js

const server = require("http").createServer()
const { Server } = require("@web-udp/server")

Server({ server })

server.listen(8000)

Reliability

Client.connect optionally takes the RTCDataChannel maxPacketLifeTime and maxRetransmits options. These options can be used to enable an unordered and reliable data channel.

Known Issues

WebSockets are used as the signaling transport via the ws package. Due to a current issue in the wrtc library, this socket is kept open after the DataChannel is established to forward it's close event (e.g. when a browser tab is closed) in order to terminate hanging UDP connections. A keepalive signal is sent periodically to keep the socket open in the case of hosts with connection timeouts. The period at which the keepalive signal is sent can be configured via the server's keepAlivePeriod option.

License

Copyright 2018 Eric McDaniel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].