Be stricter with what is passed in to the openid components
This commit is contained in:
parent
9e95e8b5a7
commit
f2eabec382
3 changed files with 40 additions and 17 deletions
|
@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MatrixClient } from "matrix-js-sdk";
|
|
||||||
import React, {
|
import React, {
|
||||||
ReactNode,
|
ReactNode,
|
||||||
createContext,
|
createContext,
|
||||||
|
@ -24,11 +23,16 @@ import React, {
|
||||||
} from "react";
|
} from "react";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
|
||||||
import { SFUConfig, getSFUConfigWithOpenID } from "./openIDSFU";
|
import {
|
||||||
|
OpenIDClientParts,
|
||||||
|
SFUConfig,
|
||||||
|
getSFUConfigWithOpenID,
|
||||||
|
} from "./openIDSFU";
|
||||||
import { ErrorView, LoadingView } from "../FullScreenView";
|
import { ErrorView, LoadingView } from "../FullScreenView";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
client: MatrixClient;
|
client: OpenIDClientParts;
|
||||||
|
livekitServiceURL: string;
|
||||||
roomName: string;
|
roomName: string;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}
|
}
|
||||||
|
@ -37,21 +41,30 @@ const SFUConfigContext = createContext<SFUConfig>(undefined);
|
||||||
|
|
||||||
export const useSFUConfig = () => useContext(SFUConfigContext);
|
export const useSFUConfig = () => useContext(SFUConfigContext);
|
||||||
|
|
||||||
export function OpenIDLoader({ client, roomName, children }: Props) {
|
export function OpenIDLoader({
|
||||||
|
client,
|
||||||
|
livekitServiceURL,
|
||||||
|
roomName,
|
||||||
|
children,
|
||||||
|
}: Props) {
|
||||||
const [sfuConfig, setSFUConfig] = useState<SFUConfig>();
|
const [sfuConfig, setSFUConfig] = useState<SFUConfig>();
|
||||||
const [error, setError] = useState<Error>();
|
const [error, setError] = useState<Error>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const result = await getSFUConfigWithOpenID(client, roomName);
|
const result = await getSFUConfigWithOpenID(
|
||||||
|
client,
|
||||||
|
livekitServiceURL,
|
||||||
|
roomName
|
||||||
|
);
|
||||||
setSFUConfig(result);
|
setSFUConfig(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error("Failed to fetch SFU config: ", e);
|
logger.error("Failed to fetch SFU config: ", e);
|
||||||
setError(new Error("Failed to fetch SFU config"));
|
setError(new Error("Failed to fetch SFU config"));
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, [client, roomName]);
|
}, [client, livekitServiceURL, roomName]);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return <ErrorView error={error} />;
|
return <ErrorView error={error} />;
|
||||||
|
|
|
@ -17,27 +17,26 @@ limitations under the License.
|
||||||
import { MatrixClient } from "matrix-js-sdk";
|
import { MatrixClient } from "matrix-js-sdk";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
|
||||||
import { Config } from "../config/Config";
|
|
||||||
|
|
||||||
export interface SFUConfig {
|
export interface SFUConfig {
|
||||||
url: string;
|
url: string;
|
||||||
jwt: string;
|
jwt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The bits we need from MatrixClient
|
||||||
|
export type OpenIDClientParts = Pick<
|
||||||
|
MatrixClient,
|
||||||
|
"getOpenIdToken" | "getDeviceId"
|
||||||
|
>;
|
||||||
|
|
||||||
export async function getSFUConfigWithOpenID(
|
export async function getSFUConfigWithOpenID(
|
||||||
client: MatrixClient,
|
client: OpenIDClientParts,
|
||||||
|
livekitServiceURL: string,
|
||||||
roomName: string
|
roomName: string
|
||||||
): Promise<SFUConfig> {
|
): Promise<SFUConfig> {
|
||||||
const openIdToken = await client.getOpenIdToken();
|
const openIdToken = await client.getOpenIdToken();
|
||||||
logger.debug("Got openID token", openIdToken);
|
logger.debug("Got openID token", openIdToken);
|
||||||
|
|
||||||
const livekitCfg = Config.get().livekit;
|
const res = await fetch(livekitServiceURL + "/sfu/get", {
|
||||||
|
|
||||||
if (!livekitCfg?.livekit_service_url) {
|
|
||||||
throw new Error("No livekit service URL defined");
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await fetch(livekitCfg.livekit_service_url + "/sfu/get", {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
|
@ -36,6 +36,7 @@ import { UserChoices } from "../livekit/useLiveKit";
|
||||||
import { findDeviceByName } from "../media-utils";
|
import { findDeviceByName } from "../media-utils";
|
||||||
import { OpenIDLoader } from "../livekit/OpenIDLoader";
|
import { OpenIDLoader } from "../livekit/OpenIDLoader";
|
||||||
import { ActiveCall } from "./InCallView";
|
import { ActiveCall } from "./InCallView";
|
||||||
|
import { Config } from "../config/Config";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
@ -219,11 +220,21 @@ export function GroupCallView({
|
||||||
undefined
|
undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const lkServiceURL = Config.get().livekit?.livekit_service_url;
|
||||||
|
|
||||||
|
if (!lkServiceURL) {
|
||||||
|
return <ErrorView error={new Error("No livekit_service_url defined")} />;
|
||||||
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return <ErrorView error={error} />;
|
return <ErrorView error={error} />;
|
||||||
} else if (state === GroupCallState.Entered && userChoices) {
|
} else if (state === GroupCallState.Entered && userChoices) {
|
||||||
return (
|
return (
|
||||||
<OpenIDLoader client={client} roomName={matrixInfo.roomName}>
|
<OpenIDLoader
|
||||||
|
client={client}
|
||||||
|
livekitServiceURL={lkServiceURL}
|
||||||
|
roomName={matrixInfo.roomName}
|
||||||
|
>
|
||||||
<ActiveCall
|
<ActiveCall
|
||||||
client={client}
|
client={client}
|
||||||
groupCall={groupCall}
|
groupCall={groupCall}
|
||||||
|
|
Loading…
Reference in a new issue