import React, { useState } from 'react'; import Button from '@dailyjs/shared/components/Button'; import Loader from '@dailyjs/shared/components/Loader'; import { Well } from '@dailyjs/shared/components/Well'; import PropTypes from 'prop-types'; /** * Splash * --- * - Checks our app is configured properly * - Creates a new Daily room for this session * - Calls the onJoin method with the room name and instructor (owner) status */ export const Splash = ({ onJoin, isConfigured }) => { const [fetching, setFetching] = useState(false); const [error, setError] = useState(false); async function createRoom(asInstructor) { // Create a new room for this class setError(false); setFetching(true); console.log(`🚪 Creating new demo room...`); // Create a room server side (using Next JS serverless) const res = await fetch('/api/createRoom', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ privacy: 'private', expiryMinutes: 10, }), }); const resJson = await res.json(); if (resJson.name) { onJoin(resJson.name, asInstructor); return; } setError(resJson.error || 'An unknown error occured'); setFetching(false); } return (
Daily
{(() => { // Application is not yet configured (there are missing globals, such as domain and dev key) if (!isConfigured) return ( <>

Not configured

Please ensure you have set both the{' '} DAILY_API_KEY and DAILY_DOMAIN{' '} environmental variables. An example can be found in the provided env.example file.

If you do not yet have a Daily developer account, please{' '} create one now {' '} . You can find your Daily API key on the{' '} developer page of the dashboard.

); // There was an error creating the room if (error) return (
{error} An error occured when trying to create a demo room. Please check that your environmental variables are correct and try again.
); // Loader whilst we create the room if (fetching) return ( <>

Creating room, please wait...

); // Introductory splash screen return ( <>

Live fitness example

This example demonstrates how to use Daily JS to create a live class experience. Please be sure to reference the project readme first.

Note: all rooms created with this demo will have a 5 minute expiry time. If you would like to create a longer running room, please set the DAILY_ROOM environmental variable to use your own custom room.


); })()}
); }; Splash.propTypes = { onJoin: PropTypes.func, isConfigured: PropTypes.bool, }; export default Splash;