├── .deepsource.toml ├── .github ├── FUNDING.yml └── workflows │ ├── browserstack.yml │ ├── codeql-analysis.yml │ ├── prettier.yml │ ├── release.yml │ └── test.yml ├── .gitignore ├── .prettierignore ├── .prettierrc.toml ├── .releaserc.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── __test__ ├── faker.ts ├── logger.spec.ts ├── peer.spec.ts ├── setup.ts └── util.spec.ts ├── e2e ├── .eslintrc ├── alice.html ├── bob.html ├── commit_data.js ├── data.js ├── datachannel │ ├── Int32Array.js │ ├── Int32Array_as_ArrayBuffer.js │ ├── Int32Array_as_Uint8Array.js │ ├── TypedArrayView_as_ArrayBuffer.js │ ├── Uint8Array.js │ ├── Uint8Array_as_ArrayBuffer.js │ ├── arraybuffers.js │ ├── arraybuffers_as_uint8array.js │ ├── arrays.js │ ├── arrays_unchunked.js │ ├── blobs.js │ ├── dates.js │ ├── dates_as_json_string.js │ ├── dates_as_string.js │ ├── files.js │ ├── long_string.js │ ├── numbers.js │ ├── objects.js │ ├── serialization.html │ ├── serialization.js │ ├── serialization.page.ts │ ├── serializationTest.ts │ ├── serialization_binary.spec.ts │ ├── serialization_json.spec.ts │ ├── serialization_msgpack.spec.ts │ ├── strings.js │ └── typed_array_view.js ├── mediachannel │ ├── close.html │ ├── close.js │ ├── close.page.ts │ └── close.spec.ts ├── package.json ├── peer │ ├── disconnected.html │ ├── id-taken.html │ ├── peer.page.ts │ ├── peer.spec.ts │ └── server-unavailable.html ├── style.css ├── tsconfig.json ├── types.d.ts ├── wdio.bstack.conf.ts ├── wdio.local.conf.ts └── wdio.shared.conf.ts ├── jest.config.cjs ├── lib ├── api.ts ├── baseconnection.ts ├── dataconnection │ ├── BufferedConnection │ │ ├── BinaryPack.ts │ │ ├── BufferedConnection.ts │ │ ├── Json.ts │ │ ├── Raw.ts │ │ └── binaryPackChunker.ts │ ├── DataConnection.ts │ └── StreamConnection │ │ ├── MsgPack.ts │ │ └── StreamConnection.ts ├── encodingQueue.ts ├── enums.ts ├── exports.ts ├── global.ts ├── logger.ts ├── mediaconnection.ts ├── msgPackPeer.ts ├── negotiator.ts ├── optionInterfaces.ts ├── peer.ts ├── peerError.ts ├── servermessage.ts ├── socket.ts ├── supports.ts ├── util.ts └── utils │ ├── randomToken.ts │ └── validateId.ts ├── package-lock.json ├── package.json ├── renovate.json └── tsconfig.json /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | test_patterns = ["test/**"] 4 | 5 | [[analyzers]] 6 | name = "javascript" 7 | enabled = true 8 | 9 | [analyzers.meta] 10 | environment = [ 11 | "nodejs", 12 | "mocha" 13 | ] 14 | dialect = "typescript" 15 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: peers 2 | open_collective: peer 3 | -------------------------------------------------------------------------------- /.github/workflows/browserstack.yml: -------------------------------------------------------------------------------- 1 | name: "BrowserStack Test" 2 | on: [push, pull_request] 3 | 4 | concurrency: 5 | group: browserstack 6 | jobs: 7 | ubuntu-job: 8 | name: "BrowserStack Test on Ubuntu" 9 | runs-on: ubuntu-latest # Can be self-hosted runner also 10 | steps: 11 | - name: "BrowserStack Env Setup" # Invokes the setup-env action 12 | uses: browserstack/github-actions/setup-env@master 13 | with: 14 | username: ${{ secrets.BROWSERSTACK_USERNAME }} 15 | access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} 16 | 17 | - name: "BrowserStack Local Tunnel Setup" # Invokes the setup-local action 18 | uses: browserstack/github-actions/setup-local@master 19 | with: 20 | local-testing: "start" 21 | local-logging-level: "all-logs" 22 | local-identifier: "random" 23 | 24 | # The next 3 steps are for building the web application to be tested and starting the web server on the runner environment 25 | 26 | - name: "Checkout the repository" 27 | uses: actions/checkout@v4 28 | 29 | - name: "Building web application to be tested" 30 | run: npm install && npm run build 31 | 32 | - name: "Running application under test" 33 | run: npx http-server -p 3000 --cors & 34 | 35 | - name: "Running test on BrowserStack" # Invokes the actual test script that would run on BrowserStack browsers 36 | run: npm run e2e:bstack # See sample test script above 37 | env: 38 | BYPASS_WAF: ${{ secrets.BYPASS_WAF }} 39 | 40 | - name: "BrowserStackLocal Stop" # Terminating the BrowserStackLocal tunnel connection 41 | uses: browserstack/github-actions/setup-local@master 42 | with: 43 | local-testing: "stop" 44 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [master, rc, stable] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [master] 20 | schedule: 21 | - cron: "15 2 * * 5" 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: ["javascript"] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v4 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v3 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | 52 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 53 | # queries: security-extended,security-and-quality 54 | 55 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 56 | # If this step fails, then you should remove it and run the build manually (see below) 57 | - name: Autobuild 58 | uses: github/codeql-action/autobuild@v3 59 | 60 | # ℹ️ Command-line programs to run using the OS shell. 61 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 62 | 63 | # If the Autobuild fails above, remove it and uncomment the following three lines. 64 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 65 | 66 | # - run: | 67 | # echo "Run, Build Application using script" 68 | # ./location_of_script_within_repo/buildscript.sh 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v3 72 | -------------------------------------------------------------------------------- /.github/workflows/prettier.yml: -------------------------------------------------------------------------------- 1 | # From https://til.simonwillison.net/github-actions/prettier-github-actions 2 | name: Check JavaScript for conformance with Prettier 3 | 4 | on: 5 | push: 6 | pull_request: 7 | 8 | jobs: 9 | prettier: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Check out repo 13 | uses: actions/checkout@v4 14 | - uses: actions/setup-node@v4 15 | with: 16 | node-version: 16 17 | cache: "npm" 18 | - run: npm ci 19 | - name: Run prettier 20 | run: |- 21 | npm run format:check 22 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | push: 4 | branches: 5 | - rc 6 | - stable 7 | jobs: 8 | release: 9 | name: Release 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v4 14 | with: 15 | fetch-depth: 0 16 | - name: Setup Node.js 17 | uses: actions/setup-node@v4 18 | with: 19 | node-version: "lts/*" 20 | - name: Install dependencies 21 | run: npm ci 22 | - name: Import GPG key 23 | id: import_gpg 24 | uses: crazy-max/ghaction-import-gpg@v6 25 | with: 26 | gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} 27 | passphrase: ${{ secrets.GPG_PASSPHRASE }} 28 | git_user_signingkey: true 29 | git_commit_gpgsign: true 30 | - name: Release 31 | env: 32 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 33 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 34 | GIT_COMMITTER_NAME: ${{ steps.import_gpg.outputs.name }} 35 | GIT_COMMITTER_EMAIL: ${{ steps.import_gpg.outputs.email }} 36 | run: npx semantic-release 37 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: ["master"] 9 | pull_request: 10 | branches: ["master"] 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | 16 | strategy: 17 | matrix: 18 | node-version: [16.x, 18.x, 20.x] 19 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 20 | 21 | steps: 22 | - uses: actions/checkout@v4 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v4 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | cache: "npm" 28 | - run: npm ci 29 | - run: npm run check 30 | - run: npm run build 31 | # - run: npm run lint 32 | - run: npm run coverage 33 | - name: Publish code coverage to CodeClimate 34 | uses: paambaati/codeclimate-action@v6.0.0 35 | env: 36 | CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | coverage 3 | *.seed 4 | *.log 5 | *.csv 6 | *.dat 7 | *.out 8 | *.pid 9 | *.[t]gz 10 | 11 | dist 12 | pids 13 | logs 14 | results 15 | demo 16 | bower.json 17 | node_modules 18 | .parcel-cache 19 | .idea 20 | npm-debug.log 21 | .DS_STORE 22 | 23 | test/output 24 | browserstack.err 25 | .tscache 26 | test/public 27 | .vscode/ 28 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist 2 | docs 3 | package-json.lock 4 | 5 | # semantic-release 6 | CHANGELOG.md -------------------------------------------------------------------------------- /.prettierrc.toml: -------------------------------------------------------------------------------- 1 | trailingComma = "all" 2 | semi = true 3 | useTabs = true -------------------------------------------------------------------------------- /.releaserc.json: -------------------------------------------------------------------------------- 1 | { 2 | "branches": ["stable", { "name": "rc", "prerelease": true }], 3 | "plugins": [ 4 | "@semantic-release/commit-analyzer", 5 | "@semantic-release/release-notes-generator", 6 | "@semantic-release/changelog", 7 | "@semantic-release/npm", 8 | "@semantic-release/git", 9 | "@semantic-release/github" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [1.5.4](https://github.com/peers/peerjs/compare/v1.5.3...v1.5.4) (2024-05-14) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * **deps:** update dependency webrtc-adapter to v9 ([#1266](https://github.com/peers/peerjs/issues/1266)) ([5536abf](https://github.com/peers/peerjs/commit/5536abf8d6345c248df875e0e22c520a20cb2919)) 7 | * remove CBOR ([badc9e8](https://github.com/peers/peerjs/commit/badc9e8bc4f7ce5517de3a58abcaec1d566eccf5)), closes [#1271](https://github.com/peers/peerjs/issues/1271) [#1247](https://github.com/peers/peerjs/issues/1247) [#1271](https://github.com/peers/peerjs/issues/1271) 8 | 9 | ## [1.5.3](https://github.com/peers/peerjs/compare/v1.5.2...v1.5.3) (2024-05-11) 10 | 11 | 12 | ### Bug Fixes 13 | 14 | * navigator is not defined. ([#1202](https://github.com/peers/peerjs/issues/1202)) ([4b7a74d](https://github.com/peers/peerjs/commit/4b7a74d74c50461fde80e84992d88a9d564dbe72)), closes [#1165](https://github.com/peers/peerjs/issues/1165) 15 | * remove need for `unsafe-eval` ([3fb31b3](https://github.com/peers/peerjs/commit/3fb31b316b8f4d699d087e1b465e908688be3872)) 16 | 17 | ## [1.5.2](https://github.com/peers/peerjs/compare/v1.5.1...v1.5.2) (2023-12-05) 18 | 19 | 20 | ### Bug Fixes 21 | 22 | * support Blobs nested in objects ([7956dd6](https://github.com/peers/peerjs/commit/7956dd640388fce62c83453d56e1a20aec2212b2)), closes [#1163](https://github.com/peers/peerjs/issues/1163) 23 | 24 | ## [1.5.1](https://github.com/peers/peerjs/compare/v1.5.0...v1.5.1) (2023-09-23) 25 | 26 | 27 | ### Bug Fixes 28 | 29 | * convert `Blob`s to `ArrayBuffer`s during `.send()` ([95bb0f7](https://github.com/peers/peerjs/commit/95bb0f7fa9aa0d119613727c32857e5af33e14a1)), closes [#1137](https://github.com/peers/peerjs/issues/1137) 30 | * convert `Blob`s to `ArrayBuffer`s during `.send()` ([#1142](https://github.com/peers/peerjs/issues/1142)) ([094f849](https://github.com/peers/peerjs/commit/094f849816d327bf74a447fbf7d58195c1a4fc66)) 31 | 32 | # [1.5.0](https://github.com/peers/peerjs/compare/v1.4.7...v1.5.0) (2023-09-03) 33 | 34 | 35 | ### Bug Fixes 36 | 37 | * **datachannel:** sending order is now preserved correctly ([#1038](https://github.com/peers/peerjs/issues/1038)) ([0fb6179](https://github.com/peers/peerjs/commit/0fb61792ed3afe91123550a159c8633ed0976f89)), closes [#746](https://github.com/peers/peerjs/issues/746) 38 | * **deps:** update dependency @swc/helpers to ^0.4.0 ([a7de8b7](https://github.com/peers/peerjs/commit/a7de8b78f57a5cf9708fa54e9f82f4ab43c0bca2)) 39 | * **deps:** update dependency cbor-x to v1.5.4 ([c1f04ec](https://github.com/peers/peerjs/commit/c1f04ecf686e64266fb54b3e4992c73c1522ae79)) 40 | * **deps:** update dependency eventemitter3 to v5 ([caf01c6](https://github.com/peers/peerjs/commit/caf01c6440534cbe190facd84cecf9ca62e4a5ce)) 41 | * **deps:** update dependency peerjs-js-binarypack to v1.0.2 ([7452e75](https://github.com/peers/peerjs/commit/7452e7591d4982d9472c524d6ad30e66c2a2b44f)) 42 | * **deps:** update dependency webrtc-adapter to v8 ([431f00b](https://github.com/peers/peerjs/commit/431f00bd89809867a19c98224509982b82769558)) 43 | * **deps:** update dependency webrtc-adapter to v8.2.2 ([62402fc](https://github.com/peers/peerjs/commit/62402fcae03c78382d7fa80c11f459aca8d21620)) 44 | * **deps:** update dependency webrtc-adapter to v8.2.3 ([963455e](https://github.com/peers/peerjs/commit/963455ee383a069e53bd93b1128d82615a698245)) 45 | * **MediaConnection:** `close` event is fired on remote Peer ([0836356](https://github.com/peers/peerjs/commit/0836356d18c91449f4cbb23e4d4660a4351d7f56)), closes [#636](https://github.com/peers/peerjs/issues/636) [#1089](https://github.com/peers/peerjs/issues/1089) [#1032](https://github.com/peers/peerjs/issues/1032) [#832](https://github.com/peers/peerjs/issues/832) [#780](https://github.com/peers/peerjs/issues/780) [#653](https://github.com/peers/peerjs/issues/653) 46 | * **npm audit:** Updates all dependencies that cause npm audit to issue a warning ([6ef5707](https://github.com/peers/peerjs/commit/6ef5707dc85d8b921d8dfea74890b110ddf5cd4f)) 47 | 48 | 49 | ### Features 50 | 51 | * `.type` property on `Error`s emitted from connections ([#1126](https://github.com/peers/peerjs/issues/1126)) ([debe7a6](https://github.com/peers/peerjs/commit/debe7a63474b9cdb705676d4c7892b0cd294402a)) 52 | * `PeerError` from connections ([ad3a0cb](https://github.com/peers/peerjs/commit/ad3a0cbe8c5346509099116441e6c3ff0b6ca6c4)) 53 | * **DataConnection:** handle close messages and flush option ([6ca38d3](https://github.com/peers/peerjs/commit/6ca38d32b0929745b92a55c8f6aada1ee0895ce7)), closes [#982](https://github.com/peers/peerjs/issues/982) 54 | * **MediaChannel:** Add experimental `willCloseOnRemote` event to MediaConnection. ([ed84829](https://github.com/peers/peerjs/commit/ed84829a1092422f3d7f92f467bcf5b8ada82891)) 55 | * MsgPack/Cbor serialization ([fcffbf2](https://github.com/peers/peerjs/commit/fcffbf243cb7d6dabfc773211c155c0ae1e00baf)) 56 | * MsgPack/Cbor serialization ([#1120](https://github.com/peers/peerjs/issues/1120)) ([4367256](https://github.com/peers/peerjs/commit/43672564ee9edcb15e736b0333c6ad8aeae20c59)), closes [#611](https://github.com/peers/peerjs/issues/611) 57 | 58 | ## [1.4.7](https://github.com/peers/peerjs/compare/v1.4.6...v1.4.7) (2022-08-09) 59 | 60 | 61 | ### Bug Fixes 62 | 63 | * **browser-bundle:** Leaked private functions in the global scope ([857d425](https://github.com/peers/peerjs/commit/857d42524a929388b352a2330f18fdfc15df6c22)), closes [#989](https://github.com/peers/peerjs/issues/989) 64 | 65 | ## [1.4.6](https://github.com/peers/peerjs/compare/v1.4.5...v1.4.6) (2022-05-25) 66 | 67 | 68 | ### Bug Fixes 69 | 70 | * **typings:** `MediaConnection.answer()` doesn’t need a `stream` anymore, thanks [@matallui](https://github.com/matallui)! ([666dcd9](https://github.com/peers/peerjs/commit/666dcd9770fe080e00898b9138664e8996bf5162)) 71 | * **typings:** much stronger event typings for `DataConnection`,`MediaConnection` ([0c96603](https://github.com/peers/peerjs/commit/0c96603a3f97f28eabe24906e692c31ef0ebca13)) 72 | 73 | 74 | ### Performance Improvements 75 | 76 | * **turn:** reduce turn server count ([8816f54](https://github.com/peers/peerjs/commit/8816f54c4b4bff5f6bd0c7ccf5327ec84e80a8ca)) 77 | 78 | ## [1.4.5](https://github.com/peers/peerjs/compare/v1.4.4...v1.4.5) (2022-05-24) 79 | 80 | 81 | ### Bug Fixes 82 | 83 | * **referrerPolicy:** you can now set a custom referrerPolicy for api requests ([c0ba9e4](https://github.com/peers/peerjs/commit/c0ba9e4b64f233c2733a8c5e904a8536ae37eb42)), closes [#955](https://github.com/peers/peerjs/issues/955) 84 | * **typings:** add missing type exports ([#959](https://github.com/peers/peerjs/issues/959)) ([3c915d5](https://github.com/peers/peerjs/commit/3c915d57bb18ac822d3438d879717266ee84b635)), closes [#961](https://github.com/peers/peerjs/issues/961) 85 | 86 | ## [1.4.4](https://github.com/peers/peerjs/compare/v1.4.3...v1.4.4) (2022-05-13) 87 | 88 | 89 | ### Bug Fixes 90 | 91 | * **CRA@4:** import hack ([41c3ba7](https://github.com/peers/peerjs/commit/41c3ba7b2ca6adc226efd0e2add546a570a4aa3a)), closes [#954](https://github.com/peers/peerjs/issues/954) 92 | * **source maps:** enable source map inlining ([97a724b](https://github.com/peers/peerjs/commit/97a724b6a1e04817d79ecaf91d4384ae3a94cf99)) 93 | 94 | ## [1.4.3](https://github.com/peers/peerjs/compare/v1.4.2...v1.4.3) (2022-05-13) 95 | 96 | 97 | ### Bug Fixes 98 | 99 | * **typings:** export interfaces ([979e695](https://github.com/peers/peerjs/commit/979e69545cc2fe10c60535ac9793140ef8dba4ec)), closes [#953](https://github.com/peers/peerjs/issues/953) 100 | 101 | ## [1.4.2](https://github.com/peers/peerjs/compare/v1.4.1...v1.4.2) (2022-05-12) 102 | 103 | 104 | ### Bug Fixes 105 | 106 | * **bundler import:** enable module target ([b5beec4](https://github.com/peers/peerjs/commit/b5beec4a07827f82c5e50c79c71a8cfb1ec3c40e)), closes [#761](https://github.com/peers/peerjs/issues/761) 107 | 108 | ## [1.4.1](https://github.com/peers/peerjs/compare/v1.4.0...v1.4.1) (2022-05-11) 109 | 110 | 111 | ### Bug Fixes 112 | 113 | * **old bundlers:** include support for Node 10 (EOL since 2021-04-01) / old bundlers ([c0f4648](https://github.com/peers/peerjs/commit/c0f4648b1c104e5e0e5967bb239c217288aa83e0)), closes [#952](https://github.com/peers/peerjs/issues/952) 114 | 115 | # [1.4.0](https://github.com/peers/peerjs/compare/v1.3.2...v1.4.0) (2022-05-10) 116 | 117 | 118 | ### Bug Fixes 119 | 120 | * add changelog and npm version to the repo ([d5bd955](https://github.com/peers/peerjs/commit/d5bd9552daf5d42f9d04b3087ddc34c729004daa)) 121 | * add token to PeerJSOption type definition ([e7675e1](https://github.com/peers/peerjs/commit/e7675e1474b079b2804167c70335a6c6e2b8ec08)) 122 | * websocket connection string ([82b8c71](https://github.com/peers/peerjs/commit/82b8c713bc03be34c2526bdf442a583c4d547c83)) 123 | 124 | 125 | ### Features 126 | 127 | * upgrade to Parcel@2 ([aae9d1f](https://github.com/peers/peerjs/commit/aae9d1fa37731d0819f93535b8ad78fe4b685d1e)), closes [#845](https://github.com/peers/peerjs/issues/845) [#859](https://github.com/peers/peerjs/issues/859) [#552](https://github.com/peers/peerjs/issues/552) [#585](https://github.com/peers/peerjs/issues/585) 128 | 129 | 130 | ### Performance Improvements 131 | 132 | * **turn:** lower TURN-latency due to more local servers ([a412ea4](https://github.com/peers/peerjs/commit/a412ea4984a46d50de8873904b7067897b0f29f9)) 133 | 134 | 135 | 136 | ## 1.3.2 (2021-03-11) 137 | 138 | - fixed issues #800, #803 in PR #806, thanks @jordanaustin 139 | - updated devDeps: `typescript` to 4.2 140 | 141 | 142 | 143 | ## 1.3.1 (2020-07-11) 144 | 145 | - fixed: map file resolving 146 | - removed: @types/webrtc because it contains in ts dom lib. 147 | 148 | 149 | 150 | ## 1.3.0 (2020-07-03) 151 | 152 | - changed: don't close the Connection if `iceConnectionState` changed to `disconnected` 153 | 154 | 155 | 156 | ## 1.2.0 (2019-12-24) 157 | 158 | - added: ability to change json stringify / json parse methods for DataConnection #592 159 | 160 | - removed: `peerBrowser` field from `dataConnection` because unused 161 | 162 | - fixed: lastServerId and reconnect #580 #534 #265 163 | 164 | 165 | 166 | ## 1.1.0 (2019-09-16) 167 | 168 | - removed: deprecated `RtpDataChannels` and `DtlsSrtpKeyAgreement` options 169 | - removed: grunt from deps, upgrade deps versions 170 | - removed: Reliable dep because modern browsers supports `RTCDataChannel.ordered` property 171 | 172 | - added: TURN server to default config 173 | 174 | - fixed: emit error message, then destroy/disconnect when error occurred 175 | - fixed: use `peerjs-js-binarypack` instead of `js-binarypack` 176 | - fixed: sending large files via DataConnection #121 177 | 178 | 179 | 180 | ## 1.0.4 (2019-08-31) 181 | 182 | - fixed: 'close' event for DataConnection #568 183 | 184 | 185 | 186 | ## 1.0.3 (2019-08-21) 187 | 188 | - add pingInterval option 189 | 190 | 191 | 192 | ## 1.0.2 (2019-07-20) 193 | 194 | ### Bug Fixes 195 | 196 | - fixed: memory leak in DataConnection #556 197 | - fixed: missing sdpMid in IceServer #550 198 | 199 | ### Other 200 | 201 | - updated: old @types/webrtc dependency #549 202 | 203 | 204 | 205 | ## 1.0.1 (2019-07-09) 206 | 207 | ### Bug Fixes 208 | 209 | - fixed: readyState of undefined #520 210 | - fixed: call sdpTransform in Answer #524 211 | - fixed: sdpTransform does not apply to makeAnswer SDP #523 212 | 213 | 214 | 215 | ## 1.0.0 (2019-04-10) 216 | 217 | ### Refactoring 218 | 219 | Almost all project was refactored!!! 220 | 221 | - removed: xhr long-pooling #506 222 | - changed: fetch api instead of xhr 223 | 224 | ### Features 225 | 226 | - added: heartbeat #502 227 | 228 | ### Bug Fixes 229 | 230 | - fixed: destroy RTCPeerConnection #513 231 | - fixed: MediaStream memory leak #514 232 | 233 | 234 | 235 | ## 0.3.18 (2018-10-30) 236 | 237 | ### Features 238 | 239 | - **typescript:** First commit ([0c77a5b](https://github.com/peers/peerjs/commit/0c77a5b)) 240 | 241 | 242 | 243 | ## 0.3.16 (2018-08-21) 244 | 245 | ### Bug Fixes 246 | 247 | - fixed typo in README ([f1bd47e](https://github.com/peers/peerjs/commit/f1bd47e)) 248 | 249 | ## Version 0.3.14 250 | 251 | - Patch for #246, which started as of Chrome 38. 252 | 253 | ## Version 0.3.11 (28 Sep 2014) 254 | 255 | - Browserify build system 256 | 257 | ## Version 0.3.10 (29 Aug 2014) 258 | 259 | - Fixed a bug where `disconnected` would be emitted for XHR requests that were aborted on purpose. 260 | 261 | ## Version 0.3.9 (11 July 2014) 262 | 263 | - Allow an external adapter to be used (for `RTCPeerConnection` and such). (Thanks, @khankuan!) 264 | - Fixed a bug where `_chunkedData` was not being cleared recursively, causing memory to be eaten up unnecessarily. (Thanks, @UnsungHero97!) 265 | - Added `peer.reconnect()`, which allows a peer to reconnect to the signalling server with the same ID it had before after it has been disconnected. (Thanks, @jure, for the amazing input :)!) 266 | - Added previously-missing error types, such as `webrtc`, `network`, and `peer-unavailable` error types. (Thanks, @mmis1000 for reporting!) 267 | - Fixed a bug where the peer would infinitely attempt to start XHR streaming when there is no network connection available. Now, the peer will simply emit a `network` error and disconnect. (Thanks, @UnsungHero97 for reporting!) 268 | 269 | ## Version 0.3.8 beta (18 Mar 2014) 270 | 271 | - **The following changes are only compatible with PeerServer 0.2.4.** 272 | - Added the ability to specify a custom path when connecting to a self-hosted 273 | PeerServer. 274 | - Added the ability to retrieve a list of all peers connected to the server. 275 | 276 | ## Version 0.3.7 beta (23 Dec 2013) 277 | 278 | - Chrome 31+/Firefox 27+ DataConnection interop for files. 279 | - Deprecate `binary-utf8` in favor of faster support for UTF8 in the regular 280 | `binary` serialization. 281 | - Fix `invalid-key` error message. 282 | 283 | ## Version 0.3.6 beta (3 Dec 2013) 284 | 285 | - Workaround for hitting Chrome 31+ buffer limit. 286 | - Add `.bufferSize` to DataConnection to indicate the size of the buffer queue. 287 | - Add `.dataChannel` to DataConnection as an alias for `._dc`, which contains 288 | the RTCDataChannel object associated with the DataConnection. 289 | - Update BinaryPack dependency. 290 | 291 | ## Version 0.3.5 beta (26 Nov 2013) 292 | 293 | - Fix bug where chunks were being emitted. 294 | 295 | ## Version 0.3.4 beta (11 Nov 2013) 296 | 297 | - Fix file transfer issue in Chrome by chunking for data over 120KB. 298 | - Use binary data when possible. 299 | - Update BinaryPack dependency to fix inefficiencies. 300 | 301 | ## Version 0.3.3 beta (2 Nov 2013) 302 | 303 | - Fix exceptions when peer emits errors upon creation 304 | - Remove extra commas 305 | 306 | ## Version 0.3.2 beta (25 Oct 2013) 307 | 308 | - Use SCTP in Chrome 31+. 309 | - Work around Chrome 31+ tab crash. The crashes were due to Chrome's lack of support for the `maxRetransmits` parameter for modifying SDP. 310 | - Fix exceptions in Chrome 29 and below. 311 | - DataChannels are unreliable by default in Chrome 30 and below. In setting 312 | reliable to `true`, the reliable shim is used only in Chrome 30 and below. 313 | 314 | ## Version 0.3.1 beta (19 Oct 2013) 315 | 316 | - Updated docs and examples for TURN server usage 317 | - Fixed global variable leak 318 | - DataConnections now have reliable: false by default. This will switch to on when reliable: true works in more browsers 319 | 320 | ## Version 0.3.0 beta (20 Sept 2013) 321 | 322 | ### Highlights 323 | 324 | - Support for WebRTC video and audio streams in both Firefox and Chrome. 325 | - Add `util.supports.[FEATURE]` flags, which represent the WebRTC features 326 | supported by your browser. 327 | - **Breaking:** Deprecate current `Peer#connections` format. Connections will no longer be 328 | keyed by label and will instead be in a list. 329 | 330 | ### Other changes 331 | 332 | - **Breaking:** Deprecate `Peer.browser` in favor of `util.browser`. 333 | - Additional logging levels (warnings, errors, all). 334 | - Additional logging functionality (`logFunction`). 335 | - SSL option now in config rather than automatic. 336 | 337 | ## Version 0.2.8 (1 July 2013) 338 | 339 | - Fix bug, no error on Firefox 24 due to missing error callback. 340 | - TLS secure PeerServers now supported. 341 | - Updated version of Reliable shim. 342 | 343 | ## Version 0.2.7 (28 May 2013) 344 | 345 | - Fix bug, no error when .disconnect called in before socket connection established. 346 | - Fix bug, failure to enter debug mode when aborting because browser not supported. 347 | 348 | ## Version 0.2.6 (2 May 2013) 349 | 350 | - Peer.browser to check browser type. 351 | - Update Reliable library and fix Reliable functionality in Chrome. 352 | 353 | ## Version 0.2.5 (24 Apr 2013) 354 | 355 | - **Firefox compatibility for Firefox Nightly.** 356 | - Misc bug fixes. 357 | 358 | ## Version 0.2.1 (3 Apr 2013) 359 | 360 | - **Warning**: this build changes the error of type `peer-destroyed` to `server-disconnected`. 361 | - ~~**Firefox compatibility.**~~ - Pushed back due to volatility of Firefox Nightly DataChannel APIs. 362 | - Browser detection added. If an incompatible browser is detected, the `browser-incompatible` error is emitted from the `Peer`. 363 | - Added a `.disconnect()` method to `Peer`, which can be called to close connections to the PeerServer (but not any active DataConnections). 364 | 365 | ## Version 0.2.0 (24 Mar 2013) 366 | 367 | - **Warning**: this build introduces the following API changes that may break existing code. 368 | - `peer.connections` is no longer a hash mapping peer IDs to connections. 369 | - Connections no longer emit errors from `PeerConnection`; `PeerConnection` errors are now forwarded to the `Peer` object. 370 | - Add support for multiple DataConnections with different labels. 371 | - Update Reliable version to support faster file transfer. 372 | - Fix bug where using XHR streaming to broker a connection occasionally fails. 373 | 374 | ## Version 0.1.7 (6 Mar 2013) 375 | 376 | - Add experimental `reliable` messaging option. [See documentation.](https://github.com/peers/peerjs/blob/master/docs/api.md#experimental-reliable-and-large-file-transfer) 377 | - Fix bug where the ID /GET request was cached and so two Peers created simultaneously would get the same ID: [See issue.](https://github.com/peers/peerjs-server/issues/2) 378 | - Add support for relative hostname. [See documentation.](https://github.com/peers/peerjs/blob/master/docs/api.md#new-peerid-options) 379 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Michelle Bu and Eric Zhang, http://peerjs.com 2 | 3 | (The MIT License) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PeerJS: Simple peer-to-peer with WebRTC 2 | 3 | [![Backers on Open Collective](https://opencollective.com/peer/backers/badge.svg)](#backers) 4 | [![Sponsors on Open Collective](https://opencollective.com/peer/sponsors/badge.svg)](#sponsors) 5 | [![Discord](https://img.shields.io/discord/1016419835455996076?color=5865F2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/Ud2PvAtK37) 6 | 7 | PeerJS provides a complete, configurable, and easy-to-use peer-to-peer API built on top of WebRTC, supporting both data channels and media streams. 8 | 9 | ## Live Example 10 | 11 | Here's an example application that uses both media and data connections: https://glitch.com/~peerjs-video. The example also uses its own [PeerServer](https://github.com/peers/peerjs-server). 12 | 13 | --- 14 | 15 |

16 | Special Announcement: 17 |
18 | 19 | 20 | 21 |
22 | We now have a Discord Channel 23 |
24 | There we plan to discuss roadmaps, feature requests, and more
Join us today
25 |

26 | 27 | --- 28 | 29 | ## Setup 30 | 31 | **Include the library** 32 | 33 | with npm: 34 | `npm install peerjs` 35 | 36 | with yarn: 37 | `yarn add peerjs` 38 | 39 | ```js 40 | // The usage - 41 | import { Peer } from "peerjs"; 42 | ``` 43 | 44 | **Create a Peer** 45 | 46 | ```javascript 47 | const peer = new Peer("pick-an-id"); 48 | // You can pick your own id or omit the id if you want to get a random one from the server. 49 | ``` 50 | 51 | ## Data connections 52 | 53 | **Connect** 54 | 55 | ```javascript 56 | const conn = peer.connect("another-peers-id"); 57 | conn.on("open", () => { 58 | conn.send("hi!"); 59 | }); 60 | ``` 61 | 62 | **Receive** 63 | 64 | ```javascript 65 | peer.on("connection", (conn) => { 66 | conn.on("data", (data) => { 67 | // Will print 'hi!' 68 | console.log(data); 69 | }); 70 | conn.on("open", () => { 71 | conn.send("hello!"); 72 | }); 73 | }); 74 | ``` 75 | 76 | ## Media calls 77 | 78 | **Call** 79 | 80 | ```javascript 81 | navigator.mediaDevices.getUserMedia( 82 | { video: true, audio: true }, 83 | (stream) => { 84 | const call = peer.call("another-peers-id", stream); 85 | call.on("stream", (remoteStream) => { 86 | // Show stream in some