Re-enable debugger and fix fetchRoom
This commit is contained in:
parent
c29ce50757
commit
d514f682d3
4 changed files with 53 additions and 44 deletions
|
|
@ -17,10 +17,11 @@ limitations under the License.
|
||||||
import EventEmitter from "events";
|
import EventEmitter from "events";
|
||||||
|
|
||||||
export class ConferenceCallDebugger extends EventEmitter {
|
export class ConferenceCallDebugger extends EventEmitter {
|
||||||
constructor(manager) {
|
constructor(client, groupCall) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.manager = manager;
|
this.client = client;
|
||||||
|
this.groupCall = groupCall;
|
||||||
|
|
||||||
this.debugState = {
|
this.debugState = {
|
||||||
users: new Map(),
|
users: new Map(),
|
||||||
|
|
@ -29,11 +30,11 @@ export class ConferenceCallDebugger extends EventEmitter {
|
||||||
|
|
||||||
this.bufferedEvents = [];
|
this.bufferedEvents = [];
|
||||||
|
|
||||||
// this.manager.on("call", this._onCall);
|
client.on("event", this._onEvent);
|
||||||
// this.manager.on("debugstate", this._onDebugStateChanged);
|
groupCall.on("call", this._onCall);
|
||||||
// this.manager.client.on("event", this._onEvent);
|
groupCall.on("debugstate", this._onDebugStateChanged);
|
||||||
// this.manager.on("entered", this._onEntered);
|
groupCall.on("entered", this._onEntered);
|
||||||
// this.manager.on("left", this._onLeft);
|
groupCall.on("left", this._onLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onEntered = () => {
|
_onEntered = () => {
|
||||||
|
|
@ -55,7 +56,7 @@ export class ConferenceCallDebugger extends EventEmitter {
|
||||||
};
|
};
|
||||||
|
|
||||||
_onEvent = (event) => {
|
_onEvent = (event) => {
|
||||||
if (!this.manager.entered) {
|
if (!this.groupCall.entered) {
|
||||||
this.bufferedEvents.push(event);
|
this.bufferedEvents.push(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +65,7 @@ export class ConferenceCallDebugger extends EventEmitter {
|
||||||
const type = event.getType();
|
const type = event.getType();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
roomId === this.manager.room.roomId &&
|
roomId === this.groupCall.room.roomId &&
|
||||||
(type.startsWith("m.call.") ||
|
(type.startsWith("m.call.") ||
|
||||||
type === "me.robertlong.call.info" ||
|
type === "me.robertlong.call.info" ||
|
||||||
type === "m.room.member")
|
type === "m.room.member")
|
||||||
|
|
@ -376,8 +377,8 @@ export class ConferenceCallDebugger extends EventEmitter {
|
||||||
.filter((stat) => stat.type === "remote-outbound-rtp")
|
.filter((stat) => stat.type === "remote-outbound-rtp")
|
||||||
.map(processRemoteOutboundRTPStats);
|
.map(processRemoteOutboundRTPStats);
|
||||||
|
|
||||||
this.manager.client.sendEvent(
|
this.client.sendEvent(
|
||||||
this.manager.room.roomId,
|
this.groupCall.room.roomId,
|
||||||
"me.robertlong.call.info",
|
"me.robertlong.call.info",
|
||||||
event
|
event
|
||||||
);
|
);
|
||||||
|
|
@ -417,8 +418,8 @@ export class ConferenceCallDebugger extends EventEmitter {
|
||||||
peerConnection.addEventListener(
|
peerConnection.addEventListener(
|
||||||
"icecandidateerror",
|
"icecandidateerror",
|
||||||
({ errorCode, url, errorText }) => {
|
({ errorCode, url, errorText }) => {
|
||||||
this.manager.client.sendEvent(
|
this.client.sendEvent(
|
||||||
this.manager.room.roomId,
|
this.groupCall.room.roomId,
|
||||||
"me.robertlong.call.ice_error",
|
"me.robertlong.call.ice_error",
|
||||||
{
|
{
|
||||||
call_id: call.callId,
|
call_id: call.callId,
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import matrix from "matrix-js-sdk";
|
import matrix from "matrix-js-sdk";
|
||||||
|
import { ConferenceCallDebugger } from "./ConferenceCallDebugger";
|
||||||
|
|
||||||
// https://stackoverflow.com/a/9039885
|
// https://stackoverflow.com/a/9039885
|
||||||
function isIOS() {
|
function isIOS() {
|
||||||
|
|
@ -63,20 +64,8 @@ async function initClient(clientOptions, guest) {
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchRoom(client, roomId, join, timeout = 5000) {
|
export async function fetchRoom(client, roomIdOrAlias, timeout = 5000) {
|
||||||
let room = client.getRoom(roomId);
|
const { roomId } = await client.joinRoom(roomIdOrAlias);
|
||||||
|
|
||||||
if (room) {
|
|
||||||
return room;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (join) {
|
|
||||||
room = await client.joinRoom(roomId);
|
|
||||||
|
|
||||||
if (room) {
|
|
||||||
return room;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let timeoutId;
|
let timeoutId;
|
||||||
|
|
@ -297,7 +286,7 @@ function getParticipants(groupCall) {
|
||||||
return [...groupCall.participants];
|
return [...groupCall.participants];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useGroupCall(client, roomId) {
|
export function useGroupCall(client, roomId, debug = false) {
|
||||||
const groupCallRef = useRef(null);
|
const groupCallRef = useRef(null);
|
||||||
|
|
||||||
const [
|
const [
|
||||||
|
|
@ -310,6 +299,7 @@ export function useGroupCall(client, roomId) {
|
||||||
error,
|
error,
|
||||||
microphoneMuted,
|
microphoneMuted,
|
||||||
localVideoMuted,
|
localVideoMuted,
|
||||||
|
callDebugger,
|
||||||
},
|
},
|
||||||
setState,
|
setState,
|
||||||
] = useState({
|
] = useState({
|
||||||
|
|
@ -321,6 +311,7 @@ export function useGroupCall(client, roomId) {
|
||||||
error: null,
|
error: null,
|
||||||
microphoneMuted: false,
|
microphoneMuted: false,
|
||||||
localVideoMuted: false,
|
localVideoMuted: false,
|
||||||
|
callDebugger: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateState = (state) =>
|
const updateState = (state) =>
|
||||||
|
|
@ -354,6 +345,9 @@ export function useGroupCall(client, roomId) {
|
||||||
updateState({
|
updateState({
|
||||||
room,
|
room,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
callDebugger: debug
|
||||||
|
? new ConferenceCallDebugger(client, groupCall)
|
||||||
|
: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -443,6 +437,7 @@ export function useGroupCall(client, roomId) {
|
||||||
roomName: room ? room.name : null,
|
roomName: room ? room.name : null,
|
||||||
participants,
|
participants,
|
||||||
groupCall: groupCallRef.current,
|
groupCall: groupCallRef.current,
|
||||||
|
callDebugger: callDebugger,
|
||||||
microphoneMuted,
|
microphoneMuted,
|
||||||
localVideoMuted,
|
localVideoMuted,
|
||||||
error,
|
error,
|
||||||
|
|
|
||||||
|
|
@ -56,24 +56,24 @@ function sortEntries(a, b) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DevTools({ manager }) {
|
export function DevTools({ callDebugger }) {
|
||||||
const [debugState, setDebugState] = useState(manager.callDebugger.debugState);
|
const [debugState, setDebugState] = useState(callDebugger.debugState);
|
||||||
const [selectedEvent, setSelectedEvent] = useState();
|
const [selectedEvent, setSelectedEvent] = useState();
|
||||||
const [activeTab, setActiveTab] = useState("users");
|
const [activeTab, setActiveTab] = useState("users");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function onRoomDebug() {
|
function onRoomDebug() {
|
||||||
setDebugState({ ...manager.callDebugger.debugState });
|
setDebugState({ ...callDebugger.debugState });
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.callDebugger.on("debug", onRoomDebug);
|
callDebugger.on("debug", onRoomDebug);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
manager.callDebugger.removeListener("debug", onRoomDebug);
|
callDebugger.removeListener("debug", onRoomDebug);
|
||||||
};
|
};
|
||||||
}, [manager]);
|
}, [callDebugger]);
|
||||||
|
|
||||||
if (!manager.entered) {
|
if (!callDebugger.groupCall.entered) {
|
||||||
return <div className={styles.devTools} />;
|
return <div className={styles.devTools} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
31
src/Room.jsx
31
src/Room.jsx
|
|
@ -45,6 +45,7 @@ function useQuery() {
|
||||||
function useDebugMode() {
|
function useDebugMode() {
|
||||||
const query = useQuery();
|
const query = useQuery();
|
||||||
const debugStr = query.get("debug");
|
const debugStr = query.get("debug");
|
||||||
|
const debugEnabled = query.has("debug");
|
||||||
const [debugMode, setDebugMode] = useState(
|
const [debugMode, setDebugMode] = useState(
|
||||||
debugStr === "" || debugStr === "true"
|
debugStr === "" || debugStr === "true"
|
||||||
);
|
);
|
||||||
|
|
@ -70,7 +71,7 @@ function useDebugMode() {
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return [debugMode, toggleDebugMode];
|
return { debugEnabled, debugMode, toggleDebugMode };
|
||||||
}
|
}
|
||||||
|
|
||||||
function useRoomLayout() {
|
function useRoomLayout() {
|
||||||
|
|
@ -84,6 +85,7 @@ function useRoomLayout() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Room({ client }) {
|
export function Room({ client }) {
|
||||||
|
const { debugEnabled, debugMode, toggleDebugMode } = useDebugMode();
|
||||||
const { roomId } = useParams();
|
const { roomId } = useParams();
|
||||||
const {
|
const {
|
||||||
loading,
|
loading,
|
||||||
|
|
@ -100,7 +102,8 @@ export function Room({ client }) {
|
||||||
leave,
|
leave,
|
||||||
toggleLocalVideoMuted,
|
toggleLocalVideoMuted,
|
||||||
toggleMicrophoneMuted,
|
toggleMicrophoneMuted,
|
||||||
} = useGroupCall(client, roomId);
|
callDebugger,
|
||||||
|
} = useGroupCall(client, roomId, debugEnabled);
|
||||||
|
|
||||||
const content = () => {
|
const content = () => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
@ -138,6 +141,10 @@ export function Room({ client }) {
|
||||||
participants={participants}
|
participants={participants}
|
||||||
onLeave={leave}
|
onLeave={leave}
|
||||||
groupCall={groupCall}
|
groupCall={groupCall}
|
||||||
|
debugEnabled={debugEnabled}
|
||||||
|
debugMode={debugMode}
|
||||||
|
toggleDebugMode={toggleDebugMode}
|
||||||
|
callDebugger={callDebugger}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -266,9 +273,11 @@ function InRoomView({
|
||||||
toggleMicrophoneMuted,
|
toggleMicrophoneMuted,
|
||||||
participants,
|
participants,
|
||||||
onLeave,
|
onLeave,
|
||||||
groupCall,
|
debugEnabled,
|
||||||
|
debugMode,
|
||||||
|
toggleDebugMode,
|
||||||
|
callDebugger,
|
||||||
}) {
|
}) {
|
||||||
const [debugMode, toggleDebugMode] = useDebugMode();
|
|
||||||
const [roomLayout, toggleRoomLayout] = useRoomLayout();
|
const [roomLayout, toggleRoomLayout] = useRoomLayout();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -284,10 +293,12 @@ function InRoomView({
|
||||||
layout={roomLayout}
|
layout={roomLayout}
|
||||||
onClick={toggleRoomLayout}
|
onClick={toggleRoomLayout}
|
||||||
/>
|
/>
|
||||||
<SettingsButton
|
{debugEnabled && (
|
||||||
title={debugMode ? "Disable DevTools" : "Enable DevTools"}
|
<SettingsButton
|
||||||
onClick={toggleDebugMode}
|
title={debugMode ? "Disable DevTools" : "Enable DevTools"}
|
||||||
/>
|
onClick={toggleDebugMode}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</RightNav>
|
</RightNav>
|
||||||
</Header>
|
</Header>
|
||||||
{participants.length === 0 ? (
|
{participants.length === 0 ? (
|
||||||
|
|
@ -305,7 +316,9 @@ function InRoomView({
|
||||||
/>
|
/>
|
||||||
<HangupButton onClick={onLeave} />
|
<HangupButton onClick={onLeave} />
|
||||||
</div>
|
</div>
|
||||||
{debugMode && <DevTools groupCall={groupCall} />}
|
{debugEnabled && debugMode && callDebugger && (
|
||||||
|
<DevTools callDebugger={callDebugger} />
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue