} {memoizedApp}
-
- >
+ [componentForState, roomExp]
);
};
diff --git a/dailyjs/basic-call/pages/api/createRoom.js b/dailyjs/basic-call/pages/api/createRoom.js
index 1c8ff2b..d8e4a02 100644
--- a/dailyjs/basic-call/pages/api/createRoom.js
+++ b/dailyjs/basic-call/pages/api/createRoom.js
@@ -1,4 +1,6 @@
export default async function handler(req, res) {
+ const { privacy, expiryMinutes } = req.body;
+
if (req.method === 'POST') {
console.log(`Creating room on domain ${process.env.DAILY_DOMAIN}`);
@@ -9,8 +11,9 @@ export default async function handler(req, res) {
Authorization: `Bearer ${process.env.DAILY_API_KEY}`,
},
body: JSON.stringify({
+ privacy: privacy || 'public',
properties: {
- exp: Math.round(Date.now() / 1000) + 5 * 60, // expire in 5 minutes
+ exp: Math.round(Date.now() / 1000) + (expiryMinutes || 5) * 60, // expire in x minutes
eject_at_room_exp: true,
},
}),
diff --git a/dailyjs/live-fitness/components/Splash/Splash.js b/dailyjs/live-fitness/components/Splash/Splash.js
index 798a7bb..93068e8 100644
--- a/dailyjs/live-fitness/components/Splash/Splash.js
+++ b/dailyjs/live-fitness/components/Splash/Splash.js
@@ -1,17 +1,23 @@
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';
-export const Splash = ({ domain, onJoin, isConfigured }) => {
- // const [joinAsInstructor, setJoinAsInstructor] = useState(false);
+/**
+ * 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);
- const [room, setRoom] = useState('');
-
- async function createRoom() {
- // Create a room
+ async function createRoom(asInstructor) {
+ // Create a new room for this class
setError(false);
setFetching(true);
@@ -23,13 +29,16 @@ export const Splash = ({ domain, onJoin, isConfigured }) => {
headers: {
'Content-Type': 'application/json',
},
+ body: JSON.stringify({
+ privacy: 'private',
+ expiryMinutes: 10,
+ }),
});
const resJson = await res.json();
if (resJson.name) {
- setFetching(false);
- setRoom(resJson.name);
+ onJoin(resJson.name, asInstructor);
return;
}
@@ -39,25 +48,111 @@ export const Splash = ({ domain, onJoin, isConfigured }) => {
return (
-
+
-
-
-
+
+
- {!isConfigured ? (
-
- You must set Stuff
-
- ) : (
-
- )}
+ {(() => {
+ // 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 (
+ <>
+
+ 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.
+
+
+
+ >
+ );
+ })()}
-
@@ -95,7 +214,6 @@ export const Splash = ({ domain, onJoin, isConfigured }) => {
};
Splash.propTypes = {
- domain: PropTypes.string,
onJoin: PropTypes.func,
isConfigured: PropTypes.bool,
};
diff --git a/dailyjs/live-fitness/pages/[room].js b/dailyjs/live-fitness/pages/[room].js
index e69de29..deee255 100644
--- a/dailyjs/live-fitness/pages/[room].js
+++ b/dailyjs/live-fitness/pages/[room].js
@@ -0,0 +1,101 @@
+import React, { useState, useEffect } from 'react';
+import App from '@dailyjs/basic-call/components/App';
+import Loader from '@dailyjs/shared/components/Loader';
+import { CallProvider } from '@dailyjs/shared/contexts/CallProvider';
+import { MediaDeviceProvider } from '@dailyjs/shared/contexts/MediaDeviceProvider';
+import { ParticipantsProvider } from '@dailyjs/shared/contexts/ParticipantsProvider';
+import { TracksProvider } from '@dailyjs/shared/contexts/TracksProvider';
+import { UIStateProvider } from '@dailyjs/shared/contexts/UIStateProvider';
+import { WaitingRoomProvider } from '@dailyjs/shared/contexts/WaitingRoomProvider';
+import getDemoProps from '@dailyjs/shared/lib/demoProps';
+import { useRouter } from 'next/router';
+import PropTypes from 'prop-types';
+
+/**
+ * Room page
+ * ---
+ */
+export default function Room({ room, instructor, domain }) {
+ const [token, setToken] = useState();
+ const [tokenError, setTokenError] = useState();
+
+ const router = useRouter();
+
+ // Redirect to a 404 if we do not have a room
+ useEffect(
+ () => (!room || !domain) && router.replace('/not-found'),
+ [room, domain, router]
+ );
+
+ // Fetch a meeting token
+ useEffect(() => {
+ if (token || !room) {
+ return;
+ }
+
+ // We're using a simple Next serverless function to generate meeting tokens
+ // which could be replaced with your own serverside method that authenticates
+ // users / sets room owner status, user ID, user names etc
+ async function getToken() {
+ console.log(`🪙 Fetching meeting token for room '${room}'`);
+
+ const res = await fetch('/api/token', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ roomName: room, isOwner: !!instructor }),
+ });
+
+ const resJson = await res.json();
+
+ if (!resJson?.token) {
+ setTokenError(resJson?.error || true);
+ }
+
+ console.log(`🪙 Meeting token received`);
+
+ setToken(resJson.token);
+ }
+
+ getToken();
+ }, [token, room, instructor]);
+
+ if (!token) {
+ return