Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: rewrite video-calling tutorial #866

Merged
merged 4 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions sample-apps/react/stream-video-react-tutorial/.env-example

This file was deleted.

79 changes: 40 additions & 39 deletions sample-apps/react/stream-video-react-tutorial/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
import { useEffect, useState } from 'react';
import {
Call,
CallControls,
CallingState,
SpeakerLayout,
StreamCall,
StreamTheme,
StreamVideo,
StreamVideoClient,
PaginatedGridLayout,
CallControls,
CallingState,
useCallCallingState,
User,
} from '@stream-io/video-react-sdk';

import '@stream-io/video-react-sdk/dist/css/styles.css';
import './style.css';

export default function App() {
const [client, setClient] = useState<StreamVideoClient | undefined>();
const [call, setCall] = useState<Call | undefined>();

useEffect(() => {
const user = {
id: import.meta.env.VITE_STREAM_USER_ID,
};
const token = import.meta.env.VITE_STREAM_USER_TOKEN;
const apiKey = 'REPLACE_WITH_API_KEY'; // the API key can be found in the "Credentials" section
const token = 'REPLACE_WITH_TOKEN'; // the token can be found in the "Credentials" section
const userId = 'REPLACE_WITH_USER_ID'; // the user id can be found in the "Credentials" section
const callId = 'REPLACE_WITH_CALL_ID'; // the call id can be found in the "Credentials" section

const client = new StreamVideoClient({
apiKey: import.meta.env.VITE_STREAM_API_KEY,
user,
token,
});
setClient(client);
const user: User = {
id: userId,
name: 'Oliver',
image: 'https://getstream.io/random_svg/?id=oliver&name=Oliver',
};

return () => {
client?.disconnectUser();
};
}, []);
// initialize the StreamVideoClient
const client = new StreamVideoClient({ apiKey, user, token });

export default function App() {
const [call, setCall] = useState<Call>();
useEffect(() => {
const call = client?.call('default', import.meta.env.VITE_STREAM_CALL_ID);
call?.join({ create: true });
setCall(call);
const myCall = client.call('default', callId);
myCall.join({ create: true }).catch((err) => {
console.error(`Failed to join the call`, err);
});

setCall(myCall);

return () => {
if (call?.state?.callingState !== CallingState.LEFT) {
call?.leave();
}
setCall(undefined);
myCall.leave().catch((err) => {
console.error(`Failed to leave the call`, err);
});
};
}, [client]);
}, []);

if (!client || !call) {
return null;
}
if (!call) return null;

return (
<StreamVideo client={client}>
<StreamCall call={call}>
<StreamTheme className="video__call">
<UI />
</StreamTheme>
<UILayout />
</StreamCall>
</StreamVideo>
);
}

export const UI = () => {
export const UILayout = () => {
const callingState = useCallCallingState();
if (callingState !== CallingState.JOINED) {
return <div>Loading...</div>;
}

return (
<>
<PaginatedGridLayout />
<StreamTheme>
<SpeakerLayout participantsBarPosition="bottom" />
<CallControls />
</>
</StreamTheme>
);
};
27 changes: 8 additions & 19 deletions sample-apps/react/stream-video-react-tutorial/src/style.css
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
@import '@stream-io/video-react-sdk/dist/css/styles.css';

body, html {
body,
html {
height: 100%;
width: 100%;
margin: 0;
font-family: sans-serif;
}

#root {
display: flex;
justify-content: space-between;
align-items: center;
height: 100%;
.str-video {
background-color: #272a30;
color: #ffffff;
height: 100dvh;
width: 100%;
background-color: black;

}

.video__call {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 15px;
height: 100%;
width: 100%;
min-width: 0;
max-width: 100%;
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": false,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
Expand Down
Loading