import React, { useEffect, useState } from 'react'; import { Button, Platform, StyleSheet, Text, TextInput, View, TouchableOpacity } from 'react-native'; import { RTCPeerConnection, RTCView, mediaDevices } from 'react-native-webrtc'; import WebrtcSimple from 'react-native-webrtc-simple' import { callToUser, joinGroup, leaveGroup, listeningRemoteCall, peerConnection, reconnect, startGroup, startStream } from 'react-native-webrtc-simple/WebRtcSimple/peer'; import { globalCall, GlobalCallUI } from 'react-native-webrtc-simple/UIKit'; import { jsxOpeningElement } from '@babel/types'; export const globalCallRef = React.createRef(); // import io from 'socket.io-client'; const App = _props => { const [sessionId, setSessionId] = useState(null); const [calleid, setCalleeId] = useState(null); const [lstream, setLstream] = useState(null); const [isFront, setisFront] = useState(true); const configuration = { "iceServers": [{ "url": "stun:stun.l.google.com:19302" }] }; const pc = new RTCPeerConnection(configuration); useEffect(() => { console.log('hjyh'); // pc.onicecandidate = (event) => { // console.log(event); // } // pc.connectionState = (event) => { // console.log(event); // } }, []); const start = () => { mediaDevices.enumerateDevices().then(sourceInfos => { // console.log(sourceInfos); let videoSourceId; for (let i = 0; i < sourceInfos.length; i++) { const sourceInfo = sourceInfos[i]; if (sourceInfo.kind == "videoinput" && sourceInfo.facing == (isFront ? "front" : "environment")) { videoSourceId = sourceInfo.deviceId; } } mediaDevices.getUserMedia({ audio: true, video: { width: 110, height: 110, frameRate: 20, facingMode: (isFront ? "user" : "environment"), deviceId: videoSourceId } }) .then(s => { setLstream(s) pc.addStream(s) }) .catch(esquery => { // Log error }); }); } const pec = () => { pc.onicecandidate = (e) => { console.log("Candidate:" + e) } pc.onicecandidateerror = () => { console.log("createOffer:") } pc.createOffer().then(desc => { pc.setLocalDescription(desc).then(() => { console.log(desc); }); }); } const answer = () => { pc.createAnswer().then(desc => { pc.setLocalDescription(desc).then(() => { console.log("answer:" + desc); }) } ) } const stop = () => { console.log('stop'); if (lstream) { lstream.release(); setLstream(null); setSessionId(null) } }; const callToUser = (callId: string) => { pec(); }; return ( { lstream && } {sessionId} start()} style={{ backgroundColor: 'green', width: '90%', height: 30, alignItems: 'center', borderRadius: 30, marginTop: 20 }} > START stop()} style={{ backgroundColor: 'green', width: '90%', height: 30, alignItems: 'center', borderRadius: 30, marginTop: 20 }} > STOP setCalleeId(t)} style={{ width: '90%', height: 50, color: 'black', borderWidth: 1, marginTop: 10, borderRadius: 30 }} /> callToUser()} style={{ backgroundColor: 'green', width: '90%', height: 30, alignItems: 'center', borderRadius: 30, marginTop: 20 }} > Call answer()} style={{ backgroundColor: 'green', width: '90%', height: 30, alignItems: 'center', borderRadius: 30, marginTop: 20 }} > Answer Call {/* {userId} {userId && (