Network handler code.
This commit is contained in:
parent
6ae9cfe12a
commit
dd82962260
34
index.html
34
index.html
@ -4,12 +4,17 @@
|
||||
<meta charset="UTF-8">
|
||||
<title>Deep Diagram</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: clip;
|
||||
}
|
||||
|
||||
.loader {
|
||||
position: fixed;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-content: center;
|
||||
@ -24,8 +29,8 @@
|
||||
|
||||
#questLaunch {
|
||||
position: fixed;
|
||||
top: 0px;
|
||||
right: 0px;
|
||||
top: 30px;
|
||||
right: 30px;
|
||||
padding: 10px;
|
||||
background: #000;
|
||||
color: #fff;
|
||||
@ -33,22 +38,35 @@
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#hostKey {
|
||||
position: fixed;
|
||||
z-index: 11;
|
||||
width: 200px;
|
||||
height: 20px;
|
||||
position: absolute;
|
||||
bottom: 50px;
|
||||
left: 16px;
|
||||
padding: 10px;
|
||||
background: #000;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
</style>
|
||||
<link as="script" href="/newRelic.js" rel="preload">
|
||||
<script src="/newRelic.js"></script>
|
||||
<meta content="width=device-width, initial-scale=1" name="viewport">
|
||||
<meta content="width=device-width, initial-scale=1, height=device-height" name="viewport">
|
||||
<meta content="An immersive vr diagramming experience based on a-frame and webxr" name="description">
|
||||
<link href="/assets/favicon-16x16.png" rel=icon sizes="16x16" type="image/png">
|
||||
<link href="/assets/favicon-32x32.png" rel=icon sizes="32x32" type="image/png">
|
||||
<link href="/assets/favicon-96x96.png" rel=icon sizes="96x96" type="image/png">
|
||||
<link href="/manifest.webmanifest" rel="manifest"/>
|
||||
|
||||
<script src='/niceware.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loader" id="loader">Loading...</div>
|
||||
<div id="graphContainer"></div>
|
||||
<!--<div class="loader" id="loader">Loading...</div> -->
|
||||
<div id="questLaunch"><a href="https://www.oculus.com/open_url/?url=https://www.deepdiagram.com/">Launch On Quest</a>
|
||||
</div>
|
||||
<div id="hostKey">keyLaunch On Quest</div>
|
||||
<script type="module" src="./src/app.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
1889
package-lock.json
generated
1889
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
68085
public/niceware.js
Normal file
68085
public/niceware.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -23,9 +23,12 @@ export class App {
|
||||
constructor() {
|
||||
const logger = log.getLogger('App');
|
||||
log.setDefaultLevel('warn');
|
||||
//log.getLogger('PeerjsNetworkConnection').setLevel('debug');
|
||||
log.getLogger('DiagramManager').setLevel('debug');
|
||||
log.getLogger('PeerjsNetworkConnection').setLevel('debug');
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.style.width = "100%";
|
||||
canvas.style.height = "100%";
|
||||
canvas.style.width = "100vw";
|
||||
canvas.style.height = "100vh";
|
||||
canvas.id = "gameCanvas";
|
||||
document.body.appendChild(canvas);
|
||||
log.debug('App', 'gameCanvas created');
|
||||
|
||||
@ -25,6 +25,8 @@ export type DiagramListing = {
|
||||
export interface IPersistenceManager {
|
||||
diagramListingObserver: Observable<DiagramListingEvent>;
|
||||
|
||||
sync();
|
||||
|
||||
addDiagram(diagram: DiagramListing);
|
||||
|
||||
getNewRelicData(): Promise<any[]>;
|
||||
|
||||
@ -5,17 +5,21 @@ import Dexie from "dexie";
|
||||
import log from "loglevel";
|
||||
import {AppConfigType} from "../util/appConfigType";
|
||||
|
||||
|
||||
export class IndexdbPersistenceManager implements IPersistenceManager {
|
||||
private readonly logger = log.getLogger('IndexdbPersistenceManager');
|
||||
public readonly diagramListingObserver: Observable<DiagramListingEvent> = new Observable<DiagramListingEvent>();
|
||||
public readonly updateObserver: Observable<DiagramEntity> = new Observable<DiagramEntity>();
|
||||
public readonly configObserver: Observable<AppConfigType> = new Observable<AppConfigType>();
|
||||
private db: Dexie;
|
||||
|
||||
private currentDiagramId: string;
|
||||
|
||||
constructor(name: string) {
|
||||
this.db = new Dexie(name);
|
||||
const version = 6;
|
||||
const version = 7;
|
||||
|
||||
|
||||
this.db.version(version).stores({config: "id,gridSnap,rotateSnap,createSnap"});
|
||||
this.db.version(version).stores({entities: "id,diagramlistingid,position,rotation,last_seen,template,text,scale,color"});
|
||||
this.db.version(version).stores({diagramlisting: "id,name,description,sharekey"});
|
||||
@ -137,6 +141,13 @@ export class IndexdbPersistenceManager implements IPersistenceManager {
|
||||
this.logger.info("initialize finished");
|
||||
}
|
||||
|
||||
public sync() {
|
||||
this.getFilteredEntities().each((e) => {
|
||||
this.logger.debug('adding', e);
|
||||
this.updateObserver.notifyObservers(e);
|
||||
});
|
||||
}
|
||||
|
||||
public modify(entity: DiagramEntity) {
|
||||
if (!entity) {
|
||||
this.logger.error("Modifying null mesh, early return");
|
||||
|
||||
@ -1,37 +1,62 @@
|
||||
import P2PDataChannel from 'p2p-data-channel';
|
||||
import log from "loglevel";
|
||||
import {Observable} from "@babylonjs/core";
|
||||
import {DiagramEvent, DiagramEventMask, DiagramEventType} from "../diagram/diagramEntity";
|
||||
|
||||
export class PeerjsNetworkConnection {
|
||||
private logger: log.Logger = log.getLogger('PeerjsNetworkConnection');
|
||||
private dataChannel: P2PDataChannel<any>;
|
||||
|
||||
constructor(dataChannel: string, identity: string) {
|
||||
private readonly onDiagramEventObservable: Observable<DiagramEvent>;
|
||||
|
||||
constructor(dataChannel: string, identity: string, onDiagramEventObservable: Observable<DiagramEvent>) {
|
||||
const config = {
|
||||
debug: false,
|
||||
dataChannel: dataChannel,
|
||||
connectionTimeout: 5000,
|
||||
pingInterval: 4000,
|
||||
pingTimeout: 8000
|
||||
pingTimeout: 8000,
|
||||
logLevel: 'debug',
|
||||
}
|
||||
this.onDiagramEventObservable = onDiagramEventObservable;
|
||||
this.dataChannel = new P2PDataChannel(identity, config);
|
||||
this.dataChannel.broadcast({'connect': identity});
|
||||
this.dataChannel.onConnected((peerId) => {
|
||||
this.logger.debug(peerId, ' connected');
|
||||
this.onDiagramEventObservable.notifyObservers({type: DiagramEventType.SYNC}, DiagramEventMask.REMOTE);
|
||||
});
|
||||
this.dataChannel.onMessage((message) => {
|
||||
this.logger.debug(message);
|
||||
if (message.sender !== this.dataChannel.localPeerId) {
|
||||
this.logger.debug(message.payload, ' received from ', message.sender);
|
||||
if (message.payload.request == 'join') {
|
||||
this.dataChannel.send(message.sender, {type: 'join-ack'});
|
||||
this.logger.debug('Join ack sent to ', message.sender);
|
||||
this.onDiagramEventObservable.add((evt) => {
|
||||
this.dataChannel.broadcast({diagramEvent: evt});
|
||||
});
|
||||
|
||||
}
|
||||
if (message.payload.diagramEvent) {
|
||||
this.logger.debug('Received diagram event from ', message.sender, message.payload.diagramEvent);
|
||||
const event = message.payload.diagramEvent;
|
||||
if (event.type == DiagramEventType.DROP) {
|
||||
event.type = DiagramEventType.MODIFY;
|
||||
}
|
||||
this.onDiagramEventObservable.notifyObservers(event, DiagramEventMask.REMOTE);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public connect(host: string) {
|
||||
try {
|
||||
this.dataChannel.connect(host).then((peerId) => {
|
||||
this.logger.debug('Broadcasting Join', peerId);
|
||||
this.dataChannel.broadcast({payload: 'Joined'});
|
||||
});
|
||||
} catch (err) {
|
||||
this.dataChannel.broadcast({request: 'join'});
|
||||
}).catch((err) => {
|
||||
this.logger.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@ -55,4 +55,10 @@ export class AppConfig {
|
||||
this._currentConfig = config;
|
||||
this.onConfigChangedObservable.notifyObservers(this._currentConfig, 1);
|
||||
}
|
||||
|
||||
public setPassphrase(passphrase: string) {
|
||||
this._currentConfig.passphrase = passphrase;
|
||||
this.onConfigChangedObservable.notifyObservers(this._currentConfig, 2);
|
||||
|
||||
}
|
||||
}
|
||||
@ -9,5 +9,6 @@ export type AppConfigType = {
|
||||
newRelicKey?: string,
|
||||
newRelicAccount?: string,
|
||||
demoCompleted?: boolean,
|
||||
passphrase?: string,
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user