File size: 3,545 Bytes
76b9248
 
1e8ff3b
 
 
 
 
b3de037
 
1e8ff3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f66623b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b3de037
f66623b
b3de037
f66623b
 
 
 
 
 
 
 
 
 
 
 
b3de037
f66623b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b3de037
f66623b
 
1e8ff3b
f66623b
1e8ff3b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Button } from "@mantine/core";
import { IconArrowRight, IconChevronRight } from "@tabler/icons-react";
import { useState } from "react";
import { apiUrl } from "../utils";

export default function CreateRoom({ onCreateRoom }) {
  const [fetching, setFetching] = useState(false);
  const [roomUrl, setRoomUrl] = useState();
  const [showManual, setShowManual] = useState(false);

  async function create() {
    setFetching(true);

    const resp = await fetch(`${apiUrl}/create`, {
      method: "POST",
      mode: "cors",
      cache: "no-cache",
      credentials: "same-origin",
      headers: {
        "Content-Type": "application/json",
      },
    });

    const data = await resp.json();

    if (!data.room_url) {
      setFetching(false);
      console.log("error creating room");
    }

    onCreateRoom(data.room_url);
  }

  return (
    <main className="min-h-screen flex items-center justify-center bg-zinc-100">
      <div className="flex-1 bg-white shadow sm:rounded-lg max-w-xl mx-auto">
        <div className="px-4 py-5 sm:p-6">
          <h3 className="text-base font-semibold leading-6 text-gray-900">
            Stable Diffusion + WebRTC Latency Demo
          </h3>
          <div className="mt-2 text-sm text-gray-500">
            <p>
              Demonstrates implementating WebRTC via daily.co to create
              real-time vision inference. Currently implemented using SD 1.5
              Turbo with Control Net.
            </p>
          </div>
          <div className="mt-5">
            <Button
              rightSection={<IconArrowRight stroke={2} className="h-5 w-5" />}
              size="md"
              loading={fetching}
              onClick={() => create()}
            >
              Join
            </Button>
          </div>

          <hr className="my-6" />

          <div
            className="inline-flex items-center gap-1 text-sm text-gray-500 cursor-pointer"
            onClick={() => setShowManual(!showManual)}
          >
            Join an existing room
            <IconChevronRight
              stoke={2}
              className={`w-4 h-4 text-gray-300 transition-transform ${
                showManual && "rotate-90"
              }`}
            />
          </div>

          {showManual && (
            <div className="mt-5 sm:flex sm:items-center">
              <div className="w-full">
                <label htmlFor="room" className="sr-only">
                  Daily Room URL
                </label>
                <input
                  type="text"
                  name="room"
                  id="room"
                  className="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
                  placeholder="https://..."
                  onChange={(e) => setRoomUrl(e.target.value)}
                />
              </div>
              <button
                type="submit"
                onClick={() => onCreateRoom(roomUrl)}
                className="mt-3 inline-flex w-full items-center justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 sm:ml-3 sm:mt-0 sm:w-auto"
              >
                Join
              </button>
            </div>
          )}
        </div>
      </div>
    </main>
  );
}