0.0.0 โ€ข Published 17 days ago

sparrow-rtc v0.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
17 days ago

๐Ÿฆ sparrow-rtc

webrtc signalling server, and connections library

๐Ÿ“ฆ npm install sparrow-rtc

๐Ÿš€ live demo: https://sparrow-demo.benevolent.games/
๐Ÿ“ก easily establish webrtc connections and transmit data
๐Ÿ•น๏ธ provides multiplayer game connectivity for https://benevolent.games/
๐Ÿ› ๏ธ we run the signalling server free at wss://sparrow-rtc.benevolent.games/
๐Ÿงช early alpha software, expect changes
๐Ÿ’– free and open source just for you

start a webrtc session as a host

import {createSessionAsHost, standardRtcConfig} from "sparrow-rtc"

const hostConnection = await createSessionAsHost({
  label: "my game session",
  signalServerUrl: "wss://sparrow-rtc.benevolent.games/",
  rtcConfig: standardRtcConfig,

  onStateChange({session}) {
    console.log("session state changed:", session)
  },

  handleJoin({clientId, send, close}) {
    console.log(`client has joined: ${clientId}`)
    send("we can send any string or arraybuffer data!")

    // we can close the connection whenever we want
    setTimeout(close, 10_000)

    return {
      handleMessage(message) {
        console.log("message received!", message)
      },
      handleClose() {
        console.log("client connection closed:", clientId)
      },
    }
  },
})

console.log(`now hosting session:`, hostConnection.state.sessionId)

connect to a webrtc session as a client

import {joinSessionAsClient, standardRtcConfig} from "sparrow-rtc"

const clientConnection = await joinSessionAsClient({
  sessionId: "840ead63", // maybe from an invite link!
  signalServerUrl: "wss://sparrow-rtc.benevolent.games/",
  rtcConfig: standardRtcConfig,

  onStateChange({clientId, session}) {
    console.log("state changed", {clientId, session})
  },

  handleJoin({clientId, send, close}) {
    console.log(`client has joined: ${clientId}`)
    send("we can send any string or arraybuffer data!")

    // we can close the connection whenever we want
    setTimeout(close, 10_000)

    return {
      handleMessage(message) {
        console.log("message received!", message)
      },
      handleClose() {
        console.log("client connection closed:", clientId)
      },
    }
  }
})

console.log(`now connected as client to session:`, clientConnection.state.session)

run your own instance of the signalling server

we are running a free instance of the signalling server at this websocket endpoint:

wss://sparrow-rtc.benevolent.games/

but if you'd like to run your own instance of the signalling server,

you can clone this repo, and then

  • npm install to install dependencies
  • npm run build to build the project
  • npm run start-signal-server 8080 to run the signalling server on port 8080
0.0.0

17 days ago

0.0.0-dev.7

1 month ago

0.0.0-dev.6

2 years ago

0.0.0-dev.5

2 years ago

0.0.0-dev.4

2 years ago

0.0.0-dev.3

2 years ago

0.0.0-dev.2

2 years ago

0.0.0-dev.1

2 years ago

0.0.0-dev.0

2 years ago