diff --git a/src/ConferenceCallManagerHooks.js b/src/ConferenceCallManagerHooks.js index db93e51f..d6c990ea 100644 --- a/src/ConferenceCallManagerHooks.js +++ b/src/ConferenceCallManagerHooks.js @@ -91,18 +91,22 @@ export function useClient(homeserverUrl) { const authStore = localStorage.getItem("matrix-auth-store"); if (authStore) { - const { user_id, device_id, access_token } = JSON.parse(authStore); + const { user_id, device_id, access_token, guest } = + JSON.parse(authStore); - const client = await initClient({ - baseUrl: homeserverUrl, - accessToken: access_token, - userId: user_id, - deviceId: device_id, - }); + const client = await initClient( + { + baseUrl: homeserverUrl, + accessToken: access_token, + userId: user_id, + deviceId: device_id, + }, + guest + ); localStorage.setItem( "matrix-auth-store", - JSON.stringify({ user_id, device_id, access_token }) + JSON.stringify({ user_id, device_id, access_token, guest }) ); return client; @@ -153,7 +157,7 @@ export function useClient(homeserverUrl) { } }, []); - const registerGuest = useCallback(async (displayName) => { + const registerGuest = useCallback(async () => { try { const registrationClient = matrix.createClient(homeserverUrl); @@ -170,9 +174,13 @@ export function useClient(homeserverUrl) { true ); + await client.setProfileInfo("displayname", { + displayname: `Guest ${client.getUserIdLocalpart()}`, + }); + localStorage.setItem( "matrix-auth-store", - JSON.stringify({ user_id, device_id, access_token }) + JSON.stringify({ user_id, device_id, access_token, guest: true }) ); setState({ client, loading: false, authenticated: true }); diff --git a/src/ErrorModal.jsx b/src/ErrorModal.jsx new file mode 100644 index 00000000..c0cb3100 --- /dev/null +++ b/src/ErrorModal.jsx @@ -0,0 +1,30 @@ +import React, { useEffect } from "react"; +import { Center, Content, Modal } from "./Layout"; +import { Link } from "react-router-dom"; +import { ErrorMessage } from "./Input"; +import styles from "./ErrorModal.module.css"; + +export function ErrorModal({ error }) { + useEffect(() => { + console.error(error); + }, [error]); + + return ( + +
+ +

Error

+
+ {error.message} +

+ Login +

+

+ Register +

+
+
+
+
+ ); +} diff --git a/src/ErrorModal.module.css b/src/ErrorModal.module.css new file mode 100644 index 00000000..84d6701a --- /dev/null +++ b/src/ErrorModal.module.css @@ -0,0 +1,9 @@ +.errorModalContent { + display: flex; + flex-direction: column; + align-items: center; +} + +.errorModalContent p { + margin-bottom: 0; +} diff --git a/src/GuestAuthPage.jsx b/src/GuestAuthPage.jsx index 94b16216..08bd363d 100644 --- a/src/GuestAuthPage.jsx +++ b/src/GuestAuthPage.jsx @@ -14,26 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, { useState, useRef, useCallback } from "react"; +import React, { useState, useEffect } from "react"; import styles from "./GuestAuthPage.module.css"; -import { useLocation, useHistory, Link } from "react-router-dom"; +import { useLocation, useHistory } from "react-router-dom"; import { Header, LeftNav } from "./Header"; -import { Button, FieldRow, InputField, ErrorMessage } from "./Input"; -import { Center, Content, Info, Modal } from "./Layout"; +import { Center, Content, Modal } from "./Layout"; +import { ErrorModal } from "./ErrorModal"; export function GuestAuthPage({ onLoginAsGuest }) { - const displayNameRef = useRef(); const history = useHistory(); const location = useLocation(); const [error, setError] = useState(); - const onSubmitLoginForm = useCallback( - (e) => { - e.preventDefault(); - onLoginAsGuest(displayNameRef.current.value).catch(setError); - }, - [onLoginAsGuest, location, history] - ); + useEffect(() => { + onLoginAsGuest("Guest " + Math.round(Math.random() * 999)).catch(setError); + }, [onLoginAsGuest, location, history]); return (
@@ -43,46 +38,7 @@ export function GuestAuthPage({ onLoginAsGuest }) {
-

Login As Guest

-
- - - - {error && ( - - {error.message} - - )} - - - -
- - - Sign in - - {" or "} - - Create account - - + {error ? :
Loading...
}
diff --git a/src/Room.jsx b/src/Room.jsx index 06436533..099c15d4 100644 --- a/src/Room.jsx +++ b/src/Room.jsx @@ -25,7 +25,7 @@ import { ScreenshareButton, } from "./RoomButton"; import { Header, LeftNav, RightNav, CenterNav } from "./Header"; -import { Button, ErrorMessage } from "./Input"; +import { Button } from "./Input"; import { GroupCallState } from "matrix-js-sdk/src/webrtc/groupCall"; import VideoGrid, { useVideoGridLayout, @@ -35,6 +35,7 @@ import { useGroupCall } from "matrix-react-sdk/src/hooks/useGroupCall"; import { useCallFeed } from "matrix-react-sdk/src/hooks/useCallFeed"; import { useMediaStream } from "matrix-react-sdk/src/hooks/useMediaStream"; import { fetchGroupCall } from "./ConferenceCallManagerHooks"; +import { ErrorModal } from "./ErrorModal"; function useLoadGroupCall(client, roomId) { const [state, setState] = useState({ @@ -70,7 +71,7 @@ export function Room({ client }) { if (error) { return (
- +
); } @@ -160,20 +161,6 @@ export function EnteringRoomView() { ); } -export function LoadingErrorView({ error }) { - useEffect(() => { - console.error(error); - }, [error]); - - return ( - <> -
- {error.message} -
- - ); -} - function RoomSetupView({ roomName, state, diff --git a/src/Room.module.css b/src/Room.module.css index df2f8924..8e992dcb 100644 --- a/src/Room.module.css +++ b/src/Room.module.css @@ -80,10 +80,12 @@ limitations under the License. flex: 1; justify-content: center; align-items: center; + flex-direction: column; } .centerMessage p { display: block; + margin-bottom: 0; } .roomContainer {