反应元网格简单
一个简单易于使用的模块,有助于使视频呼叫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 ( ) ;
} ;