crappy event handling
This commit is contained in:
parent
f93cabb99d
commit
3dc0135b48
|
@ -19,7 +19,11 @@ function App() {
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<Sidebar usersData={roomData} />
|
<Sidebar usersData={roomData} />
|
||||||
<Meeting setConferenceData={setConferenceData} userInfo={userInfo} />
|
<Meeting
|
||||||
|
conferenceData={conferenceData}
|
||||||
|
setConferenceData={setConferenceData}
|
||||||
|
userInfo={userInfo}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,11 @@ export interface ConferenceData {
|
||||||
breakoutRoom: boolean; // whether the current room is a breakout room
|
breakoutRoom: boolean; // whether the current room is a breakout room
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DisplayNameChangeEvent {
|
||||||
|
id: string; // the id of the participant that changed their display name
|
||||||
|
displayname: string; // the new display name (WTF why is capilization different)
|
||||||
|
}
|
||||||
|
|
||||||
function videoConferenceJoinedListener(
|
function videoConferenceJoinedListener(
|
||||||
setConferenceData: (newData: ConferenceData) => void,
|
setConferenceData: (newData: ConferenceData) => void,
|
||||||
videoConferenceJoinedEvent: ConferenceData
|
videoConferenceJoinedEvent: ConferenceData
|
||||||
|
@ -13,4 +18,32 @@ function videoConferenceJoinedListener(
|
||||||
setConferenceData(videoConferenceJoinedEvent);
|
setConferenceData(videoConferenceJoinedEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { videoConferenceJoinedListener };
|
function displayNameChangeListener(
|
||||||
|
setDisplayNameChangedEvent: (newData: DisplayNameChangeEvent) => void,
|
||||||
|
displayNameChangeEvent: DisplayNameChangeEvent
|
||||||
|
) {
|
||||||
|
setDisplayNameChangedEvent(displayNameChangeEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayNameChangeListenerA(
|
||||||
|
conferenceData: ConferenceData | undefined,
|
||||||
|
setConferenceData: (newData: ConferenceData) => void,
|
||||||
|
displayNameChangeEvent: DisplayNameChangeEvent
|
||||||
|
) {
|
||||||
|
console.log(
|
||||||
|
"[Rooms] displayNameChangeListener",
|
||||||
|
displayNameChangeEvent,
|
||||||
|
conferenceData
|
||||||
|
);
|
||||||
|
if (conferenceData && conferenceData.id == displayNameChangeEvent.id)
|
||||||
|
setConferenceData({
|
||||||
|
...conferenceData,
|
||||||
|
displayName: displayNameChangeEvent.displayname,
|
||||||
|
} as ConferenceData);
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
videoConferenceJoinedListener,
|
||||||
|
displayNameChangeListener,
|
||||||
|
displayNameChangeListenerA,
|
||||||
|
};
|
||||||
|
|
|
@ -4,16 +4,35 @@ import { UserInfo } from "./types";
|
||||||
import curry from "just-curry-it";
|
import curry from "just-curry-it";
|
||||||
import {
|
import {
|
||||||
ConferenceData,
|
ConferenceData,
|
||||||
|
DisplayNameChangeEvent,
|
||||||
|
displayNameChangeListener,
|
||||||
|
displayNameChangeListenerA,
|
||||||
videoConferenceJoinedListener,
|
videoConferenceJoinedListener,
|
||||||
} from "../../background/jitsi/eventListeners";
|
} from "../../background/jitsi/eventListeners";
|
||||||
|
import { useCallback } from "react";
|
||||||
|
import useJitsiEventCapture from "../../hooks/useJitsiEventCapture";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
roomName: string;
|
roomName: string;
|
||||||
userInfo: UserInfo;
|
userInfo: UserInfo;
|
||||||
|
conferenceData: ConferenceData | undefined;
|
||||||
setConferenceData: (newData: ConferenceData) => void;
|
setConferenceData: (newData: ConferenceData) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function JitsiEntrypoint({ roomName, userInfo, setConferenceData }: Props) {
|
function JitsiEntrypoint({
|
||||||
|
roomName,
|
||||||
|
userInfo,
|
||||||
|
conferenceData,
|
||||||
|
setConferenceData,
|
||||||
|
}: Props) {
|
||||||
|
const { setDisplayNameChangeEvent } = useJitsiEventCapture(
|
||||||
|
curry(displayNameChangeListenerA)(conferenceData)(setConferenceData)
|
||||||
|
);
|
||||||
|
|
||||||
|
// const displayNameChangeEventListenerCallback = useCallback(() => {
|
||||||
|
//
|
||||||
|
// }, [conferenceData, setConferenceData]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<JitsiMeeting
|
<JitsiMeeting
|
||||||
domain={JITSI_DOMAIN}
|
domain={JITSI_DOMAIN}
|
||||||
|
@ -28,13 +47,14 @@ function JitsiEntrypoint({ roomName, userInfo, setConferenceData }: Props) {
|
||||||
interfaceConfigOverwrite={{}}
|
interfaceConfigOverwrite={{}}
|
||||||
userInfo={userInfo}
|
userInfo={userInfo}
|
||||||
onApiReady={(externalApi) => {
|
onApiReady={(externalApi) => {
|
||||||
// here you can attach custom event listeners to the Jitsi Meet External API
|
|
||||||
// you can also store it locally to execute commands
|
|
||||||
|
|
||||||
externalApi.addEventListener(
|
externalApi.addEventListener(
|
||||||
"videoConferenceJoined",
|
"videoConferenceJoined",
|
||||||
curry(videoConferenceJoinedListener)(setConferenceData)
|
curry(videoConferenceJoinedListener)(setConferenceData)
|
||||||
);
|
);
|
||||||
|
externalApi.addEventListener(
|
||||||
|
"displayNameChange",
|
||||||
|
curry(displayNameChangeListener)(setDisplayNameChangeEvent)
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
getIFrameRef={(iframeRef) => {
|
getIFrameRef={(iframeRef) => {
|
||||||
iframeRef.style.height = "100%";
|
iframeRef.style.height = "100%";
|
||||||
|
|
|
@ -6,11 +6,12 @@ import { UserInfo } from "../jitsi/types";
|
||||||
import MeetingNameInput from "./MeetingNameInput";
|
import MeetingNameInput from "./MeetingNameInput";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
conferenceData: ConferenceData | undefined;
|
||||||
setConferenceData: (newData: ConferenceData) => void;
|
setConferenceData: (newData: ConferenceData) => void;
|
||||||
userInfo: UserInfo;
|
userInfo: UserInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Meeting({ setConferenceData, userInfo }: Props) {
|
function Meeting({ conferenceData, setConferenceData, userInfo }: Props) {
|
||||||
const { roomName, updateRoomName, submitRoomName } = useRoomName();
|
const { roomName, updateRoomName, submitRoomName } = useRoomName();
|
||||||
const [meetingStarted, setMeetingStarted] = useState(false);
|
const [meetingStarted, setMeetingStarted] = useState(false);
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ function Meeting({ setConferenceData, userInfo }: Props) {
|
||||||
if (meetingStarted) {
|
if (meetingStarted) {
|
||||||
return (
|
return (
|
||||||
<JitsiEntrypoint
|
<JitsiEntrypoint
|
||||||
|
conferenceData={conferenceData}
|
||||||
roomName={roomName}
|
roomName={roomName}
|
||||||
userInfo={userInfo}
|
userInfo={userInfo}
|
||||||
setConferenceData={setConferenceData}
|
setConferenceData={setConferenceData}
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
.sidebar {
|
.sidebar {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar h3 {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-footer {
|
.sidebar-footer {
|
||||||
|
@ -12,6 +21,10 @@
|
||||||
max-width: 60px;
|
max-width: 60px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebar-full {
|
||||||
|
max-width: 220px;
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar-hidden > .sidebar-footer {
|
.sidebar-hidden > .sidebar-footer {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
|
|
@ -9,7 +9,7 @@ function useConferenceData(
|
||||||
const [conferenceData, setConferenceDataLocal] = useState<ConferenceData>();
|
const [conferenceData, setConferenceDataLocal] = useState<ConferenceData>();
|
||||||
|
|
||||||
const setConferenceData = (newData: ConferenceData) => {
|
const setConferenceData = (newData: ConferenceData) => {
|
||||||
console.log("[Rooms] set conferenceData");
|
console.log("[Rooms] set conferenceData", conferenceData);
|
||||||
sendMessage(JSON.stringify(newData));
|
sendMessage(JSON.stringify(newData));
|
||||||
setConferenceDataLocal(newData);
|
setConferenceDataLocal(newData);
|
||||||
setUserInfo({ displayName: newData.displayName, email: "" });
|
setUserInfo({ displayName: newData.displayName, email: "" });
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
|
import { DisplayNameChangeEvent } from "../background/jitsi/eventListeners";
|
||||||
|
|
||||||
|
function useJitsiEventCapture(displayNameChangeHandler: Function) {
|
||||||
|
const [displayNameChangeEvent, setDisplayNameChangeEventLocal] =
|
||||||
|
useState<DisplayNameChangeEvent>();
|
||||||
|
// const [displayNameChangeHandler, setDisplayNameChangeHandler] =
|
||||||
|
// useState<Function>();
|
||||||
|
|
||||||
|
const setDisplayNameChangeEvent = useCallback(
|
||||||
|
(newValue: DisplayNameChangeEvent) => {
|
||||||
|
console.log("[Rooms] newValue", newValue, displayNameChangeEvent);
|
||||||
|
if (displayNameChangeEvent != newValue) {
|
||||||
|
setDisplayNameChangeEventLocal(newValue);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[setDisplayNameChangeEventLocal]
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("[Rooms] displayNameChangeHandler", displayNameChangeEvent);
|
||||||
|
displayNameChangeHandler &&
|
||||||
|
displayNameChangeEvent &&
|
||||||
|
displayNameChangeHandler(displayNameChangeEvent);
|
||||||
|
}, [displayNameChangeEvent]);
|
||||||
|
|
||||||
|
return { setDisplayNameChangeEvent };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useJitsiEventCapture;
|
|
@ -18,7 +18,7 @@ function useLocalUser() {
|
||||||
|
|
||||||
function getUserInfoFromCookie(): UserInfo {
|
function getUserInfoFromCookie(): UserInfo {
|
||||||
let cookie = getCookie(USER_COOKIE_NAME);
|
let cookie = getCookie(USER_COOKIE_NAME);
|
||||||
console.log("[Rooms] getUserNameFromCookie 1", cookie);
|
console.log("[Rooms] getUserNameFromCookie", cookie);
|
||||||
if (cookie) return JSON.parse(cookie);
|
if (cookie) return JSON.parse(cookie);
|
||||||
return {
|
return {
|
||||||
displayName: "unknown traveller",
|
displayName: "unknown traveller",
|
||||||
|
@ -27,6 +27,7 @@ function getUserInfoFromCookie(): UserInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
function storeUserInfoInCookie(userInfo: UserInfo) {
|
function storeUserInfoInCookie(userInfo: UserInfo) {
|
||||||
|
console.log("[Rooms] storeUserInfoInCookie", userInfo);
|
||||||
setCookie(USER_COOKIE_NAME, JSON.stringify(userInfo));
|
setCookie(USER_COOKIE_NAME, JSON.stringify(userInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue