{"id":13482314,"url":"https://github.com/peers/peerjs-server","last_synced_at":"2025-05-14T08:05:19.381Z","repository":{"id":6221327,"uuid":"7452705","full_name":"peers/peerjs-server","owner":"peers","description":"Server for PeerJS","archived":false,"fork":false,"pushed_at":"2025-05-12T16:03:45.000Z","size":4424,"stargazers_count":4541,"open_issues_count":44,"forks_count":1111,"subscribers_count":137,"default_branch":"master","last_synced_at":"2025-05-14T08:05:06.796Z","etag":null,"topics":["nodejs","peerjs","server","signaling","typescript","webrtc"],"latest_commit_sha":null,"homepage":"https://peerjs.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peers.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"peers","open_collective":"peer"}},"created_at":"2013-01-05T06:49:08.000Z","updated_at":"2025-05-14T02:18:15.000Z","dependencies_parsed_at":"2023-09-27T09:50:02.051Z","dependency_job_id":"d0f3255f-bad0-4b3a-924b-aa61a5837841","html_url":"https://github.com/peers/peerjs-server","commit_stats":{"total_commits":751,"total_committers":51,"mean_commits":14.72549019607843,"dds":"0.49001331557922767","last_synced_commit":"65b81650a2320d3456b67cd872b2f317ef960641"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peers%2Fpeerjs-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peers%2Fpeerjs-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peers%2Fpeerjs-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peers%2Fpeerjs-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peers","download_url":"https://codeload.github.com/peers/peerjs-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101588,"owners_count":22014907,"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":["nodejs","peerjs","server","signaling","typescript","webrtc"],"created_at":"2024-07-31T17:01:00.798Z","updated_at":"2025-05-14T08:05:19.364Z","avatar_url":"https://github.com/peers.png","language":"TypeScript","readme":"[![Build Status](https://travis-ci.org/peers/peerjs-server.png?branch=master)](https://travis-ci.org/peers/peerjs-server)\n![node](https://img.shields.io/node/v/peer)\n![David](https://img.shields.io/david/peers/peerjs-server)\n[![npm version](https://badge.fury.io/js/peer.svg)](https://www.npmjs.com/package/peer)\n[![Downloads](https://img.shields.io/npm/dm/peer.svg)](https://www.npmjs.com/package/peer)\n[![Docker Image Size (latest semver)](https://img.shields.io/docker/image-size/peerjs/peerjs-server)](https://hub.docker.com/r/peerjs/peerjs-server)\n\n# PeerServer: A server for PeerJS\n\nPeerServer helps establishing connections between PeerJS clients. Data is not proxied through the server.\n\nRun your own server on Gitpod!\n\n[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/peers/peerjs-server)\n\n### [https://peerjs.com](https://peerjs.com)\n\n## Usage\n\n### Run server\n\n#### Natively\n\nIf you don't want to develop anything, just enter few commands below.\n\n1. Install the package globally:\n   ```sh\n   $ npm install peer -g\n   ```\n2. Run the server:\n\n   ```sh\n   $ peerjs --port 9000 --key peerjs --path /myapp\n\n     Started PeerServer on ::, port: 9000, path: /myapp (v. 0.3.2)\n   ```\n\n3. Check it: http://127.0.0.1:9000/myapp It should returns JSON with name, description and website fields.\n\n#### Docker\n\nAlso, you can use Docker image to run a new container:\n\n```sh\n$ docker run -p 9000:9000 -d peerjs/peerjs-server\n```\n\n##### Kubernetes\n\n```sh\n$ kubectl run peerjs-server --image=peerjs/peerjs-server --port 9000 --expose -- --port 9000 --path /myapp\n```\n\n### Create a custom server:\n\nIf you have your own server, you can attach PeerServer.\n\n1. Install the package:\n\n   ```bash\n   # $ cd your-project-path\n\n   # with npm\n   $ npm install peer\n\n   # with yarn\n   $ yarn add peer\n   ```\n\n2. Use PeerServer object to create a new server:\n\n   ```javascript\n   const { PeerServer } = require(\"peer\");\n\n   const peerServer = PeerServer({ port: 9000, path: \"/myapp\" });\n   ```\n\n3. Check it: http://127.0.0.1:9000/myapp It should returns JSON with name, description and website fields.\n\n### Connecting to the server from client PeerJS:\n\n```html\n\u003cscript\u003e\n\tconst peer = new Peer(\"someid\", {\n\t\thost: \"localhost\",\n\t\tport: 9000,\n\t\tpath: \"/myapp\",\n\t});\n\u003c/script\u003e\n```\n\n## Config / CLI options\n\nYou can provide config object to `PeerServer` function or specify options for `peerjs` CLI.\n\n| CLI option               | JS option          | Description                                                                                                                                                                                                                                           | Required |  Default   |\n| ------------------------ | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | :--------: |\n| `--port, -p`             | `port`             | Port to listen (number)                                                                                                                                                                                                                               | **Yes**  |            |\n| `--key, -k`              | `key`              | Connection key (string). Client must provide it to call API methods                                                                                                                                                                                   |    No    | `\"peerjs\"` |\n| `--path`                 | `path`             | Path (string). The server responds for requests to the root URL + path. **E.g.** Set the `path` to `/myapp` and run server on 9000 port via `peerjs --port 9000 --path /myapp` Then open http://127.0.0.1:9000/myapp - you should see a JSON reponse. |    No    |   `\"/\"`    |\n| `--proxied`              | `proxied`          | Set `true` if PeerServer stays behind a reverse proxy (boolean)                                                                                                                                                                                       |    No    |  `false`   |\n| `--expire_timeout, -t`   | `expire_timeout`   | The amount of time after which a message sent will expire, the sender will then receive a `EXPIRE` message (milliseconds).                                                                                                                            |    No    |   `5000`   |\n| `--alive_timeout`        | `alive_timeout`    | Timeout for broken connection (milliseconds). If the server doesn't receive any data from client (includes `pong` messages), the client's connection will be destroyed.                                                                               |    No    |  `60000`   |\n| `--concurrent_limit, -c` | `concurrent_limit` | Maximum number of clients' connections to WebSocket server (number)                                                                                                                                                                                   |    No    |   `5000`   |\n| `--sslkey`               | `sslkey`           | Path to SSL key (string)                                                                                                                                                                                                                              |    No    |            |\n| `--sslcert`              | `sslcert`          | Path to SSL certificate (string)                                                                                                                                                                                                                      |    No    |            |\n| `--allow_discovery`      | `allow_discovery`  | Allow to use GET `/peers` http API method to get an array of ids of all connected clients (boolean)                                                                                                                                                   |    No    |            |\n| `--cors`                 | `corsOptions`      | The CORS origins that can access this server                                                                                                                                                                                                          |\n|                          | `generateClientId` | A function which generate random client IDs when calling `/id` API method (`() =\u003e string`)                                                                                                                                                            |    No    | `uuid/v4`  |\n\n## Using HTTPS\n\nSimply pass in PEM-encoded certificate and key.\n\n```javascript\nconst fs = require(\"fs\");\nconst { PeerServer } = require(\"peer\");\n\nconst peerServer = PeerServer({\n\tport: 9000,\n\tssl: {\n\t\tkey: fs.readFileSync(\"/path/to/your/ssl/key/here.key\"),\n\t\tcert: fs.readFileSync(\"/path/to/your/ssl/certificate/here.crt\"),\n\t},\n});\n```\n\nYou can also pass any other [SSL options accepted by https.createServer](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistenerfrom), such as `SNICallback:\n\n```javascript\nconst fs = require(\"fs\");\nconst { PeerServer } = require(\"peer\");\n\nconst peerServer = PeerServer({\n\tport: 9000,\n\tssl: {\n\t\tSNICallback: (servername, cb) =\u003e {\n\t\t\t// your code here ....\n\t\t},\n\t},\n});\n```\n\n## Running PeerServer behind a reverse proxy\n\nMake sure to set the `proxied` option, otherwise IP based limiting will fail.\nThe option is passed verbatim to the\n[expressjs `trust proxy` setting](http://expressjs.com/4x/api.html#app-settings)\nif it is truthy.\n\n```javascript\nconst { PeerServer } = require(\"peer\");\n\nconst peerServer = PeerServer({\n\tport: 9000,\n\tpath: \"/myapp\",\n\tproxied: true,\n});\n```\n\n## Custom client ID generation\n\nBy default, PeerServer uses `uuid/v4` npm package to generate random client IDs.\n\nYou can set `generateClientId` option in config to specify a custom function to generate client IDs.\n\n```javascript\nconst { PeerServer } = require(\"peer\");\n\nconst customGenerationFunction = () =\u003e\n\t(Math.random().toString(36) + \"0000000000000000000\").substr(2, 16);\n\nconst peerServer = PeerServer({\n\tport: 9000,\n\tpath: \"/myapp\",\n\tgenerateClientId: customGenerationFunction,\n});\n```\n\nOpen http://127.0.0.1:9000/myapp/peerjs/id to see a new random id.\n\n## Combining with existing express app\n\n```javascript\nconst express = require(\"express\");\nconst { ExpressPeerServer } = require(\"peer\");\n\nconst app = express();\n\napp.get(\"/\", (req, res, next) =\u003e res.send(\"Hello world!\"));\n\n// =======\n\nconst server = app.listen(9000);\n\nconst peerServer = ExpressPeerServer(server, {\n\tpath: \"/myapp\",\n});\n\napp.use(\"/peerjs\", peerServer);\n\n// == OR ==\n\nconst http = require(\"http\");\n\nconst server = http.createServer(app);\nconst peerServer = ExpressPeerServer(server, {\n\tdebug: true,\n\tpath: \"/myapp\",\n});\n\napp.use(\"/peerjs\", peerServer);\n\nserver.listen(9000);\n\n// ========\n```\n\nOpen the browser and check http://127.0.0.1:9000/peerjs/myapp\n\n## Events\n\nThe `'connection'` event is emitted when a peer connects to the server.\n\n```javascript\npeerServer.on('connection', (client) =\u003e { ... });\n```\n\nThe `'disconnect'` event is emitted when a peer disconnects from the server or\nwhen the peer can no longer be reached.\n\n```javascript\npeerServer.on('disconnect', (client) =\u003e { ... });\n```\n\n## HTTP API\n\nRead [/src/api/README.md](src/api/README.md)\n\n## Running tests\n\n```sh\n$ npm test\n```\n\n## Docker\n\nWe have 'ready to use' images on docker hub:\nhttps://hub.docker.com/r/peerjs/peerjs-server\n\nTo run the latest image:\n\n```sh\n$ docker run -p 9000:9000 -d peerjs/peerjs-server\n```\n\nYou can build a new image simply by calling:\n\n```sh\n$ docker build -t myimage https://github.com/peers/peerjs-server.git\n```\n\nTo run the image execute this:\n\n```sh\n$ docker run -p 9000:9000 -d myimage\n```\n\nThis will start a peerjs server on port 9000 exposed on port 9000 with key `peerjs` on path `/myapp`.\n\nOpen your browser with http://localhost:9000/myapp It should returns JSON with name, description and website fields. http://localhost:9000/myapp/peerjs/id - should returns a random string (random client id)\n\n## Running in Google App Engine\n\nGoogle App Engine will create an HTTPS certificate for you automatically,\nmaking this by far the easiest way to deploy PeerJS in the Google Cloud\nPlatform.\n\n1. Create a `package.json` file for GAE to read:\n\n```sh\necho \"{}\" \u003e package.json\nnpm install express@latest peer@latest\n```\n\n2. Create an `app.yaml` file to configure the GAE application.\n\n```yaml\nruntime: nodejs\n\n# Flex environment required for WebSocket support, which is required for PeerJS.\nenv: flex\n\n# Limit resources to one instance, one CPU, very little memory or disk.\nmanual_scaling:\n  instances: 1\nresources:\n  cpu: 1\n  memory_gb: 0.5\n  disk_size_gb: 0.5\n```\n\n3. Create `server.js` (which node will run by default for the `start` script):\n\n```js\nconst express = require(\"express\");\nconst { ExpressPeerServer } = require(\"peer\");\nconst app = express();\n\napp.enable(\"trust proxy\");\n\nconst PORT = process.env.PORT || 9000;\nconst server = app.listen(PORT, () =\u003e {\n\tconsole.log(`App listening on port ${PORT}`);\n\tconsole.log(\"Press Ctrl+C to quit.\");\n});\n\nconst peerServer = ExpressPeerServer(server, {\n\tpath: \"/\",\n});\n\napp.use(\"/\", peerServer);\n\nmodule.exports = app;\n```\n\n4. Deploy to an existing GAE project (assuming you are already logged in via\n   `gcloud`), replacing `YOUR-PROJECT-ID-HERE` with your particular project ID:\n\n```sh\ngcloud app deploy --project=YOUR-PROJECT-ID-HERE --promote --quiet app.yaml\n```\n\n## Privacy\n\nSee [PRIVACY.md](https://github.com/peers/peerjs-server/blob/master/PRIVACY.md)\n\n## Problems?\n\nDiscuss PeerJS on our Discord community:\nhttps://discord.gg/Ud2PvAtK37\n\nPlease post any bugs as a Github issue.\n","funding_links":["https://github.com/sponsors/peers","https://opencollective.com/peer"],"categories":["TypeScript","Modules","typescript","nodejs","webrtc","JavaScript","Uncategorized","Signaling Server"],"sub_categories":["Uncategorized","C/C++"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeers%2Fpeerjs-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeers%2Fpeerjs-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeers%2Fpeerjs-server/lists"}