1.4.2 • Published 2 years ago

react-native-webrtc-simple v1.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-native-webrtc-simple

A simple and easy to use module that help in making video call for React Native. Implemented using react-native-webrtc.

Getting started

npm install react-native-webrtc-simple --save

or

yarn add react-native-webrtc-simple

Now we need to install react-native-webrtc

Document

WebrtcSimple

MethodDescription
startCreate connections
stopStop connections
getSessionIdGet your session id
getLocalStreamGet your video stream
getRemoteStreamGet remote video stream
listeningsListenings call events
eventsMethod call events

WebrtcSimple.start

ValueTypeDescription
optionalObject or nullOption peer configuration (https://peerjs.com/)
keyStringYour session id

Peer-to-Peer

WebrtcSimple.listenings.callEvents

ValueTypeDescription
START_CALLStringYour start call status
RECEIVED_CALLStringCall received status
ACCEPT_CALLStringCall aceept status
END_CALLStringCall end status
MESSAGEStringListenings a message

WebrtcSimple.events

MethodParamsDescription
callsessionId:String, data:anyInitiate a call
acceptCallNoAccept a call
endCallNoReject a call
switchCameraNoSwitch camera
videoEnableNoOn/Off video
audioEnableNoOn/Off audio
messagedata:anyEvents send message

Multiple Peer

WebrtcSimple.listenings.callEvents

ValueTypeDescription
START_GROUP_CALLStringYour start call status
RECEIVED_GROUP_CALLStringCall received status
JOIN_GROUP_CALLStringCall received status
LEAVE_GROUP_CALLStringCall reject status

WebrtcSimple.events

MethodParamsDescription
groupCallgroupSessionId: string[], userData: object = {}Start group call
joinGrouparrSessionId: string[]Join group call
leaveGroupNoLeave group call
addStreamsessionId: stringCreate a stream
switchCameraNoSwitch camera
videoEnableNoOn/Off video
audioEnableNoOn/Off audio
messagedata:anyEvents send 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();
};
1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.1.27

3 years ago

0.1.26

3 years ago

0.1.20

3 years ago

0.1.21

3 years ago

0.1.22

3 years ago

0.1.23

3 years ago

0.1.24

3 years ago

0.1.25

3 years ago

0.1.17

3 years ago

0.1.18

3 years ago

0.1.15

3 years ago

0.1.16

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.14

3 years ago

0.1.10

3 years ago

0.1.8

3 years ago

0.1.9

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.4

3 years ago

0.1.5

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago