102 lines
2.1 KiB
JavaScript
102 lines
2.1 KiB
JavaScript
|
|
/*
|
||
|
|
|
||
|
|
Copyright (c) 2020, 2023, The Unified Company.
|
||
|
|
|
||
|
|
This code is part of Unify.
|
||
|
|
|
||
|
|
This program is free software; you can redistribute it and/or modify
|
||
|
|
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
|
||
|
|
as published by the ESA.
|
||
|
|
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
|
||
|
|
|
||
|
|
https://unifyjs.org
|
||
|
|
|
||
|
|
*/
|
||
|
|
|
||
|
|
import unify from '../unify/unify.js';
|
||
|
|
|
||
|
|
import tools from '../unify/tools.js';
|
||
|
|
|
||
|
|
import Console from './console.js';
|
||
|
|
|
||
|
|
import cacheManager from "./objectCacheManager.js";
|
||
|
|
|
||
|
|
|
||
|
|
export default class objectManager{
|
||
|
|
|
||
|
|
clientObjects = new Array(); // clientObjects[ className ] [ id ] --> [ clientObjects ]
|
||
|
|
|
||
|
|
cacheManager = new cacheManager();
|
||
|
|
|
||
|
|
registerObject( object, socketClient ) {
|
||
|
|
|
||
|
|
this.registerChildren( object, socketClient );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
removeObjectsByClientID( userID ) {
|
||
|
|
|
||
|
|
this.cacheManager.removeObjectsByClientID( userID );
|
||
|
|
|
||
|
|
// todo : delete object when client disconnects
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
registerChildren( object, socketClient ) {
|
||
|
|
|
||
|
|
var clientObject = new Object();
|
||
|
|
|
||
|
|
clientObject.socketClient = socketClient;
|
||
|
|
|
||
|
|
clientObject.object = object;
|
||
|
|
|
||
|
|
this.cacheManager.addClientObject( clientObject, socketClient.userID );
|
||
|
|
|
||
|
|
if( object.getChildren ) {
|
||
|
|
|
||
|
|
var children = object.getChildren();
|
||
|
|
|
||
|
|
for( var c = 0; c< children.length;c++ ) {
|
||
|
|
|
||
|
|
var child = children[c];
|
||
|
|
|
||
|
|
this.registerChildren( child, socketClient );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
updateClient( object, clientA, eventName ) {
|
||
|
|
|
||
|
|
var clientObjects = this.cacheManager.getClientObjects( object.getApplicationPathString(), object.id );
|
||
|
|
|
||
|
|
if( clientObjects ) {
|
||
|
|
|
||
|
|
for( var c = 0; c < clientObjects.length; c++ ) {
|
||
|
|
|
||
|
|
var clientObject = clientObjects[c];
|
||
|
|
|
||
|
|
if( clientObject ) {
|
||
|
|
|
||
|
|
var clientB = clientObject.socketClient;
|
||
|
|
|
||
|
|
if( clientB.userID != clientA.userID || object.getClassName() == "collection" ) {
|
||
|
|
|
||
|
|
clientB.updateMessage( 10, object, eventName ); //registeredObject.object
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|