canozgen9 / react-native-janus Goto Github PK
View Code? Open in Web Editor NEWJanus WebRTC Server client implementation in React Native.
Janus WebRTC Server client implementation in React Native.
Hello. I'm trying to build these package and examples in my environment, but it doesn't work, it just shows white screen.
I've trying to fix it out, I've trace it and in my console log, this.state.publishers.publisher
always print null
, so I changed like this:
on line 27
-- videoRoom.setOnStreamListener((stream) => {
-- this.setState(state => ({
-- publishers: [
-- ...state.publishers,
-- {
-- publisher: publisher,
-- stream: stream,
-- },
-- ],
-- }));
-- });
to
++ let tstream = videoRoom.setOnStreamListener()
++ this.setState({
++ publishers: [
++ ...this.state.publishers,
++ {
++ publisher: _publisher,
++ stream: tstream,
++ }
++ ]
++ });
after changing this, the publishers doesn't have null and now they have proper objects, but after this I got another error on render:
TypeError: Cannot read property 'toURL' of undefined
This error is located at:
in CellRenderer (at VirtualizedList.js:851)
in RCTView (at ScrollView.js:1063)
in RCTScrollView (at ScrollView.js:1196)
in ScrollView (at VirtualizedList.js:1280)
in VirtualizedList (at FlatList.js:633)
in FlatList (at test.js:181)
in RCTView (at test.js:173)
in JanusVideoRoomScreen
in RCTView (at SafeAreaView.js:41)
in ForwardRef(SafeAreaView) (at App.js:39)
in App (at renderApplication.js:45)
in RCTView (at AppContainer.js:109)
in RCTView (at AppContainer.js:135)
in AppContainer (at renderApplication.js:39)
How can I fix these? Can you give me a advice?
Also, here is my environment:
+-- @babel/[email protected]
+-- @babel/[email protected]
+-- @react-native-community/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
hi, first thanks for your library
im new in React native, im trying to re-write your code using hook, but got some error
undefined is not an object (evaluating 'stream.publishers')
here is my code, please help
import React, { useEffect, useState } from 'react';
import {StyleSheet,View,Text, Dimensions,
TouchableOpacity, SearchBar, StatusBar,
FlatList, Button,
PlatformColor} from "react-native" ;
import { useLayoutEffect } from 'react/cjs/react.production.min';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import * as RootNavigation from '../../utils/navigation/RootNavigation';
import { Janus } from 'react-native-janus';
import {mediaDevices, MediaStream, RTCIceCandidate, RTCPeerConnection, RTCSessionDescription, RTCView} from 'react-native-webrtc';
Janus.setDependencies({
RTCPeerConnection,
RTCSessionDescription,
RTCIceCandidate,
MediaStream,
});
export default function GroupCallScreen({navigation}){
const [stream, setStream] = useState()
const [publisher, setPublisher] = useState([])
useEffect(() => {
navigation.setOptions({
headerLeft: () => (<MaterialCommunityIcons
name='arrow-left'
size={24}
color={RootNavigation.defaultNavBtnColor}
onPress={() => {navigation.pop()}} />)
})
}, []);
_receivePublisher = async (publisher) => {
try {
let videoRoom = new JanusVideoRoomPlugin(this.janus);
videoRoom.setRoomID(1234);
videoRoom.setOnStreamListener((stream) => {
setStream(stream)
setPublisher(publisher)
});
await videoRoom.createPeer();
await videoRoom.connect();
await videoRoom.receive(this.videoRoom.getUserPrivateID(), publisher);
} catch (e) {
console.error(e);
}
};
_removePublisher = async (publisher) => {
try {
setPublisher(publishers.filter(pub => pub.publisher == null || pub.publisher.id !== publisherID))
} catch(e) {
console.error(e);
}
};
_initJanus = async (stream) => {
try {
setStream(null)
setPublisher([])
this.janus = new Janus('ws://${YOUR_JANUS_ADDRESS]:8188');
this.janus.setApiSecret('janusrocks');
await this.janus.init();
this.videoRoom = new JanusVideoRoomPlugin(this.janus);
this.videoRoom.setRoomID(1234);
this.videoRoom.setDisplayName('can');
this.videoRoom.setOnPublishersListener((publishers) => {
for (let i = 0; i < publishers.length; i++) {
this.receivePublisher(publishers[i]);
}
});
this.videoRoom.setOnPublisherJoinedListener((publisher) => {
this.receivePublisher(publisher);
});
this.videoRoom.setOnPublisherLeftListener((publisherID) => {
this.removePublisher(publisherID);
});
this.videoRoom.setOnWebRTCUpListener(async () => {
});
await this.videoRoom.createPeer();
await this.videoRoom.connect();
await this.videoRoom.join();
await this.videoRoom.publish(stream);
} catch(e) {
console.error(e);
}
};
_getMediaStream = async () => {
let isFront = true;
let sourceInfos = await mediaDevices.enumerateDevices();
let videoSourceId;
for (let i = 0; i < sourceInfos.length; i++) {
const sourceInfo = sourceInfos[i];
console.log(sourceInfo);
if (sourceInfo.kind == 'videoinput' && sourceInfo.facing == (isFront ? 'front' : 'environment')) {
videoSourceId = sourceInfo.deviceId;
}
}
let stream = await mediaDevices.getUserMedia({
audio: true,
video: {
facingMode: (isFront ? 'user' : 'environment'),
},
});
await this.initJanus(stream);
};
return(
<View style={{flex: 1, width: '100%', height: '100%', backgroundColor: 'white', flexDirection: 'row'}}>
<StatusBar translucent={true} barStyle={'light-content'}/>
<FlatList
data={stream.publishers}
numColumns={2}
keyExtractor={(item, index) => {
if (item.publisher === null) {
return `rtc-default`;
}
return `rtc-${item.publisher.id}`;
}}
renderItem={({item}) => (
<RTCView style={{
flex: 1,
height: (Dimensions.get('window').height / 2),
}} objectFit={'cover'} streamURL={item.stream.toURL()}/>
)}
/>
</View>
)
}
const GroupCallLeftHeader = (props) => {
return(
<View style={{
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center'
}}>
<MaterialCommunityIcons name='qrcode' color={navBtnColor} size={24} style={{ marginLeft: 12, marginRight: 24}}/>
<MaterialIcons name='business-center' color={navBtnColor} size={28} style={{ marginBottom: 3}}/>
</View>
)
}
hi,
how to implement to use 'https'
I am trying to add the data channel support to this plugin but the code refuses to work. Any insight on this. ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.