{"id":13481919,"url":"https://github.com/rtc-io/rtc-switchboard","last_synced_at":"2025-07-25T03:32:18.510Z","repository":{"id":11402127,"uuid":"13849060","full_name":"rtc-io/rtc-switchboard","owner":"rtc-io","description":"Node server side in memory signaller for rtc.io components","archived":false,"fork":false,"pushed_at":"2019-10-29T13:44:38.000Z","size":154,"stargazers_count":57,"open_issues_count":5,"forks_count":36,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-11-08T08:48:28.046Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.rtc.io/modules.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rtc-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-25T01:45:21.000Z","updated_at":"2020-11-19T04:18:57.000Z","dependencies_parsed_at":"2022-09-22T22:51:42.723Z","dependency_job_id":null,"html_url":"https://github.com/rtc-io/rtc-switchboard","commit_stats":null,"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtc-io%2Frtc-switchboard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtc-io%2Frtc-switchboard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtc-io%2Frtc-switchboard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtc-io%2Frtc-switchboard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rtc-io","download_url":"https://codeload.github.com/rtc-io/rtc-switchboard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227515157,"owners_count":17782642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:00:57.441Z","updated_at":"2024-12-01T08:15:15.469Z","avatar_url":"https://github.com/rtc-io.png","language":"JavaScript","funding_links":[],"categories":["Modules"],"sub_categories":[],"readme":"# rtc-switchboard\n\nThis is an rtc.io signalling server (counterpart to\n[rtc-signaller](https://github.com/rtc-io/rtc-signaller)) uses websockets to\ncommunicate with signalling clients. It has been designed and built\nprimarily as a _reference implementation_ for a signalling server and is\nnot designed to be deployed at scale.\n\n\n[![NPM](https://nodei.co/npm/rtc-switchboard.png)](https://nodei.co/npm/rtc-switchboard/)\n\n[![unstable](https://img.shields.io/badge/stability-unstable-yellowgreen.svg)](https://github.com/dominictarr/stability#unstable) [![Build Status](https://api.travis-ci.org/rtc-io/rtc-switchboard.svg?branch=master)](https://travis-ci.org/rtc-io/rtc-switchboard) [![bitHound Score](https://www.bithound.io/github/rtc-io/rtc-switchboard/badges/score.svg)](https://www.bithound.io/github/rtc-io/rtc-switchboard)\n\n## Try it out\n\nIf you would like to use our test signalling server (no uptime guaranteed) then\nyou can use [rtc-quickconnect](https://github.com/rtc-io/rtc-quickconnect)\nand take it for a spin:\n\n```js\nvar quickconnect = require('rtc-quickconnect');\n\nquickconnect('//switchboard.rtc.io/', { room: 'switchboard-test' })\n  .createDataChannel('test')\n  .once('channel:opened:test', function(peerId, dc) {\n    dc.onmessage = function(evt) {\n      console.log('received data: ', evt.data);\n    };\n\n    dc.send('hello');\n  });\n\n```\n\nOther examples are available in the [guidebook](http://guidebook.rtc.io)\n\n## Usage: Standalone\n\nIf you wish to use `rtc-switchboard` on its own to test signalling,\nthen you can simply clone this repository, install dependencies and start\nthe server:\n\n```\ngit clone https://github.com/rtc-io/rtc-switchboard.git\ncd rtc-switchboard\nnpm install \u0026\u0026 npm start\n```\n\nIf you wish to run the server on a specific port, then set the `NODE_PORT`\nenvironment variable prior to execution:\n\n```\nNODE_PORT=8997 node server.js\n```\n\n## Usage: API\n\nTo create an application using switchboard signalling, see the following\nexamples:\n\n### Pure Node HTTP\n\n```js\nvar server = require('http').createServer();\nvar switchboard = require('rtc-switchboard/')(server, { servelib: true });\nvar port = parseInt(process.env.NODE_PORT || process.env.PORT || process.argv[2], 10) || 3000;\nvar replify = require('replify');\n\nserver.on('request', function(req, res) {\n  if (req.url === '/') {\n    res.writeHead(302, {\n      'Location': 'https://github.com/rtc-io/rtc-switchboard'\n    });\n    res.end('switchboard available from: https://github.com/rtc-io/rtc-switchboard');\n  }\n});\n\n// start the server\nserver.listen(port, function(err) {\n  if (err) {\n    return console.log('Encountered error starting server: ', err);\n  }\n\n  console.log('server running at http://localhost:' + port + '/');\n});\n\n// add the repl\nreplify({\n  name: 'switchboard',\n  app: switchboard,\n  contexts: {\n    server: server\n  }\n});\n\nswitchboard.on('room:create', function(room) {\n  console.log('room ' + room + ' created, now have ' + switchboard.rooms.length + ' active rooms');\n});\n\nswitchboard.on('room:destroy', function(room) {\n  console.log('room ' + room + ' destroyed, ' + switchboard.rooms.length + ' active rooms remain');\n\n  if (typeof gc == 'function') {\n    console.log('gc');\n    gc();\n  }\n});\n\n\n```\n\n### Using Express\n\n```js\nvar express = require('express');\nvar app = express();\nvar server = require('http').Server(app);\nvar port = process.env.PORT || 3000;\n\n// create the switchboard\nvar switchboard = require('rtc-switchboard')(server);\n\nserver.listen(port, function(err) {\n  if (err) {\n    return;\n  }\n\n  console.log('server listening on port: ' + port);\n});\n\n```\n\n## Usage: Docker\n\nIf you are interested in deploying an instance of `rtc-switchboard` using\n[docker](https://www.docker.com/) then the following is a great place to\nstart:\n\n\u003chttps://github.com/synctree/docker-rtc-switchboard\u003e\n\n## Logging and Analytics using the `data` event\n\nEvery message that flows through the switchboard (whether handled or not) can be logged through tapping into the `data` event.  The example below demonstrates how this can be done with a node logging module like [bunyan](https://github.com/trentm/node-bunyan):\n\n```js\nvar express = require('express');\nvar app = express();\nvar server = require('http').Server(app);\nvar port = process.env.PORT || 3000;\nvar bunyan = require('bunyan');\nvar log = bunyan.createLogger({ name: 'rtc-switchboard' });\n\n// create the switchboard\nvar switchboard = require('rtc-switchboard')(server);\n\nserver.listen(port, function(err) {\n  if (err) {\n    return;\n  }\n\n  console.log('server running at: http://localhost:' + port + '/');\n});\n\nswitchboard.on('data', function(data, peerId, spark) {\n  log.info({ peer: peerId }, 'received: ' + data);\n});\n\n```\n\nAs can be seen in the example above, the handlers of the `data` event can expect to receive three arguments to the handler function, as per the code snippet below:\n\n```js\nswitchboard.on('data', function(data, peerId, spark) {\n});\n```\n\nThe `data` is the raw data of that has been sent from the client, the `peerId` is the id of the peer sending the data (this will be `undefined` if it is a message received prior to an `/announce` command).\n\n\n## License(s)\n\n### Apache 2.0\n\nCopyright 2015 National ICT Australia Limited (NICTA)\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n     http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtc-io%2Frtc-switchboard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frtc-io%2Frtc-switchboard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtc-io%2Frtc-switchboard/lists"}