Skip to content

Commit

Permalink
Merge branch 'main' into fix/issue-6466
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaboleken committed Nov 27, 2024
2 parents 448a75e + 174fc97 commit 0b90aea
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 205 deletions.
4 changes: 2 additions & 2 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AppRegistry } from 'react-native';
//import App from './src/App';
import App from './src/App';
//import App from './src/Play';
//import App from './src/Peer';
import App from './src/Conference';
//import App from './src/Conference';
import { name as appName } from './app.json';

AppRegistry.registerComponent(appName, () => App);
62 changes: 44 additions & 18 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {useAntMedia, rtc_view} from '@antmedia/react-native-ant-media';

import InCallManager from 'react-native-incall-manager';

var publishStreamId:string;

export default function App() {
var defaultStreamName = 'streamTest1';
const webSocketUrl = 'ws://test.antmedia.io:5080/WebRTCAppEE/websocket';
Expand All @@ -19,7 +21,7 @@ export default function App() {
const streamNameRef = useRef<string>(defaultStreamName);
const [localMedia, setLocalMedia] = useState('');
const [isPlaying, setIsPlaying] = useState(false);

const [isWaitingWebsocketInit, setIsWaitingWebsocketInit] = useState(false);

let localStream: any = useRef(null);

Expand Down Expand Up @@ -50,6 +52,19 @@ export default function App() {
console.log('publish_finished');
InCallManager.stop();
setIsPlaying(false);
adaptor.closeWebSocket();
break;
case 'local_stream_updated':
console.log('local_stream_updated');
verify();
break;
case 'websocket_not_initialized':
setIsWaitingWebsocketInit(true);
adaptor.initialiseWebSocket();
break;
case 'websocket_closed':
console.log('websocket_closed');
adaptor.stopLocalStream();
break;
default:
console.log(command);
Expand All @@ -69,22 +84,33 @@ export default function App() {
debug: true,
});

useEffect(() => {
const verify = () => {
console.log('in verify');

if (adaptor.localStream.current && adaptor.localStream.current.toURL()) {
console.log('in verify if adaptor local stream', adaptor.localStream);
const generateRandomString = (length: number): string => {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
const charactersLength = characters.length;

console.log(
'localStream.current.toURL()',
adaptor.localStream.current.toURL(),
);

return setLocalMedia(adaptor.localStream.current.toURL());
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charactersLength);
result += characters.charAt(randomIndex);
}
return result;
};

const verify = () => {
console.log('in verify');
if (adaptor.localStream.current && adaptor.localStream.current.toURL()) {
console.log('in verify if adaptor local stream', adaptor.localStream);
if (isWaitingWebsocketInit) {
setIsWaitingWebsocketInit(false);
publishStreamId = generateRandomString(12);
adaptor.publish(publishStreamId);
}
setTimeout(verify, 5000);
};
return setLocalMedia(adaptor.localStream.current.toURL());
}
setTimeout(verify, 5000);
};

useEffect(() => {
verify();
}, [adaptor.localStream]);

Expand All @@ -98,15 +124,15 @@ export default function App() {
if (!adaptor) {
return;
}

adaptor.publish(streamNameRef.current);
publishStreamId = generateRandomString(12);
adaptor.publish(publishStreamId);
}, [adaptor]);

const handleStop = useCallback(() => {
if (!adaptor) {
return;
}
adaptor.stop(streamNameRef.current);
adaptor.stop(publishStreamId);
}, [adaptor]);

return (
Expand Down
Loading

0 comments on commit 0b90aea

Please sign in to comment.