I am working on Video/Audio streaming functionality in my project and I am using react-native-webrtc library to implement the above features. Initially I am rendering local stream on ComponentDidMount()
componentDidMount () {
this.getLocalStream();
}
getLocalStream() {
mediaDevices.enumerateDevices().then(sourceInfos => {
console.log("mediaDevices.enumerateDevices", sourceInfos);
let videoSourceId;
for (let i = 0; i < sourceInfos.length; i++) {
const sourceInfo = sourceInfos[i];
if(sourceInfo.kind === "videoinput" && sourceInfo.facing === (this.state.isFront ? "front" : "environment")) {
videoSourceId = sourceInfo.id;
}
}
mediaDevices.getUserMedia({
audio: true,
// IF simulator/audio call is running for webrtc then video to false.
video: this.state.isSwitching,
facingMode: (this.state.isFront ? "user" : "environment"),
optional: (videoSourceId ? [{sourceId: videoSourceId}] : [])
}
)
.then(stream => {
InCallManager.start({media: 'audio'});
InCallManager.startRingtone('_BUNDLE_');
if (this.state.isSwitching === false) {
InCallManager.setSpeakerphoneOn(true);
InCallManager.setForceSpeakerphoneOn(true);
}
this.setState({videoUrl: stream.toURL(),})
localStream = stream;
pc.addStream(localStream);
connectedUser = false;
createPC(this.state.roomID,true);
})
.catch(error => {
// Log error
console.log('Error',error.message);
this.setState({loading: false});
});
});
}
After its successful rendering, I am initiating an offer() to another peer; however the method of RTCPeerConnection pc.createOffer() is not able to trigger and it is not executing the function, logic inside it. I tried many ways to make method trigger but it was unsuccessful.
const createPC = (socketId, isOffer) => {
pcPeers = {
...pcPeers,
[socketId]: pc,
};
if (isOffer){
pc.createOffer(function(desc) {
log("fgf");
console.log('createOffer', desc);
pc.setLocalDescription(desc, function () {
console.log('setLocalDescription', pc.localDescription);
socket.emit('exchange', {'to': socketId, 'sdp': pc.localDescription });
}, logError);
}, logError);
}
// On Add Stream:
pc.onaddstream = event => {
//console.log('onaddstream', event.stream);
const remoteList = this.state.remoteList;
remoteList[socketId] = event.stream.toURL();
this.setState({
remoteList: remoteList,
});
};
// ice candidates
pc.onicecandidate = event => {
log('Howeeeee');
if (event.candidate) {
socket.emit('exchange', { to: socketId, candidate: event.candidate });
}
};
return pc;
}
What was the cause of not getting fired even after providing all the parameters to the methods. As I am new to React Native, Can someone assist me where was I committing mistake. Help will be highly appreciated.
I solved my issue by downgrading react-native-webrtc version to 1.67.1 which is quite compatible with react native 0.59.0.