反應元網格簡單
一個簡單易於使用的模塊,有助於使視頻呼叫React Native。使用React-Native-Webrtc實施。
入門
npm install react - native - webrtc - simple -- save
或者
yarn add react - native - webrtc - simple
現在我們需要安裝React-Native-Webrtc
文件
webrtcsimple
| 方法 | 描述 |
|---|
| 開始 | 創建連接 |
| 停止 | 停止連接 |
| getsessiond | 獲取您的會話ID |
| getLocalStream | 獲取視頻流 |
| getRemotestream | 獲取遠程視頻流 |
| 聽 | 傾聽電話事件 |
| 事件 | 方法調用事件 |
webrtcsimple.start
| 價值 | 類型 | 描述 |
|---|
| 選修的 | 對像或null | 選項對等配置(https://peerjs.com/) |
| 鑰匙 | 細繩 | 您的會話ID |
點對點
webrtcsimple.listenings.callevents
| 價值 | 類型 | 描述 |
|---|
| start_call | 細繩 | 您的開始通話狀態 |
| 接收_CALL | 細繩 | 呼叫接收狀態 |
| accept_call | 細繩 | 調用Aceept狀態 |
| end_call | 細繩 | 呼叫結束狀態 |
| 訊息 | 細繩 | 聆聽消息 |
webrtcsimple.events
| 方法 | 參數 | 描述 |
|---|
| 稱呼 | SessionID:字符串,數據:任何 | 啟動電話 |
| 接受通話 | 不 | 接受電話 |
| endcall | 不 | 拒絕電話 |
| SwitchCamera | 不 | 開關相機 |
| 可視頻 | 不 | 開/關視頻 |
| 聲音含糊 | 不 | 打開/關閉音頻 |
| 訊息 | 數據:任何 | 事件發送消息 |
多個同伴
webrtcsimple.listenings.callevents
| 價值 | 類型 | 描述 |
|---|
| start_group_call | 細繩 | 您的開始通話狀態 |
| RECTER_GROUP_CALL | 細繩 | 呼叫接收狀態 |
| join_group_call | 細繩 | 呼叫接收狀態 |
| felw_group_call | 細繩 | 致電拒絕狀態 |
webrtcsimple.events
| 方法 | 參數 | 描述 |
|---|
| GroupCall | groupsessession:string [],userData:object = {} | 啟動組呼叫 |
| Joingroup | arrsessionid:string [] | 加入組電話 |
| 離開組 | 不 | 離開小組電話 |
| addstream | SessionID:字符串 | 創建一個流 |
| SwitchCamera | 不 | 開關相機 |
| 可視頻 | 不 | 開/關視頻 |
| 聲音含糊 | 不 | 打開/關閉音頻 |
| 訊息 | 數據:任何 | 事件發送消息 |
用法
import WebrtcSimple from 'react-native-webrtc-simple' ;
useEffect ( ( ) => {
const configuration = {
optional : null ,
key : Math . random ( ) . toString ( 36 ) . substr ( 2 , 4 ) , //optional
} ;
WebrtcSimple . start ( configuration )
. then ( ( status ) => {
if ( status ) {
const stream = WebrtcSimple . getLocalStream ( ) ;
console . log ( 'My stream: ' , stream ) ;
WebrtcSimple . getSessionId ( ( id : string ) => {
console . log ( 'UserId: ' , id ) ;
} ) ;
}
} )
. catch ( ) ;
WebrtcSimple . listenings . callEvents ( ( type , userData ) => {
console . log ( 'Type: ' , type ) ;
// START_CALL
// RECEIVED_CALL
// ACCEPT_CALL
// END_CALL
// MESSAGE
// START_GROUP_CALL
// RECEIVED_GROUP_CALL
// JOIN_GROUP_CALL
// LEAVE_GROUP_CALL
} ) ;
WebrtcSimple . listenings . getRemoteStream ( ( remoteStream ) => {
console . log ( 'Remote stream' , remoteStream ) ;
} ) ;
} , [ ] ) ;
const callToUser = ( userId ) => {
const data = { } ;
WebrtcSimple . events . call ( userId , data ) ;
} ;
const acceptCall = ( ) => {
WebrtcSimple . events . acceptCall ( ) ;
} ;
const endCall = ( ) => {
WebrtcSimple . events . endCall ( ) ;
} ;
const switchCamera = ( ) => {
WebrtcSimple . events . switchCamera ( ) ;
} ;
const video = ( enable : boolean ) => {
WebrtcSimple . events . videoEnable ( enable ) ;
} ;
const audio = ( enable : boolean ) => {
WebrtcSimple . events . audioEnable ( enable ) ;
} ;
const sendMessage = ( message : any ) => {
WebrtcSimple . events . message ( message ) ;
} ;
const groupCall = ( sessionId : string [ ] ) => {
const data = { } ;
WebrtcSimple . events . groupCall ( sessionId , data ) ;
} ;
const joinGroup = ( groupSessionId : string [ ] ) => {
WebrtcSimple . events . joinGroup ( groupSessionId ) ;
} ;
const leaveGroup = ( ) => {
WebrtcSimple . events . leaveGroup ( ) ;
} ;