added TODO for broadcast, fixed videochat

This commit is contained in:
Jeff Emmett 2024-12-16 16:36:36 -05:00
parent d6ab873ec9
commit e0684a5520
2 changed files with 31 additions and 7 deletions

View File

@ -30,7 +30,10 @@ export class VideoChatShape extends BaseBoxShapeUtil<IVideoChatShape> {
} }
async ensureRoomExists(shape: IVideoChatShape) { async ensureRoomExists(shape: IVideoChatShape) {
if (shape.props.roomUrl !== null) return if (shape.props.roomUrl !== null) {
console.log("Room already exists:", shape.props.roomUrl)
return
}
try { try {
const apiKey = import.meta.env["VITE_DAILY_API_KEY"] const apiKey = import.meta.env["VITE_DAILY_API_KEY"]
@ -51,6 +54,9 @@ export class VideoChatShape extends BaseBoxShapeUtil<IVideoChatShape> {
}), }),
}) })
console.log("Response status:", response.status)
console.log("Response data:", await response.clone().json())
if (!response.ok) if (!response.ok)
throw new Error(`Failed to create room (${response.status})`) throw new Error(`Failed to create room (${response.status})`)
@ -59,22 +65,35 @@ export class VideoChatShape extends BaseBoxShapeUtil<IVideoChatShape> {
if (!url) throw new Error("Room URL is missing") if (!url) throw new Error("Room URL is missing")
this.editor.updateShape<IVideoChatShape>({ console.log("Room created successfully:", url)
console.log("Updating shape with new URL")
await this.editor.updateShape<IVideoChatShape>({
id: shape.id, id: shape.id,
type: "VideoChat", type: shape.type,
props: { ...shape.props, roomUrl: url }, props: {
...shape.props,
roomUrl: url,
},
}) })
console.log("Shape updated:", this.editor.getShape(shape.id))
} catch (error) { } catch (error) {
console.error("Failed to create Daily room:", error) console.error("Error in ensureRoomExists:", error)
throw error throw error
} }
} }
component(shape: IVideoChatShape) { component(shape: IVideoChatShape) {
const [hasPermissions, setHasPermissions] = useState(false) const [hasPermissions, setHasPermissions] = useState(false)
const [error, setError] = useState<Error | null>(null)
const [isLoading, setIsLoading] = useState(true)
useEffect(() => { useEffect(() => {
this.ensureRoomExists(shape).catch(console.error) setIsLoading(true)
this.ensureRoomExists(shape)
.catch(console.error)
.finally(() => setIsLoading(false))
}, []) }, [])
useEffect(() => { useEffect(() => {
@ -98,6 +117,10 @@ export class VideoChatShape extends BaseBoxShapeUtil<IVideoChatShape> {
requestPermissions() requestPermissions()
}, [shape.props.allowCamera, shape.props.allowMicrophone]) }, [shape.props.allowCamera, shape.props.allowMicrophone])
if (error) {
return <div>Error creating room: {error.message}</div>
}
if (!shape.props.roomUrl) { if (!shape.props.roomUrl) {
return ( return (
<div <div
@ -111,7 +134,7 @@ export class VideoChatShape extends BaseBoxShapeUtil<IVideoChatShape> {
borderRadius: "4px", borderRadius: "4px",
}} }}
> >
Creating room... {isLoading ? "Creating room... Please wait" : "Creating room..."}
</div> </div>
) )
} }

View File

@ -283,6 +283,7 @@ export const overrides: TLUiOverrides = {
} }
}, },
}, },
//TODO: MAKE THIS WORK, ADD USER PERMISSIONING TO JOIN BROADCAST?
broadcastView: { broadcastView: {
id: "broadcast-view", id: "broadcast-view",
label: "Broadcast View", label: "Broadcast View",