5051 lines
189 KiB
JavaScript
5051 lines
189 KiB
JavaScript
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jiboCommandLibrary = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const jibo_typed_events_1 = require("jibo-typed-events");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class CommandConnector {
|
|
get id() {
|
|
return this._id;
|
|
}
|
|
get aco() {
|
|
return this._aco;
|
|
}
|
|
get isReady() {
|
|
return this._isReady;
|
|
}
|
|
get isConnected() {
|
|
return this._isConnected;
|
|
}
|
|
get isAwaitingReconnect() {
|
|
return this._isAwaitingReconnect;
|
|
}
|
|
get sessionId() {
|
|
return this._sessionId;
|
|
}
|
|
set responseHandler(handler) {
|
|
this._responseCB = handler;
|
|
}
|
|
set sessionClosedHandler(handler) {
|
|
this._sessionEndedCB = handler;
|
|
}
|
|
constructor(id, commandLib, isReady = true) {
|
|
this.onResponse = this.onResponse.bind(this);
|
|
this.onSessionClose = this.onSessionClose.bind(this);
|
|
this.onSessionStarted = this.onSessionStarted.bind(this);
|
|
this._id = id;
|
|
this._isConnected = false;
|
|
this._isAwaitingReconnect = false;
|
|
this._aco = null;
|
|
this._commandProxy = null;
|
|
this._responseCB = null;
|
|
this._sessionEndedCB = null;
|
|
this._sessionId = '';
|
|
this._isReady = isReady;
|
|
this.onReady = new jibo_typed_events_1.Event('Conection ready, id:' + this._id);
|
|
this._onConnect = new jibo_typed_events_1.Event('Connect to command library');
|
|
this._onConnect.on(commandLib.connect);
|
|
}
|
|
connect(aco, responseCB, sessionEndedCB) {
|
|
this._aco = aco;
|
|
this._onConnect.emit(this);
|
|
this._responseCB = responseCB;
|
|
this._sessionEndedCB = sessionEndedCB;
|
|
this._isConnected = true;
|
|
this._isAwaitingReconnect = false;
|
|
}
|
|
disconnect(code = jibo_command_protocol_1.DisconnectCode.RobotError) {
|
|
if (this._isConnected || this._isAwaitingReconnect) {
|
|
this._isConnected = false;
|
|
this._isAwaitingReconnect = false;
|
|
this._commandProxy.onEndSession.emit();
|
|
if (this._sessionEndedCB) {
|
|
this._sessionEndedCB(code);
|
|
}
|
|
this._responseCB = null;
|
|
this._sessionEndedCB = null;
|
|
this._sessionId = '';
|
|
if (this._commandProxy) {
|
|
this._commandProxy.destroy();
|
|
this._commandProxy = null;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
awaitReconnect() {
|
|
this._isConnected = false;
|
|
this._isAwaitingReconnect = true;
|
|
if (this._commandProxy) {
|
|
this._commandProxy.onAwaitReconnect.emit();
|
|
}
|
|
}
|
|
sendMessage(message) {
|
|
if (this._commandProxy) {
|
|
this._commandProxy.onMessage.emit(message);
|
|
}
|
|
}
|
|
responseFailed(message) {
|
|
if (this._commandProxy) {
|
|
this._commandProxy.onResponseFailed.emit(message);
|
|
}
|
|
}
|
|
ready(isReady = true) {
|
|
this._isReady = isReady;
|
|
if (isReady) {
|
|
this.onReady.emit();
|
|
}
|
|
}
|
|
applyProxy(commandProxy) {
|
|
this._commandProxy = commandProxy;
|
|
commandProxy.onResponse.on(this.onResponse);
|
|
commandProxy.onSessionClose.on(this.onSessionClose);
|
|
commandProxy.onSessionStarted.on(this.onSessionStarted);
|
|
}
|
|
onResponse(message) {
|
|
if (this._responseCB) {
|
|
this._responseCB(message);
|
|
}
|
|
}
|
|
onSessionClose(code) {
|
|
if (this._sessionEndedCB) {
|
|
this._sessionEndedCB(code);
|
|
}
|
|
}
|
|
onSessionStarted(sessionId) {
|
|
this._sessionId = sessionId;
|
|
}
|
|
}
|
|
exports.CommandConnector = CommandConnector;
|
|
|
|
},{"jibo-command-protocol":undefined,"jibo-typed-events":undefined}],2:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const jibo_typed_events_1 = require("jibo-typed-events");
|
|
class CommandProxy {
|
|
constructor() {
|
|
this.response = this.response.bind(this);
|
|
this.sessionClose = this.sessionClose.bind(this);
|
|
this.onAwaitReconnect = new jibo_typed_events_1.Event('Pause session');
|
|
this.onEndSession = new jibo_typed_events_1.Event('End session, external cause');
|
|
this.onMessage = new jibo_typed_events_1.Event('Send command');
|
|
this.onResponseFailed = new jibo_typed_events_1.Event('Response failed command');
|
|
this.onResponse = new jibo_typed_events_1.Event('Command response');
|
|
this.onSessionClose = new jibo_typed_events_1.Event('Session ended, internal cause');
|
|
this.onSessionStarted = new jibo_typed_events_1.Event('Session started');
|
|
}
|
|
response(message) {
|
|
this.onResponse.emit(message);
|
|
}
|
|
sessionClose(code) {
|
|
this.onSessionClose.emit(code);
|
|
}
|
|
sessionStarted(sessionId) {
|
|
this.onSessionStarted.emit(sessionId);
|
|
}
|
|
destroy() {
|
|
if (this.onAwaitReconnect) {
|
|
this.onAwaitReconnect.removeAllListeners();
|
|
this.onAwaitReconnect = null;
|
|
}
|
|
if (this.onEndSession) {
|
|
this.onEndSession.removeAllListeners();
|
|
this.onEndSession = null;
|
|
}
|
|
if (this.onMessage) {
|
|
this.onMessage.removeAllListeners();
|
|
this.onMessage = null;
|
|
}
|
|
if (this.onResponse) {
|
|
this.onResponse.removeAllListeners();
|
|
this.onResponse = null;
|
|
}
|
|
if (this.onSessionClose) {
|
|
this.onSessionClose.removeAllListeners();
|
|
this.onSessionClose = null;
|
|
}
|
|
}
|
|
}
|
|
exports.default = CommandProxy;
|
|
|
|
},{"jibo-typed-events":undefined}],3:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const components_1 = require("./commander/components");
|
|
class CommandSession {
|
|
get sessionId() {
|
|
return this._sessionId;
|
|
}
|
|
constructor(commandManager, entity, sessionId, messageQueue) {
|
|
this.commandManager = commandManager;
|
|
this._sessionId = sessionId;
|
|
entity.name = sessionId;
|
|
this._entity = entity;
|
|
this.session = entity.get(components_1.Session);
|
|
this.session.id = sessionId;
|
|
this.messageQueue = messageQueue;
|
|
}
|
|
storeFailedResponse(message) {
|
|
this.session.storedEvents.push(message);
|
|
}
|
|
dispose() {
|
|
if (this.commandManager) {
|
|
this.commandManager.dispose();
|
|
}
|
|
this.clear();
|
|
}
|
|
clear() {
|
|
this.commandManager = null;
|
|
this.session = null;
|
|
this._entity = null;
|
|
}
|
|
}
|
|
exports.default = CommandSession;
|
|
|
|
},{"./commander/components":34}],4:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const uuid = require("uuid");
|
|
const log_1 = require("./log");
|
|
const CommandManager_1 = require("./commander/CommandManager");
|
|
const CommandSession_1 = require("./CommandSession");
|
|
const CommandUtil_1 = require("./CommandUtil");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class CommandSessionManager {
|
|
set permissions(permissions) {
|
|
this._permissions = permissions;
|
|
}
|
|
get version() {
|
|
if (this._permissions) {
|
|
return this._permissions.version;
|
|
}
|
|
return null;
|
|
}
|
|
get session() {
|
|
return this._commandSession;
|
|
}
|
|
get sessionId() {
|
|
if (this._commandSession) {
|
|
return this._commandSession.sessionId;
|
|
}
|
|
this.log.warn('no active command session, cannot retrieve a sessionId');
|
|
return '';
|
|
}
|
|
constructor() {
|
|
this._commandSession = null;
|
|
this._permissions = null;
|
|
this._pendingSessionCommand = null;
|
|
this.log = log_1.default.createChild('session-manager');
|
|
}
|
|
checkSessionMismatch(sessionId) {
|
|
if (this._commandSession) {
|
|
return (sessionId !== this._commandSession.session.id);
|
|
}
|
|
return false;
|
|
}
|
|
checkSessionCommand(data) {
|
|
if (CommandUtil_1.default.getCommandType(data, this.version) === jibo_command_protocol_1.CommandTypes.StartSession) {
|
|
this._pendingSessionCommand = data;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
startSession(sendMethod, sessionCloseMethod) {
|
|
if (this._commandSession) {
|
|
this._commandSession.session.hasConnection = true;
|
|
this.log.info('startSession : session has been restored');
|
|
}
|
|
else {
|
|
this.log.info('startSession : creating a new session');
|
|
const commander = new CommandManager_1.default(this._permissions);
|
|
const sessionEntity = commander.onCommand(this._pendingSessionCommand);
|
|
let sessionId = CommandUtil_1.default.getSessionId(this._pendingSessionCommand, this._permissions.version) || uuid.v4();
|
|
this._commandSession = new CommandSession_1.default(commander, sessionEntity, sessionId);
|
|
this._commandSession.session.sendMethod = sendMethod;
|
|
this._commandSession.session.endSessionMethod = sessionCloseMethod;
|
|
commander.startSession(sessionEntity);
|
|
}
|
|
}
|
|
endSession() {
|
|
if (this._commandSession) {
|
|
this._commandSession.dispose();
|
|
this._commandSession = null;
|
|
}
|
|
else {
|
|
this.log.info('endSession : command session is already null, nothing to dispose');
|
|
}
|
|
}
|
|
resetInactivityTimeout() {
|
|
if (this._commandSession) {
|
|
this._commandSession.session.inactivityDuration = 0;
|
|
}
|
|
}
|
|
resetReconnectTimeout() {
|
|
if (this._commandSession) {
|
|
this._commandSession.session.reconnectDuration = 0;
|
|
}
|
|
}
|
|
startCommand(data) {
|
|
this._commandSession.commandManager.onCommand(data);
|
|
}
|
|
handleFailedResponse(message) {
|
|
if (this._commandSession) {
|
|
this._commandSession.storeFailedResponse(message);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
handleDisconnection() {
|
|
if (!this._commandSession) {
|
|
return false;
|
|
}
|
|
this._commandSession.session.hasConnection = false;
|
|
return true;
|
|
}
|
|
}
|
|
exports.default = CommandSessionManager;
|
|
|
|
},{"./CommandSession":3,"./CommandUtil":5,"./commander/CommandManager":8,"./log":98,"jibo-command-protocol":undefined,"uuid":undefined}],5:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class CommandUtil {
|
|
static createAcknowledgement(version, transactionId, sessionId, responseCode, data) {
|
|
let event;
|
|
if (version === '1.0') {
|
|
const header = {
|
|
RobotID: CommandUtil.robotId,
|
|
TransactionID: transactionId,
|
|
SessionID: sessionId
|
|
};
|
|
const response = {
|
|
ResponseCode: responseCode,
|
|
ResponseString: jibo_command_protocol_1.ResponseStrings[responseCode],
|
|
Value: responseCode >= 400 ? 'Error' : 'Success'
|
|
};
|
|
if (data) {
|
|
if (responseCode >= 400) {
|
|
response.ErrorDetail = data;
|
|
}
|
|
else {
|
|
response.ResponseBody = data;
|
|
}
|
|
}
|
|
event = {
|
|
ResponseHeader: header,
|
|
Response: response
|
|
};
|
|
}
|
|
return event;
|
|
}
|
|
static createEvent(version, transactionId, sessionId, data) {
|
|
let event;
|
|
if (version === '1.0') {
|
|
const header = {
|
|
RobotID: CommandUtil.robotId,
|
|
TransactionID: transactionId,
|
|
SessionID: sessionId,
|
|
Timestamp: CommandUtil.getNetworkTime()
|
|
};
|
|
event = {
|
|
EventHeader: header,
|
|
EventBody: data
|
|
};
|
|
}
|
|
return event;
|
|
}
|
|
static getNetworkTime() {
|
|
return Date.now();
|
|
}
|
|
static getVersion(data, version = "1.0") {
|
|
switch (version) {
|
|
case '1.0':
|
|
if (data.ClientHeader) {
|
|
return data.ClientHeader.Version;
|
|
}
|
|
break;
|
|
}
|
|
return null;
|
|
}
|
|
static getTransactionId(data, version = '1.0') {
|
|
switch (version) {
|
|
case '1.0':
|
|
if (data.ClientHeader) {
|
|
return data.ClientHeader.TransactionID;
|
|
}
|
|
break;
|
|
}
|
|
return null;
|
|
}
|
|
static getSessionId(data, version = '1.0') {
|
|
switch (version) {
|
|
case '1.0':
|
|
if (data.ClientHeader) {
|
|
return data.ClientHeader.SessionID;
|
|
}
|
|
break;
|
|
}
|
|
return null;
|
|
}
|
|
static getCommandType(data, version = '1.0') {
|
|
switch (version) {
|
|
case '1.0':
|
|
if (data.Command) {
|
|
return data.Command.Type;
|
|
}
|
|
break;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
CommandUtil.robotId = '';
|
|
CommandUtil.LISTEN_COLORS = [0.05, 0.73, 0.94];
|
|
exports.default = CommandUtil;
|
|
|
|
},{"jibo-command-protocol":undefined}],6:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
function formatCommandErrors(errors) {
|
|
const filtered = errors.filter(isCommandSpecific);
|
|
return formatGeneralErrors(filtered.length ? filtered : errors);
|
|
}
|
|
exports.formatCommandErrors = formatCommandErrors;
|
|
function isCommandSpecific(error) {
|
|
if (error.data && error.data.Type) {
|
|
const type = error.data.Type;
|
|
if (error.parentSchema && error.parentSchema.properties &&
|
|
error.parentSchema.properties.Type && error.parentSchema.properties.Type.enum &&
|
|
error.parentSchema.properties.Type.enum[0] === type) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
function formatGeneralErrors(errors) {
|
|
return errors.map(formatError).join('\n');
|
|
}
|
|
function formatError(error) {
|
|
let output = error.dataPath + ' ' + error.message;
|
|
if (error.keyword === 'additionalProperties') {
|
|
output += ' - found property ' + error.params.additionalProperty;
|
|
}
|
|
return output;
|
|
}
|
|
|
|
},{}],7:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("./core");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
const components_1 = require("./components");
|
|
const components_2 = require("./components");
|
|
class CommandCreator {
|
|
constructor(engine, permissions) {
|
|
this._engine = engine;
|
|
this._permissions = permissions;
|
|
this.version = permissions.version;
|
|
}
|
|
commandFromRequestProtocol(data) {
|
|
let commandEntity = new core_1.Entity();
|
|
let request = new components_1.RequestCommand(data);
|
|
request.version = this.version;
|
|
commandEntity.name = request.id;
|
|
commandEntity.add(request);
|
|
let body = data.Command;
|
|
switch (body.Type) {
|
|
case jibo_command_protocol_1.CommandTypes.StartSession:
|
|
this.createSession(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.Cancel:
|
|
this.createInterrupt(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.LookAt:
|
|
this.createLookAt(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.Say:
|
|
this.createPlay(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.SetAttention:
|
|
this.createAttention(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.Subscribe:
|
|
switch (body.StreamType) {
|
|
case jibo_command_protocol_1.StreamTypes.Entity:
|
|
this.createPersonStream(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.StreamTypes.HotWord:
|
|
this.createHotWord(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.StreamTypes.ScreenGesture:
|
|
this.createScreenGesture(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.StreamTypes.Motion:
|
|
this.createMotionStream(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.StreamTypes.HeadTouch:
|
|
this.createHeadTouch(commandEntity, request, body);
|
|
break;
|
|
}
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.TakePhoto:
|
|
this.createTakePhoto(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.Video:
|
|
this.createPhotoStream(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.SetConfig:
|
|
this.createSetConfig(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.GetConfig:
|
|
this.createGetConfig(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.Display:
|
|
this.createDisplay(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.FetchAsset:
|
|
this.createFetchAsset(commandEntity, request, body);
|
|
break;
|
|
case jibo_command_protocol_1.CommandTypes.Listen:
|
|
this.createListen(commandEntity, request, body);
|
|
break;
|
|
default:
|
|
if (body.Type === 'Test') {
|
|
this.createTest(commandEntity, request, body);
|
|
break;
|
|
}
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.NotFound, true);
|
|
break;
|
|
}
|
|
return commandEntity;
|
|
}
|
|
createSession(commandEntity, request, body) {
|
|
const session = new components_1.Session();
|
|
session.inactivityTimeout = this._permissions.inactivityTimeout / 1000;
|
|
session.reconnectTimeout = 10;
|
|
commandEntity.add(session);
|
|
}
|
|
createInterrupt(commandEntity, request, body) {
|
|
commandEntity.add(new components_1.Interrupt(body.ID));
|
|
}
|
|
createLookAt(commandEntity, request, body) {
|
|
if (this._permissions.lookAt) {
|
|
commandEntity.add(new components_1.LookAt(body.TrackFlag, body.LevelHeadFlag));
|
|
commandEntity.add(new components_1.Target(body.LookAtTarget));
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createPlay(commandEntity, request, body) {
|
|
if (this._permissions.play) {
|
|
commandEntity.add(new components_1.Play(body.ESML));
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createAttention(commandEntity, request, body) {
|
|
commandEntity.add(new components_1.Attention(body.Mode));
|
|
}
|
|
createPersonStream(commandEntity, request, body) {
|
|
if (this._permissions.personStream) {
|
|
commandEntity.add(new components_1.PersonStream());
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createHotWord(commandEntity, request, body) {
|
|
if (this._permissions.hotWord) {
|
|
commandEntity.add(new components_1.HotWord());
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createScreenGesture(commandEntity, request, body) {
|
|
if (this._permissions.screenGesture) {
|
|
commandEntity.add(new components_1.ScreenGesture());
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createMotionStream(commandEntity, request, body) {
|
|
if (this._permissions.motionStream) {
|
|
commandEntity.add(new components_1.MotionStream());
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createHeadTouch(commandEntity, request, body) {
|
|
if (this._permissions.headTouch) {
|
|
commandEntity.add(new components_1.HeadTouch());
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createTakePhoto(commandEntity, request, body) {
|
|
if (this._permissions.takePhoto) {
|
|
commandEntity.add(new components_1.TakePhoto(body.Distortion, body.Camera, body.Resolution));
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createPhotoStream(commandEntity, request, body) {
|
|
if (this._permissions.video) {
|
|
commandEntity.add(new components_1.PhotoStream(body.VideoType));
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createSetConfig(commandEntity, request, body) {
|
|
if (this._permissions.setConfig) {
|
|
commandEntity.add(new components_1.SetConfig(body.Options));
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createGetConfig(commandEntity, request, body) {
|
|
if (this._permissions.getConfig) {
|
|
commandEntity.add(new components_1.GetConfig());
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createDisplay(commandEntity, request, body) {
|
|
if (this._permissions.display) {
|
|
commandEntity.add(new components_1.Display(body.View));
|
|
commandEntity.add(new components_1.DisplayChange());
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createFetchAsset(commandEntity, request, body) {
|
|
if (this._permissions.fetchAsset) {
|
|
commandEntity.add(new components_1.FetchAsset(body.Name, body.URI));
|
|
commandEntity.add(this._engine.getEntityByName("assetCache").get(components_1.AssetCache));
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createListen(commandEntity, request, body) {
|
|
if (this._permissions.listen) {
|
|
commandEntity.add(new components_1.Listen(body.LanguageCode, body.MaxNoSpeechTimeout, body.MaxSpeechTimeout));
|
|
commandEntity.add(new components_1.LightRing());
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
createTest(commandEntity, request, body) {
|
|
if (this._permissions.test) {
|
|
commandEntity.add(new components_2.Test(body));
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Forbidden, true);
|
|
}
|
|
}
|
|
}
|
|
exports.default = CommandCreator;
|
|
|
|
},{"./components":34,"./core":45,"jibo-command-protocol":undefined}],8:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const events_1 = require("events");
|
|
const log_1 = require("../log");
|
|
const EntityManager_1 = require("./EntityManager");
|
|
class CommandManager extends events_1.EventEmitter {
|
|
constructor(permissions) {
|
|
super();
|
|
this._permissions = permissions;
|
|
this.log = log_1.default.createChild('command-manager');
|
|
this.init();
|
|
}
|
|
init() {
|
|
this.entityManager = new EntityManager_1.EntityManager(this._permissions);
|
|
}
|
|
reset() {
|
|
this.entityManager.reset();
|
|
this.init();
|
|
}
|
|
dispose() {
|
|
this.entityManager.dispose();
|
|
}
|
|
onCommand(data) {
|
|
return this.entityManager.addCommand(data);
|
|
}
|
|
startSession(sessionEntity) {
|
|
if (!this.entityManager.active) {
|
|
this.entityManager.addSessionSystems(sessionEntity);
|
|
this.entityManager.start();
|
|
}
|
|
else {
|
|
this.log.warn('startSession() called but entity engine is already active');
|
|
}
|
|
}
|
|
}
|
|
exports.default = CommandManager;
|
|
|
|
},{"../log":98,"./EntityManager":9,"events":undefined}],9:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("./core");
|
|
const CommandCreator_1 = require("./CommandCreator");
|
|
const SystemPriorities_1 = require("./systems/SystemPriorities");
|
|
const AttentionSystem_1 = require("./systems/AttentionSystem");
|
|
const CommandSystem_1 = require("./systems/CommandSystem");
|
|
const DisplaySystem_1 = require("./systems/DisplaySystem");
|
|
const HotWordSystem_1 = require("./systems/HotWordSystem");
|
|
const InterruptSystem_1 = require("./systems/InterruptSystem");
|
|
const RAFTickProvider_1 = require("./core/tick/RAFTickProvider");
|
|
const LookAtSystem_1 = require("./systems/LookAtSystem");
|
|
const PlaySystem_1 = require("./systems/PlaySystem");
|
|
const TakePhotoSystem_1 = require("./systems/TakePhotoSystem");
|
|
const PhotoStreamSystem_1 = require("./systems/PhotoStreamSystem");
|
|
const PersonStreamSystem_1 = require("./systems/PersonStreamSystem");
|
|
const SetConfigSystem_1 = require("./systems/SetConfigSystem");
|
|
const GetConfigSystem_1 = require("./systems/GetConfigSystem");
|
|
const MotionStreamSystem_1 = require("./systems/MotionStreamSystem");
|
|
const AssetsSystem_1 = require("./systems/AssetsSystem");
|
|
const RemoteIndicatorSystem_1 = require("./systems/RemoteIndicatorSystem");
|
|
const HeadTouchSystem_1 = require("./systems/HeadTouchSystem");
|
|
const ScreenTouchSystem_1 = require("./systems/ScreenTouchSystem");
|
|
const ListenSystem_1 = require("./systems/ListenSystem");
|
|
const SessionSystem_1 = require("./systems/SessionSystem");
|
|
const LightRingSystem_1 = require("./systems/LightRingSystem");
|
|
const TestSystem_1 = require("./systems/TestSystem");
|
|
const components_1 = require("./components");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
var Resource;
|
|
(function (Resource) {
|
|
Resource["LIGHT_RING"] = "LIGHT_RING";
|
|
})(Resource = exports.Resource || (exports.Resource = {}));
|
|
class EntityManager {
|
|
constructor(permissions) {
|
|
this._active = false;
|
|
this._permissions = permissions;
|
|
this.prepare();
|
|
}
|
|
get active() {
|
|
return this._active;
|
|
}
|
|
prepare() {
|
|
this.engine = new core_1.Engine();
|
|
this._commandCreator = new CommandCreator_1.default(this.engine, this._permissions);
|
|
}
|
|
addSessionSystems(sessionEntity) {
|
|
this.engine.addSystem(new CommandSystem_1.default(), SystemPriorities_1.SystemPriorities.response);
|
|
this.engine.addSystem(new InterruptSystem_1.default(), SystemPriorities_1.SystemPriorities.interrupt);
|
|
this.engine.addSystem(new SessionSystem_1.default(), SystemPriorities_1.SystemPriorities.session);
|
|
let useLightRing = false;
|
|
if (this._permissions.test) {
|
|
this.engine.addSystem(new TestSystem_1.default(), SystemPriorities_1.SystemPriorities.update);
|
|
}
|
|
if (this._permissions.play) {
|
|
this.engine.addSystem(new PlaySystem_1.default(), SystemPriorities_1.SystemPriorities.update);
|
|
}
|
|
if (this._permissions.display) {
|
|
this.engine.addSystem(new DisplaySystem_1.default(), SystemPriorities_1.SystemPriorities.update);
|
|
}
|
|
if (this._permissions.lookAt) {
|
|
this.engine.addSystem(new LookAtSystem_1.default(), SystemPriorities_1.SystemPriorities.update);
|
|
}
|
|
if (this._permissions.takePhoto) {
|
|
this.engine.addSystem(new TakePhotoSystem_1.default(), SystemPriorities_1.SystemPriorities.update);
|
|
}
|
|
if (this._permissions.video) {
|
|
this.engine.addSystem(new PhotoStreamSystem_1.default(), SystemPriorities_1.SystemPriorities.update);
|
|
}
|
|
if (this._permissions.personStream) {
|
|
this.engine.addSystem(new PersonStreamSystem_1.default(), SystemPriorities_1.SystemPriorities.lps);
|
|
}
|
|
if (this._permissions.motionStream) {
|
|
this.engine.addSystem(new MotionStreamSystem_1.default(), SystemPriorities_1.SystemPriorities.lps);
|
|
}
|
|
if (this._permissions.headTouch) {
|
|
this.engine.addSystem(new HeadTouchSystem_1.default(), SystemPriorities_1.SystemPriorities.update);
|
|
}
|
|
if (this._permissions.setConfig) {
|
|
this.engine.addSystem(new SetConfigSystem_1.default(), SystemPriorities_1.SystemPriorities.load);
|
|
}
|
|
if (this._permissions.getConfig) {
|
|
this.engine.addSystem(new GetConfigSystem_1.default(), SystemPriorities_1.SystemPriorities.update);
|
|
}
|
|
if (this._permissions.listen) {
|
|
this.engine.addSystem(new ListenSystem_1.default(), SystemPriorities_1.SystemPriorities.update);
|
|
useLightRing = true;
|
|
}
|
|
if (this._permissions.screenGesture) {
|
|
this.engine.addSystem(new ScreenTouchSystem_1.default(), SystemPriorities_1.SystemPriorities.update);
|
|
}
|
|
this.engine.addSystem(new HotWordSystem_1.default(this._permissions.hotWord), SystemPriorities_1.SystemPriorities.update);
|
|
if (this._permissions.hotWord) {
|
|
useLightRing = true;
|
|
}
|
|
this.engine.addSystem(new AttentionSystem_1.default(), SystemPriorities_1.SystemPriorities.lps);
|
|
if (!this._permissions.attention) {
|
|
let attention = new components_1.Attention();
|
|
attention.mode = jibo_command_protocol_1.AttentionMode.Off;
|
|
sessionEntity.add(attention);
|
|
}
|
|
if (this._permissions.fetchAsset) {
|
|
this.engine.addSystem(new AssetsSystem_1.default(), SystemPriorities_1.SystemPriorities.load);
|
|
let assetCache = new core_1.Entity('assetCache');
|
|
assetCache.add(new components_1.AssetCache());
|
|
this.engine.addEntity(assetCache);
|
|
}
|
|
if (this._permissions.hideRemoteIndicator) {
|
|
}
|
|
else {
|
|
this.engine.addSystem(new RemoteIndicatorSystem_1.default(), SystemPriorities_1.SystemPriorities.update);
|
|
sessionEntity.add(new components_1.RemoteIndicator());
|
|
sessionEntity.add(new components_1.LightRing());
|
|
useLightRing = true;
|
|
}
|
|
if (useLightRing) {
|
|
this.engine.addSystem(new LightRingSystem_1.default(), SystemPriorities_1.SystemPriorities.light);
|
|
}
|
|
}
|
|
addCommand(data) {
|
|
let entity = this._commandCreator.commandFromRequestProtocol(data);
|
|
this.engine.addEntity(entity);
|
|
return entity;
|
|
}
|
|
start() {
|
|
this._active = true;
|
|
if (!this._tickProvider) {
|
|
this._tickProvider = new RAFTickProvider_1.default();
|
|
this._tickProvider.add(delta => this.engine.update(delta));
|
|
}
|
|
this._tickProvider.start();
|
|
this.engine.update(0);
|
|
}
|
|
stop() {
|
|
this._active = false;
|
|
this._tickProvider.stop();
|
|
}
|
|
reset() {
|
|
this.stop();
|
|
this._tickProvider.removeAll();
|
|
this.engine.updateComplete.removeAll();
|
|
this.engine.removeAllEntities();
|
|
this.engine.removeAllSystems();
|
|
}
|
|
dispose() {
|
|
this.reset();
|
|
this.engine = null;
|
|
this._tickProvider = null;
|
|
}
|
|
}
|
|
exports.EntityManager = EntityManager;
|
|
|
|
},{"./CommandCreator":7,"./components":34,"./core":45,"./core/tick/RAFTickProvider":52,"./systems/AssetsSystem":75,"./systems/AttentionSystem":76,"./systems/CommandSystem":77,"./systems/DisplaySystem":78,"./systems/GetConfigSystem":79,"./systems/HeadTouchSystem":80,"./systems/HotWordSystem":81,"./systems/InterruptSystem":82,"./systems/LightRingSystem":83,"./systems/ListenSystem":84,"./systems/LookAtSystem":85,"./systems/MotionStreamSystem":86,"./systems/PersonStreamSystem":87,"./systems/PhotoStreamSystem":88,"./systems/PlaySystem":89,"./systems/RemoteIndicatorSystem":90,"./systems/ScreenTouchSystem":91,"./systems/SessionSystem":92,"./systems/SetConfigSystem":93,"./systems/SystemPriorities":94,"./systems/TakePhotoSystem":95,"./systems/TestSystem":96,"jibo-command-protocol":undefined}],10:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class AssetCache {
|
|
constructor() {
|
|
this.assetTokens = new Map();
|
|
}
|
|
}
|
|
exports.AssetCache = AssetCache;
|
|
|
|
},{}],11:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class Attention {
|
|
constructor(mode) {
|
|
this.active = false;
|
|
if (mode) {
|
|
this.mode = mode;
|
|
}
|
|
}
|
|
}
|
|
exports.Attention = Attention;
|
|
|
|
},{}],12:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class Display {
|
|
constructor(view) {
|
|
if (view) {
|
|
this.view = view;
|
|
}
|
|
}
|
|
}
|
|
exports.Display = Display;
|
|
|
|
},{}],13:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class DisplayChange {
|
|
constructor() {
|
|
this.type = 'Swap';
|
|
this.isActive = false;
|
|
}
|
|
}
|
|
exports.DisplayChange = DisplayChange;
|
|
|
|
},{}],14:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class FetchAsset {
|
|
constructor(name, uri) {
|
|
if (name) {
|
|
this.name = name;
|
|
}
|
|
if (uri) {
|
|
this.uri = uri;
|
|
}
|
|
}
|
|
}
|
|
exports.FetchAsset = FetchAsset;
|
|
|
|
},{}],15:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class GetConfig {
|
|
}
|
|
exports.GetConfig = GetConfig;
|
|
|
|
},{}],16:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class HeadTouch {
|
|
constructor() {
|
|
this.isActive = false;
|
|
}
|
|
}
|
|
exports.HeadTouch = HeadTouch;
|
|
|
|
},{}],17:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class HotWord {
|
|
constructor() {
|
|
this.hjHeard = false;
|
|
this.coolDown = 0;
|
|
this.coolDownMax = .4;
|
|
}
|
|
}
|
|
exports.HotWord = HotWord;
|
|
|
|
},{}],18:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class Interrupt {
|
|
constructor(id) {
|
|
this.interruptId = '';
|
|
this.interruptAll = false;
|
|
if (id) {
|
|
this.interruptId = id;
|
|
}
|
|
}
|
|
}
|
|
exports.Interrupt = Interrupt;
|
|
|
|
},{}],19:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class LightRing {
|
|
constructor() {
|
|
this.isActive = false;
|
|
this.isDirty = false;
|
|
this._color = [0, 0, 0];
|
|
}
|
|
get color() {
|
|
return this._color;
|
|
}
|
|
setColor(color) {
|
|
this.isDirty = true;
|
|
this._color[0] = this._color[0];
|
|
this._color[1] = this._color[1];
|
|
this._color[2] = this._color[2];
|
|
}
|
|
setColors(r, g, b) {
|
|
this.isDirty = true;
|
|
this._color[0] = r;
|
|
this._color[1] = g;
|
|
this._color[2] = b;
|
|
}
|
|
}
|
|
exports.LightRing = LightRing;
|
|
|
|
},{}],20:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class Listen {
|
|
constructor(language = "en-US", maxNoSpeechTimeout = 15000, maxSpeechTimeout = 15000) {
|
|
this.isActive = false;
|
|
this.language = language;
|
|
this.maxSpeechTimeout = maxSpeechTimeout;
|
|
this.maxNoSpeechTimeout = maxNoSpeechTimeout;
|
|
}
|
|
onMimEnd(results) {
|
|
if (results.asrResults) {
|
|
this.speech = results.asrResults;
|
|
}
|
|
else {
|
|
this.speech = null;
|
|
}
|
|
}
|
|
}
|
|
exports.Listen = Listen;
|
|
|
|
},{}],21:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class LookAt {
|
|
constructor(trackFlag = false, levelHeadFlag = false) {
|
|
this.isActive = false;
|
|
this.interrupted = false;
|
|
this.trackFlag = false;
|
|
this.levelHeadFlag = false;
|
|
this.trackFlag = trackFlag;
|
|
this.levelHeadFlag = levelHeadFlag;
|
|
}
|
|
}
|
|
exports.LookAt = LookAt;
|
|
|
|
},{}],22:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class MotionStream {
|
|
constructor() {
|
|
this.isActive = false;
|
|
}
|
|
}
|
|
exports.MotionStream = MotionStream;
|
|
|
|
},{}],23:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class PersonStream {
|
|
constructor() {
|
|
this.isActive = false;
|
|
}
|
|
}
|
|
exports.PersonStream = PersonStream;
|
|
|
|
},{}],24:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class PhotoStream {
|
|
constructor(photoType) {
|
|
this.isActive = false;
|
|
this.assetUrl = null;
|
|
this.photoType = 'NORMAL';
|
|
if (photoType) {
|
|
this.photoType = photoType;
|
|
}
|
|
}
|
|
}
|
|
exports.PhotoStream = PhotoStream;
|
|
|
|
},{}],25:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class Play {
|
|
constructor(textInESML) {
|
|
this.textInESML = null;
|
|
this.activated = false;
|
|
this.completed = false;
|
|
this.audioId = null;
|
|
if (textInESML) {
|
|
this.textInESML = textInESML;
|
|
}
|
|
}
|
|
}
|
|
exports.Play = Play;
|
|
|
|
},{}],26:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class RemoteIndicator {
|
|
constructor() {
|
|
this.dotColor = '0xFF00FF';
|
|
this.dotRadius = 15;
|
|
this.horizontalOffset = 45;
|
|
this.verticalOffset = 45;
|
|
this.minAlpha = 0.3;
|
|
this.maxAlpha = 1;
|
|
this.duration = 2;
|
|
this.minHexColor = '0x330033';
|
|
this.maxHexColor = '0xFF00FF';
|
|
this.minLEDColor = [0, 0, 0];
|
|
this.maxLEDColor = [0, 0, 0];
|
|
this.deltaInColor = [0, 0, 0];
|
|
this.deltaAlpha = 0;
|
|
this.lerpIsRising = true;
|
|
this.timer = 0;
|
|
this.icon = null;
|
|
}
|
|
}
|
|
exports.RemoteIndicator = RemoteIndicator;
|
|
|
|
},{}],27:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class RequestCommand {
|
|
constructor(data) {
|
|
this.acknowledged = false;
|
|
this._acknowledgeCode = jibo_command_protocol_1.ResponseCode.Accepted;
|
|
this._isDirty = true;
|
|
this._complete = false;
|
|
this._responses = [];
|
|
if (data) {
|
|
this.applyData(data);
|
|
}
|
|
}
|
|
get acknowledgeCode() {
|
|
return this._acknowledgeCode;
|
|
}
|
|
get acknowledgeData() {
|
|
return this._acknowledgeData;
|
|
}
|
|
get complete() {
|
|
return this._complete;
|
|
}
|
|
get isDirty() {
|
|
return this._isDirty;
|
|
}
|
|
get responses() {
|
|
return this._responses;
|
|
}
|
|
applyData(data) {
|
|
this.id = data.ClientHeader.TransactionID;
|
|
}
|
|
setAcknowledge(code, isComplete = false, data) {
|
|
this._acknowledgeCode = code;
|
|
this._isDirty = true;
|
|
if (isComplete) {
|
|
this._complete = true;
|
|
}
|
|
if (data) {
|
|
this._acknowledgeData = data;
|
|
}
|
|
}
|
|
addResponse(data, isComplete = false) {
|
|
this._responses.push(data);
|
|
this._isDirty = true;
|
|
if (isComplete) {
|
|
this._complete = true;
|
|
}
|
|
}
|
|
setComplete() {
|
|
this._isDirty = true;
|
|
this._complete = true;
|
|
}
|
|
clean() {
|
|
this._isDirty = false;
|
|
this._responses.length = 0;
|
|
}
|
|
}
|
|
exports.RequestCommand = RequestCommand;
|
|
|
|
},{"jibo-command-protocol":undefined}],28:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class ScreenGesture {
|
|
}
|
|
exports.ScreenGesture = ScreenGesture;
|
|
|
|
},{}],29:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class Session {
|
|
constructor(id, sendMethod, reconnectTimeout = 1000, inactivityTimeout = 0) {
|
|
this.waitingOnReconnect = false;
|
|
this.reconnection = false;
|
|
this.reconnectDuration = 0;
|
|
this.inactivityDuration = 0;
|
|
this._hasConnection = true;
|
|
this.storedEvents = [];
|
|
if (id) {
|
|
this.id = id;
|
|
}
|
|
if (sendMethod) {
|
|
this.sendMethod = sendMethod;
|
|
}
|
|
if (reconnectTimeout) {
|
|
this.reconnectTimeout = reconnectTimeout;
|
|
}
|
|
if (inactivityTimeout) {
|
|
this.inactivityTimeout = inactivityTimeout;
|
|
}
|
|
}
|
|
get hasConnection() {
|
|
return this._hasConnection;
|
|
}
|
|
set hasConnection(connected) {
|
|
this._hasConnection = connected;
|
|
if (connected) {
|
|
if (this.waitingOnReconnect) {
|
|
this.reconnection = true;
|
|
}
|
|
this.waitingOnReconnect = false;
|
|
this.reconnectDuration = 0;
|
|
}
|
|
else {
|
|
if (!this.waitingOnReconnect) {
|
|
this.waitingOnReconnect = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
exports.Session = Session;
|
|
|
|
},{}],30:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class SetConfig {
|
|
constructor(options) {
|
|
this.isActive = false;
|
|
if (options) {
|
|
this.options = options;
|
|
}
|
|
}
|
|
}
|
|
exports.SetConfig = SetConfig;
|
|
|
|
},{}],31:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class TakePhoto {
|
|
constructor(distortion, camera, resolution) {
|
|
this.isActive = false;
|
|
this.assetUrl = null;
|
|
this.distortion = false;
|
|
this.assetUrl = null;
|
|
this.distortion = distortion;
|
|
this.camera = camera;
|
|
this.resolution = resolution;
|
|
}
|
|
}
|
|
exports.TakePhoto = TakePhoto;
|
|
|
|
},{}],32:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class Target {
|
|
constructor(target) {
|
|
if (target) {
|
|
this.lookAtTarget = target;
|
|
}
|
|
}
|
|
}
|
|
exports.Target = Target;
|
|
|
|
},{}],33:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class Test {
|
|
constructor(data) {
|
|
this.message = data.Message;
|
|
}
|
|
}
|
|
exports.Test = Test;
|
|
|
|
},{}],34:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var Attention_1 = require("./Attention");
|
|
exports.Attention = Attention_1.Attention;
|
|
var Display_1 = require("./Display");
|
|
exports.Display = Display_1.Display;
|
|
var DisplayChange_1 = require("./DisplayChange");
|
|
exports.DisplayChange = DisplayChange_1.DisplayChange;
|
|
var HeadTouch_1 = require("./HeadTouch");
|
|
exports.HeadTouch = HeadTouch_1.HeadTouch;
|
|
var HotWord_1 = require("./HotWord");
|
|
exports.HotWord = HotWord_1.HotWord;
|
|
var Interrupt_1 = require("./Interrupt");
|
|
exports.Interrupt = Interrupt_1.Interrupt;
|
|
var LightRing_1 = require("./LightRing");
|
|
exports.LightRing = LightRing_1.LightRing;
|
|
var Listen_1 = require("./Listen");
|
|
exports.Listen = Listen_1.Listen;
|
|
var LookAt_1 = require("./LookAt");
|
|
exports.LookAt = LookAt_1.LookAt;
|
|
var MotionStream_1 = require("./MotionStream");
|
|
exports.MotionStream = MotionStream_1.MotionStream;
|
|
var PersonStream_1 = require("./PersonStream");
|
|
exports.PersonStream = PersonStream_1.PersonStream;
|
|
var Play_1 = require("./Play");
|
|
exports.Play = Play_1.Play;
|
|
var TakePhoto_1 = require("./TakePhoto");
|
|
exports.TakePhoto = TakePhoto_1.TakePhoto;
|
|
var Target_1 = require("./Target");
|
|
exports.Target = Target_1.Target;
|
|
var PhotoStream_1 = require("./PhotoStream");
|
|
exports.PhotoStream = PhotoStream_1.PhotoStream;
|
|
var RequestCommand_1 = require("./RequestCommand");
|
|
exports.RequestCommand = RequestCommand_1.RequestCommand;
|
|
var RemoteIndicator_1 = require("./RemoteIndicator");
|
|
exports.RemoteIndicator = RemoteIndicator_1.RemoteIndicator;
|
|
var SetConfig_1 = require("./SetConfig");
|
|
exports.SetConfig = SetConfig_1.SetConfig;
|
|
var GetConfig_1 = require("./GetConfig");
|
|
exports.GetConfig = GetConfig_1.GetConfig;
|
|
var FetchAsset_1 = require("./FetchAsset");
|
|
exports.FetchAsset = FetchAsset_1.FetchAsset;
|
|
var AssetCache_1 = require("./AssetCache");
|
|
exports.AssetCache = AssetCache_1.AssetCache;
|
|
var ScreenGesture_1 = require("./ScreenGesture");
|
|
exports.ScreenGesture = ScreenGesture_1.ScreenGesture;
|
|
var Session_1 = require("./Session");
|
|
exports.Session = Session_1.Session;
|
|
var Test_1 = require("./Test");
|
|
exports.Test = Test_1.Test;
|
|
|
|
},{"./AssetCache":10,"./Attention":11,"./Display":12,"./DisplayChange":13,"./FetchAsset":14,"./GetConfig":15,"./HeadTouch":16,"./HotWord":17,"./Interrupt":18,"./LightRing":19,"./Listen":20,"./LookAt":21,"./MotionStream":22,"./PersonStream":23,"./PhotoStream":24,"./Play":25,"./RemoteIndicator":26,"./RequestCommand":27,"./ScreenGesture":28,"./Session":29,"./SetConfig":30,"./TakePhoto":31,"./Target":32,"./Test":33}],35:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Dictionary_1 = require("./Dictionary");
|
|
const NodeList_1 = require("./NodeList");
|
|
const NodePool_1 = require("./NodePool");
|
|
class ComponentMatchingFamily {
|
|
constructor(nodeClass, engine) {
|
|
this.releaseNodePoolCache = () => {
|
|
this.engine.updateComplete.remove(this.releaseNodePoolCache);
|
|
this.nodePool.releaseCache();
|
|
};
|
|
this.nodeClass = nodeClass;
|
|
this.engine = engine;
|
|
this.init();
|
|
}
|
|
get nodeList() {
|
|
return this.nodes;
|
|
}
|
|
newEntity(entity) {
|
|
this.addIfMatch(entity);
|
|
}
|
|
componentAddedToEntity(entity, componentClass) {
|
|
this.addIfMatch(entity);
|
|
}
|
|
componentRemovedFromEntity(entity, componentClass) {
|
|
if (this.components.has(componentClass)) {
|
|
this.removeIfMatch(entity);
|
|
}
|
|
}
|
|
removeEntity(entity) {
|
|
this.removeIfMatch(entity);
|
|
}
|
|
cleanUp() {
|
|
for (let node = this.nodes.head; node; node = node.next) {
|
|
this.entities.remove(node.entity);
|
|
}
|
|
this.nodes.removeAll();
|
|
}
|
|
init() {
|
|
this.nodes = new NodeList_1.NodeList();
|
|
this.entities = new Dictionary_1.default();
|
|
this.components = new Dictionary_1.default();
|
|
this.nodePool = new NodePool_1.NodePool(this.nodeClass, this.components);
|
|
let dummyNode = this.nodePool.get();
|
|
this.nodePool.dispose(dummyNode);
|
|
let types = dummyNode.constructor['__ash_types__'];
|
|
for (let type in types) {
|
|
if (types.hasOwnProperty(type)) {
|
|
this.components.set(types[type], type);
|
|
}
|
|
}
|
|
}
|
|
addIfMatch(entity) {
|
|
if (!this.entities.has(entity)) {
|
|
for (let componentClass of this.components.keys()) {
|
|
if (!entity.has(componentClass)) {
|
|
return;
|
|
}
|
|
}
|
|
let node = this.nodePool.get();
|
|
node.entity = entity;
|
|
for (let componentClass of this.components.keys()) {
|
|
node[this.components.get(componentClass)] = entity.get(componentClass);
|
|
}
|
|
this.entities.set(entity, node);
|
|
this.nodes.add(node);
|
|
}
|
|
}
|
|
removeIfMatch(entity) {
|
|
if (this.entities.has(entity)) {
|
|
let node = this.entities.get(entity);
|
|
this.entities.remove(entity);
|
|
this.nodes.remove(node);
|
|
if (this.engine.updating) {
|
|
this.nodePool.cache(node);
|
|
this.engine.updateComplete.add(this.releaseNodePoolCache);
|
|
}
|
|
else {
|
|
this.nodePool.dispose(node);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
exports.default = ComponentMatchingFamily;
|
|
|
|
},{"./Dictionary":36,"./NodeList":41,"./NodePool":42}],36:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class Dictionary {
|
|
constructor() {
|
|
this._keys = [];
|
|
this._values = [];
|
|
}
|
|
set(key, value) {
|
|
let index = this._keys.indexOf(key);
|
|
if (index < 0) {
|
|
let len = this._keys.length;
|
|
this._keys[len] = key;
|
|
this._values[len] = value;
|
|
}
|
|
else {
|
|
this._values[index] = value;
|
|
}
|
|
return value;
|
|
}
|
|
get(key) {
|
|
let index = this._keys.indexOf(key);
|
|
if (index < 0) {
|
|
return null;
|
|
}
|
|
else {
|
|
return this._values[index];
|
|
}
|
|
}
|
|
has(key) {
|
|
return !(this._keys.indexOf(key) < 0);
|
|
}
|
|
remove(key) {
|
|
let index = this._keys.indexOf(key);
|
|
if (index < 0) {
|
|
return null;
|
|
}
|
|
else {
|
|
this._keys.splice(index, 1);
|
|
return this._values.splice(index, 1)[0];
|
|
}
|
|
}
|
|
keys() {
|
|
return this._keys;
|
|
}
|
|
values() {
|
|
return this._values;
|
|
}
|
|
}
|
|
exports.default = Dictionary;
|
|
|
|
},{}],37:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Signal0_1 = require("./signals/Signal0");
|
|
const Dictionary_1 = require("./Dictionary");
|
|
const EntityList_1 = require("./EntityList");
|
|
const SystemList_1 = require("./SystemList");
|
|
const ComponentMatchingFamily_1 = require("./ComponentMatchingFamily");
|
|
class Engine {
|
|
constructor() {
|
|
this.familyClass = ComponentMatchingFamily_1.default;
|
|
this.entityNameChanged = (entity, oldName) => {
|
|
if (this._entityNames[oldName] === entity) {
|
|
this._entityNames[oldName] = null;
|
|
this._entityNames[entity.name] = entity;
|
|
}
|
|
};
|
|
this.componentAdded = (entity, componentClass) => {
|
|
for (let family of this._families.values()) {
|
|
family.componentAddedToEntity(entity, componentClass);
|
|
}
|
|
};
|
|
this.componentRemoved = (entity, componentClass) => {
|
|
for (let family of this._families.values()) {
|
|
family.componentRemovedFromEntity(entity, componentClass);
|
|
}
|
|
};
|
|
this._entityList = new EntityList_1.default();
|
|
this._entityNames = [];
|
|
this._systemList = new SystemList_1.default();
|
|
this._families = new Dictionary_1.default();
|
|
this.updateComplete = new Signal0_1.Signal0();
|
|
}
|
|
addEntity(entity) {
|
|
if (this._entityNames[entity.name]) {
|
|
throw new Error('The entity name ' + entity.name + ' is already in use by another entity.');
|
|
}
|
|
this._entityList.add(entity);
|
|
this._entityNames[entity.name] = entity;
|
|
entity.componentAdded.add(this.componentAdded);
|
|
entity.componentRemoved.add(this.componentRemoved);
|
|
entity.nameChanged.add(this.entityNameChanged);
|
|
for (let family of this._families.values()) {
|
|
family.newEntity(entity);
|
|
}
|
|
}
|
|
removeEntity(entity) {
|
|
entity.componentAdded.remove(this.componentAdded);
|
|
entity.componentRemoved.remove(this.componentRemoved);
|
|
entity.nameChanged.remove(this.entityNameChanged);
|
|
for (let family of this._families.values()) {
|
|
family.removeEntity(entity);
|
|
}
|
|
this._entityNames[entity.name] = null;
|
|
this._entityList.remove(entity);
|
|
}
|
|
getEntityByName(name) {
|
|
return this._entityNames[name];
|
|
}
|
|
removeAllEntities() {
|
|
while (this._entityList.head) {
|
|
this.removeEntity(this._entityList.head);
|
|
}
|
|
}
|
|
get entities() {
|
|
let entities = [];
|
|
for (let entity = this._entityList.head; entity; entity = entity.next) {
|
|
entities[entities.length] = entity;
|
|
}
|
|
return entities;
|
|
}
|
|
getNodeList(nodeClass) {
|
|
if (this._families.has(nodeClass)) {
|
|
return this._families.get(nodeClass).nodeList;
|
|
}
|
|
let family = new this.familyClass(nodeClass, this);
|
|
this._families.set(nodeClass, family);
|
|
for (let entity = this._entityList.head; entity; entity = entity.next) {
|
|
family.newEntity(entity);
|
|
}
|
|
return family.nodeList;
|
|
}
|
|
releaseNodeList(nodeClass) {
|
|
if (this._families.has(nodeClass)) {
|
|
this._families.get(nodeClass).cleanUp();
|
|
}
|
|
this._families.remove(nodeClass);
|
|
}
|
|
addSystem(system, priority) {
|
|
system.priority = priority;
|
|
system.addToEngine(this);
|
|
this._systemList.add(system);
|
|
}
|
|
getSystem(type) {
|
|
return this._systemList.get(type);
|
|
}
|
|
get systems() {
|
|
let systems = [];
|
|
for (let system = this._systemList.head; system; system = system.next) {
|
|
systems[systems.length] = system;
|
|
}
|
|
return systems;
|
|
}
|
|
removeSystem(system) {
|
|
this._systemList.remove(system);
|
|
system.removeFromEngine(this);
|
|
}
|
|
removeAllSystems() {
|
|
while (this._systemList.head) {
|
|
let system = this._systemList.head;
|
|
this._systemList.head = this._systemList.head.next;
|
|
system.previous = null;
|
|
system.next = null;
|
|
system.removeFromEngine(this);
|
|
}
|
|
this._systemList.tail = null;
|
|
}
|
|
requestUpdate() {
|
|
}
|
|
update(time) {
|
|
this.updating = true;
|
|
for (let system = this._systemList.head; system; system = system.next) {
|
|
system.update(time);
|
|
}
|
|
this.updating = false;
|
|
this.updateComplete.dispatch();
|
|
}
|
|
}
|
|
exports.Engine = Engine;
|
|
|
|
},{"./ComponentMatchingFamily":35,"./Dictionary":36,"./EntityList":39,"./SystemList":44,"./signals/Signal0":48}],38:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Signal2_1 = require("./signals/Signal2");
|
|
const Dictionary_1 = require("./Dictionary");
|
|
class Entity {
|
|
constructor(name = '') {
|
|
this.componentAdded = new Signal2_1.Signal2();
|
|
this.componentRemoved = new Signal2_1.Signal2();
|
|
this.nameChanged = new Signal2_1.Signal2();
|
|
this.components = new Dictionary_1.default();
|
|
if (name) {
|
|
this._name = name;
|
|
}
|
|
else {
|
|
this._name = '_entity' + (++Entity.nameCount);
|
|
}
|
|
}
|
|
get name() {
|
|
return this._name;
|
|
}
|
|
set name(value) {
|
|
if (this._name !== value) {
|
|
let previous = this._name;
|
|
this._name = value;
|
|
this.nameChanged.dispatch(this, previous);
|
|
}
|
|
}
|
|
add(component, componentClass = null) {
|
|
if (!componentClass) {
|
|
componentClass = component.constructor.prototype.constructor;
|
|
}
|
|
if (this.components.has(componentClass)) {
|
|
this.remove(componentClass);
|
|
}
|
|
this.components.set(componentClass, component);
|
|
this.componentAdded.dispatch(this, componentClass);
|
|
return this;
|
|
}
|
|
remove(componentClass) {
|
|
let component = this.components.get(componentClass);
|
|
if (component) {
|
|
this.components.remove(componentClass);
|
|
this.componentRemoved.dispatch(this, componentClass);
|
|
return component;
|
|
}
|
|
return null;
|
|
}
|
|
get(componentClass) {
|
|
return this.components.get(componentClass);
|
|
}
|
|
getAll() {
|
|
let componentArray = [];
|
|
for (let value of this.components.values()) {
|
|
componentArray[componentArray.length] = value;
|
|
}
|
|
return componentArray;
|
|
}
|
|
has(componentClass) {
|
|
return this.components.has(componentClass);
|
|
}
|
|
}
|
|
Entity.nameCount = 0;
|
|
exports.Entity = Entity;
|
|
|
|
},{"./Dictionary":36,"./signals/Signal2":50}],39:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class EntityList {
|
|
add(entity) {
|
|
if (!this.head) {
|
|
this.head = this.tail = entity;
|
|
entity.next = entity.previous = null;
|
|
}
|
|
else {
|
|
this.tail.next = entity;
|
|
entity.previous = this.tail;
|
|
entity.next = null;
|
|
this.tail = entity;
|
|
}
|
|
}
|
|
remove(entity) {
|
|
if (this.head === entity) {
|
|
this.head = this.head.next;
|
|
}
|
|
if (this.tail === entity) {
|
|
this.tail = this.tail.previous;
|
|
}
|
|
if (entity.previous) {
|
|
entity.previous.next = entity.next;
|
|
}
|
|
if (entity.next) {
|
|
entity.next.previous = entity.previous;
|
|
}
|
|
}
|
|
removeAll() {
|
|
while (this.head) {
|
|
let entity = this.head;
|
|
this.head = this.head.next;
|
|
entity.previous = null;
|
|
entity.next = null;
|
|
}
|
|
this.tail = null;
|
|
}
|
|
}
|
|
exports.default = EntityList;
|
|
|
|
},{}],40:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class Node {
|
|
constructor() {
|
|
this.entity = null;
|
|
this.previous = null;
|
|
this.next = null;
|
|
}
|
|
}
|
|
exports.Node = Node;
|
|
function keep(type) {
|
|
return (target, propertyKey, descriptor) => {
|
|
let ctor = target.constructor;
|
|
let map;
|
|
let ashProp = '__ash_types__';
|
|
if (ctor.hasOwnProperty(ashProp)) {
|
|
map = ctor[ashProp];
|
|
}
|
|
else {
|
|
map = {};
|
|
Object.defineProperty(ctor, ashProp, {
|
|
enumerable: true,
|
|
value: map
|
|
});
|
|
}
|
|
map[propertyKey] = type;
|
|
return descriptor;
|
|
};
|
|
}
|
|
exports.keep = keep;
|
|
|
|
},{}],41:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Signal1_1 = require("./signals/Signal1");
|
|
class NodeList {
|
|
constructor() {
|
|
this.nodeAdded = new Signal1_1.Signal1();
|
|
this.nodeRemoved = new Signal1_1.Signal1();
|
|
}
|
|
add(node) {
|
|
if (!this.head) {
|
|
this.head = this.tail = node;
|
|
node.next = node.previous = null;
|
|
}
|
|
else {
|
|
this.tail.next = node;
|
|
node.previous = this.tail;
|
|
node.next = null;
|
|
this.tail = node;
|
|
}
|
|
this.nodeAdded.dispatch(node);
|
|
}
|
|
remove(node) {
|
|
if (this.head === node) {
|
|
this.head = this.head.next;
|
|
}
|
|
if (this.tail === node) {
|
|
this.tail = this.tail.previous;
|
|
}
|
|
if (node.previous) {
|
|
node.previous.next = node.next;
|
|
}
|
|
if (node.next) {
|
|
node.next.previous = node.previous;
|
|
}
|
|
this.nodeRemoved.dispatch(node);
|
|
}
|
|
removeAll() {
|
|
while (this.head) {
|
|
let node = this.head;
|
|
this.head = node.next;
|
|
node.previous = null;
|
|
node.next = null;
|
|
this.nodeRemoved.dispatch(node);
|
|
}
|
|
this.tail = null;
|
|
}
|
|
get empty() {
|
|
return this.head === null;
|
|
}
|
|
swap(node1, node2) {
|
|
if (node1.previous === node2) {
|
|
node1.previous = node2.previous;
|
|
node2.previous = node1;
|
|
node2.next = node1.next;
|
|
node1.next = node2;
|
|
}
|
|
else if (node2.previous === node1) {
|
|
node2.previous = node1.previous;
|
|
node1.previous = node2;
|
|
node1.next = node2.next;
|
|
node2.next = node1;
|
|
}
|
|
else {
|
|
let temp = node1.previous;
|
|
node1.previous = node2.previous;
|
|
node2.previous = temp;
|
|
temp = node1.next;
|
|
node1.next = node2.next;
|
|
node2.next = temp;
|
|
}
|
|
if (this.head === node1) {
|
|
this.head = node2;
|
|
}
|
|
else if (this.head === node2) {
|
|
this.head = node1;
|
|
}
|
|
if (this.tail === node1) {
|
|
this.tail = node2;
|
|
}
|
|
else if (this.tail === node2) {
|
|
this.tail = node1;
|
|
}
|
|
if (node1.previous) {
|
|
node1.previous.next = node1;
|
|
}
|
|
if (node2.previous) {
|
|
node2.previous.next = node2;
|
|
}
|
|
if (node1.next) {
|
|
node1.next.previous = node1;
|
|
}
|
|
if (node2.next) {
|
|
node2.next.previous = node2;
|
|
}
|
|
}
|
|
insertionSort(sortFunction) {
|
|
if (this.head === this.tail) {
|
|
return;
|
|
}
|
|
let remains = this.head.next;
|
|
for (let node = remains; node; node = remains) {
|
|
let other;
|
|
remains = node.next;
|
|
for (other = node.previous; other; other = other.previous) {
|
|
if (sortFunction(node, other) >= 0) {
|
|
if (node !== other.next) {
|
|
if (this.tail === node) {
|
|
this.tail = node.previous;
|
|
}
|
|
node.previous.next = node.next;
|
|
if (node.next) {
|
|
node.next.previous = node.previous;
|
|
}
|
|
node.next = other.next;
|
|
node.previous = other;
|
|
node.next.previous = node;
|
|
other.next = node;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (!other) {
|
|
if (this.tail === node) {
|
|
this.tail = node.previous;
|
|
}
|
|
node.previous.next = node.next;
|
|
if (node.next) {
|
|
node.next.previous = node.previous;
|
|
}
|
|
node.next = this.head;
|
|
this.head.previous = node;
|
|
node.previous = null;
|
|
this.head = node;
|
|
}
|
|
}
|
|
}
|
|
mergeSort(sortFunction) {
|
|
if (this.head === this.tail) {
|
|
return;
|
|
}
|
|
let lists = [];
|
|
let start = this.head;
|
|
let end;
|
|
while (start) {
|
|
end = start;
|
|
while (end.next && sortFunction(end, end.next) <= 0) {
|
|
end = end.next;
|
|
}
|
|
let next = end.next;
|
|
start.previous = end.next = null;
|
|
lists[lists.length] = start;
|
|
start = next;
|
|
}
|
|
while (lists.length > 1) {
|
|
lists.push(this.merge(lists.shift(), lists.shift(), sortFunction));
|
|
}
|
|
this.tail = this.head = lists[0];
|
|
while (this.tail.next) {
|
|
this.tail = this.tail.next;
|
|
}
|
|
}
|
|
merge(head1, head2, sortFunction) {
|
|
let node;
|
|
let head;
|
|
if (sortFunction(head1, head2) <= 0) {
|
|
head = node = head1;
|
|
head1 = head1.next;
|
|
}
|
|
else {
|
|
head = node = head2;
|
|
head2 = head2.next;
|
|
}
|
|
while (head1 && head2) {
|
|
if (sortFunction(head1, head2) <= 0) {
|
|
node.next = head1;
|
|
head1.previous = node;
|
|
node = head1;
|
|
head1 = head1.next;
|
|
}
|
|
else {
|
|
node.next = head2;
|
|
head2.previous = node;
|
|
node = head2;
|
|
head2 = head2.next;
|
|
}
|
|
}
|
|
if (head1) {
|
|
node.next = head1;
|
|
head1.previous = node;
|
|
}
|
|
else {
|
|
node.next = head2;
|
|
head2.previous = node;
|
|
}
|
|
return head;
|
|
}
|
|
}
|
|
exports.NodeList = NodeList;
|
|
|
|
},{"./signals/Signal1":49}],42:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class NodePool {
|
|
constructor(nodeClass, components) {
|
|
this.nodeClass = nodeClass;
|
|
this.components = components;
|
|
}
|
|
get() {
|
|
if (this.tail) {
|
|
let node = this.tail;
|
|
this.tail = this.tail.previous;
|
|
node.previous = null;
|
|
return node;
|
|
}
|
|
else {
|
|
return new this.nodeClass();
|
|
}
|
|
}
|
|
dispose(node) {
|
|
for (let val of this.components.values()) {
|
|
node[val] = null;
|
|
}
|
|
node.entity = null;
|
|
node.next = null;
|
|
node.previous = this.tail;
|
|
this.tail = node;
|
|
}
|
|
cache(node) {
|
|
node.previous = this.cacheTail;
|
|
this.cacheTail = node;
|
|
}
|
|
releaseCache() {
|
|
while (this.cacheTail) {
|
|
let node = this.cacheTail;
|
|
this.cacheTail = node.previous;
|
|
this.dispose(node);
|
|
}
|
|
}
|
|
}
|
|
exports.NodePool = NodePool;
|
|
|
|
},{}],43:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class System {
|
|
constructor() {
|
|
this.priority = 0;
|
|
}
|
|
}
|
|
exports.System = System;
|
|
|
|
},{}],44:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class SystemList {
|
|
add(system) {
|
|
if (!this.head) {
|
|
this.head = this.tail = system;
|
|
system.next = system.previous = null;
|
|
}
|
|
else {
|
|
let node;
|
|
for (node = this.tail; node; node = node.previous) {
|
|
if (node.priority <= system.priority) {
|
|
break;
|
|
}
|
|
}
|
|
if (node === this.tail) {
|
|
this.tail.next = system;
|
|
system.previous = this.tail;
|
|
system.next = null;
|
|
this.tail = system;
|
|
}
|
|
else if (!node) {
|
|
system.next = this.head;
|
|
system.previous = null;
|
|
this.head.previous = system;
|
|
this.head = system;
|
|
}
|
|
else {
|
|
system.next = node.next;
|
|
system.previous = node;
|
|
node.next.previous = system;
|
|
node.next = system;
|
|
}
|
|
}
|
|
}
|
|
remove(system) {
|
|
if (this.head === system) {
|
|
this.head = this.head.next;
|
|
}
|
|
if (this.tail === system) {
|
|
this.tail = this.tail.previous;
|
|
}
|
|
if (system.previous) {
|
|
system.previous.next = system.next;
|
|
}
|
|
if (system.next) {
|
|
system.next.previous = system.previous;
|
|
}
|
|
}
|
|
removeAll() {
|
|
while (this.head) {
|
|
let system = this.head;
|
|
this.head = this.head.next;
|
|
system.previous = null;
|
|
system.next = null;
|
|
}
|
|
this.tail = null;
|
|
}
|
|
get(type) {
|
|
for (let system = this.head; system; system = system.next) {
|
|
if (system instanceof type) {
|
|
return system;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
exports.default = SystemList;
|
|
|
|
},{}],45:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var Engine_1 = require("./Engine");
|
|
exports.Engine = Engine_1.Engine;
|
|
var NodeList_1 = require("./NodeList");
|
|
exports.NodeList = NodeList_1.NodeList;
|
|
var Node_1 = require("./Node");
|
|
exports.Node = Node_1.Node;
|
|
var System_1 = require("./System");
|
|
exports.System = System_1.System;
|
|
var Entity_1 = require("./Entity");
|
|
exports.Entity = Entity_1.Entity;
|
|
var Node_2 = require("./Node");
|
|
exports.keep = Node_2.keep;
|
|
|
|
},{"./Engine":37,"./Entity":38,"./Node":40,"./NodeList":41,"./System":43}],46:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
class ListenerNode {
|
|
}
|
|
exports.ListenerNode = ListenerNode;
|
|
|
|
},{}],47:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const ListenerNode_1 = require("./ListenerNode");
|
|
class ListenerNodePool {
|
|
get() {
|
|
if (this.tail) {
|
|
let node = this.tail;
|
|
this.tail = this.tail.previous;
|
|
node.previous = null;
|
|
return node;
|
|
}
|
|
else {
|
|
return new ListenerNode_1.ListenerNode();
|
|
}
|
|
}
|
|
dispose(node) {
|
|
node.listener = null;
|
|
node.once = false;
|
|
node.next = null;
|
|
node.previous = this.tail;
|
|
this.tail = node;
|
|
}
|
|
cache(node) {
|
|
node.listener = null;
|
|
node.previous = this.cacheTail;
|
|
this.cacheTail = node;
|
|
}
|
|
releaseCache() {
|
|
while (this.cacheTail) {
|
|
let node = this.cacheTail;
|
|
this.cacheTail = node.previous;
|
|
node.next = null;
|
|
node.previous = this.tail;
|
|
this.tail = node;
|
|
}
|
|
}
|
|
}
|
|
exports.ListenerNodePool = ListenerNodePool;
|
|
|
|
},{"./ListenerNode":46}],48:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const SignalBase_1 = require("./SignalBase");
|
|
class Signal0 extends SignalBase_1.SignalBase {
|
|
dispatch() {
|
|
this.startDispatch();
|
|
let node;
|
|
for (node = this.head; node; node = node.next) {
|
|
node.listener.call(node);
|
|
if (node.once) {
|
|
this.remove(node.listener);
|
|
}
|
|
}
|
|
this.endDispatch();
|
|
}
|
|
}
|
|
exports.Signal0 = Signal0;
|
|
|
|
},{"./SignalBase":51}],49:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const SignalBase_1 = require("./SignalBase");
|
|
class Signal1 extends SignalBase_1.SignalBase {
|
|
dispatch(object) {
|
|
this.startDispatch();
|
|
let node;
|
|
for (node = this.head; node; node = node.next) {
|
|
node.listener.call(node, object);
|
|
if (node.once) {
|
|
this.remove(node.listener);
|
|
}
|
|
}
|
|
this.endDispatch();
|
|
}
|
|
}
|
|
exports.Signal1 = Signal1;
|
|
|
|
},{"./SignalBase":51}],50:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const SignalBase_1 = require("./SignalBase");
|
|
class Signal2 extends SignalBase_1.SignalBase {
|
|
dispatch(object1, object2) {
|
|
this.startDispatch();
|
|
let node;
|
|
for (node = this.head; node; node = node.next) {
|
|
node.listener.call(node, object1, object2);
|
|
if (node.once) {
|
|
this.remove(node.listener);
|
|
}
|
|
}
|
|
this.endDispatch();
|
|
}
|
|
}
|
|
exports.Signal2 = Signal2;
|
|
|
|
},{"./SignalBase":51}],51:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Dictionary_1 = require("../Dictionary");
|
|
const ListenerNodePool_1 = require("./ListenerNodePool");
|
|
class SignalBase {
|
|
constructor() {
|
|
this._numListeners = 0;
|
|
this.nodes = new Dictionary_1.default();
|
|
this.listenerNodePool = new ListenerNodePool_1.ListenerNodePool();
|
|
}
|
|
startDispatch() {
|
|
this.dispatching = true;
|
|
}
|
|
endDispatch() {
|
|
this.dispatching = false;
|
|
if (this.toAddHead) {
|
|
if (!this.head) {
|
|
this.head = this.toAddHead;
|
|
this.tail = this.toAddTail;
|
|
}
|
|
else {
|
|
this.tail.next = this.toAddHead;
|
|
this.toAddHead.previous = this.tail;
|
|
this.tail = this.toAddTail;
|
|
}
|
|
this.toAddHead = null;
|
|
this.toAddTail = null;
|
|
}
|
|
this.listenerNodePool.releaseCache();
|
|
}
|
|
get numListeners() {
|
|
return this._numListeners;
|
|
}
|
|
add(listener) {
|
|
if (this.nodes.has(listener)) {
|
|
return;
|
|
}
|
|
let node = this.listenerNodePool.get();
|
|
node.listener = listener;
|
|
this.nodes.set(listener, node);
|
|
this.addNode(node);
|
|
}
|
|
addOnce(listener) {
|
|
if (this.nodes.has(listener)) {
|
|
return;
|
|
}
|
|
let node = this.listenerNodePool.get();
|
|
node.listener = listener;
|
|
node.once = true;
|
|
this.nodes.set(listener, node);
|
|
this.addNode(node);
|
|
}
|
|
addNode(node) {
|
|
if (this.dispatching) {
|
|
if (!this.toAddHead) {
|
|
this.toAddHead = this.toAddTail = node;
|
|
}
|
|
else {
|
|
this.toAddTail.next = node;
|
|
node.previous = this.toAddTail;
|
|
this.toAddTail = node;
|
|
}
|
|
}
|
|
else {
|
|
if (!this.head) {
|
|
this.head = this.tail = node;
|
|
}
|
|
else {
|
|
this.tail.next = node;
|
|
node.previous = this.tail;
|
|
this.tail = node;
|
|
}
|
|
}
|
|
this._numListeners++;
|
|
}
|
|
remove(listener) {
|
|
let node = this.nodes.get(listener);
|
|
if (node) {
|
|
if (this.head === node) {
|
|
this.head = this.head.next;
|
|
}
|
|
if (this.tail === node) {
|
|
this.tail = this.tail.previous;
|
|
}
|
|
if (this.toAddHead === node) {
|
|
this.toAddHead = this.toAddHead.next;
|
|
}
|
|
if (this.toAddTail === node) {
|
|
this.toAddTail = this.toAddTail.previous;
|
|
}
|
|
if (node.previous) {
|
|
node.previous.next = node.next;
|
|
}
|
|
if (node.next) {
|
|
node.next.previous = node.previous;
|
|
}
|
|
this.nodes.remove(listener);
|
|
if (this.dispatching) {
|
|
this.listenerNodePool.cache(node);
|
|
}
|
|
else {
|
|
this.listenerNodePool.dispose(node);
|
|
}
|
|
this._numListeners--;
|
|
}
|
|
}
|
|
removeAll() {
|
|
while (this.head) {
|
|
let node = this.head;
|
|
this.head = this.head.next;
|
|
this.nodes.remove(node.listener);
|
|
this.listenerNodePool.dispose(node);
|
|
}
|
|
this.tail = null;
|
|
this.toAddHead = null;
|
|
this.toAddTail = null;
|
|
this._numListeners = 0;
|
|
}
|
|
}
|
|
exports.SignalBase = SignalBase;
|
|
|
|
},{"../Dictionary":36,"./ListenerNodePool":47}],52:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Signal1_1 = require("../signals/Signal1");
|
|
class RAFTickProvider extends Signal1_1.Signal1 {
|
|
constructor() {
|
|
super();
|
|
this.update = () => {
|
|
this._rafId = requestAnimationFrame(this.update);
|
|
let time = performance.now();
|
|
this.dispatch((time - this._previousTime) / 1000);
|
|
this._previousTime = time;
|
|
};
|
|
}
|
|
start() {
|
|
this._previousTime = performance.now();
|
|
this.playing = true;
|
|
this._rafId = requestAnimationFrame(this.update);
|
|
}
|
|
stop() {
|
|
cancelAnimationFrame(this._rafId);
|
|
}
|
|
}
|
|
exports.default = RAFTickProvider;
|
|
|
|
},{"../signals/Signal1":49}],53:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class AttentionNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.Attention)
|
|
], AttentionNode.prototype, "attention", void 0);
|
|
exports.AttentionNode = AttentionNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],54:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class DisplayNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], DisplayNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.Display)
|
|
], DisplayNode.prototype, "display", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.DisplayChange)
|
|
], DisplayNode.prototype, "displayChange", void 0);
|
|
exports.DisplayNode = DisplayNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],55:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class FetchAssetNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], FetchAssetNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.FetchAsset)
|
|
], FetchAssetNode.prototype, "fetchAsset", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.AssetCache)
|
|
], FetchAssetNode.prototype, "assetCache", void 0);
|
|
exports.FetchAssetNode = FetchAssetNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],56:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class GetConfigNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], GetConfigNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.GetConfig)
|
|
], GetConfigNode.prototype, "getConfig", void 0);
|
|
exports.GetConfigNode = GetConfigNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],57:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class HeadTouchNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], HeadTouchNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.HeadTouch)
|
|
], HeadTouchNode.prototype, "headTouch", void 0);
|
|
exports.HeadTouchNode = HeadTouchNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],58:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class HotWordNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.HotWord)
|
|
], HotWordNode.prototype, "hotWord", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], HotWordNode.prototype, "request", void 0);
|
|
exports.HotWordNode = HotWordNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],59:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class InterruptNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.Interrupt)
|
|
], InterruptNode.prototype, "interrupt", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], InterruptNode.prototype, "request", void 0);
|
|
exports.InterruptNode = InterruptNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],60:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class LightRingNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.LightRing)
|
|
], LightRingNode.prototype, "lightRing", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], LightRingNode.prototype, "request", void 0);
|
|
exports.LightRingNode = LightRingNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],61:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class ListenNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.Listen)
|
|
], ListenNode.prototype, "listen", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], ListenNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.LightRing)
|
|
], ListenNode.prototype, "lightRing", void 0);
|
|
exports.ListenNode = ListenNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],62:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class LookAtNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], LookAtNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.LookAt)
|
|
], LookAtNode.prototype, "lookAt", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.Target)
|
|
], LookAtNode.prototype, "target", void 0);
|
|
exports.LookAtNode = LookAtNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],63:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class MotionStreamNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], MotionStreamNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.MotionStream)
|
|
], MotionStreamNode.prototype, "motion", void 0);
|
|
exports.MotionStreamNode = MotionStreamNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],64:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class PersonStreamNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], PersonStreamNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.PersonStream)
|
|
], PersonStreamNode.prototype, "lps", void 0);
|
|
exports.PersonStreamNode = PersonStreamNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],65:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class PhotoStreamNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], PhotoStreamNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.PhotoStream)
|
|
], PhotoStreamNode.prototype, "stream", void 0);
|
|
exports.PhotoStreamNode = PhotoStreamNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],66:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class PlayNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], PlayNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.Play)
|
|
], PlayNode.prototype, "play", void 0);
|
|
exports.PlayNode = PlayNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],67:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class RemoteIndicatorNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RemoteIndicator)
|
|
], RemoteIndicatorNode.prototype, "indicator", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.LightRing)
|
|
], RemoteIndicatorNode.prototype, "lightRing", void 0);
|
|
exports.RemoteIndicatorNode = RemoteIndicatorNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],68:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class RequestCommandNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], RequestCommandNode.prototype, "request", void 0);
|
|
exports.RequestCommandNode = RequestCommandNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],69:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class ScreenGestureNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], ScreenGestureNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.ScreenGesture)
|
|
], ScreenGestureNode.prototype, "gesture", void 0);
|
|
exports.ScreenGestureNode = ScreenGestureNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],70:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class SessionNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], SessionNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.Session)
|
|
], SessionNode.prototype, "session", void 0);
|
|
exports.SessionNode = SessionNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],71:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class SetConfigNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], SetConfigNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.SetConfig)
|
|
], SetConfigNode.prototype, "setConfig", void 0);
|
|
exports.SetConfigNode = SetConfigNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],72:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class TakePhotoNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], TakePhotoNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.TakePhoto)
|
|
], TakePhotoNode.prototype, "photoData", void 0);
|
|
exports.TakePhotoNode = TakePhotoNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],73:[function(require,module,exports){
|
|
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Node_1 = require("../core/Node");
|
|
const components_1 = require("../components");
|
|
class TestNode extends Node_1.Node {
|
|
}
|
|
__decorate([
|
|
Node_1.keep(components_1.RequestCommand)
|
|
], TestNode.prototype, "request", void 0);
|
|
__decorate([
|
|
Node_1.keep(components_1.Test)
|
|
], TestNode.prototype, "test", void 0);
|
|
exports.TestNode = TestNode;
|
|
|
|
},{"../components":34,"../core/Node":40}],74:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var AttentionNode_1 = require("./AttentionNode");
|
|
exports.AttentionNode = AttentionNode_1.AttentionNode;
|
|
var DisplayNode_1 = require("./DisplayNode");
|
|
exports.DisplayNode = DisplayNode_1.DisplayNode;
|
|
var FetchAssetNode_1 = require("./FetchAssetNode");
|
|
exports.FetchAssetNode = FetchAssetNode_1.FetchAssetNode;
|
|
var GetConfigNode_1 = require("./GetConfigNode");
|
|
exports.GetConfigNode = GetConfigNode_1.GetConfigNode;
|
|
var HeadTouchNode_1 = require("./HeadTouchNode");
|
|
exports.HeadTouchNode = HeadTouchNode_1.HeadTouchNode;
|
|
var HotWordNode_1 = require("./HotWordNode");
|
|
exports.HotWordNode = HotWordNode_1.HotWordNode;
|
|
var InterruptNode_1 = require("./InterruptNode");
|
|
exports.InterruptNode = InterruptNode_1.InterruptNode;
|
|
var LightRingNode_1 = require("./LightRingNode");
|
|
exports.LightRingNode = LightRingNode_1.LightRingNode;
|
|
var ListenNode_1 = require("./ListenNode");
|
|
exports.ListenNode = ListenNode_1.ListenNode;
|
|
var LookAtNode_1 = require("./LookAtNode");
|
|
exports.LookAtNode = LookAtNode_1.LookAtNode;
|
|
var MotionStreamNode_1 = require("./MotionStreamNode");
|
|
exports.MotionStreamNode = MotionStreamNode_1.MotionStreamNode;
|
|
var PersonStreamNode_1 = require("./PersonStreamNode");
|
|
exports.PersonStreamNode = PersonStreamNode_1.PersonStreamNode;
|
|
var PhotoStreamNode_1 = require("./PhotoStreamNode");
|
|
exports.PhotoStreamNode = PhotoStreamNode_1.PhotoStreamNode;
|
|
var PlayNode_1 = require("./PlayNode");
|
|
exports.PlayNode = PlayNode_1.PlayNode;
|
|
var RemoteIndicatorNode_1 = require("./RemoteIndicatorNode");
|
|
exports.RemoteIndicatorNode = RemoteIndicatorNode_1.RemoteIndicatorNode;
|
|
var RequestCommandNode_1 = require("./RequestCommandNode");
|
|
exports.RequestCommandNode = RequestCommandNode_1.RequestCommandNode;
|
|
var ScreenGestureNode_1 = require("./ScreenGestureNode");
|
|
exports.ScreenGestureNode = ScreenGestureNode_1.ScreenGestureNode;
|
|
var SessionNode_1 = require("./SessionNode");
|
|
exports.SessionNode = SessionNode_1.SessionNode;
|
|
var SetConfigNode_1 = require("./SetConfigNode");
|
|
exports.SetConfigNode = SetConfigNode_1.SetConfigNode;
|
|
var TakePhotoNode_1 = require("./TakePhotoNode");
|
|
exports.TakePhotoNode = TakePhotoNode_1.TakePhotoNode;
|
|
var TestNode_1 = require("./TestNode");
|
|
exports.TestNode = TestNode_1.TestNode;
|
|
|
|
},{"./AttentionNode":53,"./DisplayNode":54,"./FetchAssetNode":55,"./GetConfigNode":56,"./HeadTouchNode":57,"./HotWordNode":58,"./InterruptNode":59,"./LightRingNode":60,"./ListenNode":61,"./LookAtNode":62,"./MotionStreamNode":63,"./PersonStreamNode":64,"./PhotoStreamNode":65,"./PlayNode":66,"./RemoteIndicatorNode":67,"./RequestCommandNode":68,"./ScreenGestureNode":69,"./SessionNode":70,"./SetConfigNode":71,"./TakePhotoNode":72,"./TestNode":73}],75:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const nodes_1 = require("../nodes");
|
|
const components_1 = require("../components");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
const os = require("os");
|
|
exports.MIN_FREE_MEM_RATE = 0.05;
|
|
class AssetsSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.onAdded = (node) => {
|
|
};
|
|
this.onRemoved = (node) => {
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.engine = engine;
|
|
this.nodes = this.engine.getNodeList(nodes_1.FetchAssetNode);
|
|
for (let node = this.nodes.head; node; node = node.next) {
|
|
this.onAdded(node);
|
|
}
|
|
this.nodes.nodeAdded.add(this.onAdded);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
for (node; node; node = node.next) {
|
|
let jibo = jibo_1.jiboRef.jibo;
|
|
let fetchAsset = node.fetchAsset;
|
|
let request = node.request;
|
|
if (!request.acknowledged) {
|
|
if (!this.thereIsFreeMemory()) {
|
|
let code;
|
|
code = jibo_command_protocol_1.ResponseCode.NotAcceptable;
|
|
request.setAcknowledge(code, true, jibo_command_protocol_1.FetchAssetErrorDetails.OutOfMemory);
|
|
}
|
|
else {
|
|
let assetToken = jibo.loader.load(this.buildAsset(fetchAsset), (err, res) => {
|
|
let response;
|
|
if (err) {
|
|
response = {
|
|
Event: jibo_command_protocol_1.FetchAssetEvents.AssetFailed,
|
|
Detail: err
|
|
};
|
|
}
|
|
else {
|
|
response = {
|
|
Event: jibo_command_protocol_1.FetchAssetEvents.AssetReady,
|
|
Detail: fetchAsset.name
|
|
};
|
|
}
|
|
request.addResponse(response, true);
|
|
});
|
|
node.assetCache.assetTokens.set(fetchAsset.name, assetToken);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
let entityCache = engine.getEntityByName("assetCache");
|
|
if (entityCache) {
|
|
let assetCache = entityCache.get(components_1.AssetCache);
|
|
let removeAssetToken = (value, key, map) => {
|
|
jibo_1.jiboRef.jibo.loader.unload(value);
|
|
map.delete(key);
|
|
};
|
|
assetCache.assetTokens.forEach(removeAssetToken);
|
|
}
|
|
this.nodes = null;
|
|
}
|
|
thereIsFreeMemory() {
|
|
if (jibo_1.jiboRef.jibo.runMode === jibo_1.jiboRef.jibo.RunMode.ON_ROBOT) {
|
|
return (os.freemem() / os.totalmem() > exports.MIN_FREE_MEM_RATE);
|
|
}
|
|
return true;
|
|
}
|
|
buildAsset(fetchAsset) {
|
|
if (fetchAsset.uri.endsWith(".wav") || fetchAsset.uri.endsWith(".mp3")) {
|
|
return {
|
|
id: fetchAsset.name,
|
|
src: fetchAsset.uri,
|
|
type: "sound",
|
|
block: false,
|
|
volume: 1,
|
|
panning: 0,
|
|
loop: false,
|
|
autoPlay: false,
|
|
cache: jibo_1.jiboRef.jibo.loader.activeCache,
|
|
complete: function (err, sound) { }
|
|
};
|
|
}
|
|
else if (fetchAsset.uri.endsWith(".png") || fetchAsset.uri.endsWith(".jpg") || fetchAsset.uri.endsWith(".jpeg")) {
|
|
return {
|
|
id: fetchAsset.name,
|
|
src: fetchAsset.uri,
|
|
type: "texture",
|
|
upload: false,
|
|
cache: jibo_1.jiboRef.jibo.loader.activeCache,
|
|
complete: function (err, texture) { }
|
|
};
|
|
}
|
|
else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
exports.default = AssetsSystem;
|
|
|
|
},{"../../jibo":97,"../components":34,"../core":45,"../nodes":74,"jibo-command-protocol":undefined,"os":undefined}],76:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_1 = require("../../jibo");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class AttentionSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.onRemoved = (node) => {
|
|
this.releaseAttention(node.attention);
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.nodes = engine.getNodeList(nodes_1.AttentionNode);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
let attention;
|
|
let request;
|
|
let jibo = jibo_1.jiboRef.jibo;
|
|
for (node; node; node = node.next) {
|
|
attention = node.attention;
|
|
if (node.next) {
|
|
this.releaseAttention(node.attention);
|
|
request = node.request;
|
|
if (request) {
|
|
if (request.acknowledged) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Error,
|
|
EventError: {
|
|
ErrorString: "Attention mode overwritten",
|
|
ErrorCode: 1
|
|
}
|
|
};
|
|
request.addResponse(response, true);
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Conflict, true);
|
|
}
|
|
}
|
|
}
|
|
else if (!attention.active) {
|
|
attention.active = true;
|
|
jibo.expression.pushAttentionMode(this.convertMode(attention.mode))
|
|
.then((handle) => {
|
|
if (attention.active) {
|
|
attention.handle = handle;
|
|
}
|
|
else {
|
|
handle.release()
|
|
.then(() => {
|
|
});
|
|
}
|
|
});
|
|
if (node.request) {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Created, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
convertMode(mode) {
|
|
return String(mode);
|
|
}
|
|
releaseAttention(attention) {
|
|
if (attention.active) {
|
|
attention.active = false;
|
|
if (attention.handle) {
|
|
attention.handle.release()
|
|
.then(() => {
|
|
attention.handle = null;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
exports.default = AttentionSystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],77:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const nodes_1 = require("../nodes");
|
|
const CommandUtil_1 = require("../../CommandUtil");
|
|
class CommandSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
}
|
|
addToEngine(engine) {
|
|
this.engine = engine;
|
|
this.commandNodes = engine.getNodeList(nodes_1.RequestCommandNode);
|
|
this.sessionNodes = engine.getNodeList(nodes_1.SessionNode);
|
|
}
|
|
update(time) {
|
|
let node = this.commandNodes.head;
|
|
const sessionNode = this.sessionNodes.tail;
|
|
if (sessionNode) {
|
|
const session = sessionNode.session;
|
|
if (session.reconnection) {
|
|
for (let i = 0; i < session.storedEvents.length; i++) {
|
|
session.sendMethod(session.storedEvents[i]);
|
|
}
|
|
session.storedEvents.length = 0;
|
|
session.reconnection = false;
|
|
}
|
|
let request;
|
|
for (node; node; node = node.next) {
|
|
request = node.request;
|
|
if (request.isDirty) {
|
|
if (!request.acknowledged) {
|
|
this.sendEvent(session, this.createAcknowledgement(session, request));
|
|
request.acknowledged = true;
|
|
}
|
|
if (request.responses.length > 0) {
|
|
this.sendMessages(request, session);
|
|
}
|
|
if (request.complete) {
|
|
this.engine.removeEntity(node.entity);
|
|
}
|
|
else {
|
|
request.clean();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.commandNodes = null;
|
|
this.engine = engine;
|
|
}
|
|
sendEvent(session, data) {
|
|
if (session.hasConnection) {
|
|
session.sendMethod(data);
|
|
}
|
|
else {
|
|
session.storedEvents.push(data);
|
|
}
|
|
}
|
|
sendMessages(request, session) {
|
|
for (let i = 0; i < request.responses.length; i++) {
|
|
this.sendEvent(session, this.createEvent(session, request, request.responses[i]));
|
|
}
|
|
request.responses.length = 0;
|
|
}
|
|
createAcknowledgement(ses, req) {
|
|
return CommandUtil_1.default.createAcknowledgement(req.version, req.id, ses.id, req.acknowledgeCode, req.acknowledgeData);
|
|
}
|
|
createEvent(ses, req, data) {
|
|
return CommandUtil_1.default.createEvent(req.version, req.id, ses.id, data);
|
|
}
|
|
}
|
|
exports.default = CommandSystem;
|
|
|
|
},{"../../CommandUtil":5,"../core":45,"../nodes":74}],78:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class DisplaySystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.onAdded = (node) => {
|
|
};
|
|
this.onRemoved = (node) => {
|
|
if (node.displayChange.isActive) {
|
|
this.removeView().then((view) => {
|
|
console.log('onRemoved : remove view succeeded');
|
|
})
|
|
.catch(() => {
|
|
console.log('onRemoved : remove view failed');
|
|
});
|
|
}
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.nodes = engine.getNodeList(nodes_1.DisplayNode);
|
|
for (let node = this.nodes.head; node; node = node.next) {
|
|
this.onAdded(node);
|
|
}
|
|
this.nodes.nodeAdded.add(this.onAdded);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.tail;
|
|
while (node) {
|
|
let displayChange = node.displayChange;
|
|
if (!displayChange.isActive) {
|
|
displayChange.isActive = true;
|
|
let request = node.request;
|
|
switch (displayChange.type) {
|
|
case jibo_command_protocol_1.DisplayChangeType.Swap:
|
|
let view = this.createView(node.display.view);
|
|
if (view) {
|
|
this.swapViews(view)
|
|
.then((view) => {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.DisplayEvents.ViewStateChange,
|
|
State: jibo_command_protocol_1.ViewStates.Opened
|
|
};
|
|
request.addResponse(response, false);
|
|
})
|
|
.catch(() => {
|
|
console.log('update : swap view failed');
|
|
displayChange.isActive = false;
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Stop,
|
|
};
|
|
request.addResponse(response, true);
|
|
});
|
|
}
|
|
else {
|
|
console.log('update : invalid view data');
|
|
displayChange.isActive = false;
|
|
let code = jibo_command_protocol_1.ResponseCode.BadRequest;
|
|
let message = jibo_command_protocol_1.DisplayErrorDetails.MissingValues;
|
|
request.setAcknowledge(code, true, message);
|
|
node = node.previous;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
node = node.previous;
|
|
for (node; node; node = node.previous) {
|
|
if (!node.displayChange.isActive) {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Conflict, true, 'active view change in process');
|
|
}
|
|
else {
|
|
node.displayChange.isActive = false;
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Stop,
|
|
};
|
|
node.request.addResponse(response, true);
|
|
}
|
|
}
|
|
node = null;
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
swapViews(view) {
|
|
return new Promise((resolve, reject) => {
|
|
if (view) {
|
|
jibo_1.jiboRef.jibo.face.views.changeView({
|
|
remove: true,
|
|
addView: view
|
|
}, resolve, reject);
|
|
}
|
|
});
|
|
}
|
|
removeView() {
|
|
return new Promise((resolve, reject) => {
|
|
jibo_1.jiboRef.jibo.face.views.changeView({
|
|
remove: true
|
|
}, resolve, reject);
|
|
});
|
|
}
|
|
createView(viewRequest) {
|
|
try {
|
|
if (viewRequest) {
|
|
let view;
|
|
switch (viewRequest.Type) {
|
|
case jibo_command_protocol_1.DisplayViewType.Eye:
|
|
let eyeView = new jibo_1.jiboRef.jibo.face.views.EyeView();
|
|
this.setViewDefaults(eyeView, viewRequest);
|
|
return eyeView;
|
|
case jibo_command_protocol_1.DisplayViewType.Text:
|
|
view = this.setViewDefaults(new jibo_1.jiboRef.jibo.face.views.View(), viewRequest);
|
|
let label = new jibo_1.jiboRef.jibo.face.views.Label();
|
|
label.text = viewRequest.Text;
|
|
label.setTargetAnchor(.5, .5);
|
|
label.setTargetPosition(jibo_1.jiboRef.jibo.face.width / 2, jibo_1.jiboRef.jibo.face.height / 2);
|
|
view.addComponent(label);
|
|
return view;
|
|
case jibo_command_protocol_1.DisplayViewType.Image:
|
|
view = this.setViewDefaults(new jibo_1.jiboRef.jibo.face.views.View(), viewRequest);
|
|
let clip = new jibo_1.jiboRef.jibo.face.views.Clip();
|
|
clip.addAssetDescriptor(viewRequest.Image.name, viewRequest.Image.src, 'texture');
|
|
view.addComponent(clip);
|
|
return view;
|
|
}
|
|
}
|
|
else {
|
|
console.log('swapViews : given view request was null');
|
|
}
|
|
}
|
|
catch (err) {
|
|
console.log('swapViews : error encountered creating view', err);
|
|
}
|
|
return null;
|
|
}
|
|
setViewDefaults(view, viewRequest) {
|
|
view.id = viewRequest.Name;
|
|
view.closeOnSwipeDown = false;
|
|
return view;
|
|
}
|
|
}
|
|
exports.default = DisplaySystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],79:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_1 = require("../../jibo");
|
|
const jibo_common_types_1 = require("jibo-common-types");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class GetConfigSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.onRemoved = (node) => {
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.nodes = engine.getNodeList(nodes_1.GetConfigNode);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
for (node; node; node = node.next) {
|
|
console.log("got node");
|
|
let request = node.request;
|
|
if (!request.acknowledged) {
|
|
let getConfig = node.getConfig;
|
|
this.getConfigState(getConfig).then((response) => {
|
|
request.addResponse(response, true);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
getConfigState(getConfig) {
|
|
return new Promise((resolve, reject) => {
|
|
let config;
|
|
let bs = new jibo_common_types_1.BodyState();
|
|
let battery = {
|
|
Settable: false,
|
|
Capacity: bs.powerState.battery.capacity,
|
|
Max_capacity: bs.powerState.battery.max_capacity,
|
|
Charge_rate: bs.powerState.battery.charge_rate
|
|
};
|
|
let wifi = {
|
|
Settable: false,
|
|
Strength: 0,
|
|
};
|
|
let mixers = {
|
|
Settable: true,
|
|
Master: null
|
|
};
|
|
const head = jibo_1.jiboRef.jibo.expression.features.head;
|
|
let actualPosition = head.direction.clone().add(head.position);
|
|
let position = {
|
|
WorldPosition: [actualPosition.x, actualPosition.y, actualPosition.z],
|
|
AnglePosition: this.XYZ2Angles(actualPosition)
|
|
};
|
|
jibo_1.jiboRef.jibo.system.getMasterVolume((err, volume) => {
|
|
mixers.Master = volume;
|
|
jibo_1.jiboRef.jibo.wifi.getCurrentNetwork((err, net) => {
|
|
wifi.Strength = net.strength;
|
|
config = {
|
|
Event: jibo_command_protocol_1.ConfigEvents.onConfig,
|
|
Battery: battery,
|
|
Wifi: wifi,
|
|
Mixers: mixers,
|
|
Position: position
|
|
};
|
|
resolve(config);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
XYZ2Angles(actualPosition) {
|
|
return [0, 0];
|
|
}
|
|
}
|
|
exports.default = GetConfigSystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74,"jibo-command-protocol":undefined,"jibo-common-types":undefined}],80:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class HeadTouchSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.headPads = [false, false, false, false, false, false];
|
|
}
|
|
addToEngine(engine) {
|
|
this.engine = engine;
|
|
this.nodes = this.engine.getNodeList(nodes_1.HeadTouchNode);
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.tail;
|
|
if (node) {
|
|
let request = node.request;
|
|
this.updatePads();
|
|
if (this.hasBeenTouched === true) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.HeadTouchEvents.HeadTouched,
|
|
Pads: this.headPads
|
|
};
|
|
request.addResponse(response, false);
|
|
}
|
|
for (node = node.previous; node; node = node.previous) {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Conflict, true);
|
|
}
|
|
}
|
|
}
|
|
updatePads() {
|
|
let headTouchData = jibo_1.jiboRef.jibo.system.getTouchState();
|
|
this.headPads = headTouchData.pad_state;
|
|
this.hasBeenTouched = headTouchData.touched;
|
|
}
|
|
}
|
|
exports.default = HeadTouchSystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],81:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const nodes_1 = require("../nodes");
|
|
const components_1 = require("../components");
|
|
const CommandUtil_1 = require("../../CommandUtil");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class HotWordSystem extends core_1.System {
|
|
constructor(enable = true) {
|
|
super();
|
|
this.hjHeard = false;
|
|
this.hjEnable = enable;
|
|
this.onHJHeard = this.onHJHeard.bind(this);
|
|
}
|
|
addToEngine(engine) {
|
|
if (this.hjEnable) {
|
|
this.resetHJHeard();
|
|
jibo_1.jiboRef.jibo.jetstream.events.hjHeard.on(this.onHJHeard);
|
|
this.nodes = engine.getNodeList(nodes_1.HotWordNode);
|
|
}
|
|
this.enableHJ(this.hjEnable);
|
|
}
|
|
update(time) {
|
|
if (this.nodes) {
|
|
let node = this.nodes.head;
|
|
for (node; node; node = node.next) {
|
|
let request = node.request;
|
|
if (node.next) {
|
|
if (request.acknowledged) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Error,
|
|
EventError: {
|
|
ErrorString: "HotWord Subscribe overwritten",
|
|
ErrorCode: 1
|
|
}
|
|
};
|
|
request.addResponse(response, true);
|
|
node.entity.remove(components_1.LightRing);
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Conflict, true);
|
|
}
|
|
}
|
|
else {
|
|
const hotWord = node.hotWord;
|
|
if (hotWord.coolDown > 0) {
|
|
hotWord.coolDown -= time;
|
|
if (hotWord.coolDown <= 0) {
|
|
hotWord.coolDown = 0;
|
|
node.entity.remove(components_1.LightRing);
|
|
}
|
|
}
|
|
else if (this.hjHeard) {
|
|
const response = {
|
|
Event: jibo_command_protocol_1.HotWordEvents.HotWordHeard,
|
|
Speaker: this.speaker
|
|
};
|
|
request.addResponse(response);
|
|
hotWord.coolDown = hotWord.coolDownMax;
|
|
const lightRing = new components_1.LightRing();
|
|
lightRing.setColor(CommandUtil_1.default.LISTEN_COLORS);
|
|
node.entity.add(lightRing);
|
|
}
|
|
}
|
|
}
|
|
this.resetHJHeard();
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
if (this.hjEnable) {
|
|
jibo_1.jiboRef.jibo.jetstream.events.hjHeard.off(this.onHJHeard);
|
|
}
|
|
this.resetHJHeard();
|
|
if (this.hjToken) {
|
|
this.hjToken.release().catch((err) => {
|
|
}).then(() => {
|
|
this.hjToken = null;
|
|
});
|
|
}
|
|
}
|
|
enableHJ(enable) {
|
|
if (enable) {
|
|
if (!this.hjToken) {
|
|
this.hjToken = jibo_1.jiboRef.jibo.jetstream.setHotwordMode(jibo_1.jiboRef.jibo.jetstream.types.HotwordListenMode.HJ_Only);
|
|
}
|
|
else {
|
|
}
|
|
return this.hjToken.activated.catch((err) => {
|
|
});
|
|
}
|
|
else {
|
|
if (!this.hjToken) {
|
|
this.hjToken = jibo_1.jiboRef.jibo.jetstream.setHotwordMode(jibo_1.jiboRef.jibo.jetstream.types.HotwordListenMode.Disabled);
|
|
}
|
|
else {
|
|
}
|
|
return this.hjToken.activated.catch((err) => {
|
|
});
|
|
}
|
|
}
|
|
onHJHeard(data) {
|
|
this.hjHeard = true;
|
|
let stubSpeaker = {
|
|
LPSPosition: {
|
|
Position: [0, 0, 0],
|
|
AngleVector: [0, 0],
|
|
Confidence: 0
|
|
},
|
|
SpeakerID: {
|
|
Type: jibo_command_protocol_1.EntityType.Unknown,
|
|
Confidence: 0
|
|
}
|
|
};
|
|
this.speaker = stubSpeaker;
|
|
}
|
|
resetHJHeard() {
|
|
if (this.hjHeard) {
|
|
jibo_1.jiboRef.jibo.embodied.listen.waitForIdle(true);
|
|
jibo_1.jiboRef.jibo.globalEvents.shared.hjOnly.emit();
|
|
}
|
|
this.hjHeard = false;
|
|
this.speaker = null;
|
|
}
|
|
}
|
|
exports.default = HotWordSystem;
|
|
|
|
},{"../../CommandUtil":5,"../../jibo":97,"../components":34,"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],82:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const nodes_1 = require("../nodes");
|
|
const components_1 = require("../components");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class InterruptSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
}
|
|
addToEngine(engine) {
|
|
this.interrupts = engine.getNodeList(nodes_1.InterruptNode);
|
|
this.requests = engine.getNodeList(nodes_1.RequestCommandNode);
|
|
}
|
|
update(time) {
|
|
for (let node = this.interrupts.head; node; node = node.next) {
|
|
if (node.interrupt.interruptAll) {
|
|
this.interruptAllCommands();
|
|
return;
|
|
}
|
|
else {
|
|
let interruptId = node.interrupt.interruptId;
|
|
if (interruptId) {
|
|
if (this.interruptCommandById(interruptId)) {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.OK, true, interruptId);
|
|
}
|
|
else {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.OK, true, 'No command found with id: ' + interruptId);
|
|
}
|
|
}
|
|
else {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.NotAcceptable, true, 'Id not provided');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.interrupts = null;
|
|
this.requests = null;
|
|
}
|
|
interruptAllCommands() {
|
|
let node = this.requests.head;
|
|
for (node; node; node = node.next) {
|
|
if (!node.entity.has(components_1.Interrupt)) {
|
|
this.interruptEntity(node);
|
|
}
|
|
else {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.OK, true);
|
|
}
|
|
}
|
|
}
|
|
interruptCommandById(id) {
|
|
let node = this.requests.head;
|
|
for (node; node; node = node.next) {
|
|
if (node.request.id === id) {
|
|
this.interruptEntity(node);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
interruptEntity(node) {
|
|
let components = node.entity.getAll();
|
|
for (let i = components.length - 1; i >= 0; i--) {
|
|
let componentClass = components[i].constructor.prototype.constructor;
|
|
if (componentClass !== components_1.RequestCommand) {
|
|
node.entity.remove(componentClass);
|
|
}
|
|
}
|
|
node.request.acknowledged = true;
|
|
node.request.setComplete();
|
|
}
|
|
}
|
|
exports.default = InterruptSystem;
|
|
|
|
},{"../components":34,"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],83:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const nodes_1 = require("../nodes");
|
|
class ListenRingSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.onRemoved = (node) => {
|
|
if (node.lightRing.isActive) {
|
|
if (node.previous) {
|
|
jibo_1.jiboRef.jibo.expression.setLEDColor(node.previous.lightRing.color);
|
|
node.previous.lightRing.isActive = true;
|
|
}
|
|
else {
|
|
jibo_1.jiboRef.jibo.expression.setLEDColor([0, 0, 0]);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.nodes = engine.getNodeList(nodes_1.LightRingNode);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
for (node; node; node = node.next) {
|
|
let lightRing = node.lightRing;
|
|
if (node.next) {
|
|
lightRing.isActive = false;
|
|
}
|
|
else {
|
|
lightRing.isActive = true;
|
|
if (lightRing.isDirty) {
|
|
jibo_1.jiboRef.jibo.expression.setLEDColor(node.lightRing.color);
|
|
lightRing.isDirty = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
jibo_1.jiboRef.jibo.expression.setLEDColor([0, 0, 0]);
|
|
}
|
|
}
|
|
exports.default = ListenRingSystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74}],84:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const nodes_1 = require("../nodes");
|
|
const CommandUtil_1 = require("../../CommandUtil");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class ListenSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.onRemoved = (node) => {
|
|
if (node.listen.isActive) {
|
|
if (node.listen.mim) {
|
|
node.listen.mim.stopAndDestroy();
|
|
node.listen.mim = null;
|
|
}
|
|
node.listen.isActive = false;
|
|
}
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.nodes = engine.getNodeList(nodes_1.ListenNode);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
for (node; node; node = node.next) {
|
|
let request = node.request;
|
|
if (node.next) {
|
|
if (request.acknowledged) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Error,
|
|
EventError: {
|
|
ErrorString: "Listen overwritten",
|
|
ErrorCode: 1
|
|
}
|
|
};
|
|
request.addResponse(response, true);
|
|
}
|
|
else {
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Conflict, true);
|
|
}
|
|
}
|
|
else {
|
|
let listen = node.listen;
|
|
if (!listen.mim) {
|
|
this.createMim(listen);
|
|
listen.isActive = true;
|
|
node.lightRing.setColor(CommandUtil_1.default.LISTEN_COLORS);
|
|
}
|
|
else {
|
|
let status = node.listen.mim.update();
|
|
if (status !== jibo_1.jiboRef.jibo.bt.Status.IN_PROGRESS) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.ListenEvents.ListenResult,
|
|
LanguageCode: "en-US",
|
|
Speech: node.listen.speech.text
|
|
};
|
|
request.addResponse(response, true);
|
|
listen.isActive = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
createMim(listen) {
|
|
let mimConfig = {
|
|
mim_id: "Listen System",
|
|
mim_type: "optional-response",
|
|
rule_name: "shared/wildcard",
|
|
timeout: listen.maxNoSpeechTimeout,
|
|
barge_in: false,
|
|
prompts: [
|
|
{
|
|
prompt_category: "Entry-Core",
|
|
prompt_sub_category: "AN",
|
|
index: 1,
|
|
condition: "",
|
|
prompt: "",
|
|
media: "silence",
|
|
prompt_id: ""
|
|
}
|
|
],
|
|
num_tries_for_gui: 0,
|
|
es_auto_tagging: true,
|
|
ignore_no_match: true
|
|
};
|
|
let mimOptions = {
|
|
onSuccess: listen.onMimEnd.bind(listen),
|
|
mimConfig: mimConfig,
|
|
assetPack: "jibo",
|
|
onFailure: listen.onMimEnd.bind(listen),
|
|
onPositionalSelect: null,
|
|
mimPath: null,
|
|
guiConfig: null,
|
|
getPromptData: null,
|
|
asrMetadata: {
|
|
skill: "remote"
|
|
},
|
|
isMenu: false
|
|
};
|
|
listen.mim = new jibo_1.jiboRef.jibo.bt.behaviors.Mim(mimOptions);
|
|
listen.mim.start();
|
|
}
|
|
}
|
|
exports.default = ListenSystem;
|
|
|
|
},{"../../CommandUtil":5,"../../jibo":97,"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],85:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const THREE = require("@jibo/three");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
const jibo_command_protocol_2 = require("jibo-command-protocol");
|
|
class LookAtSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.screenSize = [640, 360];
|
|
this.onRemoved = (node) => {
|
|
if (node.lookAt.isActive && !node.lookAt.interrupted) {
|
|
let actualPosition = jibo_1.jiboRef.jibo.expression.features.head.direction.clone().add(jibo_1.jiboRef.jibo.expression.features.head.position);
|
|
jibo_1.jiboRef.jibo.expression.acquireTarget({ position: actualPosition });
|
|
}
|
|
};
|
|
this.getCameraParameters();
|
|
}
|
|
addToEngine(engine) {
|
|
this.nodes = engine.getNodeList(nodes_1.LookAtNode);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
for (node; node; node = node.next) {
|
|
let lookAt = node.lookAt;
|
|
let request = node.request;
|
|
if (node.next) {
|
|
if (request.acknowledged) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Error,
|
|
EventError: {
|
|
ErrorString: "Target overwritten",
|
|
ErrorCode: 1
|
|
}
|
|
};
|
|
request.addResponse(response, true);
|
|
}
|
|
else {
|
|
let code;
|
|
code = jibo_command_protocol_1.ResponseCode.Conflict;
|
|
request.setAcknowledge(code, true);
|
|
}
|
|
node.lookAt.interrupted = true;
|
|
}
|
|
else {
|
|
if (!lookAt.isActive) {
|
|
let target = {
|
|
position: null
|
|
};
|
|
const lookAtTarget = node.target.lookAtTarget;
|
|
if (jibo_command_protocol_2.typeguards.isPositionTarget(lookAtTarget)) {
|
|
target.position = {
|
|
x: lookAtTarget.Position[0],
|
|
y: lookAtTarget.Position[1],
|
|
z: lookAtTarget.Position[2]
|
|
};
|
|
}
|
|
else if (jibo_command_protocol_2.typeguards.isAngleTarget(lookAtTarget)) {
|
|
target.position = this.angles2XYZ(lookAtTarget.Angle);
|
|
}
|
|
else if (jibo_command_protocol_2.typeguards.isCameraTarget(lookAtTarget)) {
|
|
target.position = this.screencords2XYZ(lookAtTarget);
|
|
}
|
|
else if (jibo_command_protocol_2.typeguards.isEntityTarget(lookAtTarget)) {
|
|
target.position = this.entity2XYZ(lookAtTarget.Entity);
|
|
}
|
|
if (target.position) {
|
|
lookAt.isActive = true;
|
|
jibo_1.jiboRef.jibo.expression.acquireTarget(target).then((acquireHandle) => {
|
|
acquireHandle.promise.then((result) => {
|
|
let response;
|
|
if (result === "SUCCEEDED") {
|
|
response = {
|
|
Event: jibo_command_protocol_1.LookAtEvents.LookAtAchieved,
|
|
PositionTarget: [0, 0, 0],
|
|
AngleTarget: [0, 0]
|
|
};
|
|
}
|
|
else {
|
|
response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Error,
|
|
EventError: {
|
|
ErrorString: "Target overwritten",
|
|
ErrorCode: 1
|
|
}
|
|
};
|
|
}
|
|
request.addResponse(response, true);
|
|
});
|
|
});
|
|
}
|
|
else {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Error,
|
|
EventError: {
|
|
ErrorString: "Bad target",
|
|
ErrorCode: 2
|
|
}
|
|
};
|
|
request.addResponse(response, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
entity2XYZ(lookAtEntity) {
|
|
let lpsData = jibo_1.jiboRef.jibo.lps.motionData;
|
|
for (let entity of lpsData.entities) {
|
|
if (entity.description = "person") {
|
|
let hasParts = entity.parts.some((part) => {
|
|
return ((part.key === "head") || (part.key === "face"));
|
|
});
|
|
if (hasParts) {
|
|
if (lookAtEntity === entity.id) {
|
|
return entity.position;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
angles2XYZ(angles) {
|
|
const head = jibo_1.jiboRef.jibo.expression.features.head;
|
|
let actualPosition = head.direction.clone().add(head.position);
|
|
let up = new THREE.Vector3(0, 0, 1);
|
|
let perpendicular = actualPosition.clone().cross(up);
|
|
let auxVector = actualPosition.clone().applyAxisAngle(up, angles[0]);
|
|
let target = auxVector.clone().applyAxisAngle(perpendicular.clone().applyAxisAngle(up, angles[0]), angles[1]);
|
|
return target;
|
|
}
|
|
screencords2XYZ(target) {
|
|
let screencords = [null, null];
|
|
let cx = this.cameraParameters.center.x;
|
|
let cy = this.cameraParameters.center.y;
|
|
let fx = this.cameraParameters.focalLength.x;
|
|
let fy = this.cameraParameters.focalLength.y;
|
|
if (target.ScreenSize) {
|
|
screencords[0] = target.ScreenCoords[0] * this.cameraParameters.width / target.ScreenSize[0];
|
|
screencords[1] = target.ScreenCoords[1] * this.cameraParameters.height / target.ScreenSize[1];
|
|
}
|
|
else {
|
|
screencords[0] = target.ScreenCoords[0] * this.cameraParameters.width / this.screenSize[0];
|
|
screencords[1] = target.ScreenCoords[1] * this.cameraParameters.height / this.screenSize[1];
|
|
}
|
|
let n_pix = [(screencords[0] - cx) / fx, (screencords[1] - cy) / fy];
|
|
let k1 = this.cameraParameters.distortion[0];
|
|
let k2 = this.cameraParameters.distortion[1];
|
|
let k3 = this.cameraParameters.distortion[4];
|
|
let p1 = this.cameraParameters.distortion[2];
|
|
let p2 = this.cameraParameters.distortion[3];
|
|
let nd_pix = [n_pix[0], n_pix[1]];
|
|
for (let i = 0; i < 20; i++) {
|
|
let r_2 = Math.pow(nd_pix[0], 2) + Math.pow(nd_pix[1], 2);
|
|
let r_4 = r_2 * r_2;
|
|
let r_6 = r_2 * r_4;
|
|
let k_radial = 1 + k1 * r_2 + k2 * r_4 + k3 * r_6;
|
|
let delta_x = 2 * p1 * nd_pix[0] * nd_pix[1] + p2 * (r_2 + 2 * Math.pow(nd_pix[0], 2));
|
|
let delta_y = p1 * (r_2 + 2 * Math.pow(nd_pix[1], 2)) + 2 * p2 * nd_pix[0] * nd_pix[1];
|
|
nd_pix[0] = (n_pix[0] - delta_x) / k_radial;
|
|
nd_pix[1] = (n_pix[1] - delta_y) / k_radial;
|
|
}
|
|
let u_pix = [nd_pix[0] * fx + cx, nd_pix[1] * fy + cy];
|
|
let theta = Math.atan((u_pix[0] - cx) / fx);
|
|
let psi = -Math.atan((u_pix[1] - cy) / fy);
|
|
let angles = [theta, psi];
|
|
return this.angles2XYZ(angles);
|
|
}
|
|
getCameraParameters() {
|
|
this.cameraParameters = {
|
|
width: 1280,
|
|
height: 720,
|
|
center: {
|
|
x: 657.3223266601562,
|
|
y: 378.8253479003906
|
|
},
|
|
focalLength: {
|
|
x: 783.9614868164062,
|
|
y: 784.0986328125
|
|
},
|
|
distortion: [
|
|
-0.36631643772125244,
|
|
0.1101401150226593,
|
|
0.0009784416761249304,
|
|
0.0012007149634882808,
|
|
0
|
|
]
|
|
};
|
|
try {
|
|
jibo_1.jiboRef.jibo.lps.getCameraParameters(0, (err, data) => {
|
|
if (data && this.isCameraParameters(data)) {
|
|
this.cameraParameters = data;
|
|
}
|
|
});
|
|
}
|
|
catch (e) {
|
|
}
|
|
}
|
|
isCameraParameters(data) {
|
|
return typeof data === 'object' && 'focalLength' in data;
|
|
}
|
|
}
|
|
exports.default = LookAtSystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74,"@jibo/three":undefined,"jibo-command-protocol":undefined}],86:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class MotionStreamSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.detectedMotions = [];
|
|
}
|
|
addToEngine(engine) {
|
|
this.engine = engine;
|
|
this.nodes = this.engine.getNodeList(nodes_1.MotionStreamNode);
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
this.detectedMotions = null;
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.tail;
|
|
if (node) {
|
|
let request = node.request;
|
|
this.detectMotion();
|
|
if (this.detectedMotions.length > 0) {
|
|
console.log("Motion detected: ", this.detectedMotions);
|
|
let response = {
|
|
Event: jibo_command_protocol_1.MotionEvents.MotionDetected,
|
|
Motions: this.detectedMotions
|
|
};
|
|
request.addResponse(response, false);
|
|
}
|
|
for (node = node.previous; node; node = node.previous) {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Conflict, true);
|
|
}
|
|
}
|
|
}
|
|
detectMotion() {
|
|
let lpsData = jibo_1.jiboRef.jibo.lps.motionData;
|
|
this.detectedMotions.length = 0;
|
|
let detectedMotion = {
|
|
Intensity: null,
|
|
WorldCoords: null,
|
|
ScreenCoords: null
|
|
};
|
|
for (let entity of lpsData.entities) {
|
|
if (entity.description = "motion") {
|
|
detectedMotion.Intensity = entity.intensity;
|
|
detectedMotion.WorldCoords = [entity.position.x, entity.position.y, entity.position.z];
|
|
let rectangle = entity.parts[0].value.trackers[0].rectangle;
|
|
let x = rectangle.left;
|
|
let y = rectangle.top;
|
|
let width = rectangle.right - rectangle.left;
|
|
let height = rectangle.bottom - rectangle.top;
|
|
detectedMotion.ScreenCoords = [x, y, width, height];
|
|
this.detectedMotions.push(detectedMotion);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
exports.default = MotionStreamSystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],87:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class PersonStreamSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.detectedEntities = [];
|
|
this.lostEntities = [];
|
|
this.updatedEntities = [];
|
|
}
|
|
addToEngine(engine) {
|
|
this.engine = engine;
|
|
this.nodes = this.engine.getNodeList(nodes_1.PersonStreamNode);
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
if (node) {
|
|
let request = node.request;
|
|
this.updateLPS();
|
|
if (this.detectedEntities.length > 0) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.EntityTrackEvents.TrackGained,
|
|
Tracks: this.detectedEntities
|
|
};
|
|
request.addResponse(response, false);
|
|
}
|
|
let response = {
|
|
Event: jibo_command_protocol_1.EntityTrackEvents.TrackUpdate,
|
|
Tracks: this.updatedEntities
|
|
};
|
|
request.addResponse(response, false);
|
|
if (this.lostEntities.length > 0) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.EntityTrackEvents.TrackLost,
|
|
Tracks: this.lostEntities
|
|
};
|
|
request.addResponse(response, false);
|
|
}
|
|
for (node = node.next; node; node = node.next) {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Conflict, true);
|
|
}
|
|
}
|
|
}
|
|
updateLPS() {
|
|
let lpsData = jibo_1.jiboRef.jibo.lps.motionData;
|
|
let prevUpdatedEntities = this.updatedEntities.slice().concat(this.detectedEntities.slice());
|
|
this.detectedEntities.length = 0;
|
|
this.lostEntities.length = 0;
|
|
this.updatedEntities.length = 0;
|
|
for (let entity of lpsData.entities) {
|
|
if (entity.description = "person") {
|
|
let hasParts = entity.parts.some((part) => {
|
|
return ((part.key === "head") || (part.key === "face"));
|
|
});
|
|
if (hasParts) {
|
|
let trackedEntity = {
|
|
EntityID: null,
|
|
Type: null,
|
|
Confidence: null,
|
|
WorldCoords: null,
|
|
ScreenCoords: null
|
|
};
|
|
trackedEntity.Type = jibo_command_protocol_1.EntityType.Person;
|
|
trackedEntity.Confidence = entity.confidence;
|
|
trackedEntity.EntityID = entity.id;
|
|
trackedEntity.WorldCoords = [entity.position.x, entity.position.y, entity.position.z];
|
|
let rectangle = entity.parts[0].value.trackers[0].rectangle;
|
|
let x = rectangle.left;
|
|
let y = rectangle.top;
|
|
let width = rectangle.right - rectangle.left;
|
|
let height = rectangle.bottom - rectangle.top;
|
|
trackedEntity.ScreenCoords = [x, y, width, height];
|
|
if (!this.checkOldEntity(trackedEntity, prevUpdatedEntities)) {
|
|
this.detectedEntities.push(trackedEntity);
|
|
}
|
|
else {
|
|
this.updatedEntities.push(trackedEntity);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.lostEntities = this.checkLostEntities(prevUpdatedEntities);
|
|
}
|
|
checkOldEntity(trackedEntity, prevUpdatedEntities) {
|
|
if (prevUpdatedEntities.length > 0) {
|
|
return prevUpdatedEntities.some((entity) => {
|
|
return entity.EntityID === trackedEntity.EntityID;
|
|
});
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
checkLostEntities(prevUpdatedEntities) {
|
|
return prevUpdatedEntities.filter((prevEntity) => {
|
|
let exist = this.updatedEntities.some((entity) => {
|
|
return entity.EntityID === prevEntity.EntityID;
|
|
});
|
|
return !exist;
|
|
});
|
|
}
|
|
}
|
|
exports.default = PersonStreamSystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],88:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const uuid = require("uuid");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const nodes_1 = require("../nodes");
|
|
exports.ASSET_PATH = '/assets/';
|
|
class PhotoStreamSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.onRemoved = (node) => {
|
|
if (node.stream.isActive) {
|
|
jibo_1.jiboRef.jibo.remote.cancelAsset(node.stream.assetUrl);
|
|
}
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.engine = engine;
|
|
this.nodes = this.engine.getNodeList(nodes_1.PhotoStreamNode);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
if (node) {
|
|
let stream = node.stream;
|
|
if (!stream.isActive) {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Accepted, false);
|
|
stream.isActive = true;
|
|
const url = stream.assetUrl = exports.ASSET_PATH + uuid.v4();
|
|
jibo_1.jiboRef.jibo.remote.handleVideo(url, stream.photoType);
|
|
const response = {
|
|
Event: jibo_command_protocol_1.VideoEvents.VideoReady,
|
|
URI: url
|
|
};
|
|
node.request.addResponse(response);
|
|
}
|
|
for (node = node.next; node; node = node.next) {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Conflict, true);
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
}
|
|
exports.default = PhotoStreamSystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74,"jibo-command-protocol":undefined,"uuid":undefined}],89:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
const jibo_node_xml_1 = require("jibo-node-xml");
|
|
class PlaySystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.onAdded = (node) => {
|
|
};
|
|
this.onRemoved = (node) => {
|
|
if (node.play.activated && !node.play.completed) {
|
|
if (jibo_1.jiboRef.jibo.embodied.speech.isActive()) {
|
|
jibo_1.jiboRef.jibo.embodied.speech.stop()
|
|
.then(() => {
|
|
});
|
|
}
|
|
if (node.play.audioId) {
|
|
jibo_1.jiboRef.jibo.sound.stop(node.play.audioId);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.engine = engine;
|
|
this.nodes = this.engine.getNodeList(nodes_1.PlayNode);
|
|
for (let node = this.nodes.head; node; node = node.next) {
|
|
this.onAdded(node);
|
|
}
|
|
this.nodes.nodeAdded.add(this.onAdded);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
for (node; node; node = node.next) {
|
|
let play = node.play;
|
|
if (!play.activated) {
|
|
if (play.textInESML) {
|
|
play.activated = true;
|
|
play.audioId = this.getAudioFile(play.textInESML);
|
|
let request = node.request;
|
|
this.playESML(play).then((response) => {
|
|
play.completed = true;
|
|
request.addResponse(response, true);
|
|
});
|
|
}
|
|
else {
|
|
let code;
|
|
code = jibo_command_protocol_1.ResponseCode.BadRequest;
|
|
node.request.setAcknowledge(code, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
getAudioFile(esml) {
|
|
let esmlParsed = jibo_node_xml_1.Parser.parseXML(esml);
|
|
let allNodes = esmlParsed.gatherChildren();
|
|
if (allNodes.length === 1) {
|
|
let tagNode = esmlParsed.findFirstChildType('audio');
|
|
if (tagNode) {
|
|
let path = tagNode.getAttribute('path');
|
|
if (path) {
|
|
return String(path);
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
playESML(play) {
|
|
return new Promise((resolve) => {
|
|
let jibo = jibo_1.jiboRef.jibo;
|
|
if (play.audioId) {
|
|
if (jibo.sound.exists(play.audioId)) {
|
|
jibo.sound.play(play.audioId, () => {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Stop
|
|
};
|
|
resolve(response);
|
|
});
|
|
}
|
|
else {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Error,
|
|
EventError: {
|
|
ErrorString: "No sound matching alias '" + play.audioId + "'",
|
|
ErrorCode: 2
|
|
}
|
|
};
|
|
resolve(response);
|
|
}
|
|
}
|
|
else {
|
|
jibo.embodied.speech.speak(play.textInESML)
|
|
.then(() => {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Stop
|
|
};
|
|
resolve(response);
|
|
})
|
|
.catch((err) => {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Error,
|
|
EventError: {
|
|
ErrorString: err.message ? err.message : String(err),
|
|
ErrorCode: 1
|
|
}
|
|
};
|
|
resolve(response);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
exports.default = PlaySystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74,"jibo-command-protocol":undefined,"jibo-node-xml":undefined}],90:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_1 = require("../../jibo");
|
|
class RemoteIndicatorSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.onAdded = (node) => {
|
|
let indicator = node.indicator;
|
|
indicator.maxLEDColor = this.hexToLightRing(indicator.maxHexColor);
|
|
indicator.minLEDColor = this.hexToLightRing(indicator.minHexColor);
|
|
indicator.deltaInColor[0] = indicator.maxLEDColor[0] - indicator.minLEDColor[0];
|
|
indicator.deltaInColor[1] = indicator.maxLEDColor[1] - indicator.minLEDColor[1];
|
|
indicator.deltaInColor[2] = indicator.maxLEDColor[2] - indicator.minLEDColor[2];
|
|
indicator.deltaAlpha = indicator.maxAlpha - indicator.minAlpha;
|
|
let graphic = new PIXI.Graphics();
|
|
graphic.beginFill(parseInt(indicator.dotColor));
|
|
graphic.drawCircle(0, 0, indicator.dotRadius);
|
|
let icon = new PIXI.Container();
|
|
icon.alpha = indicator.maxAlpha;
|
|
indicator.timer = indicator.duration;
|
|
indicator.lerpIsRising = true;
|
|
icon.x = jibo_1.jiboRef.jibo.face.width - indicator.horizontalOffset;
|
|
icon.y = jibo_1.jiboRef.jibo.face.height - indicator.verticalOffset;
|
|
icon.addChild(graphic);
|
|
jibo_1.jiboRef.jibo.face.views.addWatermark(icon);
|
|
node.indicator.icon = icon;
|
|
};
|
|
this.onRemoved = (node) => {
|
|
if (node.indicator.icon) {
|
|
jibo_1.jiboRef.jibo.face.views.removeWatermark();
|
|
}
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.nodes = engine.getNodeList(nodes_1.RemoteIndicatorNode);
|
|
for (let node = this.nodes.head; node; node = node.next) {
|
|
this.onAdded(node);
|
|
}
|
|
this.nodes.nodeAdded.add(this.onAdded);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
if (node) {
|
|
let indicator = node.indicator;
|
|
if (indicator.lerpIsRising) {
|
|
indicator.timer += time;
|
|
if (indicator.timer >= indicator.duration) {
|
|
indicator.timer = indicator.duration;
|
|
indicator.lerpIsRising = !indicator.lerpIsRising;
|
|
}
|
|
}
|
|
else {
|
|
indicator.timer -= time;
|
|
if (indicator.timer <= 0) {
|
|
indicator.timer = 0;
|
|
indicator.lerpIsRising = !indicator.lerpIsRising;
|
|
}
|
|
}
|
|
const lerpVal = Math.sin(indicator.timer / indicator.duration);
|
|
node.lightRing.setColors(indicator.minLEDColor[0] + (lerpVal * indicator.deltaInColor[0]), indicator.minLEDColor[1] + (lerpVal * indicator.deltaInColor[1]), indicator.minLEDColor[2] + (lerpVal * indicator.deltaInColor[2]));
|
|
indicator.icon.alpha = indicator.minAlpha +
|
|
(lerpVal * (indicator.deltaAlpha));
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
hexToLightRing(hex) {
|
|
let hexNum = /0x([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i.exec(hex);
|
|
return [parseInt(hexNum[1], 16) / 255, parseInt(hexNum[2], 16) / 255, parseInt(hexNum[3], 16) / 255];
|
|
}
|
|
}
|
|
exports.default = RemoteIndicatorSystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74}],91:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class ScreenTouchSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.screenCoordsArray = [];
|
|
this.responses = [];
|
|
}
|
|
addToEngine(engine) {
|
|
this.engine = engine;
|
|
this.nodes = this.engine.getNodeList(nodes_1.ScreenGestureNode);
|
|
document.onmousedown = this.onMouseDown.bind(this);
|
|
document.onmousemove = this.onMouseMove.bind(this);
|
|
document.onmouseup = this.onMouseUp.bind(this);
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
for (node; node; node = node.next) {
|
|
for (let response of this.responses) {
|
|
node.request.addResponse(response, false);
|
|
}
|
|
}
|
|
this.responses.length = 0;
|
|
}
|
|
onMouseDown(event) {
|
|
this.screenCoordsArray.push([event.x, event.y]);
|
|
}
|
|
onMouseMove(event) {
|
|
this.screenCoordsArray.push([event.x, event.y]);
|
|
}
|
|
onMouseUp(event) {
|
|
this.getGesture();
|
|
this.screenCoordsArray.length = 0;
|
|
}
|
|
getGesture() {
|
|
let xMax = 0;
|
|
let xMin = 1280;
|
|
let yMax = 0;
|
|
let yMin = 720;
|
|
let tolerance = 50;
|
|
let xStart = this.screenCoordsArray[0][0];
|
|
let xEnd = this.screenCoordsArray.pop()[0];
|
|
let yStart = this.screenCoordsArray[0][1];
|
|
let yEnd = this.screenCoordsArray.pop()[1];
|
|
for (let point of this.screenCoordsArray) {
|
|
if (point[0] < xMin) {
|
|
xMin = point[0];
|
|
}
|
|
if (point[0] > xMax) {
|
|
xMax = point[0];
|
|
}
|
|
if (point[1] < yMin) {
|
|
yMin = point[1];
|
|
}
|
|
if (point[1] > yMax) {
|
|
yMax = point[1];
|
|
}
|
|
}
|
|
if ((yMax - yMin) > (xMax - xMin) && (yMax - yMin) > tolerance) {
|
|
if ((yStart - yEnd) > 0) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.ScreenGestureEvents.Swipe,
|
|
Direction: jibo_command_protocol_1.SwipeDirection.Up
|
|
};
|
|
this.responses.push(response);
|
|
}
|
|
else {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.ScreenGestureEvents.Swipe,
|
|
Direction: jibo_command_protocol_1.SwipeDirection.Down
|
|
};
|
|
this.responses.push(response);
|
|
}
|
|
}
|
|
else if ((xMax - xMin) > (yMax - yMin) && (xMax - xMin) > tolerance) {
|
|
if ((xStart - yEnd) > 0) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.ScreenGestureEvents.Swipe,
|
|
Direction: jibo_command_protocol_1.SwipeDirection.Left
|
|
};
|
|
this.responses.push(response);
|
|
}
|
|
else {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.ScreenGestureEvents.Swipe,
|
|
Direction: jibo_command_protocol_1.SwipeDirection.Right
|
|
};
|
|
this.responses.push(response);
|
|
}
|
|
}
|
|
else if ((xMax - xMin) < tolerance && (yMax - yMin) < tolerance) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.ScreenGestureEvents.Tap,
|
|
Coordinate: [xEnd, yEnd]
|
|
};
|
|
this.responses.push(response);
|
|
}
|
|
}
|
|
}
|
|
exports.default = ScreenTouchSystem;
|
|
|
|
},{"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],92:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class SessionSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.onRemoved = (node) => {
|
|
node.session.storedEvents = null;
|
|
node.session.sendMethod = null;
|
|
node.session.endSessionMethod = null;
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.nodes = engine.getNodeList(nodes_1.SessionNode);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
for (node; node; node = node.next) {
|
|
if (node.next) {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Conflict, true);
|
|
}
|
|
else {
|
|
const session = node.session;
|
|
const request = node.request;
|
|
if (request.acknowledged) {
|
|
if (session.waitingOnReconnect) {
|
|
session.reconnectDuration += time;
|
|
if (session.reconnectDuration > session.reconnectTimeout) {
|
|
session.endSessionMethod(jibo_command_protocol_1.DisconnectCode.ReconnectTimeout);
|
|
request.setComplete();
|
|
}
|
|
}
|
|
else {
|
|
session.inactivityDuration += time;
|
|
if (session.inactivityDuration > session.inactivityTimeout) {
|
|
session.hasConnection = false;
|
|
session.endSessionMethod(jibo_command_protocol_1.DisconnectCode.InactivityTimeout);
|
|
request.setComplete();
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
const body = {
|
|
SessionID: session.id,
|
|
Version: request.version
|
|
};
|
|
request.setAcknowledge(jibo_command_protocol_1.ResponseCode.OK, false, body);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
exports.default = SessionSystem;
|
|
|
|
},{"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],93:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_1 = require("../../jibo");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class SetConfigSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
}
|
|
addToEngine(engine) {
|
|
this.nodes = engine.getNodeList(nodes_1.SetConfigNode);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
for (node; node; node = node.next) {
|
|
let request = node.request;
|
|
if (!request.acknowledged) {
|
|
let setConfig = node.setConfig;
|
|
this.setConfigOptions(setConfig.options).then((response) => {
|
|
request.addResponse(response, true);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
setConfigOptions(options) {
|
|
return new Promise((resolve, reject) => {
|
|
jibo_1.jiboRef.jibo.system.setMasterVolume(options.Mixer, (err) => {
|
|
if (err) {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Error,
|
|
EventError: {
|
|
ErrorString: err,
|
|
ErrorCode: 1
|
|
}
|
|
};
|
|
resolve(response);
|
|
}
|
|
else {
|
|
let response = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Stop
|
|
};
|
|
resolve(response);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
exports.default = SetConfigSystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],94:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var SystemPriorities;
|
|
(function (SystemPriorities) {
|
|
SystemPriorities[SystemPriorities["interrupt"] = 1] = "interrupt";
|
|
SystemPriorities[SystemPriorities["load"] = 2] = "load";
|
|
SystemPriorities[SystemPriorities["lps"] = 3] = "lps";
|
|
SystemPriorities[SystemPriorities["update"] = 4] = "update";
|
|
SystemPriorities[SystemPriorities["light"] = 5] = "light";
|
|
SystemPriorities[SystemPriorities["session"] = 6] = "session";
|
|
SystemPriorities[SystemPriorities["response"] = 7] = "response";
|
|
})(SystemPriorities = exports.SystemPriorities || (exports.SystemPriorities = {}));
|
|
|
|
},{}],95:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const uuid = require("uuid");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
const core_1 = require("../core");
|
|
const jibo_1 = require("../../jibo");
|
|
const nodes_1 = require("../nodes");
|
|
exports.ASSET_PATH = '/assets/';
|
|
class TakePhotoSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.onRemoved = (node) => {
|
|
if (node.photoData.isActive) {
|
|
jibo_1.jiboRef.jibo.remote.cancelAsset(node.photoData.assetUrl);
|
|
node.photoData.isActive = false;
|
|
}
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.engine = engine;
|
|
this.nodes = this.engine.getNodeList(nodes_1.TakePhotoNode);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
if (node) {
|
|
let photoData = node.photoData;
|
|
if (!photoData.isActive && !photoData.assetUrl) {
|
|
const media = jibo_1.jiboRef.jibo.media;
|
|
photoData.isActive = true;
|
|
let options = {
|
|
undistort: photoData.distortion
|
|
};
|
|
switch (photoData.camera) {
|
|
case jibo_command_protocol_1.Camera.Left:
|
|
options.camera = media.CameraID.LEFT;
|
|
break;
|
|
case jibo_command_protocol_1.Camera.Right:
|
|
options.camera = media.CameraID.RIGHT;
|
|
break;
|
|
}
|
|
switch (photoData.resolution) {
|
|
case jibo_command_protocol_1.CameraResolution.HighRes:
|
|
options.photoType = media.PhotoType.FOUR_MP;
|
|
break;
|
|
case jibo_command_protocol_1.CameraResolution.MedRes:
|
|
options.photoType = media.PhotoType.FULL;
|
|
break;
|
|
case jibo_command_protocol_1.CameraResolution.LowRes:
|
|
options.photoType = media.PhotoType.FULL;
|
|
break;
|
|
case jibo_command_protocol_1.CameraResolution.MicroRes:
|
|
options.photoType = media.PhotoType.PREVIEW;
|
|
break;
|
|
}
|
|
const activeNode = node;
|
|
jibo_1.jiboRef.jibo.media.takePhoto(options, (err, response) => {
|
|
if (!activeNode.photoData || !activeNode.photoData.isActive) {
|
|
return;
|
|
}
|
|
if (err) {
|
|
const event = {
|
|
Event: jibo_command_protocol_1.AsyncCommandEvent.Error,
|
|
EventError: {
|
|
ErrorString: err.message,
|
|
ErrorCode: 1
|
|
}
|
|
};
|
|
activeNode.request.addResponse(event, true);
|
|
return;
|
|
}
|
|
const url = photoData.assetUrl = exports.ASSET_PATH + uuid.v4();
|
|
jibo_1.jiboRef.jibo.remote.handlePhoto(url, response.url);
|
|
const event = {
|
|
Event: jibo_command_protocol_1.PhotoEvents.TakePhoto,
|
|
Name: '',
|
|
URI: url,
|
|
AngleTarget: [0, 0],
|
|
PositionTarget: [0, 0, 0]
|
|
};
|
|
activeNode.request.addResponse(event, true);
|
|
activeNode.photoData.isActive = false;
|
|
this.engine.requestUpdate();
|
|
});
|
|
}
|
|
for (node = node.next; node; node = node.next) {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Conflict, true);
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
}
|
|
exports.default = TakePhotoSystem;
|
|
|
|
},{"../../jibo":97,"../core":45,"../nodes":74,"jibo-command-protocol":undefined,"uuid":undefined}],96:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core_1 = require("../core");
|
|
const nodes_1 = require("../nodes");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
class TestSystem extends core_1.System {
|
|
constructor() {
|
|
super();
|
|
this.isBlocking = false;
|
|
this.onAdded = (node) => {
|
|
};
|
|
this.onRemoved = (node) => {
|
|
};
|
|
}
|
|
addToEngine(engine) {
|
|
this.engine = engine;
|
|
this.nodes = this.engine.getNodeList(nodes_1.TestNode);
|
|
for (let node = this.nodes.head; node; node = node.next) {
|
|
this.onAdded(node);
|
|
}
|
|
this.nodes.nodeAdded.add(this.onAdded);
|
|
this.nodes.nodeRemoved.add(this.onRemoved);
|
|
}
|
|
update(time) {
|
|
let node = this.nodes.head;
|
|
if (!this.isBlocking) {
|
|
for (node; node; node = node.next) {
|
|
}
|
|
}
|
|
else {
|
|
node = node.next;
|
|
for (node; node; node = node.next) {
|
|
node.request.setAcknowledge(jibo_command_protocol_1.ResponseCode.Conflict, true);
|
|
}
|
|
}
|
|
}
|
|
removeFromEngine(engine) {
|
|
this.nodes = null;
|
|
}
|
|
}
|
|
exports.default = TestSystem;
|
|
|
|
},{"../core":45,"../nodes":74,"jibo-command-protocol":undefined}],97:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
let _jibo;
|
|
class jiboRef {
|
|
static get jibo() {
|
|
return _jibo;
|
|
}
|
|
}
|
|
exports.jiboRef = jiboRef;
|
|
(function (jiboRef) {
|
|
function setJibo(value) {
|
|
_jibo = value;
|
|
}
|
|
jiboRef.setJibo = setJibo;
|
|
})(jiboRef = exports.jiboRef || (exports.jiboRef = {}));
|
|
|
|
},{}],98:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const jibo_log_1 = require("jibo-log");
|
|
exports.default = new jibo_log_1.Log('Jibo.Remote');
|
|
|
|
},{"jibo-log":undefined}],99:[function(require,module,exports){
|
|
"use strict";
|
|
function __export(m) {
|
|
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
}
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Ajv = require("ajv");
|
|
const ErrorFormatting_1 = require("./ErrorFormatting");
|
|
const jibo_1 = require("./jibo");
|
|
const log_1 = require("./log");
|
|
const CommandConnector_1 = require("./CommandConnector");
|
|
const CommandProxy_1 = require("./CommandProxy");
|
|
const CommandUtil_1 = require("./CommandUtil");
|
|
const CommandSessionManager_1 = require("./CommandSessionManager");
|
|
const jibo_command_protocol_1 = require("jibo-command-protocol");
|
|
__export(require("./CommandConnector"));
|
|
__export(require("./commander/components"));
|
|
var AssetsSystem_1 = require("./commander/systems/AssetsSystem");
|
|
exports.AssetsSystem = AssetsSystem_1.default;
|
|
var AttentionSystem_1 = require("./commander/systems/AttentionSystem");
|
|
exports.AttentionSystem = AttentionSystem_1.default;
|
|
var CommandSystem_1 = require("./commander/systems/CommandSystem");
|
|
exports.CommandSystem = CommandSystem_1.default;
|
|
var DisplaySystem_1 = require("./commander/systems/DisplaySystem");
|
|
exports.DisplaySystem = DisplaySystem_1.default;
|
|
var HotWordSystem_1 = require("./commander/systems/HotWordSystem");
|
|
exports.HotWordSystem = HotWordSystem_1.default;
|
|
var InterruptSystem_1 = require("./commander/systems/InterruptSystem");
|
|
exports.InterruptSystem = InterruptSystem_1.default;
|
|
var RemoteIndicatorSystem_1 = require("./commander/systems/RemoteIndicatorSystem");
|
|
exports.RemoteIndicatorSystem = RemoteIndicatorSystem_1.default;
|
|
var TestSystem_1 = require("./commander/systems/TestSystem");
|
|
exports.TestSystem = TestSystem_1.default;
|
|
var MotionStreamSystem_1 = require("./commander/systems/MotionStreamSystem");
|
|
exports.MotionStreamSystem = MotionStreamSystem_1.default;
|
|
var PersonStreamSystem_1 = require("./commander/systems/PersonStreamSystem");
|
|
exports.PersonStreamSystem = PersonStreamSystem_1.default;
|
|
var HeadTouchSystem_1 = require("./commander/systems/HeadTouchSystem");
|
|
exports.HeadTouchSystem = HeadTouchSystem_1.default;
|
|
var ListenSystem_1 = require("./commander/systems/ListenSystem");
|
|
exports.ListenSystem = ListenSystem_1.default;
|
|
var LightRingSystem_1 = require("./commander/systems/LightRingSystem");
|
|
exports.LightRingSystem = LightRingSystem_1.default;
|
|
var SessionSystem_1 = require("./commander/systems/SessionSystem");
|
|
exports.SessionSystem = SessionSystem_1.default;
|
|
var CommandUtil_2 = require("./CommandUtil");
|
|
exports.CommandUtil = CommandUtil_2.default;
|
|
const INACTIVITY_TIMEOUT = 60 * 1000;
|
|
const KEEP_ALIVE_TIMEOUT = 10 * 1000;
|
|
const RECOVERY_TIMEOUT = 20 * 1000;
|
|
class CommandLibrary {
|
|
constructor(jibo, validate = true) {
|
|
if (CommandLibrary._instance) {
|
|
log_1.default.warn('CommandLibrary Singleton has already been initialized, use CommandLibrary.instance to access');
|
|
return;
|
|
}
|
|
jibo_1.jiboRef.setJibo(jibo);
|
|
this.connect = this.connect.bind(this);
|
|
this.messageReceived = this.messageReceived.bind(this);
|
|
this.awaitReconnect = this.awaitReconnect.bind(this);
|
|
this.startSession = this.startSession.bind(this);
|
|
this.endSession = this.endSession.bind(this);
|
|
this.disconnect = this.disconnect.bind(this);
|
|
this.responseFailed = this.responseFailed.bind(this);
|
|
CommandLibrary._instance = this;
|
|
this._connections = new Map();
|
|
this._sessionManager = new CommandSessionManager_1.default();
|
|
this._validateMessages = validate;
|
|
this.createValidators();
|
|
this._validVersions = Object.keys(jibo_command_protocol_1.ProtocolVersions).map(key => (jibo_command_protocol_1.ProtocolVersions[key]));
|
|
}
|
|
static createInstance(jibo, validate = true) {
|
|
CommandLibrary._instance = new CommandLibrary(jibo);
|
|
}
|
|
static get instance() {
|
|
if (!CommandLibrary._instance) {
|
|
log_1.default.info("CommandLibrary hasn't been constructed, call constructor first.");
|
|
}
|
|
return CommandLibrary._instance;
|
|
}
|
|
destroy() {
|
|
CommandLibrary._instance = null;
|
|
this._connections = null;
|
|
this._sessionManager = null;
|
|
this._activeConnection = null;
|
|
this._activeProxy = null;
|
|
this._activeVersion = null;
|
|
this._activeSourceId = '';
|
|
this._validator = null;
|
|
this._validators = null;
|
|
}
|
|
createCommandConnector(id, startReady = true) {
|
|
let commandConnect = this._connections.get(id);
|
|
if (!commandConnect) {
|
|
commandConnect = new CommandConnector_1.CommandConnector(id, this, startReady);
|
|
this._connections.set(id, commandConnect);
|
|
}
|
|
return commandConnect;
|
|
}
|
|
removeCommandConnector(connector) {
|
|
if (this._activeConnection === connector) {
|
|
this.disconnect(jibo_command_protocol_1.DisconnectCode.NewConnection);
|
|
}
|
|
this._connections.delete(connector.id);
|
|
}
|
|
removeCommandConnectorById(id) {
|
|
let connector = this._connections.get(id);
|
|
if (connector) {
|
|
this.removeCommandConnector(connector);
|
|
}
|
|
}
|
|
connect(commandConnection) {
|
|
let permissions = this.createPermissionsFromACO(commandConnection.aco);
|
|
const sourceId = commandConnection.aco.sourceId;
|
|
if (!this.isValidVersion(permissions.version)) {
|
|
log_1.default.info(`version not accepted ${permissions.version}, connection denied`);
|
|
return;
|
|
}
|
|
if (this._activeConnection) {
|
|
if (this._activeConnection === commandConnection) {
|
|
if (this._activeConnection.isConnected) {
|
|
if (this._activeSourceId !== sourceId) {
|
|
log_1.default.info('source ids differ, new connection interrupts previous connection');
|
|
this.disconnect(jibo_command_protocol_1.DisconnectCode.NewConnection);
|
|
}
|
|
else {
|
|
log_1.default.info('attempting connection to same source, but already connected');
|
|
return;
|
|
}
|
|
}
|
|
else if (this._activeConnection.isAwaitingReconnect) {
|
|
if (this._activeSourceId !== sourceId) {
|
|
log_1.default.info('source ids differ, new connection interrupts previous connection');
|
|
this.disconnect(jibo_command_protocol_1.DisconnectCode.NewConnection);
|
|
}
|
|
else {
|
|
log_1.default.info('attempting reconnection from same source, wait for session request to restore current session');
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
log_1.default.info(`interrupting connector ${this._activeConnection.id} with connection from connector ${commandConnection.id}`);
|
|
this.disconnect(jibo_command_protocol_1.DisconnectCode.NewConnection);
|
|
}
|
|
}
|
|
let commandProxy = new CommandProxy_1.default();
|
|
commandProxy.onMessage.on(this.messageReceived);
|
|
commandProxy.onAwaitReconnect.on(this.awaitReconnect);
|
|
commandProxy.onEndSession.on(this.endSession);
|
|
commandProxy.onResponseFailed.on(this.responseFailed);
|
|
commandConnection.applyProxy(commandProxy);
|
|
this._activeProxy = commandProxy;
|
|
this._activeConnection = commandConnection;
|
|
this._activeVersion = permissions.version;
|
|
this._activeSourceId = sourceId;
|
|
this._validator = this._validators.get(this._activeVersion);
|
|
this._activeConnection.version = permissions.version;
|
|
this._sessionManager.permissions = permissions;
|
|
}
|
|
awaitUpdate() {
|
|
return new Promise((resolve) => {
|
|
let engine = this.getEngine();
|
|
if (engine) {
|
|
engine.updateComplete.addOnce(resolve);
|
|
}
|
|
else {
|
|
resolve();
|
|
}
|
|
});
|
|
}
|
|
getEngine() {
|
|
if (this._sessionManager.session) {
|
|
return this._sessionManager.session.commandManager.entityManager.engine;
|
|
}
|
|
return null;
|
|
}
|
|
set robotId(robotId) {
|
|
CommandUtil_1.default.robotId = robotId;
|
|
}
|
|
messageReceived(data) {
|
|
if (this._validateMessages) {
|
|
if (!this.validateProtocol(data)) {
|
|
return;
|
|
}
|
|
if (!this.checkVersion(data)) {
|
|
return;
|
|
}
|
|
}
|
|
const sessionMismatch = this._sessionManager.checkSessionMismatch(CommandUtil_1.default.getSessionId(data, this._activeVersion));
|
|
if (this._sessionManager.checkSessionCommand(data)) {
|
|
if (sessionMismatch) {
|
|
log_1.default.info('messageReceived : new session causing previous session end', data);
|
|
this._sessionManager.endSession();
|
|
}
|
|
if (this._activeConnection.isReady) {
|
|
this.startSession();
|
|
}
|
|
else {
|
|
this._activeConnection.onReady.on(this.startSession);
|
|
}
|
|
return;
|
|
}
|
|
else if (!this._sessionManager.session) {
|
|
this.sendAcknowledgement(data, jibo_command_protocol_1.ResponseCode.ServiceUnavailable);
|
|
return;
|
|
}
|
|
if (sessionMismatch) {
|
|
log_1.default.info('messageReceived : session mismatch for data', data);
|
|
this.sendAcknowledgement(data, jibo_command_protocol_1.ResponseCode.Forbidden);
|
|
return;
|
|
}
|
|
this._sessionManager.resetInactivityTimeout();
|
|
this._sessionManager.startCommand(data);
|
|
}
|
|
responseFailed(message) {
|
|
if (!this._sessionManager.handleFailedResponse(message)) {
|
|
}
|
|
}
|
|
startSession() {
|
|
this._activeConnection.onReady.off(this.startSession);
|
|
this._sessionManager.startSession(this._activeProxy.response, this.disconnect);
|
|
this._activeProxy.sessionStarted(this._sessionManager.sessionId);
|
|
}
|
|
awaitReconnect() {
|
|
if (!this._sessionManager.handleDisconnection()) {
|
|
this.disconnect(jibo_command_protocol_1.DisconnectCode.ReconnectError);
|
|
}
|
|
}
|
|
disconnect(code) {
|
|
this._activeConnection.disconnect(code);
|
|
}
|
|
endSession() {
|
|
this._sessionManager.endSession();
|
|
this._activeProxy = null;
|
|
if (this._activeConnection) {
|
|
this._activeConnection.onReady.off(this.startSession);
|
|
this._activeConnection = null;
|
|
}
|
|
}
|
|
createPermissionsFromACO(aco) {
|
|
let permissions;
|
|
if (aco.version === 'v0') {
|
|
log_1.default.warn(`Protocol version ${aco.version} is no longer a valid version, use 1.0 instead.`);
|
|
aco.version = jibo_command_protocol_1.ProtocolVersions.v1;
|
|
}
|
|
if (aco.version === jibo_command_protocol_1.ProtocolVersions.v1) {
|
|
permissions = {
|
|
version: aco.version,
|
|
attention: aco.commandSet.indexOf(jibo_command_protocol_1.CommandTypes.SetAttention) !== -1,
|
|
display: aco.commandSet.indexOf(jibo_command_protocol_1.CommandTypes.Display) !== -1,
|
|
getConfig: aco.commandSet.indexOf(jibo_command_protocol_1.CommandTypes.GetConfig) !== -1,
|
|
fetchAsset: aco.commandSet.indexOf(jibo_command_protocol_1.CommandTypes.FetchAsset) !== -1,
|
|
listen: aco.commandSet.indexOf(jibo_command_protocol_1.CommandTypes.Listen) !== -1,
|
|
lookAt: aco.commandSet.indexOf(jibo_command_protocol_1.CommandTypes.LookAt) !== -1,
|
|
video: aco.commandSet.indexOf(jibo_command_protocol_1.CommandTypes.Video) !== -1,
|
|
play: aco.commandSet.indexOf(jibo_command_protocol_1.CommandTypes.Say) !== -1,
|
|
setConfig: aco.commandSet.indexOf(jibo_command_protocol_1.CommandTypes.SetConfig) !== -1,
|
|
takePhoto: aco.commandSet.indexOf(jibo_command_protocol_1.CommandTypes.TakePhoto) !== -1,
|
|
personStream: aco.streamSet.indexOf(jibo_command_protocol_1.StreamTypes.Entity) !== -1,
|
|
motionStream: aco.streamSet.indexOf(jibo_command_protocol_1.StreamTypes.Motion) !== -1,
|
|
hotWord: aco.streamSet.indexOf(jibo_command_protocol_1.StreamTypes.HotWord) !== -1,
|
|
screenGesture: aco.streamSet.indexOf(jibo_command_protocol_1.StreamTypes.ScreenGesture) !== -1,
|
|
headTouch: aco.streamSet.indexOf(jibo_command_protocol_1.StreamTypes.HeadTouch) !== -1,
|
|
keepAliveTimeout: aco.keepAliveTimeout || KEEP_ALIVE_TIMEOUT,
|
|
recoveryTimeout: aco.recoveryTimeout || RECOVERY_TIMEOUT,
|
|
hideRemoteIndicator: !(aco.remoteConfig && !aco.remoteConfig.hideVisualCue),
|
|
inactivityTimeout: aco.remoteConfig.inactivityTimeout || INACTIVITY_TIMEOUT,
|
|
test: aco.test,
|
|
};
|
|
}
|
|
else {
|
|
log_1.default.error(`Protocol version not supported: ${aco.version}`);
|
|
return null;
|
|
}
|
|
return permissions;
|
|
}
|
|
createValidators() {
|
|
this._validators = new Map();
|
|
let schema = require('@types/jibo-command-protocol/commandSchema.json');
|
|
let ajv = new Ajv({ allErrors: true });
|
|
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
|
|
let validator = ajv.compile(schema);
|
|
this._validators.set(jibo_command_protocol_1.ProtocolVersions.v1, validator);
|
|
}
|
|
validateProtocol(data) {
|
|
if (!this._validator(data)) {
|
|
let error = ErrorFormatting_1.formatCommandErrors(this._validator.errors);
|
|
log_1.default.warn('Invalid protocol: ', error);
|
|
this.sendAcknowledgement(data, jibo_command_protocol_1.ResponseCode.BadRequest, error);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
checkVersion(data) {
|
|
const version = CommandUtil_1.default.getVersion(data);
|
|
if (version !== this._activeVersion) {
|
|
log_1.default.warn('Version conflict, version given: ' + version);
|
|
this.sendAcknowledgement(data, this.isValidVersion(version) ? jibo_command_protocol_1.ResponseCode.VersionConflict : jibo_command_protocol_1.ResponseCode.VersionNotSupported);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
isValidVersion(version) {
|
|
return this._validVersions.indexOf(version) !== -1;
|
|
}
|
|
sendAcknowledgement(command, code, data) {
|
|
const response = CommandUtil_1.default.createAcknowledgement(this._activeVersion, CommandUtil_1.default.getTransactionId(command, this._activeVersion), CommandUtil_1.default.getSessionId(command, this._activeVersion), code, data);
|
|
this._activeProxy.response(response);
|
|
}
|
|
}
|
|
exports.default = CommandLibrary;
|
|
|
|
},{"./CommandConnector":1,"./CommandProxy":2,"./CommandSessionManager":4,"./CommandUtil":5,"./ErrorFormatting":6,"./commander/components":34,"./commander/systems/AssetsSystem":75,"./commander/systems/AttentionSystem":76,"./commander/systems/CommandSystem":77,"./commander/systems/DisplaySystem":78,"./commander/systems/HeadTouchSystem":80,"./commander/systems/HotWordSystem":81,"./commander/systems/InterruptSystem":82,"./commander/systems/LightRingSystem":83,"./commander/systems/ListenSystem":84,"./commander/systems/MotionStreamSystem":86,"./commander/systems/PersonStreamSystem":87,"./commander/systems/RemoteIndicatorSystem":90,"./commander/systems/SessionSystem":92,"./commander/systems/TestSystem":96,"./jibo":97,"./log":98,"@types/jibo-command-protocol/commandSchema.json":undefined,"ajv":undefined,"ajv/lib/refs/json-schema-draft-04.json":undefined,"jibo-command-protocol":undefined}]},{},[99])(99)
|
|
});
|
|
|
|
//# sourceMappingURL=jibo-command-library.js.map
|