small fixes
This commit is contained in:
parent
db8a2ee471
commit
d73e4972e0
@ -1,14 +1,20 @@
|
||||
import { connect } from "react-redux"
|
||||
import { getAddress, isConnecting } from "decentraland-dapps/dist/modules/wallet/selectors"
|
||||
import { isLoggingIn } from "../../../modules/identity/selector"
|
||||
import { getServer, getToken } from "../../../modules/conference/selector"
|
||||
import { RootState } from "../../../modules/reducer"
|
||||
import withRouter from "../../../utils/WithRouter"
|
||||
import Conference from "./Conference"
|
||||
import { MapDispatch, MapStateProps, OwnProps } from "./Conference.types"
|
||||
import { connect } from "react-redux";
|
||||
import {
|
||||
getAddress,
|
||||
isConnecting,
|
||||
} from "decentraland-dapps/dist/modules/wallet/selectors";
|
||||
import { isLoggingIn } from "../../../modules/identity/selector";
|
||||
import { getServer, getToken } from "../../../modules/conference/selector";
|
||||
import { RootState } from "../../../modules/reducer";
|
||||
import withRouter from "../../../utils/WithRouter";
|
||||
import Conference from "./Conference";
|
||||
import { MapDispatch, MapStateProps, OwnProps } from "./Conference.types";
|
||||
|
||||
const mapStateToProps = (state: RootState, ownProps: OwnProps): MapStateProps => {
|
||||
const addressFromPath = ownProps.router.params.profileAddress
|
||||
const mapStateToProps = (
|
||||
state: RootState,
|
||||
ownProps: OwnProps
|
||||
): MapStateProps => {
|
||||
const addressFromPath = ownProps.router.params.profileAddress;
|
||||
|
||||
return {
|
||||
profileAddress: addressFromPath?.toLowerCase(),
|
||||
@ -16,9 +22,9 @@ const mapStateToProps = (state: RootState, ownProps: OwnProps): MapStateProps =>
|
||||
loggedInAddress: getAddress(state)?.toLowerCase(),
|
||||
server: getServer(state),
|
||||
token: getToken(state),
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatch = (dispatch: MapDispatch): any => ({})
|
||||
const mapDispatch = (_dispatch: MapDispatch): any => ({});
|
||||
|
||||
export default withRouter(connect(mapStateToProps, mapDispatch)(Conference))
|
||||
export default withRouter(connect(mapStateToProps, mapDispatch)(Conference));
|
||||
|
||||
@ -1,52 +1,59 @@
|
||||
import React, { ChangeEvent, useEffect, useState } from "react"
|
||||
import { useNavigate } from "react-router-dom"
|
||||
import Divider from "semantic-ui-react/dist/commonjs/elements/Divider/Divider"
|
||||
import { t } from "decentraland-dapps/dist/modules/translation/utils"
|
||||
import { Loader } from "decentraland-ui"
|
||||
import { locations } from "../../../modules/routing/locations"
|
||||
import { getView } from "../../../utils/view"
|
||||
import { PageLayout } from "../../PageLayout"
|
||||
import { Props } from "./MainPage.types"
|
||||
import styles from "./MainPage.module.css"
|
||||
import { flatFetch } from "../../../utils/flat-fetch"
|
||||
import { signedFetch } from "../../../utils/auth"
|
||||
import { AuthIdentity } from "@dcl/crypto"
|
||||
import React, { ChangeEvent, useEffect, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import Divider from "semantic-ui-react/dist/commonjs/elements/Divider/Divider";
|
||||
import { Loader } from "decentraland-ui";
|
||||
import { locations } from "../../../modules/routing/locations";
|
||||
import { PageLayout } from "../../PageLayout";
|
||||
import { Props } from "./MainPage.types";
|
||||
import styles from "./MainPage.module.css";
|
||||
import { flatFetch } from "../../../utils/flat-fetch";
|
||||
import { signedFetch } from "../../../utils/auth";
|
||||
import { AuthIdentity } from "@dcl/crypto";
|
||||
|
||||
function MainPage(props: Props) {
|
||||
const [selectedServer, setSelectedServer] = useState("")
|
||||
const [isConnectingToServer, setIsConnectingToServer] = useState(false)
|
||||
const [selectedServer, setSelectedServer] = useState("");
|
||||
const [isConnectingToServer, _setIsConnectingToServer] = useState(false);
|
||||
|
||||
const { isLoading, onFetchProfile, profileAddress, loggedInAddress, identity, onSubmitConnectForm } = props
|
||||
const tabs: { displayValue: string; value: string }[] = [
|
||||
{ displayValue: t("tabs.overview"), value: t("tabs.overview") },
|
||||
]
|
||||
const {
|
||||
isLoading,
|
||||
onFetchProfile,
|
||||
profileAddress,
|
||||
loggedInAddress,
|
||||
identity,
|
||||
onSubmitConnectForm,
|
||||
} = props;
|
||||
|
||||
const navigate = useNavigate()
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
if (profileAddress) {
|
||||
onFetchProfile(profileAddress)
|
||||
onFetchProfile(profileAddress);
|
||||
}
|
||||
}, [profileAddress])
|
||||
}, [profileAddress]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!profileAddress && !loggedInAddress && !isLoading) {
|
||||
navigate(locations.signIn(locations.root()))
|
||||
navigate(locations.signIn(locations.root()));
|
||||
}
|
||||
}, [isLoading, loggedInAddress, profileAddress])
|
||||
const view = getView(loggedInAddress, profileAddress)
|
||||
}, [isLoading, loggedInAddress, profileAddress]);
|
||||
|
||||
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
setSelectedServer(e.target.value)
|
||||
}
|
||||
setSelectedServer(e.target.value);
|
||||
};
|
||||
|
||||
async function livekitConnect(identity: AuthIdentity, worldServer: string, worldName: string) {
|
||||
const aboutResponse = await flatFetch(`${worldServer}/world/${worldName}/about`)
|
||||
console.log(aboutResponse.text)
|
||||
async function livekitConnect(
|
||||
identity: AuthIdentity,
|
||||
worldServer: string,
|
||||
worldName: string
|
||||
) {
|
||||
const aboutResponse = await flatFetch(
|
||||
`${worldServer}/world/${worldName}/about`
|
||||
);
|
||||
console.log(aboutResponse.text);
|
||||
if (aboutResponse.status === 200) {
|
||||
const url = JSON.parse(aboutResponse.text!)
|
||||
["comms"]["fixedAdapter"].replace("signed-login:", "")
|
||||
.replace("get-comms-adapter", "cast-adapter")
|
||||
.replace("get-comms-adapter", "cast-adapter");
|
||||
const response = await signedFetch(
|
||||
url,
|
||||
identity,
|
||||
@ -57,37 +64,45 @@ function MainPage(props: Props) {
|
||||
signer: "dcl:explorer",
|
||||
intent: "dcl:explorer:comms-handshake",
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
if (response.status === 200) {
|
||||
console.log(response.text)
|
||||
return JSON.parse(response.text!)
|
||||
console.log(response.text);
|
||||
return JSON.parse(response.text!);
|
||||
} else {
|
||||
let message = ""
|
||||
let message = "";
|
||||
try {
|
||||
message = JSON.parse(response.text || "")?.message
|
||||
message = JSON.parse(response.text || "")?.message;
|
||||
} catch (e) {
|
||||
message = response.text || ""
|
||||
message = response.text || "";
|
||||
}
|
||||
throw Error(message)
|
||||
throw Error(message);
|
||||
}
|
||||
// throw Error(`Failed to connect to LiveKit: ${JSON.stringify(response.text || response.json?.message)}`)
|
||||
} else if (aboutResponse.status === 404) {
|
||||
throw Error(`World ${worldName} not found`)
|
||||
throw Error(`World ${worldName} not found`);
|
||||
}
|
||||
throw Error("An error has occurred")
|
||||
throw Error("An error has occurred");
|
||||
}
|
||||
|
||||
const handleClick = () => {
|
||||
livekitConnect(identity!, "https://worlds-content-server.decentraland.zone", selectedServer)
|
||||
livekitConnect(
|
||||
identity!,
|
||||
"https://worlds-content-server.decentraland.zone",
|
||||
selectedServer
|
||||
)
|
||||
.then((response: { url: string; token: string }) => {
|
||||
onSubmitConnectForm(response.url, response.token)
|
||||
navigate(`/meet/${encodeURIComponent(response.url)}?token=${encodeURIComponent(response.token)}`)
|
||||
onSubmitConnectForm(response.url, response.token);
|
||||
navigate(
|
||||
`/meet/${encodeURIComponent(response.url)}?token=${encodeURIComponent(
|
||||
response.token
|
||||
)}`
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("ERROR livekit connect", err)
|
||||
})
|
||||
}
|
||||
console.error("ERROR livekit connect", err);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<PageLayout>
|
||||
@ -99,7 +114,11 @@ function MainPage(props: Props) {
|
||||
<Divider />
|
||||
|
||||
<div>
|
||||
<input name="server" value={selectedServer} onChange={handleChange} />
|
||||
<input
|
||||
name="server"
|
||||
value={selectedServer}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
|
||||
<button onClick={handleClick}>Connect</button>
|
||||
</div>
|
||||
@ -107,7 +126,7 @@ function MainPage(props: Props) {
|
||||
</div>
|
||||
)}
|
||||
</PageLayout>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default MainPage
|
||||
export default MainPage;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user