mirror of
https://github.com/esiur/esiur-js.git
synced 2025-05-06 12:32:58 +00:00
1.3.0
This commit is contained in:
parent
399a096c58
commit
7d2bcc60f7
@ -26,8 +26,8 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
import IEventHandler from '../Engine/IEventHandler.js';
|
||||
import IDestructible from '../Engine/IDestructible.js';
|
||||
import IEventHandler from '../Core/IEventHandler.js';
|
||||
import IDestructible from '../Core/IDestructible.js';
|
||||
|
||||
export default class AutoList extends IEventHandler
|
||||
{
|
||||
|
@ -25,8 +25,8 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
import IEventHandler from '../Engine/IEventHandler.js';
|
||||
import IDestructible from '../Engine/IDestructible.js';
|
||||
import IEventHandler from '../Core/IEventHandler.js';
|
||||
import IDestructible from '../Core/IDestructible.js';
|
||||
|
||||
export default class AutoMap extends IEventHandler
|
||||
{
|
||||
|
@ -30,13 +30,15 @@ import DataType from './DataType.js';
|
||||
import ResourceComparisonResult from './ResourceComparisionResult.js';
|
||||
import StructureComparisonResult from './StructureComparisonResult.js';
|
||||
|
||||
import AsyncBag from '../Engine/AsyncBag.js';
|
||||
import AsyncReply from '../Engine/AsyncReply.js';
|
||||
import AsyncBag from '../Core/AsyncBag.js';
|
||||
import AsyncReply from '../Core/AsyncReply.js';
|
||||
import Structure from './Structure.js';
|
||||
import PropertyValue from './PropertyValue.js';
|
||||
import {DC, BL} from './DataConverter.js';
|
||||
import BinaryList from './BinaryList.js';
|
||||
import DistributedPropertyContext from '../Net/IIP/DistributedPropertyContext.JS';
|
||||
import DistributedPropertyContext from '../Net/IIP/DistributedPropertyContext.js';
|
||||
import DistributedResource from '../Net/IIP/DistributedResource.js'
|
||||
import IResource from '../Resource/IResource.js';
|
||||
|
||||
export default class Codec {
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
import IDestructible from '../Engine/IDestructible.js';
|
||||
import IDestructible from '../Core/IDestructible.js';
|
||||
|
||||
export default class KeyList
|
||||
{
|
||||
@ -35,6 +35,14 @@ export default class KeyList
|
||||
this.values = [];
|
||||
}
|
||||
|
||||
toObject()
|
||||
{
|
||||
var rt = {};
|
||||
for(var i = 0; i < this.keys.length; i++)
|
||||
rt[this.keys[i]]=this.values[i];
|
||||
return rt;
|
||||
}
|
||||
|
||||
at(index)
|
||||
{
|
||||
return this.values[index];
|
||||
|
@ -35,11 +35,11 @@ import SHA256 from '../../Security/Integrity/SHA256.js';
|
||||
import {BL, DC} from '../../Data/DataConverter.js';
|
||||
import SendList from '../SendList.js';
|
||||
|
||||
import AsyncReply from '../../Engine/AsyncReply.js';
|
||||
import AsyncReply from '../../Core/AsyncReply.js';
|
||||
import Codec from '../../Data/Codec.js';
|
||||
import NetworkBuffer from '../Sockets/NetworkBuffer.js';
|
||||
import KeyList from '../../Data/KeyList.js';
|
||||
import AsyncQueue from '../../Engine/AsyncQueue.js';
|
||||
import AsyncQueue from '../../Core/AsyncQueue.js';
|
||||
import Warehouse from '../../Resource/Warehouse.js';
|
||||
|
||||
import IIPAuthPacket from "../Packets/IIPAuthPacket.js";
|
||||
@ -53,9 +53,9 @@ import IIPPacketCommand from "../Packets/IIPPacketCommand.js";
|
||||
import IIPPacketEvent from "../Packets/IIPPacketEvent.js";
|
||||
import IIPPacketReport from "../Packets//IIPPacketReport.js";
|
||||
|
||||
import ErrorType from "../../Engine/ErrorType.js";
|
||||
import ProgressType from "../../Engine/ProgressType.js";
|
||||
import ExceptionCode from "../../Engine/ExceptionCode.js";
|
||||
import ErrorType from "../../Core/ErrorType.js";
|
||||
import ProgressType from "../../Core/ProgressType.js";
|
||||
import ExceptionCode from "../../Core/ExceptionCode.js";
|
||||
|
||||
import DistributedResource from './DistributedResource.js';
|
||||
import ResourceTemplate from '../../Resource/Template/ResourceTemplate.js';
|
||||
@ -64,6 +64,7 @@ import DistributedResourceQueueItem from './DistributedResourceQueueItem.js';
|
||||
import DistributedResourceQueueItemType from './DistributedResourceQueueItemType.js';
|
||||
|
||||
import DistributedPropertyContext from './DistributedPropertyContext.js';
|
||||
import { ResourceTrigger } from '../../Resource/IResource.js';
|
||||
|
||||
export default class DistributedConnection extends IStore {
|
||||
|
||||
@ -134,81 +135,6 @@ export default class DistributedConnection extends IStore {
|
||||
}
|
||||
|
||||
|
||||
open(settings = {})
|
||||
{
|
||||
|
||||
var { domain = null,
|
||||
secure = false,
|
||||
username = "guest",
|
||||
password = "",
|
||||
checkInterval = 30,
|
||||
connectionTimeout = 600,
|
||||
revivingTime = 120,
|
||||
debug = false} = settings;
|
||||
|
||||
this.openReply = new AsyncReply();
|
||||
|
||||
var hostname = this.instance.name.split("://", 2)[1].split("/", 2)[0];
|
||||
|
||||
// assign domain from hostname if not provided
|
||||
domain = domain ? domain : hostname.split(":")[0];
|
||||
|
||||
this.session.localAuthentication.domain = domain;
|
||||
this.session.localAuthentication.username = username;
|
||||
|
||||
this.localPassword = DC.stringToBytes(password);
|
||||
|
||||
var url = `ws${secure ? 's' : ''}://${hostname}`;
|
||||
|
||||
|
||||
this.debug = debug;
|
||||
this.totalReceived = 0;
|
||||
this.totalSent = 0;
|
||||
|
||||
this.checkInterval = checkInterval * 1000; // check every 30 seconds
|
||||
this.connectionTimeout = connectionTimeout * 1000; // 10 minutes (4 pings failed)
|
||||
this.revivingTime = revivingTime * 1000; // 2 minutes
|
||||
this.lastAction = Date.now();
|
||||
|
||||
this.socket = new WebSocket(url, "iip");
|
||||
this.socket.binaryType = "arraybuffer";
|
||||
this.socket.connection = this;
|
||||
this.socket.networkBuffer = new NetworkBuffer();
|
||||
|
||||
var un = DC.stringToBytes(username);
|
||||
var dmn = DC.stringToBytes(domain);
|
||||
var self = this;
|
||||
|
||||
this.socket.onopen = function () {
|
||||
var bl = BL();
|
||||
bl.addUint8(0x60).addUint8(dmn.length).addUint8Array(dmn).addUint8Array(self.localNonce).addUint8(un.length).addUint8Array(un);
|
||||
self.send(bl.toArray());
|
||||
};
|
||||
|
||||
this.socket.onmessage = function (msg) {
|
||||
|
||||
//console.log("Rec", msg.data.byteLength);
|
||||
|
||||
this.networkBuffer.writeAll(msg.data);
|
||||
|
||||
self.lastAction = new Date();
|
||||
|
||||
while (this.networkBuffer.available > 0 && !this.networkBuffer.protected)
|
||||
self.receive(this.networkBuffer);
|
||||
|
||||
|
||||
};
|
||||
|
||||
this.socket.onclose = function(event)
|
||||
{
|
||||
if (this.connection.openReply)
|
||||
this.connection.openReply.triggerError(0, 0, "Host not reachable");
|
||||
|
||||
self.close(event);
|
||||
};
|
||||
|
||||
return this.openReply;
|
||||
}
|
||||
|
||||
processPacket(msg, offset, ends, data)
|
||||
{
|
||||
@ -590,8 +516,85 @@ export default class DistributedConnection extends IStore {
|
||||
}
|
||||
}
|
||||
|
||||
trigger(trigger) {
|
||||
return true;
|
||||
trigger(trigger)
|
||||
{
|
||||
if (trigger == ResourceTrigger.Open)
|
||||
{
|
||||
var { domain = null,
|
||||
secure = false,
|
||||
username = "guest",
|
||||
password = "",
|
||||
checkInterval = 30,
|
||||
connectionTimeout = 600,
|
||||
revivingTime = 120,
|
||||
debug = false} = this.instance.attributes.toObject();
|
||||
|
||||
this.openReply = new AsyncReply();
|
||||
|
||||
var hostname = this.instance.name.split("://", 2)[1].split("/", 2)[0];
|
||||
|
||||
// assign domain from hostname if not provided
|
||||
domain = domain ? domain : hostname.split(":")[0];
|
||||
|
||||
this.session.localAuthentication.domain = domain;
|
||||
this.session.localAuthentication.username = username;
|
||||
|
||||
this.localPassword = DC.stringToBytes(password);
|
||||
|
||||
var url = `ws${secure ? 's' : ''}://${hostname}`;
|
||||
|
||||
|
||||
this.debug = debug;
|
||||
this.totalReceived = 0;
|
||||
this.totalSent = 0;
|
||||
|
||||
this.checkInterval = checkInterval * 1000; // check every 30 seconds
|
||||
this.connectionTimeout = connectionTimeout * 1000; // 10 minutes (4 pings failed)
|
||||
this.revivingTime = revivingTime * 1000; // 2 minutes
|
||||
this.lastAction = Date.now();
|
||||
|
||||
this.socket = new WebSocket(url, "iip");
|
||||
this.socket.binaryType = "arraybuffer";
|
||||
this.socket.connection = this;
|
||||
this.socket.networkBuffer = new NetworkBuffer();
|
||||
|
||||
var un = DC.stringToBytes(username);
|
||||
var dmn = DC.stringToBytes(domain);
|
||||
var self = this;
|
||||
|
||||
this.socket.onopen = function () {
|
||||
var bl = BL();
|
||||
bl.addUint8(0x60).addUint8(dmn.length).addUint8Array(dmn).addUint8Array(self.localNonce).addUint8(un.length).addUint8Array(un);
|
||||
self.send(bl.toArray());
|
||||
};
|
||||
|
||||
this.socket.onmessage = function (msg) {
|
||||
|
||||
//console.log("Rec", msg.data.byteLength);
|
||||
|
||||
this.networkBuffer.writeAll(msg.data);
|
||||
|
||||
self.lastAction = new Date();
|
||||
|
||||
while (this.networkBuffer.available > 0 && !this.networkBuffer.protected)
|
||||
self.receive(this.networkBuffer);
|
||||
|
||||
|
||||
};
|
||||
|
||||
this.socket.onclose = function(event)
|
||||
{
|
||||
if (this.connection.openReply)
|
||||
this.connection.openReply.triggerError(0, 0, "Host not reachable");
|
||||
|
||||
self.close(event);
|
||||
};
|
||||
|
||||
return this.openReply;
|
||||
|
||||
}
|
||||
|
||||
return new AsyncReply(true);
|
||||
}
|
||||
|
||||
put(resource) {
|
||||
@ -1948,7 +1951,7 @@ export default class DistributedConnection extends IStore {
|
||||
.then(function(ar)
|
||||
{
|
||||
rt.trigger(true);
|
||||
}).error(function(ex) { rt.triggerChunk(ex); });
|
||||
}).error(function(ex) { rt.triggerError(ex); });
|
||||
}
|
||||
|
||||
return rt;
|
||||
|
@ -27,7 +27,7 @@
|
||||
"use strict";
|
||||
|
||||
import IResource from '../../Resource/IResource.js';
|
||||
import AsyncReply from '../../Engine/AsyncReply.js';
|
||||
import AsyncReply from '../../Core/AsyncReply.js';
|
||||
import Codec from '../../Data/Codec.js';
|
||||
import Structure from '../../Data/Structure.js';
|
||||
import IIPPacketAction from '../Packets//IIPPacketAction.js';
|
||||
|
@ -26,11 +26,11 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
import IDestructible from '../Engine/IDestructible.js';
|
||||
import IDestructible from '../Core/IDestructible.js';
|
||||
|
||||
export const ResourceTrigger =
|
||||
{
|
||||
Loaded : 0,
|
||||
Open : 0,
|
||||
Initialize: 1,
|
||||
Terminate: 2,
|
||||
Configure: 3,
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
import IEventHandler from '../Engine/IEventHandler.js';
|
||||
import IEventHandler from '../Core/IEventHandler.js';
|
||||
import IPermissionsManager from '../Security/Permissions/IPermissionsManager.js';
|
||||
import StructureArray from '../Data/StructureArray.js';
|
||||
import AutoList from '../Data/AutoList.js';
|
||||
|
@ -26,15 +26,16 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
import AsyncReply from '../Engine/AsyncReply.js';
|
||||
import AsyncReply from '../Core/AsyncReply.js';
|
||||
import ResourceTemplate from '../Resource/Template/ResourceTemplate.js';
|
||||
import IEventHandler from '../Engine/IEventHandler.js';
|
||||
import IEventHandler from '../Core/IEventHandler.js';
|
||||
import AutoList from '../Data/AutoList.js';
|
||||
import KeyList from '../Data/KeyList.js';
|
||||
import DistributedConnection from '../Net/IIP/DistributedConnection.js';
|
||||
import MemoryStore from '../Stores/MemoryStore.js';
|
||||
import Instance from '../Resource/Instance.js';
|
||||
import IStore from './IStore.js';
|
||||
import { ResourceTrigger } from './IResource.js';
|
||||
|
||||
|
||||
export class WH extends IEventHandler
|
||||
@ -52,14 +53,14 @@ export class WH extends IEventHandler
|
||||
this._register("disconnected");
|
||||
}
|
||||
|
||||
new(type, name, store = null, parent = null, manager = null)
|
||||
new(type, name, store = null, parent = null, manager = null, attributes = null)
|
||||
{
|
||||
var res = new type();
|
||||
this.put(res, name, store, parent, null, 0, manager);
|
||||
this.put(res, name, store, parent, null, 0, manager, attributes);
|
||||
return res;
|
||||
}
|
||||
|
||||
get(id, settings)
|
||||
get(id, attributes = null, parent = null, manager = null)
|
||||
{
|
||||
if (Number.isInteger(id))
|
||||
{
|
||||
@ -114,8 +115,9 @@ export class WH extends IEventHandler
|
||||
|
||||
if (handler = this.protocols.item(url[0]))
|
||||
{
|
||||
var store = this.new(handler, url[0] + "://" + hostname);
|
||||
store.open(settings).then(x=>{
|
||||
var store = handler();
|
||||
this.put(store, url[0] + "://" + hostname, null, parent, null, 0, manager, attributes);
|
||||
store.trigger(ResourceTrigger.Open).then(x=>{
|
||||
if (pathname.length > 0 && pathname != "")
|
||||
store.get(pathname).then(r=>{
|
||||
rt.trigger(r);
|
||||
@ -177,11 +179,15 @@ export class WH extends IEventHandler
|
||||
return true;
|
||||
}
|
||||
|
||||
put(resource, name, store, parent, customTemplate = null, age = 0, manager = null){
|
||||
put(resource, name, store, parent, customTemplate = null, age = 0, manager = null, attributes = null){
|
||||
|
||||
resource.instance = new Instance(this.resourceCounter++, name, resource, store, customTemplate, age);
|
||||
//resource.instance.children.on("add", Warehouse._onChildrenAdd).on("remove", Warehouse._onChildrenRemove);
|
||||
//resource.instance.parents.on("add", Warehouse._onParentsAdd).on("remove", Warehouse._onParentsRemove);
|
||||
|
||||
if (attributes != null)
|
||||
resource.instance.setAttributes(attributes);
|
||||
|
||||
if (manager != null)
|
||||
resource.instance.managers.add(manager);
|
||||
|
||||
@ -294,8 +300,8 @@ export class WH extends IEventHandler
|
||||
|
||||
let Warehouse = new WH();
|
||||
|
||||
Warehouse.protocols.add("iip", DistributedConnection);
|
||||
Warehouse.protocols.add("mem", MemoryStore);
|
||||
Warehouse.protocols.add("iip", () => new DistributedConnection());
|
||||
Warehouse.protocols.add("mem", () => new MemoryStore());
|
||||
|
||||
export default Warehouse;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "esiur",
|
||||
"version": "1.2.7",
|
||||
"version": "1.3.0",
|
||||
"description": "Distributed Object Framework",
|
||||
"main": "esiur.js",
|
||||
"scripts": {
|
||||
|
@ -11,6 +11,7 @@ class MyStore extends IStore
|
||||
async function load()
|
||||
{
|
||||
window.x = await wh.get("iip://localhost:5001/db/my", {username: "demo", password: "1234"});
|
||||
|
||||
console.log(window.x);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user