{"id":20863522,"url":"https://github.com/grabss/peerjs-server","last_synced_at":"2025-05-12T09:32:15.008Z","repository":{"id":212390213,"uuid":"292426099","full_name":"grabss/peerjs-server","owner":"grabss","description":null,"archived":false,"fork":false,"pushed_at":"2020-11-05T08:07:28.000Z","size":453,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2023-12-14T02:31:03.522Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/grabss.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}},"created_at":"2020-09-03T00:36:16.000Z","updated_at":"2023-12-14T02:31:04.270Z","dependencies_parsed_at":"2023-12-14T02:41:10.839Z","dependency_job_id":null,"html_url":"https://github.com/grabss/peerjs-server","commit_stats":null,"previous_names":["grabss/peerjs-server"],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grabss%2Fpeerjs-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grabss%2Fpeerjs-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grabss%2Fpeerjs-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grabss%2Fpeerjs-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grabss","download_url":"https://codeload.github.com/grabss/peerjs-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225133149,"owners_count":17425945,"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-11-18T05:29:32.952Z","updated_at":"2024-11-18T05:29:33.462Z","avatar_url":"https://github.com/grabss.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"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# 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\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    ```sh\n    $ peerjs --port 9000 --key peerjs --path /myapp\n\n      Started PeerServer on ::, port: 9000, path: /myapp (v. 0.3.2)\n    ```\n3. Check it: http://127.0.0.1:9000/myapp It should returns JSON with name, description and website fields.\n\nAlso, you can use Docker image to run a new container:\n```sh\n$ docker run -p 9000:9000 -d peerjs/peerjs-server\n```\n\n### Create a custom server:\nIf you have your own server, you can attach PeerServer.\n\n1. Install the package:\n    ```sh\n    #$ cd your-project-path\n    $ npm install peer\n    ```\n2. Use PeerServer object to create a new server:\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    const peer = new Peer('someid', {\n      host: 'localhost',\n      port: 9000,\n      path: '/myapp'\n    });\n\u003c/script\u003e\n```\n\n## Config / CLI options\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|  | `generateClientId` | A function which generate random client IDs when calling `/id` API method (`() =\u003e string`) | No | `uuid/v4` |\n\n## Using HTTPS\nSimply pass in PEM-encoded certificate and key.\n\n```javascript\nconst fs = require('fs');\nconst { PeerServer } = require('peer');\n\nconst peerServer = PeerServer({\n  port: 9000,\n  ssl: {\n    key: fs.readFileSync('/path/to/your/ssl/key/here.key'),\n    cert: fs.readFileSync('/path/to/your/ssl/certificate/here.crt')\n  }\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  port: 9000,\n  path: '/myapp',\n  proxied: true\n});\n```\n\n## Custom client ID generation\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 (Math.random().toString(36) + '0000000000000000000').substr(2, 16);\n\nconst peerServer = PeerServer({\n  port: 9000,\n  path: '/myapp',\n  generateClientId: 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  path: '/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  debug: true,\n  path: '/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\n\nTo run the latest image:  \n```sh\n$ docker run -p 9000:9000 -d peerjs/peerjs-server\n```\n\nYou can build a new image simply by calling:\n```sh\n$ docker build -t myimage https://github.com/peers/peerjs-server.git\n```\n\nTo run the image execute this:  \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## Problems?\n\nDiscuss PeerJS on our Telegram chat:\nhttps://t.me/joinchat/ENhPuhTvhm8WlIxTjQf7Og\n\nPlease post any bugs as a Github issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrabss%2Fpeerjs-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrabss%2Fpeerjs-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrabss%2Fpeerjs-server/lists"}