react-native-webrtc-simple
Un module simple et facile à utiliser qui aide à passer l'appel vidéo pour React Native. Implémenté à l'aide de React-Native-WEBRTC.
Commencer
npm install react - native - webrtc - simple -- save
ou
yarn add react - native - webrtc - simple
Nous devons maintenant installer React-Native-wEBRTC
Document
Webrtcsimple
| Méthode | Description |
|---|
| commencer | Créer des connexions |
| arrêt | Connexions d'arrêt |
| getSessionId | Obtenez votre identifiant de session |
| getLocalstream | Obtenez votre flux vidéo |
| getRemoteStream | Obtenez un flux vidéo distant |
| écoute | Les écoutes appellent les événements |
| événements | Événements d'appel de méthode |
Webrtcsimple.start
| Valeur | Taper | Description |
|---|
| facultatif | Objet ou nul | Configuration des pairs d'option (https://peerjs.com/) |
| clé | Chaîne | Votre identifiant de session |
Pairs
Webrtcsimple.listenings.callevents
| Valeur | Taper | Description |
|---|
| Start_call | Chaîne | Votre statut d'appel de début |
| Reçu_Call | Chaîne | État d'appel reçu |
| Accept_Call | Chaîne | Appeler le statut Aceept |
| End_call | Chaîne | Statut de fin d'appel |
| MESSAGE | Chaîne | Écoute un message |
Webrtcsimple.events
| Méthode | Paramètres | Description |
|---|
| appel | SessionId: chaîne, données: tout | Lancer un appel |
| concept | Non | Accepter un appel |
| finir | Non | Rejeter un appel |
| caméra de commutation | Non | Commutation de la caméra |
| vidéo vidéo | Non | Vidéo en marche / arrêt |
| audio-interdiction | Non | Audio marche / arrêt |
| message | Données: tout | Les événements envoient un message |
Plusieurs pairs
Webrtcsimple.listenings.callevents
| Valeur | Taper | Description |
|---|
| Start_group_call | Chaîne | Votre statut d'appel de début |
| Reçu_group_call | Chaîne | État d'appel reçu |
| Join_group_call | Chaîne | État d'appel reçu |
| LEART_GROUP_CALL | Chaîne | Statut de rejet d'appel |
Webrtcsimple.events
| Méthode | Paramètres | Description |
|---|
| calcul des groupes | GroupeSessionId: String [], userData: object = {} | Démarrer l'appel de groupe |
| joingroup | arrsessionId: String [] | Rejoignez l'appel de groupe |
| groupe de feuilles | Non | Laisser un appel de groupe |
| complexe | sessiond: chaîne | Créer un flux |
| caméra de commutation | Non | Commutation de la caméra |
| vidéo vidéo | Non | Vidéo en marche / arrêt |
| audio-interdiction | Non | Audio marche / arrêt |
| message | Données: tout | Les événements envoient un message |
Usage
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 ( ) ;
} ;