Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix embed codes for anonymous users or non-owners #5623

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,15 +537,6 @@ function handleHubChannelJoined(entryManager, hubChannel, messageDispatch, data,
}

const hub = data.hubs[0];
let embedToken = hub.embed_token;

if (!embedToken) {
const embedTokenEntry = store.state.embedTokens && store.state.embedTokens.find(t => t.hubId === hub.hub_id);

if (embedTokenEntry) {
embedToken = embedTokenEntry.embedToken;
}
}

console.log(`Dialog host: ${hub.host}:${hub.port}`);

Expand All @@ -556,8 +547,7 @@ function handleHubChannelJoined(entryManager, hubChannel, messageDispatch, data,
onMediaSearchResultEntrySelected: (entry, selectAction) =>
scene.emit("action_selected_media_result_entry", { entry, selectAction }),
onMediaSearchCancelled: entry => scene.emit("action_media_search_cancelled", entry),
onAvatarSaved: entry => scene.emit("action_avatar_saved", entry),
embedToken: embedToken
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The embedToken prop was a remnant from older an UI design. It is no longer used in UIRoot.

onAvatarSaved: entry => scene.emit("action_avatar_saved", entry)
});

scene.addEventListener("action_selected_media_result_entry", e => {
Expand Down
14 changes: 8 additions & 6 deletions src/react-components/room/InvitePopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ function InvitePopoverContent({ url, embed, inviteRequired, fetchingInvite, invi
value={url}
buttonPreset="accent3"
/>
<CopyableTextInputField
label={<FormattedMessage id="invite-popover.embed-code" defaultMessage="Embed Code" />}
value={embed}
buttonPreset="accent5"
/>
{embed && (
<CopyableTextInputField
label={<FormattedMessage id="invite-popover.embed-code" defaultMessage="Embed Code" />}
value={embed}
buttonPreset="accent5"
/>
)}
</>
)}
</Column>
Expand All @@ -36,7 +38,7 @@ function InvitePopoverContent({ url, embed, inviteRequired, fetchingInvite, invi

InvitePopoverContent.propTypes = {
url: PropTypes.string.isRequired,
embed: PropTypes.string.isRequired,
embed: PropTypes.string,
inviteRequired: PropTypes.bool,
fetchingInvite: PropTypes.bool,
inviteUrl: PropTypes.string,
Expand Down
15 changes: 11 additions & 4 deletions src/react-components/room/InvitePopoverContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import { InvitePopoverButton } from "./InvitePopover";
import { handleExitTo2DInterstitial } from "../../utils/vr-interstitial";
import { useInviteUrl } from "./useInviteUrl";

export function InvitePopoverContainer({ hub, hubChannel, scene, ...rest }) {
export function InvitePopoverContainer({ hub, hubChannel, scene, store, ...rest }) {
// TODO: Move to Hub class
const shortUrl = `https://${configs.SHORTLINK_DOMAIN}`;
const url = `${shortUrl}/${hub.hub_id}`;
const embedUrl = hubUrl(hub.hub_id, { embed_token: hub.embed_token });
const embedText = `<iframe src="${embedUrl}" style="width: 1024px; height: 768px;" allow="microphone; camera; vr; speaker;"></iframe>`;

let embedText = null;
const embedToken = hub.embed_token || store.getEmbedTokenForHub(hub);
if (embedToken) {
const embedUrl = hubUrl(hub.hub_id, { embed_token: embedToken });
embedText = `<iframe src="${embedUrl}" style="width: 1024px; height: 768px;" allow="microphone; camera; vr; speaker;"></iframe>`;
}

const popoverApiRef = useRef();

// Handle clicking on the invite button while in VR.
Expand Down Expand Up @@ -61,5 +67,6 @@ export function InvitePopoverContainer({ hub, hubChannel, scene, ...rest }) {
InvitePopoverContainer.propTypes = {
hub: PropTypes.object.isRequired,
scene: PropTypes.object.isRequired,
hubChannel: PropTypes.object.isRequired
hubChannel: PropTypes.object.isRequired,
store: PropTypes.object.isRequired
};
2 changes: 1 addition & 1 deletion src/react-components/ui-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ class UIRoot extends Component {
showPreload: PropTypes.bool,
onPreloadLoadClicked: PropTypes.func,
embed: PropTypes.bool,
embedToken: PropTypes.string,
onLoaded: PropTypes.func,
activeObject: PropTypes.object,
selectedObject: PropTypes.object,
Expand Down Expand Up @@ -1518,6 +1517,7 @@ class UIRoot extends Component {
hub={this.props.hub}
hubChannel={this.props.hubChannel}
scene={this.props.scene}
store={this.props.store}
/>
}
toolbarCenter={
Expand Down
9 changes: 9 additions & 0 deletions src/storage/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,15 @@ export default class Store extends EventTarget {
return finalState;
}

getEmbedTokenForHub(hub) {
const embedTokenEntry = this.state.embedTokens.find(embedTokenEntry => embedTokenEntry.hubId === hub.hub_id);
if (embedTokenEntry) {
return embedTokenEntry.embedToken;
} else {
return null;
}
}

get schema() {
return SCHEMA;
}
Expand Down