Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
webrtc-signal-http
Advanced tools
Readme
opinionated webrtc signal provider using http
as a protocol :spider_web: :signal_strength:
We needed a simple to use, easy to extend WebRTC signaling server that communicated over regular old HTTP/1.1
for 3dtoolkit - this is it. It's designed to mirror the WebRTC example server at an API level, while allowing developers to consume and extend the base functionality.
Learn about the RESTful API via the OpenAPI doc (raw or hosted) to understand how clients should interact with the service.
To install the server cli npm install -g webrtc-signal-http
. To run it, just use webrtc-signal-http
from the command line, using the PORT
environment variable to configure it's listening port.
To consume this server as a basis but add some extended functionality, npm install webrtc-signal-http
and then run some code like the following:
const express = require('express')
const signalRouterCreator = require('webrtc-signal-http')
const app = express()
const router = signalRouterCreator({
enableLogging: true
})
app.use(router)
app.get('/new-endpoint', (req, res) => { res.send('hello') })
app.listen(process.env.PORT || 3000)
For example clients, see the following:
Takes
peer_name
query parameter
Indicates a peer is available to peer with. The response will contain the unique peer_id assigned to the caller in the Pragma
header, and a csv
formatted list of peers in the body
.
GET http://localhost:3000/sign_in?peer_name=test HTTP/1.1
Host: localhost:3000
=>
HTTP/1.1 200 OK
Pragma: 1
Content-Type: text/plain; charset=utf-8
Content-Length: 8
test,1,1
Takes
peer_id
query parameter
Indicates a peer is no longer available to peer with. It is expected this method be called when a peer is no longer intending to use signaling. The response will be empty.
GET http://localhost:3000/sign_out?peer_id=1 HTTP/1.1
Host: localhost:3000
=>
HTTP/1.1 200 OK
Content-Length: 0
Takes
peer_id
(indicating the caller id) andto
(indicating whom we're sending to)
Provides a messaging mechanism for one peer to send data to another. There are no requirements around the type of data that can be sent. The message may be buffered until the receiving peer connects to the service. The response will be empty.
POST http://localhost:3000/message?peer_id=2&to=3 HTTP/1.1
Host: localhost:3000
Content-Type: text/plain
Content-Length: 12
test content
=>
HTTP/1.1 200 OK
Content-Length: 0
Takes
peer_id
query parameter
Provides a mechanism for simulated server push, using vanilla http long polling. That is, the TCP socket behind this request will remain open to the server until there is content the server needs to send. In the event of a TCP timeout the client should reconnect. Messages that contain a Pragma
value that matches the client peer_id
are peer status updates and should be handled the same as the status update provided in the GET /sign_in
response. Content-Type
headers will not reflect the type of the original content.
Peer status update:
GET http://localhost:3000/wait?peer_id=2 HTTP/1.1
Host: localhost:3000
=>
HTTP/1.1 200 OK
Pragma: 2
Content-Type: text/html; charset=utf-8
Content-Length: 18
test2,3,1
test,2,0
Peer message:
GET http://localhost:3000/wait?peer_id=2 HTTP/1.1
Host: localhost:3000
=>
HTTP/1.1 200 OK
Pragma: 3
Content-Type: text/html; charset=utf-8
Content-Length: 12
test content
For example extensions, see the following:
This is the exported behavior, you access it with
require('webrtc-signal-http)
[Function] - takes a SignalOpts indicating if the bunyan logger should be enabled. Returns an express router
object.
[Object] - can be used to retrieve a PeerList
from the express router
. Returns a PeerList object.
[Class] - Represents a collection of WebRTC peers on which signaling operations are possible.
[Function] - takes name
(a string), and res
(a http.Response object). Creates a representation of the peer for signaling. Returns a Number
that shall be used as a unique id for the peer.
[Function] - takes id
(a Number). Removes the representation of the peer from signaling. Returns nothing.
[Function] - takes id
(a Number). Retrieves the representation of the peer from signaling. Returns a Peer object.
[Function] - takes nothing. Retrieves all the peer id's in the PeerList. Returns an [Array] of id's (Numbers).
[Function] - takes id
(a Number), and res
(a http.Response object). Updates a representation of the peer with a new response object for signaling. Returns nothing.
[Function] - takes srcId
(a Number), destId
(a Number), data
(an Object). Pushs arbitrary data onto a stack for a particular destination peer. Returns nothing.
[Function] - takes id
(a Number). Retrives arbitrary data from the stack for the particular peer. Returns a PeerData object.
[Function] - takes nothing. Formats a csv (without headers) list of the peers in the format of peerName, peerId, peerConnectionStatusAsInt
. It's worth noting that peerConnectionStatusAsInt
is a 0
or 1
literal that represents if the peer is currently connected to the server. Returns a string
.
[Object] - Represents arbitrary data to be sent to a peer on behalf of another peer.
[Number] - the peer id that sent the data (as defined when pushPeerData
was called).
[Object] - the peer data to be sent (as defined when pushPeerData
was called).
[Object] - Represents a peer for signaling. Contains both interally used data properties as well as externally exposed data properties.
[String] - the name of the peer.
[Number] - the unique id of the peer.
[Array] - an internally used stack that stores arbitrary data (see pushPeerData
and popPeerData
).
[http.Response] - the response object of the peer. Used to send 'push' data to a hanging socket.
[Function] - takes nothing. Determines if the peer's res
is able to be written to. Returns a bool
.
[Object] - represents the options that can be given to the signal creator
[Bool] - enables logging (default true
)
[Bool] - enables Cross Origin Resource Sharing (default true
)
PeerList - uses a given peerList implementation instead of creating one
MIT
FAQs
opinionated webrtc signal provider using http as a protocol
The npm package webrtc-signal-http receives a total of 1 weekly downloads. As such, webrtc-signal-http popularity was classified as not popular.
We found that webrtc-signal-http demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.