Skip to content

Commit

Permalink
Merge pull request #3 from SuperViz/v.6-compatible
Browse files Browse the repository at this point in the history
Update to v6.3
  • Loading branch information
vtnorton authored Jun 11, 2024
2 parents 157eb57 + 440248f commit 721a835
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 263 deletions.
49 changes: 29 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<title>SuperViz - Matterport demo</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1" />
<link href="./src/styles.css" rel="stylesheet" />
</head>
<head>
<title>SuperViz - Matterport demo</title>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1"
/>
<link href="./src/styles.css" rel="stylesheet" />
</head>

<body>
<main id="app">
<section id="loader-section">
<div class="loader"></div>
</section>
<section id="content-section" class="hide hidden-menu">
<aside id="menu"></aside>
</section>
</main>
<script type="module" src="https://unpkg.com/@superviz/[email protected]"></script>
<script type="module" src="https://unpkg.com/@superviz/[email protected]"></script>
<script type="module" src="https://cdnjs.cloudflare.com/ajax/libs/pubsub-js/1.9.4/pubsub.min.js"></script>
<script type="module" src="src/index.js"></script>
</body>
<body>
<main id="app">
<section id="loader-section">
<div class="loader"></div>
</section>
<section id="content-section" class="hide hidden-menu">
<aside id="menu"></aside>
</section>
</main>
<script type="module" src="https://unpkg.com/@superviz/[email protected]"></script>
<script
type="module"
src="https://unpkg.com/@superviz/[email protected]"
></script>
<script
type="module"
src="https://cdnjs.cloudflare.com/ajax/libs/pubsub-js/1.9.4/pubsub.min.js"
></script>
<script type="module" src="src/index.js"></script>
</body>
</html>
144 changes: 81 additions & 63 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,92 @@
import Matterport from './components/Matterport.js';
import Menu from './components/Menu.js';
import { SuperViz } from './components/SuperViz.js';
import Matterport from "./components/Matterport.js";
import Menu from "./components/Menu.js";
import { SuperViz } from "./components/SuperViz.js";

const url = new URL(document.URL);
let userType = url.searchParams.get('user-type');
let roomId = url.searchParams.get('roomId');
let userType = url.searchParams.get("user-type");
let roomId = url.searchParams.get("roomId");
let userId = Date.now().toPrecision(20);
let realtime;
let mainChannel;
let currentContent;
let defaultModel = "v4LWLiLDm3s";

class App {
constructor() {
this.contentSection = document.getElementById('content-section');
this.loaderSection = document.getElementById('loader-section');

// Pubsub - listen for event: Menu clicked loaded ::
PubSub.subscribe(Menu.ITEM_CLICKED, this.changeProject.bind(this));

// Pubsub - listen for event: Matterport loaded ::
PubSub.subscribe(Matterport.MATTERPORT_LOADED, this.onContentLoaded.bind(this));
}

init() {
// check userType ::
if (userType == null) userType = 'host';

// Initilize the SDK ::
SuperViz.init(userId, roomId === null ? '1' : roomId, ' ', userType);

// Pubsub - listen for event: When I joined ::
PubSub.subscribe(SuperViz.MY_PARTICIPANT_JOINED, this.onMyParticipantJoined.bind(this));
}

onMyParticipantJoined(e, payload) {
realtime = payload.realtime;

// sync engine - listen for event: Matterport model changed ::
realtime.subscribe(SuperViz.CONTENT_CHANGED, (participant) => {
if (participant[Object.keys(participant).length - 1].participantId != userId) {
if (userType != 'host') {
PubSub.publish(Menu.ITEM_CLICKED, participant[Object.keys(participant).length - 1].data);
}
}
constructor() {
this.contentSection = document.getElementById("content-section");
this.loaderSection = document.getElementById("loader-section");

// Pubsub - listen for event: Menu clicked loaded ::
PubSub.subscribe(Menu.ITEM_CLICKED, this.changeProject.bind(this));

// Pubsub - listen for event: Matterport loaded ::
PubSub.subscribe(
Matterport.MATTERPORT_LOADED,
this.onContentLoaded.bind(this)
);
}

init() {
// check userType ::
if (userType == null) userType = "host";

// Initilize the SDK ::
SuperViz.init(userId, roomId === null ? "1" : roomId, " ", userType);

// Pubsub - listen for event: When I joined ::
PubSub.subscribe(
SuperViz.MY_PARTICIPANT_JOINED,
this.onMyParticipantJoined.bind(this)
);
}

onMyParticipantJoined(e, payload) {
realtime = payload.realtime;
mainChannel = payload.channel;

// subscribe to real-time "SuperViz.CONTENT_CHANGED_IN_CHANNEL" events ::
mainChannel.subscribe(SuperViz.CONTENT_CHANGED_IN_CHANNEL, (payload) => {
// don't do anything if tour is already there ::
if (currentContent === payload.data) return;

// if it was not me who changed the content, go ahead and change it ::
if (payload.participantId != userId)
PubSub.publish(SuperViz.CHANGE_CONTENT, payload.data);
});

mainChannel
.fetchHistory(SuperViz.CONTENT_CHANGED_IN_CHANNEL)
.then((value) => {
// get the model current model in the real-time "SuperViz.CONTENT_CHANGED_IN_CHANNEL" channel ::
currentContent = value[value.length - 1].data;

// publish to internal pubsub that we should load new content ::
if (currentContent == undefined)
PubSub.publish(SuperViz.CHANGE_CONTENT, defaultModel);
else PubSub.publish(SuperViz.CHANGE_CONTENT, currentContent);
})
.catch(() => {
PubSub.publish(SuperViz.CHANGE_CONTENT, defaultModel);
});

realtime
.fetchHistory(SuperViz.CONTENT_CHANGED)
.then((value) => {
//console.log(value);
PubSub.publish(Menu.ITEM_CLICKED, value.data);
})
.catch(() => {
PubSub.publish(Menu.ITEM_CLICKED, 'v4LWLiLDm3s');
});

// show content ::
this.loaderSection.classList.add('hide');
this.contentSection.classList.remove('hide');
}

changeProject(e, id) {
// let sync engine know we updated the content ::
if (currentContent != id) {
realtime.publish(SuperViz.CONTENT_CHANGED, id);
}
}

async onContentLoaded(e, payload) {
//Save content ::
currentContent = payload.model;
}
// show content ::
this.loaderSection.classList.add("hide");
this.contentSection.classList.remove("hide");
}

changeProject(e, id) {
if (currentContent != id) {
// let internal engine know we updated the content ::
PubSub.publish(SuperViz.CHANGE_CONTENT, id);

// let real-time channel know we updated the content ::
mainChannel.publish(SuperViz.CONTENT_CHANGED_IN_CHANNEL, id);
}
}

async onContentLoaded(e, payload) {
//Save content ::
currentContent = payload.model;
}
}
export default App;
Loading

0 comments on commit 721a835

Please sign in to comment.