Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit 89b689e

Browse files
committed
Initial Commit
0 parents  commit 89b689e

33 files changed

Lines changed: 49759 additions & 0 deletions

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build/
2+
dist/
3+
node_modules/
4+
.snapshots/
5+
*.min.js

.eslintrc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"extends": [
4+
"standard",
5+
"standard-react",
6+
"plugin:prettier/recommended",
7+
"plugin:react/recommended",
8+
"prettier/standard",
9+
"prettier/react",
10+
"plugin:@typescript-eslint/eslint-recommended"
11+
],
12+
"env": {
13+
"node": true
14+
},
15+
"parserOptions": {
16+
"ecmaVersion": 2020,
17+
"ecmaFeatures": {
18+
"legacyDecorators": true,
19+
"jsx": true
20+
}
21+
},
22+
"settings": {
23+
"react": {
24+
"version": "16"
25+
}
26+
},
27+
"rules": {
28+
"space-before-function-paren": 0,
29+
"react/prop-types": 0,
30+
"react/jsx-handler-names": 0,
31+
"react/jsx-fragments": 0,
32+
"react/no-unused-prop-types": 0,
33+
"jsx-uses-vars": true,
34+
"jsx-uses-react": true,
35+
"import/export": 0
36+
}
37+
}

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
# See https://help.github.com/ignore-files/ for more about ignoring files.
3+
4+
# dependencies
5+
node_modules
6+
7+
# builds
8+
build
9+
# dist hosts the github release
10+
.rpt2_cache
11+
12+
# misc
13+
.DS_Store
14+
.env
15+
.env.local
16+
.env.development.local
17+
.env.test.local
18+
.env.production.local
19+
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"singleQuote": true,
3+
"jsxSingleQuote": true,
4+
"semi": false,
5+
"tabWidth": 2,
6+
"bracketSpacing": true,
7+
"jsxBracketSameLine": false,
8+
"arrowParens": "always",
9+
"trailingComma": "none"
10+
}

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- 12
4+
- 10

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Agora RTC SDK React Wrapper
2+
3+
A react wrapper for [Agora RTC NG SDK](https://www.npmjs.com/package/agora-rtc-sdk-ng).
4+
This wrapper supports **React >= v16.8**
5+
6+
## Install
7+
```bash
8+
npm install git://github.com/AgoraIO-Community/agora-rtc-react#v1.0.0
9+
```
10+
11+
## Usage
12+
```tsx
13+
import React from "react";
14+
import { AgoraVideoPlayer, createClient, createMicrophoneAndCameraTracks } from "agora-rtc-react";
15+
16+
const config = {mode: "rtc", codec: "vp8"}
17+
18+
const useClient = createClient(config);
19+
const useMicrophoneAndCameraTracks = createMicrophoneAndCameraTracks();
20+
21+
const App = () => {
22+
const client = useClient();
23+
const { ready, tracks } = useMicrophoneAndCameraTracks();
24+
25+
return (
26+
ready && <AgoraVideoPlayer videoTrack={tracks[1]} />
27+
)
28+
}
29+
30+
```
31+
32+
## Example
33+
A full videocall example using the wrapper can be found [here](example.md).
34+
35+
## Reference
36+
You can view the methods in the wrapper [here](api.md).

api.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# API Reference
2+
3+
## Wrapper Functions
4+
5+
| Factory Method | Parameters (? = optional)| Return Value | Reference
6+
| ----- | ---- | ---- | ---- |
7+
| createClient | [ClientConfig](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/clientconfig.html) | A hook that gives a [client object](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iagorartcclient.html) | [AgoraRTC.createClient](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iagorartc.html#createclient) |
8+
| createMicrophoneAndCameraTracks | [AudioConfig?](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/microphoneaudiotrackinitconfig.html), [VideoConfig?](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/cameravideotrackinitconfig.html) | A hook that gives an object containg tracks ([microphone](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/imicrophoneaudiotrack.html) and [camera](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/icameravideotrack.html)) and a state variable `ready` which is set to true when the feeds are initialised | [createMicrophoneAndCameraTracks](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iagorartc.html#createmicrophoneandcameratracks) |
9+
| createBufferSourceAudioTrack | [BufferSourceAudioTrackInitConfig](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/buffersourceaudiotrackinitconfig.html) | A hook that gives an object containg the [audio track](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/ibuffersourceaudiotrack.html) and a state variable `ready` which is set to true when the feeds are initialised | [AgoraRTC.createBufferSourceAudioTrack](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iagorartc.html#createbuffersourceaudiotrack) |
10+
| createCameraVideoTrack | [CameraVideoTrackInitConfig?](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/cameravideotrackinitconfig.html)| A hook that gives an object containg the [camera video track](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/icameravideotrack.html) and a state variable `ready` which is set to true when the feeds are initialised | [AgoraRTC.createCameraVideoTrack](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iagorartc.html#createcameravideotrack) |
11+
| createCustomAudioTrack |[CustomAudioTrackInitConfig](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/customaudiotrackinitconfig.html)| A hook that gives an object containg the [custom audio track](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/ilocalaudiotrack.html) and a state variable `ready` which is set to true when the feeds are initialised | [AgoraRTC.createCustomAudioTrack](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iagorartc.html#createcustomaudiotrack) |
12+
| createCustomVideoTrack |[CustomVideoTrackInitConfig](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/customvideotrackinitconfig.html)| A hook that gives an object containg the [custom video track](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/ilocalvideotrack.html) and a state variable `ready` which is set to true when the feeds are initialised | [AgoraRTC.createCustomVideoTrack](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iagorartc.html#createcustomvideotrack) |
13+
| createMicrophoneAudioTrack |[MicrophoneAudioTrackInitConfig?](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/microphoneaudiotrackinitconfig.html)| A hook that gives an object containg the [microphone audio track](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/imicrophoneaudiotrack.html) and a state variable `ready` which is set to true when the feeds are initialised | [AgoraRTC.createMicrophoneAudioTrack](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iagorartc.html#createmicrophoneaudiotrack) |
14+
| createScreenVideoTrack |[ScreenVideoTrackInitConfig?](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/screenvideotrackinitconfig.html), [withAudio?](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iagorartc.html#createscreenvideotrack)| A hook that gives an object containg tracks ([audio](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/ilocalaudiotrack.html) and [video](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/ilocalvideotrack.html)) and a state variable `ready` which is set to true when the feeds are initialised | [AgoraRTC.createScreenVideoTrack](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iagorartc.html#createscreenvideotrack) |
15+
16+
All methods take in the same parameters as the NG SDK. You can visit the official docs for each methods to know more.
17+
18+
## Components
19+
20+
### AgoraVideoPlayer
21+
This component lets you display a video track in the DOM.
22+
You can pass in the `videoTrack` as prop along with other props that get passed to the rendered div containing your video.
23+
#### ***Required Prop***
24+
videoTrack: [ILocalVideoTrack](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/ilocalvideotrack.html) | [IRemoteVideoTrack](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iremotevideotrack.html) | [ICameraVideoTrack](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/icameravideotrack.html)
25+
26+
Example:
27+
```tsx
28+
<AgoraVideoPlayer videoTrack={track} className="video" key={key} style={{height: '100px'}} />
29+
```
30+
## Wrapper Functions Examples
31+
32+
### createClient
33+
```tsx
34+
import React from "react";
35+
import { createClient } from "agora-rtc-react";
36+
37+
const config = {mode: "rtc", codec: "vp8"}
38+
const useClient = createClient(config);
39+
40+
const App = () => {
41+
const client = useClient();
42+
43+
useEffect(() => {
44+
client.join(appId, name, token, null);
45+
}, [])
46+
47+
return (
48+
<p>{client.uid}</p>
49+
)
50+
}
51+
```
52+
53+
### createMicrophoneAndCameraTracks
54+
```tsx
55+
import React from "react";
56+
import { createMicrophoneAndCameraTracks, AgoraVideoPlayer } from "agora-rtc-react";
57+
58+
const useMicrophoneAndCameraTracks = createMicrophoneAndCameraTracks();
59+
60+
const App = () => {
61+
const { ready, tracks } = useMicrophoneAndCameraTracks();
62+
63+
return (
64+
ready && <AgoraVideoPlayer videoTrack={tracks[1]} />
65+
)
66+
}
67+
```
68+
All other create methods use a similar pattern.
69+
70+
## Other AgoraRTC Methods
71+
72+
For other RTC SDK methods you can directly use them from the [AgoraRTC](https://docs.agora.io/en/Video/API%20Reference/web_ng/interfaces/iagorartc.html) object. Look at the example using the wrapper for group videocall [here](example.md) to understand better.

dist/index.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* add css module styles here (optional) */
2+
3+
._3ybTi {
4+
margin: 2em;
5+
padding: 0.5em;
6+
border: 2px solid #000;
7+
font-size: 2em;
8+
text-align: center;
9+
}

dist/index.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import { BufferSourceAudioTrackInitConfig, CameraVideoTrackInitConfig, ClientConfig, CustomAudioTrackInitConfig, CustomVideoTrackInitConfig, IAgoraRTCClient, IBufferSourceAudioTrack, ICameraVideoTrack, ILocalAudioTrack, ILocalVideoTrack, IMicrophoneAudioTrack, IRemoteVideoTrack, MicrophoneAudioTrackInitConfig, ScreenVideoTrackInitConfig } from 'agora-rtc-sdk-ng';
3+
export declare const createClient: (config: ClientConfig) => () => IAgoraRTCClient;
4+
export declare function createMicrophoneAndCameraTracks(audioConfig?: MicrophoneAudioTrackInitConfig | undefined, videoConfig?: CameraVideoTrackInitConfig | undefined): () => {
5+
ready: boolean;
6+
tracks: [IMicrophoneAudioTrack, ICameraVideoTrack] | null;
7+
};
8+
export declare function createBufferSourceAudioTrack(config: BufferSourceAudioTrackInitConfig): () => {
9+
ready: boolean;
10+
track: IBufferSourceAudioTrack | null;
11+
};
12+
export declare function createCameraVideoTrack(config?: CameraVideoTrackInitConfig): () => {
13+
ready: boolean;
14+
track: ICameraVideoTrack | null;
15+
};
16+
export declare function createCustomAudioTrack(config: CustomAudioTrackInitConfig): () => {
17+
ready: boolean;
18+
track: ILocalAudioTrack | null;
19+
};
20+
export declare function createCustomVideoTrack(config: CustomVideoTrackInitConfig): () => {
21+
ready: boolean;
22+
track: ILocalVideoTrack | null;
23+
};
24+
export declare function createMicrophoneAudioTrack(config?: MicrophoneAudioTrackInitConfig): () => {
25+
ready: boolean;
26+
track: IMicrophoneAudioTrack | null;
27+
};
28+
export declare function createScreenVideoTrack(config: ScreenVideoTrackInitConfig, withAudio?: 'enable' | 'disable' | 'auto'): () => {
29+
ready: boolean;
30+
tracks: ILocalVideoTrack | [ILocalVideoTrack, ILocalAudioTrack];
31+
};
32+
export declare const AgoraVideoPlayer: (props: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
33+
videoTrack: ILocalVideoTrack | IRemoteVideoTrack | ICameraVideoTrack;
34+
}) => JSX.Element;

0 commit comments

Comments
 (0)