@soundworks/core
Advanced tools
Comparing version 3.0.0-alpha.6 to 3.0.0-alpha.7
@@ -10,3 +10,3 @@ "use strict"; | ||
var _StateManager = _interopRequireDefault(require("./StateManager")); | ||
var _ClientStateManager = _interopRequireDefault(require("../common/ClientStateManager")); | ||
@@ -50,3 +50,3 @@ var _Socket = _interopRequireDefault(require("./Socket")); | ||
*/ | ||
this.clientType = null; | ||
this.type = null; | ||
/** | ||
@@ -102,3 +102,3 @@ * Unique session id of the client (incremeted positive number), | ||
this.clientType = config.clientType; // @todo - review that to adapt to ws options | ||
this.type = config.clientType; // @todo - review that to adapt to ws options | ||
@@ -114,3 +114,3 @@ const websockets = Object.assign({ | ||
await this.socket.init(this.clientType, this.config); | ||
await this.socket.init(this.type, this.config); | ||
return Promise.resolve(); | ||
@@ -139,5 +139,12 @@ } | ||
this.id = id; | ||
this.uuid = uuid; | ||
this.stateManager = new _StateManager.default(this.id, this.socket); // everything is ready start service manager | ||
this.uuid = uuid; // mimic eventEmitter API | ||
const transport = { | ||
emit: this.socket.send.bind(this.socket), | ||
addListener: this.socket.addListener.bind(this.socket), | ||
// removeListener: this.socket.removeListener.bind(this.socket), | ||
removeAllListeners: this.socket.removeAllListeners.bind(this.socket) | ||
}; | ||
this.stateManager = new _ClientStateManager.default(this.id, transport); // everything is ready start service manager | ||
this.serviceManager.start().then(() => resolve()); | ||
@@ -144,0 +151,0 @@ }); |
@@ -6,8 +6,6 @@ "use strict"; | ||
}); | ||
exports.default = exports.Client = exports.Service = exports.Experience = void 0; | ||
exports.default = exports.Client = exports.Experience = void 0; | ||
var _Experience = _interopRequireDefault(require("./Experience")); | ||
var _Service = _interopRequireDefault(require("./Service")); | ||
var _Client = _interopRequireDefault(require("./Client")); | ||
@@ -40,2 +38,3 @@ | ||
*/ | ||
// import { default as TmpService } from './Service'; | ||
// (very) weird workaround to be able to: | ||
@@ -47,6 +46,5 @@ // | ||
// | ||
const Experience = _Experience.default; | ||
const Experience = _Experience.default; // export const Service = TmpService; | ||
exports.Experience = Experience; | ||
const Service = _Service.default; | ||
exports.Service = Service; | ||
const Client = _Client.default; | ||
@@ -53,0 +51,0 @@ exports.Client = Client; |
@@ -37,3 +37,3 @@ "use strict"; | ||
* @instance | ||
* @memberof module:@soundworks/core/server.Service | ||
* @memberof @soundworks/core/client.Service | ||
*/ | ||
@@ -64,3 +64,3 @@ | ||
* Signals defining the process state. | ||
* @name signal | ||
* @name signals | ||
* @type {Object} | ||
@@ -112,3 +112,3 @@ * @instance | ||
start() { | ||
throw new Error(`service "${this.name}.start()" not implemented`); | ||
throw new Error(`service "${this.name}": "start()" not implemented or "super.start()" called`); | ||
} | ||
@@ -115,0 +115,0 @@ /** |
@@ -172,6 +172,14 @@ "use strict"; | ||
this._servicesStatus[name] = 'started'; | ||
unsubscribe = instance.state.subscribe(() => { | ||
this._emitChange(); | ||
}); | ||
/** | ||
* @fixme - relying on `instance.state` is very weak... | ||
* we should find a better solution, to declare that we want the | ||
* serviceManager to watch and propagate initialization steps. | ||
*/ | ||
if (instance.state) { | ||
unsubscribe = instance.state.subscribe(() => { | ||
this._emitChange(); | ||
}); | ||
} | ||
this._emitChange(); | ||
@@ -185,3 +193,6 @@ }; | ||
unsubscribe(); | ||
if (unsubscribe) { | ||
unsubscribe(); | ||
} | ||
instance.signals.started.removeObserver(onServiceStarted); | ||
@@ -197,3 +208,6 @@ instance.signals.ready.removeObserver(onServiceReady); | ||
unsubscribe(); | ||
if (unsubscribe) { | ||
unsubscribe(); | ||
} | ||
instance.signals.started.removeObserver(onServiceStarted); | ||
@@ -200,0 +214,0 @@ instance.signals.ready.removeObserver(onServiceReady); |
@@ -50,2 +50,4 @@ "use strict"; | ||
*/ | ||
/** @private */ | ||
this.ws = null; | ||
@@ -56,3 +58,4 @@ this._stringListeners = new Map(); | ||
/** | ||
* Initialize a websocket connection with the server | ||
* Initialize a websocket connection with the server. This is automatically | ||
* called in `client.init()` | ||
* @param {String} clientType - `client.type` {@link client} | ||
@@ -63,3 +66,5 @@ * @param {Object} options - Options of the socket | ||
/** @private */ | ||
init(clientType, config) { | ||
@@ -66,0 +71,0 @@ // unique key that allows to associate the two sockets to the same client. |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.UPDATE_NOTIFICATION = exports.UPDATE_RESPONSE = exports.UPDATE_REQUEST = exports.OBSERVE_NOTIFICATION = exports.OBSERVE_RESPONSE = exports.OBSERVE_REQUEST = exports.DETACH_ERROR = exports.DETACH_RESPONSE = exports.DETACH_REQUEST = exports.ATTACH_ERROR = exports.ATTACH_RESPONSE = exports.ATTACH_REQUEST = exports.DELETE_NOTIFICATION = exports.DELETE_ERROR = exports.DELETE_RESPONSE = exports.DELETE_REQUEST = exports.CREATE_ERROR = exports.CREATE_RESPONSE = exports.CREATE_REQUEST = exports.SERVER_ID = void 0; | ||
exports.UPDATE_NOTIFICATION = exports.UPDATE_ABORT = exports.UPDATE_RESPONSE = exports.UPDATE_REQUEST = exports.OBSERVE_NOTIFICATION = exports.OBSERVE_RESPONSE = exports.OBSERVE_REQUEST = exports.DETACH_ERROR = exports.DETACH_RESPONSE = exports.DETACH_REQUEST = exports.ATTACH_ERROR = exports.ATTACH_RESPONSE = exports.ATTACH_REQUEST = exports.DELETE_NOTIFICATION = exports.DELETE_ERROR = exports.DELETE_RESPONSE = exports.DELETE_REQUEST = exports.CREATE_ERROR = exports.CREATE_RESPONSE = exports.CREATE_REQUEST = exports.SERVER_ID = void 0; | ||
// id of the server when owner of a state | ||
@@ -48,3 +48,5 @@ const SERVER_ID = -1; | ||
exports.UPDATE_RESPONSE = UPDATE_RESPONSE; | ||
const UPDATE_ABORT = 's:u:ab'; | ||
exports.UPDATE_ABORT = UPDATE_ABORT; | ||
const UPDATE_NOTIFICATION = 's:u:not'; | ||
exports.UPDATE_NOTIFICATION = UPDATE_NOTIFICATION; |
{ | ||
"name": "@soundworks/core", | ||
"version": "3.0.0-alpha.6", | ||
"version": "3.0.0-alpha.7", | ||
"description": "full-stack javascript framework for distributed audio visual experiences on the web", | ||
@@ -21,2 +21,3 @@ "authors": [ | ||
"clean": "rm -Rf client && rm -Rf server && rm -Rf common", | ||
"graphs": "madge --image resources/graph-client.svg src/client && madge --image resources/graph-server.svg src/server", | ||
"deploy": "np --yolo", | ||
@@ -35,3 +36,2 @@ "doc": "jsdoc -c jsdoc.json", | ||
"dependencies": { | ||
"@babel/plugin-proposal-export-default-from": "^7.5.2", | ||
"@ircam/parameters": "^1.2.2", | ||
@@ -58,2 +58,3 @@ "chalk": "^2.4.2", | ||
"@babel/preset-env": "^7.4.5", | ||
"@babel/plugin-proposal-export-default-from": "^7.5.2", | ||
"@ircam/jsdoc-template": "^1.0.2", | ||
@@ -60,0 +61,0 @@ "chokidar": "^3.0.1", |
@@ -59,65 +59,2 @@ "use strict"; | ||
/** | ||
* @note - remove all that, should be directly related to the services | ||
* @example | ||
* // client side | ||
* const index = this.checkin.getIndex(); | ||
* // server side | ||
* const index = this.checkin.getIndex(client); | ||
*/ | ||
/** | ||
* Coordinates of the client, stored as an `[x:Number, y:Number]` array. | ||
* @name coordinates | ||
* @type {Array<Number>} | ||
* @memberof module:soundworks/server.Client | ||
* @instance | ||
*/ | ||
this.coordinates = null; | ||
/** | ||
* Geoposition of the client as returned by `geolocation.getCurrentPosition` | ||
* @name geoposition | ||
* @typ {Object} | ||
* @memberof module:soundworks/server.Client | ||
* @instance | ||
*/ | ||
this.geoposition = null; | ||
/** | ||
* Ticket index of the client. | ||
* @name index | ||
* @type {Number} | ||
* @memberof module:soundworks/server.Client | ||
* @instance | ||
*/ | ||
this.index = null; | ||
/** | ||
* Ticket label of the client. | ||
* @name label | ||
* @type {Number} | ||
* @memberof module:soundworks/server.Client | ||
* @instance | ||
*/ | ||
this.label = null; // /** | ||
// * Used by the activities to associate data to a particular client. | ||
// * | ||
// * All the data associated with a activity whose `name` is `'activityName'` | ||
// * is accessible through the key `activityName`. | ||
// * For instance, the {@link src/server/Checkin.js~Checkin} activity keeps | ||
// * track of client's checkin index and label in `this.activities.checkin.index` | ||
// * and `this.activities.checkin.label`. | ||
// * Similarly, a {@link src/server/Performance.js~Performance} activity whose | ||
// * name is `'myPerformance'` could report the client's status in | ||
// * `this.activities.myPerformance.status`. | ||
// * | ||
// * @name activities | ||
// * @type {Object} | ||
// * @memberof module:soundworks/server.Client | ||
// * @instance | ||
// */ | ||
// this.activities = {}; | ||
/** | ||
* Socket used to communicate with the client. | ||
@@ -131,17 +68,2 @@ * @type {Socket} | ||
/** | ||
* Returns a lightweight version of the data defining the client. | ||
* @returns {Object} | ||
*/ | ||
// serialize() { | ||
// return { | ||
// type: this.type, | ||
// uuid: this.uuid, | ||
// coordinates: this.coordinates, | ||
// index: this.index, | ||
// label: this.label, | ||
// activities: this.activities, | ||
// }; | ||
// } | ||
/** | ||
* Destroy the client. | ||
@@ -148,0 +70,0 @@ */ |
@@ -20,6 +20,11 @@ "use strict"; | ||
* Simple in file key / value database. | ||
* Do not expose for now, may not be the right way to go... | ||
* | ||
* @todo - implement options to change storage solution. | ||
* cf. https://github.com/lukechilds/keyv | ||
* | ||
* @memberof @soundworks/core/server | ||
*/ | ||
/** @private */ | ||
class Db { | ||
@@ -26,0 +31,0 @@ constructor(options = {}) { |
@@ -72,3 +72,10 @@ "use strict"; | ||
connect(client) { | ||
this.server.stateManager.addClient(client); // listen for the `'enter' socket message from the client, the message is | ||
const nodeId = client.id; | ||
const transport = { | ||
emit: client.socket.send.bind(client.socket), | ||
addListener: client.socket.addListener.bind(client.socket), | ||
// removeListener: client.socket.removeListener.bind(client.socket), | ||
removeAllListeners: client.socket.removeAllListeners.bind(client.socket) | ||
}; | ||
this.server.stateManager.addClient(nodeId, transport); // listen for the `'enter' socket message from the client, the message is | ||
// sent when the client `enters` the Experience client side, i.e. when all | ||
@@ -92,3 +99,4 @@ // required services are ready | ||
disconnect(client) { | ||
this.server.stateManager.removeClient(client); // only call exit if the client has fully entered | ||
const nodeId = client.id; | ||
this.server.stateManager.removeClient(nodeId); // only call exit if the client has fully entered | ||
// (i.e. has finished the its initialization phase) | ||
@@ -95,0 +103,0 @@ |
@@ -12,8 +12,2 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "Service", { | ||
enumerable: true, | ||
get: function () { | ||
return _Service.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Experience", { | ||
@@ -28,6 +22,4 @@ enumerable: true, | ||
var _Service = _interopRequireDefault(require("./Service")); | ||
var _Experience = _interopRequireDefault(require("./Experience")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _events = _interopRequireDefault(require("events")); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
@@ -35,3 +37,3 @@ | ||
var _StateManager = _interopRequireDefault(require("./StateManager")); | ||
var _ServerStateManager = _interopRequireDefault(require("../common/ServerStateManager")); | ||
@@ -85,3 +87,3 @@ var _Db = _interopRequireDefault(require("./Db")); | ||
* Router. Internally use polka. | ||
* (cf. https://github.com/lukeed/polka) | ||
* (cf. {@link https://github.com/lukeed/polka}) | ||
*/ | ||
@@ -92,3 +94,3 @@ | ||
* http(s) server instance. The node `http` or `https` module instance | ||
* (cf. https://nodejs.org/api/http.html) | ||
* (cf. {@link https://nodejs.org/api/http.html}) | ||
*/ | ||
@@ -99,3 +101,4 @@ | ||
* Key / value storage with Promise based Map API | ||
* basically a wrapper around kvey (https://github.com/lukechilds/keyv) | ||
* basically a wrapper around kvey (cf. {@link https://github.com/lukechilds/keyv}) | ||
* @private | ||
*/ | ||
@@ -105,5 +108,5 @@ | ||
/** | ||
* wrapper around `ws` server | ||
* @type {module:soundworks/server.sockets} | ||
* @default module:soundworks/server.sockets | ||
* Wrapper around `ws` server. | ||
* cf. {@link @soundworks/core/server.Sockets} | ||
* @type {soundworks/core/server.Sockets} | ||
*/ | ||
@@ -113,3 +116,5 @@ | ||
/** | ||
* | ||
* The `serviceManager` instance. | ||
* cf. {@link @soundworks/core/server.ServiceManager} | ||
* @type {soundworks/core/server.ServiceManager} | ||
*/ | ||
@@ -119,3 +124,5 @@ | ||
/** | ||
* | ||
* The `StateManager` instance. | ||
* cf. {@link @soundworks/core/server.StateManager} | ||
* @type {soundworks/core/server.StateManager} | ||
*/ | ||
@@ -127,2 +134,3 @@ | ||
* @todo - put in config... | ||
* @private | ||
*/ | ||
@@ -146,4 +154,4 @@ | ||
* Optionnal routing defined for each client. | ||
* @type {Object} | ||
* @private | ||
* @type {Object} | ||
*/ | ||
@@ -153,3 +161,3 @@ | ||
/** | ||
* | ||
* @private | ||
*/ | ||
@@ -210,3 +218,14 @@ | ||
this.router.use((0, _compression.default)()); | ||
this.stateManager = new _StateManager.default(this); | ||
this.stateManager = new _ServerStateManager.default(); // const transport = new EventEmitter(); | ||
// transport.send = transport.emit.bind(transport); | ||
// serverStateManager.addClient({ id: -1, transport }); | ||
// this.stateManager = new ClientStateManager(-1, transport); | ||
// // should be a mixin | ||
// this.stateManager.registerSchema = (name, schema) => { | ||
// serverStateManager.registerSchema(name, schema); | ||
// } | ||
// this.stateManager.deleteSchema = (name, schema) => { | ||
// serverStateManager.deleteSchema(name, schema); | ||
// } | ||
this.db = new _Db.default(); | ||
@@ -257,2 +276,4 @@ return Promise.resolve(); | ||
const httpsServer = _https.default.createServer(this._httpsInfos); | ||
return Promise.resolve(httpsServer); | ||
} catch (err) { | ||
@@ -265,4 +286,2 @@ console.error(`Invalid certificate files, please check your: | ||
} | ||
return Promise.resolve(httpsServer); | ||
} else { | ||
@@ -273,3 +292,3 @@ return new Promise(async (resolve, reject) => { | ||
if (key !== null && cert !== null) { | ||
if (key && cert) { | ||
this._httpsInfos = { | ||
@@ -276,0 +295,0 @@ key, |
@@ -21,3 +21,3 @@ "use strict"; | ||
/** | ||
* Base class to be extended in order to create a new service. | ||
* Base class to extend for creating new soundworks services. | ||
* | ||
@@ -32,3 +32,3 @@ * @memberof @soundworks/core/server | ||
/** | ||
* Instance of soundworks server | ||
* Instance of soundworks server. | ||
* @type {String} | ||
@@ -38,2 +38,3 @@ * @name server | ||
* @memberof module:@soundworks/core/server.Service | ||
* | ||
*/ | ||
@@ -62,5 +63,5 @@ this.server = server; | ||
* Signals defining the process state. | ||
* @name signal | ||
* @name signals | ||
* @type {Object} | ||
* @instanceof Process | ||
* @memberof module:@soundworks/core/server.Service | ||
*/ | ||
@@ -74,5 +75,3 @@ | ||
}; | ||
/** | ||
* | ||
*/ | ||
/** @private */ | ||
@@ -114,3 +113,3 @@ this.clientTypes = new Set(); // register in the server | ||
start() { | ||
throw new Error(`service "${this.name}.start()" not implemented`); | ||
throw new Error(`service "${this.name}": "start()" not implemented or "super.start()" called`); | ||
} | ||
@@ -117,0 +116,0 @@ |
@@ -139,7 +139,8 @@ "use strict"; | ||
/** | ||
* @private | ||
* Called when the string socket closes (aka client reload). | ||
*/ | ||
/** @private */ | ||
terminate() { | ||
@@ -146,0 +147,0 @@ clearInterval(this._intervalId); // clean rooms |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
121114
16
10
2900
- Removed@ampproject/remapping@2.3.0(transitive)
- Removed@babel/code-frame@7.24.7(transitive)
- Removed@babel/compat-data@7.25.4(transitive)
- Removed@babel/core@7.25.2(transitive)
- Removed@babel/generator@7.25.6(transitive)
- Removed@babel/helper-compilation-targets@7.25.2(transitive)
- Removed@babel/helper-module-imports@7.24.7(transitive)
- Removed@babel/helper-module-transforms@7.25.2(transitive)
- Removed@babel/helper-plugin-utils@7.24.8(transitive)
- Removed@babel/helper-simple-access@7.24.7(transitive)
- Removed@babel/helper-string-parser@7.24.8(transitive)
- Removed@babel/helper-validator-identifier@7.24.7(transitive)
- Removed@babel/helper-validator-option@7.24.8(transitive)
- Removed@babel/helpers@7.25.6(transitive)
- Removed@babel/highlight@7.24.7(transitive)
- Removed@babel/parser@7.25.6(transitive)
- Removed@babel/plugin-proposal-export-default-from@7.24.7(transitive)
- Removed@babel/plugin-syntax-export-default-from@7.24.7(transitive)
- Removed@babel/template@7.25.0(transitive)
- Removed@babel/traverse@7.25.6(transitive)
- Removed@babel/types@7.25.6(transitive)
- Removed@jridgewell/gen-mapping@0.3.5(transitive)
- Removed@jridgewell/resolve-uri@3.1.2(transitive)
- Removed@jridgewell/set-array@1.2.1(transitive)
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removed@jridgewell/trace-mapping@0.3.25(transitive)
- Removedbrowserslist@4.24.0(transitive)
- Removedcaniuse-lite@1.0.30001664(transitive)
- Removedconvert-source-map@2.0.0(transitive)
- Removedelectron-to-chromium@1.5.29(transitive)
- Removedescalade@3.2.0(transitive)
- Removedgensync@1.0.0-beta.2(transitive)
- Removedglobals@11.12.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjsesc@2.5.2(transitive)
- Removedjson5@2.2.3(transitive)
- Removedlru-cache@5.1.1(transitive)
- Removednode-releases@2.0.18(transitive)
- Removedpicocolors@1.1.0(transitive)
- Removedsemver@6.3.1(transitive)
- Removedto-fast-properties@2.0.0(transitive)
- Removedupdate-browserslist-db@1.1.1(transitive)
- Removedyallist@3.1.1(transitive)