Skip to content

Commit

Permalink
Add createWebRTCAdaptor function
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaboleken committed Jan 6, 2025
1 parent 9b8f770 commit 00ed391
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion react/src/Components/PublisherRequestTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Stack from "@mui/material/Stack";
import Grid from "@mui/material/Grid";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import {styled, useTheme} from "@mui/material/styles";
import {styled} from "@mui/material/styles";
import { SvgIcon } from "./SvgIcon";

const PublisherRequestName = styled(Typography)(({ theme }) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,49 @@
// src/PublisherRequestTab.test.js
// src/PublisherRequestTab.tet.js

import React from 'react';
import { render } from '@testing-library/react';
import { ConferenceContext } from 'pages/AntMedia';
import PublisherRequestTab from "../../Components/PublisherRequestTab";
import theme from "../../styles/theme";
import {ThemeList} from "../../styles/themeList";
import {ThemeProvider} from "@mui/material";

const contextValue = {
initialized: true,
setLocalVideo: jest.fn(),
localVideoCreate: jest.fn(),
setIsJoining: jest.fn(),
joinRoom: jest.fn(),
localVideo: {},
setSpeedTestObject: jest.fn(),
makeId: jest.fn(),
requestSpeakerList: [
"test1",
"test2",
],
setRequestSpeakerList: jest.fn(),
approveBecomeSpeakerRequest: jest.fn(),
rejectBecomeSpeakerRequest: jest.fn(),
};

// Mock the useContext hook
jest.mock('react', () => ({
...jest.requireActual('react'),
useContext: jest.fn(),
}));


describe('Publisher Request Tab Component', () => {

beforeEach(() => {
// Reset the mock implementation before each test
jest.clearAllMocks();

React.useContext.mockImplementation(input => {
if (input === ConferenceContext) {
return contextValue;
}
return jest.requireActual('react').useContext(input);
});
});


it('renders without crashing', () => {
render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<PublisherRequestTab />
<PublisherRequestTab
approveBecomeSpeakerRequest={jest.fn()}
rejectBecomeSpeakerRequest={jest.fn()}
requestSpeakerList={["test1", "test2"]}
publishStreamId={"test0"}
/>
</ThemeProvider>
);
});

it('renders the publisher request items', () => {
const { getByText } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<PublisherRequestTab />
<PublisherRequestTab
approveBecomeSpeakerRequest={jest.fn()}
rejectBecomeSpeakerRequest={jest.fn()}
requestSpeakerList={["test1", "test2"]}
publishStreamId={"test0"}
/>
</ThemeProvider>
);

Expand All @@ -67,25 +52,39 @@ describe('Publisher Request Tab Component', () => {
});

it('calls the approveBecomeSpeakerRequest function when the allow button is clicked', () => {
let mockApproveBecomeSpeakerRequest = jest.fn();

const { getByTestId } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<PublisherRequestTab />
<PublisherRequestTab
approveBecomeSpeakerRequest={mockApproveBecomeSpeakerRequest}
rejectBecomeSpeakerRequest={jest.fn()}
requestSpeakerList={["test1", "test2"]}
publishStreamId={"test0"}
/>
</ThemeProvider>
);

getByTestId('approve-become-speaker-test1').click();
expect(contextValue.approveBecomeSpeakerRequest).toHaveBeenCalledWith('test1');
expect(mockApproveBecomeSpeakerRequest).toHaveBeenCalledWith('test1');
});

it('calls the rejectBecomeSpeakerRequest function when the deny button is clicked', () => {
let mockRejectBecomeSpeakerRequest = jest.fn();

const { getByTestId } = render(
<ThemeProvider theme={theme(ThemeList.Green)}>
<PublisherRequestTab />
<PublisherRequestTab
approveBecomeSpeakerRequest={jest.fn()}
rejectBecomeSpeakerRequest={mockRejectBecomeSpeakerRequest}
requestSpeakerList={["test1", "test2"]}
publishStreamId={"test0"}
/>
</ThemeProvider>
);

getByTestId('reject-become-speaker-test1').click();
expect(contextValue.rejectBecomeSpeakerRequest).toHaveBeenCalledWith('test1');
expect(mockRejectBecomeSpeakerRequest).toHaveBeenCalledWith('test1');
});

});
49 changes: 25 additions & 24 deletions react/src/pages/AntMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -1343,31 +1343,32 @@ function AntMedia(props) {
}

useEffect(() => {


reconnecting = false;
publishReconnected = true;
playReconnected = true;
console.log("++ createWebRTCAdaptor");
//here we check if audio or video device available and wait result
//according to the result we modify mediaConstraints

checkDevices().then(() => {
var adaptor = new WebRTCAdaptor({
websocket_url: websocketURL,
mediaConstraints: mediaConstraints,
peerconnection_config: peerconnection_config,
isPlayMode: isPlayOnly, // onlyDataChannel: isPlayOnly,
debug: true,
callback: infoCallback,
callbackError: errorCallback,
purposeForTest: "main-adaptor"
});
setWebRTCAdaptor(adaptor)
createWebRTCAdaptor();
//just run once when component is mounted
}, []); //eslint-disable-line

function createWebRTCAdaptor() {
reconnecting = false;
publishReconnected = true;
playReconnected = true;
console.log("++ createWebRTCAdaptor");
//here we check if audio or video device available and wait result
//according to the result we modify mediaConstraints

checkDevices().then(() => {
var adaptor = new WebRTCAdaptor({
websocket_url: websocketURL,
mediaConstraints: mediaConstraints,
peerconnection_config: peerconnection_config,
isPlayMode: isPlayOnly, // onlyDataChannel: isPlayOnly,
debug: true,
callback: infoCallback,
callbackError: errorCallback,
purposeForTest: "main-adaptor"
});

//just run once when component is mounted
}, []); //eslint-disable-line
setWebRTCAdaptor(adaptor)
});
}

useEffect(() => {
if (devices.length > 0) {
Expand Down

0 comments on commit 00ed391

Please sign in to comment.