{"id":23099178,"url":"https://github.com/giovannicalo/react-wrtc","last_synced_at":"2026-05-05T22:31:55.403Z","repository":{"id":89746290,"uuid":"543811422","full_name":"giovannicalo/react-wrtc","owner":"giovannicalo","description":"React WebRTC","archived":false,"fork":false,"pushed_at":"2024-08-15T01:24:40.000Z","size":63,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-09T08:35:57.141Z","etag":null,"topics":["composite","react","stream","video","webrtc","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/giovannicalo.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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}},"created_at":"2022-09-30T22:26:47.000Z","updated_at":"2024-08-15T01:24:43.000Z","dependencies_parsed_at":"2024-01-20T16:29:02.160Z","dependency_job_id":"62103bd0-ab03-4029-8949-0fad91571d6f","html_url":"https://github.com/giovannicalo/react-wrtc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giovannicalo%2Freact-wrtc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giovannicalo%2Freact-wrtc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giovannicalo%2Freact-wrtc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giovannicalo%2Freact-wrtc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/giovannicalo","download_url":"https://codeload.github.com/giovannicalo/react-wrtc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247071716,"owners_count":20878743,"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":["composite","react","stream","video","webrtc","websocket"],"created_at":"2024-12-16T23:18:30.420Z","updated_at":"2026-05-05T22:31:55.394Z","avatar_url":"https://github.com/giovannicalo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React WebRTC\n\n[![Build Status](https://github.com/giovannicalo/react-wrtc/actions/workflows/build.yml/badge.svg)](https://github.com/giovannicalo/react-wrtc/actions/workflows/build.yml)\n[![Coverage Status](https://coveralls.io/repos/github/giovannicalo/react-wrtc/badge.svg?branch=master)](https://coveralls.io/github/giovannicalo/react-wrtc?branch=master)\n\n## Installation\n\n```bash\nnpm install giovannicalo/react-wrtc\n```\n\n\u003e Not yet published to NPM. This will install it from GitHub.\n\n## Usage\n\n```javascript\nimport { Player, Provider, Stream } from \"react-wrtc\";\n\nconst stream = new Stream(\"ws://localhost:8080\");\n\nconst Foo = () =\u003e {\n    return \u003cProvider stream={stream}\u003e\n        \u003cPlayer source=\"foo\" /\u003e\n    \u003c/Provider\u003e;\n};\n\nexport default Foo;\n```\n\n## API\n\n### `Context`\n\n[React `Context`](https://reactjs.org/docs/context.html) wrapping a `Stream` instance.\n\n### `Player`\n\nVideo player component. It must be placed inside a `Provider`.\n\nProps are:\n\n* `debug?: boolean`: whether to render the debug overlay, defaults to `false`.\n* `onRender?(context: CanvasRenderingContext2D, request: Region, response: Region, stream: Stream): void` a function to be called on every video frame, defaults to `undefined`.\n* `source?: JsonSerializable`: a JSON-serializable identifier used to control what will be played, defaults to `undefined`.\n* any [React View](https://github.com/giovannicalo/react-view) props.\n* any [Styled Components](https://github.com/styled-components/styled-components) props.\n* any [HTML Canvas Element](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement) props.\n\n### `Provider`\n\nReact `Context` `Provider` wrapping a `Stream` instance.\n\nProps are:\n\n* `stream`: a `Stream` instance, defaults to `undefined`\n\n### `new Stream(apiUrl: string, apiOptions?: ApiClient.Options, decoder?: Decoder)`\n\nCreates an [API client](https://github.com/giovannicalo/js-wrtc-ws-api-client) with the given `apiOptions` that will try to connect to the server running at `apiUrl`. Upon success, it will initialize a [WebRTC connection](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection) and request to play the `source`s of any associated `Player`s.\n\nFor the WebSocket signaling connection to be successfully established, the API server should accept the following message:\n\n* `{ data: { role, ... }, event: \"handshake\" }`: use this for authentication.\n\nIt should also send the following message:\n\n* `{ data: { id }, event: \"handshake\" }`: use this to acknowledge a successful `handshake` and give the client an ID.\n\nFor the WebRTC connection to be established, the media server must accept the following messages:\n\n* `{ data: { sdp }, event: \"answer\" }`: use this to set its `RTCPeerConnection`'s `remoteDescription`.\n* `{ data: { height, regions, width }, event: \"state\" }`: use this to set frame and region dimensions and sources.\n\nIt must also send the following messages:\n\n* `{ data: { candidate }, event: \"candidate\" }`: when its own `RTCPeerConnection`'s `icecandidate` event occurs.\n* `{ data: { sdp }, event: \"offer\" }`: upon connection, with its `RTCPeerConnection`' `localDescription`.\n\nAn optional `decoder` can be provided to decode any metadata present in the video frames.\n\n#### `apiClient: ApiClient`\n\nThe `Stream`'s `ApiClient`. It can be used to e.g. send custom messages to the server.\n\n#### `cancelFrameCallback(handle: number): void`\n\nA convenient wrapper around [`cancelVideoFrameCallback`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement/cancelVideoFrameCallback) or [`cancelAnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame), depending on what's available.\n\n#### `close(): void`\n\nPermanently closes the `Stream`.\n\n#### `composer: Composer`\n\nThe `Stream`'s `Composer`. It can be used e.g. to add regions that will be used by a custom player.\n\n#### `decoder: Decoder`\n\nThe `Stream`'s metadata `Decoder`, if any.\n\n#### `metadata: any`\n\nMetadata for the current frame, if any.\n\n#### `requestFrameCallback(callback: () =\u003e void): number`\n\nA convenient wrapper around [`requestVideoFrameCallback`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement/requestVideoFrameCallback) or [`requestAnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame), depending on what's available.\n\n#### `video: HTMLVideoElement`\n\nThe `Stream`'s [`HTMLVideoElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement). It can be used e.g. to read custom parts of the stream.\n\n### `useStream(): Stream`\n\n[React Hook](https://reactjs.org/docs/hooks-intro.html) returning the context's `Stream` instance. It can only be used inside a `Provider`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiovannicalo%2Freact-wrtc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgiovannicalo%2Freact-wrtc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiovannicalo%2Freact-wrtc/lists"}