Files
Zos/Skills/@be/be/node_modules/jibo/lib/jibo.js

21932 lines
832 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.jibo = 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 Orchestrator = require("orchestrator");
const ServiceClients = require("jibo-service-clients");
const jibo_loader_1 = require("jibo-loader");
const GlobalPerfTimer_1 = require("./utils/perf/GlobalPerfTimer");
const SerialTimer_1 = require("./utils/perf/SerialTimer");
const mim_1 = require("./bt/mim");
const Analytics_1 = require("./bt/mim/analytics/Analytics");
const electron_1 = require("./utils/electron");
const jibo_kb_1 = require("jibo-kb");
const RemoteService_1 = require("./services/remote/RemoteService");
const log_1 = require("./log");
const RunMode = {
SIMULATOR: "SIMULATOR",
REMOTELY: "REMOTELY",
ON_ROBOT: "ON_ROBOT",
UNIT_TESTS: "UNIT_TESTS"
};
class Runtime {
constructor(classes) {
if (Runtime._instance) {
throw new Error("Jibo Singleton may only be initialized once.");
}
Runtime._instance = this;
this.utils = classes.utils;
this.services = classes.services;
this.RunMode = RunMode;
this.system = ServiceClients.system;
this.kb = new jibo_kb_1.KnowledgeBase();
this.lps = ServiceClients.lps;
this.ics = ServiceClients.ics;
this.tts = ServiceClients.tts;
this.timer = new classes.utils.Timer();
this.log = log_1.default;
this.performance = ServiceClients.performance;
this.analytics = new Analytics_1.default();
this.wifi = ServiceClients.wifi;
this.errors = ServiceClients.errors;
this.secureTransferService = ServiceClients.secureTransferService;
this.web = ServiceClients.web;
this.scheduler = ServiceClients.scheduler;
this.globalEvents = new classes.services.GlobalEvents();
this.remote = new RemoteService_1.default();
if (electron_1.default) {
this.bt = new classes.bt.Factory(classes.bt);
this.flow = new classes.flow.FlowExecutorFactory(classes.flow);
PIXI.utils.skipHello();
this.face = new classes.rendering.FaceRenderer(this.timer);
this.rendering = classes.rendering;
this.behaviorEmitter = new classes.bt.BehaviorEmitter();
}
this.session = new classes.services.SessionManager();
this.systemManager = ServiceClients.systemManager;
this.options = null;
this._installPlugins();
this.mim = mim_1.MimManager.instance;
}
static registerPlugin(pluginClass, id, options) {
options = Object.assign({
depends: [],
api: false,
name: id,
electron: false
}, options || {});
const plugin = {
pluginClass,
id,
name: options.name,
api: options.api,
depends: options.depends,
electron: options.electron,
installed: false,
initialized: false
};
Runtime._plugins.push(plugin);
return plugin;
}
init(options, callback) {
if (Runtime.isInitializing || Runtime.isInitialized) {
throw new Error('Jibo may only be initialized once.');
}
this.initTimer = new SerialTimer_1.default("initNetworkServices", GlobalPerfTimer_1.default.get());
if (typeof options === 'function') {
callback = options;
options = null;
}
else if (typeof options === 'string' || options instanceof HTMLElement) {
options = { display: options };
}
this.options = Object.assign({
display: null
}, options || {});
if (typeof callback === 'function') {
this._init((err) => {
this.initTimer.stop();
if (electron_1.default) {
Runtime.ipcRenderer.send('init-done');
}
callback(err);
});
}
}
get runMode() {
let runMode = process.env.runMode || process.env.RUNMODE;
if (!runMode && process.platform === 'linux' && process.arch === 'arm') {
runMode = RunMode.ON_ROBOT;
}
return runMode;
}
get plugins() {
return Runtime._plugins;
}
_init(callback) {
Runtime.isInitializing = true;
if (electron_1.default) {
Runtime.ipcRenderer.send('get-context');
}
this._initPlugins((err) => {
GlobalPerfTimer_1.default.get().stop();
if (err) {
console.error(err);
}
else {
if (this.options.analytics) {
this.analytics = this.options.analytics;
}
if (electron_1.default) {
let display = this.options.display;
if (display) {
if (typeof display === "string") {
display = document.getElementById(display);
}
if (!display) {
throw new Error("Display canvas element is invalid");
}
Runtime.instance.face.init(display);
}
}
Runtime.isInitialized = true;
this.timer.start();
}
callback(err);
});
}
_installPlugins() {
const orc = new Orchestrator();
const plugins = [];
Runtime._plugins.forEach((plugin) => {
if (plugin.installed || (plugin.electron && !electron_1.default)) {
return;
}
plugins.push(plugin.id);
orc.add(plugin.id, plugin.depends, (done) => {
plugin.installed = true;
plugin.instance = new plugin.pluginClass();
if (plugin.api) {
this[plugin.name] = plugin.instance.api || plugin.instance;
}
done();
});
});
if (plugins.length) {
orc.add('end', plugins, (done) => {
done();
});
orc.start('end');
}
}
_initPlugins(done) {
const orc = new Orchestrator();
const plugins = [];
Runtime._plugins.forEach((plugin) => {
if (plugin.initialized || (plugin.electron && !electron_1.default)) {
return;
}
plugins.push(plugin.id);
orc.add(plugin.id, plugin.depends, (callback) => {
let startTime = Date.now();
this.log.info(`Starting to initialize plugin '${plugin.id}'`);
plugin.instance.init((err, api) => {
this.log.info(`done initializing ${plugin.id} in ${Date.now() - startTime} ms`);
plugin.initialized = true;
if (api) {
this[plugin.name] = api;
}
callback(err);
});
});
});
if (!plugins.length) {
return done();
}
orc.add('end', plugins, (done) => {
done();
});
orc.start('end', (error) => {
if (error) {
console.error('Error: ' + error);
done(error);
}
else {
done();
}
});
}
static get instance() {
return Runtime._instance;
}
static get ipcRenderer() {
if (!Runtime._ipcRenderer && electron_1.default) {
Runtime._ipcRenderer = require('electron').ipcRenderer;
}
return Runtime._ipcRenderer;
}
}
Runtime.isInitializing = false;
Runtime.isInitialized = false;
Runtime.electron = electron_1.default;
Runtime._ipcRenderer = null;
Runtime._plugins = [];
Runtime.registerPlugin(jibo_loader_1.LoaderPlugin, 'loader', {
api: true
});
exports.default = Runtime;
},{"./bt/mim":63,"./bt/mim/analytics/Analytics":57,"./log":75,"./services/remote/RemoteService":190,"./utils/electron":205,"./utils/perf/GlobalPerfTimer":209,"./utils/perf/SerialTimer":212,"electron":undefined,"jibo-kb":undefined,"jibo-loader":undefined,"jibo-service-clients":undefined,"orchestrator":undefined}],2:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Status_1 = require("./Status");
class BaseElement {
constructor(options, defaultOptions) {
this._currentStatus = Status_1.default.INVALID;
options = options || {};
defaultOptions = defaultOptions || {};
this.options = Object.assign({
name: "",
emitter: null,
blackboard: null,
assetPack: ""
}, defaultOptions, options);
this._currentStatus = Status_1.default.INVALID;
this.blackboard = this.options.blackboard;
this.emitter = this.options.emitter;
this.assetPack = this.options.assetPack || "";
}
get name() {
return this.options.name;
}
get currentStatus() {
return this._currentStatus;
}
stop() {
return Promise.resolve();
}
destroy() {
this.options = null;
this.blackboard = null;
this.emitter = null;
this.assetPack = null;
this._currentStatus = null;
}
stopAndDestroy() {
return this.stop().catch(() => { }).then(() => {
this.destroy();
});
}
}
exports.default = BaseElement;
},{"./Status":10}],3:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Status_1 = require("./Status");
const BaseElement_1 = require("./BaseElement");
class Behavior extends BaseElement_1.default {
constructor(options, defaultOptions = {}) {
super(options, Object.assign({
decorators: []
}, defaultOptions || {}));
this.decorators = this.options.decorators;
this.parent = null;
this.waitDecorators = [];
this.waitDecoratorsLength = 0;
}
destroy() {
if (this._decorators) {
this._decorators.forEach((decorator) => {
decorator.destroy();
});
}
this.parent = null;
this._decorators = null;
this.waitDecorators = null;
super.destroy();
}
get decorators() { return this._decorators; }
set decorators(decorators) {
this._decorators = decorators;
if (decorators) {
decorators.forEach((decorator) => {
decorator.behavior = this;
});
}
}
start() {
return true;
}
_pause() {
this.previousStatus = this._currentStatus;
this._currentStatus = Status_1.default.PAUSED;
}
_unpause() {
this._currentStatus = this.previousStatus;
}
_start() {
if (this._currentStatus === Status_1.default.IN_PROGRESS) {
return false;
}
this.waitDecorators.length = this.waitDecoratorsLength = 0;
if (this._decorators.length) {
for (let i = 0; i < this._decorators.length; i++) {
let success = this._decorators[i]._start();
if (success === Status_1.default.WAIT) {
this.waitDecorators.push(this._decorators[i]);
this.waitDecoratorsLength++;
}
else if (!success) {
this._currentStatus = Status_1.default.FAILED;
this._stop();
return false;
}
}
}
if (this.waitDecorators.length === 0) {
let success = this.start();
this._currentStatus = success ? Status_1.default.IN_PROGRESS : Status_1.default.FAILED;
if (!success) {
this._stop();
}
return success;
}
else {
this._currentStatus = Status_1.default.IN_PROGRESS;
return true;
}
}
_stop() {
const promises = [];
if (this._decorators.length) {
this._decorators.forEach(function (decorator) {
if (decorator.currentStatus === Status_1.default.IN_PROGRESS) {
promises.push(decorator._stop());
}
});
}
if (this._currentStatus === Status_1.default.IN_PROGRESS) {
this._currentStatus = Status_1.default.INTERRUPTED;
promises.push(this.stop());
}
if (promises.length === 0) {
return Promise.resolve();
}
else if (promises.length === 1) {
return promises[0];
}
return Promise.all(promises);
}
_update() {
if (this.waitDecoratorsLength > 0) {
for (let i = 0; i < this.waitDecorators.length; i++) {
if (this.waitDecorators[i]) {
let status = this.waitDecorators[i]._update(this._currentStatus);
if (status !== Status_1.default.WAIT) {
this.waitDecoratorsLength--;
this.waitDecorators[i] = null;
}
}
}
if (this.waitDecoratorsLength === 0) {
let success = this.start();
this._currentStatus = success ? Status_1.default.IN_PROGRESS : Status_1.default.FAILED;
if (!success) {
this._stop();
}
}
else {
return Status_1.default.IN_PROGRESS;
}
}
if (this._currentStatus === Status_1.default.PAUSED) {
let status = this._currentStatus;
if (this._decorators.length) {
for (let i = 0; i < this._decorators.length; i++) {
status = this._decorators[i]._update(this._currentStatus);
if (status !== Status_1.default.IN_PROGRESS) {
this._stop();
return status;
}
}
}
return this._currentStatus;
}
else if (this._currentStatus === Status_1.default.IN_PROGRESS) {
let tempStatus = this.update();
if (tempStatus !== Status_1.default.IN_PROGRESS) {
this._currentStatus = tempStatus;
this._stop();
}
if (this._decorators.length) {
for (let i = 0; i < this._decorators.length; i++) {
tempStatus = this._decorators[i]._update(this._currentStatus);
if (tempStatus !== Status_1.default.IN_PROGRESS) {
this._stop();
this._currentStatus = tempStatus;
return this._currentStatus;
}
}
}
return this._currentStatus;
}
else if (this._currentStatus === Status_1.default.SUCCEEDED) {
return Status_1.default.SUCCEEDED;
}
else {
return Status_1.default.FAILED;
}
}
}
exports.default = Behavior;
},{"./BaseElement":2,"./Status":10}],4:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
class BehaviorEmitter extends events_1.EventEmitter {
constructor() {
super();
}
}
exports.default = BehaviorEmitter;
},{"events":undefined}],5:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
class BehaviorTree extends events_1.EventEmitter {
constructor(root, blackboard, notepad, result, emitter) {
super();
this.root = root;
this.blackboard = blackboard;
this.notepad = notepad;
this.result = result;
this.emitter = emitter;
}
get currentStatus() {
return this.root.currentStatus;
}
start() {
this.emit('start');
return this.root._start();
}
stop() {
const rtn = this.root._stop();
this.emit('stop');
return rtn;
}
pause() {
this.root._pause();
this.emit('pause');
}
unpause() {
this.root._unpause();
this.emit('unpause');
}
update() {
return this.root._update();
}
destroy() {
this.emit('destroy');
this.removeAllListeners();
if (this.root) {
this.root.destroy();
}
this.root = null;
this.blackboard = null;
this.result = null;
this.notepad = null;
if (this.emitter) {
this.emitter.removeAllListeners();
}
this.emitter = null;
}
stopAndDestroy() {
return this.stop().catch(() => { }).then(() => {
this.destroy();
});
}
}
exports.default = BehaviorTree;
},{"events":undefined}],6:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Blackboard {
}
exports.default = Blackboard;
},{}],7:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Status_1 = require("./Status");
const BaseElement_1 = require("./BaseElement");
class Decorator extends BaseElement_1.default {
constructor(options, defaultOptions) {
super(options, defaultOptions);
this.behavior = null;
}
start() {
return true;
}
destroy() {
this.behavior = null;
super.destroy();
}
_start() {
let success = this.start();
this._currentStatus = success ? Status_1.default.IN_PROGRESS : Status_1.default.FAILED;
return success;
}
_stop() {
this._currentStatus = Status_1.default.INTERRUPTED;
return this.stop();
}
_update(result) {
this._currentStatus = this.update(result);
return this._currentStatus;
}
}
exports.default = Decorator;
},{"./BaseElement":2,"./Status":10}],8:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const callsite = require("callsite");
const Runtime_1 = require("../Runtime");
const BehaviorEmitter_1 = require("./BehaviorEmitter");
const Blackboard_1 = require("./Blackboard");
const BehaviorTree_1 = require("./BehaviorTree");
const Status_1 = require("./Status");
const log_1 = require("./log");
class Factory {
constructor(bt) {
this._behaviors = {};
this.Status = Status_1.default;
this.blackboard = new Blackboard_1.default();
this.emitter = new BehaviorEmitter_1.default();
Object.assign(this, bt);
this.registerCore();
}
register(name, namespace, classRef) {
let ns = this._behaviors[namespace];
if (!ns) {
ns = this._behaviors[namespace] = {};
}
ns[name] = classRef;
}
registerCore() {
const namespace = 'core';
const all = Object.assign({}, this.behaviors, this.decorators);
for (let name in all) {
this.register(name, namespace, all[name]);
}
}
getBehaviorConstructor(behavior, namespace) {
let ns = this._behaviors[namespace || 'core'];
if (ns) {
return ns[behavior];
}
}
getBlackboard() {
return this.blackboard;
}
getEmitter() {
return this.emitter;
}
create(uri, overrides = {}) {
let createTree;
if (typeof uri === 'string') {
let calleeDirname = callsite()[1].getFileName();
let treePath = this.getFilePathFromCallee(calleeDirname, uri);
try {
createTree = require(treePath);
}
catch (e) {
console.error(e);
throw new Error(uri + ' is not a valid behavior tree');
}
}
else {
createTree = uri;
}
let blackboard = overrides.blackboard || this.blackboard;
let notepad = overrides.notepad || {};
let result = {};
let tree = createTree(blackboard, notepad, result, this.emitter);
let map = {};
let i, j, node, id;
let ids = Object.keys(tree);
let namespace = "", ns;
for (i = 0; i < ids.length; i++) {
id = ids[i];
if (id === 'meta') {
continue;
}
node = tree[id];
if (typeof node === 'function') {
tree[id] = node.bind({})({});
}
}
for (i = 0; i < ids.length; i++) {
id = ids[i];
if (id === 'meta') {
continue;
}
node = tree[id];
namespace = node['asset-pack'] || "core";
if (namespace === "project" && overrides.assetPack) {
namespace = overrides.assetPack;
}
ns = this._behaviors[namespace];
if (!ns) {
throw new Error("Namespace '" + namespace + "' is not registered with the behavior factory");
}
else if (!ns[node.class]) {
throw new Error("Behavior '" + node.class + "' in namespace '" + namespace + "' is not registered with the behavior factory");
}
else if (Array.isArray(node.args)) {
throw new Error("Behavior '" + node.class + "' options are invalid, re-run behaviorify");
}
let Constructor = ns[node.class];
let options = Object.assign({
name: node.name,
emitter: this.emitter,
blackboard: blackboard,
assetPack: overrides.assetPack || ""
}, node.options || {});
log_1.default.debug('Constructing beh', node.class, node.name, node.options);
map[id] = new Constructor(options);
}
let possibleRoots = {};
for (i = 0; i < ids.length; i++) {
id = ids[i];
if (id === 'meta') {
continue;
}
node = tree[id];
if (!node.parent) {
possibleRoots[node.id] = true;
}
if (node.skipped) {
delete possibleRoots[node.id];
continue;
}
let behavior = map[node.id];
if (node.children) {
let children = [];
for (j = 0; j < node.children.length; j++) {
let childId = node.children[j];
let child = map[childId];
if (!tree[childId].skipped) {
children.push(child);
}
}
behavior.children = children;
}
if (node.decorators) {
let decorators = [];
for (j = 0; j < node.decorators.length; j++) {
let decorator = map[node.decorators[j]];
delete possibleRoots[node.decorators[j]];
if (!tree[node.decorators[j]].skipped) {
decorators.push(decorator);
}
}
if (decorators.length > 0) {
behavior.decorators = decorators;
}
}
}
let root = map[Object.keys(possibleRoots)[0]];
return new BehaviorTree_1.default(root, this.blackboard, notepad, result, this.emitter);
}
run(uri, overrides = {}, onFinishedCallback = null) {
if (typeof (overrides) === "function") {
onFinishedCallback = overrides;
overrides = {};
}
if (typeof uri === 'string') {
let calleeDirname = callsite()[1].getFileName();
uri = this.getFilePathFromCallee(calleeDirname, uri);
}
const behaviorTree = this.create(uri, overrides);
function doUpdate(elapsed) {
if (behaviorTree.currentStatus === Status_1.default.IN_PROGRESS) {
behaviorTree.update();
}
else if (behaviorTree.currentStatus === Status_1.default.FAILED ||
behaviorTree.currentStatus === Status_1.default.SUCCEEDED ||
behaviorTree.currentStatus === Status_1.default.INTERRUPTED) {
stopUpdate();
}
}
function clearTimer() {
Runtime_1.default.instance.timer.removeListener('update', doUpdate);
}
function stopUpdate() {
clearTimer();
if (onFinishedCallback) {
let callback = onFinishedCallback;
onFinishedCallback = null;
callback(behaviorTree.currentStatus);
}
}
function startUpdate() {
clearTimer();
Runtime_1.default.instance.timer.on('update', doUpdate);
}
behaviorTree.on('start', startUpdate);
behaviorTree.on('stop', stopUpdate);
behaviorTree.on('destroy', clearTimer);
behaviorTree.start();
return behaviorTree;
}
getFilePathFromCallee(calleeDirname, uri) {
let filePath;
uri = uri.substr(0, uri.lastIndexOf(path.parse(uri).ext));
if (!path.isAbsolute(uri)) {
if (calleeDirname.indexOf('file://') === 0) {
calleeDirname = calleeDirname.substr(7);
}
filePath = path.join(calleeDirname, '..', uri);
}
else {
filePath = uri;
}
return filePath;
}
}
exports.default = Factory;
},{"../Runtime":1,"./BehaviorEmitter":4,"./BehaviorTree":5,"./Blackboard":6,"./Status":10,"./log":49,"callsite":undefined,"path":undefined}],9:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Status_1 = require("./Status");
const Behavior_1 = require("./Behavior");
class ParentBehavior extends Behavior_1.default {
constructor(options, defaultOptions) {
super(options, Object.assign({
children: []
}, defaultOptions || {}));
this.children = this.options.children;
}
destroy() {
this._children.forEach((child) => {
child.destroy();
});
this._children = null;
super.destroy();
}
get children() { return this._children; }
set children(children) {
for (let i = 0; i < children.length; i++) {
children[i].parent = this;
}
this._children = children;
}
_stop() {
const promises = [];
if (this.children.length) {
this.children.forEach(function (child) {
if (child.currentStatus === Status_1.default.IN_PROGRESS) {
promises.push(child._stop());
}
});
}
promises.push(super._stop());
if (promises.length === 0) {
return Promise.resolve();
}
else if (promises.length === 1) {
return promises[0];
}
return Promise.all(promises);
}
}
exports.default = ParentBehavior;
},{"./Behavior":3,"./Status":10}],10:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Status;
(function (Status) {
Status[Status["SUCCEEDED"] = 0] = "SUCCEEDED";
Status[Status["FAILED"] = 1] = "FAILED";
Status[Status["INTERRUPTED"] = 2] = "INTERRUPTED";
Status[Status["IN_PROGRESS"] = 3] = "IN_PROGRESS";
Status[Status["INVALID"] = 4] = "INVALID";
Status[Status["PAUSED"] = 5] = "PAUSED";
Status[Status["WAIT"] = 6] = "WAIT";
})(Status || (Status = {}));
exports.default = Status;
},{}],11:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
const Runtime_1 = require("../../Runtime");
class Blink extends Behavior_1.default {
start() {
Runtime_1.default.instance.expression.blink();
return true;
}
update() {
return Status_1.default.SUCCEEDED;
}
}
exports.default = Blink;
},{"../../Runtime":1,"../Behavior":3,"../Status":10}],12:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
class ExecuteScript extends Behavior_1.default {
start() {
this.options.exec();
return true;
}
update() {
return Status_1.default.SUCCEEDED;
}
}
exports.default = ExecuteScript;
},{"../Behavior":3,"../Status":10}],13:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
class ExecuteScriptAsync extends Behavior_1.default {
constructor(options) {
super(options);
this.status = Status_1.default.INVALID;
}
start() {
this.status = Status_1.default.IN_PROGRESS;
this.options.exec(this.onSucceed.bind(this), this.onFail.bind(this));
return true;
}
update() {
return this.status;
}
onSucceed() {
this.status = Status_1.default.SUCCEEDED;
}
onFail() {
this.status = Status_1.default.FAILED;
}
}
exports.default = ExecuteScriptAsync;
},{"../Behavior":3,"../Status":10}],14:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
const Runtime_1 = require("../../Runtime");
class LookAt extends Behavior_1.default {
constructor(options) {
super(options, {
isContinuous: false
});
this.status = Status_1.default.INVALID;
}
start() {
this.status = Status_1.default.IN_PROGRESS;
let position = this.options.getTarget();
Runtime_1.default.instance.expression.acquireTarget({
position
}).then((handle) => {
this.handle = handle;
return this.handle.promise;
}).then((status) => {
this.handle = undefined;
this.status = Status_1.default.SUCCEEDED;
});
return true;
}
stop() {
if (this.handle) {
return this.handle.cancel();
}
else {
return Promise.resolve();
}
}
update() {
return this.status;
}
destroy() {
super.destroy();
this.handle = undefined;
}
}
exports.default = LookAt;
},{"../../Runtime":1,"../Behavior":3,"../Status":10}],15:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
const Runtime_1 = require("../../Runtime");
const Mim_1 = require("./Mim");
const GenerateListConfig_1 = require("../mim/GenerateListConfig");
const View_1 = require("../../rendering/gui/views/View");
const ActionData_1 = require("../../rendering/gui/actions/ActionData");
const TouchManager_1 = require("../../rendering/gui/TouchManager");
const MENU_MIM_CONFIG = {
mim_id: Mim_1.MENU_NAME,
mim_type: "optional-response",
rule_name: null,
timeout: 10,
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
};
const DEFAULT_CLOSE = {
remove: true
};
class Menu extends Behavior_1.default {
constructor(options) {
super(options);
this.createdMenu = false;
this.isQuitting = false;
this.gotPick = false;
this.getConfig = options.getConfig;
this.onMenuClosed = options.onMenuClosed;
this.onItemChosen = options.onItemChosen;
this.onPositionalSelect = options.onPositionalSelect;
this.onListClosed = this.onListClosed.bind(this);
this.onPressEvent = this.onPressEvent.bind(this);
}
start() {
this.status = Status_1.default.IN_PROGRESS;
const configLoaded = (config) => {
if (!config) {
this.status = Status_1.default.FAILED;
return;
}
if (typeof config === 'string') {
const path = Runtime_1.default.instance.utils.PathUtils.getAssetUri(config, this.assetPack);
Runtime_1.default.instance.loader.load(path, (err, data) => {
if (err) {
throw err;
}
configLoaded(data);
});
return;
}
if (!config.open) {
config.open = {
pause: false
};
}
else if (!config.open.hasOwnProperty('pause')) {
config.open.pause = false;
}
this.config = config;
let mimConfig = null;
let mimPath = null;
if (config.baseMim) {
mimPath = config.baseMim;
}
else {
mimConfig = GenerateListConfig_1.mergeDeep({}, MENU_MIM_CONFIG);
if (config.timeout > 1) {
mimConfig.timeout = config.timeout;
}
mimConfig.rule_name = config.rule;
}
const mimEnd = this.onMimEnd.bind(this);
let mimOptions = {
assetPack: this.assetPack,
onSuccess: mimEnd,
onFailure: mimEnd,
onPositionalSelect: this.onPositionalSelect,
mimConfig: mimConfig,
mimPath: mimPath,
guiConfig: config,
asrMetadata: {
skill: this.assetPack
},
isMenu: true
};
this.mim = new Mim_1.default(mimOptions);
this.mim.start();
};
this.getConfig(configLoaded);
return true;
}
stop() {
this.status = Status_1.default.INVALID;
if (this.mim) {
const activeView = this.mim.activeView;
if (activeView) {
activeView.removeListener('press', this.onPressEvent);
activeView.removeListener(View_1.STATE.CLOSED, this.onListClosed);
}
return this.mim.stop();
}
return Promise.resolve();
}
update() {
if (this.isQuitting) {
return Status_1.default.IN_PROGRESS;
}
if (this.status !== Status_1.default.IN_PROGRESS) {
return this.status;
}
if (this.mim) {
this.status = this.mim.update();
if (this.isQuitting) {
this.status = Status_1.default.IN_PROGRESS;
}
const activeView = this.mim.activeView;
if (!this.createdMenu && activeView &&
(activeView.state === View_1.STATE.LOADED || activeView.state === View_1.STATE.OPENED)) {
activeView.once('press', this.onPressEvent);
activeView.once(View_1.STATE.CLOSED, this.onListClosed);
this.createdMenu = true;
activeView.removeActionsByType(ActionData_1.default.CLOSE_VIEW, TouchManager_1.GESTURE.SWIPE);
}
}
return this.status;
}
destroy() {
super.destroy();
if (this.mim) {
this.mim.destroy();
this.mim = null;
}
}
onPressEvent(event) {
if (this.gotPick || !this.mim) {
return;
}
this.gotPick = true;
let transition = this.config.defaultSelect || DEFAULT_CLOSE;
this.onItemChosen(event, this.mim.activeView, (trans) => {
transition = trans;
});
if (!this.mim) {
console.error('Menu was destroyed during onItemChosen() - please wait until the behavior returns Status.SUCCEEDED or Status.FAILED from update() to consider it completed');
return;
}
this.mim.viewTransition = transition;
if (this.mim.activeView) {
const activeView = this.mim.activeView;
activeView.removeListener('press', this.onPressEvent);
activeView.removeListener(View_1.STATE.CLOSED, this.onListClosed);
}
this.mim.stop(true);
if (this.mim.destroyViewPromise) {
this.mim.destroyViewPromise.then(() => {
this.status = Status_1.default.SUCCEEDED;
});
}
else {
this.status = Status_1.default.SUCCEEDED;
}
}
onListClosed() {
if (this.gotPick || !this.mim) {
return;
}
this.gotPick = true;
let transition = this.config.defaultClose || DEFAULT_CLOSE;
let handled = false;
if (this.onMenuClosed) {
handled = this.onMenuClosed(false, this.mim.activeView, (trans) => {
transition = trans;
});
}
if (!this.mim) {
console.error('Menu was destroyed during onMenuClosed() - please wait until the behavior returns Status.SUCCEEDED or Status.FAILED from update() to consider it completed');
return;
}
this.mim.viewTransition = transition;
if (this.mim.activeView) {
const activeView = this.mim.activeView;
activeView.removeListener(View_1.default.BACK, this.onListClosed);
activeView.removeListener('press', this.onPressEvent);
activeView.removeListener(View_1.STATE.CLOSED, this.onListClosed);
}
if (!handled) {
this.isQuitting = true;
this.mim.activeView.inputLocked = true;
Runtime_1.default.instance.lifecycle.finished();
}
else {
this.mim.stop();
if (this.mim.destroyViewPromise) {
this.mim.destroyViewPromise.then(() => {
this.status = Status_1.default.SUCCEEDED;
});
}
else {
this.status = Status_1.default.SUCCEEDED;
}
}
}
onMimEnd(results) {
if (this.gotPick || !this.mim) {
return;
}
this.gotPick = true;
let transition = this.config.defaultClose || DEFAULT_CLOSE;
const lastResultState = results.state.lastResultState;
if (lastResultState === 'noInput' || lastResultState === 'MenuClosed' || lastResultState === 'noMatch') {
let handled = false;
if (this.onMenuClosed) {
handled = this.onMenuClosed(lastResultState === 'noInput' || lastResultState === 'noMatch', this.mim.activeView, (trans) => {
transition = trans;
});
if (!this.mim) {
console.error('Menu was destroyed during onMenuClosed() - please wait until the behavior returns Status.SUCCEEDED or Status.FAILED from update() to consider it completed');
return true;
}
}
if (!handled) {
this.isQuitting = true;
Runtime_1.default.instance.lifecycle.finished();
}
}
else {
transition = this.config.defaultSelect || DEFAULT_CLOSE;
this.onItemChosen(results.asrResults, this.mim.activeView, (trans) => {
transition = trans;
});
if (!this.mim) {
console.error('Menu was destroyed during onItemChosen() - please wait until the behavior returns Status.SUCCEEDED or Status.FAILED from update() to consider it completed');
return;
}
}
this.mim.viewTransition = transition;
if (this.mim.activeView) {
const activeView = this.mim.activeView;
activeView.removeListener(View_1.default.BACK, this.onListClosed);
activeView.removeListener('press', this.onPressEvent);
activeView.removeListener(View_1.STATE.CLOSED, this.onListClosed);
}
return true;
}
}
exports.default = Menu;
},{"../../Runtime":1,"../../rendering/gui/TouchManager":125,"../../rendering/gui/actions/ActionData":130,"../../rendering/gui/views/View":156,"../Behavior":3,"../Status":10,"../mim/GenerateListConfig":50,"./Mim":16}],16:[function(require,module,exports){
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const jibo_state_machine_1 = require("jibo-state-machine");
const uuid = require("uuid");
const log_1 = require("./log");
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
const Runtime_1 = require("../../Runtime");
const jibo_plugins_1 = require("jibo-plugins");
const jetstream_client_1 = require("@jibo/jetstream-client");
const MimConfig_1 = require("../mim/MimConfig");
const jibo_embodied_dialog_1 = require("jibo-embodied-dialog");
const MimState_1 = require("../mim/MimState");
const GenerateListConfig_1 = require("../mim/GenerateListConfig");
const MimManager_1 = require("../mim/MimManager");
const ListenEvent_1 = require("../mim/delegates/ListenEvent");
const analytics = require("../mim/analytics/MimAnalytics");
const FaceRenderer_1 = require("../../rendering/FaceRenderer");
const ViewManager_1 = require("../../rendering/gui/ViewManager");
const View_1 = require("../../rendering/gui/views/View");
const EyeView_1 = require("../../rendering/gui/views/EyeView");
const MenuView_1 = require("../../rendering/gui/views/MenuView");
const ActionData_1 = require("../../rendering/gui/actions/ActionData");
const NoInputException = require('../mim/flows/NoInputException');
const NoMatchException = require('../mim/flows/NoMatchException');
class ListenBundle {
constructor() {
this.timeout = NaN;
this.startTime = NaN;
this.failedToGetListener = false;
}
}
class MimStates {
constructor(sm) {
this.loadConfig = new jibo_state_machine_1.State(sm, 'Load MIM Config');
this.loadRule = new jibo_state_machine_1.State(sm, 'Load Rule');
this.choosePrompt = new jibo_state_machine_1.State(sm, 'Choose Prompt');
this.speak = new jibo_state_machine_1.State(sm, 'Speak');
this.listen = new jibo_state_machine_1.State(sm, 'Listen');
this.restartListen = new jibo_state_machine_1.State(sm, 'Restart Listen');
this.analyzeMimGlobal = new jibo_state_machine_1.State(sm, 'Analyze Mim Global');
this.analyzeMenuGlobal = new jibo_state_machine_1.State(sm, 'Analyze Menu Global');
this.analyzeResults = new jibo_state_machine_1.State(sm, 'Analyze Results');
this.parseSpoof = new jibo_state_machine_1.State(sm, 'Parse Spoofed Utterance');
this.reportResults = new jibo_state_machine_1.State(sm, 'Report Results');
this.handleException = new jibo_state_machine_1.State(sm, 'Handle Exception');
this.waitForHJEnd = new jibo_state_machine_1.State(sm, 'Wait for Hey Jibo end');
this.loadConfig.addInternalTransition('Config loaded', this.loadRule);
this.loadConfig.addInternalTransition('AN mim', this.choosePrompt);
this.loadConfig.addInternalTransition('HJ before/during config for AN', this.waitForHJEnd);
this.loadRule.addInternalTransition('Rule loading', this.choosePrompt);
this.loadRule.addInternalTransition('Spoofed utterance during config', this.parseSpoof);
this.loadRule.addInternalTransition('HJ before/during config for Q/OR', this.waitForHJEnd);
this.choosePrompt.addInternalTransition('Has prompt', this.speak);
this.choosePrompt.addInternalTransition('No prompt', this.listen);
this.choosePrompt.addInternalTransition('No valid prompt on AN mim', this.reportResults);
this.speak.addInternalTransition('AN speak done or View manually closed', this.reportResults);
this.speak.addInternalTransition('OR/Q speak done', this.listen);
this.speak.addInternalTransition('Spoofed utterance', this.parseSpoof);
this.speak.addInternalTransition('HJ Heard', this.waitForHJEnd);
this.listen.addInternalTransition('Listen complete', this.analyzeResults);
this.listen.addInternalTransition('Mim Global', this.analyzeMimGlobal);
this.listen.addInternalTransition('List Global', this.analyzeMenuGlobal);
this.listen.addInternalTransition('Premature Timeout', this.restartListen);
this.listen.addInternalTransition('Spoofed utterance', this.parseSpoof);
this.listen.addInternalTransition('HJ Heard', this.waitForHJEnd);
this.listen.addInternalTransition('What Can I Do', this.choosePrompt);
this.listen.addInternalTransition('View manually closed', this.reportResults);
this.restartListen.addTransition(new jibo_state_machine_1.TimeoutTransition('5 ms', this.listen, 5));
this.restartListen.addInternalTransition('View closed while waiting to restart', this.reportResults);
this.analyzeMimGlobal.addInternalTransition('Quick Global', this.listen);
this.analyzeMimGlobal.addInternalTransition('Repeat', this.choosePrompt);
this.analyzeMimGlobal.addInternalTransition('Irrelevant global', this.analyzeResults);
this.analyzeMenuGlobal.addInternalTransition('Quick Global', this.listen);
this.analyzeMenuGlobal.addInternalTransition('Irrelevant global', this.analyzeResults);
this.analyzeMenuGlobal.addInternalTransition('Spoofed utterance', this.parseSpoof);
this.analyzeMenuGlobal.addInternalTransition('Menu global ends menu', this.reportResults);
this.parseSpoof.addInternalTransition('Utterance parsed', this.analyzeResults);
this.analyzeResults.addInternalTransition('MIM success', this.reportResults);
this.analyzeResults.addInternalTransition('Another try', this.choosePrompt);
this.analyzeResults.addInternalTransition('Ignore NM', this.listen);
this.reportResults.addInternalTransition('NM/NI exception', this.handleException);
this.handleException.addInternalTransition('Exception solved', this.choosePrompt);
this.waitForHJEnd.addInternalTransition('Recover from HJ', this.choosePrompt);
this.waitForHJEnd.addInternalTransition('Recover from HJ (menu)', this.listen);
this.waitForHJEnd.addInternalTransition('View manually closed', this.reportResults);
this.waitForHJEnd.addInternalTransition('Button pressed while waiting', this.parseSpoof);
}
}
exports.MENU_NAME = 'Menu_AutoGenerated';
const THANKS_RULE = 'globals/mim_thanks';
const REPEAT_RULE = 'globals/mim_repeat';
const GUI_RULE = 'globals/gui_nav';
const log = log_1.default.createChild('MimBehavior');
function sanitizePromptData(data) {
let output = {};
for (let prop in data) {
if (!data[prop]) {
output[prop] = data[prop];
continue;
}
if (typeof data[prop].toLog === 'function') {
output[prop] = data[prop].toLog();
continue;
}
if (/loop|name|user|birth/i.test(prop)) {
output[prop] = `<User property ${prop} omitted>`;
}
output[prop] = data[prop];
}
return output;
}
class Mim extends Behavior_1.default {
constructor(options) {
super(options);
this.pausedHotword = null;
this.isMenu = false;
this.interactionId = uuid.v4();
MimManager_1.default.instance.loadMimAssets();
this.viewTransition = {
remove: true,
transitionClose: ViewManager_1.TRANSITION.DOWN
};
this.mimPath = options.mimPath;
this.promptData = null;
if (options.mimConfig) {
this.mimConfig = new MimConfig_1.default();
if (options.isMenu) {
this.mimConfig.mimId = exports.MENU_NAME;
}
this.mimConfig.initWithJSON(options.mimConfig);
}
this.isMenu = !!options.isMenu;
if (options.guiConfig) {
this.guiConfig = options.guiConfig;
}
this.asrMetadata = options.asrMetadata;
if (!this.asrMetadata) {
this.asrMetadata = {};
}
this.asrMetadata.skill = Runtime_1.default.instance.analytics.currentSkill;
this.asrMetadata.interactionId = this.interactionId;
this.checkResult = options.checkResult;
this.onFailure = options.onFailure;
this.onSuccess = options.onSuccess || options.onResults;
this.onPositionalSelect = options.onPositionalSelect;
this.status = Status_1.default.INVALID;
this.mimState = new MimState_1.default();
this.entryPrompt = null;
this.repeatCount = 0;
this.mimMachine = new jibo_state_machine_1.StateMachine();
const states = this.states = new MimStates(this.mimMachine);
states.loadConfig.onEntry = this.loadMim.bind(this);
states.loadRule.onEntry = this.loadRule.bind(this);
states.choosePrompt.onEntry = this.choosePrompt.bind(this);
states.speak.onEntry = this.speak.bind(this);
states.speak.onExit = states.speak.onStop = this.stopSpeaking.bind(this);
states.listen.onEntry = this.startListen.bind(this);
states.listen.onUpdate = this.updateListen.bind(this);
states.listen.onStop = this.stopListen.bind(this);
states.listen.onExit = this.listenExit.bind(this);
states.analyzeMimGlobal.onEntry = this.analyzeMimGlobal.bind(this);
states.analyzeMenuGlobal.onEntry = this.analyzeMenuGlobal.bind(this);
states.analyzeResults.onEntry = this.analyzeResults.bind(this);
states.parseSpoof.onEntry = this.parseSpoofedUtterance.bind(this);
states.reportResults.onEntry = this.reportResults.bind(this);
states.handleException.onEntry = this.handleException.bind(this);
states.handleException.onUpdate = this.updateException.bind(this);
states.handleException.onStop = this.stopException.bind(this);
states.waitForHJEnd.onEntry = this.waitForHJEnd.bind(this);
states.waitForHJEnd.onStop = states.waitForHJEnd.onExit = this.hjEnded.bind(this);
this.resetTimeout = this.resetTimeout.bind(this);
this.onEndEvent = this.onEndEvent.bind(this);
this.onSpeechEvent = this.onSpeechEvent.bind(this);
this.onOpenGUIEvent = this.onOpenGUIEvent.bind(this);
this.onHeyJiboHeard = this.onHeyJiboHeard.bind(this);
this.recoverFromHJ = this.recoverFromHJ.bind(this);
this.onViewClosed = this.onViewClosed.bind(this);
}
start() {
if (this.options.getPromptData) {
this.promptData = this.options.getPromptData();
}
if (!this.promptData) {
this.promptData = {};
}
if (this.promptData._state) {
this.mimState.lastResultState = this.promptData._state;
delete this.promptData._state;
}
this.status = Status_1.default.IN_PROGRESS;
Runtime_1.default.instance.performance.log('MimStart');
this.mimMachine.start();
if (!this.options.ignoreEvents) {
const mm = MimManager_1.default.instance;
mm.openGUI.on(this.onOpenGUIEvent);
mm.handleSpeech.on(this.onSpeechEvent);
mm.end.on(this.onEndEvent);
mm.heyJibo.on(this.onHeyJiboHeard);
}
return true;
}
stop(isMenuTap = false) {
return __awaiter(this, void 0, void 0, function* () {
if (this.status === Status_1.default.IN_PROGRESS) {
if (isMenuTap) {
analytics.end(this.analyticsBase, analytics.EXIT_TYPE.SUCCESS, analytics.INPUT.TOUCH, '<menu_tap>', analytics.NONE, '', this.lastPromptId, this.mimState.noMatchCount, this.mimState.noInputCount);
}
else {
const IS = analytics.INTERRUPT_STATE;
analytics.end(this.analyticsBase, analytics.EXIT_TYPE.INTERRUPT, analytics.INPUT.INTERRUPT, '', analytics.NONE, this.mimMachine.current === this.states.speak ? IS.SPEECH : IS.LISTEN, this.lastPromptId, this.mimState.noMatchCount, this.mimState.noInputCount);
}
}
if (this.pausedHotword) {
this.pausedHotword.release();
this.pausedHotword = null;
}
this.cleanUpEvents();
this.removeView();
this.mimMachine.stop();
this.mimMachine.current = null;
this.unloadRules();
this.status = Status_1.default.INVALID;
const listenDelegate = MimManager_1.default.instance.listenDelegate;
yield listenDelegate.exitActiveMode();
yield (this.destroyViewPromise || Promise.resolve());
});
}
update() {
if (this.status !== Status_1.default.IN_PROGRESS) {
return this.status;
}
this.mimMachine.update();
return this.status;
}
destroy() {
this.status = Status_1.default.INVALID;
super.destroy();
this.unloadRules();
this.cleanUpEvents();
if (this.pausedHotword) {
this.pausedHotword.release();
this.pausedHotword = null;
}
this.removeView();
if (this.mimMachine) {
this.mimMachine.stop();
}
this.mimMachine = null;
this.mimState = null;
this.checkResult = null;
this.onFailure = null;
this.onSuccess = null;
this.destroyViewPromise = null;
this.viewConfig = null;
}
removeView() {
if (this.activeView) {
const listenDelegate = MimManager_1.default.instance.listenDelegate;
listenDelegate.exitActiveMode();
const activeView = this.activeView;
const views = Runtime_1.default.instance.face.views;
if (views.currentView === activeView) {
if (this.viewEvents) {
for (const evType in this.viewEvents) {
activeView.removeListener(evType, this.viewEvents[evType]);
}
}
activeView.removeListener(View_1.default.BACK, this.onViewClosed);
if (this.viewTransition === 'remain') {
activeView.inputLocked = true;
this.activeView = null;
return;
}
else {
this.destroyViewPromise = new Promise((resolve, reject) => {
Runtime_1.default.instance.face.views.changeView(this.viewTransition, () => {
resolve();
this.destroyViewPromise = null;
}, () => {
resolve();
this.destroyViewPromise = null;
});
});
}
}
this.activeView = null;
}
}
unloadRules() {
}
cleanUpEvents() {
const mm = MimManager_1.default.instance;
mm.openGUI.removeListener(this.onOpenGUIEvent);
mm.handleSpeech.removeListener(this.onSpeechEvent);
mm.end.removeListener(this.onEndEvent);
mm.heyJibo.removeListener(this.onHeyJiboHeard);
}
openGUI() {
if (this.activeView) {
return;
}
const mimConfig = this.mimConfig;
const views = Runtime_1.default.instance.face.views;
let config;
if (this.guiConfig) {
config = this.guiConfig;
}
else if (mimConfig.gui) {
if (mimConfig.gui.type === 'Menu') {
config = GenerateListConfig_1.default(mimConfig.gui.data);
}
else if (mimConfig.gui.type === 'File') {
try {
const configPath = jibo_plugins_1.PathUtils.getAssetUri(mimConfig.gui.data, this.assetPack);
config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
}
catch (e) {
log.warn(`Error when reading MIM GUI json:`, e, `MIM Info: ${this.loggingLead}`);
mimConfig.gui = null;
return;
}
}
else if (mimConfig.gui.type === 'Javascript') {
config = mimConfig.getJavascriptGUI(this.promptData);
if (!config) {
mimConfig.gui = null;
return;
}
}
}
this.viewConfig = config;
if (views.currentView && views.currentView.id === config.viewConfig.id) {
this.activeView = views.currentView;
}
else {
this.activeView = views.createView(config.viewConfig.type || 'MenuView', config);
const open = config.open || {};
if (views.hasView(this.activeView.id)) {
open.removeToInclude = this.activeView.id;
}
const shouldPause = mimConfig.gui && (mimConfig.gui.pause || mimConfig.gui.pause === undefined);
if (!open.hasOwnProperty('pause') && shouldPause) {
open.pause = !!views.currentView;
if (views.currentView && views.currentView.type === EyeView_1.default.DEFAULT_TYPE && this.activeView instanceof MenuView_1.default) {
this.activeView.addTransition(View_1.default.PAUSED, true, this.activeView.openFromEye, ViewManager_1.TRANSITION.NONE);
this.activeView.addTransition(View_1.default.PAUSED, false, this.activeView.closeToEye, ViewManager_1.TRANSITION.NONE);
}
}
open.addView = this.activeView;
views.changeView(open, () => {
}, () => {
if (this.mimState && !this.mimState.done) {
if (this.isMenu) {
this.stop();
this.status = Status_1.default.FAILED;
}
else {
log.warn(`Mim ${mimConfig.mimId} failed to open view, forcing eye view`);
views.forceEyeView();
}
}
});
}
if (this.activeView) {
this.activeView.once(View_1.default.BACK, this.onViewClosed);
}
else {
log.warn(`activeView was null right after it should have been set/created. Current behavior status: ${Status_1.default[this.status]}`);
}
}
onOpenGUIEvent() {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
const current = this.mimMachine.current;
const states = this.states;
if (current !== states.loadConfig) {
this.openGUI();
}
}
onSpeechEvent(utterance) {
return __awaiter(this, void 0, void 0, function* () {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
const current = this.mimMachine.current;
const states = this.states;
if (typeof utterance === 'string') {
utterance = {
intent: utterance,
entities: {},
rules: null
};
}
if (typeof utterance.intent !== 'string' || !utterance.entities) {
log.warn('Received invalid utterance for fake NLU', utterance);
return;
}
utterance.rules = this.mimConfig.ruleNames;
if (current === states.speak || current === states.listen ||
current === states.analyzeMenuGlobal || current === states.waitForHJEnd) {
if (current === states.speak) {
MimManager_1.default.instance.speakDelegate.stop();
Runtime_1.default.instance.embodied.listen.disableOnce();
Runtime_1.default.instance.jetstream.startLocalTurn({
nluRules: utterance.rules,
clientNLU: utterance
}).catch((err) => {
log.error('Unable to start clientNLU local turn', err);
});
}
else if (current === states.listen) {
if (this.listen.listener && !this.listen.listener.stopped) {
yield this.listen.listener.updateTurn(utterance);
}
else {
Runtime_1.default.instance.embodied.listen.disableOnce();
Runtime_1.default.instance.jetstream.startLocalTurn({
nluRules: utterance.rules,
clientNLU: utterance
}).catch((err) => {
log.error('Unable to start clientNLU local turn', err);
});
}
}
current.transitionTo(states.parseSpoof, utterance);
}
else if (current === states.loadConfig) {
this.queuedState = { state: states.parseSpoof, data: utterance };
}
});
}
onEndEvent(data) {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
const current = this.mimMachine.current;
const states = this.states;
if (current === states.speak || current === states.listen ||
current === states.loadConfig || current === states.analyzeMenuGlobal) {
if (!data) {
this.stop();
this.status = Status_1.default.SUCCEEDED;
}
else {
}
}
}
onHeyJiboHeard() {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
const current = this.mimMachine.current;
const states = this.states;
if (current === states.speak) {
if (current === states.speak) {
MimManager_1.default.instance.speakDelegate.stop();
}
current.transitionTo(states.waitForHJEnd);
}
else if (current === states.loadConfig) {
this.queuedState = { state: states.waitForHJEnd, data: null };
}
}
onViewClosed() {
this.mimState.lastResultState = MimState_1.States.MENU_CLOSED;
if (this.mimConfig.mimType === MimConfig_1.MimTypes.QUESTION) {
this.mimState.failure = true;
}
if (!this.exitInputType) {
this.exitInputType = analytics.INPUT.TOUCH;
}
if (this.mimMachine.current.transitions.find((item) => item.getDestinationState() === this.states.reportResults)) {
this.mimMachine.current.transitionTo(this.states.reportResults);
}
else {
log.warn(`Attempted to transition due to view closing from ${this.mimMachine.current.name} to ${this.states.reportResults.name}, which isn't allowed.`);
}
}
loadMim(transition, result) {
const jibo = Runtime_1.default.instance;
let loadPromise;
if (this.mimConfig && this.isMenu) {
jibo.performance.log('MimDataLoadSkipped', 'Mim data already provided');
this.asrMetadata.mimType = MimConfig_1.MimTypes.OPTIONAL_RESPONSE;
this.asrMetadata.mimId = 'menu:' + this.guiConfig.viewConfig.id;
this.loggingLead = `Interaction UUID[${this.interactionId}] MIM ID[${this.asrMetadata.mimId}] MIM Type[${this.asrMetadata.mimType}]`;
this.analyticsBase = {
mim_name: this.asrMetadata.mimId,
mim_type: this.asrMetadata.mimType,
interaction_id: this.interactionId
};
loadPromise = Promise.resolve();
}
else {
const assetPack = this.assetPack;
jibo.performance.log('MimDataLoadBegin');
loadPromise = Promise.all([
this.mimConfig ? Promise.resolve(this.mimConfig) : MimConfig_1.default.load(jibo_plugins_1.PathUtils.getAssetUri(this.mimPath, assetPack)),
MimManager_1.default.instance.loadMimKB(assetPack)
])
.then((result) => {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
if (!(result[0] instanceof MimConfig_1.default)) {
log.error(`Error: Cannot load Mim File for ${this.mimPath}!`, result);
this.status = Status_1.default.FAILED;
return;
}
jibo.performance.log('MimDataLoadComplete');
this.assetPackNode = result[1];
this.mimConfig = result[0];
this.asrMetadata.mimType = this.mimConfig.mimType;
this.asrMetadata.mimId = this.mimConfig.mimId;
if (this.guiConfig) {
this.asrMetadata.mimId = 'menu:' + this.guiConfig.viewConfig.id;
this.asrMetadata.mimType = MimConfig_1.MimTypes.OPTIONAL_RESPONSE;
}
this.loggingLead = `Interaction UUID[${this.interactionId}] MIM ID[${this.asrMetadata.mimId}] MIM Type[${this.asrMetadata.mimType}]`;
this.analyticsBase = {
mim_name: this.asrMetadata.mimId,
mim_type: this.asrMetadata.mimType,
interaction_id: this.interactionId
};
});
}
loadPromise.then(() => {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
log.debug(`Starting MIM - ${this.loggingLead} Mim Variable Assignments[${JSON.stringify(sanitizePromptData(this.promptData))}]`);
analytics.launch(this.analyticsBase);
jibo.autobot.log('MIM Start', this.mimConfig.original);
if (this.mimConfig.mimType === MimConfig_1.MimTypes.ANNOUNCEMENT) {
if (this.queuedState) {
const queuedState = this.queuedState;
this.queuedState = null;
this.states.loadRule.transitionTo(queuedState.state, queuedState.data);
}
else if (MimManager_1.default.instance.isHeyJiboActive) {
this.states.loadConfig.transitionTo(this.states.waitForHJEnd);
}
else {
this.states.loadConfig.transitionTo(this.states.choosePrompt);
}
}
else {
if (MimManager_1.default.instance.isHeyJiboActive && !this.isMenu) {
this.queuedState = { state: this.states.waitForHJEnd, data: null };
}
this.states.loadConfig.transitionTo(this.states.loadRule);
}
}, reason => {
log.error('Failure to load mim config: ', reason);
this.status = Status_1.default.FAILED;
});
}
loadRule(transition, result) {
this.mimConfig.calculateRules(this.promptData);
if (this.queuedState) {
const queuedState = this.queuedState;
this.queuedState = null;
this.states.loadRule.transitionTo(queuedState.state, queuedState.data);
}
else {
this.states.loadRule.transitionTo(this.states.choosePrompt);
}
}
choosePrompt(transition, result) {
const mimState = this.mimState;
const mimConfig = this.mimConfig;
const jibo = Runtime_1.default.instance;
if (mimState.errors >= 1 && mimState.shouldShowGUI(mimConfig)) {
MimManager_1.default.instance.shouldShowGUI = true;
}
const currentView = jibo.face.views.currentView;
const shouldShow = MimManager_1.default.instance.shouldShowGUI || mimState.shouldShowGUI(mimConfig);
if (this.guiConfig || (mimConfig.hasGui && shouldShow &&
(mimState.shouldShowGUI(mimConfig) || !currentView ||
currentView.category === jibo.face.views.CATEGORY.EYE))) {
this.openGUI();
}
const home = jibo.utils.Location.jiboHome;
this.promptData._now = new jibo.utils.DateTime(null, null, home.timezone);
this.promptData._home = home;
let promptText = '';
const lastResultState = mimState.lastResultState;
jibo.performance.log('MimPromptSelectionStart', `MIM ID: ${mimConfig.mimId} State: ${lastResultState}`);
if (lastResultState === MimState_1.States.REPEAT) {
const repeat = MimManager_1.default.instance.repeat.getRepeat(mimConfig.mimType, this.repeatCount);
if (repeat.prompt) {
promptText = repeat.prompt;
}
if (repeat.action === 'verbose' && mimConfig.hasVerbosePrompt()) {
mimState.lastResultState = MimState_1.States.VERBOSE;
const prompt = mimConfig.getPromptText(mimState, this.promptData, this.assetPackNode);
promptText += prompt.text;
this.asrMetadata.lastPromptId = this.lastPromptId = prompt.id;
this.mimState.promptAutoRules = prompt.autoRuleOverride;
}
else if (repeat.action !== 'exit') {
this.asrMetadata.lastPromptId = this.lastPromptId = this.entryPrompt.id;
promptText += this.entryPrompt.text;
this.mimState.promptAutoRules = this.entryPrompt.autoRuleOverride;
}
this.mimState.promptText = promptText.trim();
}
else if (lastResultState === MimState_1.States.THANKS) {
let prompt;
if (mimConfig.hasThanksPrompt()) {
prompt = mimConfig.getPromptText(mimState, this.promptData, this.assetPackNode);
}
else {
prompt = MimManager_1.default.instance.thanksResponse.getPromptText(null, null, MimManager_1.default.instance.jiboRotationNode);
}
this.asrMetadata.lastPromptId = this.lastPromptId = prompt.id;
this.mimState.promptText = promptText = prompt.text.trim();
this.mimState.promptAutoRules = prompt.autoRuleOverride;
}
else {
const prompt = mimConfig.getPromptText(mimState, this.promptData, this.assetPackNode);
this.asrMetadata.lastPromptId = this.lastPromptId = prompt.id;
this.mimState.promptText = promptText = prompt.text.trim();
this.mimState.promptAutoRules = prompt.autoRuleOverride;
if (lastResultState === MimState_1.States.ENTRY && this.entryPrompt === null) {
this.entryPrompt = prompt;
}
}
jibo.performance.log('MimPromptSelectionEnd');
jibo.autobot.log('MIMPromptSelected', this.lastPromptId, promptText);
if (promptText) {
this.states.choosePrompt.transitionTo(this.states.speak);
}
else {
if (this.lastPromptId === null) {
log.warn(`Unable to find a valid prompt for mim ${this.mimConfig.mimId} - last result state: ${mimState.lastResultState}, prompt data: ${JSON.stringify(sanitizePromptData(this.promptData))}`);
}
else {
log.debug(`Silent Prompt Selected - ${this.loggingLead}`);
}
if (this.mimConfig.mimType === MimConfig_1.MimTypes.ANNOUNCEMENT) {
this.states.choosePrompt.transitionTo(this.states.reportResults);
}
else {
this.states.choosePrompt.transitionTo(this.states.listen, true);
}
}
}
speak(transition, result) {
const text = this.mimState.promptText;
const autoRules = this.mimState.promptAutoRules === null ? this.mimConfig.esAutoTagging : this.mimState.promptAutoRules;
const options = {
text: text,
disableAutoRules: autoRules === false,
followedByListen: this.mimConfig.mimType !== MimConfig_1.MimTypes.ANNOUNCEMENT,
autoRuleConfig: undefined
};
if (typeof autoRules !== 'boolean') {
options.autoRuleConfig = autoRules;
}
const promptStart = Date.now();
const originalText = text ? this.mimConfig.getOriginalPromptText(this.lastPromptId) : '';
log.debug(`Playing Prompt - ${this.loggingLead} Last Prompt Id[${this.lastPromptId}] Prompt[${originalText}]`);
let performanceMimPromptData = {
"MimPromptData": [
{ "InteractionUUID": this.interactionId },
{ "MIM_ID": this.asrMetadata.mimId },
{ "MIM_Type": this.asrMetadata.mimType },
{ "LastPromptId": this.lastPromptId },
{ "Prompt": text },
{ "MimVariableAssignments": this.promptData }
]
};
const jibo = Runtime_1.default.instance;
const strippedText = text.replace(/<[^>]*>/g, '');
if (/(hey|hay)\s+jibo/i.test(strippedText)) {
this.pausedHotword = jibo.jetstream.setHotwordMode(jibo.jetstream.types.HotwordListenMode.Disabled);
}
jibo.performance.log('MimPromptData', JSON.stringify(performanceMimPromptData));
jibo.autobot.log('MimPromptData', JSON.stringify(performanceMimPromptData));
jibo.autobot.log('MimSpeechStart', options.text);
jibo.performance.log('MimSpeechStart');
MimManager_1.default.instance.speakDelegate.speak(options.text, options, options.autoRuleConfig)
.then(() => {
if (this.pausedHotword) {
this.pausedHotword.release();
this.pausedHotword = null;
}
if (this.status !== Status_1.default.IN_PROGRESS ||
this.mimMachine.current !== this.states.speak) {
return;
}
jibo.autobot.log('MimSpeechEnd');
jibo.performance.log('MimSpeechEnd');
log.debug(`Prompt Complete - ${this.loggingLead} Last Prompt Id[${this.lastPromptId}] Duration[${Date.now() - promptStart}ms]`);
if (this.repeatCount >= MimManager_1.default.instance.repeat.maxRepeat) {
jibo.lifecycle.finished();
return;
}
if (this.mimState.lastResultState === MimState_1.States.THANKS &&
this.mimConfig.thanksHandling === MimConfig_1.ThanksOptions.RESPOND_AND_END) {
this.states.speak.transitionTo(this.states.reportResults);
return;
}
if (this.mimConfig.mimType === MimConfig_1.MimTypes.ANNOUNCEMENT) {
this.states.speak.transitionTo(this.states.reportResults);
}
else {
this.states.speak.transitionTo(this.states.listen, true);
}
})
.catch(e => {
if (this.pausedHotword) {
this.pausedHotword.release();
this.pausedHotword = null;
}
jibo.autobot.log('MimSpeechError', e);
log.warn('Error when speaking:', e, `Mim Info: ${this.loggingLead}`);
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
if (this.mimMachine.current === this.states.speak) {
if (this.mimState.lastResultState === MimState_1.States.THANKS &&
this.mimConfig.thanksHandling === MimConfig_1.ThanksOptions.RESPOND_AND_END) {
this.states.speak.transitionTo(this.states.reportResults);
return;
}
if (this.mimConfig.mimType === MimConfig_1.MimTypes.ANNOUNCEMENT) {
this.states.speak.transitionTo(this.states.reportResults);
}
else {
this.states.speak.transitionTo(this.states.listen, true);
}
}
});
}
stopSpeaking() {
if (this.pausedHotword) {
this.pausedHotword.release();
this.pausedHotword = null;
}
MimManager_1.default.instance.speakDelegate.stop();
}
startListen(transition, resetTimeout) {
return __awaiter(this, void 0, void 0, function* () {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
this.asrResults = null;
let listen = this.listen;
if (!listen) {
resetTimeout = true;
}
if (resetTimeout) {
listen = this.listen = new ListenBundle();
listen.startTime = Date.now();
}
const mimConfig = this.mimConfig;
const ignoreSimulator = mimConfig.mimType === MimConfig_1.MimTypes.OPTIONAL_RESPONSE || MimManager_1.default.instance.timeoutIgnoresSimulator;
const jibo = Runtime_1.default.instance;
const onRobot = jibo.runMode === jibo.RunMode.ON_ROBOT || jibo.runMode === jibo.RunMode.REMOTELY || jibo.runMode === jibo.RunMode.UNIT_TESTS;
if (mimConfig.timeout > 0 && (onRobot || ignoreSimulator)) {
listen.timeout = mimConfig.timeout * 1000;
}
window.addEventListener('touchstart', this.resetTimeout);
window.addEventListener('touchmove', this.resetTimeout);
window.addEventListener('mousedown', this.resetTimeout);
window.addEventListener('mousemove', this.resetTimeout);
const currentView = this.activeView || jibo.face.views.currentView;
const shouldListen = !MimManager_1.default.instance.silentMenus ||
mimConfig.mimType !== MimConfig_1.MimTypes.OPTIONAL_RESPONSE ||
!currentView || currentView.category !== View_1.CATEGORY.GUI;
if (shouldListen) {
const listenDelegate = MimManager_1.default.instance.listenDelegate;
if (resetTimeout) {
if (currentView && currentView.category === View_1.CATEGORY.GUI) {
listenDelegate.enterActiveMode(jibo_embodied_dialog_1.listen.ActiveListenMode.UI);
}
else {
switch (mimConfig.activeListenMode) {
case jibo_embodied_dialog_1.listen.ActiveListenMode.OPTIONAL_RESPONSE:
listenDelegate.enterActiveMode(jibo_embodied_dialog_1.listen.ActiveListenMode.OPTIONAL_RESPONSE, { timeout: listen.timeout });
break;
case jibo_embodied_dialog_1.listen.ActiveListenMode.UI:
listenDelegate.enterActiveMode(jibo_embodied_dialog_1.listen.ActiveListenMode.UI);
break;
case jibo_embodied_dialog_1.listen.AmbientListenMode.NO_BODY:
listenDelegate.setAmbientMode(jibo_embodied_dialog_1.listen.AmbientListenMode.NO_BODY);
break;
}
}
}
this.asrMetadata.mimState = this.mimState.lastResultState;
this.asrMetadata.noMatches = this.mimState.noMatchCount;
this.asrMetadata.noInputs = this.mimState.noInputCount;
const jibo = Runtime_1.default.instance;
jibo.performance.log('MimListenStart', 'Creating a listener');
jibo.autobot.log('MimListenStart', 'Creating a listener');
const rules = mimConfig.ruleNames.slice();
rules.push(GUI_RULE);
if (this.entryPrompt.text) {
rules.push(REPEAT_RULE);
}
if (mimConfig.thanksHandling !== MimConfig_1.ThanksOptions.IGNORE) {
rules.push(THANKS_RULE);
}
let hint_phrases = [];
let fast_eos_array = [];
if (this.mimConfig.hintPhrases) {
const phrases = this.mimConfig.runSandboxed('`' + this.mimConfig.hintPhrases + '`', this.promptData).split(',');
for (let phrase of phrases) {
hint_phrases.push(phrase.trim());
}
}
if (this.mimConfig.fastEosArray) {
const phrases = this.mimConfig.runSandboxed('`' + this.mimConfig.fastEosArray + '`', this.promptData).split(',');
for (let phrase of phrases) {
fast_eos_array.push(phrase.trim());
}
}
const listenOptions = {
nluRules: rules,
log: this.asrMetadata,
hintPhrases: hint_phrases,
earlyEOS: fast_eos_array,
sosTimeout: this.mimConfig.timeout - (Date.now() - listen.startTime) / 1000
};
try {
const listener = yield listenDelegate.create(listenOptions);
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
if (this.mimMachine.current !== this.states.listen) {
listener.stop();
return;
}
listen.listener = listener;
listen.failedToGetListener = false;
listen.listener.on(ListenEvent_1.default.FINISHED, () => {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
listen.listener = null;
if (this.mimMachine.current === this.states.listen) {
if (!this.asrResults) {
this.asrResults = new jetstream_client_1.types.ListenResult(null);
}
if (this.checkResult) {
this.checkResult(this.asrResults);
}
if (this.asrResults.state === jetstream_client_1.types.ListenResultState.noInput && Date.now() - listen.startTime < listen.timeout) {
this.states.listen.transitionTo(this.states.restartListen);
}
else if (this.asrResults.entities.domain === 'mim_global') {
this.states.listen.transitionTo(this.states.analyzeMimGlobal);
}
else if (this.asrResults && (this.asrResults.entities.domain === 'gui_command' ||
this.asrResults.entities.domain === 'menu_global')) {
this.states.listen.transitionTo(this.states.analyzeMenuGlobal);
}
else {
this.states.listen.transitionTo(this.states.analyzeResults, this.asrResults.state === jetstream_client_1.types.ListenResultState.noInput);
}
}
});
listen.listener.on(ListenEvent_1.default.CLOUD, (asrResultsData) => {
this.asrResults = asrResultsData.result;
this.exitInputType = analytics.INPUT.SPEECH;
});
listen.listener.on(ListenEvent_1.default.INTERRUPTED, () => {
if (this.status !== Status_1.default.IN_PROGRESS ||
this.mimMachine.current !== this.states.listen) {
return;
}
listenDelegate.exitActiveMode();
this.states.listen.transitionTo(this.states.waitForHJEnd);
});
}
catch (err) {
if (this.status !== Status_1.default.IN_PROGRESS ||
this.mimMachine.current !== this.states.listen) {
return;
}
if (listen.failedToGetListener) {
log.error('Failed to get a listener a second time. Exiting skill');
Runtime_1.default.instance.lifecycle.finished();
}
else {
log.warn('Failed to get a listener. Trying again');
listen.failedToGetListener = true;
this.startListen(transition, resetTimeout);
}
return;
}
}
else {
log.debug('Skipping listener creation because silentMenus is true');
}
});
}
resetTimeout() {
if (this.listen) {
this.listen.startTime = Date.now();
}
}
stopListen() {
this.listenExit();
}
listenExit(transition) {
if (this.listen && this.listen.listener) {
const cancelTurn = !transition || (transition.getDestinationState() !== this.states.parseSpoof);
this.listen.listener.stop(cancelTurn);
this.listen.listener = null;
}
window.removeEventListener('touchstart', this.resetTimeout);
window.removeEventListener('touchmove', this.resetTimeout);
window.removeEventListener('mousedown', this.resetTimeout);
window.removeEventListener('mousemove', this.resetTimeout);
}
updateListen() {
const listen = this.listen;
if (listen && !listen.listener && listen.timeout &&
Date.now() - listen.startTime >= listen.timeout) {
this.asrResults = new jetstream_client_1.types.ListenResult(null);
if (this.checkResult) {
this.checkResult(this.asrResults);
}
this.states.listen.transitionTo(this.states.analyzeResults, true);
}
}
analyzeMimGlobal(transition, result) {
const intent = this.asrResults.intent;
if (intent === 'repeat' && this.entryPrompt.text) {
this.mimState.lastResultState = MimState_1.States.REPEAT;
this.repeatCount++;
this.states.analyzeMimGlobal.transitionTo(this.states.choosePrompt);
analytics.nonEndingResult(this.analyticsBase, this.exitInputType, intent, this.asrResults.text, this.asrResults.entities.domain, this.lastPromptId);
return;
}
if (intent === 'thanks' && this.mimConfig.thanksHandling !== MimConfig_1.ThanksOptions.IGNORE) {
this.mimState.lastResultState = MimState_1.States.THANKS;
this.states.analyzeMimGlobal.transitionTo(this.states.choosePrompt);
analytics.nonEndingResult(this.analyticsBase, this.exitInputType, intent, this.asrResults.text, this.asrResults.entities.domain, this.lastPromptId);
return;
}
analytics.nonEndingIgnored(this.analyticsBase, this.exitInputType, intent, this.asrResults.text, this.asrResults.entities.domain, this.lastPromptId);
this.asrResults.nlu = null;
this.states.analyzeMimGlobal.transitionTo(this.states.analyzeResults);
}
analyzeMenuGlobal(transition, result) {
const handled = Runtime_1.default.instance.face.views.actionEnactor(new ActionData_1.default(ActionData_1.default.VERBAL_COMMAND, this.asrResults));
if (handled) {
analytics.nonEndingResult(this.analyticsBase, this.exitInputType, this.asrResults.intent, this.asrResults.text, this.asrResults.entities.domain, this.lastPromptId);
if (this.mimMachine.current === this.states.analyzeMenuGlobal) {
this.states.analyzeMenuGlobal.transitionTo(this.states.listen, true);
}
return;
}
analytics.nonEndingIgnored(this.analyticsBase, this.exitInputType, this.asrResults.intent, this.asrResults.text, this.asrResults.entities.domain, this.lastPromptId);
this.asrResults.nlu = null;
this.states.analyzeMenuGlobal.transitionTo(this.states.analyzeResults);
}
parseSpoofedUtterance(transition, result) {
const listenDelegate = MimManager_1.default.instance.listenDelegate;
listenDelegate.exitActiveMode();
MimManager_1.default.instance.shouldShowGUI = true;
this.exitInputType = analytics.INPUT.TOUCH;
log.debug(`Screen Tapped - ${this.loggingLead} MIM total errors[${this.mimState.errors}] LastResultState[${this.mimState.lastResultState}]`);
Runtime_1.default.instance.performance.log('MimManualParseStart', 'Starting a manual NLU parse because a GUI event is spoofing an answer');
this.asrResults = new jetstream_client_1.types.ListenResult({
text: '',
confidence: 1
}, result);
if (this.checkResult) {
this.checkResult(this.asrResults);
}
this.states.parseSpoof.transitionTo(this.states.analyzeResults);
}
analyzeResults(transition, timedOut) {
const mimState = this.mimState;
const mimConfig = this.mimConfig;
if (timedOut || !this.asrResults) {
mimState.lastResultState = MimState_1.States.NO_INPUT;
this.exitInputType = analytics.INPUT.SILENCE;
}
else {
mimState.lastResultState = this.asrResults.state;
log.debug(`MIM Listen results - ${this.loggingLead} Last Prompt Id[${this.lastPromptId}] NLU Results[intent:${this.asrResults.intent}, ${JSON.stringify(this.asrResults.entities)}]`);
}
const listenDelegate = MimManager_1.default.instance.listenDelegate;
if (mimConfig.mimType === MimConfig_1.MimTypes.OPTIONAL_RESPONSE) {
if (mimConfig.ignoreNoMatch && mimState.lastResultState === MimState_1.States.NO_MATCH) {
this.states.analyzeResults.transitionTo(this.states.listen, false);
}
else {
mimState.success = true;
listenDelegate.exitActiveMode();
this.states.analyzeResults.transitionTo(this.states.reportResults);
}
return;
}
listenDelegate.exitActiveMode();
switch (mimState.lastResultState) {
case MimState_1.States.MATCH:
mimState.success = true;
break;
case MimState_1.States.NO_MATCH:
mimState.incrementNoMatchCount();
log.debug(`MIM Listen Error - ${this.loggingLead} No Match Count[${mimState.noMatchCount}]`);
analytics.noMatch(this.analyticsBase, mimState.noMatchCount, this.lastPromptId, this.asrResults.text);
if (!mimConfig.hasErrorPrompt(MimState_1.States.NO_MATCH, mimState.noMatchCount)) {
mimState.failure = true;
}
MimManager_1.default.instance.shouldShowGUI = true;
break;
case MimState_1.States.NO_INPUT:
mimState.incrementNoInputCount();
log.debug(`MIM Listen Error - ${this.loggingLead} No Input Count[${mimState.noInputCount}]`);
analytics.noInput(this.analyticsBase, mimState.noInputCount, this.lastPromptId);
if (!mimConfig.hasErrorPrompt(MimState_1.States.NO_INPUT, mimState.noInputCount)) {
mimState.failure = true;
}
MimManager_1.default.instance.shouldShowGUI = true;
break;
}
if (mimState.done) {
this.states.analyzeResults.transitionTo(this.states.reportResults);
}
else {
this.states.analyzeResults.transitionTo(this.states.choosePrompt);
}
}
reportResults(transition, result) {
this.cleanUpEvents();
this.viewTransition = {
remove: true,
transitionClose: ViewManager_1.TRANSITION.DOWN
};
if (this.mimState.failure) {
let result = false;
if (this.viewConfig && this.viewConfig.defaultClose) {
this.viewTransition = this.viewConfig.defaultClose;
}
if (this.onFailure) {
result = this.onFailure({
state: this.mimState,
asrResults: this.asrResults
});
}
if (!result) {
const exceptionData = {
state: this.mimState.lastResultState,
input: this.asrResults ? this.asrResults.text : ''
};
this.states.reportResults.transitionTo(this.states.handleException, exceptionData);
return;
}
let exitType;
let inputType;
if (this.mimState.lastResultState === MimState_1.States.NO_INPUT) {
exitType = analytics.EXIT_TYPE.MAX_NI;
inputType = analytics.INPUT.SILENCE;
}
else {
exitType = analytics.EXIT_TYPE.MAX_NM;
inputType = analytics.INPUT.SPEECH;
}
analytics.end(this.analyticsBase, exitType, inputType, '', this.asrResults ? this.asrResults.text : '', '', this.lastPromptId, this.mimState.noMatchCount, this.mimState.noInputCount);
}
else {
if (this.viewConfig && this.viewConfig.defaultSelect) {
this.viewTransition = this.viewConfig.defaultSelect;
}
if (this.onSuccess) {
this.onSuccess({
state: this.mimState,
asrResults: this.asrResults
});
}
let intent = '';
if (this.mimState.lastResultState !== MimState_1.States.NO_INPUT &&
this.asrResults && this.asrResults && this.asrResults.intent) {
intent = this.asrResults.intent;
}
if (this.mimConfig.mimType === MimConfig_1.MimTypes.ANNOUNCEMENT) {
intent = analytics.NONE;
this.exitInputType = analytics.INPUT.NONE;
}
analytics.end(this.analyticsBase, analytics.EXIT_TYPE.SUCCESS, this.exitInputType, intent, this.asrResults ? this.asrResults.text : '', '', this.lastPromptId, this.mimState.noMatchCount, this.mimState.noInputCount);
}
this.unloadRules();
this.removeView();
if (this.destroyViewPromise) {
Runtime_1.default.instance.performance.log('MimEndViewRemovalStart', 'Waiting for the Mim GUI to be cleaned up before ending the Mim');
this.destroyViewPromise.then(() => {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
Runtime_1.default.instance.performance.log('MimEndViewRemovalEnd');
this.status = Status_1.default.SUCCEEDED;
});
}
else {
this.status = Status_1.default.SUCCEEDED;
}
}
handleException(transition, result) {
const state = result.state;
if (state === MimState_1.States.NO_INPUT) {
this.exceptionFlow = Runtime_1.default.instance.flow.create(NoInputException, {
assetPack: 'core://',
blackboard: {
speechDelegate: MimManager_1.default.instance.speakDelegate
}
});
}
else if (state === MimState_1.States.NO_MATCH) {
this.exceptionFlow = Runtime_1.default.instance.flow.create(NoMatchException, {
assetPack: 'core://',
blackboard: {
showInputText: this.showInputText.bind(this, result.input),
hideInputText: this.hideInputText.bind(this),
speechDelegate: MimManager_1.default.instance.speakDelegate
}
});
}
else if (state === MimState_1.States.MENU_CLOSED) {
Runtime_1.default.instance.lifecycle.finished();
}
}
updateException() {
if (this.exceptionFlow && this.exceptionFlow.update()) {
const result = this.exceptionFlow.result.transition;
this.exceptionFlow.destroy();
this.exceptionFlow = null;
if (result === 'exit') {
Runtime_1.default.instance.lifecycle.finished();
}
else if (result === 'restart') {
analytics.recoveredException(this.analyticsBase);
this.mimState.reset();
this.mimState.lastResultState = MimState_1.States.HOLD_RETURN;
this.states.handleException.transitionTo(this.states.choosePrompt);
}
}
}
stopException() {
if (this.exceptionFlow) {
this.exceptionFlow.destroy();
this.exceptionFlow = null;
}
this.hideInputText();
}
showInputText(notMatchedText) {
const viewConfig = {
viewConfig: {
type: "View",
id: "mim_not_matched_text"
},
componentConfigs: [
{
id: "title",
type: "Label",
text: notMatchedText,
style: {
fontSize: "100",
fontFamily: "Proxima Nova Soft",
fontStyle: "bold",
fill: "#FFFFFF",
wordWrap: true,
wordWrapWidth: 1240,
align: 'center'
},
position: {
x: FaceRenderer_1.default.WIDTH / 2,
y: FaceRenderer_1.default.HEIGHT / 2
},
targetAnchor: {
x: 0.5,
y: 0.5
}
}
]
};
if (this.destroyViewPromise) {
this.destroyViewPromise.then(() => {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
this.activeView = Runtime_1.default.instance.face.views.createView("View", viewConfig, true);
});
}
else {
this.activeView = Runtime_1.default.instance.face.views.createView("View", viewConfig, true);
}
this.viewTransition = {
remove: true,
transitionClose: ViewManager_1.TRANSITION.DOWN
};
}
hideInputText() {
this.removeView();
}
waitForHJEnd(transition, result) {
MimManager_1.default.instance.heyJiboComplete.on(this.recoverFromHJ);
}
recoverFromHJ(reason) {
if (this.lastPromptId) {
this.mimState.lastResultState = MimState_1.States.HOLD_RETURN;
}
if (this.queuedState) {
const queuedState = this.queuedState;
this.queuedState = null;
this.states.waitForHJEnd.transitionTo(queuedState.state, queuedState.data);
}
else if (this.isMenu) {
this.states.waitForHJEnd.transitionTo(this.states.listen, false);
}
else {
this.states.waitForHJEnd.transitionTo(this.states.choosePrompt);
}
}
hjEnded() {
MimManager_1.default.instance.heyJiboComplete.off(this.recoverFromHJ);
}
}
exports.default = Mim;
},{"../../Runtime":1,"../../rendering/FaceRenderer":99,"../../rendering/gui/ViewManager":127,"../../rendering/gui/actions/ActionData":130,"../../rendering/gui/views/EyeView":151,"../../rendering/gui/views/MenuView":153,"../../rendering/gui/views/View":156,"../Behavior":3,"../Status":10,"../mim/GenerateListConfig":50,"../mim/MimConfig":51,"../mim/MimManager":52,"../mim/MimState":55,"../mim/analytics/MimAnalytics":58,"../mim/delegates/ListenEvent":60,"../mim/flows/NoInputException":61,"../mim/flows/NoMatchException":62,"./log":32,"@jibo/jetstream-client":undefined,"fs":undefined,"jibo-embodied-dialog":undefined,"jibo-plugins":undefined,"jibo-state-machine":undefined,"uuid":undefined}],17:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
class Null extends Behavior_1.default {
update() {
return Status_1.default.IN_PROGRESS;
}
}
exports.default = Null;
},{"../Behavior":3,"../Status":10}],18:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ParentBehavior_1 = require("../ParentBehavior");
const Status_1 = require("../Status");
class Parallel extends ParentBehavior_1.default {
constructor(options) {
super(options);
this.runChildren = null;
this.activeChildren = 0;
this.childStops = [];
this.stopping = false;
}
destroy() {
super.destroy();
this.runChildren = null;
this.childStops = null;
}
start() {
if (this.children.length === 0) {
return false;
}
let oneFailedToStart = false;
this.runChildren = [];
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
if (child._start()) {
this.runChildren.push(child);
}
else {
oneFailedToStart = true;
}
}
this.activeChildren = this.runChildren.length;
if (oneFailedToStart) {
for (let i = 0; i < this.runChildren.length; i++) {
this.runChildren[i]._stop();
}
return false;
}
return true;
}
stop() {
for (let i = 0; i < this.runChildren.length; i++) {
if (!this.runChildren[i]) {
continue;
}
this.childStops.push(this.runChildren[i]._stop());
}
if (this.childStops.length === 0) {
return Promise.resolve();
}
return Promise.all(this.childStops);
}
update() {
if (this.stopping) {
return Status_1.default.IN_PROGRESS;
}
let oneFailed = false;
for (let i = 0; i < this.runChildren.length; i++) {
if (!this.runChildren[i]) {
continue;
}
const child = this.runChildren[i];
const status = child._update();
if (status === Status_1.default.SUCCEEDED) {
if (this.options.succeedOnOne) {
this.stopping = true;
this._stop().then(() => {
this._currentStatus = Status_1.default.SUCCEEDED;
this.stopping = false;
});
this._currentStatus = Status_1.default.IN_PROGRESS;
return Status_1.default.IN_PROGRESS;
}
else {
this.childStops.push(child._stop());
this.runChildren[i] = null;
this.activeChildren--;
}
}
else if (status === Status_1.default.FAILED) {
oneFailed = true;
}
else if (status === Status_1.default.PAUSED) {
return Status_1.default.IN_PROGRESS;
}
}
if (oneFailed) {
return Status_1.default.FAILED;
}
else if (this.activeChildren === 0) {
return Status_1.default.SUCCEEDED;
}
else {
return Status_1.default.IN_PROGRESS;
}
}
}
exports.default = Parallel;
},{"../ParentBehavior":9,"../Status":10}],19:[function(require,module,exports){
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
const Runtime_1 = require("../../Runtime");
const jibo_plugins_1 = require("jibo-plugins");
var AnimSelector;
(function (AnimSelector) {
AnimSelector[AnimSelector["path"] = 1] = "path";
AnimSelector[AnimSelector["pathFunction"] = 2] = "pathFunction";
AnimSelector[AnimSelector["name"] = 3] = "name";
AnimSelector[AnimSelector["query"] = 4] = "query";
AnimSelector[AnimSelector["nameFunction"] = 5] = "nameFunction";
})(AnimSelector || (AnimSelector = {}));
class MockBuilder {
constructor() {
this.options = {};
}
setSpeed(speed) {
this.options.speed = speed;
}
setNumLoops(numLoops) {
this.options.loops = numLoops;
}
setDOFs(dofNames) {
if (dofNames instanceof Array) {
const dofs = Runtime_1.default.instance.expression.dofs.ALL.createFromDofs(dofNames);
this.options.dofs = dofs;
}
else {
this.options.dofs = dofNames;
}
}
setLayer(layerName) {
this.options.layer = layerName;
}
}
class PlayAnimation extends Behavior_1.default {
constructor(options) {
super(options);
this.stoppedCallbacks = [];
this.destroyed = false;
this.status = Status_1.default.INVALID;
this.animation = null;
this.instance = null;
this.onEvent = this.onEvent.bind(this);
if (typeof this.options.animSelector === 'undefined') {
this.options.animSelector = AnimSelector.path;
}
this.animSelector = this.options.animSelector;
switch (this.animSelector) {
case AnimSelector.path:
this._constructorFromPath(this.options.animPath);
break;
case AnimSelector.pathFunction:
this._constructorFromPath(this.options.animPathFunction());
break;
case AnimSelector.name:
this._constructorFromAnimName(this.options.animName);
break;
case AnimSelector.nameFunction:
this._constructorFromAnimName(this.options.animNameFunction());
break;
case AnimSelector.query:
this._constructorFromAnimQuery();
break;
}
}
_constructorFromPath(animPath) {
if (typeof this.options.upload === 'undefined') {
this.options.upload = true;
}
this.alias = jibo_plugins_1.PathUtils.setDefaultPath('animations', animPath);
}
_constructorFromAnimName(name) {
this.anim = Runtime_1.default.instance.animDB.getAnimByName(name);
}
_constructorFromAnimQuery() {
let results = Runtime_1.default.instance.animDB.query(this.options.queryParams());
this.anim = this.options.queryResultSelector(results);
}
start() {
this.hasBeenReset = false;
this.status = Status_1.default.IN_PROGRESS;
if (this.options.config) {
this.builder = new MockBuilder();
this.options.config(this.builder);
}
const eye = Runtime_1.default.instance.face.eye;
switch (this.animSelector) {
case AnimSelector.path:
eye.holdCurrentAnim();
this._startFromPath();
return true;
case AnimSelector.pathFunction:
eye.holdCurrentAnim();
this._startFromPath();
return true;
default:
if (!this.anim) {
this.status = Status_1.default.FAILED;
return false;
}
eye.holdCurrentAnim();
this._startFromAnimDB();
return true;
}
}
_startFromPath() {
return __awaiter(this, void 0, void 0, function* () {
try {
const loader = Runtime_1.default.instance.loader;
const src = jibo_plugins_1.PathUtils.getAssetUri(this.alias, this.assetPack);
let loadData = {
id: this.alias,
cache: loader.activeCache,
src: src,
options: this.builder.options,
upload: this.options.upload,
root: jibo_plugins_1.PathUtils.findRoot(src),
type: 'keys',
complete: null
};
const data = yield new Promise((resolve, reject) => {
loadData.complete = (err, data) => {
if (err) {
return reject(err);
}
resolve(data);
};
const load = loader.load(loadData);
this.loadToken = load.tokens[0];
});
if (this.status !== Status_1.default.IN_PROGRESS) {
loader.unload(this.loadToken);
return;
}
let animation = yield data.getAnim(this.builder.options);
if (this.status !== Status_1.default.IN_PROGRESS) {
loader.unload(this.loadToken);
animation.destroy();
return;
}
this.onKeysLoaded(animation);
}
catch (err) {
console.error('Could not load animation in PlayAnimation: ', err);
this.onStopped(Status_1.default.FAILED);
}
});
}
_startFromAnimDB() {
return __awaiter(this, void 0, void 0, function* () {
let opts = this.options.creationOptions();
if (!opts) {
opts = {};
}
if (!opts.cache) {
opts.cache = Runtime_1.default.instance.loader.activeCache;
}
const playbackResult = this.anim.play(opts, this.options.playbackOptions());
if (this.status !== Status_1.default.IN_PROGRESS) {
playbackResult.playback.stop();
}
else {
this.instance = playbackResult.playback;
try {
yield playbackResult.result;
this.onStopped(Status_1.default.SUCCEEDED);
}
catch (error) {
console.error('Error in PlayAnimation when playing from animdb: ', error);
this.onStopped(Status_1.default.FAILED);
}
}
});
}
update() {
return this.status;
}
stop() {
if (this.instance) {
return new Promise((resolve) => {
this.stoppedCallbacks.push(resolve);
this.instance.stop();
});
}
else {
this.reset();
return Promise.resolve();
}
}
destroy() {
if (!this.destroyed) {
this.destroyed = true;
this.reset();
super.destroy();
this.status = null;
this.stoppedCallbacks = null;
}
}
onKeysLoaded(animation) {
if (this.status !== Status_1.default.IN_PROGRESS) {
if (animation) {
animation.destroy();
}
return;
}
this.animation = animation;
Runtime_1.default.instance.face.eye.addAnimation(animation);
this.animation.instance.events.stopped.on(() => this.onStopped(Status_1.default.SUCCEEDED));
this.animation.instance.events.cancelled.on(() => this.onStopped(Status_1.default.SUCCEEDED));
this.animation.instance.events.rejected.on(() => {
console.warn(`Animation rejected because of dofArbiter priority`);
this.onStopped(Status_1.default.FAILED);
});
this.animation.instance.events.general.on(this.onEvent);
this.animation.instance.play().catch(error => {
console.error('Error in PlayAnimation: ', error);
this.onStopped(Status_1.default.FAILED);
});
}
reset() {
if (this.hasBeenReset) {
return;
}
if (this.loadToken) {
this.loadToken.unload();
this.loadToken = null;
}
if (this.animation) {
Runtime_1.default.instance.face.eye.removeAnimation(this.animation);
this.animation.removeAllListeners();
}
this.animation = null;
this.instance = null;
this.hasBeenReset = true;
}
onStopped(status) {
if (!this.destroyed) {
this.reset();
this.status = status;
for (let i = 0; i < this.stoppedCallbacks.length; i++) {
this.stoppedCallbacks[i]();
}
this.stoppedCallbacks = [];
}
}
onEvent(payload) {
if (!this.destroyed) {
Runtime_1.default.instance.behaviorEmitter.emit(payload.eventName, payload.payload);
}
}
}
exports.default = PlayAnimation;
},{"../../Runtime":1,"../Behavior":3,"../Status":10,"jibo-plugins":undefined}],20:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
const jibo_plugins_1 = require("jibo-plugins");
const Runtime_1 = require("../../Runtime");
class PlayAudio extends Behavior_1.default {
constructor(options) {
super(options);
if (typeof this.options.cache === 'undefined') {
this.options.cache = true;
}
this.status = Status_1.default.INVALID;
this.alias = this.options.audioPath;
this.cache = this.options.cache;
this.sound = null;
this.token = null;
}
start() {
this.status = Status_1.default.IN_PROGRESS;
const loader = Runtime_1.default.instance.loader;
const load = loader.load({
type: 'sound',
id: this.alias,
src: jibo_plugins_1.PathUtils.getAudioUri(this.alias, this.assetPack),
cache: loader.activeCache,
complete: this.onLoaded.bind(this)
});
this.token = load.tokens[0];
return true;
}
stop() {
if (this.sound) {
this.sound.stop();
this.sound = null;
}
if (!this.cache && this.token) {
this.token.unload();
this.token = null;
}
return Promise.resolve();
}
update() {
return this.status;
}
destroy() {
this.stop();
if (this.token) {
this.token.unload();
this.token = null;
}
super.destroy();
this.status = null;
}
onLoaded(err, sound) {
if (err) {
throw err;
}
if (this.status !== Status_1.default.IN_PROGRESS) {
if (!this.cache && this.token) {
this.token.unload();
this.token = null;
}
return;
}
this.sound = sound;
this.sound.play(() => {
this.stop();
this.status = Status_1.default.SUCCEEDED;
});
}
}
exports.default = PlayAudio;
},{"../../Runtime":1,"../Behavior":3,"../Status":10,"jibo-plugins":undefined}],21:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ParentBehavior_1 = require("../ParentBehavior");
const Status_1 = require("../Status");
class Random extends ParentBehavior_1.default {
constructor(options) {
super(options);
this.current = -1;
}
start() {
if (this.children.length === 0) {
return false;
}
this.current = Math.round(Math.random() * (this.children.length - 1));
const success = this.children[this.current]._start();
this.current = success ? this.current : -1;
return success;
}
stop() {
let rtn;
if (this.current !== -1 && this.current < this.children.length) {
rtn = this.children[this.current]._stop();
this.current = -1;
}
return rtn || Promise.resolve();
}
update() {
const status = this.children[this.current]._update();
if (status === Status_1.default.PAUSED) {
return Status_1.default.IN_PROGRESS;
}
return status;
}
}
exports.default = Random;
},{"../ParentBehavior":9,"../Status":10}],22:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
const Runtime_1 = require("../../Runtime");
class ReadBarcode extends Behavior_1.default {
constructor(options) {
super(options);
this.status = Status_1.default.INVALID;
}
start() {
this.status = Status_1.default.IN_PROGRESS;
Runtime_1.default.instance.lps.readBarcode((error, data) => {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
this.options.onBarcode(error, data);
this.status = Status_1.default.SUCCEEDED;
});
return true;
}
update() {
return this.status;
}
destroy() {
super.destroy();
this.status = null;
}
}
exports.default = ReadBarcode;
},{"../../Runtime":1,"../Behavior":3,"../Status":10}],23:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ParentBehavior_1 = require("../ParentBehavior");
const Status_1 = require("../Status");
class Sequence extends ParentBehavior_1.default {
constructor(options) {
super(options);
this.current = -1;
}
start() {
if (this.children.length === 0) {
return true;
}
this.current = 0;
const success = this.children[this.current]._start();
this.current = success ? this.current : -1;
return success;
}
stop() {
let rtn;
if (this.current !== -1 && this.current < this.children.length) {
rtn = this.children[this.current]._stop();
this.current = -1;
}
return rtn || Promise.resolve();
}
update() {
if (this.children.length === 0) {
return Status_1.default.SUCCEEDED;
}
while (this.current !== -1 && this.current < this.children.length) {
const childStatus = this.children[this.current]._update();
if (childStatus === Status_1.default.SUCCEEDED) {
this.current++;
if (this.current < this.children.length) {
const startSuccess = this.children[this.current]._start();
if (!startSuccess) {
return Status_1.default.FAILED;
}
}
else {
return Status_1.default.SUCCEEDED;
}
}
else if (childStatus === Status_1.default.IN_PROGRESS || childStatus === Status_1.default.PAUSED) {
return Status_1.default.IN_PROGRESS;
}
else {
return Status_1.default.FAILED;
}
}
return Status_1.default.SUCCEEDED;
}
}
exports.default = Sequence;
},{"../ParentBehavior":9,"../Status":10}],24:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
const Runtime_1 = require("../../Runtime");
const jibo_plugins_1 = require("jibo-plugins");
class Subtree extends Behavior_1.default {
constructor(options) {
super(options);
this.status = Status_1.default.INVALID;
this.root = null;
}
set tree(tree) {
this.options.behaviorPath = () => {
return tree;
};
}
start() {
this.status = Status_1.default.IN_PROGRESS;
let tree;
if (typeof this.options.behaviorPath === 'function') {
tree = this.options.behaviorPath();
}
else {
tree = jibo_plugins_1.PathUtils.getAssetUri(this.options.behaviorPath, this.assetPack);
}
this.root = Runtime_1.default.instance.bt.create(tree, {
notepad: this.options.getNotepad(),
blackboard: this.blackboard,
assetPack: this.assetPack
});
this.status = this.root.start() ? this.status : Status_1.default.FAILED;
return true;
}
stop() {
if (this.root) {
return this.root.stop();
}
return Promise.resolve();
}
update() {
if (this.status === Status_1.default.FAILED) {
this.root.destroy();
this.root = null;
return this.status;
}
if (!this.root) {
return this.status;
}
let status = this.root.update();
if (status === Status_1.default.SUCCEEDED || status === Status_1.default.FAILED) {
this.options.onResult(this.root.result);
this.root.destroy();
this.root = null;
}
return status;
}
destroy() {
super.destroy();
if (this.root) {
this.root.destroy();
this.root = null;
}
}
}
exports.default = Subtree;
},{"../../Runtime":1,"../Behavior":3,"../Status":10,"jibo-plugins":undefined}],25:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Subtree_1 = require("./Subtree");
class SubtreeJs extends Behavior_1.default {
constructor(options) {
super(options);
this.subtree = new Subtree_1.default({
name: this.name,
getNotepad: options.getNotepad,
onResult: options.onResult,
blackboard: this.blackboard,
emitter: this.emitter,
assetPack: this.assetPack
});
}
start() {
this.options.getTree((createTree) => {
this.subtree.tree = createTree;
this.subtree._start();
});
return true;
}
stop() {
return this.subtree._stop();
}
update() {
return this.subtree._update();
}
destroy() {
super.destroy();
if (this.subtree) {
this.subtree.destroy();
this.subtree = null;
}
}
}
exports.default = SubtreeJs;
},{"../Behavior":3,"./Subtree":24}],26:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ParentBehavior_1 = require("../ParentBehavior");
const Status_1 = require("../Status");
class Switch extends ParentBehavior_1.default {
constructor(options) {
super(options);
this.current = -1;
}
start() {
if (this.children.length === 0) {
return false;
}
this.current = 0;
return this.findStart();
}
findStart() {
let startOk = false;
while (!startOk && this.current < this.children.length) {
startOk = this.children[this.current]._start();
if (!startOk) {
this.current++;
}
}
return true;
}
stop() {
let rtn;
if (this.current !== -1 && this.current < this.children.length) {
rtn = this.children[this.current]._stop();
this.current = -1;
}
return rtn || Promise.resolve();
}
update() {
if (this.current !== -1 && this.current < this.children.length) {
const childStatus = this.children[this.current]._update();
if (childStatus === Status_1.default.FAILED) {
this.current++;
if (this.current >= this.children.length || !this.findStart()) {
return Status_1.default.SUCCEEDED;
}
else {
return Status_1.default.IN_PROGRESS;
}
}
else if (childStatus === Status_1.default.PAUSED) {
return Status_1.default.IN_PROGRESS;
}
return childStatus;
}
return Status_1.default.SUCCEEDED;
}
}
exports.default = Switch;
},{"../ParentBehavior":9,"../Status":10}],27:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
const Runtime_1 = require("../../Runtime");
class TakePhoto extends Behavior_1.default {
constructor(options) {
super(options, {
noDistortion: true
});
this.status = Status_1.default.INVALID;
}
start() {
this.status = Status_1.default.IN_PROGRESS;
let params = {
camera: this.options.camera,
photoType: this.options.resolution
};
Runtime_1.default.instance.media.takePhoto(params, (error, data) => {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
if (error) {
this.onPhoto(error, null);
this.status = Status_1.default.SUCCEEDED;
return;
}
else {
let imageUrl = Runtime_1.default.instance.media.getPreviewUrl(data.id);
this.onPhoto(null, imageUrl);
}
});
return true;
}
update() {
return this.status;
}
destroy() {
super.destroy();
this.status = null;
}
onPhoto(error, imageUrl) {
this.options.onPhoto(error, imageUrl);
this.status = Status_1.default.SUCCEEDED;
}
}
exports.default = TakePhoto;
},{"../../Runtime":1,"../Behavior":3,"../Status":10}],28:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
const Runtime_1 = require("../../Runtime");
class TextToSpeech extends Behavior_1.default {
constructor(options) {
super(options);
this.onSpeakingStopped = this.onSpeakingStopped.bind(this);
this.status = Status_1.default.INVALID;
}
start() {
const tts = Runtime_1.default.instance.tts;
this.status = Status_1.default.IN_PROGRESS;
tts.speak(this.options.words, (err) => {
this.status = Status_1.default.SUCCEEDED;
if (err) {
console.log("tts.speak() error: " + err);
}
});
this.cleanup();
tts.word.on(this.options.onWord);
tts.stopped.on(this.onSpeakingStopped);
return true;
}
stop() {
this.cleanup();
return Promise.resolve();
}
update() {
if (this.status !== Status_1.default.IN_PROGRESS) {
this.cleanup();
}
return this.status;
}
destroy() {
super.destroy();
this.status = null;
}
set words(words) {
this.options.words = words;
}
onSpeakingStopped() {
this.status = Status_1.default.SUCCEEDED;
}
cleanup() {
const tts = Runtime_1.default.instance.tts;
tts.stopped.off(this.onSpeakingStopped);
tts.word.off(this.options.onWord);
}
}
exports.default = TextToSpeech;
},{"../../Runtime":1,"../Behavior":3,"../Status":10}],29:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const TextToSpeech_1 = require("./TextToSpeech");
class TextToSpeechJs extends Behavior_1.default {
constructor(options) {
super(options);
this.behavior = new TextToSpeech_1.default({
emitter: this.emitter,
blackboard: this.blackboard,
onWord: this.options.onWord,
assetPack: this.assetPack
});
}
start() {
this.options.getWords((words) => {
this.behavior.words = words;
this.behavior._start();
});
return true;
}
stop() {
return this.behavior._stop();
}
update() {
return this.behavior._update();
}
destroy() {
super.destroy();
if (this.behavior) {
this.behavior.destroy();
this.behavior = null;
}
}
}
exports.default = TextToSpeechJs;
},{"../Behavior":3,"./TextToSpeech":28}],30:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Behavior_1 = require("../Behavior");
const Status_1 = require("../Status");
const Null_1 = require("./Null");
const TimeoutSucceedJs_1 = require("../decorators/TimeoutSucceedJs");
class TimeoutJs extends Behavior_1.default {
constructor(options) {
super(options);
let decorator = new TimeoutSucceedJs_1.default({
getTime: options.getTime
});
this.behavior = new Null_1.default({
decorators: [decorator]
});
this.status = Status_1.default.INVALID;
}
start() {
this.status = Status_1.default.IN_PROGRESS;
return this.behavior._start();
}
stop() {
return this.behavior._stop();
}
update() {
this.status = this.behavior._update();
return this.status;
}
destroy() {
super.destroy();
if (this.behavior) {
this.behavior.destroy();
this.behavior = null;
}
}
}
exports.default = TimeoutJs;
},{"../Behavior":3,"../Status":10,"../decorators/TimeoutSucceedJs":45,"./Null":17}],31:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Blink_1 = require("./Blink");
const ExecuteScript_1 = require("./ExecuteScript");
const ExecuteScriptAsync_1 = require("./ExecuteScriptAsync");
const LookAt_1 = require("./LookAt");
const Mim_1 = require("./Mim");
const Menu_1 = require("./Menu");
const Null_1 = require("./Null");
const Parallel_1 = require("./Parallel");
const PlayAnimation_1 = require("./PlayAnimation");
const PlayAudio_1 = require("./PlayAudio");
const Random_1 = require("./Random");
const ReadBarcode_1 = require("./ReadBarcode");
const Sequence_1 = require("./Sequence");
const Subtree_1 = require("./Subtree");
const SubtreeJs_1 = require("./SubtreeJs");
const Switch_1 = require("./Switch");
const TakePhoto_1 = require("./TakePhoto");
const TextToSpeech_1 = require("./TextToSpeech");
const TextToSpeechJs_1 = require("./TextToSpeechJs");
const TimeoutJs_1 = require("./TimeoutJs");
exports.default = {
Blink: Blink_1.default,
ExecuteScript: ExecuteScript_1.default,
ExecuteScriptAsync: ExecuteScriptAsync_1.default,
LookAt: LookAt_1.default,
Mim: Mim_1.default,
Menu: Menu_1.default,
Null: Null_1.default,
Parallel: Parallel_1.default,
PlayAnimation: PlayAnimation_1.default,
PlayAudio: PlayAudio_1.default,
Random: Random_1.default,
ReadBarcode: ReadBarcode_1.default,
Sequence: Sequence_1.default,
Subtree: Subtree_1.default,
SubtreeJs: SubtreeJs_1.default,
Switch: Switch_1.default,
TakePhoto: TakePhoto_1.default,
TextToSpeech: TextToSpeech_1.default,
TextToSpeechJs: TextToSpeechJs_1.default,
TimeoutJs: TimeoutJs_1.default
};
},{"./Blink":11,"./ExecuteScript":12,"./ExecuteScriptAsync":13,"./LookAt":14,"./Menu":15,"./Mim":16,"./Null":17,"./Parallel":18,"./PlayAnimation":19,"./PlayAudio":20,"./Random":21,"./ReadBarcode":22,"./Sequence":23,"./Subtree":24,"./SubtreeJs":25,"./Switch":26,"./TakePhoto":27,"./TextToSpeech":28,"./TextToSpeechJs":29,"./TimeoutJs":30}],32:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
exports.default = log_1.default.createChild('Behaviors');
},{"../log":49}],33:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
class Case extends Decorator_1.default {
start() {
return this.options.conditional();
}
update(result) {
return result;
}
}
exports.default = Case;
},{"../Decorator":7}],34:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
class FailOnCondition extends Decorator_1.default {
constructor(options) {
super(options, {
init: function () { }
});
}
start() {
this.options.init();
if (this.options.conditional()) {
return false;
}
return true;
}
update(result) {
if (this.options.conditional()) {
return Status_1.default.FAILED;
}
return result;
}
}
exports.default = FailOnCondition;
},{"../Decorator":7,"../Status":10}],35:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
const Runtime_1 = require("../../Runtime");
class StartOnAnimEvent extends Decorator_1.default {
constructor(options) {
super(options);
this.didStart = false;
this._onEvent = this._onEvent.bind(this);
}
start() {
this.didStart = false;
if (this.options.eventName.length !== 0) {
Runtime_1.default.instance.behaviorEmitter.on(this.options.eventName, this._onEvent);
}
return Status_1.default.WAIT;
}
stop() {
if (this.options.eventName.length !== 0) {
Runtime_1.default.instance.behaviorEmitter.removeListener(this.options.eventName, this._onEvent);
}
return Promise.resolve();
}
update(result) {
if (this.didStart) {
return result;
}
else {
return Status_1.default.WAIT;
}
}
destroy() {
super.destroy();
this._onEvent = null;
}
_onEvent(animInstance, payload) {
if (this.options.onReceived) {
this.options.onReceived(animInstance, payload);
}
this.didStart = true;
Runtime_1.default.instance.behaviorEmitter.removeListener(this.options.eventName, this._onEvent);
}
}
exports.default = StartOnAnimEvent;
},{"../../Runtime":1,"../Decorator":7,"../Status":10}],36:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
class StartOnCondition extends Decorator_1.default {
constructor(options) {
super(options, {
init: function () { }
});
this.didStart = false;
}
start() {
this.options.init();
this.didStart = false;
if (this.options.conditional()) {
this.didStart = true;
return true;
}
else {
return Status_1.default.WAIT;
}
}
update(result) {
if (this.didStart) {
return result;
}
else if (this.options.conditional()) {
this.didStart = true;
return result;
}
else {
return Status_1.default.WAIT;
}
}
}
exports.default = StartOnCondition;
},{"../Decorator":7,"../Status":10}],37:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
class StartOnEvent extends Decorator_1.default {
constructor(options) {
super(options);
this._onEvent = this._onEvent.bind(this);
}
start() {
this.emitter.once(this.options.eventName, this._onEvent);
this.didStart = false;
return Status_1.default.WAIT;
}
stop() {
this.emitter.removeListener(this.options.eventName, this._onEvent);
return Promise.resolve();
}
update(result) {
if (this.didStart) {
return result;
}
else {
return Status_1.default.WAIT;
}
}
destroy() {
super.destroy();
this._onEvent = null;
}
_onEvent() {
this.options.onEvent.apply(null, arguments);
this.didStart = true;
}
}
exports.default = StartOnEvent;
},{"../Decorator":7,"../Status":10}],38:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
class SucceedOnCondition extends Decorator_1.default {
constructor(options) {
super(options, {
init: function () { }
});
}
start() {
this.options.init();
return true;
}
update(result) {
if (this.options.conditional()) {
return Status_1.default.SUCCEEDED;
}
return result;
}
}
exports.default = SucceedOnCondition;
},{"../Decorator":7,"../Status":10}],39:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
const events_1 = require("events");
const Runtime_1 = require("../../Runtime");
class SucceedOnEmbedded extends Decorator_1.default {
constructor(options) {
super(options);
this.status = Status_1.default.INVALID;
this._onHeyJibo = this.onHeyJibo.bind(this);
}
start() {
this.emitter = new events_1.EventEmitter();
this.status = Status_1.default.IN_PROGRESS;
Runtime_1.default.instance.jetstream.events.hjHeard.on(this._onHeyJibo);
this.options.onResult(this.emitter);
this.status = Status_1.default.IN_PROGRESS;
return true;
}
stop() {
this.emitter.removeAllListeners();
Runtime_1.default.instance.jetstream.events.hjHeard.off(this._onHeyJibo);
return Promise.resolve();
}
update(result) {
if (this.status === Status_1.default.IN_PROGRESS) {
return result;
}
else {
return this.status;
}
}
destroy() {
this.stop();
this._onHeyJibo = null;
super.destroy();
}
onHeyJibo(data) {
this.emitter.emit('hey-jibo');
this.emitter.removeAllListeners();
this.status = Status_1.default.SUCCEEDED;
Runtime_1.default.instance.jetstream.events.hjHeard.off(this._onHeyJibo);
}
}
SucceedOnEmbedded.RULES = {
HEY_jibo: "hey_jibo"
};
exports.default = SucceedOnEmbedded;
},{"../../Runtime":1,"../Decorator":7,"../Status":10,"events":undefined}],40:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
class SucceedOnEvent extends Decorator_1.default {
constructor(options) {
super(options);
this._onEvent = this._onEvent.bind(this);
this.status = Status_1.default.INVALID;
}
start() {
this.emitter.once(this.options.eventName, this._onEvent);
this.status = Status_1.default.IN_PROGRESS;
return true;
}
stop() {
this.emitter.removeListener(this.options.eventName, this._onEvent);
return Promise.resolve();
}
update(result) {
if (this.status === Status_1.default.SUCCEEDED) {
return Status_1.default.SUCCEEDED;
}
return result;
}
destroy() {
super.destroy();
this._onEvent = null;
}
_onEvent() {
this.options.onEvent.apply(null, arguments);
this.status = Status_1.default.SUCCEEDED;
}
}
exports.default = SucceedOnEvent;
},{"../Decorator":7,"../Status":10}],41:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
const SucceedOnListenJs_1 = require("./SucceedOnListenJs");
const jibo_plugins_1 = require("jibo-plugins");
const fs = require("fs");
const path = require("path");
class SucceedOnListen extends Decorator_1.default {
constructor(options) {
super(options);
this.status = Status_1.default.INVALID;
this.options.rule = options.rule;
if (!/\brules[\/\\]/.test(this.options.rule)) {
this.options.rule = jibo_plugins_1.PathUtils.setDefaultPath('rules', options.rule);
}
this.decorator = null;
}
start() {
this.status = Status_1.default.IN_PROGRESS;
let getRule = (callback) => {
let uri = jibo_plugins_1.PathUtils.getAssetUri(this.options.rule, this.assetPack);
if (path.extname(uri) === '.fst') {
callback(uri);
}
else {
fs.readFile(uri, 'utf8', (err, data) => {
if (err) {
console.error('Rule file does not exist: ' + uri);
}
callback(data);
});
}
};
this.decorator = new SucceedOnListenJs_1.default({
getOptions: this.options.getOptions,
getRule: getRule,
onResult: this.options.onResult,
emitter: this.emitter,
blackboard: this.blackboard,
assetPack: this.assetPack
});
return this.decorator._start();
}
stop() {
if (this.decorator) {
return this.decorator._stop();
}
return Promise.resolve();
}
update(result) {
if (this.decorator) {
let status = this.decorator._update(result);
return status;
}
return this.status;
}
destroy() {
super.destroy();
if (this.decorator) {
this.decorator.destroy();
this.decorator = null;
}
}
}
exports.default = SucceedOnListen;
},{"../Decorator":7,"../Status":10,"./SucceedOnListenJs":42,"fs":undefined,"jibo-plugins":undefined,"path":undefined}],42:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
const Runtime_1 = require("../../Runtime");
const jetstream_client_1 = require("@jibo/jetstream-client");
const events_1 = require("events");
var InternalState;
(function (InternalState) {
InternalState[InternalState["STOPPED"] = 0] = "STOPPED";
InternalState[InternalState["STARTING"] = 1] = "STARTING";
InternalState[InternalState["STARTED"] = 2] = "STARTED";
InternalState[InternalState["UNINITIALIZED"] = 3] = "UNINITIALIZED";
})(InternalState || (InternalState = {}));
class SucceedOnListenJs extends Decorator_1.default {
constructor(options) {
super(options, {});
this._internalState = InternalState.UNINITIALIZED;
this.getOptions = options.getOptions;
this.getRulePath = options.getRulePath;
this.onResult = options.onResult;
this.listener = null;
}
_start() {
this._internalState = InternalState.STARTING;
this.status = Status_1.default.IN_PROGRESS;
this.options.getRule((ruleText) => {
if (this.status !== Status_1.default.IN_PROGRESS) {
return;
}
if (this._internalState === InternalState.STARTING) {
let emitter = new events_1.EventEmitter();
const listenOptions = {
nluRules: []
};
Runtime_1.default.instance.jetstream.startLocalTurn(listenOptions).then((request) => {
if (this.status !== Status_1.default.IN_PROGRESS) {
request.cancel();
return;
}
this.listener = request;
this.listener.events.on((event) => {
switch (event.type) {
case jetstream_client_1.types.ServiceEventType.TURN_RESULT:
const data = event.data;
this._stopInternal();
if (data.status === jetstream_client_1.types.TurnResultType.SUCCEEDED) {
emitter.emit('cloud', data.result.nlu);
}
else if (data.status === jetstream_client_1.types.TurnResultType.INTERRUPTED) {
emitter.emit('interrupted');
}
break;
case jetstream_client_1.types.ServiceEventType.SOS:
emitter.emit('speech-start');
break;
case jetstream_client_1.types.ServiceEventType.EOS:
emitter.emit('speech-end');
break;
case jetstream_client_1.types.ServiceEventType.SPEAKER_ID:
emitter.emit('speaker-id', event.data);
break;
}
});
});
this.onResult(emitter);
this._internalState = InternalState.STARTED;
}
});
return true;
}
_stopInternal() {
if (this._internalState === InternalState.STARTED) {
this.status = Status_1.default.SUCCEEDED;
this.listener = null;
}
this._internalState = InternalState.STOPPED;
}
_stop() {
if (this.listener) {
this.listener.cancel();
this.listener = null;
}
this._internalState = InternalState.STOPPED;
return Promise.resolve();
}
update(result) {
if (this.status === Status_1.default.IN_PROGRESS) {
return result;
}
else {
return this.status;
}
}
destroy() {
super.destroy();
this.getOptions = null;
this.getRulePath = null;
this.onResult = null;
this.status = null;
}
}
exports.default = SucceedOnListenJs;
},{"../../Runtime":1,"../Decorator":7,"../Status":10,"@jibo/jetstream-client":undefined,"events":undefined}],43:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
class TimeoutFail extends Decorator_1.default {
start() {
this.startTime = Date.now();
return true;
}
update(result) {
const elapsed = Date.now() - this.startTime;
if (elapsed > this.options.timeout) {
this.behavior._stop();
return Status_1.default.FAILED;
}
return result;
}
}
exports.default = TimeoutFail;
},{"../Decorator":7,"../Status":10}],44:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
class TimeoutSucceed extends Decorator_1.default {
start() {
this.startTime = Date.now();
return true;
}
update(result) {
const elapsed = Date.now() - this.startTime;
if (elapsed > this.options.timeout) {
return Status_1.default.SUCCEEDED;
}
return result;
}
}
exports.default = TimeoutSucceed;
},{"../Decorator":7,"../Status":10}],45:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
class TimeoutSucceedJs extends Decorator_1.default {
start() {
this.startTime = Date.now();
this.timeout = this.options.getTime();
return true;
}
update(result) {
const elapsed = Date.now() - this.startTime;
if (elapsed > this.timeout) {
return Status_1.default.SUCCEEDED;
}
return result;
}
}
exports.default = TimeoutSucceedJs;
},{"../Decorator":7,"../Status":10}],46:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Decorator_1 = require("../Decorator");
const Status_1 = require("../Status");
class WhileCondition extends Decorator_1.default {
constructor(options) {
super(options, {
init: function () { }
});
this.doInit = true;
}
start() {
if (this.doInit) {
this.options.init();
this.doInit = false;
}
return true;
}
update(result) {
if (result === Status_1.default.SUCCEEDED && this.options.conditional()) {
return this.behavior._start() ? Status_1.default.IN_PROGRESS : Status_1.default.FAILED;
}
this.doInit = result !== Status_1.default.IN_PROGRESS;
return result;
}
}
exports.default = WhileCondition;
},{"../Decorator":7,"../Status":10}],47:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Case_1 = require("./Case");
const FailOnCondition_1 = require("./FailOnCondition");
const StartOnAnimEvent_1 = require("./StartOnAnimEvent");
const StartOnCondition_1 = require("./StartOnCondition");
const StartOnEvent_1 = require("./StartOnEvent");
const SucceedOnCondition_1 = require("./SucceedOnCondition");
const SucceedOnEmbedded_1 = require("./SucceedOnEmbedded");
const SucceedOnEvent_1 = require("./SucceedOnEvent");
const SucceedOnListen_1 = require("./SucceedOnListen");
const SucceedOnListenJs_1 = require("./SucceedOnListenJs");
const TimeoutFail_1 = require("./TimeoutFail");
const TimeoutSucceed_1 = require("./TimeoutSucceed");
const TimeoutSucceedJs_1 = require("./TimeoutSucceedJs");
const WhileCondition_1 = require("./WhileCondition");
exports.default = {
Case: Case_1.default,
FailOnCondition: FailOnCondition_1.default,
StartOnAnimEvent: StartOnAnimEvent_1.default,
StartOnCondition: StartOnCondition_1.default,
StartOnEvent: StartOnEvent_1.default,
SucceedOnCondition: SucceedOnCondition_1.default,
SucceedOnEmbedded: SucceedOnEmbedded_1.default,
SucceedOnEvent: SucceedOnEvent_1.default,
SucceedOnListen: SucceedOnListen_1.default,
SucceedOnListenJs: SucceedOnListenJs_1.default,
TimeoutFail: TimeoutFail_1.default,
TimeoutSucceed: TimeoutSucceed_1.default,
TimeoutSucceedJs: TimeoutSucceedJs_1.default,
WhileCondition: WhileCondition_1.default
};
},{"./Case":33,"./FailOnCondition":34,"./StartOnAnimEvent":35,"./StartOnCondition":36,"./StartOnEvent":37,"./SucceedOnCondition":38,"./SucceedOnEmbedded":39,"./SucceedOnEvent":40,"./SucceedOnListen":41,"./SucceedOnListenJs":42,"./TimeoutFail":43,"./TimeoutSucceed":44,"./TimeoutSucceedJs":45,"./WhileCondition":46}],48:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Status_1 = require("./Status");
exports.Status = Status_1.default;
const Factory_1 = require("./Factory");
exports.Factory = Factory_1.default;
const Blackboard_1 = require("./Blackboard");
exports.Blackboard = Blackboard_1.default;
const BehaviorTree_1 = require("./BehaviorTree");
exports.BehaviorTree = BehaviorTree_1.default;
const BehaviorEmitter_1 = require("./BehaviorEmitter");
exports.BehaviorEmitter = BehaviorEmitter_1.default;
const Behavior_1 = require("./Behavior");
exports.Behavior = Behavior_1.default;
const ParentBehavior_1 = require("./ParentBehavior");
exports.ParentBehavior = ParentBehavior_1.default;
const BaseElement_1 = require("./BaseElement");
exports.BaseElement = BaseElement_1.default;
const Decorator_1 = require("./Decorator");
exports.Decorator = Decorator_1.default;
const behaviors_1 = require("./behaviors");
exports.behaviors = behaviors_1.default;
const decorators_1 = require("./decorators");
exports.decorators = decorators_1.default;
},{"./BaseElement":2,"./Behavior":3,"./BehaviorEmitter":4,"./BehaviorTree":5,"./Blackboard":6,"./Decorator":7,"./Factory":8,"./ParentBehavior":9,"./Status":10,"./behaviors":31,"./decorators":47}],49:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
exports.default = log_1.default.createChild('BT');
},{"../log":75}],50:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("./log");
const log = log_1.default.createChild('GenerateListConfig');
exports.CONFIG_BASE = {
viewConfig: {
type: "MenuView",
id: "mimMenu",
ignoreSwipeDown: true,
useEyeTransitions: true,
title: null,
listDefault: {
menuButtonType: "ActionButton",
colors: 'default'
},
list: [],
soundSet: 'action'
},
open: {
transitionOpen: 'trans_up',
addView: null,
removeToInclude: null
},
defaultClose: {
remove: true,
transitionClose: "trans_down"
},
defaultSelect: {
remove: true,
transitionClose: "trans_down"
},
};
const BUTTON_BASE = {
id: '',
label: '',
iconSrc: "core://resources/actionIcons/default.png",
actions: [
{
type: "utterance",
data: {
utterance: ''
}
},
]
};
function isValue(value) {
if (!value) {
return true;
}
const valType = typeof value;
if (valType === 'number' || valType === 'function' || valType === 'boolean' ||
valType === 'string') {
return true;
}
return false;
}
function mergeDeep(target, source) {
for (const key in source) {
if (isValue(source[key])) {
target[key] = source[key];
}
else {
if (Array.isArray(source[key])) {
target[key] = [];
}
else {
target[key] = {};
}
mergeDeep(target[key], source[key]);
}
}
return target;
}
exports.mergeDeep = mergeDeep;
function default_1(menuConfig) {
const config = mergeDeep({}, exports.CONFIG_BASE);
config.viewConfig.title = menuConfig.title;
config.viewConfig.ignoreSwipeDown = !menuConfig.allowSwipe;
for (let i = 0; i < menuConfig.buttons.length; ++i) {
let button = mergeDeep({}, BUTTON_BASE);
button.id = button.label = menuConfig.buttons[i].label;
let utterance = menuConfig.buttons[i].utterance;
if (utterance[0] === '{') {
try {
utterance = JSON.parse(utterance);
}
catch (e) {
log.warn('Unable to parse utterance as JSON: ', utterance);
utterance = '';
}
}
button.actions[0].data.utterance = utterance;
button.iconSrc = menuConfig.buttons[i].icon;
const colors = menuConfig.buttons[i].color;
if (Array.isArray(colors)) {
button.colors = colors.map((value) => {
return parseInt(value.replace('#', '0x'));
});
}
else {
button.colors = colors;
}
config.viewConfig.list.push(button);
}
return config;
}
exports.default = default_1;
},{"./log":64}],51:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MimPrompt_1 = require("./MimPrompt");
const MimState_1 = require("./MimState");
const WeightedRotation_1 = require("./WeightedRotation");
const fs = require("fs");
const vm = require("vm");
const path = require("path");
const jibo_embodied_dialog_1 = require("jibo-embodied-dialog");
const log_1 = require("./log");
const log = log_1.default.createChild('MimConfig');
var PromptCategory;
(function (PromptCategory) {
PromptCategory["ENTRY"] = "Entry-Core";
PromptCategory["ERROR"] = "Errors";
PromptCategory["RESPONSE"] = "Response";
})(PromptCategory || (PromptCategory = {}));
var PromptSubCategory;
(function (PromptSubCategory) {
PromptSubCategory["QUESTION"] = "Q";
PromptSubCategory["ANNOUNCEMENT"] = "AN";
PromptSubCategory["NO_MATCH"] = "NM";
PromptSubCategory["NO_INPUT"] = "NI";
PromptSubCategory["HOLD_RETURN"] = "HoldReturn";
PromptSubCategory["VERBOSE"] = "Verbose";
PromptSubCategory["TRUNCATED"] = "Truncated";
PromptSubCategory["THANKS"] = "Thanks";
})(PromptSubCategory || (PromptSubCategory = {}));
var ThanksOptions;
(function (ThanksOptions) {
ThanksOptions["IGNORE"] = "ignore";
ThanksOptions["RESPOND_AND_LISTEN"] = "respondAndListen";
ThanksOptions["RESPOND_AND_END"] = "respondAndEnd";
})(ThanksOptions = exports.ThanksOptions || (exports.ThanksOptions = {}));
var MimTypes;
(function (MimTypes) {
MimTypes["ANNOUNCEMENT"] = "announcement";
MimTypes["OPTIONAL_RESPONSE"] = "optional-response";
MimTypes["QUESTION"] = "question";
})(MimTypes = exports.MimTypes || (exports.MimTypes = {}));
class MimConfig {
static load(filePath) {
return new Promise((resolve, reject) => {
fs.readFile(filePath, 'utf8', (error, result) => {
if (error) {
reject(error);
}
else {
let mim = new MimConfig();
mim.mimId = path.basename(filePath, path.extname(filePath));
mim.initWithJSON(JSON.parse(result));
resolve(mim);
}
});
});
}
constructor() {
this.mimId = '';
this.mimType = null;
this.ruleNames = [];
this.gui = null;
this.timeout = 0;
this.noMatchesForGUI = 0;
this.noInputsForGUI = 0;
this.bargeIn = true;
this.esAutoTagging = true;
this.ignoreNoMatch = false;
this.activeListenMode = null;
this.thanksHandling = ThanksOptions.IGNORE;
this.parseAllASR = false;
this.parseLaunch = false;
this.hintPhrases = '';
this.fastEosArray = '';
this.prompts = [];
}
get hasGui() {
return (!!this.gui && !!this.gui.data);
}
getOriginalPromptText(id) {
for (let i = 0; i < this.prompts.length; ++i) {
if (this.prompts[i].id === id) {
return this.prompts[i].prompt;
}
}
return null;
}
getPromptText(mimState, promptData, rotationNode) {
let entryPromptSubCategory;
switch (this.mimType) {
case MimTypes.QUESTION:
entryPromptSubCategory = PromptSubCategory.QUESTION;
break;
case MimTypes.ANNOUNCEMENT:
entryPromptSubCategory = PromptSubCategory.ANNOUNCEMENT;
break;
case MimTypes.OPTIONAL_RESPONSE:
entryPromptSubCategory = PromptSubCategory.ANNOUNCEMENT;
break;
default:
log.debug(`In MiM ${this.mimId}, incorrect mimType of ${this.mimType}`);
break;
}
if (!mimState) {
const prompt = this.getPromptWithCategoryAndSubCategory(PromptCategory.ENTRY, entryPromptSubCategory, null, rotationNode);
return { id: prompt.id, text: prompt.getPromptText().trim(), autoRuleOverride: prompt.autoRuleOverride };
}
let promptDataSandbox;
if (promptData) {
promptDataSandbox = this.getSandbox(promptData);
}
let prompt = null;
switch (mimState.lastResultState) {
case MimState_1.States.ENTRY:
prompt = this.getPromptWithCategoryAndSubCategory(PromptCategory.ENTRY, entryPromptSubCategory, promptDataSandbox, rotationNode);
break;
case MimState_1.States.VERBOSE:
prompt = this.getPromptWithCategoryAndSubCategory(PromptCategory.ENTRY, PromptSubCategory.VERBOSE, promptDataSandbox, rotationNode);
if (!prompt) {
prompt = this.getPromptWithCategoryAndSubCategory(PromptCategory.ENTRY, entryPromptSubCategory, promptDataSandbox, rotationNode);
}
break;
case MimState_1.States.TRUNCATED:
prompt = this.getPromptWithCategoryAndSubCategory(PromptCategory.ENTRY, PromptSubCategory.TRUNCATED, promptDataSandbox, rotationNode);
if (!prompt) {
prompt = this.getPromptWithCategoryAndSubCategory(PromptCategory.ENTRY, entryPromptSubCategory, promptDataSandbox, rotationNode);
}
break;
case MimState_1.States.HOLD_RETURN:
prompt = this.getPromptWithCategoryAndSubCategory(PromptCategory.ENTRY, PromptSubCategory.HOLD_RETURN, promptDataSandbox, rotationNode);
if (!prompt) {
prompt = this.getPromptWithCategoryAndSubCategory(PromptCategory.ENTRY, entryPromptSubCategory, promptDataSandbox, rotationNode);
}
break;
case MimState_1.States.THANKS:
prompt = this.getPromptWithCategoryAndSubCategory(PromptCategory.RESPONSE, PromptSubCategory.THANKS, promptDataSandbox, rotationNode);
break;
case MimState_1.States.NO_MATCH:
prompt = this.getErrorPrompt(PromptSubCategory.NO_MATCH, promptDataSandbox, mimState.noMatchCount, rotationNode);
break;
case MimState_1.States.NO_INPUT:
prompt = this.getErrorPrompt(PromptSubCategory.NO_INPUT, promptDataSandbox, mimState.noInputCount, rotationNode);
break;
default:
log.debug(`getPromptText() - Invalid lastResultState: ${mimState.lastResultState}`);
break;
}
if (rotationNode) {
rotationNode.save();
}
if (!prompt) {
return { id: null, text: '', autoRuleOverride: null };
}
if (prompt.media !== 'TTS') {
return { id: prompt.id, text: '', autoRuleOverride: prompt.autoRuleOverride };
}
let promptText = '';
if (promptDataSandbox) {
let script_text = '`' + prompt.getPromptText() + '`';
try {
promptText = vm.runInContext(script_text, promptDataSandbox);
}
catch (e) {
log.warn(`Error parsing prompt text for ${prompt.id}: ${prompt.getPromptText()} - error: ${e.message}`);
}
}
else {
promptText = prompt.getPromptText();
}
return { id: prompt.id, text: promptText, autoRuleOverride: prompt.autoRuleOverride };
}
getJavascriptGUI(promptData) {
if (!this.gui || !this.gui.data || this.gui.type !== 'Javascript') {
return null;
}
const sandbox = this.getSandbox(promptData);
let viewConfig = null;
let code = this.gui.data;
try {
if (code.match(/^\s*{/)) {
code = '(function() {\nreturn ' + code + '})()';
viewConfig = vm.runInContext(code, sandbox);
}
else {
code = '(function() {\n' + code + '})()';
viewConfig = vm.runInContext(code, sandbox);
}
}
catch (e) {
log.warn(`Error when trying to get GUI for MIM ${this.mimId}: `, e);
}
return viewConfig;
}
hasErrorPrompt(error, index) {
let errorCategory;
if (error === 'noInput') {
errorCategory = PromptSubCategory.NO_INPUT;
}
else if (error === 'noMatch') {
errorCategory = PromptSubCategory.NO_MATCH;
}
else {
return false;
}
for (let prompt of this.prompts) {
if (prompt.promptCategory === PromptCategory.ERROR &&
prompt.promptSubCategory === errorCategory && prompt.index === index) {
return true;
}
}
return false;
}
hasVerbosePrompt() {
for (let prompt of this.prompts) {
if (prompt.promptCategory === PromptCategory.ENTRY &&
prompt.promptSubCategory === PromptSubCategory.VERBOSE) {
return true;
}
}
return false;
}
hasTruncatedPrompt() {
for (let prompt of this.prompts) {
if (prompt.promptCategory === PromptCategory.ENTRY &&
prompt.promptSubCategory === PromptSubCategory.TRUNCATED) {
return true;
}
}
return false;
}
hasThanksPrompt() {
for (let prompt of this.prompts) {
if (prompt.promptCategory === PromptCategory.RESPONSE &&
prompt.promptSubCategory === PromptSubCategory.THANKS) {
return true;
}
}
return false;
}
calculateRules(promptData) {
const rule = this.runSandboxed('`' + this.originalRuleNames + '`', promptData);
const rules = rule.split(',');
this.ruleNames = rules.map(rule => rule.trim()).filter(rule => !!rule);
}
initWithJSON(data) {
this.original = data;
if (!this.mimId) {
this.mimId = data.mim_id || "";
}
this.mimType = data.mim_type;
if (this.mimType === 'announce') {
this.mimType = MimTypes.ANNOUNCEMENT;
}
if (typeof data.rule_name === 'string') {
this.originalRuleNames = data.rule_name;
}
if (data.gui) {
this.gui = data.gui;
}
else if (data.sample_utterances) {
const gui = {
title: '',
buttons: []
};
const utterances = data.sample_utterances.split(',');
for (let i = 0; i < utterances.length; ++i) {
const utter = utterances[i].trim();
const button = {
label: utter,
color: 'default',
icon: '',
utterance: utter,
notes: ''
};
if (utter.toLowerCase() === 'yes') {
button.color = 'confirm';
button.icon = 'jibo://resources/actionIcons/ok.png';
}
else if (utter.toLowerCase() === 'no') {
button.color = 'cancel';
button.icon = 'jibo://resources/actionIcons/cancel.png';
}
gui.buttons.push(button);
}
this.gui = {
type: 'Menu',
data: gui,
pause: true
};
}
this.timeout = parseFloat(data.timeout);
if (this.mimType !== MimTypes.ANNOUNCEMENT && !(this.timeout > 0)) {
log.debug(`Timeout is an invalid value (${this.timeout}) in mim ${this.mimId}`);
this.timeout = 6;
}
if (data.num_tries_for_gui) {
this.noInputsForGUI = this.noMatchesForGUI = parseInt(data.num_tries_for_gui);
}
else {
this.noInputsForGUI = parseInt(data.no_inputs_for_gui);
this.noMatchesForGUI = parseInt(data.no_matches_for_gui);
}
if (!(this.noMatchesForGUI >= 0)) {
this.noMatchesForGUI = 0;
}
if (!(this.noInputsForGUI >= 0)) {
this.noInputsForGUI = 0;
}
this.bargeIn = data.barge_in !== false;
this.esAutoTagging = data.es_auto_tagging === undefined ? true : data.es_auto_tagging;
if (this.mimType === MimTypes.OPTIONAL_RESPONSE) {
this.ignoreNoMatch = true;
this.activeListenMode = jibo_embodied_dialog_1.listen.ActiveListenMode.OPTIONAL_RESPONSE;
}
if (data.listenMode) {
switch (data.listenMode) {
case 'OR':
case 'OPTIONAL_RESPONSE':
this.activeListenMode = jibo_embodied_dialog_1.listen.ActiveListenMode.OPTIONAL_RESPONSE;
break;
case 'UI':
this.activeListenMode = jibo_embodied_dialog_1.listen.ActiveListenMode.UI;
break;
case 'NO_BODY':
break;
}
}
if (this.mimType === MimTypes.OPTIONAL_RESPONSE) {
this.thanksHandling = data.thanks_handling || ThanksOptions.IGNORE;
}
this.parseAllASR = data.parse_all_asr === true;
if (this.mimType === MimTypes.OPTIONAL_RESPONSE) {
this.parseLaunch = data.parse_launch === true;
}
if (data.hint_phrases || data.fast_eos_array) {
if (data.hint_phrases) {
this.hintPhrases = data.hint_phrases;
}
if (data.fast_eos_array) {
this.fastEosArray = data.fast_eos_array;
}
}
else if (data.parse_yes_no === true) {
const yesno = '$YESNO';
this.hintPhrases = yesno;
this.fastEosArray = yesno;
}
if (data.prompts) {
for (let prompt_data of data.prompts) {
this.addPromptWithJSON(prompt_data);
}
}
}
runSandboxed(code, promptData) {
const context = this.getSandbox(promptData);
return vm.runInContext(code, context);
}
getPromptWithCategoryAndSubCategory(category, sub_category, promptData, rotationNode) {
let prompts = [];
let result = null;
let usedPromptIds = null;
if (rotationNode) {
let mimData = rotationNode.data[this.mimId];
if (!mimData) {
mimData = rotationNode.data[this.mimId] = {};
}
usedPromptIds = mimData[sub_category];
if (!usedPromptIds || Array.isArray(usedPromptIds)) {
usedPromptIds = mimData[sub_category] = {};
}
}
for (let prompt of this.prompts) {
if (prompt.promptCategory === category && prompt.promptSubCategory === sub_category) {
prompts.push(prompt);
}
}
result = WeightedRotation_1.selectItem(prompts, (prompt) => {
return this.promptMeetsCondition(prompt, promptData);
}, usedPromptIds);
return result;
}
getErrorPrompt(promptSubCategory, promptData, index, rotationNode) {
let prompts = [];
let result = null;
let usedPromptIds = null;
if (rotationNode) {
let mimData = rotationNode.data[this.mimId];
if (!mimData) {
mimData = rotationNode.data[this.mimId] = {};
}
usedPromptIds = mimData[promptSubCategory + '_' + index];
if (!usedPromptIds || Array.isArray(usedPromptIds)) {
usedPromptIds = mimData[promptSubCategory + '_' + index] = {};
}
}
for (let prompt of this.prompts) {
if (prompt.promptCategory === PromptCategory.ERROR &&
prompt.promptSubCategory === promptSubCategory &&
prompt.index === index) {
prompts.push(prompt);
}
}
result = WeightedRotation_1.selectItem(prompts, (prompt) => {
return this.promptMeetsCondition(prompt, promptData);
}, usedPromptIds);
return result;
}
promptMeetsCondition(prompt, promptData) {
if (!promptData || !prompt.condition) {
return true;
}
if (prompt.weight && prompt.weight <= 0) {
return false;
}
let condition = prompt.condition.replace(/^\$\{/, "").replace(/\}$/, "");
try {
return !!vm.runInContext(condition, promptData);
}
catch (e) {
log.warn(`error evaluating prompt condition for ${prompt.id}: ${prompt.condition} - error: ${e.message}`);
return false;
}
}
addPromptWithJSON(data) {
this.prompts.push(new MimPrompt_1.default(data));
}
getSandbox(promptData) {
if (!this.vmContext) {
this.vmContext = vm.createContext(promptData);
}
return this.vmContext;
}
}
exports.default = MimConfig;
},{"./MimPrompt":53,"./MimState":55,"./WeightedRotation":56,"./log":64,"fs":undefined,"jibo-embodied-dialog":undefined,"path":undefined,"vm":undefined}],52:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
const jibo_typed_events_1 = require("jibo-typed-events");
const Runtime_1 = require("../../Runtime");
const MimRepeatManager_1 = require("./MimRepeatManager");
const MimConfig_1 = require("./MimConfig");
const MimState_1 = require("./MimState");
const jibo_plugins_1 = require("jibo-plugins");
const fs = require("fs");
const path = require("path");
const GlobalListenDelegate_1 = require("./delegates/GlobalListenDelegate");
const WeightedRotation_1 = require("./WeightedRotation");
var HJCompleteReason;
(function (HJCompleteReason) {
HJCompleteReason[HJCompleteReason["HJ_ONLY"] = 0] = "HJ_ONLY";
HJCompleteReason[HJCompleteReason["NO_MATCH"] = 1] = "NO_MATCH";
HJCompleteReason[HJCompleteReason["NON_INTERRUPTING"] = 2] = "NON_INTERRUPTING";
})(HJCompleteReason = exports.HJCompleteReason || (exports.HJCompleteReason = {}));
class SingletonEnforcer {
}
class MimManager extends events_1.EventEmitter {
constructor(enforcer) {
super();
this.MimConfig = MimConfig_1.default;
this.States = MimState_1.States;
this.GlobalListenDelegate = GlobalListenDelegate_1.default;
this.isHeyJiboActive = false;
this.timeoutIgnoresSimulator = false;
this.shouldShowGUI = false;
this.silentMenus = false;
this.listenDelegate = GlobalListenDelegate_1.default;
this.speakDelegate = Runtime_1.default.instance.embodied.speech;
this.kbModels = {};
this.end = new jibo_typed_events_1.Event('End MIM');
this.end.setMode(jibo_typed_events_1.EmitterMode.LAST_HANDLER);
this.openGUI = new jibo_typed_events_1.Event('Open MIM GUI');
this.openGUI.setMode(jibo_typed_events_1.EmitterMode.LAST_HANDLER);
this.handleSpeech = new jibo_typed_events_1.Event('Handle Spoofed Utterance');
this.handleSpeech.setMode(jibo_typed_events_1.EmitterMode.LAST_HANDLER);
this.heyJibo = new jibo_typed_events_1.Event('Hey Jibo Heard');
this.heyJibo.setMode(jibo_typed_events_1.EmitterMode.LAST_HANDLER);
this.heyJiboComplete = new jibo_typed_events_1.Event('Hey Jibo Completed');
this.heyJiboComplete.setMode(jibo_typed_events_1.EmitterMode.LAST_HANDLER);
this.onHeyJiboHeard = this.onHeyJiboHeard.bind(this);
this.onHJOnly = this.onHJOnly.bind(this);
this.onHJNoMatch = this.onHJNoMatch.bind(this);
this.onShortGlobal = this.onShortGlobal.bind(this);
this.onHJEnd = this.onHJEnd.bind(this);
const origHJOn = this.heyJibo.on;
this.heyJibo.on = (handler) => {
this.attachHJListeners();
this.heyJibo.on = origHJOn;
return this.heyJibo.on(handler);
};
if (Runtime_1.default.instance.runMode === Runtime_1.default.instance.RunMode.UNIT_TESTS) {
this.selectItem = WeightedRotation_1.selectItem;
}
}
static get instance() {
if (!MimManager._instance) {
MimManager._instance = new MimManager(new SingletonEnforcer());
}
return MimManager._instance;
}
loadMimKB(assetPack) {
if (assetPack.endsWith('://')) {
assetPack = assetPack.substring(0, assetPack.length - 3);
}
if (assetPack === 'core') {
assetPack = 'jibo';
}
if (!assetPack) {
try {
const skillJSON = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), 'package.json'), 'utf8'));
assetPack = skillJSON.name;
}
catch (e) {
return Promise.reject(e);
}
}
assetPack = assetPack.toLowerCase().replace(/[^a-z0-9\/_-]/g, '');
if (this.kbModels[assetPack]) {
return this.kbModels[assetPack].loadRoot();
}
const sliceName = assetPack === 'jibo ' ? '/jibo/mims' : `/skills/${assetPack}/mims`;
return Runtime_1.default.instance.kb.createSlice(sliceName)
.then(() => {
const model = Runtime_1.default.instance.kb.createModel(sliceName);
this.kbModels[assetPack] = model;
return model.loadRoot();
});
}
loadMimAssets() {
if (!this.globalMimLoad) {
const loadThanks = MimConfig_1.default.load(jibo_plugins_1.PathUtils.getAssetUri('core://mims/en-us/globals/ThanksResponse.mim'))
.then((config) => {
this.thanksResponse = config;
});
this.repeat = new MimRepeatManager_1.default();
const loadRotation = this.loadMimKB('jibo').then((node) => {
this.jiboRotationNode = node;
});
this.globalMimLoad = Promise.all([loadThanks, this.repeat.init(), loadRotation]);
}
}
attachHJListeners() {
const events = Runtime_1.default.instance.jetstream.events;
events.hjHeard.on(this.onHeyJiboHeard);
events.globalTurnResult.on(this.onHJEnd);
const shared = Runtime_1.default.instance.globalEvents.shared;
shared.hjOnly.on(this.onHJOnly);
shared.noGlobalMatch.on(this.onHJNoMatch);
shared.nonInterruptingGlobal.on(this.onShortGlobal);
}
onHeyJiboHeard() {
this.isHeyJiboActive = true;
this.heyJibo.emit();
}
onHJOnly() {
this.isHeyJiboActive = false;
this.heyJiboComplete.emit(HJCompleteReason.HJ_ONLY);
}
onHJNoMatch() {
this.isHeyJiboActive = false;
this.heyJiboComplete.emit(HJCompleteReason.NO_MATCH);
}
onShortGlobal() {
this.isHeyJiboActive = false;
this.heyJiboComplete.emit(HJCompleteReason.NON_INTERRUPTING);
}
onHJEnd() {
this.isHeyJiboActive = false;
}
}
exports.default = MimManager;
},{"../../Runtime":1,"./MimConfig":51,"./MimRepeatManager":54,"./MimState":55,"./WeightedRotation":56,"./delegates/GlobalListenDelegate":59,"events":undefined,"fs":undefined,"jibo-plugins":undefined,"jibo-typed-events":undefined,"path":undefined}],53:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class MimPrompt {
constructor(data) {
this.id = data.prompt_id;
this.promptCategory = data.prompt_category;
this.promptSubCategory = data.prompt_sub_category;
this.index = parseInt(data.index);
this.condition = data.condition;
this.prompt = data.prompt;
this.media = data.media;
this.autoRuleOverride = data.auto_rule_override;
if (this.autoRuleOverride === undefined) {
this.autoRuleOverride = null;
}
if (data.weight !== undefined && parseFloat(data.weight) === 0) {
this.weight = 0;
}
else {
this.weight = parseFloat(data.weight) || 1;
}
}
getPromptText() {
let result = this.prompt;
return result;
}
}
exports.default = MimPrompt;
},{}],54:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MimConfig_1 = require("./MimConfig");
const jibo_plugins_1 = require("jibo-plugins");
class MimRepeatManager {
constructor() {
this.maxRepeat = 10;
this.repeatMimQ = null;
this.repeatMimANOR = null;
this.repeatActionQ = null;
this.repeatActionANOR = null;
}
init() {
this.repeatMimQ = [];
this.repeatMimQ.length = 10;
this.repeatMimQ.fill(null, 0, 10);
this.repeatMimANOR = [];
this.repeatMimANOR.length = 10;
this.repeatMimANOR.fill(null, 0, 10);
this.repeatActionQ = ['cached'];
this.repeatActionQ.length = 10;
this.repeatActionQ.fill('verbose', 1, 8);
this.repeatActionQ[9] = 'exit';
this.repeatActionANOR = [];
this.repeatActionANOR.length = 10;
this.repeatActionANOR.fill('cached', 0, 8);
this.repeatActionANOR[9] = 'exit';
let promises = [
'core://mims/en-us/globals/RepeatORANFirst.mim',
'core://mims/en-us/globals/RepeatORANSecond.mim',
'core://mims/en-us/globals/RepeatORANThird.mim',
'core://mims/en-us/globals/RepeatORANNoMore.mim',
'core://mims/en-us/globals/RepeatQuestionFirst.mim',
'core://mims/en-us/globals/RepeatQuestionSecond.mim',
'core://mims/en-us/globals/RepeatQuestionThird.mim',
'core://mims/en-us/globals/RepeatQuestionNoMore.mim',
];
for (let i = 0; i < promises.length; ++i) {
promises[i] = MimConfig_1.default.load(jibo_plugins_1.PathUtils.getAssetUri(promises[i]));
}
return Promise.all(promises).then((results) => {
this.repeatMimANOR[0] = results[0];
this.repeatMimANOR[1] = results[1];
this.repeatMimANOR.fill(results[2], 2, 8);
this.repeatMimANOR[9] = results[3];
this.repeatMimQ[0] = results[4];
this.repeatMimQ[1] = results[5];
this.repeatMimQ[2] = results[6];
this.repeatMimQ[9] = results[7];
});
}
getRepeat(mimType, repeatCount) {
const mims = mimType === MimConfig_1.MimTypes.QUESTION ? this.repeatMimQ : this.repeatMimANOR;
const actions = mimType === MimConfig_1.MimTypes.QUESTION ? this.repeatActionQ : this.repeatActionANOR;
let prompt;
if (mims[repeatCount - 1]) {
prompt = mims[repeatCount - 1].getPromptText(null, null).text + ' ';
}
else {
prompt = '';
}
return {
action: actions[repeatCount - 1],
prompt
};
}
}
exports.default = MimRepeatManager;
},{"./MimConfig":51,"jibo-plugins":undefined}],55:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var States;
(function (States) {
States["ENTRY"] = "entry";
States["MATCH"] = "match";
States["NO_MATCH"] = "noMatch";
States["NO_INPUT"] = "noInput";
States["REPEAT"] = "repeat";
States["THANKS"] = "thanks";
States["HOLD_RETURN"] = "holdReturn";
States["VERBOSE"] = "verbose";
States["TRUNCATED"] = "truncated";
States["MENU_CLOSED"] = "MenuClosed";
})(States = exports.States || (exports.States = {}));
class MimState {
constructor() {
this.noInputCount = 0;
this.noMatchCount = 0;
this.lastResultState = States.ENTRY;
this.success = false;
this.failure = false;
this.promptText = '';
this.promptAutoRules = null;
}
reset() {
this.noInputCount = 0;
this.noMatchCount = 0;
this.lastResultState = States.ENTRY;
this.success = false;
this.failure = false;
this.promptText = '';
this.promptAutoRules = null;
}
get done() {
return (this.success || this.failure);
}
get errors() {
return this.noInputCount + this.noMatchCount;
}
incrementNoInputCount() {
this.noInputCount++;
}
incrementNoMatchCount() {
this.noMatchCount++;
}
shouldShowGUI(config) {
return config.hasGui && (this.noMatchCount >= config.noMatchesForGUI ||
this.noInputCount >= config.noInputsForGUI);
}
}
exports.default = MimState;
},{}],56:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class ItemStandin {
constructor(original, usedDict) {
this.orig = original;
this.id = original.id;
if (usedDict && typeof usedDict[this.id] === 'number') {
this.weight = original.weight - usedDict[this.id];
}
else {
this.weight = original.weight;
}
this.valid = undefined;
}
}
function selectItem(itemList, validCheck, usedDict) {
if (!itemList || !itemList.length) {
return null;
}
let itemOptions = [];
let result = null;
let usedItems = [];
for (let item of itemList) {
if (usedDict && usedDict[item.id] === true) {
usedItems.push(new ItemStandin(item, usedDict));
continue;
}
if (item.weight > 0 && validCheck(item)) {
const standin = new ItemStandin(item, usedDict);
standin.valid = true;
if (standin.weight <= 0) {
usedItems.push(standin);
}
else {
itemOptions.push(standin);
}
}
}
result = selectWeightedItem(itemOptions, usedItems, usedDict);
if (!result && usedItems.length) {
for (const prop in usedDict) {
delete usedDict[prop];
}
let maxWeight = 0;
for (let item of usedItems) {
if (item.valid || validCheck(item.orig)) {
item.weight = item.orig.weight;
itemOptions.push(item);
if (item.weight > maxWeight) {
maxWeight = item.weight;
}
}
}
if (maxWeight < 1) {
const normalizer = 1 / maxWeight;
for (let item of itemOptions) {
item.weight *= normalizer;
}
}
result = selectWeightedItem(itemOptions, usedItems, usedDict);
}
if (result && usedDict) {
const id = result.id;
if (result.weight > 1) {
usedDict[id] = usedDict[id] ? usedDict[id] + 1 : 1;
}
else {
usedDict[id] = true;
}
}
return result ? result.orig : null;
}
exports.selectItem = selectItem;
function selectWeightedItem(items, usedItems, usedDict) {
if (items.length === 0) {
return null;
}
let result = null;
let totalWeight = 0;
let length = items.length;
for (let i = 0; i < length; ++i) {
totalWeight += items[i].weight;
}
while (!result && length > 0) {
const rand = Math.random() * totalWeight;
let ongoingWeight = 0;
for (let i = 0; i < length; ++i) {
ongoingWeight += items[i].weight;
if (rand <= ongoingWeight) {
result = items[i];
break;
}
}
if (usedDict && result.weight < 1 && Math.random() >= result.weight) {
usedItems.push(result);
items.splice(items.indexOf(result), 1);
usedDict[result.id] = true;
totalWeight -= result.weight;
length -= 1;
result = null;
}
}
return result;
}
},{}],57:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class EmptyAnalytics {
constructor() {
this.currentSkill = 'none';
}
track(event, data) {
}
flush() {
}
}
exports.default = EmptyAnalytics;
},{}],58:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../../Runtime");
exports.EXIT_TYPE = {
INTERRUPT: 'interruption',
SUCCESS: 'success',
MAX_NI: 'max_no_input',
MAX_NM: 'max_no_match'
};
exports.INTERRUPT_STATE = {
SPEECH: 'speech',
LISTEN: 'listen'
};
exports.INPUT = {
SPEECH: 'speech',
TOUCH: 'touch',
SILENCE: 'silence',
INTERRUPT: 'interrupted',
NONE: 'n/a'
};
exports.NONE = 'n/a';
function end(base, exit_type, input_type, intent_selected, text, interruption_state, prev_prompt_id, total_no_matches, total_no_inputs) {
Runtime_1.default.instance.analytics.track('Mim End', Object.assign({
exit_type,
modality: input_type || '',
user_response: intent_selected || exports.NONE,
user_response_text: text,
interruption_state: interruption_state || exports.NONE,
prev_prompt_id: prev_prompt_id || 'silence',
total_no_inputs,
total_no_matches
}, base));
}
exports.end = end;
function launch(base) {
Runtime_1.default.instance.analytics.track('Mim Launch', Object.assign({}, base));
}
exports.launch = launch;
function nonEndingResult(base, input_type, intent, text, domain, prev_prompt_id) {
Runtime_1.default.instance.analytics.track('Mim Non-ending Result', Object.assign({
modality: input_type,
user_response: intent,
command_type: domain,
prev_prompt_id: prev_prompt_id || 'silence',
user_response_text: text
}, base));
}
exports.nonEndingResult = nonEndingResult;
function nonEndingIgnored(base, input_type, intent, text, domain, prev_prompt_id) {
Runtime_1.default.instance.analytics.track('Mim Non-ending Ignored', Object.assign({
modality: input_type,
user_response: intent,
command_type: domain,
prev_prompt_id: prev_prompt_id || 'silence',
user_response_text: text
}, base));
}
exports.nonEndingIgnored = nonEndingIgnored;
function noMatch(base, error_count, prev_prompt_id, text) {
Runtime_1.default.instance.analytics.track('Mim No Match', Object.assign({
error_count,
prev_prompt_id: prev_prompt_id || 'silence',
user_response_text: text
}, base));
}
exports.noMatch = noMatch;
function noInput(base, error_count, prev_prompt_id) {
Runtime_1.default.instance.analytics.track('Mim No Input', Object.assign({
error_count,
prev_prompt_id: prev_prompt_id || 'silence'
}, base));
}
exports.noInput = noInput;
function recoveredException(base) {
Runtime_1.default.instance.analytics.track('Mim Recovered From Exception', Object.assign({}, base));
}
exports.recoveredException = recoveredException;
},{"../../../Runtime":1}],59:[function(require,module,exports){
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const jetstream_client_1 = require("@jibo/jetstream-client");
const events_1 = require("events");
const ListenEvent_1 = require("./ListenEvent");
const Runtime_1 = require("../../../Runtime");
const log_1 = require("../log");
const log = log_1.default.createChild('GlobalListenDelegate');
class GlobalListener extends events_1.EventEmitter {
static setAmbientMode(mode) {
Runtime_1.default.instance.embodied.listen.setAmbientMode(mode);
}
static enterActiveMode(mode, options) {
return Runtime_1.default.instance.embodied.listen.enterActiveMode(mode, options);
}
static exitActiveMode() {
return Runtime_1.default.instance.embodied.listen.exitActiveMode();
}
static create(options) {
return __awaiter(this, void 0, void 0, function* () {
const listener = new GlobalListener();
listener.init(options);
listener.run();
return listener;
});
}
constructor() {
super();
this.stopped = false;
}
updateTurn(options) {
return __awaiter(this, void 0, void 0, function* () {
yield this.initialized;
if (this.stopped) {
return;
}
this.turn.update(options);
});
}
stop(cancelTurn = true) {
this.removeAllListeners();
if (this.turn && cancelTurn) {
this.turn.cancel();
}
this.turn = null;
this.stopped = true;
}
init(options) {
return __awaiter(this, void 0, void 0, function* () {
this.initialized = new Promise((resolve, reject) => {
Runtime_1.default.instance.jetstream.startLocalTurn(options)
.then((turn) => {
this.turn = turn;
resolve();
}, reject);
});
yield this.initialized;
if (this.stopped) {
this.turn.cancel();
this.turn = null;
}
});
}
run() {
return __awaiter(this, void 0, void 0, function* () {
yield this.initialized;
if (this.stopped) {
return;
}
Runtime_1.default.instance.jetstream.events.localTurnStarted.emit();
try {
const data = yield this.turn.promise;
if (this.stopped) {
return;
}
this.turn = null;
switch (data.status) {
case jetstream_client_1.types.TurnResultType.INTERRUPTED:
this.emit(ListenEvent_1.default.INTERRUPTED);
break;
case jetstream_client_1.types.TurnResultType.SUCCEEDED:
this.emit(ListenEvent_1.default.CLOUD, data);
break;
case jetstream_client_1.types.TurnResultType.TIMEOUT:
this.emit(ListenEvent_1.default.TIMEOUT);
break;
}
const activeMode = Runtime_1.default.instance.embodied.listen.getActiveMode();
if (!activeMode && data.status !== jetstream_client_1.types.TurnResultType.INTERRUPTED) {
try {
yield Runtime_1.default.instance.embodied.listen.waitForIdle(true);
}
catch (e) {
log.warn('Error waiting for EL to return to idle', e);
}
}
this.emit(ListenEvent_1.default.FINISHED);
this.stop();
}
catch (e) {
this.turn = null;
this.emit(ListenEvent_1.default.FINISHED, null);
}
});
}
}
exports.default = GlobalListener;
},{"../../../Runtime":1,"../log":64,"./ListenEvent":60,"@jibo/jetstream-client":undefined,"events":undefined}],60:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ListenEvent = {
CLOUD: 'CLOUD',
FINISHED: 'FINISHED',
INTERRUPTED: 'INTERRUPTED',
TIMEOUT: 'TIMEOUT',
};
exports.default = ListenEvent;
},{}],61:[function(require,module,exports){
'use strict';
module.exports = function (blackboard, notepad, result, emitter) {
return {
'meta': {
'version': 1,
'name': 'NoInputException',
'uri': '/Users/jon/mit/sdk5/packages/jibo/src/bt/mim/flows/NoInputException.flow'
},
'f5f79e38-b40a-4c5f-83a6-a62c8af42161': function () {
return {
'id': 'f5f79e38-b40a-4c5f-83a6-a62c8af42161',
'name': 'Begin',
'transitions': [{
'frm': 'f5f79e38-b40a-4c5f-83a6-a62c8af42161',
'to': '149e6048-3d51-48e8-afaf-a5c40729b563',
'value': ''
}],
'exceptions': [],
'class': 'Flow.Begin',
'options': {
'inputParameters': () => {
return {};
}
}
};
},
'28e365cb-3b40-4a5f-adec-e2ff27739d64': function () {
return {
'id': '28e365cb-3b40-4a5f-adec-e2ff27739d64',
'name': 'exit',
'transitions': [],
'exceptions': [],
'class': 'Flow.End',
'options': {
'getTransition': () => {
return;
}
}
};
},
'41987e17-23ac-4791-b7e1-4d5a149afed1': function () {
return {
'id': '41987e17-23ac-4791-b7e1-4d5a149afed1',
'name': 'restart',
'transitions': [],
'exceptions': [],
'class': 'Flow.End',
'options': {
'getTransition': () => {
return;
}
}
};
},
'149e6048-3d51-48e8-afaf-a5c40729b563': function () {
return {
'id': '149e6048-3d51-48e8-afaf-a5c40729b563',
'name': 'Final NI - You Still There?',
'transitions': [
{
'frm': '149e6048-3d51-48e8-afaf-a5c40729b563',
'to': '8072f19c-a7c9-4243-91bb-da0e5b5b6324',
'value': 'yes'
},
{
'frm': '149e6048-3d51-48e8-afaf-a5c40729b563',
'to': 'cfbe95f1-b20e-4374-8288-6545ae6ede5b',
'value': 'no'
}
],
'exceptions': [
{
'frm': '149e6048-3d51-48e8-afaf-a5c40729b563',
'to': 'acd4acbf-b76a-4e01-93d9-ea5f0ed06007',
'value': '~InteractionError.noMatch'
},
{
'frm': '149e6048-3d51-48e8-afaf-a5c40729b563',
'to': '1f39bc3c-f910-4473-a693-b3abe8f09d90',
'value': '~InteractionError.noInput'
}
],
'class': 'Mim.Question',
'options': {
'mimPath': 'mims/en-us/exceptions/FinalNI-YouStillThere.mim',
'getPromptData': () => {
return {};
},
'onStatus': status => {
let mimState = status.state;
let asrResults = status.asrResults;
let speakerIds = status.speakerIds;
},
'onSuccess': results => {
let mimState = results.state;
let asrResults = results.asrResults;
let speakerIds = results.speakerIds;
let transition = results.firstGrammarTag;
return transition;
},
'onFailure': results => {
let mimState = results.state;
let asrResults = results.asrResults;
let speakerIds = results.speakerIds;
let exception = results.exception;
return exception;
}
}
};
},
'acd4acbf-b76a-4e01-93d9-ea5f0ed06007': function () {
return {
'id': 'acd4acbf-b76a-4e01-93d9-ea5f0ed06007',
'name': 'Final NI - No Match',
'transitions': [{
'frm': 'acd4acbf-b76a-4e01-93d9-ea5f0ed06007',
'to': '41987e17-23ac-4791-b7e1-4d5a149afed1',
'value': ''
}],
'exceptions': [],
'class': 'Mim.Announcement',
'options': {
'mimPath': 'mims/en-us/exceptions/FinalNI-NoMatch.mim',
'getPromptData': () => {
return {};
}
}
};
},
'8072f19c-a7c9-4243-91bb-da0e5b5b6324': function () {
return {
'id': '8072f19c-a7c9-4243-91bb-da0e5b5b6324',
'name': 'Final NI - Recovery',
'transitions': [{
'frm': '8072f19c-a7c9-4243-91bb-da0e5b5b6324',
'to': '41987e17-23ac-4791-b7e1-4d5a149afed1',
'value': ''
}],
'exceptions': [],
'class': 'Mim.Announcement',
'options': {
'mimPath': 'mims/en-us/exceptions/FinalNI-Recovery.mim',
'getPromptData': () => {
return {};
}
}
};
},
'1f39bc3c-f910-4473-a693-b3abe8f09d90': function () {
return {
'id': '1f39bc3c-f910-4473-a693-b3abe8f09d90',
'name': 'Final NI - Surrender',
'transitions': [{
'frm': '1f39bc3c-f910-4473-a693-b3abe8f09d90',
'to': '28e365cb-3b40-4a5f-adec-e2ff27739d64',
'value': ''
}],
'exceptions': [],
'class': 'Mim.Announcement',
'options': {
'mimPath': 'mims/en-us/exceptions/FinalNI-Surrender.mim',
'getPromptData': () => {
return {};
}
}
};
},
'cfbe95f1-b20e-4374-8288-6545ae6ede5b': function () {
return {
'id': 'cfbe95f1-b20e-4374-8288-6545ae6ede5b',
'name': 'Final NI -Smartypants',
'transitions': [{
'frm': 'cfbe95f1-b20e-4374-8288-6545ae6ede5b',
'to': '28e365cb-3b40-4a5f-adec-e2ff27739d64',
'value': ''
}],
'exceptions': [],
'class': 'Mim.Announcement',
'options': {
'mimPath': 'mims/en-us/exceptions/FinalNI-Smartypants.mim',
'getPromptData': () => {
return {};
}
}
};
}
};
};
},{}],62:[function(require,module,exports){
'use strict';
module.exports = function (blackboard, notepad, result, emitter) {
return {
'meta': {
'version': 1,
'name': 'NoMatchException',
'uri': '/Users/jon/mit/sdk5/packages/jibo/src/bt/mim/flows/NoMatchException.flow'
},
'f5f79e38-b40a-4c5f-83a6-a62c8af42161': function () {
return {
'id': 'f5f79e38-b40a-4c5f-83a6-a62c8af42161',
'name': 'Begin',
'transitions': [{
'frm': 'f5f79e38-b40a-4c5f-83a6-a62c8af42161',
'to': '1a10ac7c-2d90-4dd8-aaf3-7c2e3482f048',
'value': ''
}],
'exceptions': [],
'class': 'Flow.Begin',
'options': {
'inputParameters': () => {
return {};
}
}
};
},
'28e365cb-3b40-4a5f-adec-e2ff27739d64': function () {
return {
'id': '28e365cb-3b40-4a5f-adec-e2ff27739d64',
'name': 'exit',
'transitions': [],
'exceptions': [],
'class': 'Flow.End',
'options': {
'getTransition': () => {
return;
}
}
};
},
'9280d6d3-91ab-4813-9ab5-401ab5592fc8': function () {
return {
'id': '9280d6d3-91ab-4813-9ab5-401ab5592fc8',
'name': 'restart',
'transitions': [],
'exceptions': [],
'class': 'Flow.End',
'options': {
'getTransition': () => {
return;
}
}
};
},
'1a10ac7c-2d90-4dd8-aaf3-7c2e3482f048': function () {
return {
'id': '1a10ac7c-2d90-4dd8-aaf3-7c2e3482f048',
'name': 'Final NM - Want to Keep Trying',
'transitions': [
{
'frm': '1a10ac7c-2d90-4dd8-aaf3-7c2e3482f048',
'to': '84af4933-6f6a-43f1-b1f1-4831710d3c12',
'value': 'no'
},
{
'frm': '1a10ac7c-2d90-4dd8-aaf3-7c2e3482f048',
'to': '4a745911-a5a6-455e-ab29-d1d76d6f01e4',
'value': 'yes'
}
],
'exceptions': [
{
'frm': '1a10ac7c-2d90-4dd8-aaf3-7c2e3482f048',
'to': 'd2eebf5f-b2a5-4b6f-99fe-97504bb3ef83',
'value': '~InteractionError.noMatch'
},
{
'frm': '1a10ac7c-2d90-4dd8-aaf3-7c2e3482f048',
'to': '1101d00a-9cf1-4a82-94d3-8623abbd18b7',
'value': '~InteractionError.noInput'
}
],
'class': 'Mim.Question',
'options': {
'mimPath': 'mims/en-us/exceptions/FinalNM-WantToKeepTrying.mim',
'getPromptData': () => {
return {};
},
'onStatus': status => {
let mimState = status.state;
let asrResults = status.asrResults;
let speakerIds = status.speakerIds;
},
'onSuccess': results => {
let mimState = results.state;
let asrResults = results.asrResults;
let speakerIds = results.speakerIds;
let transition = results.firstGrammarTag;
return transition;
},
'onFailure': results => {
let mimState = results.state;
let asrResults = results.asrResults;
let speakerIds = results.speakerIds;
let exception = results.exception;
return exception;
}
}
};
},
'1101d00a-9cf1-4a82-94d3-8623abbd18b7': function () {
return {
'id': '1101d00a-9cf1-4a82-94d3-8623abbd18b7',
'name': 'Final NM - Surrender',
'transitions': [{
'frm': '1101d00a-9cf1-4a82-94d3-8623abbd18b7',
'to': '28e365cb-3b40-4a5f-adec-e2ff27739d64',
'value': ''
}],
'exceptions': [],
'class': 'Mim.Announcement',
'options': {
'mimPath': 'mims/en-us/exceptions/FinalNM-Surrender.mim',
'getPromptData': () => {
return {};
}
}
};
},
'45f80d27-5a59-4c0b-a241-4b8ea274294b': {
'id': '45f80d27-5a59-4c0b-a241-4b8ea274294b',
'transitions': [],
'exceptions': [],
'class': 'Flow.Comment',
'options': {}
},
'84af4933-6f6a-43f1-b1f1-4831710d3c12': function () {
return {
'id': '84af4933-6f6a-43f1-b1f1-4831710d3c12',
'name': 'Final NM - No More',
'transitions': [{
'frm': '84af4933-6f6a-43f1-b1f1-4831710d3c12',
'to': '28e365cb-3b40-4a5f-adec-e2ff27739d64',
'value': ''
}],
'exceptions': [],
'class': 'Mim.Announcement',
'options': {
'mimPath': 'mims/en-us/exceptions/FinalNM-NoMore.mim',
'getPromptData': () => {
return {};
}
}
};
},
'1d0ca37e-be3c-4c33-af53-98bc012045a2': function () {
return {
'id': '1d0ca37e-be3c-4c33-af53-98bc012045a2',
'name': 'Final NM - Even More NM',
'transitions': [{
'frm': '1d0ca37e-be3c-4c33-af53-98bc012045a2',
'to': '45a2e357-05c6-41b4-a475-4f47ab2d7c36',
'value': ''
}],
'exceptions': [],
'class': 'Mim.Announcement',
'options': {
'mimPath': 'mims/en-us/exceptions/FinalNM-EvenMoreNM.mim',
'getPromptData': () => {
return {};
}
}
};
},
'4a745911-a5a6-455e-ab29-d1d76d6f01e4': function () {
return {
'id': '4a745911-a5a6-455e-ab29-d1d76d6f01e4',
'name': 'SSA - Happy',
'transitions': [{
'frm': '4a745911-a5a6-455e-ab29-d1d76d6f01e4',
'to': '9280d6d3-91ab-4813-9ab5-401ab5592fc8',
'value': ''
}],
'exceptions': [],
'class': 'Flow.Eval-Async',
'options': {
'exec': done => {
blackboard.speechDelegate.speak({ text: '<es cat="happy"/>.' }).then(done).catch(done);
},
'onStop': () => {
if (blackboard.speechDelegate) {
blackboard.speechDelegate.stop();
}
}
}
};
},
'd2eebf5f-b2a5-4b6f-99fe-97504bb3ef83': function () {
return {
'id': 'd2eebf5f-b2a5-4b6f-99fe-97504bb3ef83',
'name': 'Display Text',
'transitions': [{
'frm': 'd2eebf5f-b2a5-4b6f-99fe-97504bb3ef83',
'to': '1d0ca37e-be3c-4c33-af53-98bc012045a2',
'value': ''
}],
'exceptions': [],
'class': 'Flow.Eval',
'options': {
'Script': () => {
blackboard.showInputText();
}
}
};
},
'02ae347b-f1ff-4d2b-a1cc-e65eb17fdabc': function () {
return {
'id': '02ae347b-f1ff-4d2b-a1cc-e65eb17fdabc',
'name': 'Hide Text',
'transitions': [{
'frm': '02ae347b-f1ff-4d2b-a1cc-e65eb17fdabc',
'to': '28e365cb-3b40-4a5f-adec-e2ff27739d64',
'value': ''
}],
'exceptions': [],
'class': 'Flow.Eval',
'options': {
'Script': () => {
blackboard.hideInputText();
}
}
};
},
'45a2e357-05c6-41b4-a475-4f47ab2d7c36': function () {
return {
'id': '45a2e357-05c6-41b4-a475-4f47ab2d7c36',
'name': 'Keep words onscreen for a bit',
'asset-pack': 'core',
'transitions': [{
'frm': '45a2e357-05c6-41b4-a475-4f47ab2d7c36',
'to': '02ae347b-f1ff-4d2b-a1cc-e65eb17fdabc',
'value': ''
}],
'exceptions': [],
'class': 'TimeoutJs',
'options': {
'getTime': () => {
return 1000;
}
}
};
}
};
};
},{}],63:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MimManager_1 = require("./MimManager");
exports.MimManager = MimManager_1.default;
const ListenEvent_1 = require("./delegates/ListenEvent");
exports.ListenEvent = ListenEvent_1.default;
},{"./MimManager":52,"./delegates/ListenEvent":60}],64:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
exports.default = log_1.default.createChild('Mim');
},{"../log":49}],65:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const fs = require("fs");
const electron_1 = require("./utils/electron");
const flowCore = require("jibo-flow-core");
const Behavior_1 = require("./bt/Behavior");
const Decorator_1 = require("./bt/Decorator");
function warn(msg) {
let stack = new Error().stack;
stack = stack.split('\n').splice(3).join('\n');
if (console.groupCollapsed) {
console.groupCollapsed("%cDeprecation Warning: %c%s", "color:#614108;background:#fffbe6", "font-weight:normal;color:#614108;background:#fffbe6", msg);
console.warn(stack);
console.groupEnd();
}
else {
console.warn("Deprecation Warning:", msg);
console.warn(stack);
}
}
function default_1(jibo) {
Object.defineProperties(jibo.utils, {
SerialTimer: {
get: function () {
warn("jibo.utils.SerialTimer has moved, please use jibo.utils.perf.SerialTimer");
return jibo.utils.perf.SerialTimer;
}
},
ParallelTimer: {
get: function () {
warn("jibo.utils.ParallelTimer has moved, please use jibo.utils.perf.ParallelTimer");
return jibo.utils.perf.ParallelTimer;
}
}
});
const RuntimePrototype = jibo.Runtime.prototype;
RuntimePrototype.initOutput = function (service) {
warn('jibo.initOutput is deprecated, used jibo.animUtils.initOutput');
this.animUtils.initOutput(service);
};
RuntimePrototype.attachOutput = function () {
warn('jibo.attachOutput is deprecated, used jibo.animUtils.attachOutput');
this.animUtils.attachOutput();
};
RuntimePrototype.detachOutput = function () {
warn('jibo.detachOutput is deprecated, used jibo.animUtils.detachOutput');
this.animUtils.detachOutput();
};
RuntimePrototype.initAnimationUtilities = function (done, headless = false) {
warn('jibo.initAnimationUtilities is deprecated, used jibo.animUtils.initUtilities');
this.animUtils.initUtilities(done, headless);
};
Object.defineProperty(RuntimePrototype, 'FaceRenderer', {
get: function () {
warn('jibo.FaceRenderer is deprecated, please use jibo.rendering.FaceRenderer');
return this.rendering.FaceRenderer;
}
});
Object.defineProperty(RuntimePrototype, 'flowCore', {
get: function () {
warn('jibo.flowCore is deprecated, please use the jibo-flow-core module instead');
return flowCore;
}
});
Object.defineProperty(RuntimePrototype, "bodySettings", {
get: function () {
warn("jibo.bodySettings is deprecated, please use jibo.system");
return this.system;
}
});
Object.defineProperty(RuntimePrototype, "body", {
get: function () {
warn("jibo.body is deprecated, please use jibo.system");
return this.system;
}
});
Object.defineProperty(RuntimePrototype, "audio", {
get: function () {
warn("jibo.audio is deprecated, please use jibo.system");
return this.system;
}
});
RuntimePrototype.requireAssetPack = function (assetPackPackage) {
warn('jibo.requireAssetPack is deprecated');
if (fs.existsSync(assetPackPackage)) {
const project = require(assetPackPackage);
if (project.jibo && project.jibo.type === "asset-pack") {
const uri = path.resolve(path.parse(assetPackPackage).dir, project.main);
return require(uri);
}
}
};
const PathUtils = jibo.utils.PathUtils;
PathUtils.getBaseDirectory = function (dir, callback) {
warn("PathUtils.getBaseDirectory is deprecated, please use PathUtils.findRoot(dir)");
const base = PathUtils.findRoot(dir);
callback(base, PathUtils.getProjectName(base));
};
PathUtils.getProjectRoot = function (callback) {
warn("PathUtils.getProjectRoot is deprecated, please use PathUtils.findRoot()");
PathUtils.getBaseDirectory(process.cwd(), callback);
};
const kb = jibo.services.kb;
const ModelPrototype = kb.Model.prototype;
ModelPrototype.loadList = function (ids, callback) {
warn('kb.Model.loadList is deprecated, please use kb.Model.load');
return this.load(ids, callback);
};
ModelPrototype.fetchList = function (ids, quietly = false) {
warn('kb.Model.fetchList is deprecated, please use kb.Model.fetch');
return this.fetch(ids, quietly);
};
if (!electron_1.default) {
return;
}
const globalJibo = global.JIBO = {};
const Factory = jibo.bt.Factory;
const FaceRenderer = jibo.rendering.FaceRenderer;
const ViewManager = jibo.rendering.gui.ViewManager;
const TRANSITION = jibo.rendering.gui.TRANSITION;
const STATE = jibo.rendering.gui.views.STATE;
const CATEGORY = jibo.rendering.gui.views.CATEGORY;
const GESTURE = jibo.rendering.gui.GESTURE;
const STACK_DIRECTION = jibo.rendering.gui.STACK_DIRECTION;
const View = jibo.rendering.gui.views.View;
Object.defineProperty(globalJibo, "bt", {
get: function () {
warn("JIBO.bt has moved, please use jibo.bt");
return jibo.bt;
}
});
Object.defineProperty(jibo.flow.FlowExecutorFactory.prototype, 'flowObjects', {
get: function () {
warn("jibo.flow.flowObjects has moved, please use jibo.flow.core");
return jibo.flow.core;
}
});
Object.defineProperty(Factory.prototype, "factory", {
get: function () {
warn("jibo.bt.factory is deprecated, please use jibo.bt");
return this;
}
});
Object.defineProperty(jibo.bt.BehaviorTree.prototype, "status", {
get: function () {
warn('BehaviorTree.status is deprecated, please use BehaviorTree.currentStatus');
return this.currentStatus;
}
});
Object.defineProperty(ViewManager.prototype, "UP", {
get: function () {
warn('jibo.rendering.gui.ViewManager.UP is deprecated, please use jibo.face.views.TRANSITION.UP');
return TRANSITION.UP;
}
});
Object.defineProperty(ViewManager.prototype, "DOWN", {
get: function () {
warn('jibo.rendering.gui.ViewManager.DOWN is deprecated, please use jibo.face.views.TRANSITION.DOWN');
return TRANSITION.DOWN;
}
});
Object.defineProperty(ViewManager.prototype, "RIGHT", {
get: function () {
warn('jibo.rendering.gui.ViewManager.RIGHT is deprecated, please use jibo.face.views.TRANSITION.RIGHT');
return TRANSITION.RIGHT;
}
});
Object.defineProperty(ViewManager.prototype, "LEFT", {
get: function () {
warn('jibo.rendering.gui.ViewManager.LEFT is deprecated, please use jibo.face.views.TRANSITION.LEFT');
return TRANSITION.LEFT;
}
});
Object.defineProperty(ViewManager.prototype, "IN", {
get: function () {
warn('jibo.rendering.gui.ViewManager.IN is deprecated, please use jibo.face.views.TRANSITION.IN');
return TRANSITION.IN;
}
});
Object.defineProperty(ViewManager.prototype, "OUT", {
get: function () {
warn('jibo.rendering.gui.ViewManager.OUT is deprecated, please use jibo.face.views.TRANSITION.OUT');
return TRANSITION.OUT;
}
});
Object.defineProperty(ViewManager.prototype, "NONE", {
get: function () {
warn('jibo.rendering.gui.ViewManager.NONE is deprecated, please use jibo.face.views.TRANSITION.NONE');
return TRANSITION.NONE;
}
});
Object.defineProperty(jibo.rendering.gui.ViewManager, "TRANS_UP", {
get: function () {
warn('jibo.rendering.gui.ViewManager.TRANS_UP is deprecated, please use jibo.face.views.TRANSITION.UP');
return TRANSITION.UP;
}
});
Object.defineProperty(jibo.rendering.gui.ViewManager, "TRANS_DOWN", {
get: function () {
warn('jibo.rendering.gui.ViewManager.TRANS_DOWN is deprecated, please use jibo.face.views.TRANSITION.DOWN');
return TRANSITION.DOWN;
}
});
Object.defineProperty(jibo.rendering.gui.ViewManager, "TRANS_RIGHT", {
get: function () {
warn('jibo.rendering.gui.ViewManager.TRANS_RIGHT is deprecated, please use jibo.face.views.TRANSITION.RIGHT');
return TRANSITION.RIGHT;
}
});
Object.defineProperty(jibo.rendering.gui.ViewManager, "TRANS_LEFT", {
get: function () {
warn('jibo.rendering.gui.ViewManager.TRANS_LEFT is deprecated, please use jibo.face.views.TRANSITION.LEFT');
return TRANSITION.LEFT;
}
});
Object.defineProperty(jibo.rendering.gui.ViewManager, "TRANS_IN", {
get: function () {
warn('jibo.rendering.gui.ViewManager.TRANS_IN is deprecated, please use jibo.face.views.TRANSITION.IN');
return TRANSITION.IN;
}
});
Object.defineProperty(jibo.rendering.gui.ViewManager, "TRANS_EYE", {
get: function () {
warn('jibo.rendering.gui.ViewManager.TRANS_EYE is deprecated, please use jibo.face.views.TRANSITION.EYE');
return TRANSITION.EYE;
}
});
Object.defineProperty(jibo.rendering.gui.ViewManager, "TRANS_OUT", {
get: function () {
warn('jibo.rendering.gui.ViewManager.TRANS_OUT is deprecated, please use jibo.face.views.TRANSITION.OUT');
return TRANSITION.OUT;
}
});
Object.defineProperty(jibo.rendering.gui.ViewManager, "TRANS_NONE", {
get: function () {
warn('jibo.rendering.gui.ViewManager.TRANS_NONE is deprecated, please use jibo.face.views.TRANSITION.NONE');
return TRANSITION.NONE;
}
});
Object.defineProperty(jibo.rendering.gui.ViewManager, "NONE", {
get: function () {
warn('jibo.rendering.gui.ViewManager.NONE is deprecated, please use jibo.face.views.TRANSITION.NONE');
return TRANSITION.NONE;
}
});
Object.defineProperty(ViewManager.prototype, "INITIALIZED", {
get: function () {
warn('jibo.rendering.gui.ViewManager.INITIALIZED is deprecated, please use jibo.face.views.STATE.INITIALIZED');
return STATE.INITIALIZED;
}
});
Object.defineProperty(ViewManager.prototype, "DATA_LOADED", {
get: function () {
warn('jibo.rendering.gui.ViewManager.DATA_LOADED is deprecated, please use jibo.face.views.STATE.DATA_LOADED');
return STATE.DATA_LOADED;
}
});
Object.defineProperty(ViewManager.prototype, "ASSETS_LOADED", {
get: function () {
warn('jibo.rendering.gui.ViewManager.ASSETS_LOADED is deprecated, please use jibo.face.views.STATE.ASSETS_LOADED');
return STATE.ASSETS_LOADED;
}
});
Object.defineProperty(ViewManager.prototype, "LOADED", {
get: function () {
warn('jibo.rendering.gui.ViewManager.LOADED is deprecated, please use jibo.face.views.STATE.LOADED');
return STATE.LOADED;
}
});
Object.defineProperty(ViewManager.prototype, "OPENED", {
get: function () {
warn('jibo.rendering.gui.ViewManager.OPENED is deprecated, please use jibo.face.views.STATE.OPENED');
return STATE.OPENED;
}
});
Object.defineProperty(ViewManager.prototype, "CLOSED", {
get: function () {
warn('jibo.rendering.gui.ViewManager.CLOSED is deprecated, please use jibo.face.views.STATE.CLOSED');
return STATE.CLOSED;
}
});
Object.defineProperty(ViewManager.prototype, "CATEGORY_GUI", {
get: function () {
warn('jibo.rendering.gui.ViewManager.CATEGORY_GUI is deprecated, please use jibo.face.views.CATEGORY.GUI');
return CATEGORY.GUI;
}
});
Object.defineProperty(ViewManager.prototype, "CATEGORY_DISPLAY", {
get: function () {
warn('jibo.rendering.gui.ViewManager.CATEGORY_DISPLAY is deprecated, please use jibo.face.views.CATEGORY.DISPLAY');
return CATEGORY.DISPLAY;
}
});
Object.defineProperty(ViewManager.prototype, "CATEGORY_EYE", {
get: function () {
warn('jibo.rendering.gui.ViewManager.CATEGORY_EYE is deprecated, please use jibo.face.views.CATEGORY.EYE');
return CATEGORY.EYE;
}
});
Object.defineProperty(ViewManager.prototype, "TAP", {
get: function () {
warn('jibo.rendering.gui.ViewManager.TAP is deprecated, please use jibo.face.views.GESTURE.TAP');
return GESTURE.TAP;
}
});
Object.defineProperty(ViewManager.prototype, "SWIPE", {
get: function () {
warn('jibo.rendering.gui.ViewManager.SWIPE is deprecated, please use jibo.face.views.GESTURE.SWIPE_DOWN');
return GESTURE.SWIPE_DOWN;
}
});
Object.defineProperty(ViewManager.prototype, "STACK_ADD", {
get: function () {
warn('jibo.rendering.gui.ViewManager.STACK_ADD is deprecated, please use jibo.face.views.STACK_DIRECTION.ADD');
return STACK_DIRECTION.ADD;
}
});
Object.defineProperty(ViewManager.prototype, "STACK_REMOVE", {
get: function () {
warn('jibo.rendering.gui.ViewManager.STACK_REMOVE is deprecated, please use jibo.face.views.STACK_DIRECTION.REMOVE');
return STACK_DIRECTION.REMOVE;
}
});
Object.defineProperty(ViewManager.prototype, "STACK_SWAP", {
get: function () {
warn('jibo.rendering.gui.ViewManager.STACK_SWAP is deprecated, please use jibo.face.views.STACK_DIRECTION.SWAP');
return STACK_DIRECTION.SWAP;
}
});
ViewManager.prototype.closeAll = function (onClosedAll, openTransition, closeTransition) {
warn('jibo.face.views.closeAll is deprecated, please use:' +
' jibo.face.views.changeView({removeAll:true, closeTransition:closeTransition}, onClosedAll)');
const config = {
removeAll: true,
openTransition: openTransition,
closeTransition: closeTransition
};
this.changeView(config, onClosedAll);
};
ViewManager.prototype.closeAllThenAdd = function (viewDeterminer, onAdded, openTransition, closeTransition) {
warn('jibo.face.views.closeAllThenAdd is deprecated, please use:' +
' jibo.face.views.changeView({removeAll:true, add:viewDeterminer, openTransition:openTransition, closeTransition:closeTransition}, onAdded)');
const config = {
removeAll: true,
addView: viewDeterminer,
openTransition: openTransition,
closeTransition: closeTransition
};
this.changeView(config, onAdded);
};
ViewManager.prototype.closeAllLeaveEmpty = function (onClosedAll, closeTransition) {
warn('jibo.face.views.closeAllLeaveEmpty is deprecated, please use:' +
' jibo.face.views.changeView({removeAll:true, leaveEmpty:true, closeTransition:closeTransition}, onClosedAll)');
const config = {
removeAll: true,
leaveEmpty: true,
closeTransition: closeTransition
};
this.changeView(config, onClosedAll);
};
ViewManager.prototype.removeViewLeaveEmpty = function (onRemoved, closeTransition, onFailure) {
warn('jibo.face.views.removeViewLeaveEmpty is deprecated, please use' +
' jibo.face.views.changeView({remove:true, leaveEmpty:true, closeTransition:closeTransition}, onRemoved, onFailure)');
const config = {
remove: true,
leaveEmpty: true,
closeTransition: closeTransition
};
this.changeView(config, onRemoved, onFailure);
};
ViewManager.prototype.removeAllThenAdd = function (view, onAdded, openTransition, closeTransition, onFailure) {
warn('jibo.face.views.removeAllThenAdd is deprecated, please use' +
' jibo.face.views.changeView({removeAll:true, add:view, openTransition:openTransition, closeTransition:closeTransition}, onAdded, onFailure)');
const config = {
removeAll: true,
addView: view,
openTransition: openTransition,
closeTransition: closeTransition
};
this.changeView(config, onAdded, onFailure);
};
ViewManager.prototype.removeAllLeaveEmpty = function (onClosedAll, closeTransition, onFailure) {
warn('jibo.face.views.removeAllLeaveEmpty is deprecated, please use' +
' jibo.face.views.changeView({removeAll:true, leaveEmpty:true, closeTransition:closeTransition}, onClosedAll, onFailure)');
const config = {
removeAll: true,
leaveEmpty: true,
closeTransition: closeTransition
};
this.changeView(config, onClosedAll, onFailure);
};
ViewManager.prototype.removeAll = function (onClosedAll, openTransition, closeTransition, onFailure) {
warn('jibo.face.views.removeAll is deprecated, please use' +
' jibo.face.views.changeView({removeAll:true, openTransition:openTransition, closeTransition:closeTransition}, onClosedAll, onFailure)');
const config = {
removeAll: true,
openTransition: openTransition,
closeTransition: closeTransition
};
this.changeView(config, onClosedAll, onFailure);
};
Object.defineProperty(jibo.rendering.gui.TouchManager, "TAP", {
get: function () {
warn('jibo.rendering.gui.TouchManager.TAP is deprecated, please use jibo.face.views.GESTURE.TAP');
return GESTURE.TAP;
}
});
Object.defineProperty(jibo.rendering.gui.TouchManager, "SWIPE", {
get: function () {
warn('jibo.rendering.gui.TouchManager.SWIPE is deprecated, please use jibo.face.views.GESTURE.SWIPE_DOWN');
return GESTURE.SWIPE_DOWN;
}
});
Object.defineProperty(jibo.rendering.gui.TouchManager, "PAN", {
get: function () {
warn('jibo.rendering.gui.TouchManager.PAN is deprecated, please use jibo.face.views.GESTURE.PAN');
return GESTURE.PAN;
}
});
Object.defineProperty(jibo.rendering.gui.views.View.prototype, "swipeDownActions", {
get: function () {
warn('jibo.rendering.gui.View.swipeDownActions get is deprecated, ' +
'use jibo.face.views.View.getActions(jibo.face.views.SWIPE_DOWN)');
return this.getActions('swipeDown');
},
set: function (actions) {
warn('jibo.rendering.gui.View.swipeDownActions set is deprecated, ' +
'use jibo.face.views.View.addAction(ActionData|string, Object|null, false, false, jibo.face.views.SWIPE_DOWN) for each action');
if (actions.length > 0) {
for (let i = 0; i < actions.length; i++) {
this.addAction(actions[i], null, (i === 0), false, 'swipeDown');
}
}
else {
this.clearActions('swipeDown');
}
},
enumerable: true
});
View.prototype.setupScreenClick = function () {
warn("Views.setupScreenClick is deprecated and no longer necessary, just use addAction and specify 'tap' as the gesture");
};
Object.defineProperty(jibo.rendering.gui.views.View, "INITIALIZED", {
get: function () {
warn('jibo.rendering.gui.views.View.INITIALIZED is deprecated, please use jibo.face.views.STATE.INITIALIZED');
return STATE.INITIALIZED;
}
});
Object.defineProperty(jibo.rendering.gui.views.View, "DATA_LOADED", {
get: function () {
warn('jibo.rendering.gui.views.View.DATA_LOADED is deprecated, please use jibo.face.views.STATE.DATA_LOADED');
return STATE.DATA_LOADED;
}
});
Object.defineProperty(jibo.rendering.gui.views.View, "ASSETS_LOADED", {
get: function () {
warn('jibo.rendering.gui.views.View.ASSETS_LOADED is deprecated, please use jibo.face.views.STATE.ASSETS_LOADED');
return STATE.ASSETS_LOADED;
}
});
Object.defineProperty(jibo.rendering.gui.views.View, "LOADED", {
get: function () {
warn('jibo.rendering.gui.views.View.LOADED is deprecated, please use jibo.face.views.STATE.LOADED');
return STATE.LOADED;
}
});
Object.defineProperty(jibo.rendering.gui.views.View, "OPENED", {
get: function () {
warn('jibo.rendering.gui.views.View.OPENED is deprecated, please use jibo.face.views.STATE.OPENED');
return STATE.OPENED;
}
});
Object.defineProperty(jibo.rendering.gui.views.View, "CLOSED", {
get: function () {
warn('jibo.rendering.gui.views.View.CLOSED is deprecated, please use jibo.face.views.STATE.CLOSED');
return STATE.CLOSED;
}
});
Object.defineProperty(jibo.rendering.gui.views.View, "DESTROYED", {
get: function () {
warn('jibo.rendering.gui.views.View.DESTROYED is deprecated, please use jibo.face.views.STATE.DESTROYED');
return STATE.DESTROYED;
}
});
Object.defineProperty(jibo.rendering.gui.views.View, "LOAD_ERROR", {
get: function () {
warn('jibo.rendering.gui.views.View.LOAD_ERROR is deprecated, please use jibo.face.views.STATE.LOAD_ERROR');
return STATE.LOAD_ERROR;
}
});
Object.defineProperty(jibo.rendering.gui.views.View, "CATEGORY_GUI", {
get: function () {
warn('jibo.rendering.gui.views.View.CATEGORY_GUI is deprecated, please use jibo.face.views.CATEGORY.GUI');
return CATEGORY.GUI;
}
});
Object.defineProperty(jibo.rendering.gui.views.View, "CATEGORY_DISPLAY", {
get: function () {
warn('jibo.rendering.gui.views.View.CATEGORY_DISPLAY is deprecated, please use jibo.face.views.CATEGORY.DISPLAY');
return CATEGORY.DISPLAY;
}
});
Object.defineProperty(jibo.rendering.gui.views.View, "CATEGORY_EYE", {
get: function () {
warn('jibo.rendering.gui.views.View.CATEGORY_EYE is deprecated, please use jibo.face.views.CATEGORY.EYE');
return CATEGORY.EYE;
}
});
Factory.prototype.addBehavior = function (mod, namespace) {
warn("Factory.addBehavior is deprecated, please use jibo.bt.register");
namespace = namespace || "";
const name = path.parse(mod.filename).name
.replace(/[^\d\w]/g, ' ')
.toLowerCase()
.replace(/(?:^|\s)(\w)/g, (matches, letter) => {
return letter.toUpperCase();
});
this.register(name, namespace, mod.exports);
};
Factory.prototype.createBehavior = function (object) {
warn("jibo.bt.createBehavior is deprecated, please extend from jibo.bt.Behavior and use jibo.bt.register");
return newBehavior(object);
};
Factory.prototype.createDecorator = function (object) {
warn("jibo.bt.createDecorator is deprecated, please extend from jibo.bt.Decorator and use jibo.bt.register");
return newDecorator(object);
};
function newBehavior(config) {
config = Object.assign({
constructor: function () { },
start: function () { return true; },
update: function () { return this.currentStatus; },
stop: function () { }
}, config);
class NewElement extends Behavior_1.default {
constructor(options) {
super(options);
for (let method in config) {
if (method === "constructor") {
continue;
}
if (typeof config[method] === "function") {
this[method] = config[method];
}
}
config.constructor.call(this, options);
}
update() {
return config.update.call(this);
}
}
return NewElement;
}
function newDecorator(config) {
config = Object.assign({
constructor: function () { },
start: function () { return true; },
update: function (status) { return status; },
stop: function () { }
}, config);
class NewElement extends Decorator_1.default {
constructor(options) {
super(options);
for (let method in config) {
if (method === "constructor") {
continue;
}
if (method === "name") {
continue;
}
if (method === "namespace") {
continue;
}
this[method] = config[method];
}
config.constructor.call(this, options);
}
update(result) {
return config.update.call(this, result);
}
}
return NewElement;
}
Factory.prototype.registerBehavior = function (config) {
warn("jibo.bt.registerBehavior is deprecated, please extend from jibo.bt.Behavior and use jibo.bt.register");
let name = config.name;
let namespace = config.namespace;
let Constructor = newBehavior(config);
this.register(name, namespace, Constructor);
return Constructor;
};
Factory.prototype.registerDecorator = function (config) {
warn("jibo.bt.registerDecorator is deprecated, please extend from jibo.bt.Decorator and use jibo.bt.register");
let name = config.name;
let namespace = config.namespace;
let Constructor = newDecorator(config);
this.register(name, namespace, Constructor);
return Constructor;
};
jibo.bt.Behavior.prototype.setDecorators = function (decorators) {
warn("Behavior.setDecorators is deprecated, please use Behavior.decorators setter, e.g. behavior.decorators = []");
this.decorators = decorators;
return this;
};
jibo.bt.Behavior.prototype.getName = function () {
warn("Behavior.getName is deprecated, please use Behavior.name getter, e.g. behavior.name");
return this.name;
};
jibo.bt.Behavior.prototype.setChildren = function (children) {
warn("Behavior.setChildren is deprecated, please use Behavior.children setter, e.g. behavior.children = []");
this.children = children;
};
FaceRenderer.prototype.setRenderOnlyWhenDirty = function () {
warn("renderer.setRenderOnlyWhenDirty is deprecated and no required");
};
Object.defineProperty(FaceRenderer.prototype, "scene", {
get: function () {
let thiz = this;
return {
stop() {
warn("renderer.scene.stop() is deprecated, please use jibo.face.paused = true");
thiz.paused = true;
},
play() {
warn("renderer.scene.play() is deprecated, please use jibo.face.paused = false");
thiz.paused = false;
}
};
}
});
jibo.utils.AudioUtils = {
getPath: (fileName) => {
warn("AudioUtils.getPath is deprecated, please use PathUtils.setDefaultPath('audio', fileName)");
return PathUtils.setDefaultPath('audio', fileName);
},
startAudio: (audioPath, assetPack, cb) => {
warn("AudioUtils.startAudio is deprecated, please use SoundUtils.playOnce(fileName, callback)");
const uri = PathUtils.getAudioUri(audioPath, assetPack);
jibo.sound.SoundUtils.playOnce(uri, cb);
return audioPath;
}
};
jibo.services.Media.prototype.getUrlById = function (id) {
warn('Media.getUrlById is deprecated, please use Media.getUrl');
return jibo.Runtime.instance.getUrl(id);
};
Object.defineProperties(jibo.rendering.animation.KeysAnimation.prototype, {
setSpeed: {
value: function (speed) {
warn('KeysAnimation.setSpeed is deprecated, please use KeysAnimation.builder.setSpeed(speed)');
return this._builder.setSpeed(speed);
}
},
setNumLoops: {
value: function (numLoops) {
warn('KeysAnimation.setNumLoops is deprecated, please use KeysAnimation.builder.setNumLoops(numLoops)');
this._builder.setNumLoops(numLoops);
}
},
setDOFs: {
value: function (dofNames) {
warn('KeysAnimation.setDOFs is deprecated, please use KeysAnimation.builder.setDOFs(dofNames)');
this._builder.setDOFs(dofNames);
}
},
getDOFs: {
value: function (dofNames) {
warn('KeysAnimation.getDOFs is deprecated, please use KeysAnimation.builder.getDOFs()');
return this._builder.getDOFs(dofNames);
}
},
setPlayBounds: {
value: function (inPoint, outPoint) {
warn('KeysAnimation.setPlayBounds is deprecated, please use KeysAnimation.builder.setPlayBounds(inPoint, outPoint)');
this._builder.setPlayBounds(inPoint, outPoint);
}
},
getSourceAnimationDuration: {
value: function () {
warn('KeysAnimation.getSourceAnimationDuration is deprecated, please use KeysAnimation.builder.getSourceAnimationDuration()');
return this._builder.getSourceAnimationDuration();
}
}
});
Object.defineProperty(RuntimePrototype, 'attention', {
get: function () {
throw new Error('jibo.attention has been removed, please use jibo.expression');
}
});
Object.defineProperty(RuntimePrototype, 'dofArbiter', {
get: function () {
throw new Error('jibo.dofArbiter has been removed, please use jibo.expression');
}
});
Object.defineProperty(jibo.services.GlobalEvents.prototype, "stop", {
get: function () {
warn("jibo.globalEvents.stop has been renamed to jibo.globalEvents.voiceStop");
return jibo.Runtime.instance.globalEvents.voiceStop;
}
});
Object.defineProperty(jibo.services.GlobalEvents.prototype, "touchOn", {
get: function () {
warn("jibo.globalEvents.touchOn has been renamed to jibo.globalEvents.touchStop");
return jibo.Runtime.instance.globalEvents.touchStop;
}
});
}
exports.default = default_1;
},{"./bt/Behavior":3,"./bt/Decorator":7,"./utils/electron":205,"fs":undefined,"jibo-flow-core":undefined,"path":undefined}],66:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Status_1 = require("../bt/Status");
const Subtree_1 = require("../bt/behaviors/Subtree");
const Mim_1 = require("../bt/behaviors/Mim");
const Menu_1 = require("../bt/behaviors/Menu");
const log_1 = require("./log");
const path = require("path");
class ActivityImplementation {
constructor(activity, flowExecutor, optionCodeThis) {
this.activity = activity;
this.flowExecutor = flowExecutor;
this.name = activity.name;
this.class = activity.class;
this.assetPack = activity.assetPack;
this.optionCodeThis = optionCodeThis;
this.options = flowExecutor.context.getActivityOptions(activity.id, this.optionCodeThis);
this.transitions = activity.transitions;
this.exceptions = activity.exceptions;
this.result = null;
this.exceptionPayload = null;
}
start(context) { return true; }
update(context) { return Status_1.default.SUCCEEDED; }
stop(context) {
return Promise.resolve();
}
destroy() { }
formOrThrowException(jsexception) {
let exception = '~Exception.' + jsexception.name;
if (!this.flowExecutor.searchException(exception)) {
throw jsexception;
}
return exception;
}
getResultAsString() {
let activityResult = this.result;
if (activityResult === undefined) {
activityResult = '';
}
return String(activityResult);
}
}
class FlowBegin extends ActivityImplementation {
}
class FlowNop extends ActivityImplementation {
}
class FlowBeginParallel extends ActivityImplementation {
}
class FlowWait extends ActivityImplementation {
start() {
this.startTime = Date.now();
this.ms_to_pause = parseFloat(this.options.ms_to_pause);
return true;
}
update() {
let success = Date.now() - this.startTime >= this.ms_to_pause;
return success ? Status_1.default.SUCCEEDED : Status_1.default.IN_PROGRESS;
}
}
class FlowSubflow extends ActivityImplementation {
update() {
let subflow = typeof this.options.subflowId === typeof ''
? this.options.subflowId
: this.options.subflowId();
this.flowExecutor.enterProcedure(subflow, undefined, this.options.inputParameters());
return Status_1.default.SUCCEEDED;
}
}
class FlowEnd extends ActivityImplementation {
update() {
let transition = this.options.getTransition();
if (transition === undefined) {
transition = this.name || '';
}
this.flowExecutor.emitStoppingActivity();
this.flowExecutor.returnFromProcedure(transition);
return Status_1.default.SUCCEEDED;
}
}
class FlowCatch extends ActivityImplementation {
update() {
if (typeof (this.options.getTransition) === 'function') {
this.result = this.options.getTransition(this.optionCodeThis.in.name, this.optionCodeThis.in.payload);
}
return Status_1.default.SUCCEEDED;
}
}
class FlowThrow extends ActivityImplementation {
update() {
this.result = this.name;
this.exceptionPayload = this.options.getPayload && this.options.getPayload();
return Status_1.default.SUCCEEDED;
}
}
class FlowInterrupt extends ActivityImplementation {
update() {
let payload = this.options.getPayload && this.options.getPayload();
this.flowExecutor.injectExceptionInPrimary(this.name, payload);
this.result = '';
return Status_1.default.SUCCEEDED;
}
}
class FlowEval extends ActivityImplementation {
update() {
this.result = this.options.Script();
return Status_1.default.SUCCEEDED;
}
}
class FlowBehavior extends ActivityImplementation {
constructor(activity, flowExecutor, behavior, optionCodeThis) {
super(activity, flowExecutor, optionCodeThis);
this.behavior = behavior;
}
start() {
return this.behavior.start();
}
update() {
return this.behavior.update(Status_1.default.IN_PROGRESS);
}
stop() {
return this.behavior ? this.behavior.stop() : Promise.resolve();
}
destroy() {
if (this.behavior) {
this.behavior.destroy();
this.behavior = null;
}
}
}
exports.FlowBehavior = FlowBehavior;
class FlowMim extends ActivityImplementation {
constructor(activity, flowExecutor, optionCodeThis) {
super(activity, flowExecutor, optionCodeThis);
let options = this.options;
this.activityClass = activity.class;
if (options.mimId && !options.mimPath) {
let env = flowExecutor.environment;
options.mimPath = path.join('mims', env.language, options.mimId);
if (!options.mimPath.endsWith('.mim')) {
options.mimPath += '.mim';
}
if (!options.config) {
options.config = {};
}
options.config.rulesPath = path.join('rules', env.language);
}
if (typeof options.getMimPath === 'function') {
options.mimPath = options.getMimPath();
}
if (!options.innerOnSuccess) {
options.innerOnSuccess = options.onSuccess || options.onResults;
}
let onSuccess = this.activityClass === 'Mim.Announcement'
? () => { }
: (result) => {
let firstGrammarTag = '';
if (result.asrResults && result.asrResults.intent) {
firstGrammarTag = result.firstGrammarTag = result.asrResults.intent;
result.grammarResults = result.asrResults.entities;
}
let transition = options.innerOnSuccess(result);
if (transition === undefined) {
transition = firstGrammarTag;
}
this.transition = transition;
};
options.onSuccess = onSuccess;
if (!options.innerOnFailure) {
options.innerOnFailure = options.onFailure;
}
let onFailure = (this.activityClass !== 'Mim.Question' && this.activityClass !== 'Mim')
? () => { }
: (result) => {
let exception = "~InteractionError." + result.state.lastResultState;
result.exception = exception;
let transition = options.innerOnFailure(result);
if (transition === undefined) {
transition = exception;
}
this.transition = transition;
return flowExecutor.searchException(transition) !== undefined;
};
options.onFailure = onFailure;
options.assetPack = flowExecutor.assetPack;
options.blackboard = flowExecutor.blackboard;
options.emitter = flowExecutor.emitter;
options.asrMetadata = {
flowFile: flowExecutor.environment.currentFile,
activityName: activity.name,
activityId: activity.id
};
this.mim = new Mim_1.default(options);
}
start() {
return this.mim.start();
}
update() {
let status = this.mim.update();
if (status !== Status_1.default.IN_PROGRESS) {
if (status === Status_1.default.FAILED) {
this.result = '~MimFailed';
}
else {
this.result = this.transition;
}
}
return status;
}
stop() {
return this.mim ? this.mim.stop() : Promise.resolve();
}
destroy() {
if (this.mim) {
this.mim.destroy();
this.mim = null;
}
}
}
exports.FlowMim = FlowMim;
class FlowSubtree extends ActivityImplementation {
constructor(activity, flowExecutor, optionCodeThis) {
super(activity, flowExecutor, optionCodeThis);
if (!this.options.onInnerResult) {
this.options.onInnerResult = this.options.onResult;
}
let onResult = (result) => {
this.transition = this.options.onInnerResult(result);
};
this.options.onResult = onResult;
this.options.assetPack = flowExecutor.assetPack;
this.options.blackboard = flowExecutor.blackboard;
this.options.emitter = flowExecutor.emitter;
this.subtree = new Subtree_1.default(this.options);
}
start() {
return this.subtree.start();
}
update() {
let status = this.subtree.update();
if (status !== Status_1.default.IN_PROGRESS) {
this.result = this.transition;
}
return status;
}
stop() {
return this.subtree ? this.subtree.stop() : Promise.resolve();
}
destroy() {
if (this.subtree) {
this.subtree.destroy();
this.subtree = null;
}
}
}
exports.FlowSubtree = FlowSubtree;
class FlowEvalAsync extends ActivityImplementation {
start() {
this.isDone = false;
try {
this.options.exec((transition) => {
if (!this.isDone) {
this.isDone = true;
this.result = transition;
}
});
}
catch (e) {
if (!this.isDone) {
this.isDone = true;
this.exceptionPayload = e;
this.result = this.formOrThrowException(e);
}
}
return true;
}
update() {
if (this.isDone) {
return Status_1.default.SUCCEEDED;
}
return Status_1.default.IN_PROGRESS;
}
stop() {
if (this.options.onStop) {
return this.options.onStop() || Promise.resolve();
}
return Promise.resolve();
}
}
exports.FlowEvalAsync = FlowEvalAsync;
class FlowMenu extends ActivityImplementation {
constructor(activity, flowExecutor, optionCodeThis) {
super(activity, flowExecutor, optionCodeThis);
let options = this.options;
if (!options.innerOnItemChosen) {
options.innerOnItemChosen = options.onItemChosen;
if (options.innerOnItemChosen.length === 2) {
log_1.default.warn('Menu::onItemChosen signature has changed from (result, menu) => string to (result, menu, overrideMenuTransition) => string');
}
}
let onItemChosen = (result, menu, overrideMenuTransition) => {
let firstGrammarTag = '';
if (result && result.intent) {
firstGrammarTag = result.intent;
}
let transition = options.innerOnItemChosen(result, menu, overrideMenuTransition);
if (transition === undefined) {
transition = firstGrammarTag;
}
this.transition = transition;
};
options.onItemChosen = onItemChosen;
if (!options.innerOnMenuClosed) {
options.innerOnMenuClosed = options.onMenuClosed;
if (options.innerOnMenuClosed.length === 3) {
log_1.default.warn('Menu::onMenuClosed signature has changed from (wasTimeout, menu, exception) => string to (wasTimeout, menu, overrideMenuTransition, exception) => string');
}
}
let onMenuClosed = (timedOut, menu, overrideMenuTransition) => {
let exception = "~InteractionError." + (timedOut ? 'MenuTimeout' : 'MenuClosed');
let transition = options.innerOnMenuClosed(timedOut, menu, overrideMenuTransition, exception);
if (transition === undefined) {
transition = exception;
}
this.transition = transition;
return flowExecutor.searchException(transition) !== undefined;
};
options.onMenuClosed = onMenuClosed;
options.assetPack = flowExecutor.assetPack;
options.blackboard = flowExecutor.blackboard;
options.emitter = flowExecutor.emitter;
this.menu = new Menu_1.default(options);
}
start() {
return this.menu.start();
}
update() {
let status = this.menu.update();
if (status !== Status_1.default.IN_PROGRESS) {
this.result = this.transition;
if (status === Status_1.default.FAILED) {
this.result = this.transition = '~MenuFailed';
}
}
return status;
}
stop() {
return this.menu ? this.menu.stop() : Promise.resolve();
}
destroy() {
if (this.menu) {
this.menu.destroy();
this.menu = null;
}
}
}
exports.FlowMenu = FlowMenu;
exports.FlowClasses = {
FlowBegin,
FlowBeginParallel,
FlowInterrupt,
FlowCatch,
FlowEvalAsync,
FlowNop,
FlowWait,
FlowSubflow,
FlowSubtree,
FlowEnd,
FlowThrow,
FlowEval,
Mim: FlowMim,
MimAnnouncement: FlowMim,
MimOptionalResponse: FlowMim,
MimQuestion: FlowMim,
Menu: FlowMenu
};
exports.default = ActivityImplementation;
},{"../bt/Status":10,"../bt/behaviors/Menu":15,"../bt/behaviors/Mim":16,"../bt/behaviors/Subtree":24,"./log":74,"path":undefined}],67:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ActivityImplementation_1 = require("./ActivityImplementation");
const Runtime_1 = require("../Runtime");
class ActivityImplementationFactory {
static getImplementationOfActivity(activity, flowExecutor, optionCodeThis) {
let implementation;
optionCodeThis = optionCodeThis || {};
let result = this.getActivityOrBehaviorConstructor(activity);
if (result.isActivity) {
implementation = this.getActivityClassInstance(result.constructor, activity, flowExecutor, optionCodeThis);
}
else {
implementation = this.getBehaviorClassInstance(result.constructor, activity, flowExecutor, optionCodeThis);
}
this.logActivity(activity, flowExecutor);
let environment = flowExecutor.context.notepad.FlowEnv;
environment.currentActivity = implementation;
environment.currentProcedure = flowExecutor.context.current_procedure;
environment.currentFile = flowExecutor.context.current_procedure.uri;
let payload = {
timestamp: Date.now(),
thread: flowExecutor.name,
uri: flowExecutor.context.current_procedure.uri,
id: implementation.activity.id,
name: implementation.name,
class: implementation.class
};
flowExecutor.emit('constructing-activity', payload);
return implementation;
}
static getActivityOrBehaviorConstructor(activity) {
let className = this.getActivityImplementationClassName(activity);
let isActivity = true;
let constructor;
constructor = Runtime_1.default.instance.flow.getActivityConstructor(className, activity.assetPack);
if (!constructor) {
constructor = Runtime_1.default.instance.bt.getBehaviorConstructor(className, activity.assetPack);
if (constructor) {
isActivity = false;
}
}
if (!constructor) {
throw new Error(`No implementation found for activity type: "${activity.class}" in namespace "${activity.assetPack}"`);
}
return { isActivity: isActivity, constructor: constructor };
}
static getActivityImplementationClassName(activity) {
return activity.class.replace(/[.-]/g, '');
}
static getBehaviorClassInstance(behaviorConstructor, activity, flowExecutor, optionCodeThis) {
let behaviorOptions = Object.assign({
name: activity.name,
emitter: flowExecutor.emitter,
blackboard: flowExecutor.blackboard,
assetPack: flowExecutor.assetPack,
}, flowExecutor.context.getActivityOptions(activity.id, optionCodeThis));
let behavior = new behaviorConstructor(behaviorOptions);
return new ActivityImplementation_1.FlowBehavior(activity, flowExecutor, behavior, optionCodeThis);
}
static getActivityClassInstance(activityConstructor, activity, flowExecutor, optionCodeThis) {
return new activityConstructor(activity, flowExecutor, optionCodeThis);
}
static logActivity(activity, flowExecutor) {
let name = activity.name ? `("${activity.name}") ` : '';
flowExecutor.log(`jfe-Executing: ${activity.class} ${name}in ${flowExecutor.context.current_procedure.name}`);
}
}
exports.default = ActivityImplementationFactory;
},{"../Runtime":1,"./ActivityImplementation":66}],68:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Notepad {
setTransition(transition) {
this.context.current_activity.result = transition;
}
constructor(context, params, environment) {
this.context = context;
this.params = params;
this.FlowEnv = environment;
}
}
class Result {
constructor() {
this.transition = "";
}
}
class Context {
constructor(flowExecutor, parent, current_procedure, params, notepad) {
this.flowExecutor = flowExecutor;
this.parent = parent;
this.current_procedure = current_procedure;
this.asyncFlows = [];
this.notepad = notepad || new Notepad(this, params, flowExecutor.environment);
this.result = new Result();
this.code = current_procedure.procedureConstructor(this.flowExecutor.blackboard, this.notepad, this.result, this.flowExecutor.emitter);
}
getActivityOptions(activityId, optionCodeThis) {
if (!(activityId in this.code)) {
throw new Error(`FlowExecutor: Cannot find activity ID ${activityId} in procedure ${this.current_procedure.name}`);
}
let codeBehind = this.code[activityId];
let options;
if (typeof codeBehind === 'function') {
options = codeBehind.bind(optionCodeThis)().options;
}
else {
options = Object.assign({}, codeBehind.options || {});
}
return options;
}
}
class FlowExceptionInfo {
}
exports.FlowExceptionInfo = FlowExceptionInfo;
exports.default = Context;
},{}],69:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_plugins_1 = require("jibo-plugins");
class Environment {
constructor(assetPack) {
this.assetPack = assetPack;
this.assetPack = assetPack;
this.lastException = null;
this.language = "en-us";
this.projectRoot = jibo_plugins_1.PathUtils.findRoot();
}
}
exports.default = Environment;
},{"jibo-plugins":undefined}],70:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const State_1 = require("./State");
const ActivityImplementationFactory_1 = require("./ActivityImplementationFactory");
const Context_1 = require("./Context");
const Context_2 = require("./Context");
const Status_1 = require("../bt/Status");
const events_1 = require("events");
const Environment_1 = require("./Environment");
const Runtime_1 = require("../Runtime");
const log_1 = require("./log");
class FlowExecutor extends events_1.EventEmitter {
constructor(flowRoot, overrides) {
super();
this.context = null;
this.primary = null;
this.nextClonePid = 0;
overrides = overrides || {};
this.blackboard = overrides.blackboard || Runtime_1.default.instance.bt.getBlackboard();
this.emitter = overrides.emitter || new events_1.EventEmitter();
this.assetPack = overrides.assetPack || "";
this.params = overrides.params || {};
this.enableLogging = overrides.enableLogging || false;
this.environment = overrides.environment || new Environment_1.default(this.assetPack);
this.environment.flowOptions = overrides;
this.setupName(overrides);
this.preloadAnims();
this.state = State_1.default.READY;
if (flowRoot) {
this.flowRoot = flowRoot;
let payload = {
timestamp: Date.now(),
thread: this.name,
uri: flowRoot.startUri
};
this.emit('constructing-flow-executor', payload);
this.enterProcedure(flowRoot.startProcedureOrName, flowRoot.startUri, this.params);
}
}
setupName(overrides) {
FlowExecutor.InstanceCount++;
let pid = 0;
if (overrides.getNextPid) {
pid = overrides.getNextPid();
}
this.name = (overrides.name || '') + `${pid}-`;
}
preloadAnims() {
console.warn("preloading anim");
}
getNextPid() {
return this.nextClonePid++;
}
update() {
this.updateAsyncs(this.context);
return this.updatePrimary();
}
updatePrimary() {
let lastState;
while (this.state !== lastState) {
lastState = this.state;
this.step();
if (this.state === State_1.default.READY) {
break;
}
}
return this.state === State_1.default.EXITED;
}
step() {
switch (this.state) {
case State_1.default.READY: {
let success = false;
let current_activity = this.context.current_activity;
try {
success = current_activity.start(this.context);
}
catch (e) {
current_activity.exceptionPayload = e;
current_activity.result = current_activity.formOrThrowException(e);
}
this.state = !success ? State_1.default.DONE : State_1.default.IN_PROGRESS;
break;
}
case State_1.default.IN_PROGRESS: {
let current_activity = this.context.current_activity;
let status;
try {
status = current_activity.update(this.context);
}
catch (e) {
current_activity.exceptionPayload = e;
current_activity.result = current_activity.formOrThrowException(e);
this.state = State_1.default.DONE;
}
if (this.state !== State_1.default.IN_PROGRESS) {
}
else if (status === Status_1.default.SUCCEEDED || status === Status_1.default.FAILED) {
this.state = State_1.default.DONE;
if (status === Status_1.default.FAILED && this.context.current_activity.result === null) {
this.context.current_activity.result = 'fail';
}
}
break;
}
case State_1.default.DONE: {
this.state = State_1.default.READY;
this.selectAndFollowTransition();
break;
}
}
}
updateAsyncs(context) {
if (context) {
this.updateAsyncs(context.parent);
for (let i = 0; i < context.asyncFlows.length; i++) {
let flow = context.asyncFlows[i];
if (flow.update()) {
context.asyncFlows.splice(i--, 1);
}
}
}
}
start() {
this.emit('start');
}
stop() {
this.log('Stopped');
this.state = State_1.default.PAUSED;
const rtn = this.stopCurrentActivity();
this.emit('stop');
let payload = {
timestamp: Date.now(),
thread: this.name,
uri: this.context.current_procedure.uri
};
this.emit('stopping-flow-executor', payload);
return rtn;
}
finish() {
this.log('Finished');
this.emit('finished');
this.emit('flow-executor-finished', {
timestamp: Date.now(),
thread: this.name,
uri: this.context.current_procedure.relativeUri
});
}
stopCurrentActivity() {
return this.stopCurrentActivityInContext(this.context);
}
stopCurrentActivityInContext(context) {
this.emitStoppingActivity();
const current_activity = context.current_activity;
const rtn = current_activity.stop(context);
rtn.then(() => {
current_activity.destroy();
});
return rtn;
}
destroy() {
this.log('Destroyed');
FlowExecutor.InstanceCount--;
this.stopCurrentActivity();
this.emit('destroy');
let context = this.context;
while (context !== null) {
this.destroyAsyncFlows([context]);
context = context.parent;
}
this.flowRoot = null;
}
destroyAsyncFlows(contexts) {
for (let context of contexts) {
for (let flow of context.asyncFlows) {
flow.stop().then(() => {
flow.destroy();
});
}
context.asyncFlows = [];
}
}
stopAndDestroy() {
return this.stop().catch(() => { }).then(() => {
this.destroy();
});
}
enterProcedure(procedureObjectOrName, currentUri, params) {
if (currentUri === undefined) {
currentUri = this.context.current_procedure.uri;
}
let currentProcedure = this.flowRoot.loadProcedure(currentUri, procedureObjectOrName);
let payload = {
timestamp: Date.now(),
thread: this.name,
uri: currentProcedure.uri
};
this.emit('entering-procedure', payload);
params = params || {};
this.context = new Context_1.default(this, this.context, currentProcedure, params);
let beginActivity = currentProcedure.getBeginActivity();
this.context.current_activity = ActivityImplementationFactory_1.default.getImplementationOfActivity(beginActivity, this);
this.loadAsyncBegins();
}
loadAsyncBegins() {
let asyncBegins = this.context.current_procedure.getAsyncBeginActivities();
for (let asyncBegin of asyncBegins) {
this.context.asyncFlows.push(this.clone(asyncBegin));
}
}
clone(activity) {
let flow = new this.constructor(undefined, this);
flow.primary = this;
flow.flowRoot = this.flowRoot;
flow.context = new Context_1.default(flow, null, this.context.current_procedure, {}, this.context.notepad);
flow.context.current_activity = ActivityImplementationFactory_1.default.getImplementationOfActivity(activity, flow);
return flow;
}
emitStoppingActivity() {
let payload = {
timestamp: Date.now(),
thread: this.name,
uri: this.context.current_procedure.uri,
id: this.context.current_activity.activity.id,
name: this.context.current_activity.name,
class: this.context.current_activity.class,
result: this.context.current_activity.getResultAsString()
};
this.emit('stopping-activity', payload);
}
returnFromProcedure(transition) {
this.log('jfe-Procedure-Return', transition, this.context.current_procedure.relativeUri);
let payload = {
timestamp: Date.now(),
thread: this.name,
uri: this.context.current_procedure.uri,
result: transition
};
this.emit('returning-from-procedure', payload);
this.destroyAsyncFlows([this.context]);
let result = this.context.result;
result.transition = transition;
if (this.context.parent === null) {
this.state = State_1.default.EXITED;
this.result = result;
}
else {
this.context = this.context.parent;
if (this.context.current_activity.class !== "Flow.Subflow") {
throw new Error("Returned from a subflow (to something besides a Flow.Subflow activity");
}
this.context.current_activity.result = this.context.current_activity.options.getTransition(result);
}
}
selectAndFollowTransition() {
let dfault = null;
let selected = null;
let activityResult = this.context.current_activity.getResultAsString();
if (activityResult.startsWith('~')) {
this.throwException(activityResult);
return;
}
this.log('jfe-Transition: ', activityResult);
for (let transition of this.context.current_activity.transitions) {
if (transition.value === '') {
dfault = transition;
}
if (activityResult === transition.value) {
selected = transition;
break;
}
}
if (selected === null) {
if (dfault === null) {
let activity_type = this.context.current_activity.activity.class;
let procedure = this.context.current_procedure.name;
throw new Error(`Activity named "${this.context.current_activity.name}" of type ${activity_type}
in procedure "${procedure}" with result: "${activityResult}" found no matching transition.`);
}
selected = dfault;
}
this.transitionTo(selected.to);
}
injectExceptionInPrimary(exception, payload) {
this.primary.stopCurrentActivity();
this.primary.state = State_1.default.DONE;
this.primary.context.current_activity.result = exception;
this.primary.context.current_activity.exceptionPayload = payload;
}
searchException(exception) {
let context = this.context;
let foundActivity;
let abandonedContexts = [];
outer: do {
let exceptions = context.current_activity.exceptions
.sort((a, b) => b.value.length - a.value.length);
for (let transition of exceptions) {
if (this.isExceptionMatch(exception, transition.value)) {
foundActivity = context.current_procedure.activities[transition.to];
break outer;
}
}
let catches = Object.keys(context.current_procedure.activities)
.map((a) => context.current_procedure.activities[a])
.filter((a) => a.class === 'Flow.Catch')
.sort((a, b) => b.name.length - a.name.length);
for (let activity of catches) {
if (this.isExceptionMatch(exception, activity.name)) {
foundActivity = activity;
break outer;
}
}
abandonedContexts.push(context);
context = context.parent;
} while (context !== null);
if (context !== null) {
return {
context: context,
activity: foundActivity,
abandonedContexts: abandonedContexts
};
}
}
getCurrentStackTrace() {
let trace = [];
let context = this.context;
while (context !== null) {
trace.push({ activity: context.current_activity, procedure: context.current_procedure });
context = context.parent;
}
return trace;
}
getFlowExceptionInfo(exception) {
let flowException = new Context_2.FlowExceptionInfo();
flowException.name = exception;
flowException.activity = this.context.current_activity;
flowException.procedure = this.context.current_procedure;
flowException.stackTrace = this.getCurrentStackTrace();
flowException.payload = this.context.current_activity.exceptionPayload;
return flowException;
}
throwException(exception) {
this.log('jfe-Exception: ', exception);
this.state = State_1.default.PAUSED;
let found = this.searchException(exception);
if (!found) {
throw new Error(`Failed to find exception handler for ${exception}`);
}
let exceptionInfo = this.getFlowExceptionInfo(exception);
this.environment.lastException = exceptionInfo;
this.context.current_activity.result = exceptionInfo.name;
const prevOut = this.context.current_activity.optionCodeThis.out;
this.stopCurrentActivity().then(() => {
this.context = found.context;
this.context.current_activity = ActivityImplementationFactory_1.default.getImplementationOfActivity(found.activity, this, { in: prevOut || exceptionInfo, inTransition: exceptionInfo.name });
this.state = State_1.default.READY;
});
this.destroyAsyncFlows(found.abandonedContexts);
for (let context of found.abandonedContexts) {
this.stopCurrentActivityInContext(context);
}
}
isExceptionMatch(actual_exception, candidate_catch) {
if (!candidate_catch || !candidate_catch.startsWith('~') ||
!actual_exception || !actual_exception.startsWith('~')) {
return false;
}
let trycatch = candidate_catch.replace('~', '~.').replace(/\.$/, '');
let exception = actual_exception.replace('~', '~.').replace(/\.$/, '');
if (!exception.startsWith('~')) {
return false;
}
while (true) {
if (exception === trycatch) {
return true;
}
if (exception === '~') {
break;
}
exception = exception.replace(/\.[^.]+$/, '');
}
return false;
}
transitionTo(to) {
let nextActivityThis = {
'in': this.context.current_activity.optionCodeThis.out,
'inResult': this.context.current_activity.result,
'inTransition': this.context.current_activity.getResultAsString()
};
log_1.default.debug(this.name, 'transitionTo', nextActivityThis);
this.stopCurrentActivity();
this.context.current_activity =
ActivityImplementationFactory_1.default.getImplementationOfActivity(this.context.current_procedure.activities[to], this, nextActivityThis);
}
log(...args) {
log_1.default.debug(this.name, ...args);
}
}
FlowExecutor.InstanceCount = 0;
exports.default = FlowExecutor;
},{"../Runtime":1,"../bt/Status":10,"./ActivityImplementationFactory":67,"./Context":68,"./Environment":69,"./State":72,"./log":74,"events":undefined}],71:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FlowExecutor_1 = require("./FlowExecutor");
const jibo_flow_core_1 = require("jibo-flow-core");
const Runtime_1 = require("../Runtime");
const callsite = require("callsite");
const path = require("path");
const Status_1 = require("../bt/Status");
const State_1 = require("./State");
const log_1 = require("./log");
class FlowExecutorFactory {
static create(uri, overrides = {}) {
let flowRoot = jibo_flow_core_1.FlowRootFactory.create(uri);
let flowExecutor = overrides.flowExecutor || FlowExecutor_1.default;
return new flowExecutor(flowRoot, overrides);
}
constructor(flow) {
this._activities = {};
Object.assign(this, flow);
this.registerCore();
}
register(name, namespace, classRef) {
let ns = this._activities[namespace];
if (!ns) {
ns = this._activities[namespace] = {};
}
ns[name] = classRef;
}
registerCore() {
for (let name in this.activities) {
this.register(name, 'core', this.activities[name]);
}
}
getActivityConstructor(className, namespace) {
let ns = this._activities[namespace || 'core'];
if (ns) {
return ns[className];
}
}
create(uri, overrides = {}) {
let flowProcedure;
if (typeof uri === 'string') {
let calleeDirname = callsite()[1].getFileName();
flowProcedure = this.getFilePathFromCallee(calleeDirname, uri);
}
else {
flowProcedure = uri;
}
let flowRoot = jibo_flow_core_1.FlowRootFactory.create(flowProcedure);
let flowExecutor = overrides.flowExecutor || FlowExecutor_1.default;
return new flowExecutor(flowRoot, overrides);
}
run(uri, overrides = {}, onFinishedCallback = null) {
if (typeof (overrides) === "function") {
onFinishedCallback = overrides;
overrides = {};
}
let flowExecutor;
try {
flowExecutor = this.create(uri, overrides);
}
catch (e) {
log_1.default.error('Could not start flow: ', e, `uri: ${uri}, notepad overridden: ${!!overrides.notepad}, blackboard overridden: ${!!overrides.blackboard}, emitter overridden: ${!!overrides.emitter}, assetPack: ${overrides.assetPack}, stopOnException: ${overrides.stopOnException}, enableLogging: ${overrides.enableLogging}, flowExecutor overridden: ${!!overrides.flowExecutor}`);
throw e;
}
let isExited = flowExecutor.update();
function doUpdate(elapsed) {
if (!isExited) {
try {
isExited = flowExecutor.update();
}
catch (e) {
if (overrides.stopOnException || overrides.harnesses) {
clearTimer();
throw e;
}
log_1.default.error('FlowExecutor caught exception during update:', e);
if (onFinishedCallback !== null) {
clearTimer();
flowExecutor.removeListener('stop', stopUpdate);
flowExecutor.stop();
flowExecutor.destroy();
let callback = onFinishedCallback;
onFinishedCallback = null;
callback(e, Status_1.default.FAILED);
}
}
}
else {
flowExecutor.finish();
stopUpdate();
}
}
function clearTimer() {
Runtime_1.default.instance.timer.removeListener('update', doUpdate);
}
function stopUpdate() {
clearTimer();
if (onFinishedCallback) {
let callback = onFinishedCallback;
onFinishedCallback = null;
callback(null, flowExecutor.state === State_1.default.EXITED ? Status_1.default.SUCCEEDED : Status_1.default.INTERRUPTED);
}
}
function startUpdate() {
clearTimer();
Runtime_1.default.instance.timer.on('update', doUpdate);
}
flowExecutor.once('start', startUpdate);
flowExecutor.once('stop', stopUpdate);
flowExecutor.once('destroy', clearTimer);
flowExecutor.start();
return flowExecutor;
}
getFilePathFromCallee(calleeDirname, uri) {
let filePath;
uri = uri.substr(0, uri.lastIndexOf(path.parse(uri).ext));
if (!path.isAbsolute(uri)) {
if (calleeDirname.indexOf('file://') === 0) {
calleeDirname = calleeDirname.substr(7);
}
filePath = path.join(calleeDirname, '..', uri);
}
else {
filePath = uri;
}
return filePath;
}
}
exports.default = FlowExecutorFactory;
},{"../Runtime":1,"../bt/Status":10,"./FlowExecutor":70,"./State":72,"./log":74,"callsite":undefined,"jibo-flow-core":undefined,"path":undefined}],72:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var State;
(function (State) {
State[State["IN_PROGRESS"] = 0] = "IN_PROGRESS";
State[State["DONE"] = 1] = "DONE";
State[State["READY"] = 2] = "READY";
State[State["EXITED"] = 3] = "EXITED";
State[State["PAUSED"] = 4] = "PAUSED";
})(State || (State = {}));
exports.default = State;
},{}],73:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FlowExecutorFactory_1 = require("./FlowExecutorFactory");
exports.FlowExecutorFactory = FlowExecutorFactory_1.default;
const FlowExecutor_1 = require("./FlowExecutor");
exports.FlowExecutor = FlowExecutor_1.default;
const ActivityImplementation_1 = require("./ActivityImplementation");
exports.ActivityImplementation = ActivityImplementation_1.default;
const ActivityImplementation_2 = require("./ActivityImplementation");
const jibo_flow_core_1 = require("jibo-flow-core");
exports.Activity = jibo_flow_core_1.Activity;
exports.Procedure = jibo_flow_core_1.Procedure;
exports.FlowRootFactory = jibo_flow_core_1.FlowRootFactory;
const Context_1 = require("./Context");
exports.FlowExceptionInfo = Context_1.FlowExceptionInfo;
const core = require("jibo-flow-core");
exports.core = core;
const State_1 = require("./State");
exports.State = State_1.default;
let activities = ActivityImplementation_2.FlowClasses;
exports.activities = activities;
},{"./ActivityImplementation":66,"./Context":68,"./FlowExecutor":70,"./FlowExecutorFactory":71,"./State":72,"jibo-flow-core":undefined}],74:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
exports.default = log_1.default.createChild('Flow');
},{"../log":75}],75:[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');
},{"jibo-log":undefined}],76:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const action = require("jibo-action-system");
const Runtime_1 = require("../Runtime");
class ActionPlugin {
constructor() {
this.api = action.api;
}
init(done) {
const jibo = Runtime_1.default.instance;
if (jibo.runMode === jibo.RunMode.UNIT_TESTS) {
return done();
}
action.api.init({ jibo })
.then(() => done())
.catch(e => done(e));
}
}
Runtime_1.default.registerPlugin(ActionPlugin, 'action', {
depends: ['expression', 'services', 'anim-db'],
api: true,
name: 'action'
});
exports.default = ActionPlugin;
},{"../Runtime":1,"jibo-action-system":undefined}],77:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const animdb = require("jibo-anim-db");
const Runtime_1 = require("../Runtime");
const log_1 = require("../log");
class AnimDBPlugin {
constructor() {
this.api = animdb.api;
}
init(done) {
const jibo = Runtime_1.default.instance;
let promise;
const animDBPath = animdb.api.resolveAnimDB(jibo);
if (!animDBPath) {
log_1.default.warn(`Module 'jibo-anim-db-animations' not found. AnimDB plugin will not contain animations.`);
promise = animdb.api.init(jibo);
}
else {
promise = animdb.api.init(jibo, animDBPath);
}
promise.then(() => done())
.catch(err => {
log_1.default.error(`Error parsing AnimDB at path: '${animDBPath}':`, err);
done();
});
}
}
Runtime_1.default.registerPlugin(AnimDBPlugin, 'anim-db', {
depends: ['expression'],
api: true,
name: 'animDB'
});
exports.default = AnimDBPlugin;
},{"../Runtime":1,"../log":75,"jibo-anim-db":undefined}],78:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../Runtime");
class AutobotPlugin {
constructor() {
}
init(done) {
done(null, this);
}
executeCommand(command) {
const jibo = Runtime_1.default.instance;
if (!jibo['dev-shell'] || !jibo['dev-shell']._client) {
return;
}
process.nextTick(() => {
const client = jibo['dev-shell']._client;
try {
let result = eval(command.script);
client.send({
command: 'execute-result',
result,
id: command.id,
success: true
});
}
catch (error) {
client.send({
command: 'execute-result',
id: command.id,
error: error.toString(),
success: false
});
}
});
}
log(...args) {
const jibo = Runtime_1.default.instance;
if (!jibo['dev-shell'] || !jibo['dev-shell']._client) {
return;
}
const client = jibo['dev-shell']._client;
client.send({
command: 'autobot-log',
data: args
});
}
}
Runtime_1.default.registerPlugin(AutobotPlugin, 'autobot', {
depends: ['services'],
api: true,
name: 'autobot'
});
exports.default = AutobotPlugin;
},{"../Runtime":1}],79:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
const jibo_client_framework_1 = require("jibo-client-framework");
const Runtime_1 = require("../Runtime");
const log_1 = require("../log");
const log = log_1.default.createChild('DevShellPlugin');
class DevShellPlugin extends events_1.EventEmitter {
constructor() {
super();
}
init(done) {
const jibo = Runtime_1.default.instance;
jibo.systemManager.getMode((err, mode) => {
if (mode === 'int-developer' ||
mode === 'developer' ||
jibo.runMode === jibo.RunMode.SIMULATOR) {
log.info('Initializing DevShellPlugin...');
const records = jibo.records;
for (let i = 0; i < records.length; i++) {
let record = records[i];
if (record.name === 'dev-shell') {
this._devShellPortHost = `ws://127.0.0.1:${record.port}`;
break;
}
}
if (!this._devShellPortHost) {
done(new Error(`dev-shell service is down, even though mode is ${mode}`));
}
this._client = new jibo_client_framework_1.WSClient(this._devShellPortHost);
this._client.on('message', this.onMessage.bind(this));
done();
}
else {
done();
}
});
this.once('init', done);
}
onMessage(command) {
if (command.command === 'execute') {
Runtime_1.default.instance.autobot.executeCommand(command);
}
}
}
Runtime_1.default.registerPlugin(DevShellPlugin, 'dev-shell', {
api: true,
depends: ['service-records']
});
exports.default = DevShellPlugin;
},{"../Runtime":1,"../log":75,"events":undefined,"jibo-client-framework":undefined}],80:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const embodied = require("jibo-embodied-dialog");
const Runtime_1 = require("../Runtime");
const log_1 = require("../log");
class EmbodiedPlugin {
constructor() {
this.api = embodied.api;
}
init(done) {
const jibo = Runtime_1.default.instance;
embodied.api.init(jibo)
.then(() => done())
.catch(err => {
log_1.default.error(`Error initializing EmbodiedDialog: `, err);
done();
});
}
}
Runtime_1.default.registerPlugin(EmbodiedPlugin, 'embodied', {
depends: ['anim-db', 'expression', 'emotion'],
api: true,
name: 'embodied'
});
exports.default = EmbodiedPlugin;
},{"../Runtime":1,"../log":75,"jibo-embodied-dialog":undefined}],81:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const emotion = require("jibo-emotion-system");
const Runtime_1 = require("../Runtime");
class EmotionPlugin {
constructor() {
this.api = emotion.api;
}
init(done) {
const jibo = Runtime_1.default.instance;
emotion.api.init({ jibo: jibo })
.then(() => done())
.catch(e => done(e));
}
}
Runtime_1.default.registerPlugin(EmotionPlugin, 'emotion', {
depends: ['action'],
api: true,
name: 'emotion'
});
exports.default = EmotionPlugin;
},{"../Runtime":1,"jibo-emotion-system":undefined}],82:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_expression_client_1 = require("jibo-expression-client");
const Runtime_1 = require("../Runtime");
class ExpressionPlugin {
constructor() {
this.api = jibo_expression_client_1.expression;
}
init(done) {
const jibo = Runtime_1.default.instance;
if (jibo.runMode === jibo.RunMode.UNIT_TESTS) {
return done();
}
const record = Runtime_1.default.instance.records.find(record => (record.name === 'expression'));
if (record) {
this.api.init(record.port, jibo)
.then(() => {
this.api.events.dofs.on((data) => {
Runtime_1.default.instance.face.eye.display(data.timestamp, data.dofValues, data.metadata);
});
return this.api.setSkillRoot(process.cwd());
})
.then(() => done())
.catch(error => done(error));
}
else {
done(new Error(`Registry record missing for 'expression'`));
}
}
}
Runtime_1.default.registerPlugin(ExpressionPlugin, 'expression', {
depends: ['service-records'],
api: true,
name: 'expression'
});
exports.default = ExpressionPlugin;
},{"../Runtime":1,"jibo-expression-client":undefined}],83:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const Runtime_1 = require("../Runtime");
const jibo_plugins_1 = require("jibo-plugins");
const log_1 = require("../log");
const log = log_1.default.createChild('Fonts');
class FontsPlugin {
init(done) {
if (Runtime_1.default.electron) {
const src = path.join(jibo_plugins_1.PathUtils.findRoot(__dirname), 'resources/fonts.css');
log.debug('Electron runtime. Loading fonts from', src);
Runtime_1.default.instance.loader.load(src, (err, style) => {
log.debug('CSS loaded. Loading fonts...', src);
document.head.appendChild(style);
Promise.all([
document.fonts.load('bold 1em "Proxima Nova Soft"'),
document.fonts.load('normal 1em "Proxima Nova Soft"'),
document.fonts.load('bold 1em "Proxima Nova"'),
document.fonts.load('normal 1em "Proxima Nova Light"')
]).then(() => {
log.info('Fonts loaded');
done();
});
});
}
else {
log.debug('Non-Electron build; skipping font loading');
done();
}
}
}
Runtime_1.default.registerPlugin(FontsPlugin, 'fonts', {
depends: ['loader'],
electron: true
});
exports.default = FontsPlugin;
},{"../Runtime":1,"../log":75,"jibo-plugins":undefined,"path":undefined}],84:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const im = require("jibo-interaction-memory");
const Runtime_1 = require("../Runtime");
class InteractionMemoryPlugin {
constructor() {
this.api = im.api;
}
init(done) {
const jibo = Runtime_1.default.instance;
if (jibo.runMode === jibo.RunMode.UNIT_TESTS) {
return done();
}
try {
im.api.init(jibo);
done();
}
catch (error) {
jibo.log.error("Could not initialize interaction memory plugin: ", error);
done(error);
}
}
}
Runtime_1.default.registerPlugin(InteractionMemoryPlugin, 'im', {
depends: ['services'],
api: true,
name: 'im'
});
exports.default = InteractionMemoryPlugin;
},{"../Runtime":1,"jibo-interaction-memory":undefined}],85:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jetstream_client_1 = require("@jibo/jetstream-client");
const Runtime_1 = require("../Runtime");
const log_1 = require("../log");
const log = log_1.default.createChild('Jetstream');
const DEBUG = true;
class JetstreamPlugin {
constructor() {
this.api = jetstream_client_1.api;
}
init(done) {
const jibo = Runtime_1.default.instance;
if (jibo.runMode === jibo.RunMode.UNIT_TESTS) {
return done();
}
const record = Runtime_1.default.instance.records.find(record => (record.name === 'jetstream'));
if (!record) {
done(new Error(`Couldn't find 'jetstream' record`));
}
else {
this.api.init({
hostname: 'localhost',
port: record.port
})
.then(() => done())
.catch(error => done(error));
if (DEBUG) {
this.api.events.error.on((error) => {
log.error(`Jetstream: error received: `, error);
});
this.api.events.sos.on(() => {
log.info(`Jetstream: sos received`);
});
this.api.events.eos.on(() => {
log.info(`Jetstream: eos received`);
});
this.api.events.hjHeard.on(() => {
log.info(`Jetstream: hjHeard`);
});
this.api.events.localTurnStarted.on(() => {
log.info(`Jetstream: localTurnStarted`);
});
this.api.events.localTurnResult.on((data) => {
log.info(`Jetstream: localTurnResult: `, data);
});
this.api.events.globalTurnStarted.on(() => {
log.info(`Jetstream: globalTurnStarted`);
});
this.api.events.globalTurnResult.on((data) => {
log.info(`Jetstream: globalTurnResult: `, data);
});
this.api.events.skillSwitch.on((data) => {
log.info(`Jetstream: skillSwitch: `, data);
});
}
}
}
}
Runtime_1.default.registerPlugin(JetstreamPlugin, 'jetstream', {
depends: ['service-records'],
api: true,
name: 'jetstream'
});
exports.default = JetstreamPlugin;
},{"../Runtime":1,"../log":75,"@jibo/jetstream-client":undefined}],86:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
const jibo_client_framework_1 = require("jibo-client-framework");
const Runtime_1 = require("../Runtime");
const log_1 = require("../log");
const log = log_1.default.createChild('Lifecycle');
class IPC extends events_1.EventEmitter {
constructor() {
super();
}
send(channel, ...args) {
this.emit(`send-${channel}`, args);
}
}
const ipc = Runtime_1.default.ipcRenderer || new IPC();
class Lifecycle extends events_1.EventEmitter {
constructor() {
super();
this.onShutdown = this.onShutdown.bind(this);
this.onMessage = this.onMessage.bind(this);
ipc.on('shutdown', this.onShutdown);
}
init(done) {
const jibo = Runtime_1.default.instance;
if (jibo.runMode === jibo.RunMode.UNIT_TESTS) {
return done();
}
const records = jibo.records;
for (let i = 0; i < records.length; i++) {
let record = records[i];
if (record.name === 'skills-service') {
this._skillServiceHost = `ws://127.0.0.1:${record.port}`;
break;
}
}
if (!this._skillServiceHost) {
done('Skills Service is down');
}
this._client = new jibo_client_framework_1.WSClient(this._skillServiceHost);
this._client.once('open', () => {
this._client.send({
command: 'initDone'
});
});
this._client.on('message', this.onMessage);
this.once('init', done);
}
finished() {
this._client.send({
command: 'finished'
});
ipc.send('finished');
}
onMessage(command) {
log.debug('command', command, command.command === 'show');
if (command.command === 'shutdown') {
this.emit('shutdown');
setTimeout(() => {
ipc.send('finished');
}, 100);
}
else if (command.command === 'show') {
ipc.send('show');
this.emit('init');
}
}
onShutdown() {
this._client.send({
command: 'shutdown'
});
}
}
Runtime_1.default.registerPlugin(Lifecycle, 'lifecycle', {
api: true,
depends: ['service-records']
});
exports.default = Lifecycle;
},{"../Runtime":1,"../log":75,"events":undefined,"jibo-client-framework":undefined}],87:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../Runtime");
const HomeLocation_1 = require("../utils/location/HomeLocation");
class LocationPlugin {
init(done) {
HomeLocation_1.default.init();
done();
}
}
Runtime_1.default.registerPlugin(LocationPlugin, 'location', {
depends: ['services'],
api: false,
name: 'location'
});
exports.default = LocationPlugin;
},{"../Runtime":1,"../utils/location/HomeLocation":207}],88:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../Runtime");
const Media_1 = require("../services/media/Media");
class MediaPlugin {
constructor() {
this.api = new Media_1.Media();
}
init(done) {
const jibo = Runtime_1.default.instance;
if (jibo.runMode === jibo.RunMode.UNIT_TESTS) {
return done();
}
this.api.init(() => {
done(null, this.api);
});
}
}
Runtime_1.default.registerPlugin(MediaPlugin, 'media', {
depends: ['services'],
api: true,
name: 'media'
});
exports.default = MediaPlugin;
},{"../Runtime":1,"../services/media/Media":184}],89:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const url = require("url");
const Runtime_1 = require("../Runtime");
const jibo_client_framework_1 = require("jibo-client-framework");
const SerialTimer_1 = require("../utils/perf/SerialTimer");
const log_1 = require("../log");
const log = log_1.default.createChild('Registry');
class RegistryPlugin {
init(done) {
const jibo = Runtime_1.default.instance;
if (jibo.runMode === jibo.RunMode.UNIT_TESTS) {
log.debug('UNIT_TESTS run mode; skipping init');
return done();
}
const timer = new SerialTimer_1.default('getRegistryHost', jibo.initTimer);
if (!Runtime_1.default.electron) {
timer.stop();
log.debug('Not Electron build; skipping init');
return done();
}
if (jibo.options.registryHost) {
jibo.registryHost = jibo.options.registryHost;
timer.stop();
log.debug('Set Registry host to', jibo.registryHost);
return done();
}
log.debug('Setting up ipcRenderer set-context event handler');
Runtime_1.default.ipcRenderer.on('set-context', (sender, initData) => {
if (typeof initData === 'string' || initData instanceof String) {
jibo.registryHost = initData;
log.debug('Set Registry host to', jibo.registryHost);
}
else {
jibo.registryHost = initData.registryHost;
log.debug('Set Registry host to', initData.registryHost);
if (initData.token) {
log.debug('Set session token to', initData.token);
jibo.session.token = initData.token;
}
if (initData.context) {
jibo.electronContext = initData.context;
log.debug('Set Electron context');
}
}
this._createRegistryClientInstance(jibo);
timer.stop();
done();
});
}
_createRegistryClientInstance(jibo) {
const hostUrl = url.parse(jibo.registryHost);
jibo_client_framework_1.RegistryClient.createInstance(hostUrl.hostname, parseInt(hostUrl.port));
}
}
Runtime_1.default.registerPlugin(RegistryPlugin, 'registry');
exports.default = RegistryPlugin;
},{"../Runtime":1,"../log":75,"../utils/perf/SerialTimer":212,"jibo-client-framework":undefined,"url":undefined}],90:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../Runtime");
class RenderingPlugin {
constructor() {
const jibo = Runtime_1.default.instance;
jibo.loader
.register(jibo.rendering.tasks.ColorAlphaTask, 40)
.register(jibo.rendering.tasks.TimelineTask, 60)
.register(jibo.rendering.tasks.ShapesTask, 70)
.register(jibo.rendering.tasks.KeysTask, 80)
.register(jibo.rendering.tasks.KeysDataTask, 81)
.register(jibo.rendering.tasks.SpritesheetTask, 90)
.register(jibo.rendering.tasks.TextureTask, 30)
.register(jibo.rendering.tasks.CompressedImageTask, 25);
}
init(done) {
done();
}
}
Runtime_1.default.registerPlugin(RenderingPlugin, 'rendering', {
depends: ['loader'],
electron: true
});
exports.default = RenderingPlugin;
},{"../Runtime":1}],91:[function(require,module,exports){
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../Runtime");
const log_1 = require("../log");
const jibo_cai_utils_1 = require("jibo-cai-utils");
const log = log_1.default.createChild('ServiceRecords');
const MAX_TRIES = 5;
const WAIT_BETWEEN = 2000;
const TIMEOUT_INCR = 1000;
class ServiceRecordsPlugin {
init(done) {
const jibo = Runtime_1.default.instance;
if (jibo.runMode === jibo.RunMode.UNIT_TESTS) {
log.debug('Skipping loading registry services in unit tests');
return done();
}
const asset = {
src: jibo.registryHost,
format: 'json',
timeout: 3000
};
log.debug('Asset to load:', asset);
let attempt = 0;
let services = null;
(() => __awaiter(this, void 0, void 0, function* () {
while (services === null) {
attempt++;
try {
services = yield jibo_cai_utils_1.PromiseUtils.promisify(h => jibo.loader.load(asset, h));
}
catch (err) {
if (attempt === MAX_TRIES) {
log.error(`Error loading registry service at ${jibo.registryHost} on attempt #${attempt}; giving up`, err);
return done(new Error(`Error loading registry service at ${jibo.registryHost}: ${err.Message}`));
}
else {
log.warn(`Error loading registry service at ${jibo.registryHost} on attempt #${attempt}; will attempt a total of ${MAX_TRIES} times`, err);
asset.timeout += TIMEOUT_INCR;
yield new Promise(h => setTimeout(h, WAIT_BETWEEN));
}
}
}
const systemManagerFirst = (a, b) => {
if (a.name === "system-manager") {
return -1;
}
if (b.name === "system-manager") {
return 1;
}
return -1;
};
if (services !== null) {
log.debug(`Loaded registry service at ${jibo.registryHost}`, services);
const records = services.records ? services.records : services;
jibo.records = records.sort(systemManagerFirst);
done();
}
}))();
}
}
Runtime_1.default.registerPlugin(ServiceRecordsPlugin, 'service-records', {
depends: ['loader', 'registry']
});
exports.default = ServiceRecordsPlugin;
},{"../Runtime":1,"../log":75,"jibo-cai-utils":undefined}],92:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const async = require("async");
const ServiceClients = require("jibo-service-clients");
const Runtime_1 = require("../Runtime");
const SerialTimer_1 = require("../utils/perf/SerialTimer");
const ParallelTimer_1 = require("../utils/perf/ParallelTimer");
const log_1 = require("../log");
const log = log_1.default.createChild('Services');
class ServicesPlugin {
constructor() {
const jibo = Runtime_1.default.instance;
this.serviceInit = {
'global-manager': (service, callback) => {
jibo.globalEvents.init(service, callback);
},
kb: (service, callback) => {
jibo.kb.init(service, (err) => {
if (!err) {
jibo.kb.initLoop();
jibo.kb.initMedia();
}
callback(err);
});
},
remote: (service, callback) => {
jibo.remote.init(service, callback);
}
};
}
init(done) {
const jibo = Runtime_1.default.instance;
if (jibo.runMode === jibo.RunMode.UNIT_TESTS) {
return done();
}
const tasks = [];
const parallelTimer = new ParallelTimer_1.default('parallelInitializedServices', jibo.initTimer);
jibo.records.forEach((service) => {
const initFunction = this.serviceInit[service.name];
if (initFunction) {
tasks.push((_callback) => {
const timer = new SerialTimer_1.default(service.name, parallelTimer);
initFunction(service, (error, param) => {
timer.stop();
_callback();
});
});
}
});
tasks.push((callback) => {
ServiceClients.init(Runtime_1.default.instance, jibo.records, callback, (initFunction, service) => {
return (_callback) => {
const timer = new SerialTimer_1.default(service, parallelTimer);
initFunction((error, param) => {
timer.stop();
_callback();
});
};
});
});
async.parallel(tasks, (error, results) => {
if (error) {
log.debug('Error: ', error);
done(error);
}
else {
parallelTimer.stop();
done();
}
});
}
}
Runtime_1.default.registerPlugin(ServicesPlugin, 'services', {
depends: ['service-records']
});
exports.default = ServicesPlugin;
},{"../Runtime":1,"../log":75,"../utils/perf/ParallelTimer":210,"../utils/perf/SerialTimer":212,"async":undefined,"jibo-service-clients":undefined}],93:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../Runtime");
const jibo_plugins_1 = require("jibo-plugins");
const semver = require("semver");
const log_1 = require("../log");
const log = log_1.default.createChild('Versions');
class VersionsPlugin {
constructor() {
const jibo = Runtime_1.default.instance;
const dir = jibo_plugins_1.PathUtils.findRoot(__dirname);
this._packageInfo = require(`${dir}/package.json`);
this.jibo = this._packageInfo.version;
jibo.version = this.jibo;
}
init(done) {
const jibo = Runtime_1.default.instance;
if (jibo.runMode === jibo.RunMode.UNIT_TESTS) {
return done();
}
let tbd;
try {
tbd = require('/opt/jibo/Jibo/Skills/jibo-tbd/package.json');
}
catch (err) {
if (jibo.runMode === jibo.RunMode.ON_ROBOT) {
log.warn('no full-stack release number found', err);
}
tbd = { version: '8.67.5309' };
}
this.release = tbd.version;
if (Runtime_1.default.electron) {
for (let i = 0; i < jibo.records.length; i++) {
const service = jibo.records[i];
if (service.name === 'skills-service') {
this._getSSMVersion(service, done);
break;
}
}
}
else {
done();
}
}
supported(currentPlatformVersion) {
const jiboVersion = this.requiresPlatform;
this.platform = currentPlatformVersion;
return semver.satisfies(currentPlatformVersion, jiboVersion);
}
get requiresPlatform() {
return this._packageInfo.platform;
}
get packageInfo() {
return this._packageInfo;
}
toJSON() {
return {
jibo: this.jibo,
ssm: this.ssm,
platform: this.platform,
release: this.release
};
}
_getSSMVersion(service, done) {
const url = "http://" + service.host + ":" + service.port + '/version';
const request = new XMLHttpRequest();
request.open("GET", url, true);
request.onload = () => {
if (request.status === 200) {
const response = JSON.parse(request.response);
this.ssm = response.version;
}
else {
log.warn('Unable to request SSM version');
}
done();
};
request.send();
}
}
Runtime_1.default.registerPlugin(VersionsPlugin, 'versions', {
depends: ['services'],
api: true
});
exports.default = VersionsPlugin;
},{"../Runtime":1,"../log":75,"/opt/jibo/Jibo/Skills/jibo-tbd/package.json":undefined,"jibo-plugins":undefined,"semver":undefined}],94:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
const Runtime_1 = require("../Runtime");
const log_1 = require("../log");
const path = require("path");
const jibo_plugins_1 = require("jibo-plugins");
const log = log_1.default.createChild('VolumePlugin');
const END_OF_BOUNDS = 'SFX_EndofBounds';
const VOLUME_UPDOWN = 'SFX_VolumeIncDec';
const HW_MIN_VOLUME = 0.25;
const HW_MAX_VOLUME = 1;
const DEFAULT_VOLUME = 7;
class VolumePlugin extends events_1.EventEmitter {
constructor() {
super(...arguments);
this.MAX_VOLUME = 10;
this.MIN_VOLUME = 1;
this.currentVolume = DEFAULT_VOLUME;
this._lastVolume = DEFAULT_VOLUME;
this._volumeChanging = false;
this.onVoiceCommand = (command) => {
if (command && command.entities.volumeLevel) {
this.changeVolume(command.intent, command.entities.volumeLevel);
}
Runtime_1.default.instance.globalEvents.shared.nonInterruptingGlobal.emit();
};
}
init(callback) {
Runtime_1.default.instance.globalEvents.volume.on(this.onVoiceCommand);
Promise.all([
new Promise((resolve) => {
if (Runtime_1.default.instance.runMode === Runtime_1.default.instance.RunMode.UNIT_TESTS) {
return resolve();
}
Runtime_1.default.instance.kb.createModel('/settings').loadRoot((err, root) => {
if (err || !root) {
log.error('KB error, no root found for settings', err);
resolve();
}
else {
this._root = root;
if (root.data.volume === undefined) {
this._setVolume(resolve, true);
}
else {
this.currentVolume = Math.max(Math.min(parseInt(root.data.volume), this.MAX_VOLUME), this.MIN_VOLUME);
this._setVolume(resolve, true);
}
}
});
}),
new Promise((resolve) => {
Runtime_1.default.instance.loader.load(path.join(jibo_plugins_1.PathUtils.findRoot(__dirname), 'resources/audio/SFX_EndofBounds.m4a'), () => {
resolve();
});
}),
new Promise((resolve) => {
Runtime_1.default.instance.loader.load(path.join(jibo_plugins_1.PathUtils.findRoot(__dirname), 'resources/audio/SFX_VolumeIncDec.m4a'), () => {
resolve();
});
})
]).then(() => {
callback();
}, (err) => {
callback(err);
});
}
changeVolume(intent, value) {
if (this._volumeChanging) {
log.warn('volume change already in progress. ignoring command: ', intent);
return;
}
this._volumeChanging = true;
switch (intent) {
case 'volumeUp':
this.currentVolume = Math.min(this.currentVolume + 2, this.MAX_VOLUME);
break;
case 'volumeDown':
this.currentVolume = Math.max(this.currentVolume - 2, this.MIN_VOLUME);
break;
case 'volumeToValue':
this.currentVolume = Math.max(Math.min(parseInt(value), this.MAX_VOLUME), this.MIN_VOLUME);
break;
}
this._setVolume();
}
destroy() {
Runtime_1.default.instance.globalEvents.volume.removeListener(this.onVoiceCommand);
Runtime_1.default.instance.sound.remove(VOLUME_UPDOWN);
Runtime_1.default.instance.sound.remove(END_OF_BOUNDS);
}
_setVolume(callback, silent) {
let hwRange = HW_MAX_VOLUME - HW_MIN_VOLUME;
let userRange = this.MAX_VOLUME - this.MIN_VOLUME;
let normalizedVolume = (this.currentVolume - this.MIN_VOLUME) / userRange;
let hwVolume = HW_MIN_VOLUME + (normalizedVolume * hwRange);
Runtime_1.default.instance.system.setMasterVolume(hwVolume, (err) => {
if (err) {
if (Runtime_1.default.instance.runMode !== Runtime_1.default.instance.RunMode.ON_ROBOT) {
log.warn(`tried setting volume, but this isn't a robot`);
}
else {
log.error('error setting volume: ', err);
}
}
if (!silent) {
if (this._lastVolume === this.currentVolume) {
if (this._lastVolume === this.MAX_VOLUME || this._lastVolume === this.MIN_VOLUME) {
Runtime_1.default.instance.sound.play(END_OF_BOUNDS);
}
}
else {
Runtime_1.default.instance.sound.play(VOLUME_UPDOWN);
}
}
this._lastVolume = this.currentVolume;
this.emit('change', this.currentVolume);
if (Runtime_1.default.instance.runMode === Runtime_1.default.instance.RunMode.UNIT_TESTS) {
this._volumeChanging = false;
if (callback) {
return callback();
}
return;
}
this._root.data.volume = this.currentVolume;
this._root.save((err) => {
if (err) {
log.warn('error saving volume to KB', err);
}
this._volumeChanging = false;
this.emit('change', this.currentVolume);
if (callback) {
callback();
}
});
});
}
}
Runtime_1.default.registerPlugin(VolumePlugin, 'volume', {
depends: ['services', 'loader'],
api: true,
name: 'volume'
});
exports.default = VolumePlugin;
},{"../Runtime":1,"../log":75,"events":undefined,"jibo-plugins":undefined,"path":undefined}],95:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const context = require("./api");
const Runtime_1 = require("../../Runtime");
class ContextPlugin {
constructor() {
this.api = context;
}
init(done) {
this.api.init()
.then(() => done())
.catch(e => done(e));
}
}
Runtime_1.default.registerPlugin(ContextPlugin, 'context', {
depends: ['registry', 'emotion', 'location', 'action'],
api: true,
name: 'context'
});
exports.default = ContextPlugin;
},{"../../Runtime":1,"./api":97}],96:[function(require,module,exports){
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_cai_utils_1 = require("jibo-cai-utils");
const context = require("./api");
const Runtime_1 = require("../../Runtime");
const log_1 = require("../../log");
const log = log_1.default.createChild('Context');
const prify = jibo_cai_utils_1.PromiseUtils.promisify;
const timeout = jibo_cai_utils_1.PromiseUtils.timeout;
class ContextProvider {
init() {
return __awaiter(this, void 0, void 0, function* () {
try {
const rootNode = yield Runtime_1.default.instance.kb.loop.loadRoot();
this.ownerNode = (yield Runtime_1.default.instance.kb.loop.load(rootNode.getEdges('owner')[0]));
}
catch (err) {
log.warn('Unable to load owner information from KB', err);
}
try {
const identity = yield prify(h => Runtime_1.default.instance.systemManager.getIdentity(h));
const isBlack = identity.serial_number ? identity.serial_number.toUpperCase()[3] === 'B' : false;
this.jiboColor = isBlack ? context.JiboColor.BLACK : context.JiboColor.WHITE;
}
catch (err) {
log.warn('Unable to determine Jibo color information', err);
}
this.resetSkillContext();
});
}
updateSkillContext(skill) {
this.skill = skill;
}
resetSkillContext() {
this.skill = {
id: null
};
}
getContext(speakers, omitLoop = false) {
return __awaiter(this, void 0, void 0, function* () {
let runtime = {
character: null,
perception: null,
location: null,
loop: null,
dialog: null
};
try {
runtime = yield this.getRuntimeContext(speakers, omitLoop);
}
catch (error) {
log.error('Unable to retreive RuntimeContext -- will only send SkillContext:', error);
}
return {
runtime,
skill: this.skill
};
});
}
getRuntimeContext(speakers, omitLoop = false) {
return __awaiter(this, void 0, void 0, function* () {
let emotionName = null;
let emotionValues = null;
try {
emotionName = Runtime_1.default.instance.emotion.getNearestEmotion().name;
emotionValues = Runtime_1.default.instance.emotion.getCurrentEmotionalValues();
}
catch (err) {
log.warn('Unable to retrieve Jibo\'s emotions', err);
}
const emotion = {
name: emotionName,
valence: emotionValues && emotionValues.valence,
confidence: emotionValues && emotionValues.confidence
};
let social = null;
let playful = null;
try {
social = Runtime_1.default.instance.action.getMotivationalDriveValue(Runtime_1.default.instance.action.types.DriveName.SOCIAL);
playful = Runtime_1.default.instance.action.getMotivationalDriveValue(Runtime_1.default.instance.action.types.DriveName.PLAYFUL);
}
catch (err) {
log.warn('Unable to retrieve Jibo\'s motiviations', err);
}
const motivation = {
social,
playful
};
const character = {
emotion,
motivation
};
let location = null;
const jiboHome = Runtime_1.default.instance.utils.Location.jiboHome;
if (jiboHome) {
location = {
city: jiboHome.city,
state: jiboHome.state,
stateAbbr: jiboHome.stateAbbr,
country: jiboHome.country,
countryCode: jiboHome.countryCode,
lat: jiboHome.lat,
lng: jiboHome.lng,
iso: (new Runtime_1.default.instance.utils.DateTime(null, null, jiboHome.timezone)).toISOString()
};
}
let loop = null;
try {
loop = yield this.getLoopContext(omitLoop);
}
catch (err) {
log.warn('Unable to retrieve Jibo\'s loop information', err);
}
let speaker;
if (speakers) {
speaker = (speakers.accepted && speakers.accepted.length) ? speakers.accepted[0].id : null;
}
else {
const speakerCandidate = Runtime_1.default.instance.lps.identity.getActiveSpeaker();
speaker = (speakerCandidate && speakerCandidate.idInfo.id);
}
const peoplePresent = Runtime_1.default.instance.lps.identity.getPresentPersons();
const perception = {
speaker,
peoplePresent
};
const dialog = {
referent: null
};
return {
character,
perception,
location,
loop,
dialog
};
});
}
getLoopContext(omitLoop) {
return __awaiter(this, void 0, void 0, function* () {
let users = null;
let jibo = null;
const owner = (this.ownerNode && this.ownerNode.id);
const loopId = (this.ownerNode && this.ownerNode.data && this.ownerNode.data.loopId);
if (!omitLoop) {
let loopNodes = null;
try {
const loopPr = Runtime_1.default.instance.kb.loop.loadLoop()
.then((nodes) => {
this.cachedLoopNodes = nodes;
return this.cachedLoopNodes;
});
loopNodes = yield timeout(loopPr, 1500, `Timed-out loading Jibo's loop -- 'jibo' and 'users' will be empty.`);
}
catch (err) {
log.warn(`Unable to load Jibo's loop, defaulting to cached loop nodes.`, err);
loopNodes = this.cachedLoopNodes;
}
if (loopNodes) {
users = [];
loopNodes.forEach(loopNode => {
if (loopNode.isJibo) {
jibo = {
color: this.jiboColor,
birthdate: loopNode.created,
id: loopNode.id
};
}
else {
let user = {
firstName: loopNode.firstName,
lastName: loopNode.lastName,
phoneticName: loopNode.toString(),
gender: loopNode.gender,
birthdate: loopNode.data.birthday,
id: loopNode.id,
accountId: loopNode.data.accountId,
};
users.push(user);
}
});
}
}
return {
loopId,
users,
jibo,
owner
};
});
}
}
exports.ContextProvider = ContextProvider;
},{"../../Runtime":1,"../../log":75,"./api":97,"jibo-cai-utils":undefined}],97:[function(require,module,exports){
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const cloud = require("@jibo/interfaces");
const ContextProvider_1 = require("./ContextProvider");
exports.JiboColor = cloud.jibo.runtime.JiboColor;
const instance = new ContextProvider_1.ContextProvider();
function init() {
return __awaiter(this, void 0, void 0, function* () {
return instance.init();
});
}
exports.init = init;
function getContext(speakers, omitLoop = false) {
return __awaiter(this, void 0, void 0, function* () {
return instance.getContext(speakers, omitLoop);
});
}
exports.getContext = getContext;
function updateSkillContext(data) {
instance.updateSkillContext(data);
}
exports.updateSkillContext = updateSkillContext;
function resetSkillContext() {
instance.resetSkillContext();
}
exports.resetSkillContext = resetSkillContext;
},{"./ContextProvider":96,"@jibo/interfaces":undefined}],98:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FontsPlugin_1 = require("./FontsPlugin");
const RegistryPlugin_1 = require("./RegistryPlugin");
const ServiceRecordsPlugin_1 = require("./ServiceRecordsPlugin");
const ServicesPlugin_1 = require("./ServicesPlugin");
const RenderingPlugin_1 = require("./RenderingPlugin");
const Lifecycle_1 = require("./Lifecycle");
const LocationPlugin_1 = require("./LocationPlugin");
const VersionsPlugin_1 = require("./VersionsPlugin");
const VolumePlugin_1 = require("./VolumePlugin");
const ExpressionPlugin_1 = require("./ExpressionPlugin");
const AnimDBPlugin_1 = require("./AnimDBPlugin");
const ActionPlugin_1 = require("./ActionPlugin");
const EmotionPlugin_1 = require("./EmotionPlugin");
const MediaPlugin_1 = require("./MediaPlugin");
const EmbodiedPlugin_1 = require("./EmbodiedPlugin");
const ContextPlugin_1 = require("./context/ContextPlugin");
const DevShellPlugin_1 = require("./DevShellPlugin");
const AutobotPlugin_1 = require("./AutobotPlugin");
const JetstreamPlugin_1 = require("./JetstreamPlugin");
const InteractionMemoryPlugin_1 = require("./InteractionMemoryPlugin");
exports.default = {
FontsPlugin: FontsPlugin_1.default,
RenderingPlugin: RenderingPlugin_1.default,
RegistryPlugin: RegistryPlugin_1.default,
ServiceRecordsPlugin: ServiceRecordsPlugin_1.default,
ServicesPlugin: ServicesPlugin_1.default,
Lifecycle: Lifecycle_1.default,
LocationPlugin: LocationPlugin_1.default,
VersionsPlugin: VersionsPlugin_1.default,
VolumePlugin: VolumePlugin_1.default,
ExpressionPlugin: ExpressionPlugin_1.default,
AnimDBPlugin: AnimDBPlugin_1.default,
ActionPlugin: ActionPlugin_1.default,
EmotionPlugin: EmotionPlugin_1.default,
MediaPlugin: MediaPlugin_1.default,
EmbodiedPlugin: EmbodiedPlugin_1.default,
ContextPlugin: ContextPlugin_1.default,
DevShellPlugin: DevShellPlugin_1.default,
AutobotPlugin: AutobotPlugin_1.default,
JetstreamPlugin: JetstreamPlugin_1.default,
InteractionMemoryPlugin: InteractionMemoryPlugin_1.default,
};
},{"./ActionPlugin":76,"./AnimDBPlugin":77,"./AutobotPlugin":78,"./DevShellPlugin":79,"./EmbodiedPlugin":80,"./EmotionPlugin":81,"./ExpressionPlugin":82,"./FontsPlugin":83,"./InteractionMemoryPlugin":84,"./JetstreamPlugin":85,"./Lifecycle":86,"./LocationPlugin":87,"./MediaPlugin":88,"./RegistryPlugin":89,"./RenderingPlugin":90,"./ServiceRecordsPlugin":91,"./ServicesPlugin":92,"./VersionsPlugin":93,"./VolumePlugin":94,"./context/ContextPlugin":95}],99:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ViewManager_1 = require("./gui/ViewManager");
const TweenManager_1 = require("./tween/TweenManager");
const EyeContainer_1 = require("./eye/EyeContainer");
const GestureManager_1 = require("./input/GestureManager");
const Runtime_1 = require("../Runtime");
const log_1 = require("./log");
const log = log_1.default.createChild('FaceRenderer');
class FaceRenderer extends PIXI.WebGLRenderer {
constructor(timer) {
super(FaceRenderer.WIDTH, FaceRenderer.HEIGHT, {
view: FaceRenderer.createView(),
antialias: true
});
let texturesOnGPU = new Map();
const origUpdate = this.textureManager.updateTexture;
this.textureManager.updateTexture = function (texture, location) {
if (!texture._destroyed && texture.hasLoaded && !texture._glTextures[this.renderer.CONTEXT_UID]) {
let id = texture.imageUrl || texture.textureCacheIds[0];
if (!id) {
if (texture === PIXI.Texture.WHITE.baseTexture) {
id = '<PIXI.Texture.WHITE>';
}
else {
id = '<no id>';
}
}
texturesOnGPU.set(texture, id);
log.debug(`PIXI.TextureManager - uploaded BaseTexture with imageUrl or id of ${id} - # of textures on GPU: ${texturesOnGPU.size}`);
}
return origUpdate.call(this, texture, location);
};
const origDestroy = this.textureManager.destroyTexture;
this.textureManager.destroyTexture = function (texture, skipRemove) {
texture = texture.baseTexture || texture;
if (texturesOnGPU.has(texture)) {
const id = texturesOnGPU.get(texture);
texturesOnGPU.delete(texture);
log.debug(`PIXI.TextureManager - disposed BaseTexture with imageUrl or id of ${id} - # of textures on GPU: ${texturesOnGPU.size}`);
}
return origDestroy.call(this, texture, skipRemove);
};
this._webContextLost = (ev) => {
log.error(`WebGL Context Lost because ${ev.statusMessage} - Previously ${texturesOnGPU.size} textures on GPU`);
ev.preventDefault();
this._paused = true;
this._views.disabled = true;
texturesOnGPU = new Map();
this._views.reset();
this._views.destroyBorder();
if (this._eye.parent) {
this._eye.parent.removeChild(this._eye);
}
this._eye.destroy();
this.tween.stop();
Runtime_1.default.instance.loader.deleteCache(ViewManager_1.default.GLOBAL_CACHE);
Runtime_1.default.instance.loader.deleteCache(this.eye.CACHE_ID);
Runtime_1.default.instance.lifecycle.finished();
};
this.view.addEventListener('webglcontextlost', this._webContextLost, false);
this._webContextRestored = (ev) => {
log.info(`WebGL Context restored!`);
this._eye = new EyeContainer_1.default();
this.init(this.view.parentNode, false);
this._paused = false;
this._views.disabled = false;
Runtime_1.default.instance.lifecycle.finished();
};
this.view.addEventListener('webglcontextrestored', this._webContextRestored, false);
window.listGpuTextures = () => {
return Array.from(texturesOnGPU.values());
};
const loseContextExt = this.gl.getExtension('WEBGL_lose_context');
window.loseWebGLContext = () => {
loseContextExt.loseContext();
setTimeout(() => {
loseContextExt.restoreContext();
}, 1000);
};
this.gl.getExtension('WEBGL_compressed_texture_s3tc');
this.stage = new PIXI.Container();
this.update = this.update.bind(this);
this._paused = true;
this._timer = timer;
this._eye = new EyeContainer_1.default();
this._views = new ViewManager_1.default(this);
this._gestures = GestureManager_1.default.init(this);
this.stage.addChild(this._views.stage);
this._timer.on('update', this.update);
this.plugins.prepare.limiter = new PIXI.prepare.TimeLimiter(10);
}
static createView() {
const view = document.createElement('canvas');
view.style.width = '100%';
view.style.height = '100%';
return view;
}
init(element, prepWorkers = true) {
element.appendChild(this.view);
this._views.init(null, prepWorkers);
this._eye.init();
this.paused = false;
}
get views() {
return this._views;
}
get gestures() {
return this._gestures;
}
get tween() {
return TweenManager_1.default;
}
get eye() {
return this._eye;
}
update(elapsed) {
if (this._paused) {
return;
}
TweenManager_1.default.update(elapsed);
this._views.update(elapsed);
try {
this.render(this.stage);
}
catch (e) {
log.warn(`Error while rendering. Resetting views and eye and returning to idle.`, e);
this._views.reset();
if (this._eye.parent) {
this._eye.parent.removeChild(this._eye);
}
this._eye.destroy();
this._eye = new EyeContainer_1.default();
this.eye.init();
Runtime_1.default.instance.lifecycle.finished();
}
}
set paused(value) {
if (value !== this._paused) {
this._paused = value;
}
}
get paused() {
return this._paused;
}
reset() {
this._eye.reset();
this._views.reset();
return super.reset();
}
destroy() {
this.view.removeEventListener('webglcontextlost', this._webContextLost, false);
this.view.removeEventListener('webglcontextrestored', this._webContextRestored, false);
if (this._views) {
this.stage.removeChild(this._views.stage);
this._views.destroy();
this._views = null;
}
if (this._timer) {
this._timer.removeListener('update', this.update);
this._timer = null;
}
this._paused = true;
this.stage.destroy(true);
this.stage = null;
super.destroy(true);
}
}
FaceRenderer.WIDTH = 1280;
FaceRenderer.HEIGHT = 720;
exports.default = FaceRenderer;
},{"../Runtime":1,"./eye/EyeContainer":113,"./gui/ViewManager":127,"./input/GestureManager":160,"./log":162,"./tween/TweenManager":174}],100:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
const jibo_keyframes_1 = require("jibo-keyframes");
const animate = require("pixi-animate");
const jibo_expression_client_1 = require("jibo-expression-client");
const path = require("path");
const Runtime_1 = require("../../Runtime");
const log_1 = require("./log");
class Layer {
constructor(index, name) {
this.index = index;
this.name = name;
}
destroy() {
this.index = null;
this.name = null;
}
}
Layer.EYE = 'Eye';
exports.Layer = Layer;
class EyeLayer extends Layer {
constructor(index) {
super(index, Layer.EYE);
}
}
exports.EyeLayer = EyeLayer;
class TimelineLayer extends Layer {
constructor(index, name, timeline, startTime, attach, offsetValue) {
super(index, name);
this.startTime = startTime;
this.attach = attach;
const instance = this.instance = new timeline.library.stage();
let framerate = timeline.library.framerate;
if (framerate !== KeysAnimation.FRAMERATE) {
log_1.default.debug(`Timeline was animated at ${framerate} expecting ${KeysAnimation.FRAMERATE}, converting...`);
}
instance.framerate = KeysAnimation.FRAMERATE;
if (/^\d+$/.test(offsetValue)) {
this.offset = parseInt(offsetValue);
}
else if (instance.labelsMap && instance.labelsMap[offsetValue]) {
this.offset = instance.labelsMap[offsetValue];
}
else {
this.offset = 0;
}
instance.gotoAndStop(this.offset);
if (attach) {
instance.pivot.x = timeline.library.width / 2;
instance.pivot.y = timeline.library.height / 2;
}
else {
instance.pivot.x = 0;
instance.pivot.y = 0;
}
}
update(time, dofValues) {
const instance = this.instance;
const currFrame = Math.round((time - this.startTime) * instance.framerate);
instance.gotoAndStop(this.offset + currFrame);
if (this.attach) {
instance.x = jibo_keyframes_1.conversion.toPixelsX(dofValues.eyeSubRootBn_t) + instance.pivot.x;
instance.y = -jibo_keyframes_1.conversion.toPixelsX(dofValues.eyeSubRootBn_t_2) + instance.pivot.y;
instance.rotation = -dofValues.eyeSubRootBn_r;
}
}
destroy() {
super.destroy();
this.instance.destroy({ children: true });
this.instance = null;
}
}
exports.TimelineLayer = TimelineLayer;
class KeysAnimation extends events_1.EventEmitter {
constructor(keysData) {
super();
this._keysData = keysData;
this.id = keysData.id;
this.name = path.basename(this.id);
this.assetPack = keysData.assetPack;
this.root = keysData.root;
this.layers = [];
this.onPlayTimeline = this.onPlayTimeline.bind(this);
this.onPlayAudio = this.onPlayAudio.bind(this);
this.onEvent = this.onEvent.bind(this);
if (keysData.data) {
this.data = keysData.data;
}
this.reorder();
}
get timelines() {
return this._keysData.timelines;
}
get textures() {
return this._keysData.textures;
}
get sounds() {
return this._keysData.sounds;
}
set options(options) {
if (this._options) {
throw new Error("AnimationOptions can only be set once on a KeysAnimation. Call getCleanCopy() to start fresh.");
}
this._options = options;
}
get options() {
return this._options;
}
set instance(instance) {
if (this._instance) {
throw new Error("Instance can only be set once on a KeysAnimation.");
}
this._instance = instance;
if (instance) {
instance.events.general.on(this.onEvent);
instance.events.audio.on(this.onPlayAudio);
instance.events.pixi.on(this.onPlayTimeline);
}
}
get instance() {
return this._instance;
}
update(time, dofValues) {
this._currentTime = time;
for (let i = 0, len = this.layers.length; i < len; i++) {
const layer = this.layers[i];
if (layer instanceof TimelineLayer) {
layer.update(time, dofValues);
}
}
this.emit(KeysAnimation.UPDATE, time, dofValues);
}
set data(data) {
this.layers.length = 0;
for (let i = 0; i < data.layers.length; i++) {
if (data.layers[i].type === Layer.EYE) {
this.layers.push(new EyeLayer(i));
break;
}
}
this._data = data;
}
get data() {
return this._data;
}
playSync(instance, event, callback) {
if (typeof event === "function") {
callback = event;
event = null;
}
const startFrame = event ? instance.labelsMap[event] : 0;
let endFrame = instance.totalFrames - 1;
if (event) {
endFrame = instance.labelsMap[event + '_stop'] ||
instance.labelsMap[event + '_loop'];
}
let timelineDone = false;
let keysDone = false;
instance.gotoAndStop(startFrame);
const onComplete = () => {
if (keysDone && timelineDone) {
this.removeListener(KeysAnimation.UPDATE, onUpdate);
this.removeListener(KeysAnimation.STOPPED, onStopped);
if (callback) {
callback();
}
}
};
const onTimelineDone = () => {
timelineDone = true;
onComplete();
};
const onUpdate = (time) => {
const currentFrame = Math.round(time * instance.framerate);
const frame = startFrame + currentFrame;
if (frame <= endFrame) {
instance.gotoAndStop(frame);
if (frame === endFrame) {
onTimelineDone();
}
}
};
const onStopped = () => {
keysDone = true;
if (!timelineDone) {
animate.Animator.to(instance, endFrame, onTimelineDone);
}
else {
onComplete();
}
};
this.on(KeysAnimation.STOPPED, onStopped);
this.on(KeysAnimation.UPDATE, onUpdate);
}
destroyWhenComplete() {
const state = this._instance ? this._instance.state : jibo_expression_client_1.AnimationState.INVALID;
switch (state) {
case jibo_expression_client_1.AnimationState.INVALID:
case jibo_expression_client_1.AnimationState.CANCELLED:
case jibo_expression_client_1.AnimationState.STOPPED:
case jibo_expression_client_1.AnimationState.REJECTED:
this.destroy();
break;
default:
const destroyCB = () => {
this.destroy();
};
this._instance.events.cancelled.once(destroyCB);
this._instance.events.stopped.once(destroyCB);
this._instance.events.rejected.once(destroyCB);
}
}
destroy() {
this.layers.forEach((layer) => {
layer.destroy();
});
this.removeAllListeners();
if (this.instance) {
this.instance.destroy();
this._instance = null;
}
Runtime_1.default.instance.loader.unload(this._loadToken);
this._options = null;
this.layers = null;
}
onEvent() {
}
onPlayAudio(payload) {
this.sounds[payload.file].play();
}
reorder() {
this.layers = this.layers.sort((a, b) => {
return a.index - b.index;
});
this.emit(KeysAnimation.REORDER);
}
onPlayTimeline(payload) {
const timeline = this.timelines[payload.file];
if (!timeline) {
throw new Error(`No timeline matching ${payload.file}`);
}
const layer = new TimelineLayer(payload.layerNum, payload.file, timeline, this._currentTime || 0, !!payload.attach, payload.offset);
this.replaceOrAddTimelineLayer(layer);
this.reorder();
}
replaceOrAddTimelineLayer(layer) {
let i;
for (i = 0; i < this.layers.length; i++) {
if (this.layers[i].index === layer.index) {
this.layers[i].destroy();
break;
}
}
this.layers[i] = layer;
}
}
KeysAnimation.FRAMERATE = 30;
KeysAnimation.STARTED = 'STARTED';
KeysAnimation.STOPPED = 'STOPPED';
KeysAnimation.EVENT = 'EVENT';
KeysAnimation.CANCELLED = 'CANCELLED';
KeysAnimation.PLAY_AUDIO = 'play-audio';
KeysAnimation.PLAY_TIMELINE = 'play-pixi';
KeysAnimation.REORDER = 'reorder';
KeysAnimation.UPDATE = 'update';
exports.default = KeysAnimation;
},{"../../Runtime":1,"./log":107,"events":undefined,"jibo-expression-client":undefined,"jibo-keyframes":undefined,"path":undefined,"pixi-animate":undefined}],101:[function(require,module,exports){
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../Runtime");
const KeysAnimation_1 = require("./KeysAnimation");
const jibo_cai_utils_1 = require("jibo-cai-utils");
const path = require("path");
const jiboKeyframes = require('jibo-keyframes');
class KeysData {
constructor(id, src, cache) {
this.dotAnimSrc = null;
this.id = id || path.basename(src);
this.src = src;
this.cache = cache;
this.timelines = {};
this.sounds = {};
this.textures = {};
}
addSound(id, sound) {
this.sounds[id] = sound;
}
addTimeline(id, timeline) {
this.timelines[id] = timeline;
}
addTexture(id, texture) {
this.textures[id] = texture;
}
getAnim(options) {
return __awaiter(this, void 0, void 0, function* () {
const anim = new KeysAnimation_1.default(this);
yield jibo_cai_utils_1.PromiseUtils.promisify(cb => {
const load = Runtime_1.default.instance.loader.load({
id: this.id,
src: this.src,
cache: Runtime_1.default.instance.face.eye.CACHE_ID
}, cb);
anim._loadToken = load.tokens[0];
});
if (!options) {
options = {};
}
anim.options = this.createAnimOptions(options);
anim.instance = yield Runtime_1.default.instance.expression.createAnimation(anim.options);
return anim;
});
}
getAndPlayAnim(options, requestor) {
return __awaiter(this, void 0, void 0, function* () {
const anim = new KeysAnimation_1.default(this);
yield jibo_cai_utils_1.PromiseUtils.promisify(cb => {
const load = Runtime_1.default.instance.loader.load({
id: this.id,
src: this.src,
cache: Runtime_1.default.instance.face.eye.CACHE_ID
}, cb);
anim._loadToken = load.tokens[0];
});
if (!options) {
options = {};
}
anim.options = this.createAnimOptions(options);
anim.instance = yield Runtime_1.default.instance.expression.createAndPlayAnimation(anim.options, requestor);
return anim;
});
}
destroy() {
this.timelines = null;
this.textures = null;
this.sounds = null;
}
createAnimOptions(options) {
let data = null, src = null;
if (!this.data) {
src = this.dotAnimSrc;
if (!src) {
console.warn(`Generating missing anim data for ${this.src}.`);
}
}
if (!src) {
console.time('computeAnimObject');
data = jiboKeyframes.computeAnimObject(this.data, this.src);
console.timeEnd('computeAnimObject');
}
options = Object.assign({}, options, {
path: this.root,
src,
data,
cacheName: this.cache
});
return options;
}
}
exports.default = KeysData;
},{"../../Runtime":1,"./KeysAnimation":100,"jibo-cai-utils":undefined,"jibo-keyframes":undefined,"path":undefined}],102:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../Runtime");
const path = require("path");
const async = require("async");
const jibo_keyframes_1 = require("jibo-keyframes");
class Keyframes {
}
exports.Keyframes = Keyframes;
class KeyframesLayer {
}
exports.KeyframesLayer = KeyframesLayer;
class KeysLoader {
constructor(src, root, assetId, skipAssetPack = false) {
this.src = src;
this.root = root;
if (!skipAssetPack) {
this.assetPack = Runtime_1.default.instance.utils.PathUtils.getAssetPack(assetId || '');
}
}
load(callback) {
const promise = new Promise((resolve, reject) => {
this.innerNestedLoad(this.src, this.assetPack, (err, keyframes) => {
if (err) {
return reject(err);
}
this.removeHoldSafesInReferences(keyframes);
resolve(keyframes);
}, undefined);
});
if (callback) {
promise.then((keyframes) => {
callback(null, keyframes);
})
.catch(callback);
}
else {
return promise;
}
}
innerNestedLoad(url, assetPack, complete, parentId) {
Runtime_1.default.instance.loader.load(url, (err, keyframes) => {
if (err) {
return complete(err);
}
jibo_keyframes_1.JiboKeyframeInfo.onLoad(keyframes);
if (parentId !== undefined) {
this.fixLayerIds(keyframes, parentId);
}
const dir = path.dirname(url);
this.resolveAssetRefs(keyframes, assetPack);
let fileRefs;
try {
fileRefs = this.getKeyFileReferences(keyframes, dir);
}
catch (err) {
return complete(err);
}
async.each(fileRefs, (ref, callback) => {
this.innerNestedLoad(ref.url, ref.assetPack, (err, newkeyframes) => {
if (err) {
return callback(err);
}
ref.frames = newkeyframes;
const validUpto = ref.holdFinalPose ? ref.nextRefStart : ref.timeOffset + ref.frames.duration;
this.timeshift(ref.frames, ref.timeOffset, validUpto, ref.containerDuration - 1);
callback();
}, ref.parentId);
}, (err) => {
if (err) {
return complete(err);
}
for (let ref of fileRefs) {
this.composite(ref.layerNumber, keyframes, ref.frames);
}
this.removeReferenceLayers(keyframes);
complete(null, keyframes);
});
});
}
resolveAssetRefs(frames, assetPack) {
if (assetPack) {
for (let layer of frames.layers) {
if (layer.type === 'Pixi') {
for (let keyframe of layer.keyframes) {
keyframe.value.Pixi = this.convertToAssetReference(assetPack, keyframe.value.Pixi);
}
}
else if (layer.type === 'Audio Event') {
for (let keyframe of layer.keyframes) {
keyframe.value.AudioEvent.file = this.convertToAssetReference(assetPack, keyframe.value.AudioEvent.file);
}
}
else if (layer.type.indexOf('Texture') !== -1) {
for (let keyframe of layer.keyframes) {
keyframe.value.Texture = this.convertToAssetReference(assetPack, keyframe.value.Texture);
}
}
}
}
}
convertToAssetReference(assetPack, filepath) {
const ASSETPACK_DELIMITER = '://';
if (filepath && filepath.indexOf(ASSETPACK_DELIMITER) !== -1) {
return filepath;
}
return assetPack + ASSETPACK_DELIMITER + filepath;
}
getKeyFileReferences(frames, refBase) {
const fileRefs = [];
for (let i = 0; i < frames.layers.length; i++) {
const layer = frames.layers[i];
if (layer.type === 'Reference' && layer.visible) {
for (let keyi = 0; keyi < layer.keyframes.length; keyi++) {
const keyframe = layer.keyframes[keyi];
const atEnd = layer.keyframes.length === keyi + 1;
const nextRefStart = atEnd ? Infinity : layer.keyframes[keyi + 1].time;
let { url, assetPack } = this.getReferencedUrl(keyframe, refBase);
keyframe.childPrefix = `${layer.id}-${this.zeroPad(keyi, 2)}`;
fileRefs.push({
url,
assetPack,
parentId: keyframe.childPrefix,
holdFinalPose: keyframe.value.HoldFinalPose,
containerDuration: frames.duration,
layerNumber: i,
atEnd,
nextRefStart,
timeOffset: keyframe.time
});
}
}
}
fileRefs.reverse();
return fileRefs;
}
zeroPad(num, size) {
return (1e15 + num + "").slice(-size);
}
getReferencedUrl(keyframe, refBase) {
let url;
let assetPack;
if (keyframe.value.ReferenceMode && keyframe.value.ReferenceMode.value === 'name') {
let name = keyframe.value.KeysFileReference.name;
let anim = Runtime_1.default.instance.animDB.getAnimByName(name);
if (!anim) {
throw new ReferenceError("AnimDB name lookup failed");
}
let parts = anim.resourceRoot.split('/node_modules/');
if (parts.length > 1) {
assetPack = parts[1];
}
else {
assetPack = 'jibo-anim-db-animations';
}
url = path.join(anim.resourceRoot, anim.meta.path);
}
else {
let filename = keyframe.value.KeysFileReference.file;
assetPack = Runtime_1.default.instance.utils.PathUtils.getAssetPack(filename);
url = Runtime_1.default.instance.utils.PathUtils.getAssetUri(filename, '', refBase);
}
return { url, assetPack };
}
removeHoldSafesInReferences(keyframes) {
for (let layer of keyframes.layers) {
if (layer.type === 'Event' && this.isReferencedLayer(layer)) {
for (let keyframe of layer.keyframes) {
if (keyframe.value.Event.name === 'HOLD_SAFE') {
keyframe.value.Event.name = 'REFERENCED_HOLD_SAFE';
}
}
}
}
}
removeReferenceLayers(keyframes) {
for (let i = keyframes.layers.length - 1; i >= 0; i--) {
const layer = keyframes.layers[i];
if (layer.type === 'Reference') {
keyframes.layers.splice(i, 1);
}
}
}
timeshift(frames, validFrom, validUpto, holdAfter) {
for (let layer of frames.layers) {
if (layer.validFrom === undefined) {
layer.validFrom = validFrom;
layer.validUpto = validUpto;
layer.holdAfter = holdAfter;
}
else {
layer.validFrom += validFrom;
layer.validUpto += validFrom;
layer.holdAfter += validFrom;
}
if (layer.validUpto > validUpto) {
layer.validUpto = validUpto;
}
if (layer.holdAfter > holdAfter) {
layer.holdAfter = holdAfter;
}
for (let keyframe of layer.keyframes) {
keyframe.time += validFrom;
}
}
}
composite(layerNumber, existingKeyframes, toBeInsertedKeyframes) {
for (let i = toBeInsertedKeyframes.layers.length - 1; i >= 0; i--) {
existingKeyframes.layers.splice(layerNumber, 0, toBeInsertedKeyframes.layers[i]);
}
}
fixLayerIds(frames, prefix) {
let i = 0;
for (let layer of frames.layers) {
layer.id = `${prefix}-${layer.id}.${i}`;
i++;
}
}
isReferencedLayer(layer) {
return layer.id.indexOf('-') >= 0;
}
}
exports.default = KeysLoader;
},{"../../Runtime":1,"async":undefined,"jibo-keyframes":undefined,"path":undefined}],103:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const pixi_animate_1 = require("pixi-animate");
class Shapes {
constructor(id, shapes) {
pixi_animate_1.ShapesCache.add(id, shapes);
this.id = id;
}
destroy() {
pixi_animate_1.ShapesCache.remove(this.id);
}
}
exports.default = Shapes;
},{"pixi-animate":undefined}],104:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Spritesheet {
constructor(baseTexture, frames, resolution) {
this.baseTexture = baseTexture;
if (resolution !== 1) {
baseTexture.resolution = resolution;
baseTexture.update();
}
this.frames = {};
for (let name in frames) {
let frame = frames[name];
let rect = frame.frame;
let trim = null;
const orig = new PIXI.Rectangle(0, 0, frame.sourceSize.w / resolution, frame.sourceSize.h / resolution);
const size = new PIXI.Rectangle(rect.x / resolution, rect.y / resolution, rect.w / resolution, rect.h / resolution);
if (frame.rotated) {
size.width = rect.h / resolution;
size.height = rect.w / resolution;
}
if (frame.trimmed) {
trim = new PIXI.Rectangle(frame.spriteSourceSize.x / resolution, frame.spriteSourceSize.y / resolution, rect.w / resolution, rect.h / resolution);
}
this.frames[name] = new PIXI.Texture(baseTexture, size, orig, trim, frame.rotate);
}
}
destroy() {
for (let name in this.frames) {
this.frames[name].destroy();
}
this.frames = null;
this.baseTexture.destroy();
}
}
exports.default = Spritesheet;
},{}],105:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Texture = PIXI.Texture;
class Timeline {
constructor() {
this.textures = [];
this.textureMap = new Map();
}
addTexture(texture, id) {
Texture.addToCache(texture, id);
this.textures.push(texture);
this.textureMap.set(id, texture);
}
getTexture(id) {
return this.textureMap.get(id);
}
addShapes(shapes) {
this.shapes = shapes;
}
addSpritesheet(spritesheet) {
for (let id in spritesheet.frames) {
this.addTexture(spritesheet.frames[id], id);
this.textureMap.set(id, spritesheet.frames[id]);
}
}
upload(renderer, callback) {
this.textures.forEach((texture) => {
renderer.plugins.prepare.upload(texture);
});
renderer.plugins.prepare.upload(callback);
}
destroy() {
if (this.textures) {
this.textures.forEach((texture) => {
Texture.removeFromCache(texture);
});
this.textures = null;
}
this.textureMap = null;
if (this.shapes) {
this.shapes.destroy();
this.shapes = null;
}
this.library = null;
}
}
exports.default = Timeline;
},{}],106:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Timeline_1 = require("./Timeline");
const Shapes_1 = require("./Shapes");
const KeysAnimation_1 = require("./KeysAnimation");
const KeysLoader_1 = require("./KeysLoader");
const Spritesheet_1 = require("./Spritesheet");
exports.default = {
Timeline: Timeline_1.default,
Shapes: Shapes_1.default,
Spritesheet: Spritesheet_1.default,
KeysAnimation: KeysAnimation_1.default,
KeysLoader: KeysLoader_1.default
};
},{"./KeysAnimation":100,"./KeysLoader":102,"./Shapes":103,"./Spritesheet":104,"./Timeline":105}],107:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
exports.default = log_1.default.createChild('Animation');
},{"../log":162}],108:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const EyeMesh_1 = require("./EyeMesh");
const AbstractLayer_1 = require("./AbstractLayer");
const log_1 = require("./log");
class AbstractEye extends AbstractLayer_1.default {
init(texture) {
this.eyeMesh = new EyeMesh_1.default(texture);
this.addChild(this.eyeMesh);
super.init(texture);
}
destroy() {
super.destroy();
this.eyeMesh = null;
}
setTexture(texture) {
log_1.default.debug('AbstractEye.setTexture - ' + log_1.simplifyTexture(texture));
if (texture && texture.baseTexture) {
super.setTexture(texture);
this.eyeMesh.texture = texture;
}
else {
this.reset(false);
}
}
}
exports.default = AbstractEye;
},{"./AbstractLayer":109,"./EyeMesh":114,"./log":120}],109:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../Runtime");
const jibo_plugins_1 = require("jibo-plugins");
const log_1 = require("./log");
class AbstractLayer extends PIXI.Container {
constructor(eyeContainer) {
super();
this.eyeContainer = eyeContainer;
this.x = 0;
this.y = 0;
this.connected = true;
this.initialized = false;
}
reset(resetPath) {
if (this.initialized) {
this._applyTexture(this._defaultTexture);
if (resetPath !== false) {
this._texturePath = this._defaultTexture.baseTexture.imageUrl;
}
}
}
init(texture) {
this._defaultTexture = texture;
this.initialized = true;
this.reset();
if (this.timestamp && this.dofValues) {
this.display(this.timestamp, this.dofValues);
}
}
display(timestamp, dofValues) {
if (!this.initialized) {
this.timestamp = timestamp;
this.dofValues = dofValues;
return false;
}
if (!this.connected) {
return false;
}
return true;
}
set texturePath(value) {
if (value !== this._texturePath) {
this._texturePath = value;
this._cancelLoad();
if (!jibo_plugins_1.PathUtils.isImage(value)) {
this.reset(false);
}
else {
log_1.default.debug('AbstractLayer.set-texturePath', value);
const texture = this.eyeContainer.getTexture(value);
if (texture) {
this._applyTexture(texture);
}
else if (this._isDefaultTexture(this._defaultTexture, value)) {
this.reset();
}
else {
this._loadTexture(value);
}
}
}
}
get texturePath() {
return this._texturePath;
}
destroy() {
if (this._destroyed) {
return;
}
this._cancelLoad();
this.reset();
this._defaultTexture = null;
this._texture = null;
super.destroy({ children: true });
}
setTexture(texture) {
this._texture = texture;
}
rgb2hex(red, green, blue) {
return (red * 255) << 16 | (green * 255) << 8 | (blue * 255);
}
_isDefaultTexture(texture, value) {
const parts = texture.baseTexture.imageUrl.split('animation-utilities');
return parts.length === 2 && value.endsWith(parts[1]);
}
_cancelLoad() {
if (this._load) {
this._load.cancel();
this._load = null;
}
}
_applyTexture(texture) {
const oldTexture = this._texture;
if (oldTexture && this._textureToken) {
this._textureToken.unload();
this._textureToken = null;
}
this.setTexture(texture);
}
_loadTexture(value) {
this._load = Runtime_1.default.instance.loader.load({
id: value,
src: value,
cache: this.eyeContainer.CACHE_ID,
type: 'texture',
complete: (err, texture) => {
const token = this._load.tokens[0];
this._load = null;
this._applyTexture(texture);
this._textureToken = token;
}
});
}
}
exports.default = AbstractLayer;
},{"../../Runtime":1,"./log":120,"jibo-plugins":undefined}],110:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const AbstractLayer_1 = require("./AbstractLayer");
const log_1 = require("./log");
class Background extends AbstractLayer_1.default {
init(texture) {
this.sprite = new PIXI.Sprite(texture);
this.addChild(this.sprite);
super.init(texture);
}
display(timestamp, dofValues) {
if (!super.display(timestamp, dofValues)) {
return false;
}
this.texturePath = dofValues.screenBGTextureInfixBn_r;
this.sprite.tint = this.rgb2hex(dofValues.screenBG_redChannelBn_r, dofValues.screenBG_greenChannelBn_r, dofValues.screenBG_blueChannelBn_r);
return true;
}
destroy() {
super.destroy();
this.sprite = null;
}
setTexture(texture) {
super.setTexture(texture);
log_1.default.debug('Background.setTexture', log_1.simplifyTexture(texture));
if (texture && texture.baseTexture) {
this.sprite.texture = texture;
}
else {
this.reset(false);
}
}
}
exports.default = Background;
},{"./AbstractLayer":109,"./log":120}],111:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function isNotDirty(a, b) {
if (!a || !b) {
return false;
}
return a.eyeSubRootBn_t === b.eyeSubRootBn_t &&
a.eyeSubRootBn_t_2 === b.eyeSubRootBn_t_2 &&
a.vertexJoint1_t === b.vertexJoint1_t &&
a.vertexJoint1_t_2 === b.vertexJoint1_t_2 &&
a.vertexJoint2_t === b.vertexJoint2_t &&
a.vertexJoint2_t_2 === b.vertexJoint2_t_2 &&
a.vertexJoint3_t === b.vertexJoint3_t &&
a.vertexJoint3_t_2 === b.vertexJoint3_t_2 &&
a.vertexJoint4_t === b.vertexJoint4_t &&
a.vertexJoint4_t_2 === b.vertexJoint4_t_2 &&
a.vertexJoint5_t === b.vertexJoint5_t &&
a.vertexJoint5_t_2 === b.vertexJoint5_t_2 &&
a.vertexJoint6_t === b.vertexJoint6_t &&
a.vertexJoint6_t_2 === b.vertexJoint6_t_2 &&
a.vertexJoint7_t === b.vertexJoint7_t &&
a.vertexJoint7_t_2 === b.vertexJoint7_t_2 &&
a.vertexJoint8_t === b.vertexJoint8_t &&
a.vertexJoint8_t_2 === b.vertexJoint8_t_2 &&
a.vertexJoint9_t === b.vertexJoint9_t &&
a.vertexJoint9_t_2 === b.vertexJoint9_t_2 &&
a.eye_redChannelBn_r === b.eye_redChannelBn_r &&
a.eye_greenChannelBn_r === b.eye_greenChannelBn_r &&
a.eye_blueChannelBn_r === b.eye_blueChannelBn_r &&
a.eye_alphaChannelBn_r === b.eye_alphaChannelBn_r &&
a.eyeTextureInfixBn_r === b.eyeTextureInfixBn_r &&
a.eyeSubRootBn_r === b.eyeSubRootBn_r &&
a.eyeVisibilityBn_r === b.eyeVisibilityBn_r &&
a.overlay_textureSubRootBn_t === b.overlay_textureSubRootBn_t &&
a.overlay_textureSubRootBn_t_2 === b.overlay_textureSubRootBn_t_2 &&
a.overlay_textureSubRootBn_r === b.overlay_textureSubRootBn_r &&
a.overlay_vertexJoint1_t === b.overlay_vertexJoint1_t &&
a.overlay_vertexJoint1_t_2 === b.overlay_vertexJoint1_t_2 &&
a.overlay_vertexJoint2_t === b.overlay_vertexJoint2_t &&
a.overlay_vertexJoint2_t_2 === b.overlay_vertexJoint2_t_2 &&
a.overlay_vertexJoint3_t === b.overlay_vertexJoint3_t &&
a.overlay_vertexJoint3_t_2 === b.overlay_vertexJoint3_t_2 &&
a.overlay_vertexJoint4_t === b.overlay_vertexJoint4_t &&
a.overlay_vertexJoint4_t_2 === b.overlay_vertexJoint4_t_2 &&
a.overlay_vertexJoint5_t === b.overlay_vertexJoint5_t &&
a.overlay_vertexJoint5_t_2 === b.overlay_vertexJoint5_t_2 &&
a.overlay_vertexJoint6_t === b.overlay_vertexJoint6_t &&
a.overlay_vertexJoint6_t_2 === b.overlay_vertexJoint6_t_2 &&
a.overlay_vertexJoint7_t === b.overlay_vertexJoint7_t &&
a.overlay_vertexJoint7_t_2 === b.overlay_vertexJoint7_t_2 &&
a.overlay_vertexJoint8_t === b.overlay_vertexJoint8_t &&
a.overlay_vertexJoint8_t_2 === b.overlay_vertexJoint8_t_2 &&
a.overlay_vertexJoint9_t === b.overlay_vertexJoint9_t &&
a.overlay_vertexJoint9_t_2 === b.overlay_vertexJoint9_t_2 &&
a.overlay_redChannelBn_r === b.overlay_redChannelBn_r &&
a.overlay_greenChannelBn_r === b.overlay_greenChannelBn_r &&
a.overlay_blueChannelBn_r === b.overlay_blueChannelBn_r &&
a.overlay_alphaChannelBn_r === b.overlay_alphaChannelBn_r &&
a.overlayTextureInfixBn_r === b.overlayTextureInfixBn_r &&
a.overlayVisibilityBn_r === b.overlayVisibilityBn_r &&
a.screenBGTextureInfixBn_r === b.screenBGTextureInfixBn_r &&
a.screenBG_redChannelBn_r === b.screenBG_redChannelBn_r &&
a.screenBG_greenChannelBn_r === b.screenBG_greenChannelBn_r &&
a.screenBG_blueChannelBn_r === b.screenBG_blueChannelBn_r &&
a.lighting_amount === b.lighting_amount &&
a.lighting_brightness === b.lighting_brightness &&
a.lighting_gradient === b.lighting_gradient &&
a.lighting_radius === b.lighting_radius &&
a.lighting_light_redChannel === b.lighting_light_redChannel &&
a.lighting_light_greenChannel === b.lighting_light_greenChannel &&
a.lighting_light_blueChannel === b.lighting_light_blueChannel &&
a.lighting_mid_redChannel === b.lighting_mid_redChannel &&
a.lighting_mid_greenChannel === b.lighting_mid_greenChannel &&
a.lighting_mid_blueChannel === b.lighting_mid_blueChannel &&
a.lighting_dark_redChannel === b.lighting_dark_redChannel &&
a.lighting_dark_greenChannel === b.lighting_dark_greenChannel &&
a.lighting_dark_blueChannel === b.lighting_dark_blueChannel &&
a.glow_amount === b.glow_amount &&
a.glow_blur === b.glow_blur &&
a.glow_halo === b.glow_halo &&
a.glow_haloMaxDistance === b.glow_haloMaxDistance &&
a.glow_redChannel === b.glow_redChannel &&
a.glow_greenChannel === b.glow_greenChannel &&
a.glow_blueChannel === b.glow_blueChannel;
}
exports.isNotDirty = isNotDirty;
},{}],112:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const AbstractEye_1 = require("./AbstractEye");
const jibo_keyframes_1 = require("jibo-keyframes");
const FaceRenderer_1 = require("../FaceRenderer");
class Eye extends AbstractEye_1.default {
display(timestamp, dofValues) {
if (!super.display(timestamp, dofValues)) {
return false;
}
const points = this.eyeMesh.points;
this.texturePath = dofValues.eyeTextureInfixBn_r;
points[0].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.vertexJoint1_t);
points[0].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.vertexJoint1_t_2);
points[1].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.vertexJoint2_t);
points[1].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.vertexJoint2_t_2);
points[2].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.vertexJoint3_t);
points[2].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.vertexJoint3_t_2);
points[3].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.vertexJoint4_t);
points[3].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.vertexJoint4_t_2);
points[4].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.vertexJoint5_t);
points[4].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.vertexJoint5_t_2);
points[5].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.vertexJoint6_t);
points[5].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.vertexJoint6_t_2);
points[6].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.vertexJoint7_t);
points[6].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.vertexJoint7_t_2);
points[7].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.vertexJoint8_t);
points[7].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.vertexJoint8_t_2);
points[8].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.vertexJoint9_t);
points[8].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.vertexJoint9_t_2);
this.x = jibo_keyframes_1.conversion.toPixelsX(dofValues.eyeSubRootBn_t) + (FaceRenderer_1.default.WIDTH) / 2;
this.y = -jibo_keyframes_1.conversion.toPixelsX(dofValues.eyeSubRootBn_t_2) + (FaceRenderer_1.default.HEIGHT) / 2;
this.visible = dofValues.eyeVisibilityBn_r === undefined ? true : !!dofValues.eyeVisibilityBn_r;
this.alpha = dofValues.eye_alphaChannelBn_r === undefined ? 1 : dofValues.eye_alphaChannelBn_r;
this.eyeMesh.tint = this.rgb2hex(dofValues.eye_redChannelBn_r, dofValues.eye_greenChannelBn_r, dofValues.eye_blueChannelBn_r);
this.rotation = -dofValues.eyeSubRootBn_r;
return true;
}
}
exports.default = Eye;
},{"../FaceRenderer":99,"./AbstractEye":108,"jibo-keyframes":undefined}],113:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Background_1 = require("./Background");
const Eye_1 = require("./Eye");
const EyeOverlay_1 = require("./EyeOverlay");
const DOFValues_1 = require("./DOFValues");
const KeysAnimation_1 = require("../animation/KeysAnimation");
const KeysAnimation_2 = require("../animation/KeysAnimation");
const FaceRenderer_1 = require("../FaceRenderer");
const GlowFilter_1 = require("./filters/glow/GlowFilter");
const LightFilter_1 = require("./filters/light/LightFilter");
const Runtime_1 = require("../../Runtime");
const jibo_plugins_1 = require("jibo-plugins");
const path = require("path");
const DEFAULT_TEXTURES = {
EYE: "res/geometry-config/P1.0/textures/Default_Eye.png",
EYE_OVERLAY: "res/geometry-config/P1.0/textures/JiBO_eye_customizer_44.png",
BACKGROUND: "res/geometry-config/P1.0/textures/JiBO_BG_00.png"
};
const ANIM_REMOVAL_DELAY = 100;
class EyeContainer extends PIXI.Container {
constructor() {
super();
this.CACHE_ID = 'global-eye';
this._previousDofValues = null;
this._currentDofValues = null;
this._animation = null;
this._animRemovalTimer = null;
this._pendingAnim = null;
this.backgroundBorder = new PIXI.Graphics();
this._zoom = 1.0;
this.eye = new Eye_1.default(this);
this.eyeOverlay = new EyeOverlay_1.default(this);
this.background = new Background_1.default(this);
this.onAnimationStopped = this.onAnimationStopped.bind(this);
this.onAnimationReorder = this.onAnimationReorder.bind(this);
this.removeLastAnimAndReset = this.removeLastAnimAndReset.bind(this);
this.removeLastAnimAndReset.isGlobalTimer = true;
this.glow = new GlowFilter_1.default();
this.lighting = new LightFilter_1.default();
this.glow.target = this.eye;
this.lighting.target = this.eye;
this.lighting.lightPosition.set(FaceRenderer_1.default.WIDTH / 2, FaceRenderer_1.default.HEIGHT / 2);
this.eye.filters = [this.lighting, this.glow];
this.active = false;
}
init() {
const loader = Runtime_1.default.instance.loader;
loader.addCache(this.CACHE_ID);
loader.load(this._getDefaultTextures(), {
complete: (err, results) => {
this.eyeOverlay.init(results.eyeOverlay);
this.eye.init(results.eye);
this.background.init(results.background);
}
});
}
addAnimation(anim) {
if (this._pendingAnim && anim !== this._pendingAnim) {
this._pendingAnim.destroyWhenComplete();
this._pendingAnim = null;
}
if (anim === this._animation) {
this.onAnimationReorder();
return;
}
if (anim) {
this.emit('addAnimation');
this._pendingAnim = anim;
this.holdCurrentAnim();
}
else {
if (this._animation) {
this.removeLastAnim();
}
this._animation = anim;
this.reset();
}
}
removeAnimation(anim) {
if (anim !== this._animation) {
return;
}
if (!this._pendingAnim) {
this.emit('removeAnimation');
this.queueAnimRemoval();
}
}
holdCurrentAnim() {
if (this._animRemovalTimer) {
this._animRemovalTimer.destroy();
this._animRemovalTimer = null;
}
}
getTexture(value) {
let texture = null;
if (this._animation) {
if (!this._animation.textures) {
console.error(`Animation ${this._animation.id} has no textures and can't get ${value} - was the KeysData unloaded?`);
return null;
}
texture = this._animation.textures[value] || null;
}
return texture;
}
set active(active) {
this.connected = active;
this.visible = active;
this.removeLastAnim();
this.reset();
}
display(timestamp, dofValues, meta) {
if (this._destroyed) {
return;
}
if (this._pendingAnim && meta.sourceTimes && meta.sourceTimes[this._pendingAnim.name]) {
this.swapLastAnimForPending();
}
if (meta && meta.sourceTimes && this._animation) {
this._animation.update(meta.sourceTimes[this._animation.name], dofValues);
}
if (this.connected) {
this._previousDofValues = this._currentDofValues;
this._currentDofValues = dofValues;
}
this.glow.animate();
if (!DOFValues_1.isNotDirty(this._previousDofValues, this._currentDofValues)) {
this.glow.update(timestamp, dofValues);
this.lighting.update(timestamp, dofValues);
this.eye.display(timestamp, dofValues);
this.eyeOverlay.display(timestamp, dofValues);
this.background.display(timestamp, dofValues);
}
}
set zoom(zoom) {
this._zoom = zoom;
zoom = Math.min(zoom, 1);
this.scale.x = zoom;
this.scale.y = zoom;
this.x = 0.5 * (FaceRenderer_1.default.WIDTH - zoom * FaceRenderer_1.default.WIDTH);
this.y = 0.5 * (FaceRenderer_1.default.HEIGHT - zoom * FaceRenderer_1.default.HEIGHT);
}
get zoom() {
return this._zoom;
}
makeBorder() {
this.backgroundBorder.lineStyle(3, 0xFFFFFF)
.moveTo(0, 0)
.lineTo(FaceRenderer_1.default.WIDTH, 0)
.lineTo(FaceRenderer_1.default.WIDTH, FaceRenderer_1.default.HEIGHT)
.lineTo(0, FaceRenderer_1.default.HEIGHT)
.lineTo(0, 0);
}
destroy() {
this.removeLastAnim();
this.eye.destroy();
this.eye = null;
this.eyeOverlay.destroy();
this.eyeOverlay = null;
this.background.destroy();
this.background = null;
this.backgroundBorder.destroy();
this.backgroundBorder = null;
super.destroy({ children: true });
}
reset() {
if (this._animRemovalTimer) {
this._animRemovalTimer.destroy();
this._animRemovalTimer = null;
}
this.removeChildren();
this.addChild(this.background);
this.addChild(this.backgroundBorder);
this.addChild(this.eye);
this.addChild(this.eyeOverlay);
this.eye.reset();
this.eyeOverlay.reset();
this.background.reset();
}
_getDefaultTextures() {
const dir = path.dirname(path.dirname(jibo_plugins_1.PathUtils.resolve('animation-utilities', __dirname)));
return [
{
id: "eye",
src: path.join(dir, DEFAULT_TEXTURES.EYE),
type: 'texture',
cache: this.CACHE_ID
},
{
id: "eyeOverlay",
src: path.join(dir, DEFAULT_TEXTURES.EYE_OVERLAY),
type: 'texture',
cache: this.CACHE_ID
},
{
id: "background",
src: path.join(dir, DEFAULT_TEXTURES.BACKGROUND),
type: 'texture',
cache: this.CACHE_ID
}
];
}
onAnimationReorder() {
this.reset();
this._animation.layers.forEach((layer) => {
if (!(layer instanceof KeysAnimation_2.EyeLayer)) {
const instance = layer.instance;
this.addChild(instance);
}
});
}
onAnimationStopped() {
this.reset();
}
queueAnimRemoval() {
this.removeListenersAndDestroy(false);
if (this._animRemovalTimer) {
this._animRemovalTimer.destroy();
}
this._animRemovalTimer = Runtime_1.default.instance.timer.setTimeout(this.removeLastAnimAndReset, ANIM_REMOVAL_DELAY);
}
swapLastAnimForPending() {
if (this._animRemovalTimer) {
this._animRemovalTimer.destroy();
this._animRemovalTimer = null;
}
if (this._animation) {
this.removeListenersAndDestroy(true);
}
const anim = this._animation = this._pendingAnim;
anim.on(KeysAnimation_1.default.STOPPED, this.onAnimationStopped);
anim.on(KeysAnimation_1.default.REORDER, this.onAnimationReorder);
this.onAnimationReorder();
this._pendingAnim = null;
}
removeLastAnim() {
if (this._animRemovalTimer) {
this._animRemovalTimer.destroy();
this._animRemovalTimer = null;
}
if (this._animation) {
this.removeListenersAndDestroy(true);
}
}
removeListenersAndDestroy(destroy) {
this._animation.removeListener(KeysAnimation_1.default.STOPPED, this.onAnimationStopped);
this._animation.removeListener(KeysAnimation_1.default.REORDER, this.onAnimationReorder);
if (destroy) {
this._animation.destroyWhenComplete();
this._animation = null;
}
}
removeLastAnimAndReset() {
this.removeLastAnim();
this.reset();
}
}
exports.default = EyeContainer;
},{"../../Runtime":1,"../FaceRenderer":99,"../animation/KeysAnimation":100,"./Background":110,"./DOFValues":111,"./Eye":112,"./EyeOverlay":115,"./filters/glow/GlowFilter":116,"./filters/light/LightFilter":118,"jibo-plugins":undefined,"path":undefined}],114:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class EyeMesh extends PIXI.mesh.Mesh {
constructor(texture) {
super(texture, null, null, null, PIXI.mesh.Mesh.DRAW_MODES.TRIANGLES);
this.uvs = new Float32Array([
0, 0,
0.5, 0,
1, 0,
0, 0.5,
0.5, 0.5,
1, 0.5,
0, 1,
0.5, 1,
1, 1
]);
this.vertices = new Float32Array(this.uvs.length * 2);
this.points = [];
for (let i = 0; i < this.uvs.length; i += 2) {
this.points.push(new PIXI.Point(this.uvs[i], this.uvs[i + 1]));
}
this.indices = new Uint16Array([
0, 1, 3,
1, 3, 4,
1, 4, 5,
2, 5, 1,
3, 4, 7,
7, 6, 3,
4, 5, 7,
5, 7, 8
]);
}
updateTransform() {
for (let i = 0; i < this.points.length; i++) {
const point = this.points[i];
const index = i * 2;
this.vertices[index] = point.x;
this.vertices[index + 1] = point.y;
}
this.containerUpdateTransform();
}
}
exports.default = EyeMesh;
},{}],115:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const AbstractEye_1 = require("./AbstractEye");
const jibo_keyframes_1 = require("jibo-keyframes");
const FaceRenderer_1 = require("../FaceRenderer");
class EyeOverlay extends AbstractEye_1.default {
display(timestamp, dofValues) {
if (!super.display(timestamp, dofValues)) {
return false;
}
const points = this.eyeMesh.points;
this.texturePath = dofValues.overlayTextureInfixBn_r;
points[0].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.overlay_vertexJoint1_t);
points[0].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.overlay_vertexJoint1_t_2);
points[1].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.overlay_vertexJoint2_t);
points[1].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.overlay_vertexJoint2_t_2);
points[2].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.overlay_vertexJoint3_t);
points[2].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.overlay_vertexJoint3_t_2);
points[3].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.overlay_vertexJoint4_t);
points[3].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.overlay_vertexJoint4_t_2);
points[4].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.overlay_vertexJoint5_t);
points[4].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.overlay_vertexJoint5_t_2);
points[5].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.overlay_vertexJoint6_t);
points[5].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.overlay_vertexJoint6_t_2);
points[6].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.overlay_vertexJoint7_t);
points[6].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.overlay_vertexJoint7_t_2);
points[7].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.overlay_vertexJoint8_t);
points[7].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.overlay_vertexJoint8_t_2);
points[8].x = jibo_keyframes_1.conversion.toPixelsX(dofValues.overlay_vertexJoint9_t);
points[8].y = jibo_keyframes_1.conversion.toPixelsY(dofValues.overlay_vertexJoint9_t_2);
this.x = jibo_keyframes_1.conversion.toPixelsX(dofValues.overlay_textureSubRootBn_t) + (FaceRenderer_1.default.WIDTH) / 2;
this.y = -jibo_keyframes_1.conversion.toPixelsX(dofValues.overlay_textureSubRootBn_t_2) + (FaceRenderer_1.default.HEIGHT) / 2;
this.eyeMesh.tint = this.rgb2hex(dofValues.overlay_redChannelBn_r, dofValues.overlay_greenChannelBn_r, dofValues.overlay_blueChannelBn_r);
this.visible = dofValues.overlayVisibilityBn_r === undefined ? true : !!dofValues.overlayVisibilityBn_r;
this.alpha = dofValues.overlay_alphaChannelBn_r === undefined ? 1 : dofValues.overlay_alphaChannelBn_r;
this.rotation = -dofValues.overlay_textureSubRootBn_r;
return true;
}
}
exports.default = EyeOverlay;
},{"../FaceRenderer":99,"./AbstractEye":108,"jibo-keyframes":undefined}],116:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class GlowFilter extends PIXI.Filter {
constructor() {
super("#define GLSLIFY 1\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform vec4 filterArea;\nuniform vec2 center;\nuniform float haloScale;\n\nvarying vec2 vTextureCoord;\nvarying vec2 vTextureCoordScaled;\n\nvec2 mapCoord( vec2 coord )\n{\n coord *= filterArea.xy;\n coord += filterArea.zw;\n\n return coord;\n}\n\nvec2 unmapCoord( vec2 coord )\n{\n coord -= filterArea.zw;\n coord /= filterArea.xy;\n\n return coord;\n}\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n\n vec2 transl = mapCoord(aTextureCoord);\n\n vec2 c = center;//vec2(1280.0/2.0, 720.0/2.0);\n\n transl -= c;\n\n transl *= haloScale;\n\n transl += c ;\n\n transl = unmapCoord(transl);\n\n// center\n vTextureCoordScaled = transl;\n}", "#define GLSLIFY 1\nvarying vec2 vTextureCoord;\nvarying vec2 vTextureCoordScaled;\n\nuniform sampler2D uSampler;\nuniform sampler2D uBlurSampler;\nuniform float amount;\nuniform float haloStrength;\nuniform vec4 glowColor;\n\nvoid main(void)\n{\n vec4 original = texture2D(uSampler, vTextureCoord);\n vec4 bluredNormal = texture2D(uBlurSampler, vTextureCoord);\n\n vec4 originalScaled = texture2D(uSampler, vTextureCoordScaled);\n vec4 bluredScaled = texture2D(uBlurSampler, vTextureCoordScaled);\n\n float strength = 2.0;\n float alpha = max(bluredNormal.a * strength, original.a);\n alpha = min(alpha, 1.0);\n\n vec4 color = glowColor * alpha;\n\n color *= amount;\n\n float knockout = bluredScaled.a * ( 1.0-originalScaled.a );\n bluredScaled *= knockout;\n bluredScaled *= 3.0;\n bluredScaled *= haloStrength * amount;\n bluredScaled = glowColor * bluredScaled.a;\n\n gl_FragColor = color + (bluredScaled * (1.0-color.a) );\n\n}");
this.enabled = false;
this.padding = 200;
this.blurXFilter = new PIXI.filters.BlurXFilter();
this.blurYFilter = new PIXI.filters.BlurYFilter();
this.blendMode = PIXI.BLEND_MODES.ADD;
this.defaultFilter = new PIXI.filters.AlphaFilter();
this.uniforms.center.x = 0.1;
this.uniforms.center.y = 0.1;
this.uniforms.haloScale = 0.8;
this.reset();
this.target = null;
}
reset() {
this.amount = 0;
this.blur = 15;
this.blurQuality = 4;
this.haloSpeed = 0;
this.halo = 0;
this.haloMaxDistance = 80;
this.color = 0x7df9ff;
}
apply(filterManager, input, output) {
const target = this.target || filterManager.filterData.stack[filterManager.filterData.index].target;
const renderTarget = filterManager.getRenderTarget(true);
const renderTarget2 = filterManager.getRenderTarget(true);
this.defaultFilter.apply(filterManager, input, output, false);
this.defaultFilter.apply(filterManager, input, renderTarget, true);
this.blurXFilter.apply(filterManager, renderTarget, renderTarget2, true);
this.blurYFilter.apply(filterManager, renderTarget2, renderTarget, true);
this.uniforms.center.x = target.position.x;
this.uniforms.center.y = target.position.y;
this.uniforms.uBlurSampler = renderTarget;
const width = target.getBounds(true).width;
this.uniforms.haloScale = 1 / ((width + this.haloDistance) / (width));
filterManager.applyFilter(this, input, output, false);
filterManager.returnRenderTarget(renderTarget);
filterManager.returnRenderTarget(renderTarget2);
}
get blur() {
return this.blurXFilter.blur;
}
set blur(value) {
this.blurXFilter.blur = this.blurYFilter.blur = value;
}
set blurQuality(value) {
this.blurXFilter.quality = value;
this.blurYFilter.quality = value;
}
get blurQuality() {
return this.blurXFilter.quality;
}
get halo() {
return this._halo;
}
set halo(value) {
this._halo = value;
this.haloDistance = value * this.haloMaxDistance;
this.uniforms.haloStrength = Math.sin(Math.PI * (1 - value));
}
get amount() {
return this.uniforms.amount;
}
set amount(value) {
this.enabled = value > 0;
this.uniforms.amount = value;
}
get color() {
return PIXI.utils.rgb2hex(this.uniforms.glowColor);
}
set color(value) {
this.uniforms.glowColor = this.hex2rgba(value);
}
hex2rgba(value, alpha = 1) {
const rgba = PIXI.utils.hex2rgb(value, this.uniforms.light);
rgba[3] = alpha;
return Array.prototype.slice.call(rgba);
}
update(timestamp, dofValues) {
if (dofValues.glow_amount !== undefined) {
this.setWithDOFS = true;
this.amount = dofValues.glow_amount;
this.blur = dofValues.glow_blur;
this.halo = dofValues.glow_halo;
this.haloMaxDistance = dofValues.glow_haloMaxDistance;
this.color = dofValues.glow_redChannel << 16 |
dofValues.glow_greenChannel << 8 |
dofValues.glow_blueChannel;
}
else if (this.setWithDOFS) {
this.setWithDOFS = false;
this.reset();
}
}
animate() {
if (this.haloSpeed === 0) {
return;
}
let value = this.halo + this.haloSpeed;
if (value > 1) {
value = 0;
}
else if (value < 0) {
value = 1;
}
this.halo = value;
}
}
exports.default = GlowFilter;
},{}],117:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const GlowFilter_1 = require("./glow/GlowFilter");
const LightFilter_1 = require("./light/LightFilter");
exports.default = {
GlowFilter: GlowFilter_1.default,
LightFilter: LightFilter_1.default
};
},{"./glow/GlowFilter":116,"./light/LightFilter":118}],118:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class LightFilter extends PIXI.Filter {
constructor() {
super("#define GLSLIFY 1\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}", "#define GLSLIFY 1\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform float radius;\nuniform vec2 offset;\nuniform vec2 direction;\nuniform vec2 scale;\nuniform vec4 dark;\nuniform vec4 mid;\nuniform vec4 light;\nuniform vec4 filterArea;\nuniform float intensity;\nuniform float amount;\nuniform float gradientRatio;\n\nconst float PI = 3.141592657;\n\nvec2 mapCoord( vec2 coord )\n{\n coord *= filterArea.xy;\n coord += filterArea.zw;\n\n return coord;\n}\n\nvec2 unmapCoord( vec2 coord )\n{\n coord -= filterArea.zw;\n coord /= filterArea.xy;\n\n return coord;\n}\n\nfloat gradientLine ( float t, float b, float c, float d) {\n\n return c * sin(t/d * (PI/2.0)) + b;\n //return c * sqrt(1.0 - (t=t/d-1.0)*t) + b;\n}\n\nfloat gradient(vec2 coord)\n{\n coord -= offset;\n\n coord += direction;\n\n coord *= scale;\n\n float dist = length(coord);\n\n float ratioDist = (radius - dist) / radius;\n ratioDist = max(ratioDist, 0.0);\n ratioDist = min(ratioDist, 1.0);\n\n ratioDist = gradientLine(ratioDist, 0.0, ratioDist, 1.0);\n\n return ratioDist;\n\n}\n\nvoid main(void)\n{\n\n vec2 coord = mapCoord(vTextureCoord);\n\n float lightGrad = gradient(coord);\n\n vec4 original = texture2D(uSampler, vTextureCoord );\n\n gl_FragColor = original;\n\n vec4 blend = vec4(0.0);\n\n if(lightGrad < gradientRatio)\n {\n float firstMix = (lightGrad / gradientRatio);\n blend += mix(dark, mid, firstMix);// * step(firstMix, 1.0);\n }\n else\n {\n float secondMix = (lightGrad - gradientRatio)/(1.0-gradientRatio);\n blend += mix(mid, light, secondMix);/// * step(1.0 - lightGrad, gradientRatio);\n }\n\n gl_FragColor *= blend;//mix(dark, light, lightGrad);\n gl_FragColor.rgb += intensity*(1.0-lightGrad)* gl_FragColor.a;\n\n gl_FragColor = mix(original, gl_FragColor, amount);\n}");
this.enabled = false;
this.reset();
this.padding = 200;
this.distanceMagnification = new PIXI.Point(300, 1100);
this.lightPosition = new PIXI.Point();
this.target = null;
}
reset() {
this.amount = 1.1;
this.radius = 250;
this.gradientRatio = 0.53;
this.lightScale = 0.98;
this.dark = 0x5a5552;
this.mid = 0xc0bab6;
this.light = 0xffffff;
}
apply(filterManager, input, output) {
const target = this.target || filterManager.filterData.stack[filterManager.filterData.index].target;
const bounds = target.getBounds(true);
this.uniforms.offset.x = target.position.x;
this.uniforms.offset.y = target.position.y;
this.uniforms.radius = this.radius;
this.uniforms.scale.x = (this.radius / bounds.width) / this.lightScale;
this.uniforms.scale.y = (this.radius / bounds.height) / this.lightScale;
const centerX = target.position.x - this.lightPosition.x;
const centerY = target.position.y - this.lightPosition.y;
let dist = Math.sqrt(centerX * centerX + centerY * centerY);
if (!dist) {
dist = 0.001;
}
const nx = centerX / dist;
const ny = centerY / dist;
const intensityX = this.map(dist, 0, 500, 0, this.distanceMagnification.x);
const intensityY = this.map(dist, 0, 500, 0, this.distanceMagnification.y);
this.uniforms.direction.x = nx * -intensityX;
this.uniforms.direction.y = ny * -intensityY;
filterManager.applyFilter(this, input, output, false);
}
map(val, inputMin, inputMax, outputMin, outputMax) {
return ((outputMax - outputMin) * ((val - inputMin) / (inputMax - inputMin))) + outputMin;
}
get dark() {
return PIXI.utils.rgb2hex(this.uniforms.dark);
}
set dark(value) {
this.uniforms.dark = this.hex2rgba(value, this.uniforms.dark);
}
get mid() {
return PIXI.utils.rgb2hex(this.uniforms.mid);
}
set mid(value) {
this.uniforms.mid = this.hex2rgba(value, this.uniforms.mid);
}
get light() {
return PIXI.utils.rgb2hex(this.uniforms.light);
}
set light(value) {
this.uniforms.light = this.hex2rgba(value, this.uniforms.light);
}
get amount() {
return this.uniforms.amount;
}
set amount(value) {
this.enabled = value > 0;
this.uniforms.amount = value;
}
get brightness() {
return this.uniforms.intensity;
}
set brightness(value) {
this.uniforms.intensity = value;
}
get gradientRatio() {
return this.uniforms.gradientRatio;
}
set gradientRatio(value) {
this.uniforms.gradientRatio = value;
}
hex2rgba(value, current, alpha = 1) {
const rgba = PIXI.utils.hex2rgb(value, current);
rgba[3] = alpha;
return Array.prototype.slice.call(rgba);
}
update(timestamp, dofValues) {
const eyeTexturePath = dofValues.eyeTextureInfixBn_r;
if (eyeTexturePath.endsWith("Default_Eye.png") ||
eyeTexturePath.endsWith("White_Eye.png") ||
eyeTexturePath.endsWith("white-eye.png")) {
this.amount = 1.1;
}
else {
this.amount = 0;
}
}
}
exports.default = LightFilter;
},{}],119:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const AbstractEye_1 = require("./AbstractEye");
const Background_1 = require("./Background");
const Eye_1 = require("./Eye");
const EyeMesh_1 = require("./EyeMesh");
const EyeOverlay_1 = require("./EyeOverlay");
const EyeContainer_1 = require("./EyeContainer");
const AbstractLayer_1 = require("./AbstractLayer");
const filters_1 = require("./filters");
exports.default = {
AbstractEye: AbstractEye_1.default,
Background: Background_1.default,
Eye: Eye_1.default,
EyeMesh: EyeMesh_1.default,
EyeOverlay: EyeOverlay_1.default,
EyeContainer: EyeContainer_1.default,
AbstractLayer: AbstractLayer_1.default,
filters: filters_1.default
};
},{"./AbstractEye":108,"./AbstractLayer":109,"./Background":110,"./Eye":112,"./EyeContainer":113,"./EyeMesh":114,"./EyeOverlay":115,"./filters":117}],120:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
exports.default = log_1.default.createChild('Eye');
function simplifyTexture(texture) {
if (!texture) {
return '[Texture NO TEXTURE]';
}
let frame = texture.frame ? `(${texture.frame.x}, ${texture.frame.y}, ${texture.frame.width}, ${texture.frame.height})` : 'NO FRAME';
let url = texture.baseTexture ? texture.baseTexture.imageUrl : 'NO BASE TEXTURE';
return `[Texture frame=${frame} url=${url}]`;
}
exports.simplifyTexture = simplifyTexture;
},{"../log":162}],121:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../Runtime");
const ViewManager_1 = require("./ViewManager");
const ActionData_1 = require("./actions/ActionData");
const TouchInteractive_1 = require("./components/subcomponents/TouchInteractive");
const TouchManager_1 = require("./TouchManager");
const events_1 = require("events");
const log_1 = require("./log");
const log = log_1.default.createChild('Component');
class Component extends events_1.EventEmitter {
constructor() {
super(...arguments);
this.id = '';
this.parentGroup = null;
this._stateChanged = false;
this._type = '';
this._assetDescriptors = null;
this._assets = null;
this._inputLocked = true;
this._parentView = null;
this._touchInteractivity = null;
this._subcomponents = null;
}
get stateChanged() {
return this._stateChanged;
}
get type() { return this._type; }
get inputLocked() {
return this._inputLocked;
}
set inputLocked(flag) {
log.warn('Deprecation: the ability to set inputLocked is deprecated, please use lockInput(true|false) instead');
this.lockInput(flag);
}
get assetDescriptors() {
return this._assetDescriptors;
}
get parentView() {
if (this._parentView) {
return this._parentView;
}
let group = this;
while (group.parentGroup) {
group = group.parentGroup;
}
if (group instanceof Runtime_1.default.instance.face.views.View) {
this._parentView = group;
return this._parentView;
}
else {
log.info('Component is not yet parented to a View.');
return null;
}
}
addSubcomponent(subcomponent) {
if (!this._subcomponents) {
this._subcomponents = {};
}
subcomponent.init(this);
this._subcomponents[subcomponent.type] = subcomponent;
return subcomponent;
}
getSubcomponent(type) {
return this._subcomponents ? this._subcomponents[type] : null;
}
assignConfig(configData) {
if (configData) {
if (configData.hasOwnProperty('id')) {
if (!this.id) {
this.id = configData.id;
}
}
if (configData.hasOwnProperty('type')) {
this._type = configData.type;
}
if (configData.hasOwnProperty('assets')) {
if (!this._assetDescriptors) {
this._assetDescriptors = [];
}
this._assetDescriptors = this._assetDescriptors.concat(configData.assets);
}
if (configData.hasOwnProperty('action')) {
this.addAction(ActionData_1.default.createFromConfig(configData.action));
}
else if (configData.hasOwnProperty('actions')) {
for (let i = 0; i < configData.actions.length; i++) {
this.addAction(ActionData_1.default.createFromConfig(configData.actions[i]));
}
}
}
}
registerUpdate(bool) {
if (this.parentGroup) {
if (bool) {
this.parentGroup.registerComponentUpdate(this);
}
else {
this.parentGroup.unregisterComponentUpdate(this);
}
}
}
destroy() {
this.removeAllListeners();
this._assetDescriptors = null;
this._assets = null;
if (this._subcomponents) {
for (let key in this._subcomponents) {
if (this._subcomponents.hasOwnProperty(key)) {
this._subcomponents[key].destroy();
}
}
this._subcomponents = null;
}
this._touchInteractivity = null;
this.parentGroup = null;
}
open(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME) {
callback();
}
close(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME) {
callback();
}
addAssetDescriptor(id, src, type, upload = false, cache = undefined) {
return this.addAssetDescriptorObject({
id: id,
src: src,
type: type,
upload: upload,
cache: cache
});
}
addAssetDescriptorObject(assetDescriptor) {
if (!this._assetDescriptors) {
this._assetDescriptors = [];
}
return this._assetDescriptors.push(assetDescriptor);
}
get hasTouchInteractive() {
return (this._touchInteractivity !== null);
}
get isTouchInteractive() {
return (this._touchInteractivity && this._touchInteractivity.isActive);
}
addAction(action, data, clearPrevious = false, toFront = false, gesture = TouchManager_1.GESTURE.TAP) {
if (!this._touchInteractivity) {
this._touchInteractivity = this.addSubcomponent(new TouchInteractive_1.default());
this._touchInteractivity.isActive = !this._inputLocked;
}
let actionData;
if (typeof action === 'string') {
actionData = new ActionData_1.default(action, data);
}
else {
actionData = action;
if (data) {
actionData.data = data;
}
}
return this._touchInteractivity.addAction(actionData, clearPrevious, toFront, gesture);
}
clearActions(gesture = TouchManager_1.GESTURE.TAP) {
if (this._touchInteractivity) {
this._touchInteractivity.clearActions(gesture);
}
}
removeActionsByType(actionType, gesture = TouchManager_1.GESTURE.TAP) {
if (this._touchInteractivity) {
const actions = this._touchInteractivity.getActions(gesture);
if (actions) {
for (let i = actions.length - 1; i >= 0; i--) {
if (actions[i].type === actionType) {
actions.splice(i, 1);
}
}
}
}
}
triggerActions(gesture = TouchManager_1.GESTURE.TAP) {
if (this._touchInteractivity) {
return this._touchInteractivity.triggerActions(gesture);
}
return false;
}
getActions(gesture = TouchManager_1.GESTURE.TAP) {
if (this._touchInteractivity) {
return this._touchInteractivity.getActions(gesture);
}
}
hasActions(gesture = TouchManager_1.GESTURE.TAP) {
return (this._touchInteractivity && this._touchInteractivity.hasActions(gesture));
}
lockInput(flag) {
this._inputLocked = flag;
if (this._touchInteractivity) {
this._touchInteractivity.isActive = !flag;
}
}
}
exports.default = Component;
},{"../../Runtime":1,"./TouchManager":125,"./ViewManager":127,"./actions/ActionData":130,"./components/subcomponents/TouchInteractive":147,"./log":149,"events":undefined}],122:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../Runtime");
const ViewState_1 = require("./ViewState");
const log_1 = require("./log");
const log = log_1.default.createChild('ComponentCreator');
class ComponentCreator {
constructor() {
this._classRegistry = {};
if (!ComponentCreator._instance) {
ComponentCreator._instance = this;
}
}
get DEFAULT_VIEW() { return 'View'; }
static get instance() {
return ComponentCreator._instance;
}
createView(viewClass, config) {
return this.createViewFromState(this.createViewState(viewClass, config));
}
createViewFromConfigObject(config) {
if (config) {
const viewState = new ViewState_1.default();
viewState.applyConfig(config);
return this.createViewFromState(viewState);
}
else {
log.info('createViewFromConfigObject() config Object given was undefined');
return null;
}
}
createViewFromConfigPath(configPath, complete, failure) {
if (configPath) {
Runtime_1.default.instance.loader.load(configPath, (err, result) => {
if (err) {
log.error('createViewFromConfigPath() cannot create View, error loading configuration at: ' + configPath + ' error:', err);
if (failure) {
failure('Unable to load config file ' + configPath);
}
return;
}
complete(this.createViewFromConfigObject(result));
});
}
else {
log.error('createViewFromConfigPath() config path given was undefined, cannot make View.');
if (failure) {
failure('Configuration path was not given');
}
}
}
createViewState(viewClass, config) {
let viewState;
if (typeof viewClass === 'string') {
if (this._classRegistry.hasOwnProperty(viewClass)) {
viewState = new ViewState_1.default(viewClass);
}
else {
viewState = new ViewState_1.default(this.DEFAULT_VIEW);
}
}
else if (viewClass && (typeof viewClass === 'object' || typeof viewClass === 'function')) {
this.registerClass(viewClass);
viewState = new ViewState_1.default(viewClass.name);
}
else {
viewState = new ViewState_1.default(this.DEFAULT_VIEW);
}
if (typeof config === 'string') {
viewState.configPath = config;
}
if (typeof config === 'object') {
viewState.applyConfig(config);
}
return viewState;
}
createViewFromState(viewState) {
if (viewState) {
let viewClass = this.getClassFromRegistry(viewState.viewClassName);
if (viewClass !== null) {
let view = new viewClass();
view.applyState(viewState);
return view;
}
else {
log.error('createViewFromState() class ' + viewState.viewClassName +
' not found in registry, make sure class is registered before trying to create it.');
return null;
}
}
else {
log.error('createViewFromState() provided viewState was null, must provide a valid ViewState');
return null;
}
}
createComponentFromConfig(componentConfig) {
if (componentConfig.hasOwnProperty('type')) {
let componentClass = this._classRegistry[componentConfig.type];
if (componentClass) {
return componentClass.createFromConfig(componentConfig);
}
else {
log.warn('createComponentFromConfig() given invalid component type: ' + componentConfig.type);
return null;
}
}
else {
log.warn('createComponentFromConfig() type was not specified.');
return null;
}
}
registerClass(componentClass, classType) {
let classKey = classType;
if (!classKey && componentClass.hasOwnProperty('DEFAULT_TYPE')) {
classKey = componentClass.DEFAULT_TYPE;
}
if (classKey) {
if (!this._classRegistry.hasOwnProperty(classKey)) {
this._classRegistry[classKey] = componentClass;
}
else {
log.info('registryClass() : class was already registered for name: ' + classKey);
}
}
else {
log.warn('registerClass() : No valid class key was given: ' + classKey +
'. Attempting to register a class without providing a key will cause a failure when attempting to retrieve/use that class later');
}
}
unregisterClass(classType) {
if (this._classRegistry.hasOwnProperty(classType)) {
delete this._classRegistry[classType];
}
else {
log.info('unregisterClass() found no class registered for name: ' + classType);
}
}
getClassFromRegistry(className) {
if (this._classRegistry.hasOwnProperty(className)) {
return this._classRegistry[className];
}
else {
log.warn('getClassFromRegistry() no class found in registry with name: ' + className);
return null;
}
}
}
exports.default = ComponentCreator;
},{"../../Runtime":1,"./ViewState":129,"./log":149}],123:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Component_1 = require("./Component");
const ComponentCreator_1 = require("./ComponentCreator");
const ViewManager_1 = require("./ViewManager");
const async = require("async");
const log_1 = require("./log");
const log = log_1.default.createChild('ComponentGroup');
class ComponentGroup extends Component_1.default {
constructor() {
super(...arguments);
this.componentLibrary = {};
this.componentList = [];
this._childInputLocked = true;
}
get componentsTotal() {
if (this.componentList) {
return this.componentList.length;
}
return 0;
}
get assetDescriptors() {
return this.groupAssetDescriptors;
}
get groupAssetDescriptors() {
let groupAssetDescriptors = (this._assetDescriptors) ? this._assetDescriptors.slice(0) : [];
if (this.componentList) {
let i = 0;
let length = this.componentList.length;
let component;
let nextAssetDescriptors;
for (i; i < length; i++) {
component = this.componentList[i];
nextAssetDescriptors = component.assetDescriptors;
if (nextAssetDescriptors) {
groupAssetDescriptors = groupAssetDescriptors.concat(nextAssetDescriptors);
}
}
}
return groupAssetDescriptors;
}
lockInput(flag) {
super.lockInput(flag);
this.lockChildInput(flag);
}
lockChildInput(flag) {
if (this._childInputLocked !== flag) {
this._childInputLocked = flag;
if (this.componentList) {
let component;
let length = this.componentList.length;
for (let i = 0; i < length; i++) {
component = this.componentList[i];
component.lockInput(flag);
}
}
}
}
updateConfig(configObject) {
if (this.updateComponentConfigs()) {
this._stateChanged = true;
Object.assign(configObject, { "componentConfigs": this.componentConfigs });
}
return configObject;
}
createComponentsFromConfigs(componentConfigs) {
if (componentConfigs) {
let creator = ComponentCreator_1.default.instance;
let component;
let length = componentConfigs.length;
for (let i = 0; i < length; i++) {
component = creator.createComponentFromConfig(componentConfigs[i]);
if (component) {
this.addComponent(component);
}
}
}
}
addComponent(component, componentId) {
if (component) {
component.parentGroup = this;
if (!this.componentLibrary) {
this.componentLibrary = {};
}
if (!this.componentList) {
this.componentList = [];
}
if (componentId) {
component.id = componentId;
}
if (!component.id) {
let j = 1;
while (this.componentLibrary.hasOwnProperty(String(component.type + j))) {
j++;
}
this.componentLibrary[String(component.type + j)] = component;
this.componentList.push(component);
}
else {
this.componentLibrary[component.id] = component;
this.componentList.push(component);
}
}
return component;
}
getIndexOfComponent(component) {
return this.componentList.indexOf(component);
}
removeComponent(componentDeterminer) {
let component;
if (componentDeterminer instanceof Component_1.default) {
component = componentDeterminer;
const index = this.componentList.indexOf(component);
if (index > -1) {
this.componentList.splice(index, 1);
this.componentLibrary[component.id] = null;
}
else {
log.warn('removeComponent() Component not found:', componentDeterminer);
return null;
}
}
else if (typeof componentDeterminer === 'number') {
component = this.componentList.splice(componentDeterminer, 1)[0];
this.componentLibrary[component.id] = null;
}
else if (typeof componentDeterminer === 'string') {
component = this.componentLibrary[componentDeterminer];
if (component) {
this.componentList.splice(this.componentList.indexOf(component), 1);
this.componentLibrary[component.id] = null;
}
else {
log.warn('removeComponent() Component not found with id: ' + componentDeterminer);
return null;
}
}
else {
log.warn('removeComponent() Must pass Component, number, or string. Was given:', componentDeterminer);
return null;
}
return component;
}
getComponentById(componentId) {
if (this.componentLibrary) {
return this.componentLibrary[componentId];
}
else {
log.debug("getComponentById() this.componentLibrary is undefined, meaning no components have been added");
}
}
getComponentByIndex(index) {
if (this.componentList) {
if (index > -1 && index < this.componentList.length) {
return this.componentList[index];
}
else {
log.warn('getComponentByIndex() index ' + index + ' is out of bounds, must be under ' + this.componentList.length);
}
}
else {
log.warn('getComponentByIndex() this.componentList is undefined, meaning no components have been added');
}
return null;
}
findComponent(testFunction, against) {
if (testFunction(this, against)) {
return this;
}
else if (this.componentList) {
let component;
let foundComponent;
let length = this.componentList.length;
for (let i = 0; i < length; i++) {
component = this.componentList[i];
if (component instanceof ComponentGroup) {
foundComponent = component.findComponent(testFunction, against);
if (foundComponent) {
return foundComponent;
}
}
else {
if (testFunction(component, against)) {
return component;
}
}
}
}
return null;
}
update(elapsed) {
if (this._updateRegistry) {
let length = this._updateRegistry.length;
for (let i = 0; i < length; i++) {
this._updateRegistry[i].update(elapsed);
}
}
}
registerComponentUpdate(component) {
if (!this._updateRegistry) {
this._updateRegistry = [];
}
this._updateRegistry.push(component);
}
unregisterComponentUpdate(component) {
if (this._updateRegistry) {
for (let i = 0; i < this._updateRegistry.length; i++) {
if (this._updateRegistry[i] === component) {
this._updateRegistry.splice(i, 1);
}
}
}
}
createDisplay(container, assets) {
this.container = container;
if (this.componentList) {
const length = this.componentList.length;
for (let i = 0; i < length; i++) {
this.componentList[i].createDisplay(container, assets);
}
}
}
ready() {
if (this.componentList) {
const length = this.componentList.length;
for (let i = 0; i < length; i++) {
this.componentList[i].ready();
}
}
}
open(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME) {
this.openChildren(callback, transitionType, duration);
}
close(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME) {
this.closeChildren(callback, transitionType, duration);
}
openChildren(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME) {
if (this.componentList) {
let transitionArray = [];
let i = 0;
let length = this.componentList.length;
for (i; i < length; i++) {
let component = this.componentList[i];
transitionArray.push(function (subCallback) {
component.open(subCallback, transitionType, duration);
});
}
if (transitionArray.length > 0) {
async.parallel(transitionArray, function (err, results) {
if (err) {
log.error('openChildren() encountered error', err);
}
this.transitionComplete(callback, err, results);
}.bind(this));
}
else {
this.transitionComplete(callback);
}
}
else {
this.transitionComplete(callback);
}
}
closeChildren(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME) {
if (this.componentList) {
let transitionArray = [];
let i = 0;
let length = this.componentList.length;
for (i; i < length; i++) {
let component = this.componentList[i];
transitionArray.push(function (subCallback) {
component.close(subCallback, transitionType, duration);
});
}
if (transitionArray.length > 0) {
async.parallel(transitionArray, function (err, results) {
if (err) {
log.error('closeChildren() encountered error', err);
}
this.transitionComplete(callback, err, results);
}.bind(this));
}
else {
this.transitionComplete(callback);
}
}
else {
this.transitionComplete(callback);
}
}
actionHandler(action, fromComponent) {
this.parentGroup.actionHandler(action, fromComponent);
}
actionEnactor(action) {
let actionActedOn = false;
if (!this.inputLocked) {
if (this.componentList) {
let component;
let length = this.componentList.length;
for (let i = 0; i < length; i++) {
component = this.componentList[i];
if (component instanceof ComponentGroup) {
if (component.actionEnactor(action)) {
actionActedOn = true;
}
}
}
}
}
return actionActedOn;
}
destroy() {
if (this.componentList) {
let length = this.componentList.length;
for (let i = 0; i < length; i++) {
this.componentList[i].destroy();
}
}
this.container = null;
this.componentLibrary = null;
this.componentList = null;
this.componentConfigs = null;
this._updateRegistry = null;
super.destroy();
}
transitionComplete(callback, err, results) {
if (err) {
log.error('transitionComplete() error during transition, error', err);
}
callback();
}
updateComponentConfigs() {
let componentChanged = false;
if (this.componentList && this.componentConfigs) {
let length = this.componentList.length;
let component;
for (let i = 0; i < length; i++) {
component = this.componentList[i];
if (component.stateChanged) {
componentChanged = true;
component.updateConfig(this.componentConfigs[i]);
}
}
}
return componentChanged;
}
}
exports.default = ComponentGroup;
},{"./Component":121,"./ComponentCreator":122,"./ViewManager":127,"./log":149,"async":undefined}],124:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FaceRenderer_1 = require("../FaceRenderer");
class DisplayUtils {
static getScaleByWidthHeight(displayObject, width, height) {
const rect = displayObject.getBounds();
return Math.max(width / rect.width * displayObject.scale.x, height / rect.height * displayObject.scale.y);
}
static isContained(display, container) {
let parent = display.parent;
while (parent) {
if (parent === container) {
return true;
}
parent = parent.parent;
}
return false;
}
static getElementPosition(position) {
let point = new PIXI.Point(0, 0);
let margin = { x: 0, y: 0 };
if (position.margin) {
isNaN(position.margin) ? Object.assign(margin, position.margin) : Object.assign(margin, { x: Number(position.margin), y: Number(position.margin) });
}
margin.x = isNaN(margin.x) ? 0 : margin.x;
margin.y = isNaN(margin.y) ? 0 : margin.y;
if (!isNaN(position.x)) {
point.x = Number(position.x) + margin.x;
}
else if (DisplayUtils.CENTER === position.x) {
point.x = FaceRenderer_1.default.WIDTH / 2;
}
else if (DisplayUtils.LEFT === position.x) {
point.x = margin.x;
}
else if (DisplayUtils.RIGHT === position.x) {
point.x = FaceRenderer_1.default.WIDTH - margin.x;
}
if (!isNaN(position.y)) {
point.y = Number(position.y) + margin.y;
}
else if (DisplayUtils.CENTER === position.y) {
point.y = FaceRenderer_1.default.HEIGHT / 2;
}
else if (DisplayUtils.TOP === position.y) {
point.y = margin.y;
}
else if (DisplayUtils.BOTTOM === position.y) {
point.y = FaceRenderer_1.default.HEIGHT - margin.y;
}
return point;
}
}
DisplayUtils.LEFT = 'LEFT';
DisplayUtils.RIGHT = 'RIGHT';
DisplayUtils.CENTER = 'CENTER';
DisplayUtils.TOP = 'TOP';
DisplayUtils.BOTTOM = 'BOTTOM';
exports.default = DisplayUtils;
},{"../FaceRenderer":99}],125:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../Runtime");
const GestureManager_1 = require("../input/GestureManager");
const FaceRenderer_1 = require("../FaceRenderer");
const log_1 = require("./log");
const log = log_1.default.createChild('TouchManager');
var GESTURE;
(function (GESTURE) {
GESTURE["TAP"] = "tap";
GESTURE["SWIPE_DOWN"] = "swipeDown";
GESTURE["SWIPE"] = "swipeDown";
GESTURE["SWIPE_UP"] = "swipeUp";
GESTURE["PAN"] = "pan";
})(GESTURE = exports.GESTURE || (exports.GESTURE = {}));
class TouchManager {
constructor(renderer, viewManager) {
this.GESTURE = GESTURE;
this._interactionManager = null;
this._canvas = null;
this._gestureManager = null;
this._viewManager = null;
this._tapGesture = null;
this._swipeDownGesture = null;
this._swipeUpGesture = null;
this._panHorizontalGesture = null;
this._interactionEvent = null;
this._elementHit = null;
this._isSim = false;
this._prevX = null;
this._prevY = null;
this._isEmulatingPan = false;
this._isMouseDown = false;
if (!TouchManager._instance) {
this._isSim = (Runtime_1.default.instance.runMode === Runtime_1.default.instance.RunMode.SIMULATOR);
TouchManager._instance = this;
this._interactionManager = renderer['plugins'].interaction;
this._viewManager = viewManager;
this._canvas = renderer.view;
if (this._isSim) {
this.onViewportOut = this.onViewportOut.bind(this);
}
else {
this.onCoreTouchEvent = this.onCoreTouchEvent.bind(this);
}
this.checkElementHit = this.checkElementHit.bind(this);
}
}
static get instance() {
return TouchManager._instance;
}
init() {
this._gestureManager = Runtime_1.default.instance.face.gestures;
this._interactionEvent = {
data: {
global: new PIXI.Point()
}
};
if (this._isSim) {
this.addViewportOut();
}
}
addGesture(gesture = GESTURE.TAP, gestureEventCallback) {
switch (gesture) {
case GESTURE.TAP:
this.createTapGesture();
break;
case GESTURE.SWIPE_DOWN:
this.createSwipeDownGesture();
break;
case GESTURE.SWIPE_UP:
this.createSwipeUpGesture();
break;
case GESTURE.PAN:
this.createPanHorizontalGesture(gestureEventCallback);
break;
default:
log.warn('addGesture() passed: ' + gesture + ' which is not supported.');
break;
}
}
removeGesture(gesture = GESTURE.TAP) {
switch (gesture) {
case GESTURE.TAP:
if (this._tapGesture) {
this._gestureManager.removeStageGesture(this._tapGesture);
this._tapGesture = null;
}
break;
case GESTURE.SWIPE_DOWN:
if (this._swipeDownGesture) {
this._gestureManager.removeStageGesture(this._swipeDownGesture);
this._swipeDownGesture = null;
}
break;
case GESTURE.SWIPE_UP:
if (this._swipeUpGesture) {
this._gestureManager.removeStageGesture(this._swipeUpGesture);
this._swipeUpGesture = null;
}
break;
case GESTURE.PAN:
if (this._panHorizontalGesture) {
this._gestureManager.removeStageGesture(this._panHorizontalGesture);
this._panHorizontalGesture = null;
}
break;
default:
log.warn('removeGesture() passed: ' + gesture + ' which is not supported.');
return;
}
}
removeAllGestures() {
this.removeGesture(GESTURE.TAP);
this.removeGesture(GESTURE.SWIPE_DOWN);
this.removeGesture(GESTURE.SWIPE_UP);
this.removeGesture(GESTURE.PAN);
}
createRequiredGestures(view) {
let possibleGestures = [];
if (!this._tapGesture) {
possibleGestures.push(GESTURE.TAP);
}
if (!this._swipeDownGesture) {
possibleGestures.push(GESTURE.SWIPE_DOWN);
}
let i;
if (possibleGestures.length > 0 && view) {
view.findComponent((component) => {
if (component.hasTouchInteractive) {
for (i = possibleGestures.length; i >= 0; i--) {
if (component.hasActions(possibleGestures[i])) {
this.addGesture(possibleGestures[i]);
possibleGestures.splice(i, 1);
if (possibleGestures.length === 0) {
return true;
}
}
}
}
return false;
});
}
}
destroy() {
this.removeAllGestures();
if (this._isSim) {
this.removeViewportOut();
}
else {
this.removeCoreTouchEvents();
}
this._canvas = null;
this._interactionManager = null;
this._viewManager = null;
this._gestureManager = null;
this._interactionEvent = null;
}
addViewportOut() {
if (this._canvas) {
this._canvas.addEventListener('mouseleave', this.onViewportOut);
}
}
removeViewportOut() {
if (this._canvas) {
this._canvas.removeEventListener('mouseleave', this.onViewportOut);
}
}
onViewportOut() {
this._gestureManager.stop();
if (this._panHorizontalGesture) {
this._panHorizontalGesture.emit({ isFinal: true });
}
}
addCoreTouchEvents() {
if (this._canvas) {
this._canvas.addEventListener('mouseleave', this.onCoreTouchEvent);
this._canvas.addEventListener('mousedown', this.onCoreTouchEvent);
this._canvas.addEventListener('mouseup', this.onCoreTouchEvent);
this._canvas.addEventListener('mousemove', this.onCoreTouchEvent);
}
}
removeCoreTouchEvents() {
if (this._canvas) {
this._canvas.removeEventListener('mouseleave', this.onCoreTouchEvent);
this._canvas.removeEventListener('mousedown', this.onCoreTouchEvent);
this._canvas.removeEventListener('mouseup', this.onCoreTouchEvent);
this._canvas.removeEventListener('mousemove', this.onCoreTouchEvent);
}
}
onCoreTouchEvent(event) {
if (event.type === 'mousedown') {
this._isMouseDown = true;
this._prevX = this._prevY = null;
}
else if (event.type === 'mouseup' || event.type === 'mouseleave') {
this._prevX = this._prevY = null;
if (this._isEmulatingPan) {
this._gestureManager.spoofGestureWithOptions('pan', { isFinal: true, srcEvent: { movementX: 0, movementY: 0 }, pointers: [{ clientX: this._prevX, clientY: this._prevY }] });
}
this._isEmulatingPan = false;
this._isMouseDown = false;
}
else if (event.type === 'mousemove') {
if (!this._isMouseDown) {
if (!this._isEmulatingPan) {
let xMargin = FaceRenderer_1.default.WIDTH * 0.1;
if (!this._prevX && !this._prevY && (event.clientX <= xMargin || (event.clientX <= FaceRenderer_1.default.WIDTH && event.clientX >= FaceRenderer_1.default.WIDTH - xMargin))) {
this._isEmulatingPan = true;
this._prevX = event.clientX;
this._prevY = event.clientY;
}
}
else {
this._gestureManager.spoofGestureWithOptions('pan', { isFinal: false, srcEvent: { movementX: (event.clientX - this._prevX),
movementY: (event.clientY - this._prevY) }, pointers: [{ clientX: event.clientX, clientY: event.clientY }] });
this._prevX = event.clientX;
this._prevY = event.clientY;
}
}
}
}
resetInput(x, y) {
this._interactionEvent.data.global.x = x;
this._interactionEvent.data.global.y = y;
this._interactionEvent.target = null;
}
createTapGesture() {
if (!this._tapGesture) {
this._tapGesture = this._gestureManager.addStageGesture(this._gestureManager.hammer.Tap, {
event: GestureManager_1.default.TAP,
time: 5000,
interval: 0,
threshold: TouchManager.THRESHOLD,
touchAction: 'manipulation'
}, this.tapHandler.bind(this));
return true;
}
return false;
}
tapHandler(gestureEvent) {
if (gestureEvent.pointers[0].clientY === 358) {
log.warn("Ignoring tap event for y coord = 358!");
return;
}
Runtime_1.default.instance.globalEvents.shared.screenGesture.emit(GESTURE.TAP);
log.info("received tap event", gestureEvent.eventType, gestureEvent.pointers[0].clientX, gestureEvent.pointers[0].clientY);
let handled = false;
const currentView = this._viewManager.currentView;
if (currentView && !currentView.inputLocked) {
if (currentView.isTouchInteractive && currentView.hasActions(GESTURE.TAP)) {
handled = currentView.triggerActions(GESTURE.TAP);
}
else {
this.resetInput(gestureEvent.pointers[0].clientX, gestureEvent.pointers[0].clientY);
if (this.findTappedDisplay(currentView)) {
handled = this._elementHit.triggerActions(GESTURE.TAP);
this._elementHit = null;
}
this.resetInput(0, 0);
}
}
if (handled) {
Runtime_1.default.instance.face.views.disableMovement = true;
}
}
findTappedDisplay(currentView) {
this._elementHit = null;
this._interactionManager['processInteractive'](this._interactionEvent, currentView.stage, this.checkElementHit, true, true);
return (this._elementHit !== null);
}
checkElementHit(event, displayObject, hit) {
if (hit && displayObject.hasOwnProperty('parentElement')) {
this._elementHit = displayObject['parentElement'];
}
}
createSwipeDownGesture() {
if (!this._swipeDownGesture) {
this._swipeDownGesture = this._gestureManager.addStageGesture(this._gestureManager.hammer.Swipe, {
event: GestureManager_1.default.SWIPEDOWN,
direction: this._gestureManager.hammer.DIRECTION_DOWN,
threshold: TouchManager.THRESHOLD,
velocity: .3
}, this.swipeDownHandler.bind(this));
if (this._panHorizontalGesture) {
this._panHorizontalGesture.recognizeWith(this._swipeDownGesture);
}
return true;
}
return false;
}
swipeDownHandler(gestureEvent) {
Runtime_1.default.instance.globalEvents.shared.screenGesture.emit(GESTURE.SWIPE_DOWN);
const currentView = this._viewManager.currentView;
if (currentView && currentView.isTouchInteractive) {
const handled = currentView.triggerActions(GESTURE.SWIPE_DOWN);
if (handled) {
Runtime_1.default.instance.face.views.disableMovement = true;
}
}
}
createSwipeUpGesture() {
if (!this._swipeUpGesture) {
this._swipeUpGesture = this._gestureManager.addStageGesture(this._gestureManager.hammer.Swipe, {
event: GestureManager_1.default.SWIPEUP,
direction: this._gestureManager.hammer.DIRECTION_UP,
threshold: TouchManager.THRESHOLD,
velocity: .3
}, this.swipeUpHandler.bind(this));
if (this._panHorizontalGesture) {
this._panHorizontalGesture.recognizeWith(this._swipeUpGesture);
}
if (this._swipeDownGesture) {
this._swipeDownGesture.recognizeWith(this._swipeUpGesture);
}
return true;
}
return false;
}
swipeUpHandler(gestureEvent) {
Runtime_1.default.instance.globalEvents.shared.screenGesture.emit(GESTURE.SWIPE_UP);
const currentView = this._viewManager.currentView;
if (currentView && currentView.isTouchInteractive) {
const handled = currentView.triggerActions(GESTURE.SWIPE_UP);
if (handled) {
Runtime_1.default.instance.face.views.disableMovement = true;
}
}
}
createPanHorizontalGesture(gestureEventCallback) {
if (!this._panHorizontalGesture) {
if (!this._isSim) {
this.addCoreTouchEvents();
}
this._panHorizontalGesture = this._gestureManager.addStageGesture(this._gestureManager.hammer.Pan, {
event: GestureManager_1.default.PAN,
direction: this._gestureManager.hammer.DIRECTION_HORIZONTAL,
threshold: TouchManager.THRESHOLD,
}, gestureEventCallback);
if (this._swipeDownGesture) {
this._swipeDownGesture.recognizeWith(this._panHorizontalGesture);
}
if (this._swipeUpGesture) {
this._swipeUpGesture.recognizeWith(this._panHorizontalGesture);
}
this._gestureManager.addStageGesture(this._gestureManager.hammer.Pan, {
event: GestureManager_1.default.PAN,
direction: this._gestureManager.hammer.DIRECTION_HORIZONTAL
}, () => {
Runtime_1.default.instance.face.views.disableMovement = true;
});
return true;
}
else {
this._gestureManager.addStageGesture(this._gestureManager.hammer.Pan, {
event: GestureManager_1.default.PAN,
direction: this._gestureManager.hammer.DIRECTION_HORIZONTAL
}, gestureEventCallback);
}
return false;
}
}
TouchManager._instance = null;
TouchManager.THRESHOLD = 30;
exports.default = TouchManager;
},{"../../Runtime":1,"../FaceRenderer":99,"../input/GestureManager":160,"./log":149}],126:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_typed_events_1 = require("jibo-typed-events");
const ViewProcess_1 = require("./ViewProcess");
class ViewGlobalEvents extends jibo_typed_events_1.EventContainer {
constructor() {
super();
this.process = new jibo_typed_events_1.Event('View process status changed');
this.view = new jibo_typed_events_1.Event('View emitted an event');
}
}
exports.default = ViewGlobalEvents;
class ViewProcessResult {
constructor(viewProcess) {
this.status = '';
this.currentId = '';
this.closingId = '';
this.changeOptions = {};
this.status = viewProcess.status;
this.currentId = (viewProcess.currentView) ? viewProcess.currentView.id : '';
this.closingId = (viewProcess.closingView) ? viewProcess.closingView.id : '';
this.changeOptions = (viewProcess.changeOptions) ? ViewProcess_1.default.serializeOptions(viewProcess.changeOptions) : {};
}
}
exports.ViewProcessResult = ViewProcessResult;
class ViewResult {
constructor(view, event, data) {
this.event = '';
this.id = '';
this.type = '';
this.status = '';
this.data = null;
this.event = event;
this.id = view.id;
this.type = view.type;
this.status = view.state;
this.data = data;
}
}
exports.ViewResult = ViewResult;
},{"./ViewProcess":128,"jibo-typed-events":undefined}],127:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../Runtime");
const ComponentCreator_1 = require("./ComponentCreator");
const Component_1 = require("./Component");
const ComponentGroup_1 = require("./ComponentGroup");
const TouchManager_1 = require("./TouchManager");
const ActionData_1 = require("./actions/ActionData");
const View_1 = require("./views/View");
const EyeView_1 = require("./views/EyeView");
const MenuView_1 = require("./views/MenuView");
const ImageView_1 = require("./views/ImageView");
const ContactsView_1 = require("./views/ContactsView");
const TextView_1 = require("./views/TextView");
const Element_1 = require("./components/Element");
const ElementGroup_1 = require("./components/ElementGroup");
const Label_1 = require("./components/Label");
const Button_1 = require("./components/Button");
const StandardButton_1 = require("./components/StandardButton");
const MenuButton_1 = require("./components/MenuButton");
const ContactButton_1 = require("./components/ContactButton");
const List_1 = require("./components/List");
const Clip_1 = require("./components/Clip");
const FaceRenderer_1 = require("../FaceRenderer");
const ViewState_1 = require("./ViewState");
const ContentButton_1 = require("./components/ContentButton");
const ViewProcess_1 = require("./ViewProcess");
const ViewGlobalEvents_1 = require("./ViewGlobalEvents");
const MimManager_1 = require("../../bt/mim/MimManager");
const async = require("async");
const log_1 = require("./log");
const log = log_1.default.createChild('ViewManager');
const DEFAULT_TRANS_TIME = 550;
var STACK_DIRECTION;
(function (STACK_DIRECTION) {
STACK_DIRECTION[STACK_DIRECTION["ADD"] = 1] = "ADD";
STACK_DIRECTION[STACK_DIRECTION["REMOVE"] = 2] = "REMOVE";
STACK_DIRECTION[STACK_DIRECTION["SWAP"] = 3] = "SWAP";
})(STACK_DIRECTION = exports.STACK_DIRECTION || (exports.STACK_DIRECTION = {}));
var TRANSITION;
(function (TRANSITION) {
TRANSITION["UP"] = "trans_up";
TRANSITION["DOWN"] = "trans_down";
TRANSITION["LEFT"] = "trans_left";
TRANSITION["RIGHT"] = "trans_right";
TRANSITION["IN"] = "trans_in";
TRANSITION["OUT"] = "trans_out";
TRANSITION["EYE"] = "trans_eye";
TRANSITION["NONE"] = "trans_none";
})(TRANSITION = exports.TRANSITION || (exports.TRANSITION = {}));
class ViewManager {
constructor(renderer) {
this.ActionData = ActionData_1.default;
this.Component = Component_1.default;
this.ComponentGroup = ComponentGroup_1.default;
this.Button = Button_1.default;
this.Clip = Clip_1.default;
this.ContactButton = ContactButton_1.default;
this.ContentButton = ContentButton_1.default;
this.Element = Element_1.default;
this.Label = Label_1.default;
this.List = List_1.default;
this.MenuButton = MenuButton_1.default;
this.ContactsView = ContactsView_1.default;
this.EyeView = EyeView_1.default;
this.MenuView = MenuView_1.default;
this.ImageView = ImageView_1.default;
this.View = View_1.default;
this.TextView = TextView_1.default;
this.TRANSITION = TRANSITION;
this.STATE = View_1.STATE;
this.CATEGORY = View_1.CATEGORY;
this.STACK_DIRECTION = STACK_DIRECTION;
this.GESTURE = TouchManager_1.GESTURE;
this.stage = null;
this.disabled = false;
this._disableMovement = false;
this._viewStates = [];
this._viewProcess = null;
this._events = null;
this._border = null;
this._waterMark = null;
this._borderVisibility = false;
this.stage = new PIXI.Container();
this._viewStates = [];
this._viewProcess = new ViewProcess_1.default();
this._events = new ViewGlobalEvents_1.default();
this._touchManager = new TouchManager_1.default(renderer, this);
this._creator = new ComponentCreator_1.default();
this.registerDefaults();
this._viewStates.push(this._creator.createViewState(EyeView_1.default.DEFAULT_TYPE));
const debug = false;
if (debug) {
this.logEvents();
}
}
static get TRANS_TIME() {
return ViewManager._transTime;
}
get TRANSITION_TIME() { return ViewManager.TRANS_TIME; }
get BACK() { return View_1.default.BACK; }
get EMPTY() { return View_1.default.EMPTY; }
get PAUSED() { return View_1.default.PAUSED; }
static get GLOBAL_CACHE() { return 'global-gui'; }
get currentView() {
return this._viewProcess.currentView;
}
get creator() {
return this._creator;
}
set borderVisible(visible) {
if (this._borderVisibility !== visible) {
this._borderVisibility = visible;
if (this._border) {
this._border.visible = this._borderVisibility;
}
}
}
get borderVisible() {
return this._borderVisibility;
}
get viewStackLength() {
let length = 0;
if (this._viewStates) {
length = this._viewStates.length;
}
if (this.currentView) {
length++;
let pausedParent = this.currentView.pausedParent;
while (pausedParent) {
length++;
pausedParent = pausedParent.pausedParent;
}
}
return length;
}
get viewsInProcess() {
return this._viewProcess.active;
}
get events() {
return this._events;
}
set disableMovement(value) {
if (this._menuMode && value !== this._disableMovement) {
this._menuMode.release();
this._menuMode = null;
const expression = Runtime_1.default.instance.expression;
if (value) {
expression.pushAttentionMode(expression.AttentionMode.OFF).then((handle) => {
this._menuMode = handle;
}).catch(() => {
});
}
else {
expression.pushAttentionMode(expression.AttentionMode.MENU).then((handle) => {
this._menuMode = handle;
}).catch(() => {
});
}
}
this._disableMovement = value;
}
reset() {
this._viewProcess.reset();
this._viewProcess = new ViewProcess_1.default();
this._events.removeAllListeners();
this._viewStates.length = 0;
this._viewStates.push(this._creator.createViewState(EyeView_1.default.DEFAULT_TYPE));
this.removeWatermark();
this.stage.removeChildren();
this.borderVisible = false;
this._touchManager.removeAllGestures();
if (this._menuMode) {
this._menuMode.release();
this._menuMode = null;
}
}
destroyBorder() {
if (this._border) {
if (this._border.parent) {
this._border.parent.removeChild(this._border);
}
this._border.destroy({ children: true });
this._border = null;
}
}
addWatermark(icon) {
if (!this._border) {
log.warn('cannot add watermark until border has been created');
return;
}
if (this._waterMark) {
this.stage.parent.removeChild(this._waterMark);
}
this._waterMark = icon;
this.stage.parent.addChildAt(this._waterMark, this.stage.parent.getChildIndex(this._border) + 1);
}
removeWatermark() {
if (this._waterMark) {
this.stage.parent.removeChild(this._waterMark);
this._waterMark = null;
}
}
destroy() {
this._viewProcess = null;
this.stage = null;
this._touchManager.destroy();
this._touchManager = null;
Runtime_1.default.instance.loader.deleteCache(ViewManager.GLOBAL_CACHE);
}
init(callback, prepWorkers = true) {
this._touchManager.init();
this.addViewNextInStack(null, TRANSITION.NONE);
Runtime_1.default.instance.loader.addCache(ViewManager.GLOBAL_CACHE);
const sfxMapId = 'guiSfxMap';
const loader = Runtime_1.default.instance.loader.load({
id: sfxMapId,
src: 'core://resources/audio/guiMap.json'
}, (err) => {
if (err) {
log.error('init() error loading initial assets', err);
}
this.createBorder(Runtime_1.default.instance.loader.cached('border-corner', ViewManager.GLOBAL_CACHE), Runtime_1.default.instance.loader.cached('border-edge', ViewManager.GLOBAL_CACHE));
if (callback) {
callback();
}
});
loader.once('taskDone', (result, original, load) => {
const assets = [];
for (let key in result) {
if (result.hasOwnProperty(key)) {
assets.push({
id: key,
src: result[key],
type: 'sound',
cache: ViewManager.GLOBAL_CACHE
});
}
}
assets.push({
id: 'border-corner',
src: 'core://resources/border/border-corner.png',
type: 'texture',
cache: ViewManager.GLOBAL_CACHE
});
assets.push({
id: 'border-edge',
src: 'core://resources/border/border-edge.png',
type: 'texture',
cache: ViewManager.GLOBAL_CACHE
});
load.addAssets(assets);
});
if (prepWorkers) {
Runtime_1.default.instance.loader.load([
'core://resources/buttons/images/actionButton_atlas_1.crn',
'core://resources/buttons/images/skillButton_atlas_1.crn',
'core://resources/buttons/images/loader_atlas_1.crn'
], {
complete: () => {
Runtime_1.default.instance.loader.load([
'core://resources/buttons/images/actionButton_atlas_1.crn',
'core://resources/buttons/images/skillButton_atlas_1.crn',
'core://resources/buttons/images/loader_atlas_1.crn'
], {
complete: () => {
}
});
}
});
}
}
createView(viewDeterminer, config, open = false, onOpenComplete, openTransition = TRANSITION.UP, closeTransition = TRANSITION.UP) {
let viewState = this._creator.createViewState(viewDeterminer, config);
let view = this._creator.createViewFromState(viewState);
if (open) {
this.changeView({ addView: view, transitionOpen: openTransition, transitionClose: closeTransition }, onOpenComplete);
}
return view;
}
createViewFromConfigPath(configPath, open = false, callback, openTransition = TRANSITION.UP, closeTransition = TRANSITION.UP) {
if (open) {
this.changeView({ addView: configPath, transitionOpen: openTransition, transitionClose: closeTransition }, callback);
}
else {
this._creator.createViewFromConfigPath(configPath, callback);
}
}
addViewNextInStack(callback, openTransition = TRANSITION.UP, closeTransition = TRANSITION.UP, onFailure) {
this.changeView({ addView: this.popViewFromStack(), transitionOpen: openTransition, transitionClose: closeTransition }, callback, onFailure);
}
update(elapsed) {
if (this._viewProcess.currentView) {
this._viewProcess.currentView.update(elapsed);
}
}
actionHandler(action, fromComponent, onComplete) {
const data = action.data;
switch (action.type) {
case ActionData_1.default.CHANGE_VIEW: {
if (data && data.hasOwnProperty('options')) {
this.changeView(data.options, onComplete);
}
else {
log.info('actionHandler() action of type: ' + ActionData_1.default.CHANGE_VIEW + ' must specify options');
}
break;
}
case ActionData_1.default.CLOSE_ALL_OPEN:
log.warn('Deprecation :: ActionData.CLOSE_ALL_OPEN is deprecated, please use ActionData.CHANGE_VIEW with the appropriate options instead');
break;
case ActionData_1.default.OPEN_VIEW: {
if (data) {
let view;
let viewConfigPath;
if (data.hasOwnProperty('viewType')) {
const viewState = new ViewState_1.default(data.viewType);
if (data.hasOwnProperty('configPath')) {
viewState.configPath = data.configPath;
}
view = this._creator.createViewFromState(viewState);
}
else if (data.hasOwnProperty('configPath')) {
viewConfigPath = data.configPath;
}
let openTransition;
let closeTransition;
if (data.hasOwnProperty('openTransition')) {
openTransition = data['openTransition'];
}
if (data.hasOwnProperty('closeTransition')) {
closeTransition = data['closeTransition'];
}
if (view) {
this.changeView({ addView: view, transitionOpen: openTransition, transitionClose: closeTransition }, onComplete);
}
else if (viewConfigPath) {
this.changeView({ addView: viewConfigPath, transitionOpen: openTransition, transitionClose: closeTransition }, onComplete);
}
else {
log.warn('actionHandler() action of type ' + ActionData_1.default.OPEN_VIEW + ' neither View nor path to the View configuration were given, ' +
'cannot open a new View without this data');
}
}
else {
log.warn('actionHandler() action of type ' + ActionData_1.default.OPEN_VIEW + ' called but action data was undefined. ' +
'Cannot open new view without data defining view to open.');
}
break;
}
case ActionData_1.default.SWIPE_DOWN: {
log.warn('Deprecation :: the ActionData.SWIPE_DOWN action is getting phased out');
this.changeView({ remove: true, transitionClose: TRANSITION.DOWN, transitionOpen: TRANSITION.DOWN }, onComplete);
break;
}
case ActionData_1.default.CLOSE_VIEW: {
let openTransition = TRANSITION.DOWN;
let closeTransition = TRANSITION.DOWN;
if (data) {
if (data.hasOwnProperty('openTransition')) {
openTransition = data['openTransition'];
}
if (data.hasOwnProperty('closeTransition')) {
closeTransition = data['closeTransition'];
}
}
this.changeView({ remove: true, transitionClose: closeTransition, transitionOpen: openTransition }, onComplete);
break;
}
case ActionData_1.default.CLOSE_VIEW_EMPTY: {
log.warn('Deprecation :: ActionData.CLOSE_ALL_OPEN is deprecated, please use ActionData.CLOSE_VIEW_EMPTY with the appropriate options instead');
let closeTransition = TRANSITION.DOWN;
if (data) {
if (data.hasOwnProperty('closeTransition')) {
closeTransition = data['closeTransition'];
}
}
this.changeView({ remove: true, leaveEmpty: true, transitionClose: closeTransition }, onComplete);
break;
}
case ActionData_1.default.CLOSE_ALL: {
log.warn('Deprecation :: ActionData.CLOSE_ALL_OPEN is deprecated, please use ActionData.CLOSE_ALL with the appropriate options instead');
this.changeView({ removeAll: true }, onComplete);
break;
}
case ActionData_1.default.CLOSE_ALL_EMPTY: {
log.warn('Deprecation :: ActionData.CLOSE_ALL_OPEN is deprecated, please use ActionData.CLOSE_ALL_EMPTY with the appropriate options instead');
this.changeView({ removeAll: true, leaveEmpty: true }, onComplete);
break;
}
case ActionData_1.default.SWIPE_RIGHT:
case ActionData_1.default.SWIPE_LEFT: {
if (this.currentView) {
this.currentView.actionEnactor(action);
}
break;
}
case ActionData_1.default.UTTERANCE: {
if (data && data.hasOwnProperty('utterance')) {
MimManager_1.default.instance.handleSpeech.emit(data.utterance);
}
else {
log.warn('actionHandler() action ' + ActionData_1.default.UTTERANCE + ' action data was absent ' +
' or utterance string was not specified');
}
break;
}
case ActionData_1.default.VERBAL_COMMAND: {
if (data && data.hasOwnProperty('intent')) {
this.actionEnactor(action);
}
else {
log.warn('actionHandler() action ' + ActionData_1.default.VERBAL_COMMAND + ' action called but action data was absent ' +
' or intent string was not specified');
}
break;
}
case ActionData_1.default.MIM_END: {
MimManager_1.default.instance.end.emit(data);
break;
}
case ActionData_1.default.MIM_SHOW_GUI: {
MimManager_1.default.instance.openGUI.emit();
break;
}
default: {
log.debug('actionHandler() : action type handled: ' + action.type);
break;
}
}
}
actionEnactor(action) {
if (this.currentView) {
return (this.currentView.actionEnactor(action));
}
return false;
}
changeView(options, onComplete, onFailure, onLoaded) {
if (this.disabled) {
if (onFailure) {
onFailure("jibo.face.views is disabled.");
}
return;
}
if (!options) {
log.warn('changeView() must be provided options, none were given so changeView will not execute.');
return;
}
const process = this._viewProcess;
this.setTextureGC(false, process.currentView);
if (process.currentView) {
process.currentView.lockInput(true);
}
if (process.interrupt(options)) {
this._events.process.emit(new ViewGlobalEvents_1.ViewProcessResult(process));
process.addProcessToQueue(options, onComplete, onFailure, onLoaded);
}
else {
process.start(onComplete, onFailure, onLoaded, options);
this._events.process.emit(new ViewGlobalEvents_1.ViewProcessResult(process));
new Promise((changeResolve, changeReject) => {
if (process.interrupted) {
changeReject(new Error('View process interruption'));
}
else {
changeResolve();
}
})
.then(() => {
return new Promise((resolveView, rejectView) => {
if (process.interrupted) {
rejectView(new Error('View process interruption'));
}
else {
if (!options.leaveEmpty && options.addView) {
if (typeof options.addView === 'string') {
this._creator.createViewFromConfigPath(options.addView, resolveView, rejectView);
}
else if (options.addView instanceof View_1.default) {
resolveView(options.addView.loadConfig());
}
else {
resolveView(this._creator.createViewFromConfigObject(options.addView));
}
}
else {
resolveView(null);
}
}
});
})
.then((nextView) => {
if (nextView) {
process.storeView(nextView);
}
if (process.interrupted) {
return Promise.reject(new Error('View process interruption'));
}
else {
if (options.removeAll) {
return this.removeToRoot(process, nextView, options.leaveEmpty, options.transitionClose, options.transitionOpen);
}
else if (options.removeTo) {
return this.removeTo(process, options.removeTo, false, nextView, options.pause, options.leaveEmpty, options.transitionClose, options.transitionOpen);
}
else if (options.removeToInclude) {
return this.removeTo(process, options.removeToInclude, true, nextView, options.pause, options.leaveEmpty, options.transitionClose, options.transitionOpen);
}
else if (options.remove) {
return this.remove(process, nextView, options.leaveEmpty, options.transitionClose, options.transitionOpen);
}
else if (nextView) {
return this.add(process, nextView, options.pause, options.transitionOpen, options.transitionClose);
}
else {
log.warn('changeView() invalid options:', ViewProcess_1.default.serializeOptions(options));
return Promise.reject(new Error('View process given invalid options.'));
}
}
})
.then((view) => {
if (process.interrupted) {
this.viewProcessFailure(process);
}
else {
process.complete(view);
this.setTextureGC(true, process.currentView);
this._events.process.emit(new ViewGlobalEvents_1.ViewProcessResult(this._viewProcess));
}
})
.catch((err) => {
log.info('changeView() error caught during view changing process:', err);
this.viewProcessFailure(process);
});
}
}
addView(viewDeterminer, onAdded, openTransition = TRANSITION.UP, closeTransition = TRANSITION.UP, onFailure) {
this.changeView({ addView: viewDeterminer, transitionOpen: openTransition, transitionClose: closeTransition }, onAdded, onFailure);
}
removeView(onRemoved, openTransition = TRANSITION.DOWN, closeTransition = TRANSITION.DOWN, onFailure) {
this.changeView({ remove: true, transitionOpen: openTransition, transitionClose: closeTransition }, onRemoved, onFailure);
}
forceEyeView(onCompleteCallback, onPressCallback, openTransition = TRANSITION.IN, closeTransition = TRANSITION.UP, onFailure) {
if (this.disabled) {
if (onFailure) {
onFailure("jibo.face.views is disabled.");
}
return;
}
const process = this._viewProcess;
let eyeIsCurrent = (this.currentView && this.currentView.type === EyeView_1.default.DEFAULT_TYPE);
if (eyeIsCurrent && process.status === ViewProcess_1.default.STARTED) {
eyeIsCurrent = (process.closingView && this.currentView.state === View_1.STATE.LOADED);
}
if (eyeIsCurrent) {
if (process.active) {
if (onPressCallback) {
this.currentView.addAction(ActionData_1.default.CALLBACK, { callback: onPressCallback }, true);
}
if (process.onComplete) {
const origComplete = process.onComplete;
process.onComplete = (view) => {
this.clearViewStack(view);
origComplete(view);
this.closePaused(process, view, TRANSITION.NONE)
.then(() => {
if (onCompleteCallback) {
onCompleteCallback(view);
}
})
.catch((err) => {
log.error('forceEyeView() error closing paused views', view);
if (onFailure) {
onFailure();
}
});
};
}
else {
process.onComplete = (view) => {
this.clearViewStack(view);
this.closePaused(process, view, TRANSITION.NONE)
.then(() => {
if (onCompleteCallback) {
onCompleteCallback(view);
}
})
.catch((err) => {
log.error('forceEyeView() error closing paused views', view);
if (onFailure) {
onFailure();
}
});
};
}
if (onFailure) {
if (process.onFailure) {
const origFailure = process.onFailure;
process.onFailure = () => {
origFailure();
onFailure();
};
}
else {
process.onFailure = onFailure;
}
}
}
else {
this.clearViewStack(this.currentView);
this.closePaused(process, this.currentView, TRANSITION.NONE)
.then(() => {
this.setTextureGC(true, process.currentView);
if (onPressCallback) {
this.currentView.lockInput(false);
this.currentView.addAction(ActionData_1.default.CALLBACK, { callback: onPressCallback }, true);
}
if (onCompleteCallback) {
onCompleteCallback(this.currentView);
}
})
.catch((err) => {
log.error('forceEyeView() error closing paused views', this.currentView);
if (onFailure) {
onFailure();
}
});
}
}
else {
this.changeView({
removeAll: true,
transitionOpen: openTransition,
transitionClose: closeTransition,
}, (view) => {
if (view) {
if (onPressCallback) {
view.addAction(ActionData_1.default.CALLBACK, { callback: onPressCallback }, true);
}
}
else {
log.warn('forceEyeView() view was not returned from view change process removeAll, this should not happen.');
}
if (onCompleteCallback) {
onCompleteCallback(view);
}
}, onFailure);
}
}
viewStackCleanup(closeTransition = TRANSITION.DOWN) {
return new Promise((resolve, reject) => {
let view = this.currentView;
if (view) {
if (view.category !== View_1.CATEGORY.EYE) {
this.changeView({
removeAll: true,
leaveEmpty: true,
transitionClose: closeTransition
}, () => {
resolve();
}, () => {
log.error('cleanupViews() failed to remove all views, calling done anyway');
reject();
});
}
else {
this.forceEyeView(() => {
resolve();
}, null, TRANSITION.IN, TRANSITION.DOWN, () => {
log.error('cleanupViews() failure during forceEyeView, calling done anyway');
reject();
});
}
}
else {
this.changeView({
removeAll: true,
leaveEmpty: true
}, () => {
resolve();
}, () => {
log.error('cleanupViews() failed to remove all views, calling done anyway');
reject();
});
}
});
}
hasView(id) {
let view = this._viewProcess.currentView;
while (view) {
if (view.id === id) {
return true;
}
else {
view = view.pausedParent;
}
}
for (let i = this._viewStates.length - 1; i >= 0; i--) {
if (this._viewStates[i].id === id) {
return true;
}
}
return false;
}
resetTransTime(transTime = DEFAULT_TRANS_TIME) {
ViewManager._transTime = transTime;
}
viewProcessFailure(process) {
let leaveCurrent = false;
let queueLength = process.processQueue.length;
if (process.interrupted && queueLength > 0) {
let currentView = process.currentView;
if (currentView) {
let nextOptions = process.processQueue[queueLength - 1].changeOptions;
let currentOptions = process.changeOptions;
if (nextOptions.remove || nextOptions.removeAll || (nextOptions.removeToInclude && nextOptions.removeToInclude === currentView.id)) {
if (currentOptions.removeTo || currentOptions.removeAll) {
log.info('viewProcessFailure() managing clean transition with removeTo or removeToInclude in current process is too complicated, will not attempt');
}
else {
if (currentView.state === View_1.STATE.LOADED || currentView.state === View_1.STATE.OPENED) {
log.info('viewProcessFailure() since interrupting process will close current view ' + currentView.id + ', preserve it so it can be closed cleanly: ');
leaveCurrent = true;
if (process.closingView && process.closingView.state !== View_1.STATE.DESTROYED) {
if (currentOptions.addView && !currentOptions.pause && !currentOptions.remove && !currentOptions.removeAll) {
log.debug('viewProcessFailure() add closing view and its paused views to stack.');
this.pushViewWithPausedToStack(process.closingView);
}
}
}
}
}
}
}
process.fail(leaveCurrent);
this._events.process.emit(new ViewGlobalEvents_1.ViewProcessResult(process));
if (!process.currentView && this.viewStackLength === 0) {
this._viewStates.push(this._creator.createViewState(EyeView_1.default.DEFAULT_TYPE));
}
log.debug('viewProcessFailure() number of processes in queue: ' + process.processQueue.length);
if (queueLength > 0) {
let queuedProcess = null;
let whileCondition = true;
while (whileCondition) {
queuedProcess = process.processQueue.shift();
if (process.processQueue.length === 0) {
log.debug('viewProcessFailure() start process at top of queue', ViewProcess_1.default.serializeOptions(queuedProcess.changeOptions));
Runtime_1.default.instance.face.paused = false;
this.changeView(queuedProcess.changeOptions, queuedProcess.onComplete, queuedProcess.onFailure, queuedProcess.onLoaded);
return;
}
else {
log.debug('viewProcessFailure() process beneath top most process, trigger fail', ViewProcess_1.default.serializeOptions(queuedProcess.changeOptions));
queuedProcess.fail();
this._events.process.emit(new ViewGlobalEvents_1.ViewProcessResult(queuedProcess));
}
}
}
else if (process.currentView) {
process.currentView.lockInput(false);
Runtime_1.default.instance.face.paused = false;
log.info('viewProcessFailure() view process failed with no pending processes in queue, resume use of current view');
this.setTextureGC(true, process.currentView);
}
}
add(process, nextView, pauseOptions, openTransition = TRANSITION.UP, closeTransition = TRANSITION.UP) {
return new Promise((resolve, reject) => {
if (process.currentView) {
if (nextView.willPauseParent || pauseOptions) {
nextView.pausedParent = process.currentView;
process.currentView = nextView;
nextView.applyTransitions(View_1.default.PAUSED, true, STACK_DIRECTION.ADD);
resolve(this.pauseThenOpen(process, nextView, nextView.pausedParent, pauseOptions, openTransition));
}
else {
process.closingView = process.currentView;
process.currentView = nextView;
process.storeView(process.closingView);
this.prepareTransitions(nextView, process.closingView, STACK_DIRECTION.ADD);
resolve(this.closeAndOpenViews(process, nextView, process.closingView, openTransition, closeTransition, true));
}
}
else {
process.currentView = nextView;
nextView.applyTransitions(View_1.default.EMPTY, true, STACK_DIRECTION.ADD);
resolve(this.openView(process, nextView, openTransition));
}
});
}
remove(process, nextView, leaveEmpty = false, closeTransition = TRANSITION.DOWN, openTransition = TRANSITION.DOWN) {
return new Promise((resolve, reject) => {
if (process.currentView) {
if (this.viewStackLength === 1) {
if (leaveEmpty) {
process.closingView = process.currentView;
process.currentView = null;
process.storeView(process.closingView);
process.closingView.applyTransitions(View_1.default.EMPTY, false, STACK_DIRECTION.REMOVE);
resolve(this.closeView(process, process.closingView, closeTransition, true));
}
else if (nextView) {
process.closingView = process.currentView;
process.currentView = nextView;
process.storeView(process.closingView);
this.prepareTransitions(nextView, process.closingView, STACK_DIRECTION.SWAP);
resolve(this.closeAndOpenViews(process, nextView, process.closingView, openTransition, closeTransition, true));
}
else {
resolve(process.currentView);
}
}
else {
if (leaveEmpty) {
process.closingView = process.currentView;
process.currentView = null;
process.storeView(process.closingView);
process.closingView.applyTransitions(View_1.default.EMPTY, false, STACK_DIRECTION.REMOVE);
resolve(this.closeView(process, process.closingView, closeTransition));
}
else if (nextView) {
nextView.pausedParent = process.currentView.pausedParent;
process.closingView = process.currentView;
process.currentView = nextView;
process.storeView(process.closingView);
this.prepareTransitions(nextView, process.closingView, STACK_DIRECTION.SWAP);
resolve(this.closeAndOpenViews(process, nextView, process.closingView, openTransition, closeTransition, false));
}
else {
if (process.currentView.pausedParent) {
process.closingView = process.currentView;
process.currentView = nextView = process.currentView.pausedParent;
process.storeView(process.closingView);
process.storeView(nextView);
process.closingView.applyTransitions(View_1.default.PAUSED, false, STACK_DIRECTION.REMOVE);
resolve(this.closeView(process, process.closingView, closeTransition, false, false)
.then(() => {
process.closingView.destroy();
Runtime_1.default.instance.face.paused = false;
this.updateAttentionMode(nextView);
nextView.pause(false);
return nextView;
}));
}
else {
process.closingView = process.currentView;
process.currentView = nextView = this.popViewFromStack();
process.storeView(process.closingView);
process.storeView(nextView);
this.prepareTransitions(nextView, process.closingView, STACK_DIRECTION.REMOVE);
resolve(this.closeAndOpenViews(process, nextView, process.closingView, openTransition, closeTransition, false));
}
}
}
}
else {
if (leaveEmpty) {
resolve(null);
}
else if (nextView) {
process.currentView = nextView;
process.storeView(nextView);
nextView.applyTransitions(View_1.default.EMPTY, true, STACK_DIRECTION.ADD);
resolve(this.openView(process, nextView, openTransition));
}
else {
process.currentView = nextView = this.popViewFromStack();
process.storeView(nextView);
nextView.applyTransitions(View_1.default.EMPTY, true, STACK_DIRECTION.REMOVE);
resolve(this.openView(process, nextView, openTransition));
}
}
});
}
removeToRoot(process, nextView, leaveEmpty = false, closeTransition = TRANSITION.DOWN, openTransition = TRANSITION.DOWN) {
return new Promise((resolve, reject) => {
if (process.currentView) {
if (this.viewStackLength === 1) {
if (leaveEmpty) {
process.closingView = process.currentView;
process.currentView = null;
process.storeView(process.closingView);
process.closingView.applyTransitions(View_1.default.EMPTY, false, STACK_DIRECTION.REMOVE);
resolve(this.closeView(process, process.closingView, closeTransition, true));
}
else if (nextView) {
process.closingView = process.currentView;
process.currentView = nextView;
process.storeView(process.closingView);
this.prepareTransitions(nextView, process.closingView, STACK_DIRECTION.ADD);
resolve(this.closeAndOpenViews(process, nextView, process.closingView, openTransition, closeTransition, true));
}
else {
resolve(process.currentView);
}
}
else {
if (leaveEmpty) {
process.closingView = process.currentView;
process.currentView = null;
process.storeView(process.closingView);
resolve(this.closeViewWithPaused(process, process.closingView, closeTransition)
.then(() => {
this.clearViewStack(null);
return (null);
}));
}
else if (nextView) {
process.closingView = process.currentView;
process.currentView = nextView;
process.storeView(process.closingView);
this.clearViewStack(null);
resolve(this.closeWithPausedAndOpenViews(process, nextView, process.closingView, openTransition, closeTransition, false, STACK_DIRECTION.SWAP));
}
else {
process.closingView = process.currentView;
process.storeView(process.closingView);
this.clearViewStack(null);
process.currentView = nextView = this.popViewFromStack();
process.storeView(nextView);
resolve(this.closeWithPausedAndOpenViews(process, nextView, process.closingView, openTransition, closeTransition, false, STACK_DIRECTION.REMOVE));
}
}
}
else {
if (leaveEmpty) {
this.clearViewStack(null);
resolve(null);
}
else if (nextView) {
process.currentView = nextView;
this.clearViewStack(null);
resolve(this.openView(process, nextView, openTransition));
}
else {
this.clearViewStack(null);
process.currentView = nextView = this.popViewFromStack();
process.storeView(nextView);
resolve(this.openView(process, nextView, openTransition));
}
}
});
}
removeTo(process, viewId, includeId = false, nextView, pauseOptions, leaveEmpty = false, closeTransition = TRANSITION.DOWN, openTransition = TRANSITION.DOWN) {
return new Promise((resolve, reject) => {
if (process.currentView) {
if (process.currentView.id === viewId) {
if (includeId) {
resolve(this.remove(process, nextView, leaveEmpty, closeTransition, openTransition));
}
else {
if (nextView) {
resolve(this.add(process, nextView, pauseOptions, openTransition));
}
else {
resolve(process.currentView);
}
}
}
else {
let found = false;
let index = 0;
let pausedParent = process.currentView.pausedParent;
while (pausedParent) {
index++;
if (pausedParent.id === viewId) {
found = true;
break;
}
pausedParent = pausedParent.pausedParent;
}
if (found) {
if (includeId) {
index++;
}
let closingViews = [];
let pausedView = process.currentView;
while (index > 0 && pausedView) {
closingViews.unshift(pausedView);
pausedView.applyTransitions(View_1.default.PAUSED, false, STACK_DIRECTION.REMOVE);
index--;
if (pausedView.pausedParent) {
pausedView = pausedView.pausedParent;
}
else {
break;
}
}
process.closingView = process.currentView;
process.storeView(process.closingView);
if (!nextView) {
process.currentView = pausedView;
process.storeView(pausedView);
}
this.closeGroup(process, closingViews, closeTransition, false, false)
.then(() => {
if (leaveEmpty) {
if (pausedView) {
for (let i = closingViews.length - 1; i >= 0; i--) {
closingViews[i].destroy();
}
Runtime_1.default.instance.face.paused = false;
this.updateAttentionMode(pausedView);
pausedView.pause(false);
}
else {
for (let i = closingViews.length - 1; i >= 0; i--) {
closingViews[i].destroy();
}
}
resolve(pausedView);
}
else if (nextView) {
for (let i = closingViews.length - 1; i >= 0; i--) {
closingViews[i].destroy();
}
nextView.pausedParent = pausedView;
nextView.applyTransitions(View_1.default.PAUSED, true, STACK_DIRECTION.SWAP);
resolve(this.openView(process, nextView, openTransition));
}
else {
if (pausedView) {
for (let i = closingViews.length - 1; i >= 0; i--) {
closingViews[i].destroy();
}
Runtime_1.default.instance.face.paused = false;
this.updateAttentionMode(pausedView);
pausedView.pause(false);
resolve(pausedView);
}
else {
for (let i = closingViews.length - 1; i >= 0; i--) {
closingViews[i].destroy();
}
throw (new Error('Error removing to paused view'));
}
}
});
}
else {
index = 0;
for (let i = this._viewStates.length - 1; i >= 0; i--) {
if (this._viewStates[i].id === viewId) {
found = true;
break;
}
index++;
}
if (found) {
if (includeId) {
index++;
}
while (index > 0) {
this.popViewFromStack();
index--;
}
process.closingView = process.currentView;
process.storeView(process.closingView);
if (!leaveEmpty) {
if (!nextView) {
nextView = this.popViewFromStack();
process.storeView(nextView);
}
process.currentView = nextView;
}
if (leaveEmpty) {
resolve(this.closeViewWithPaused(process, process.closingView, closeTransition));
}
else {
resolve(this.closeWithPausedAndOpenViews(process, nextView, process.closingView, openTransition, closeTransition, false, STACK_DIRECTION.REMOVE));
}
}
else {
reject(new Error('Corresponding view not found for id:' + viewId));
}
}
}
}
else {
let stackFound = false;
let stackIndex = 0;
for (let i = this._viewStates.length - 1; i >= 0; i--) {
stackIndex++;
if (this._viewStates[i].id === viewId) {
stackFound = true;
break;
}
}
if (stackFound) {
if (includeId) {
stackIndex++;
}
for (let i = 0; i < stackIndex; i++) {
this._viewStates.pop();
}
if (leaveEmpty) {
resolve(null);
}
else {
if (!nextView) {
nextView = this.popViewFromStack();
}
resolve(this.add(process, nextView, null, openTransition, closeTransition));
}
}
else {
reject(new Error('Corresponding view not found for id:' + viewId));
}
}
});
}
openView(process, view, openTransition) {
return new Promise((resolve, reject) => {
view.once(View_1.STATE.LOAD_ERROR, () => {
reject(new Error('View load error'));
});
view.once(View_1.STATE.DATA_LOADED, () => {
if (process.interrupted) {
return reject(new Error('View process interruption'));
}
view.once(View_1.STATE.LOADED, () => {
if (process.interrupted) {
return reject(new Error('View process interruption'));
}
view.removeAllListeners(View_1.STATE.LOAD_ERROR);
const proceed = () => {
if (process.interrupted) {
return reject(new Error('View process interruption'));
}
view.once(View_1.STATE.OPENED, (openedView) => {
if (process.interrupted) {
return reject(new Error('View process interruption'));
}
openedView.pause(false);
resolve(openedView);
});
Runtime_1.default.instance.face.paused = false;
this.stage.addChild(view.stage);
this.updateAttentionMode(view);
view.open(null, openTransition);
};
if (process.onLoaded) {
if (process.onLoaded.length > 1) {
process.onLoaded(view, proceed);
}
else {
process.onLoaded(view);
proceed();
}
}
else {
proceed();
}
});
view.loadAssets();
});
view.init(this, false);
});
}
closeView(process, view, closeTransition, addToStack = false, destroyView = true, toPaused = false) {
return new Promise((resolve, reject) => {
if (!view.inputLocked) {
view.lockInput(true);
}
view.once(View_1.STATE.CLOSED, (closedView) => {
if (process.interrupted) {
return reject(new Error('View process interruption'));
}
if (addToStack) {
this.pushViewToStack(view);
}
Runtime_1.default.instance.face.paused = true;
if (destroyView) {
closedView.destroy();
}
resolve(null);
});
view.close(null, closeTransition);
});
}
closeAndOpenViews(process, nextView, closeView, openTransition, closeTransition, addToStack = false) {
return new Promise((resolve, reject) => {
let interrupted = false;
let proceedCount = 2;
const proceed = () => {
if (process.interrupted) {
if (!interrupted) {
interrupted = true;
reject(new Error('View process interruption'));
}
return;
}
proceedCount--;
if (proceedCount === 0) {
if (!this.checkViewsValid([closeView, nextView])) {
if (!interrupted) {
interrupted = true;
reject(new Error('View process involves invalid views'));
}
return;
}
closeView.destroyAll();
nextView.once(View_1.STATE.OPENED, () => {
if (process.interrupted) {
if (!interrupted) {
interrupted = true;
reject(new Error('View process interruption'));
}
return;
}
nextView.pause(false);
resolve(nextView);
});
Runtime_1.default.instance.face.paused = false;
this.stage.addChild(nextView.stage);
this.updateAttentionMode(nextView);
nextView.open(null, openTransition);
}
};
closeView.once(View_1.STATE.CLOSED, (closedView) => {
if (process.interrupted) {
if (!interrupted) {
interrupted = true;
reject(new Error('View process interruption'));
}
return;
}
if (addToStack) {
this.pushViewWithPausedToStack(closedView);
}
Runtime_1.default.instance.face.paused = true;
proceed();
});
closeView.close(null, closeTransition);
nextView.once(View_1.STATE.LOAD_ERROR, () => {
if (!interrupted) {
interrupted = true;
reject(new Error('View load error'));
}
return;
});
nextView.once(View_1.STATE.DATA_LOADED, () => {
if (process.interrupted) {
if (!interrupted) {
interrupted = true;
reject(new Error('View process interruption'));
}
return;
}
nextView.once(View_1.STATE.LOADED, () => {
if (process.interrupted) {
if (!interrupted) {
interrupted = true;
reject(new Error('View process interruption'));
}
return;
}
nextView.removeAllListeners(View_1.STATE.LOAD_ERROR);
if (process.onLoaded) {
if (process.onLoaded.length > 1) {
process.onLoaded(nextView, proceed);
}
else {
process.onLoaded(nextView);
proceed();
}
}
else {
proceed();
}
});
nextView.loadAssets();
});
nextView.init(this, false);
});
}
closeWithPausedAndOpenViews(process, nextView, closeView, openTransition, closeTransition, addToStack = false, stackDirection) {
return new Promise((resolve, reject) => {
let interrupted = false;
let closingViews = [];
while (closeView) {
closingViews.unshift(closeView);
if (closeView.pausedParent) {
closeView.applyTransitions(View_1.default.PAUSED, false, stackDirection);
closeView = closeView.pausedParent;
}
else {
break;
}
}
if (closingViews.length > 1) {
closeView.applyTransitions(View_1.default.PAUSED, false, stackDirection);
nextView.applyTransitions(View_1.default.PAUSED, true, stackDirection);
}
else {
closeView.applyTransitions(nextView, false, stackDirection);
nextView.applyTransitions(closeView, true, stackDirection);
}
let proceedCount = 2;
const proceed = () => {
if (process.interrupted) {
if (!interrupted) {
interrupted = true;
reject(new Error('View process interruption'));
}
return;
}
proceedCount--;
if (proceedCount === 0) {
if (!this.checkViewsValid(closingViews) || !this.checkViewsValid(nextView)) {
if (!interrupted) {
interrupted = true;
reject(new Error('View process involves invalid views'));
}
return;
}
for (let i = 0; i < closingViews.length; i++) {
closingViews[i].destroy();
}
nextView.once(View_1.STATE.OPENED, (nextView) => {
if (process.interrupted) {
if (!interrupted) {
interrupted = true;
reject(new Error('View process interruption'));
}
return;
}
nextView.pause(false);
resolve(nextView);
});
Runtime_1.default.instance.face.paused = false;
this.stage.addChild(nextView.stage);
this.updateAttentionMode(nextView);
nextView.open(null, openTransition);
}
};
this.closeGroup(process, closingViews, closeTransition, addToStack, false)
.then(() => {
proceed();
})
.catch(() => {
if (!interrupted) {
interrupted = true;
reject(new Error('View load error'));
}
});
nextView.once(View_1.STATE.LOAD_ERROR, () => {
if (!interrupted) {
interrupted = true;
reject(new Error('View load error'));
}
});
nextView.once(View_1.STATE.DATA_LOADED, () => {
if (process.interrupted) {
if (!interrupted) {
interrupted = true;
reject(new Error('View process interruption'));
}
return;
}
nextView.once(View_1.STATE.LOADED, () => {
if (process.interrupted) {
if (!interrupted) {
interrupted = true;
reject(new Error('View process interruption'));
}
return;
}
nextView.removeAllListeners(View_1.STATE.LOAD_ERROR);
if (process.onLoaded) {
if (process.onLoaded.length > 1) {
process.onLoaded(nextView, proceed);
}
else {
process.onLoaded(nextView);
proceed();
}
}
else {
proceed();
}
});
nextView.loadAssets();
});
nextView.init(this, false);
});
}
closePaused(process, view, closeTransition, addToStack = false, destroyViews = true) {
return new Promise((resolve, reject) => {
if (view.pausedParent) {
this.closeViewWithPaused(process, view.pausedParent, closeTransition, addToStack, destroyViews)
.then(() => {
view.pausedParent = null;
Runtime_1.default.instance.face.paused = false;
resolve();
})
.catch((err) => {
reject(err);
});
}
else {
resolve();
}
});
}
closeViewWithPaused(process, view, closeTransition, addToStack = false, destroyViews = true) {
let closingViews = [];
while (view) {
closingViews.unshift(view);
view.applyTransitions(View_1.default.PAUSED, false, STACK_DIRECTION.REMOVE);
view = view.pausedParent;
}
return this.closeGroup(process, closingViews, closeTransition, addToStack, destroyViews);
}
closeGroup(process, closingViews, closeTransition, addToStack = false, destroyViews = true) {
return new Promise((resolve, reject) => {
let closeTransitions = [];
for (let i = 0; i < closingViews.length; i++) {
closeTransitions.push(function (subCallback) {
closingViews[i].close(subCallback, closeTransition);
});
}
async.parallel(closeTransitions, function (err, results) {
closeTransitions = null;
if (process.interrupted) {
return reject(new Error('View process interruption'));
}
if (err) {
log.warn('closeAllPaused() issue during transition: error: ', err);
closingViews = null;
return reject(new Error('Async view close error'));
}
Runtime_1.default.instance.face.paused = true;
for (let i = 0; i < closingViews.length; i++) {
if (addToStack) {
this.pushViewToStack(closingViews[i]);
}
if (destroyViews) {
closingViews[i].destroy();
}
}
closingViews = null;
resolve(null);
}.bind(this));
});
}
pauseThenOpen(process, nextView, pausingView, pauseOptions, openTransition) {
return new Promise((resolve, reject) => {
nextView.once(View_1.STATE.LOAD_ERROR, () => {
reject(new Error('View load error'));
});
pausingView.lockInput(true);
nextView.pausedParent = pausingView;
nextView.once(View_1.STATE.DATA_LOADED, () => {
if (process.interrupted) {
return reject(new Error('View process interruption'));
}
nextView.once(View_1.STATE.LOADED, () => {
if (process.interrupted) {
return reject(new Error('View process interruption'));
}
nextView.removeAllListeners(View_1.STATE.LOAD_ERROR);
const proceed = () => {
nextView.once(View_1.STATE.OPENED, (nextView) => {
if (process.interrupted) {
return reject(new Error('View process interruption'));
}
nextView.pause(false);
resolve(nextView);
});
Runtime_1.default.instance.face.paused = false;
pausingView.pause(true, (pauseOptions || nextView.pauseOptions));
this.stage.addChild(nextView.stage);
this.updateAttentionMode(nextView);
nextView.open(null, openTransition);
};
if (process.onLoaded) {
if (process.onLoaded.length > 1) {
process.onLoaded(nextView, proceed);
}
else {
process.onLoaded(nextView);
proceed();
}
}
else {
proceed();
}
});
nextView.loadAssets();
});
nextView.init(this, false);
});
}
prepareTransitions(openingView, closingView, stackDirection) {
if (openingView) {
openingView.applyTransitions(closingView, true, stackDirection);
}
if (closingView) {
closingView.applyTransitions(openingView, false, stackDirection);
}
}
popViewFromStack() {
if (this._viewStates.length > 0) {
const state = this._viewStates.pop();
return this._creator.createViewFromState(state);
}
else {
log.warn('popViewFromStack() stack is empty, creating an eye by default, not ideal.');
return this.createView(EyeView_1.default.DEFAULT_TYPE);
}
}
pushViewToStack(view) {
if (!view.viewStateStacked && (view.state === View_1.STATE.LOADED || view.state === View_1.STATE.OPENED || view.state === View_1.STATE.CLOSED)) {
const state = view.createState();
view.viewStateStacked = true;
this._viewStates.push(state);
}
else {
log.warn('pushViewToStack() View not ready to be added to stack beause state is: ' + view.state);
}
}
pushViewWithPausedToStack(view) {
if (view.pausedParent) {
const closingViews = [];
let pausedView = view.pausedParent;
while (pausedView) {
closingViews.unshift(pausedView);
pausedView = pausedView.pausedParent;
}
for (let i = 0; i < closingViews.length; i++) {
this.pushViewToStack(closingViews[i]);
}
}
this.pushViewToStack(view);
}
clearViewStack(currentView) {
if (this._viewStates.length === 0 && !currentView) {
this._viewStates.push(this._creator.createViewState(EyeView_1.default.DEFAULT_TYPE));
}
if (this._viewStates.length > 0) {
this._viewStates.length = (currentView && currentView.type === EyeView_1.default.DEFAULT_TYPE) ? 0 : 1;
}
}
updateAttentionMode(view) {
if (view && view.category === View_1.CATEGORY.GUI) {
if (this._menuMode) {
this._menuMode.release();
this._menuMode = null;
}
const expression = Runtime_1.default.instance.expression;
let mode = expression.AttentionMode.MENU;
if (this._disableMovement) {
mode = expression.AttentionMode.OFF;
}
expression.pushAttentionMode(mode).then((handle) => {
this._menuMode = handle;
}).catch(() => {
});
}
else if (this._menuMode) {
this._menuMode.release();
this._menuMode = null;
if (view && view.category !== View_1.CATEGORY.GUI) {
this._disableMovement = false;
}
}
}
setTextureGC(autoOn, currentView) {
if (autoOn) {
if ((this.viewStackLength === 1) && (currentView && currentView.category === View_1.CATEGORY.EYE)) {
Runtime_1.default.instance.face.textureGC.mode = PIXI.GC_MODES.AUTO;
return;
}
}
Runtime_1.default.instance.face.textureGC.mode = PIXI.GC_MODES.MANUAL;
}
createBorder(cornerTexture, edgeTexture) {
const border = new PIXI.Container();
this.stage.parent.addChildAt(border, this.stage.parent.getChildIndex(this.stage) + 1);
let corner = new PIXI.Sprite(cornerTexture);
border.addChild(corner);
corner = new PIXI.Sprite(cornerTexture);
corner.scale.x = -1;
corner.x = FaceRenderer_1.default.WIDTH;
border.addChild(corner);
corner = new PIXI.Sprite(cornerTexture);
corner.scale.y = -1;
corner.y = FaceRenderer_1.default.HEIGHT;
border.addChild(corner);
corner = new PIXI.Sprite(cornerTexture);
corner.scale.x = -1;
corner.scale.y = -1;
corner.x = FaceRenderer_1.default.WIDTH;
corner.y = FaceRenderer_1.default.HEIGHT;
border.addChild(corner);
const cornerW = corner.width;
const edgeW = FaceRenderer_1.default.WIDTH - cornerW * 2;
const edgeH = FaceRenderer_1.default.HEIGHT - cornerW * 2;
let edge = new PIXI.Sprite(edgeTexture);
edge.height = edgeH;
edge.y = cornerW;
border.addChild(edge);
edge = new PIXI.Sprite(edgeTexture);
edge.height = edgeH;
edge.scale.x = -1;
edge.x = FaceRenderer_1.default.WIDTH;
edge.y = cornerW;
border.addChild(edge);
edge = new PIXI.Sprite(edgeTexture);
edge.scale.y = -1;
edge.rotation = Math.PI / 2;
edge.height = edgeW;
edge.x = cornerW;
border.addChild(edge);
edge = new PIXI.Sprite(edgeTexture);
edge.rotation = Math.PI * 1.5;
edge.height = edgeW;
edge.x = cornerW;
edge.y = FaceRenderer_1.default.HEIGHT;
border.addChild(edge);
this._border = border;
this._border.visible = this._borderVisibility;
}
registerDefaults() {
this._creator.registerClass(View_1.default);
this._creator.registerClass(EyeView_1.default);
this._creator.registerClass(MenuView_1.default);
this._creator.registerClass(ImageView_1.default);
this._creator.registerClass(ContactsView_1.default);
this._creator.registerClass(TextView_1.default);
this._creator.registerClass(Button_1.default);
this._creator.registerClass(StandardButton_1.default);
this._creator.registerClass(ElementGroup_1.default);
this._creator.registerClass(Label_1.default);
this._creator.registerClass(List_1.default);
this._creator.registerClass(Clip_1.default);
this._creator.registerClass(MenuButton_1.default, MenuButton_1.default.SKILL);
this._creator.registerClass(MenuButton_1.default, MenuButton_1.default.ACTION);
this._creator.registerClass(MenuButton_1.default, MenuButton_1.default.ACTION_BIG);
this._creator.registerClass(ContactButton_1.default);
this._creator.registerClass(ContentButton_1.default);
}
checkViewsValid(views) {
if (views) {
if (Array.isArray(views)) {
for (let i = 0; i < views.length; i++) {
if (views[i].state === View_1.STATE.DESTROYED) {
return false;
}
}
}
else {
return views.state !== View_1.STATE.DESTROYED;
}
return true;
}
return false;
}
logEvents() {
this.events.process.removeAllListeners();
this.events.view.removeAllListeners();
this.events.process.on((data) => {
log.info('View process:', data);
});
this.events.view.on((data) => {
log.info('View status:', data);
});
}
}
ViewManager._transTime = DEFAULT_TRANS_TIME;
exports.default = ViewManager;
},{"../../Runtime":1,"../../bt/mim/MimManager":52,"../FaceRenderer":99,"./Component":121,"./ComponentCreator":122,"./ComponentGroup":123,"./TouchManager":125,"./ViewGlobalEvents":126,"./ViewProcess":128,"./ViewState":129,"./actions/ActionData":130,"./components/Button":132,"./components/Clip":133,"./components/ContactButton":134,"./components/ContentButton":135,"./components/Element":136,"./components/ElementGroup":137,"./components/Label":138,"./components/List":139,"./components/MenuButton":141,"./components/StandardButton":142,"./log":149,"./views/ContactsView":150,"./views/EyeView":151,"./views/ImageView":152,"./views/MenuView":153,"./views/TextView":155,"./views/View":156,"async":undefined}],128:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const View_1 = require("./views/View");
const log_1 = require("./log");
const log = log_1.default.createChild('ViewProcess');
class ViewProcess {
constructor() {
this.changeOptions = null;
this.onComplete = null;
this.onFailure = null;
this.onLoaded = null;
this.processQueue = [];
this.status = '';
this._active = false;
this._activeViews = [];
this._currentView = null;
this._closingView = null;
this._interrupted = false;
}
static get QUEUED() { return 'queued'; }
static get STARTED() { return 'started'; }
static get COMPLETED() { return 'completed'; }
static get INTERRUPTED() { return 'interrupted'; }
static get FAILED() { return 'failed'; }
get active() { return this._active; }
get currentView() {
return this._currentView;
}
set currentView(view) {
this._currentView = view;
}
get closingView() {
return this._closingView;
}
set closingView(view) {
this._closingView = view;
}
get interrupted() {
return this._interrupted;
}
static serializeOptions(options) {
let serialised = {};
let value;
Object.keys(options).forEach((key) => {
value = options[key];
if (typeof value === 'string' || typeof value === 'boolean') {
serialised[key] = value;
}
else if (key === 'addView') {
serialised.addView = `id: ${value.id} type: ${value.type}`;
}
else {
try {
serialised[key] = JSON.parse(JSON.stringify(value));
}
catch (e) {
}
}
});
return serialised;
}
start(onComplete, onFailure, onLoaded, changeOptions) {
this.clear();
this._active = true;
this._interrupted = false;
this.onComplete = onComplete;
this.onFailure = onFailure;
this.onLoaded = onLoaded;
this.changeOptions = changeOptions;
this.status = ViewProcess.STARTED;
}
storeView(view) {
if (view) {
this._activeViews.push(view);
}
else {
log.info('storeView() given undefined view');
}
}
complete(view) {
if (this._active && !this._interrupted) {
this._active = false;
this._closingView = null;
this.changeOptions = null;
this.onFailure = null;
this.onLoaded = null;
this._activeViews.length = 0;
this.status = ViewProcess.COMPLETED;
if (this.onComplete) {
let callback = this.onComplete;
this.onComplete = null;
callback(view);
callback = null;
}
}
else {
log.warn('complete() called but active:' + this._active + ' and interrupted: ' + this._interrupted);
this.clear();
}
}
fail(retainCurrent = false) {
this._active = false;
this.onComplete = null;
this.onLoaded = null;
this.changeOptions = null;
let view;
for (let i = 0; i < this._activeViews.length; i++) {
view = this._activeViews[i];
if (view.state !== View_1.STATE.DESTROYED) {
if (!retainCurrent || view !== this._currentView) {
view.destroyAll();
}
}
}
this._activeViews.length = 0;
this.status = ViewProcess.FAILED;
if (this._currentView) {
if (!retainCurrent) {
if (this._currentView.state === View_1.STATE.DESTROYED) {
this._currentView = null;
}
else {
log.warn('fail() currentView was not yet destroyed, is should have been');
}
}
else {
this._currentView.transitionHandler = null;
}
}
if (this._closingView) {
if (this._closingView.state === View_1.STATE.DESTROYED) {
this._closingView = null;
}
else {
log.warn('fail() closingView was not yet destroyed, is should have been');
}
}
if (this.onFailure) {
let callback = this.onFailure;
this.onFailure = null;
callback();
callback = null;
}
}
interrupt(changeOptions) {
if (this._active) {
log.info('View change interruption : ', ViewProcess.serializeOptions(changeOptions), ' interrupting ', ViewProcess.serializeOptions(this.changeOptions), ', interruption should be avoided.');
this._interrupted = true;
this.status = ViewProcess.INTERRUPTED;
return true;
}
return false;
}
addProcessToQueue(changeOptions, onComplete, onFailure, onLoaded) {
const viewProcess = new ViewProcess();
viewProcess.changeOptions = changeOptions;
viewProcess.onComplete = onComplete;
viewProcess.onFailure = onFailure;
viewProcess.onLoaded = onLoaded;
viewProcess.status = ViewProcess.QUEUED;
this.processQueue.push(viewProcess);
}
reset() {
if (this._active) {
log.info('View change interruption : due to reset, interrupting ', ViewProcess.serializeOptions(this.changeOptions));
this._interrupted = true;
this.status = ViewProcess.INTERRUPTED;
}
let view;
for (let i = 0; i < this._activeViews.length; i++) {
view = this._activeViews[i];
if (view.state !== View_1.STATE.DESTROYED) {
view.destroy();
}
}
if (this._currentView && this._currentView.state !== View_1.STATE.DESTROYED) {
this._currentView.destroyAll();
}
if (this._closingView && this._closingView.state !== View_1.STATE.DESTROYED) {
this._closingView.destroyAll();
}
this._currentView = null;
this._closingView = null;
this.clear();
}
clear() {
this._active = false;
this.onComplete = null;
this.onFailure = null;
this.onLoaded = null;
this._activeViews.length = 0;
this.changeOptions = null;
}
}
exports.default = ViewProcess;
},{"./log":149,"./views/View":156}],129:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class ViewState {
constructor(viewClassName = 'View', config) {
this.id = '';
this.configPath = '';
this.viewClassName = '';
this.viewConfig = null;
this.pauseParent = false;
this.ignoreSwipeDown = false;
if (viewClassName) {
this.viewClassName = viewClassName;
}
if (config) {
this.applyConfig(config);
}
}
applyConfig(config) {
if (config) {
if (config.hasOwnProperty('viewConfig')) {
this.viewConfig = config.viewConfig;
if (this.viewConfig.hasOwnProperty('type')) {
this.viewClassName = this.viewConfig.type;
}
if (this.viewConfig.hasOwnProperty('id')) {
this.id = this.viewConfig.id;
}
}
if (config.hasOwnProperty('componentConfigs')) {
this.componentConfigs = config.componentConfigs;
}
}
}
}
exports.default = ViewState;
},{}],130:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class ActionData {
constructor(type, data) {
this.type = "";
this.data = null;
this.type = type;
this.data = data;
}
static get CHANGE_VIEW() { return "changeView"; }
static get OPEN_VIEW() { return "openView"; }
static get CLOSE_VIEW() { return "closeView"; }
static get CLOSE_VIEW_EMPTY() { return "closeViewEmpty"; }
static get CLOSE_ALL() { return "closeAll"; }
static get CLOSE_ALL_OPEN() { return "closeAllOpen"; }
static get CLOSE_ALL_EMPTY() { return "closeAllEmpty"; }
static get SWIPE_RIGHT() { return "swipeRight"; }
static get SWIPE_LEFT() { return "swipeLeft"; }
static get SWIPE_DOWN() { return "swipeDown"; }
static get SWIPE_UP() { return "swipeUp"; }
static get GO_TO_BEGINNING() { return "goToBeginning"; }
static get GO_TO_END() { return "goToEnd"; }
static get EVENT() { return "event"; }
static get SOUND() { return "sound"; }
static get UTTERANCE() { return "utterance"; }
static get VERBAL_COMMAND() { return "verbalCommand"; }
static get MIM_END() { return "mimEnd"; }
static get MIM_SHOW_GUI() { return "mimShowGUI"; }
static get CALLBACK() { return "callback"; }
static createFromConfig(configData) {
let actionData = new ActionData();
actionData.applyConfig(configData);
return actionData;
}
applyConfig(configData) {
if (configData.hasOwnProperty("type")) {
this.type = configData.type;
}
if (configData.hasOwnProperty("data")) {
this.data = configData.data;
}
}
}
exports.default = ActionData;
},{}],131:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ActionData_1 = require("./ActionData");
exports.default = {
ActionData: ActionData_1.default
};
},{"./ActionData":130}],132:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Element_1 = require("./Element");
const TouchManager_1 = require("../TouchManager");
const Runtime_1 = require("../../../Runtime");
const animate = require("pixi-animate");
const log_1 = require("./log");
const log = log_1.default.createChild('Button');
class Button extends Element_1.default {
constructor() {
super();
this.timeline = null;
this._type = Button.DEFAULT_TYPE;
this.isDown = false;
this.interactable = true;
}
static get DEFAULT_TYPE() { return 'Button'; }
static createFromConfig(configData) {
let btn = new Button();
btn.assignConfig(configData);
return btn;
}
static createFromDisplayObject(displayObject, actionData, container = null) {
let btn = new Button();
btn.display = new PIXI.Container();
if (container) {
container.addChild(btn.display);
}
else if (displayObject.parent) {
displayObject.parent.addChild(btn.display);
}
if (actionData) {
btn.addAction(actionData);
}
btn.setupHitArea();
btn.setupInteractions();
btn.display.addChild(displayObject);
return btn;
}
setupDisplay(assets) {
let asset;
let assetDescriptor;
for (let i = 0; i < this._assetDescriptors.length; i++) {
assetDescriptor = this._assetDescriptors[i];
asset = assets[assetDescriptor.id];
if (assetDescriptor.hasOwnProperty('type')) {
switch (assetDescriptor.type) {
case 'texture':
let sprite = new PIXI.Sprite(asset);
this.display.addChild(sprite);
break;
case 'timeline':
let movieClip = new asset.library.stage();
this.display.addChild(movieClip);
if (assetDescriptor.upload) {
Runtime_1.default.instance.face.plugins.prepare.upload(movieClip);
}
break;
default:
log.debug('setupDisplay() will not setup for asset type: ' + asset.type);
}
}
else {
log.debug('Button :: assignAssets() no type given for asset: ' + asset + ', assuming bitmap');
let sprite = PIXI.Sprite.from(asset);
this.display.addChild(sprite);
}
}
this.setupHitArea();
this.setupInteractions();
}
setupHitArea(bounds) {
if (this.display) {
if (bounds) {
this.display.hitArea = bounds;
}
else if (this._hitArea) {
this.display.hitArea = this._hitArea;
}
else {
bounds = this.display.getBounds();
bounds.x = bounds.y = 0;
this.display.hitArea = bounds;
}
}
}
setupInteractions() {
if (this.display && this.interactable) {
this.display.interactiveChildren = false;
this.display.interactive = !this.inputLocked;
this.display.addListener('mouseout', this.out.bind(this));
this.display.addListener('mousedown', this.down.bind(this));
this.display.addListener('mouseup', this.up.bind(this));
}
}
lockInput(flag) {
super.lockInput(flag);
if (this.interactable && this.display) {
if (flag && this.isDown) {
this.up();
}
}
}
click() {
if (this.timeline) {
animate.Animator.stop(this.timeline);
}
super.triggerActions(TouchManager_1.GESTURE.TAP);
}
out(mouseData) {
if (this.isDown) {
this.isDown = false;
if (this.timeline) {
animate.Animator.play(this.timeline, 'out');
}
}
}
down(mouseData) {
this.isDown = true;
if (this.timeline) {
animate.Animator.play(this.timeline, 'down');
}
}
up(mouseData) {
this.isDown = false;
if (this.timeline) {
animate.Animator.play(this.timeline, 'up');
}
}
activate() {
if (this.timeline) {
animate.Animator.play(this.timeline, 'activate');
}
}
destroy() {
if (this.display) {
this.display.removeAllListeners('mouseout');
this.display.removeAllListeners('mousedown');
this.display.removeAllListeners('mouseup');
this.display.removeAllListeners('click');
}
this.timeline = null;
super.destroy();
}
}
exports.default = Button;
},{"../../../Runtime":1,"../TouchManager":125,"./Element":136,"./log":144,"pixi-animate":undefined}],133:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Element_1 = require("./Element");
const Runtime_1 = require("../../../Runtime");
const log_1 = require("./log");
const log = log_1.default.createChild('Clip');
class Clip extends Element_1.default {
constructor() {
super(...arguments);
this.timeline = null;
this.movieClip = null;
this._type = Clip.DEFAULT_TYPE;
}
static get DEFAULT_TYPE() { return 'Clip'; }
static createFromConfig(configData) {
const clip = new Clip();
clip.assignConfig(configData);
return clip;
}
static createFromDisplayObject(displayObject, container) {
const clip = new Clip();
clip.display = new PIXI.Container();
if (container) {
container.addChild(clip.display);
}
else if (displayObject.parent) {
displayObject.parent.addChild(clip.display);
}
clip.display.addChild(displayObject);
return clip;
}
setupDisplay(assets) {
let asset;
let assetDescriptor;
if (this._assetDescriptors) {
for (let i = 0; i < this._assetDescriptors.length; i++) {
assetDescriptor = this._assetDescriptors[i];
asset = assets[assetDescriptor.id];
if (asset) {
if (assetDescriptor.hasOwnProperty("type")) {
switch (assetDescriptor.type) {
case "texture":
this.display.addChild(new PIXI.Sprite(asset));
break;
case "timeline":
this.timeline = asset;
if (this.timeline) {
this.movieClip = new this.timeline.library.stage();
this.display.addChild(this.movieClip);
if (assetDescriptor.upload) {
Runtime_1.default.instance.face.plugins.prepare.upload(this.movieClip);
}
}
else {
log.warn("setupDisplay() invaid timeline asset given", asset);
}
break;
default:
break;
}
}
else {
log.warn('setupDisplay() : no type given for asset: ' + asset + ' of id: ' + assetDescriptor.id + ', assuming bitmap');
let sprite = PIXI.Sprite.from(asset);
this.display.addChild(sprite);
}
}
else {
log.warn("setupDisplay() : no asset found with id: " + assetDescriptor.id);
}
}
}
}
destroy() {
this.movieClip = null;
this.timeline = null;
super.destroy();
}
}
exports.default = Clip;
},{"../../../Runtime":1,"./Element":136,"./log":144}],134:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MenuButton_1 = require("./MenuButton");
const Label_1 = require("./Label");
const ActionData_1 = require("../actions/ActionData");
const Runtime_1 = require("../../../Runtime");
const animate = require("pixi-animate");
const log_1 = require("./log");
const log = log_1.default.createChild('Contactsbutton');
class ContactButton extends MenuButton_1.default {
constructor() {
super();
this._type = ContactButton.DEFAULT_TYPE;
this._looper = null;
this.colors = [0xbac5c9, 0x434d55];
super.addButtonData(ContactButton.DEFAULT_TYPE, 'core://resources/buttons/contactButton.js', { width: 330, height: 330 });
this.toggleAnimate = this.animateToggleState;
}
static get DEFAULT_TYPE() { return 'ContactButton'; }
get looper() { return this._looper; }
static createFromConfig(configData) {
let btn = new ContactButton();
btn.assignConfig(configData);
return btn;
}
applyButtonType(type) {
super.applyButtonType(type);
if (this._looper) {
const photoAsset = this._looper.getAssets('photo')[0];
if (photoAsset) {
const url = photoAsset.fullFilenameOrURL();
if (url) {
super.addAssetDescriptor(this._looper.id, url, 'texture');
}
}
}
}
destroy() {
this._looper = null;
super.destroy();
}
assignLooper(looper) {
this._looper = looper;
this.label = looper.getWrittenName();
this.id = looper.id;
this.addAction(ActionData_1.default.UTTERANCE, {
utterance: {
intent: 'loopmember',
entities: {
loopMemberReferent: looper.id
}
}
});
}
setupTimeline(assets) {
if (assets.hasOwnProperty(this.timelineId)) {
let movieClip = new assets[this.timelineId].library.stage();
this._content = movieClip['content'];
const imageContainer = this._content['icon'];
const photoTexture = this._assets[this._looper.id];
if (photoTexture) {
const photoSprite = new PIXI.Sprite(photoTexture);
photoSprite.width = this._dimensions.width;
photoSprite.height = this._dimensions.height;
photoSprite.anchor.x = photoSprite.anchor.y = .5;
photoSprite.setParent(imageContainer);
this._content['background'].visible = false;
this._content['gradient'].visible = false;
this._content['border'].visible = false;
}
else {
if (this.colors) {
this._content['background'].children[0].tint = this.colors[0];
this._content['gradient'].children[0].tint = this.colors[1];
}
const initialText = new PIXI.Text(this._looper.getInitials(), Label_1.default.createFontStyle(135, 'Proxima Nova Soft', '#FFFFFF', 'bold'));
initialText.anchor.x = initialText.anchor.y = .5;
imageContainer.addChild(initialText);
}
this.display.addChild(movieClip);
Runtime_1.default.instance.face.plugins.prepare.upload(movieClip);
this.toggleAnimate(false, false);
}
else {
log.warn('createDisplay() timeline not found in assets');
}
}
toggleDownTransition() {
}
click() {
if (this.willToggle) {
this.toggle(!this.toggledOn, true);
}
super.click();
}
animateToggleState(toggleOn = false, shouldAnimate = true) {
if (this._content) {
const checkClip = this._content['check'];
if (checkClip) {
let label = toggleOn ? 'check_open' : 'check_close';
if (shouldAnimate) {
animate.Animator.play(checkClip, label);
}
else {
checkClip.gotoAndStop(label + '_stop');
}
}
}
}
}
exports.default = ContactButton;
},{"../../../Runtime":1,"../actions/ActionData":130,"./Label":138,"./MenuButton":141,"./log":144,"pixi-animate":undefined}],135:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MenuButton_1 = require("./MenuButton");
const Runtime_1 = require("../../../Runtime");
const log_1 = require("./log");
const log = log_1.default.createChild('ContentButton');
class ContentButton extends MenuButton_1.default {
constructor() {
super();
this._type = ContentButton.DEFAULT_TYPE;
super.addButtonData(ContentButton.DEFAULT_TYPE, 'core://resources/buttons/contentButton.js', { width: 330, height: 330 });
}
static get DEFAULT_TYPE() { return 'ContentButton'; }
static createFromConfig(configData) {
let btn = new ContentButton();
btn.assignConfig(configData);
return btn;
}
assignConfig(configData) {
super.assignConfig(configData);
this._isVideo = !!configData.isVideo;
this._albumInfo = configData.albumInfo;
}
destroy() {
super.destroy();
}
setupTimeline(assets) {
if (assets.hasOwnProperty(this.timelineId)) {
const movieClip = new assets[this.timelineId].library.stage();
const sprite = new PIXI.Sprite();
sprite.texture = assets[this.iconId];
const content = this._content = movieClip['content'];
content.target.addChild(sprite);
this.display.addChild(movieClip);
Runtime_1.default.instance.face.plugins.prepare.upload(movieClip);
}
else {
log.warn('createDisplay() timeline not found in assets');
}
}
}
exports.default = ContentButton;
},{"../../../Runtime":1,"./MenuButton":141,"./log":144}],136:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Component_1 = require("../Component");
const TweenManager_1 = require("../../tween/TweenManager");
const FaceRenderer_1 = require("../../FaceRenderer");
const ViewManager_1 = require("../ViewManager");
const DisplayUtils_1 = require("../DisplayUtils");
const log_1 = require("./log");
const log = log_1.default.createChild('Element');
class Element extends Component_1.default {
constructor() {
super(...arguments);
this.interactable = false;
this._targetPosition = null;
this._transformData = null;
this._hitArea = null;
this._display = null;
}
static get PARENT_ELEMENT() { return 'parentElement'; }
set display(display) {
display[Element.PARENT_ELEMENT] = this;
this._display = display;
}
get display() {
return this._display;
}
get targetPosition() {
if (!this._targetPosition) {
this._targetPosition = new PIXI.Point();
}
return this._targetPosition;
}
get transformData() {
return this._transformData;
}
set setTransformData(transformData) {
this._transformData = transformData;
}
assignConfig(configData) {
if (configData) {
super.assignConfig(configData);
if (configData.hasOwnProperty('position')) {
this._targetPosition = DisplayUtils_1.default.getElementPosition(configData.position);
}
if (configData.hasOwnProperty('transform')) {
this._transformData = configData.transform;
}
if (configData.hasOwnProperty('hitArea')) {
this._hitArea = new PIXI.Rectangle(Number(configData.hitArea.x), Number(configData.hitArea.y), Number(configData.hitArea.width), Number(configData.hitArea.height));
}
if (configData.hasOwnProperty('interactable')) {
this.interactable = configData.interactable;
}
}
}
updateConfig(configData) {
return configData;
}
update(elapsed) {
log.info("update() : class has not overridden its update, which means update probably shouldn't be getting called on it.");
}
createDisplay(container, assets) {
this._assets = assets;
this.display = new PIXI.Container();
this.setupDisplay(assets);
this.applyPosition();
container.addChild(this._display);
}
setupDisplay(assets) {
}
emptyDisplay() {
this.stopChildTweens();
if (this.display && this.display.children) {
let childDisplay;
for (let i = this.display.children.length - 1; i >= 0; i--) {
childDisplay = this.display.children[i];
if (childDisplay instanceof PIXI.Container) {
childDisplay.destroy({ children: true });
}
else {
childDisplay.destroy();
}
}
}
}
stopChildTweens(includeDisplay = false) {
if (this._display) {
TweenManager_1.default.stopCheck(DisplayUtils_1.default.isContained, this._display);
if (includeDisplay) {
TweenManager_1.default.stop(this._display);
}
}
}
ready() {
}
setTargetPosition(x = 0, y = 0, applyNow = false) {
if (!this._targetPosition) {
this._targetPosition = new PIXI.Point();
}
this._targetPosition.x = x;
this._targetPosition.y = y;
if (applyNow && this._display) {
this._display.x = x;
this._display.y = y;
}
}
applyPosition() {
if (this._display) {
if (this._targetPosition) {
this._display.x = this._targetPosition.x;
this._display.y = this._targetPosition.y;
}
if (this._transformData) {
if (this._transformData.scaleX && this._transformData.scaleY) {
this._display.scale = { x: Number(this._transformData.scaleX), y: Number(this._transformData.scaleY) };
}
if (this._transformData.pivotX && this._transformData.pivotY) {
this._display.pivot = { x: Number(this._transformData.pivotX) * this._display.width, y: Number(this._transformData.pivotY) * this._display.height };
}
if (this.transformData.rotate && this._transformData.rotate !== 0) {
this._display.rotation = this._transformData.rotate * PIXI.DEG_TO_RAD;
this._display.x += this._display.pivot.x;
this._display.y += this._display.pivot.y;
}
}
}
}
open(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'backOut') {
const targetY = this._display.y;
const originY = +targetY + +FaceRenderer_1.default.HEIGHT;
TweenManager_1.default.stop(this._display);
TweenManager_1.default.play(this._display, {
to: { y: targetY },
from: { y: originY },
duration: duration,
ease: tweenType
}, callback);
}
close(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'backIn') {
const targetY = +this._display.y + +FaceRenderer_1.default.HEIGHT;
TweenManager_1.default.stop(this._display);
TweenManager_1.default.play(this._display, {
to: { y: targetY },
duration: duration,
ease: tweenType
}, callback);
}
destroy() {
if (this._display) {
TweenManager_1.default.stop(this._display);
delete this._display['parentElement'];
this._display = null;
}
this._targetPosition = null;
this._transformData = null;
this._hitArea = null;
super.destroy();
}
lockInput(flag) {
super.lockInput(flag);
if (this.interactable && this._display) {
this._display.interactive = !this._inputLocked;
}
}
centerPivot() {
if (this.display) {
const bounds = this.display.getLocalBounds();
const width = bounds.width / 2;
const height = bounds.height / 2;
this.display.pivot.x = width;
this.display.pivot.y = height;
this.display.x += width;
this.display.y += height;
}
}
}
exports.default = Element;
},{"../../FaceRenderer":99,"../../tween/TweenManager":174,"../Component":121,"../DisplayUtils":124,"../ViewManager":127,"./log":144}],137:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ComponentGroup_1 = require("../ComponentGroup");
const TweenManager_1 = require("../../tween/TweenManager");
const FaceRenderer_1 = require("../../FaceRenderer");
const ViewManager_1 = require("../ViewManager");
const DisplayUtils_1 = require("../DisplayUtils");
class ElementGroup extends ComponentGroup_1.default {
constructor() {
super(...arguments);
this.interactable = false;
this._targetPosition = null;
this._display = null;
}
static get DEFAULT_TYPE() {
return 'ElementGroup';
}
static get PARENT_ELEMENT() { return 'parentElement'; }
set display(display) {
display[ElementGroup.PARENT_ELEMENT] = this;
this._display = display;
}
get display() {
return this._display;
}
get targetPosition() {
if (!this._targetPosition) {
this._targetPosition = new PIXI.Point();
}
return this._targetPosition;
}
static createFromConfig(configData) {
let elementGroup = new ElementGroup();
elementGroup.assignConfig(configData);
if (configData.componentConfigs) {
elementGroup.createComponentsFromConfigs(configData.componentConfigs);
}
return elementGroup;
}
assignConfig(configData) {
if (configData) {
super.assignConfig(configData);
if (configData.hasOwnProperty("position")) {
this._targetPosition = DisplayUtils_1.default.getElementPosition(configData.position);
}
if (configData.hasOwnProperty("interactable")) {
this.interactable = configData.interactable;
}
}
}
createDisplay(container, assets) {
this.display = new PIXI.Container();
this.applyPosition();
container.addChild(this.display);
super.createDisplay(this.display, assets);
}
setupDisplay(assets) {
if (this.componentList) {
const length = this.componentList.length;
for (let i = 0; i < length; i++) {
this.componentList[i].setupDisplay(assets);
}
}
}
emptyDisplay() {
this.stopChildTweens();
if (this.componentList) {
const length = this.componentList.length;
for (let i = 0; i < length; i++) {
this.componentList[i].emptyDisplay();
}
}
}
stopChildTweens(includeDisplay = false) {
if (this._display) {
TweenManager_1.default.stopCheck(DisplayUtils_1.default.isContained, this._display);
if (includeDisplay) {
TweenManager_1.default.stop(this._display);
}
}
if (this.componentList) {
const length = this.componentList.length;
for (let i = 0; i < length; i++) {
this.componentList[i].stopChildTweens(includeDisplay);
}
}
}
setTargetPosition(x = 0, y = 0, applyNow = false) {
if (!this._targetPosition) {
this._targetPosition = new PIXI.Point();
}
this._targetPosition.x = x;
this._targetPosition.y = y;
if (applyNow && this._display) {
this._display.x = x;
this._display.y = y;
}
}
applyPosition() {
if (this._display) {
if (this._targetPosition) {
this._display.x = this._targetPosition.x;
this._display.y = this._targetPosition.y;
}
}
}
open(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'backOut') {
const targetY = this._display.y;
const originY = +targetY + +FaceRenderer_1.default.HEIGHT;
TweenManager_1.default.stop(this._display);
TweenManager_1.default.play(this._display, {
to: { y: targetY },
from: { y: originY },
duration: duration,
ease: tweenType
}, callback);
}
close(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'backIn') {
const targetY = +this._display.y + +FaceRenderer_1.default.HEIGHT;
TweenManager_1.default.stop(this._display);
TweenManager_1.default.play(this._display, {
to: { y: targetY },
duration: duration,
ease: tweenType
}, callback);
}
destroy() {
if (this._display) {
TweenManager_1.default.stop(this._display);
delete this._display['parentElement'];
this._display = null;
}
this._targetPosition = null;
super.destroy();
}
lockInput(flag) {
super.lockInput(flag);
if (this.interactable && this._display) {
this._display.interactive = !this._inputLocked;
}
}
}
exports.default = ElementGroup;
},{"../../FaceRenderer":99,"../../tween/TweenManager":174,"../ComponentGroup":123,"../DisplayUtils":124,"../ViewManager":127}],138:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Element_1 = require("./Element");
const TweenManager_1 = require("../../tween/TweenManager");
const ViewManager_1 = require("../ViewManager");
const Runtime_1 = require("../../../Runtime");
const log_1 = require("./log");
const log = log_1.default.createChild('Clip');
class Label extends Element_1.default {
constructor() {
super(...arguments);
this._type = Label.DEFAULT_TYPE;
this.style = null;
this.textDisplay = null;
this._bounds = null;
this._targetAnchor = null;
this._text = '';
}
static get DEFAULT_TYPE() { return 'Label'; }
get bounds() { return this._bounds; }
set bounds(newBounds) {
this._bounds = newBounds;
this.applyTextBounds();
}
get targetAnchor() {
if (!this._targetAnchor) {
this._targetAnchor = new PIXI.Point();
}
return this._targetAnchor;
}
get text() { return this._text; }
set text(newText) {
this._text = newText;
if (this.textDisplay) {
this.textDisplay.text = this._text;
this.applyTextBounds();
}
}
static createFontStyle(size, family, color, style, align) {
let fontStyle = new PIXI.TextStyle({
fontSize: Number(size) || size,
fontFamily: family,
fill: color,
fontStyle: style,
align: align
});
return fontStyle;
}
static createFromConfig(configData) {
let label = new Label();
label.assignConfig(configData);
return label;
}
assignConfig(configData) {
super.assignConfig(configData);
if (configData.hasOwnProperty('text')) {
this._text = configData.text;
}
if (configData.hasOwnProperty('style')) {
this.style = new PIXI.TextStyle(configData.style);
if (this.style.fontSize) {
this.style.fontSize = Number(this.style.fontSize) || this.style.fontSize;
}
}
if (configData.hasOwnProperty('bounds')) {
this._bounds = { width: Number(configData.bounds.width), height: Number(configData.bounds.height) };
}
if (configData.hasOwnProperty('targetAnchor')) {
this._targetAnchor = new PIXI.Point(Number(configData.targetAnchor.x), Number(configData.targetAnchor.y));
}
}
setupDisplay(assets) {
if (!this.style) {
this.style = Label.DEFAULT_STYLE.clone();
}
this.textDisplay = new PIXI.Text(this.text, this.style);
this._originalFontSize = this.getFontSize(this.style);
this.applyTextBounds();
this.display.addChild(this.textDisplay);
Runtime_1.default.instance.face.plugins.prepare.upload(this.textDisplay);
}
getTextDimensions(sampleText) {
sampleText = (this.text) ? this.text : sampleText;
sampleText = (sampleText) ? sampleText : 'Sample';
try {
let textMetric = PIXI.TextMetrics.measureText(sampleText, this.style);
return { width: textMetric.width, height: textMetric.height };
}
catch (err) {
log.error('Error occured requesting PIXI.TextMetrics for text: ' + sampleText + ', with style :', this.style, ' error:', err);
return null;
}
}
setTargetAnchor(x = 0, y = 0, applyNow = false) {
if (!this._targetAnchor) {
this._targetAnchor = new PIXI.Point();
}
this._targetAnchor.x = x;
this._targetAnchor.y = y;
if (applyNow && this.textDisplay) {
this.textDisplay.anchor.x = x;
this.textDisplay.anchor.y = y;
}
}
applyPosition() {
super.applyPosition();
if (this.textDisplay && this._targetAnchor) {
this.textDisplay.anchor.x = this._targetAnchor.x;
this.textDisplay.anchor.y = this._targetAnchor.y;
}
}
open(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'sineOut') {
TweenManager_1.default.stop(this.display);
TweenManager_1.default.play(this.display, {
to: { alpha: 1 },
from: { alpha: 0 },
duration: duration,
ease: tweenType
}, callback);
}
close(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'sineIn') {
TweenManager_1.default.stop(this.display);
TweenManager_1.default.play(this.display, {
to: { alpha: 0 },
duration: duration,
ease: tweenType
}, callback);
}
destroy() {
this.style = null;
if (this.textDisplay) {
this.textDisplay.destroy(true);
this.textDisplay = null;
}
this._targetAnchor = null;
this._bounds = null;
super.destroy();
}
applyTextBounds() {
const bounds = this.bounds;
if (bounds && this.textDisplay && this.textDisplay.text) {
let fontSize = this.getFontSize(this.style);
if (this._originalFontSize !== fontSize) {
this.style.fontSize = this._originalFontSize;
fontSize = this.style.fontSize;
}
let dimensions = this.getTextDimensions();
bounds.width = bounds.width ? bounds.width : dimensions.width;
bounds.height = bounds.height ? bounds.height : dimensions.height;
let refitCount = 0;
if (dimensions.width > bounds.width || dimensions.height > bounds.height) {
let fontResize = Math.ceil(fontSize / 2);
let subtract = true;
while (fontResize > 1) {
refitCount++;
if (dimensions.width > bounds.width || dimensions.height > bounds.height) {
if (!subtract) {
subtract = true;
fontResize = Math.ceil(fontResize / 2);
}
if (fontResize === fontSize) {
fontResize = Math.floor(fontResize / 2);
}
this.style.fontSize = fontSize -= fontResize;
dimensions = this.getTextDimensions();
}
else {
if (subtract) {
subtract = false;
fontResize = Math.ceil(fontResize / 2);
}
this.style.fontSize = fontSize += fontResize;
dimensions = this.getTextDimensions();
}
}
log.debug(' took ' + refitCount + ' iterations to resize text ' + this.textDisplay.text);
}
}
}
getFontSize(style) {
let fontSize = (typeof style.fontSize === 'string') ? parseInt(style.fontSize) : style.fontSize;
if (isNaN(fontSize)) {
return Number(Label.DEFAULT_STYLE.fontSize);
}
return fontSize;
}
}
Label.DEFAULT_STYLE = new PIXI.TextStyle({
fontSize: 60,
fontFamily: "Proxima Nova Soft",
fill: "#FFFFFF"
});
exports.default = Label;
},{"../../../Runtime":1,"../../tween/TweenManager":174,"../ViewManager":127,"./Element":136,"./log":144}],139:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Button_1 = require("../components/Button");
const ComponentGroup_1 = require("../ComponentGroup");
const ComponentCreator_1 = require("../ComponentCreator");
const ViewManager_1 = require("../ViewManager");
const ActionData_1 = require("../actions/ActionData");
const FaceRenderer_1 = require("../../FaceRenderer");
const TweenManager_1 = require("../../tween/TweenManager");
const Runtime_1 = require("../../../Runtime");
const TouchManager_1 = require("../TouchManager");
const DisplayUtils_1 = require("../DisplayUtils");
const ListMember_1 = require("./subcomponents/ListMember");
const log_1 = require("./log");
const log = log_1.default.createChild('List');
var Movement;
(function (Movement) {
Movement[Movement["NONE"] = 0] = "NONE";
Movement[Movement["PAN"] = 1] = "PAN";
Movement[Movement["SWIPE"] = 2] = "SWIPE";
})(Movement || (Movement = {}));
var PanCase;
(function (PanCase) {
PanCase[PanCase["STILL"] = 0] = "STILL";
PanCase[PanCase["DYNAMIC"] = 1] = "DYNAMIC";
PanCase[PanCase["CLAMP_LEFT"] = 2] = "CLAMP_LEFT";
PanCase[PanCase["CLAMP_RIGHT"] = 3] = "CLAMP_RIGHT";
})(PanCase || (PanCase = {}));
class List extends ComponentGroup_1.default {
constructor() {
super();
this._type = List.DEFAULT_TYPE;
this.elementsPerPage = 3;
this.axis = 'horizontal';
this.numElementsAtEdge = 1;
this.elementDimensions = null;
this.elementBuffer = 20;
this.defaultElementData = null;
this.axisPosition = 0;
this.dynamicLoadBuffer = 1;
this.noPan = false;
this.dynamicElements = false;
this.dynamicPreload = false;
this.autoFitElements = true;
this.pageHinting = true;
this._elementSpacing = 0;
this._listStartPosition = null;
this._requiresPan = false;
this.EDGE_HINT = 80;
this.BUFFER_SPREAD = 30;
this.PAN_THRESHOLD = 150;
this.PAN_SPREAD = 40;
this.SPRING = .08;
this.FRICTION = .7;
this.REST_THRESHOLD = 5;
this.SWIPE_THRESHOLD = 100;
this._axis = 'horizontal';
this._loadingElements = null;
this._leftPageBound = 0;
this._rightPageBound = 0;
this._pageIndex = 0;
this._pageElementOffset = 0;
this._indexOfAction = -1;
this._bufferMax = null;
this._currentMovement = Movement.NONE;
this._panTotalDelta = 0;
this._dynamicActiveIndexRange = null;
this.onPanEvent = this.onPanEvent.bind(this);
}
static get DEFAULT_TYPE() {
return 'List';
}
static get PAN() {
return 'page_pan';
}
static get PAGED() {
return 'paged';
}
static get REMOVE_ELEMENT() { return 'removeElement'; }
static get AT_END() {
return 'at_end';
}
static get AT_FRONT() {
return 'at_front';
}
get elementSpacing() {
return this._elementSpacing;
}
get listStartPosition() {
return this._listStartPosition;
}
get pageIndex() {
return this._pageIndex;
}
static createFromConfig(configData) {
let list = new List();
list.assignConfig(configData);
return list;
}
assignConfig(configData) {
if (configData) {
super.assignConfig(configData);
if (configData.hasOwnProperty('axis')) {
this._axis = configData['axis'];
}
if (configData.hasOwnProperty('position')) {
if (this._axis === 'horizontal') {
this.axisPosition = Number(configData.position['y']);
}
else {
this.axisPosition = Number(configData.position['x']);
}
}
if (configData.hasOwnProperty('dynamic')) {
this.dynamicElements = configData['dynamic'];
}
if (configData.hasOwnProperty('dynamicPreload')) {
this.dynamicPreload = configData['dynamicPreload'];
}
if (configData.hasOwnProperty('dynamicBuffer')) {
this.dynamicLoadBuffer = Number(configData['dynamicBuffer']);
}
if (configData.hasOwnProperty('noPan')) {
this.noPan = configData['noPan'];
}
if (configData.hasOwnProperty('elementsPerPage')) {
this.elementsPerPage = Number(configData['elementsPerPage']);
}
if (configData.hasOwnProperty('autoFitElements')) {
this.autoFitElements = configData['autoFitElements'];
}
if (configData.hasOwnProperty('pageHinting')) {
this.pageHinting = configData['pageHinting'];
}
if (configData.hasOwnProperty('pageIndex')) {
this._pageIndex = Number(configData['pageIndex']);
}
if (configData.hasOwnProperty('indexOfAction')) {
this._indexOfAction = Number(configData['indexOfAction']);
}
if (configData.hasOwnProperty('elementDimensions')) {
let width = Number(configData.elementDimensions.width) || Number(configData.elementDimensions.x);
let height = Number(configData.elementDimensions.height) || Number(configData.elementDimensions.y);
this.elementDimensions = { width: width, height: height };
}
else {
this.elementDimensions = { width: 300, height: 300 };
}
if (configData.hasOwnProperty('elementBuffer')) {
this.elementBuffer = Number(configData['elementBuffer']);
}
let defaultElementData;
if (configData.hasOwnProperty('defaultElement')) {
defaultElementData = configData['defaultElement'];
}
if (configData.hasOwnProperty('componentConfigs')) {
this.componentConfigs = configData['componentConfigs'];
this.createComponentsFromConfigs(this.componentConfigs, defaultElementData);
}
this.calculateReferenceValues();
}
}
addComponent(element, elementId) {
if (element) {
return super.addComponent(element, elementId);
}
return null;
}
removeComponent(componentDeterminer, done, transition) {
let element = super.removeComponent(componentDeterminer);
if (!element) {
if (done) {
done();
}
return null;
}
const maxPageIndex = this.getPagesCount() - 1;
let targetPageIndex = this._pageIndex;
if (this._pageIndex > maxPageIndex) {
targetPageIndex = maxPageIndex;
this._pageElementOffset = 0;
}
if (targetPageIndex === 0 && maxPageIndex === 0) {
this.calculateReferenceValues();
}
this.setActivePage(targetPageIndex);
this.setTargetsByPage(targetPageIndex);
if (this.dynamicElements) {
this.dynamicElementsPageChange(targetPageIndex);
}
this._currentMovement = Movement.NONE;
if (maxPageIndex === 0) {
TouchManager_1.default.instance.removeGesture(TouchManager_1.GESTURE.PAN);
}
const onEnd = () => {
this._currentMovement = Movement.SWIPE;
this.destroyElement(element, done);
};
if (transition) {
transition(element, onEnd);
}
else {
this.elementRemovalTransition(element, onEnd);
}
return element;
}
getPagesCount() {
return Math.ceil(this.componentsTotal / this.elementsPerPage);
}
calculateReferenceValues() {
if (this.autoFitElements) {
const total = this.componentsTotal;
if (total > 0) {
let elementCount = 0;
let hitLimit = false;
while (!hitLimit) {
elementCount++;
if (elementCount > total || this.elementBuffer > (FaceRenderer_1.default.WIDTH - elementCount * this.elementDimensions.width) / (elementCount + 1)) {
elementCount--;
if (elementCount >= total) {
this.elementsPerPage = elementCount;
this.pageHinting = false;
}
hitLimit = true;
}
}
}
}
let width = FaceRenderer_1.default.WIDTH - ((this.pageHinting) ? (this.EDGE_HINT * 2) : 0);
let calcBuffer = Math.max(this.elementBuffer, (width - this.elementsPerPage * this.elementDimensions.width) / (this.elementsPerPage + 1));
this._listStartPosition = new PIXI.Point((FaceRenderer_1.default.WIDTH - this.elementsPerPage * this.elementDimensions.width - (this.elementsPerPage - 1) * calcBuffer) / 2, this.axisPosition - this.elementDimensions.height / 2);
this._elementSpacing = +this.elementDimensions.width + calcBuffer;
this._bufferMax = calcBuffer + this.BUFFER_SPREAD;
}
createComponentsFromConfigs(elementConfigs, defaultElementData) {
let creator = ComponentCreator_1.default.instance;
let numElements = elementConfigs.length;
let i = 0;
if (defaultElementData) {
let elementConfig;
for (; i < numElements; i++) {
elementConfig = this.mergeConfigs(elementConfigs[i], defaultElementData);
this.addComponent(creator.createComponentFromConfig(elementConfig));
}
}
else {
for (; i < numElements; i++) {
this.addComponent(creator.createComponentFromConfig(elementConfigs[i]));
}
}
}
get assetDescriptors() {
if (!this.dynamicElements) {
return this.groupAssetDescriptors;
}
else {
this._assetDescriptors = (this._assetDescriptors || []);
this._assetDescriptors.push({
id: 'loader',
type: 'timeline',
src: 'core://resources/buttons/loader.js'
});
let groupAssetDescriptors = (this._assetDescriptors) ? this._assetDescriptors.slice(0) : [];
if (this.dynamicPreload && this.componentList) {
this._pageIndex = this.normalizePageIndex(this._pageIndex);
const endLoadIndex = Math.min(this.getStartIndexByPage(this.normalizePageIndex(this._pageIndex + this.dynamicLoadBuffer)) + +this.elementsPerPage, this.componentList.length);
let i = this.getStartIndexByPage(this.normalizePageIndex(this._pageIndex - this.dynamicLoadBuffer));
let component;
let nextAssetDescriptors;
for (i; i < endLoadIndex; i++) {
component = this.componentList[i];
nextAssetDescriptors = component.assetDescriptors;
if (nextAssetDescriptors) {
groupAssetDescriptors = groupAssetDescriptors.concat(nextAssetDescriptors);
}
}
}
return groupAssetDescriptors;
}
}
updateConfig(configData) {
configData = configData || {};
Object.assign(configData, { pageIndex: this._pageIndex, indexOfAction: this._indexOfAction });
return super.updateConfig(configData);
}
createDisplay(container, assets) {
this._assets = assets;
this.container = container;
this.calculateReferenceValues();
this.setActivePage(this._pageIndex);
const startIndex = this.getStartIndexByPage(this._pageIndex);
if (!this.elementDimensions) {
this.elementDimensions = { width: 330, height: 330 };
}
let element;
let i;
let listMember;
let length = this.componentList.length;
let indexDiff;
for (i = 0; i < length; i++) {
element = this.componentList[i];
listMember = new ListMember_1.default();
element.addSubcomponent(listMember);
indexDiff = i - startIndex;
element.setTargetPosition(this._listStartPosition.x + (this._elementSpacing * indexDiff), this._listStartPosition.y);
if (!this.dynamicElements) {
element.createDisplay(container, assets);
listMember.loaded = true;
}
else {
listMember.loaded = false;
element.display = new PIXI.Container();
element.applyPosition();
}
listMember.targetPosition = element.targetPosition.clone();
listMember.velocity = new PIXI.Point(0, 0);
listMember.targetOffset = 0;
}
if (this.dynamicElements) {
this._loadingElements = [];
if (this.dynamicPreload) {
this.dynamicElementsPageChange(this._pageIndex);
}
}
}
ready() {
if (this.componentList) {
const length = this.componentList.length;
if (this.dynamicElements && !this.dynamicPreload && length > 0) {
this.dynamicElementsPageChange(this._pageIndex);
}
this.registerUpdate(true);
if (!this.noPan) {
this._leftPageBound = this._listStartPosition.x;
this._rightPageBound = FaceRenderer_1.default.WIDTH - this._listStartPosition.x;
this._requiresPan = true;
}
}
super.ready();
}
destroy() {
this.registerUpdate(false);
TouchManager_1.default.instance.removeGesture(TouchManager_1.GESTURE.PAN);
this._listStartPosition = null;
this.defaultElementData = null;
this.elementDimensions = null;
super.destroy();
}
lockInput(flag) {
if (this._requiresPan && !flag) {
TouchManager_1.default.instance.addGesture(TouchManager_1.GESTURE.PAN, this.onPanEvent);
}
super.lockInput(flag);
}
lockChildInput(flag) {
if (this._childInputLocked !== flag) {
if (!this.dynamicElements) {
super.lockChildInput(flag);
}
else {
this._childInputLocked = flag;
if (this.componentList) {
let i = this._dynamicActiveIndexRange[0];
const end = this._dynamicActiveIndexRange[1];
for (i; i < end; i++) {
this.componentList[i].lockInput(flag);
}
}
}
}
}
open(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'backOut') {
if (this.componentList.length > 0) {
if (transitionType === ViewManager_1.TRANSITION.UP || transitionType === ViewManager_1.TRANSITION.DOWN) {
this.openVertical(callback, transitionType, duration, tweenType);
}
else if (transitionType === ViewManager_1.TRANSITION.EYE) {
this.openFromEye(callback, duration);
}
else {
callback();
}
}
else {
callback();
}
}
close(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'backIn') {
if (this.componentList.length > 0) {
if (transitionType === ViewManager_1.TRANSITION.UP || transitionType === ViewManager_1.TRANSITION.DOWN) {
this.closeVertical(callback, transitionType, duration, tweenType);
}
else if (transitionType === ViewManager_1.TRANSITION.EYE) {
this.closeToEye(callback, duration);
}
else {
callback();
}
}
else {
callback();
}
}
getElementsByPage(pageIndex = this._pageIndex) {
const pageNormalized = this.normalizePageIndex(pageIndex);
const startIndex = this.getStartIndexByPage(pageNormalized);
const endIndex = Math.min(startIndex + this.elementsPerPage, this.componentsTotal);
return this.componentList.slice(startIndex, endIndex);
}
actionHandler(action, fromComponent) {
if (fromComponent) {
const member = fromComponent.getSubcomponent(ListMember_1.default.TYPE);
if (member) {
const index = super.getIndexOfComponent(fromComponent);
if (index > -1) {
this._indexOfAction = index;
this._stateChanged = true;
if (action.type === List.REMOVE_ELEMENT) {
this.removeComponent(fromComponent);
}
}
}
}
this.parentGroup.actionHandler(action);
}
actionEnactor(action) {
let actionActedOn = false;
switch (action.type) {
case ActionData_1.default.SWIPE_RIGHT:
{
this.changePage(false);
actionActedOn = true;
break;
}
case ActionData_1.default.SWIPE_LEFT:
{
this.changePage(true);
actionActedOn = true;
break;
}
case ActionData_1.default.GO_TO_BEGINNING:
{
this.pageToEnd(true);
actionActedOn = true;
break;
}
case ActionData_1.default.GO_TO_END:
{
this.pageToEnd(false);
actionActedOn = true;
break;
}
case ActionData_1.default.VERBAL_COMMAND:
{
if (action.data && action.data.intent) {
const intent = action.data.intent;
if (intent === 'right') {
this.changePage(true);
actionActedOn = true;
}
else if (intent === 'left') {
this.changePage(false);
actionActedOn = true;
}
else if (intent === 'beginning') {
this.pageToEnd(true);
actionActedOn = true;
}
else if (intent === 'end') {
this.pageToEnd(false);
actionActedOn = true;
}
else if (intent === 'selectItem') {
const startIndex = this.getStartIndexByPage(this.normalizePageIndex(this._pageIndex));
const endIndex = Math.min(startIndex + +this.elementsPerPage, this.componentsTotal);
const pageTotal = endIndex - startIndex;
let selectedElement;
if (action.data.entities.itemPosition) {
const itemPosition = action.data.entities.itemPosition;
let index;
if (pageTotal > 1) {
if (itemPosition === 'first' || itemPosition === 'left') {
selectedElement = this.componentList[startIndex];
}
else if (itemPosition === 'second') {
selectedElement = this.componentList[startIndex + 1];
}
else if (itemPosition === 'third') {
if (pageTotal > 2) {
selectedElement = this.componentList[startIndex + 2];
}
}
else if (itemPosition === 'fourth') {
if (pageTotal > 3) {
selectedElement = this.componentList[startIndex + 3];
}
}
else if (itemPosition === 'middle') {
if (pageTotal % 2 === 1) {
index = Math.min(Math.floor(startIndex + this.elementsPerPage / 2), endIndex - 1);
selectedElement = this.componentList[index];
}
}
else if (itemPosition === 'right') {
selectedElement = this.componentList[endIndex - 1];
}
}
else if (pageTotal === 1) {
if (itemPosition === 'first' || itemPosition === 'middle') {
selectedElement = this.componentList[startIndex];
}
}
else {
log.info('actionEnactor() mim result action intent selectItem, list is empty, nothing to select.');
}
}
else {
if (pageTotal === 1) {
selectedElement = this.componentList[startIndex];
}
else {
log.info('actionEnactor() mim result action intent selectItem, must define itemPosition in data if more than one element in list.');
}
}
if (selectedElement) {
actionActedOn = true;
if (selectedElement instanceof Button_1.default) {
selectedElement.activate();
}
selectedElement.triggerActions();
}
}
}
else {
log.info('actionEnactor() : mim result action define an intent with its data.');
}
break;
}
default:
{
break;
}
}
return actionActedOn;
}
update(elapsed) {
if (this._currentMovement !== Movement.NONE) {
this.springUpdate();
}
}
changePage(pageForward = true) {
if (this._axis === 'horizontal') {
if (pageForward) {
if (this._pageIndex < Math.ceil(this.componentList.length / this.elementsPerPage) - 1) {
this.setActivePage(this._pageIndex + 1);
this.setTargetsByPage(this._pageIndex);
if (this.dynamicElements) {
this.dynamicElementsPageChange(this.pageIndex);
}
this.actionHandler(new ActionData_1.default(List.PAGED), this);
this.actionHandler(new ActionData_1.default(ActionData_1.default.EVENT, { event: List.PAGED }));
Runtime_1.default.instance.sound.play('swipeLR');
return true;
}
else {
this.actionHandler(new ActionData_1.default(ActionData_1.default.EVENT, { event: List.AT_END }));
Runtime_1.default.instance.sound.play('swipeEoL');
}
}
else {
if (this._pageIndex !== 0) {
this.setActivePage(this._pageIndex - 1);
this.setTargetsByPage(this._pageIndex);
if (this.dynamicElements) {
this.dynamicElementsPageChange(this.pageIndex);
}
this.actionHandler(new ActionData_1.default(List.PAGED), this);
this.actionHandler(new ActionData_1.default(ActionData_1.default.EVENT, { event: List.PAGED }));
Runtime_1.default.instance.sound.play('swipeLR');
return true;
}
else {
this.actionHandler(new ActionData_1.default(ActionData_1.default.EVENT, { event: List.AT_FRONT }));
Runtime_1.default.instance.sound.play('swipeEoL');
}
}
}
else {
log.info('changePage() : vertical lists are not currently supported.');
}
return false;
}
pageToEnd(pageToFront = false) {
if (this._axis === 'horizontal') {
if (!pageToFront) {
if (this._pageIndex < Math.ceil(this.componentList.length / this.elementsPerPage) - 1) {
const maxIndex = Math.ceil(this.componentList.length / this.elementsPerPage) - 1;
this.setActivePage(maxIndex);
this.setTargetsByPage(maxIndex);
if (this.dynamicElements) {
this.dynamicElementsPageChange(this.pageIndex);
}
this.actionHandler(new ActionData_1.default(List.PAGED), this);
this.actionHandler(new ActionData_1.default(ActionData_1.default.EVENT, { event: List.PAGED }));
Runtime_1.default.instance.sound.play('swipeLR');
return true;
}
else {
this.actionHandler(new ActionData_1.default(ActionData_1.default.EVENT, { event: List.AT_END }));
Runtime_1.default.instance.sound.play('swipeEoL');
}
}
else {
if (this._pageIndex !== 0) {
this.setActivePage(0);
this.setTargetsByPage(0);
if (this.dynamicElements) {
this.dynamicElementsPageChange(this.pageIndex);
}
this.actionHandler(new ActionData_1.default(List.PAGED), this);
this.actionHandler(new ActionData_1.default(ActionData_1.default.EVENT, { event: List.PAGED }));
Runtime_1.default.instance.sound.play('swipeLR');
return true;
}
else {
this.actionHandler(new ActionData_1.default(ActionData_1.default.EVENT, { event: List.AT_FRONT }));
Runtime_1.default.instance.sound.play('swipeEoL');
}
}
}
else {
log.info('pageToEnd() vertical lists are not currently supported.');
}
return false;
}
getStartIndexByPage(pageIndex) {
if (pageIndex === 0) {
return 0;
}
else {
return pageIndex * this.elementsPerPage - this._pageElementOffset;
}
}
setActivePage(pageIndex) {
let index = this.normalizePageIndex(pageIndex);
if (this._pageIndex !== index) {
this._pageIndex = index;
this._stateChanged = true;
}
const length = this.componentList.length;
if (index === 0) {
this._pageElementOffset = 0;
}
else {
let startIndex = index * this.elementsPerPage;
const endIndex = startIndex + this.elementsPerPage;
if (endIndex > length) {
this._pageElementOffset = endIndex - length;
}
}
if (this.dynamicElements) {
if (!this._dynamicActiveIndexRange) {
this._dynamicActiveIndexRange = [0, 0];
}
this._dynamicActiveIndexRange[0] = this.getStartIndexByPage(this.normalizePageIndex(index - this.dynamicLoadBuffer));
this._dynamicActiveIndexRange[1] = Math.min(this.getStartIndexByPage(this.normalizePageIndex(index + this.dynamicLoadBuffer)) + this.elementsPerPage, length);
}
}
openVertical(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'backIn') {
let startY = 0;
if (transitionType === ViewManager_1.TRANSITION.UP) {
startY = +FaceRenderer_1.default.HEIGHT + +this.elementDimensions.height;
}
else if (transitionType === ViewManager_1.TRANSITION.DOWN) {
startY = -this.elementDimensions.height;
}
const startIndex = Math.max(this.getStartIndexByPage(this._pageIndex) - this.numElementsAtEdge, 0);
const endIndex = Math.min(this.getStartIndexByPage(this._pageIndex) + +this.elementsPerPage + +this.numElementsAtEdge, this.componentList.length);
const targetY = this.componentList[startIndex].targetPosition.y;
let focusIndex = Math.max(this._indexOfAction - startIndex, 0);
TweenManager_1.default.playSet(this.componentList.slice(startIndex, endIndex).map(function (element) {
return element.display;
}), {
from: { y: startY },
to: { y: targetY },
ease: tweenType,
duration: duration
}, {
focus: focusIndex,
focusIsLast: false,
delay: 100,
complete: callback,
completeOnFirst: true
});
}
closeVertical(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'backIn') {
const startIndex = Math.max(this.getStartIndexByPage(this._pageIndex) - this.numElementsAtEdge, 0);
const endIndex = Math.min(this.getStartIndexByPage(this._pageIndex) + this.elementsPerPage + +this.numElementsAtEdge, this.componentList.length);
let endY = 0;
let focusIndex = 0;
let focusIsLast = true;
let delay = 100;
if (transitionType === ViewManager_1.TRANSITION.UP) {
endY = -this.elementDimensions.height;
focusIndex = Math.max(this._indexOfAction - startIndex, 0);
focusIsLast = false;
}
else if (transitionType === ViewManager_1.TRANSITION.DOWN) {
endY = +FaceRenderer_1.default.HEIGHT + +this.elementDimensions.height;
delay = 0;
}
TweenManager_1.default.playSet(this.componentList.slice(startIndex, endIndex).map(function (element) { return element.display; }), {
to: { y: endY },
ease: tweenType,
duration: duration
}, {
focus: focusIndex,
focusIsLast: focusIsLast,
delay: delay,
complete: callback
});
}
openFromEye(callback, duration = ViewManager_1.default.TRANS_TIME) {
if (this.componentList.length > 0) {
const startIndex = Math.max(this.getStartIndexByPage(this.pageIndex) - this.numElementsAtEdge, 0);
const endIndex = Math.min(this.getStartIndexByPage(this.pageIndex) + +this.elementsPerPage + +this.numElementsAtEdge, this.componentList.length);
const elementDisplays = this.componentList.slice(startIndex, endIndex).map(function (element) {
return element.display;
});
const targetY = this.componentList[startIndex].targetPosition.y;
for (let i = 0; i < elementDisplays.length; i++) {
elementDisplays[i].y = targetY;
}
const eyeDiameter = 450;
const targetScale = DisplayUtils_1.default.getScaleByWidthHeight(elementDisplays[0], eyeDiameter, eyeDiameter);
const startX = FaceRenderer_1.default.WIDTH / 2 - eyeDiameter / 2;
const startY = FaceRenderer_1.default.HEIGHT / 2 - eyeDiameter / 2;
TweenManager_1.default.playSet(elementDisplays, {
from: {
x: startX,
y: startY,
'scale.x': targetScale,
'scale.y': targetScale
},
ease: 'backOut',
duration: duration
}, {
complete: callback
});
}
else {
callback();
}
}
closeToEye(callback, duration = ViewManager_1.default.TRANS_TIME) {
if (this.componentList.length > 0) {
const startIndex = Math.max(this.getStartIndexByPage(this.pageIndex) - this.numElementsAtEdge, 0);
const endIndex = Math.min(this.getStartIndexByPage(this.pageIndex) + this.elementsPerPage + +this.numElementsAtEdge, this.componentList.length);
const elementDisplays = this.componentList.slice(startIndex, endIndex).map(function (element) {
return element.display;
});
const eyeDiameter = 450;
const targetX = FaceRenderer_1.default.WIDTH / 2 - eyeDiameter / 2;
const targetY = FaceRenderer_1.default.HEIGHT / 2 - eyeDiameter / 2;
let targetScale = DisplayUtils_1.default.getScaleByWidthHeight(elementDisplays[0], eyeDiameter, eyeDiameter);
TweenManager_1.default.playSet(elementDisplays, {
to: {
x: targetX,
y: targetY,
'scale.x': targetScale,
'scale.y': targetScale
},
ease: 'backIn',
duration: duration
}, {
complete: callback
});
}
else {
callback();
}
}
dynamicElementsPageChange(pageIndex) {
const startLoadIndex = this._dynamicActiveIndexRange[0];
const endLoadIndex = this._dynamicActiveIndexRange[1];
let assetsToLoad;
let assetsToRemove;
let element;
let i;
let j;
let asset;
const length = this.componentList.length;
for (i = 0; i < length; i++) {
if (i < startLoadIndex || i >= endLoadIndex) {
element = this.componentList[i];
if (element.getSubcomponent(ListMember_1.default.TYPE).loaded) {
this.emptyElementDisplay(element);
this.container.removeChild(element.display);
for (j = 0; j < element.assetDescriptors.length; j++) {
asset = element.assetDescriptors[j];
if (this._assets[asset.id]) {
if (!assetsToRemove) {
assetsToRemove = {};
}
assetsToRemove[asset.id] = asset;
}
}
}
}
else {
i = endLoadIndex - 1;
}
}
let requiresLoad;
for (i = startLoadIndex; i < endLoadIndex; i++) {
element = this.componentList[i];
if (element.assetDescriptors) {
if (element.getSubcomponent(ListMember_1.default.TYPE).loaded) {
if (assetsToRemove) {
for (j = 0; j < element.assetDescriptors.length; j++) {
asset = element.assetDescriptors[j];
if (assetsToRemove[asset.id]) {
delete assetsToRemove[asset.id];
}
}
}
}
else {
requiresLoad = false;
for (j = 0; j < element.assetDescriptors.length; j++) {
asset = element.assetDescriptors[j];
if (assetsToRemove && assetsToRemove[asset.id]) {
delete assetsToRemove[asset.id];
}
if (!this._assets[asset.id]) {
requiresLoad = true;
if (!assetsToLoad) {
assetsToLoad = {};
}
assetsToLoad[asset.id] = asset;
}
}
if (!requiresLoad) {
this.updateElementDisplay(element);
}
else {
this._loadingElements.push(element);
const loaderClip = new this._assets['loader'].library.stage();
loaderClip.x += this.elementDimensions.width / 2;
loaderClip.y += this.elementDimensions.height / 2;
element.display.addChild(loaderClip);
if (!element.display.parent) {
this.container.addChild(element.display);
}
}
}
}
}
if (assetsToRemove) {
this.parentView.removeAssets(assetsToRemove);
}
if (assetsToLoad) {
this.parentView.addAssets(assetsToLoad, (err) => {
if (err) {
log.warn('encountered error loading assets for list elements');
this.iterativeLoad(assetsToLoad);
}
else {
this.assignElementAssets();
}
});
}
}
iterativeLoad(assetsToLoad) {
for (let key in assetsToLoad) {
if (assetsToLoad.hasOwnProperty(key)) {
let asset = assetsToLoad[key];
delete assetsToLoad[key];
this.parentView.addAssets(asset, (err) => {
if (err) {
log.warn('encountered error loading asset', asset);
}
this.assignElementAssets();
this.iterativeLoad(assetsToLoad);
});
return;
}
}
}
assignElementAssets() {
let element;
let assetsFound;
let i = this._loadingElements.length - 1;
let j;
for (i; i >= 0; i--) {
assetsFound = true;
element = this._loadingElements[i];
for (j = element.assetDescriptors.length - 1; j >= 0 && assetsFound; j--) {
if (!this._assets[element.assetDescriptors[j].id]) {
assetsFound = false;
}
}
if (assetsFound) {
this._loadingElements.splice(i, 1);
this.updateElementDisplay(element);
}
}
}
updateElementDisplay(element) {
this.emptyElementDisplay(element);
element.setupDisplay(this._assets);
if (!element.display.parent) {
this.container.addChild(element.display);
}
element.getSubcomponent(ListMember_1.default.TYPE).loaded = true;
}
emptyElementDisplay(element) {
element.getSubcomponent(ListMember_1.default.TYPE).loaded = false;
element.emptyDisplay();
}
setTargetsByPage(pageIndex) {
this._currentMovement = Movement.SWIPE;
let pageStartX = this._listStartPosition.x - (this.getStartIndexByPage(pageIndex) * this._elementSpacing);
this.lockChildInput(true);
const length = this.componentList.length;
let member;
for (let i = 0; i < length; i++) {
member = this.componentList[i].getSubcomponent(ListMember_1.default.TYPE);
member.targetOffset = 0;
member.targetPosition.x = (pageStartX + (i * this._elementSpacing));
}
}
setTargetsByInput(panState, velocity, inputX) {
const maxSpacing = +this.elementDimensions.width + this._bufferMax;
const targetOffset = Math.min(1, Math.abs(velocity) / this.BUFFER_SPREAD) * this.PAN_SPREAD;
let member;
let element;
let length = this.componentList.length;
for (let i = 0; i < length; ++i) {
if (panState === PanCase.CLAMP_LEFT) {
member = this.componentList[i].getSubcomponent(ListMember_1.default.TYPE);
member.targetPosition.x = +this._leftPageBound + +targetOffset + this._bufferMax + (maxSpacing * i);
}
else if (panState === PanCase.CLAMP_RIGHT) {
member = this.componentList[length - 1 - i].getSubcomponent(ListMember_1.default.TYPE);
member.targetPosition.x = this._rightPageBound - targetOffset - this._bufferMax - (maxSpacing * (i + 1));
}
else if (panState === PanCase.DYNAMIC) {
element = this.componentList[i];
member = element.getSubcomponent(ListMember_1.default.TYPE);
member.targetOffset = targetOffset * ((element.display.toGlobal(element.display.position).x - inputX) / maxSpacing);
member.targetPosition.x += velocity;
}
}
}
springUpdate() {
let element;
let member;
let deltaX;
let deltaXAbs;
let springsComplete = true;
let unlockInput = true;
const length = this.componentList.length;
for (let i = 0; i < length; ++i) {
element = this.componentList[i];
member = element.getSubcomponent(ListMember_1.default.TYPE);
deltaX = (member.targetPosition.x + member.targetOffset) - element.display.x;
deltaXAbs = Math.abs(deltaX);
if (deltaXAbs > 1 || member.velocity.x > 1) {
member.velocity.x += deltaX * this.SPRING;
element.display.x += (member.velocity.x *= this.FRICTION);
springsComplete = false;
}
else {
member.velocity.x = 0;
element.display.x = member.targetPosition.x + member.targetOffset;
}
if (unlockInput && deltaXAbs > this.SWIPE_THRESHOLD) {
unlockInput = false;
}
}
if (this._currentMovement === Movement.SWIPE) {
if (springsComplete) {
this._currentMovement = Movement.NONE;
this.lockChildInput(false);
}
else if (unlockInput) {
this.lockChildInput(false);
}
}
}
pan(inputX, velocity) {
if (this._currentMovement !== Movement.PAN) {
this._currentMovement = Movement.PAN;
this.lockChildInput(true);
this.actionHandler(new ActionData_1.default(List.PAN), this);
}
this._panTotalDelta += velocity;
const firstElement = this.componentList[0];
const lastElement = this.componentList[this.componentList.length - 1];
let panState;
if (Math.abs(velocity) >= this.REST_THRESHOLD) {
if (velocity > 0 && firstElement.display.x >= +this._leftPageBound + +this._bufferMax) {
panState = PanCase.CLAMP_LEFT;
}
else if (velocity < 0 && +lastElement.display.x + +this.elementDimensions.width <= this._rightPageBound - this._bufferMax) {
panState = PanCase.CLAMP_RIGHT;
}
else {
panState = PanCase.DYNAMIC;
}
this.setTargetsByInput(panState, velocity, inputX);
}
}
panStop() {
if (Math.abs(this._panTotalDelta) > this.PAN_THRESHOLD) {
if (!this.changePage(this._panTotalDelta < 0)) {
this.setTargetsByPage(this.pageIndex);
this.actionHandler(new ActionData_1.default(List.PAGED), this);
}
}
else {
this.setTargetsByPage(this.pageIndex);
this.actionHandler(new ActionData_1.default(List.PAGED), this);
}
this._panTotalDelta = 0;
}
onPanEvent(event) {
if (!this.inputLocked) {
if (event.isFinal) {
this.checkPanEvent(false);
}
else {
if (event.velocityX !== 0.0) {
this.checkPanEvent(true, event.pointers[0].x, event.srcEvent.movementX);
}
}
}
}
checkPanEvent(active, inputX = 0, deltaX = 0) {
if (active) {
this.pan(inputX, deltaX);
}
else if (this._currentMovement === Movement.PAN) {
Runtime_1.default.instance.globalEvents.shared.screenGesture.emit(TouchManager_1.GESTURE.PAN);
this.panStop();
}
}
elementRemovalTransition(element, done) {
const tweenTime = 200;
const scaleEase = 'backIn';
const fadeEase = 'sineIn';
const display = element.display;
element.centerPivot();
TweenManager_1.default.play(display, {
to: {
'scale.x': 0,
'scale.y': 0
},
duration: tweenTime,
ease: scaleEase
}, () => {
TweenManager_1.default.stop(display);
display.alpha = 0;
display.pivot.x = 0;
display.pivot.y = 0;
display.x = 0;
display.y = 0;
done();
});
TweenManager_1.default.play(display, {
to: { alpha: 0 },
duration: tweenTime,
ease: fadeEase
});
}
destroyElement(element, done) {
let startLoadIndex;
let endLoadIndex;
if (this.dynamicElements) {
startLoadIndex = this.getStartIndexByPage(this.normalizePageIndex(this.pageIndex - this.dynamicLoadBuffer));
endLoadIndex = Math.min(this.getStartIndexByPage(this.normalizePageIndex(this.pageIndex + this.dynamicLoadBuffer)) + +this.elementsPerPage, this.componentList.length);
}
else {
startLoadIndex = 0;
endLoadIndex = this.componentList.length;
}
let assetCount = element.assetDescriptors.length;
if (assetCount > 0 && (!this.dynamicElements || element.getSubcomponent(ListMember_1.default.TYPE).loaded)) {
let i;
let assetsToRemove;
let asset;
for (i = 0; i < assetCount; i++) {
asset = element.assetDescriptors[i];
if (this._assets[asset.id]) {
if (!assetsToRemove) {
assetsToRemove = {};
}
assetsToRemove[asset.id] = asset;
}
}
let loadedElement;
let assetId;
let j;
mainLoop: for (i = startLoadIndex; i < endLoadIndex; i++) {
loadedElement = this.componentList[i];
if (loadedElement.assetDescriptors) {
if (!this.dynamicElements || loadedElement.getSubcomponent(ListMember_1.default.TYPE).loaded) {
for (j = 0; j < loadedElement.assetDescriptors.length; j++) {
assetId = loadedElement.assetDescriptors[j].id;
if (assetsToRemove[assetId]) {
delete assetsToRemove[assetId];
assetCount--;
if (assetCount === 0) {
break mainLoop;
}
}
}
}
}
}
if (assetCount > 0) {
this.parentView.removeAssets(assetsToRemove);
}
}
element.destroy();
if (done) {
done();
}
}
mergeConfigs(data, defaultData, mergeArrays = true) {
if (!mergeArrays) {
return Object.assign({}, defaultData, data);
}
else {
let output = {};
let property;
for (property in defaultData) {
if (defaultData.hasOwnProperty(property)) {
if (!data.hasOwnProperty(property)) {
output[property] = defaultData[property];
}
}
}
for (property in data) {
if (data.hasOwnProperty(property)) {
if (Array.isArray(data[property]) && Array.isArray(defaultData[property])) {
if (property === 'colors') {
output[property] = data[property];
}
else if (property === 'assets') {
let defaultAssets = defaultData['assets'];
let outputAssets = data['assets'].slice(0);
let j = 0;
let outputLength = outputAssets.length;
let defaultAsset;
defaultLoop: for (let i = defaultAssets.length - 1; i >= 0; i--) {
defaultAsset = defaultAssets[i];
for (j = 0; j < outputLength; j++) {
if (defaultAsset.id === outputAssets[j].id) {
continue defaultLoop;
}
}
outputAssets.push(defaultAsset);
}
output['assets'] = outputAssets;
}
else {
output[property] = data[property].concat(defaultData[property]);
}
}
else {
output[property] = data[property];
}
}
}
return output;
}
}
normalizePageIndex(pageIndex) {
let page = pageIndex;
if (page < 0) {
page = 0;
}
else {
let length = this.componentList.length;
if (page * this.elementsPerPage > length) {
page = Math.floor(length / this.elementsPerPage);
}
}
return page;
}
}
exports.default = List;
},{"../../../Runtime":1,"../../FaceRenderer":99,"../../tween/TweenManager":174,"../ComponentCreator":122,"../ComponentGroup":123,"../DisplayUtils":124,"../TouchManager":125,"../ViewManager":127,"../actions/ActionData":130,"../components/Button":132,"./log":144,"./subcomponents/ListMember":145}],140:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Element_1 = require("./Element");
const TweenManager_1 = require("../../tween/TweenManager");
const ViewManager_1 = require("../ViewManager");
const Runtime_1 = require("../../../Runtime");
class ListProgress extends Element_1.default {
constructor() {
super(...arguments);
this._type = ListProgress.DEFAULT_TYPE;
this._progressDisplay = null;
this._backgroundDisplay = null;
this._pageIndex = -1;
this._pagesCount = -1;
this._cornerRadius = 0;
}
static get DEFAULT_TYPE() { return 'ListProgress'; }
assignConfig(configData) {
super.assignConfig(configData);
this._listProgressOptions = {
width: ListProgress.DEFAULT_WIDTH,
height: ListProgress.DEFAULT_HEIGHT,
backgroundColor: ListProgress.BACKGROUND_COLOR,
progressColor: ListProgress.PROGRESS_COLOR
};
Object.assign(this._listProgressOptions, configData || {});
this._cornerRadius = this._listProgressOptions.height / 2;
if (!this._targetPosition) {
this._targetPosition = new PIXI.Point(this._listProgressOptions.position.x, this._listProgressOptions.position.y);
}
}
setupDisplay(assets) {
this._progressDisplay = new PIXI.Graphics();
this._backgroundDisplay = new PIXI.Graphics();
this.display.addChild(this._backgroundDisplay);
this.display.addChild(this._progressDisplay);
Runtime_1.default.instance.face.plugins.prepare.upload(this._backgroundDisplay);
Runtime_1.default.instance.face.plugins.prepare.upload(this._progressDisplay);
}
updatePage(pageIndex = -1, pagesCount = -1) {
if (this._pageIndex === -1 && pagesCount > 1) {
this.drawBackground();
this.drawProgress(this._listProgressOptions.width / pagesCount);
this.open();
}
else {
TweenManager_1.default.stop(this._progressDisplay);
if (pagesCount === 1 && this._pagesCount > pagesCount) {
this.close(() => {
this._pagesCount = -1;
this._pageIndex = -1;
});
return;
}
else if (pagesCount > 1) {
const pageWidth = this._listProgressOptions.width / pagesCount;
if (pagesCount !== this._pagesCount) {
this.drawProgress(pageWidth);
}
TweenManager_1.default.stop(this._progressDisplay);
TweenManager_1.default.play(this._progressDisplay, {
to: {
x: pageWidth * pageIndex
},
duration: ViewManager_1.default.TRANS_TIME,
ease: 'cubicOut'
});
}
}
this._pageIndex = pageIndex;
this._pagesCount = pagesCount;
}
getHeight() {
return this._listProgressOptions.height;
}
open(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'sineOut') {
TweenManager_1.default.stop(this.display);
TweenManager_1.default.play(this.display, {
to: { alpha: 1 },
from: { alpha: 0 },
duration: duration,
ease: tweenType
}, callback);
}
close(callback, transitionType, duration = ViewManager_1.default.TRANS_TIME, tweenType = 'sineIn') {
TweenManager_1.default.stop(this.display);
TweenManager_1.default.play(this.display, {
to: { alpha: 0 },
duration: duration,
ease: tweenType
}, callback);
}
destroy() {
if (this._progressDisplay) {
TweenManager_1.default.stop(this._progressDisplay);
this._progressDisplay.destroy(true);
this._progressDisplay = null;
}
if (this._backgroundDisplay) {
this._backgroundDisplay.destroy(true);
this._backgroundDisplay = null;
}
super.destroy();
}
drawBackground() {
this._backgroundDisplay.clear();
this._backgroundDisplay.lineStyle(0, this._listProgressOptions.backgroundColor);
this._backgroundDisplay.beginFill(this._listProgressOptions.backgroundColor);
this._backgroundDisplay.arc(this._cornerRadius, this._cornerRadius, this._cornerRadius, PIXI.DEG_TO_RAD * 90, PIXI.DEG_TO_RAD * 270);
this._backgroundDisplay.drawRect(this._cornerRadius, 0, this._listProgressOptions.width - this._listProgressOptions.height, this._listProgressOptions.height);
this._backgroundDisplay.arc(this._listProgressOptions.width - this._cornerRadius, this._cornerRadius, this._cornerRadius, PIXI.DEG_TO_RAD * 90, PIXI.DEG_TO_RAD * 270, true);
this._backgroundDisplay.endFill();
}
drawProgress(pageWidth = 0) {
this._progressDisplay.clear();
this._progressDisplay.lineStyle(0, this._listProgressOptions.progressColor);
this._progressDisplay.beginFill(this._listProgressOptions.progressColor);
this._progressDisplay.arc(this._cornerRadius, this._cornerRadius, this._cornerRadius, PIXI.DEG_TO_RAD * 90, PIXI.DEG_TO_RAD * 270);
this._progressDisplay.drawRect(this._cornerRadius, 0, pageWidth - this._listProgressOptions.height, this._listProgressOptions.height);
this._progressDisplay.arc(pageWidth - this._cornerRadius, this._cornerRadius, this._cornerRadius, PIXI.DEG_TO_RAD * 90, PIXI.DEG_TO_RAD * 270, true);
this._progressDisplay.endFill();
}
}
ListProgress.DEFAULT_WIDTH = 1190;
ListProgress.DEFAULT_HEIGHT = 10;
ListProgress.BACKGROUND_COLOR = 0x21202b;
ListProgress.PROGRESS_COLOR = 0x37364a;
exports.default = ListProgress;
},{"../../../Runtime":1,"../../tween/TweenManager":174,"../ViewManager":127,"./Element":136}],141:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const StandardButton_1 = require("./StandardButton");
const Timeline_1 = require("../../animation/Timeline");
const TweenManager_1 = require("../../tween/TweenManager");
const ActionData_1 = require("../actions/ActionData");
const Runtime_1 = require("../../../Runtime");
const path = require("path");
const log_1 = require("./log");
const log = log_1.default.createChild('MenuButton');
exports.Colors = {
DEFAULT: 'default',
CONFIRM: 'confirm',
CANCEL: 'cancel'
};
const DEFAULT_COLORS = {
[exports.Colors.DEFAULT]: [0x25F2FB, 0x107799],
[exports.Colors.CONFIRM]: [0xA3FF4A, 0x2A7922],
[exports.Colors.CANCEL]: [0xFD362F, 0x990024]
};
class MenuButton extends StandardButton_1.default {
constructor() {
super(...arguments);
this._type = MenuButton.SKILL;
this.label = '';
this.timelineId = '';
this.iconMovieClip = null;
this.iconId = '';
this._dimensions = null;
this._colors = null;
this._buttonDatas = {
[MenuButton.SKILL]: {
assetPath: 'core://resources/buttons/skillButton.js',
dimensions: { width: 330, height: 300 }
},
[MenuButton.ACTION]: {
assetPath: 'core://resources/buttons/actionButton.js',
dimensions: { width: 264, height: 264 }
},
[MenuButton.ACTION_BIG]: {
assetPath: 'core://resources/buttons/bigActionButton.js',
dimensions: { width: 330, height: 330 }
}
};
}
static get DEFAULT_TYPE() { return 'SkillButton'; }
static get SKILL() { return 'SkillButton'; }
static get ACTION() { return 'ActionButton'; }
static get ACTION_BIG() { return 'ActionBigButton'; }
get dimensions() {
return this._dimensions;
}
static createFromConfig(configData) {
let btn = new MenuButton();
btn.assignConfig(configData);
return btn;
}
get colors() { return this._colors; }
set colors(value) {
if (typeof value === 'string') {
this._colors = DEFAULT_COLORS[value];
}
else {
this._colors = value;
}
if (!this._colors) {
this._colors = DEFAULT_COLORS[exports.Colors.DEFAULT];
}
this.applyColors();
}
getButtonData(type) {
return this._buttonDatas[type];
}
addButtonData(type, assetPath, dimensions, cache) {
const buttonData = {
assetPath: assetPath,
dimensions: dimensions,
cache: cache
};
this._buttonDatas[type] = buttonData;
return buttonData;
}
assignConfig(configData) {
if (configData) {
super.assignConfig(configData);
if (configData.hasOwnProperty('colors')) {
this.colors = configData.colors;
}
if (configData.hasOwnProperty('label')) {
this.label = configData.label;
}
if (configData.iconSrc) {
this.iconId = configData.iconSrc;
if (this.iconId.endsWith(".js")) {
this.addAssetDescriptor(this.iconId, configData.iconSrc, 'timeline', true);
}
else {
this.addAssetDescriptor(this.iconId, configData.iconSrc, 'texture');
}
}
let assetDescriptor;
let descriptorClone;
for (let i = 0; this._assetDescriptors && i < this._assetDescriptors.length; i++) {
assetDescriptor = this._assetDescriptors[i];
if (assetDescriptor.id === 'icon') {
this.iconId = assetDescriptor.src;
descriptorClone = JSON.parse(JSON.stringify(this._assetDescriptors[i]));
descriptorClone.id = this.iconId;
this._assetDescriptors[i] = descriptorClone;
}
}
}
this.applyButtonType();
}
applyButtonType(type) {
if (type) {
this._type = type;
}
const buttonData = this._buttonDatas[this._type];
const src = buttonData.assetPath;
this.timelineId = path.parse(src).name;
super.addAssetDescriptorObject({
id: this.timelineId,
src: src,
type: 'timeline',
cache: buttonData.cache
});
this._dimensions = buttonData.dimensions;
this.addAction(ActionData_1.default.SOUND, { id: 'button' }, false, true);
}
setupDisplay(assets) {
this.setupTimeline(assets);
this.setupHitArea();
this.setupInteractions();
}
setupTimeline(assets) {
if (assets.hasOwnProperty(this.timelineId)) {
let movieClip = new assets[this.timelineId].library.stage();
this._content = movieClip['content'];
if (this._content) {
this.applyColors();
if (assets.hasOwnProperty(this.iconId)) {
if (assets[this.iconId] instanceof Timeline_1.default) {
this.iconMovieClip = assets[this.iconId].instance;
if (!this.iconMovieClip) {
this.iconMovieClip = new assets[this.iconId].library.stage();
Runtime_1.default.instance.face.plugins.prepare.upload(this.iconMovieClip);
}
this.iconMovieClip.gotoAndStop(0);
this.setIcon(this.iconMovieClip);
}
else {
this.setIcon(new PIXI.Sprite(assets[this.iconId]));
}
}
else if (this.iconId) {
log.warn('createDisplay() icon with id of: ' + this.iconId + ' not found in assets.');
}
this.display.addChild(movieClip);
Runtime_1.default.instance.face.plugins.prepare.upload(this._content);
}
else {
log.warn('createDisplay() MovieClip with instance name content not found in timeline');
}
}
else {
log.warn('createDisplay() timeline asset of id ' + this.timelineId + ' not found in assets');
}
}
setIcon(icon) {
if (this._content) {
const iconContainer = this._content['icon'];
if (iconContainer) {
super.addToContent(icon, iconContainer, true);
}
}
}
setupHitArea(bounds) {
if (!bounds && !this._hitArea && this._dimensions) {
bounds = new PIXI.Rectangle(0, 0, this._dimensions.width, this._dimensions.height);
}
super.setupHitArea(bounds);
}
destroy() {
this._dimensions = null;
this._colors = null;
this._buttonDatas = null;
if (this.iconMovieClip) {
TweenManager_1.default.stop(this.iconMovieClip);
this.iconMovieClip = null;
}
super.destroy();
}
applyColors() {
if (this._content && this._colors) {
if (this._content['background']) {
this._content['background'].children[0].tint = this._colors[0];
}
if (this._content['gradient']) {
this._content['gradient'].children[0].tint = this._colors[1];
}
}
}
}
exports.default = MenuButton;
},{"../../../Runtime":1,"../../animation/Timeline":105,"../../tween/TweenManager":174,"../actions/ActionData":130,"./StandardButton":142,"./log":144,"path":undefined}],142:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Button_1 = require("./Button");
const TweenManager_1 = require("../../tween/TweenManager");
const Runtime_1 = require("../../../Runtime");
const async = require("async");
const log_1 = require("./log");
const log = log_1.default.createChild('StandardButton');
class StandardButton extends Button_1.default {
constructor() {
super(...arguments);
this._type = StandardButton.DEFAULT_TYPE;
this._content = null;
this.downScale = .9;
this.activateScale = 1.15;
this.tweenTime = 300;
this.willToggle = false;
this.disableStateAnimations = false;
this._toggledOn = false;
this.toggleAnimate = () => { };
}
static get DEFAULT_TYPE() { return 'StandardButton'; }
static createFromConfig(configData) {
let btn = new StandardButton();
btn.assignConfig(configData);
return btn;
}
static createFromDisplayObject(displayObject, actionData, container = null) {
let btn = new StandardButton();
btn.display = new PIXI.Container();
if (container) {
container.addChild(btn.display);
}
else if (displayObject.parent) {
displayObject.parent.addChild(btn.display);
}
if (actionData) {
btn.addAction(actionData);
}
btn.setupHitArea();
btn.setupInteractions();
btn.display.addChild(displayObject);
return btn;
}
get toggledOn() { return this._toggledOn; }
get buttonDisplay() {
return this._content;
}
assignConfig(configData) {
if (configData) {
super.assignConfig(configData);
if (configData.hasOwnProperty('willToggle')) {
this.willToggle = configData.willToggle;
}
if (configData.hasOwnProperty('toggledOn')) {
this._toggledOn = configData.toggledOn;
}
if (configData.hasOwnProperty('toggleAnimate') && typeof configData.toggleAnimate === 'function') {
this.toggleAnimate = configData.toggleAnimate;
}
if (configData.hasOwnProperty('disableStateAnimations')) {
this.disableStateAnimations = configData.disableStateAnimations;
}
}
}
emptyDisplay() {
if (this._content) {
TweenManager_1.default.stop(this._content);
}
super.emptyDisplay();
}
setupDisplay(assets) {
let asset;
let assetDescriptor;
this._content = new PIXI.Sprite();
let hasTextureAsset = false;
for (let i = 0; i < this._assetDescriptors.length; i++) {
assetDescriptor = this._assetDescriptors[i];
asset = assets[assetDescriptor.id];
if (assetDescriptor.hasOwnProperty('type')) {
switch (assetDescriptor.type) {
case 'texture':
hasTextureAsset = true;
let sprite = new PIXI.Sprite(asset);
this.addToContent(sprite, this._content);
break;
case 'timeline':
let movieClip = new asset.library.stage();
this.addToContent(movieClip, this._content);
if (assetDescriptor.upload) {
Runtime_1.default.instance.face.plugins.prepare.upload(movieClip);
}
break;
default:
log.debug('setupDisplay() will not setup for asset type: ' + asset.type);
}
}
else {
log.debug('Button :: assignAssets() no type given for asset: ' + asset + ', assuming bitmap');
let sprite = PIXI.Sprite.from(asset);
this.addToContent(sprite, this._content);
}
}
if (hasTextureAsset) {
const bounds = this._content.getBounds();
this._content.x += bounds.width / 2;
this._content.y += bounds.height / 2;
}
this.display.addChild(this._content);
if (this.willToggle) {
this.toggleAnimate(this._toggledOn, false);
}
this.setupHitArea();
this.setupInteractions();
}
addToContent(asset, container, emptyContent = false) {
container = (container) ? container : this._content;
if (container) {
if (emptyContent) {
container.removeChildren();
}
if (asset instanceof PIXI.Sprite) {
asset.anchor.x = 0.5;
asset.anchor.y = 0.5;
}
container.addChild(asset);
}
}
destroy() {
if (this._content) {
TweenManager_1.default.stop(this._content);
this._content = null;
}
super.destroy();
}
toggle(toggleOn, animate = true) {
this._toggledOn = toggleOn;
this.toggleAnimate(this._toggledOn, animate);
}
activate() {
TweenManager_1.default.stop(this._content);
TweenManager_1.default.play(this._content, {
to: {
'scale.x': this.activateScale,
'scale.y': this.activateScale
},
duration: this.tweenTime,
ease: 'sineOut'
}, () => {
TweenManager_1.default.play(this._content, {
to: {
'scale.x': 1,
'scale.y': 1
},
duration: this.tweenTime,
ease: 'backOut'
});
});
}
out() {
if (this.isDown) {
this.isDown = false;
this.executeAsyncTransitions([
() => {
if (!this.disableStateAnimations) {
this.outTransition();
}
},
() => {
if (this.willToggle) {
this.toggleOutTransition();
}
}
]);
}
}
outTransition() {
this.animateUp();
}
toggleOutTransition() {
this.toggleAnimate(this._toggledOn, true);
}
down() {
if (!this.isDown) {
this.isDown = true;
this.executeAsyncTransitions([
() => {
if (!this.disableStateAnimations) {
this.downTransition();
}
},
() => {
if (this.willToggle) {
this.toggleDownTransition();
}
}
]);
}
}
downTransition() {
this.animateDown();
}
toggleDownTransition() {
this.toggleAnimate(!this._toggledOn, true);
}
up() {
if (this.isDown) {
this.isDown = false;
this.executeAsyncTransitions([
() => {
if (!this.disableStateAnimations) {
this.upTransition();
}
},
() => {
if (this.willToggle) {
this.toggleUpTransition();
}
}
]);
}
}
upTransition() {
this.animateUp();
}
toggleUpTransition() {
this.toggle(!this._toggledOn, true);
}
animateDown() {
TweenManager_1.default.stop(this._content);
TweenManager_1.default.play(this._content, {
to: {
'scale.x': this.downScale,
'scale.y': this.downScale
},
duration: this.tweenTime,
ease: 'backOut'
});
}
animateUp() {
TweenManager_1.default.stop(this._content);
TweenManager_1.default.play(this._content, {
to: {
'scale.x': 1,
'scale.y': 1
},
duration: this.tweenTime / 2,
ease: 'backOut'
});
}
executeAsyncTransitions(transitionArray, callback) {
async.parallel(transitionArray, function (err, results) {
if (err) {
log.error('Transitions encountered error', err);
}
this.transitionComplete(callback, err, results);
}.bind(this));
}
}
exports.default = StandardButton;
},{"../../../Runtime":1,"../../tween/TweenManager":174,"./Button":132,"./log":144,"async":undefined}],143:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Button_1 = require("./Button");
const StandardButton_1 = require("./StandardButton");
const Clip_1 = require("./Clip");
const ContactButton_1 = require("./ContactButton");
const ContentButton_1 = require("./ContentButton");
const Element_1 = require("./Element");
const ElementGroup_1 = require("./ElementGroup");
const Label_1 = require("./Label");
const List_1 = require("./List");
const ListProgress_1 = require("./ListProgress");
const MenuButton_1 = require("./MenuButton");
exports.default = {
Button: Button_1.default,
StandardButton: StandardButton_1.default,
Clip: Clip_1.default,
ContactButton: ContactButton_1.default,
ContentButton: ContentButton_1.default,
Element: Element_1.default,
ElementGroup: ElementGroup_1.default,
Label: Label_1.default,
List: List_1.default,
ListProgress: ListProgress_1.default,
MenuButton: MenuButton_1.default
};
},{"./Button":132,"./Clip":133,"./ContactButton":134,"./ContentButton":135,"./Element":136,"./ElementGroup":137,"./Label":138,"./List":139,"./ListProgress":140,"./MenuButton":141,"./StandardButton":142}],144:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
const log = log_1.default.createChild('Components');
exports.default = log;
},{"../log":149}],145:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Subcomponent_1 = require("./Subcomponent");
class ListMember extends Subcomponent_1.default {
constructor() {
super(ListMember.TYPE);
this.targetPosition = null;
this.velocity = null;
this.targetOffset = null;
this.loaded = false;
}
static get TYPE() { return 'ListMember'; }
}
exports.default = ListMember;
},{"./Subcomponent":146}],146:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Subcomponent {
constructor(type) {
this.component = null;
this._type = type;
}
static get TYPE() { return 'TouchInteractive'; }
get type() { return this._type; }
init(component) {
this.component = component;
}
destroy() {
if (this.component) {
this.component = null;
}
}
}
exports.default = Subcomponent;
},{}],147:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../../../Runtime");
const TouchManager_1 = require("../../TouchManager");
const Subcomponent_1 = require("./Subcomponent");
class TouchInteractive extends Subcomponent_1.default {
constructor() {
super(TouchInteractive.TYPE);
this.isActive = false;
this._gestureActions = null;
this._gestureActions = {};
}
static get TYPE() { return 'TouchInteractive'; }
destroy() {
super.destroy();
this._gestureActions = null;
}
addAction(actionData, clearPrevious = false, toFront = false, gesture = TouchManager_1.GESTURE.TAP) {
if (!this._gestureActions[gesture]) {
this._gestureActions[gesture] = [];
}
else if (clearPrevious) {
this._gestureActions[gesture].length = 0;
}
if (toFront) {
this._gestureActions[gesture].unshift(actionData);
}
else {
this._gestureActions[gesture].push(actionData);
}
TouchManager_1.default.instance.addGesture(gesture);
return actionData;
}
hasActions(gesture = TouchManager_1.GESTURE.TAP) {
return (this._gestureActions[gesture] && this._gestureActions[gesture].length > 0);
}
getActions(gesture = TouchManager_1.GESTURE.TAP) {
return this._gestureActions[gesture];
}
clearActions(gesture = TouchManager_1.GESTURE.TAP) {
delete this._gestureActions[gesture];
}
triggerActions(gesture = TouchManager_1.GESTURE.TAP) {
let length = 0;
if (this._gestureActions[gesture]) {
if (this.component.parentGroup) {
const actions = this._gestureActions[gesture];
length = actions.length;
for (let i = 0; i < length; i++) {
this.component.parentGroup.actionHandler(actions[i], this.component);
}
}
else if (this.component instanceof Runtime_1.default.instance.face.views.View) {
const actions = this._gestureActions[gesture];
length = actions.length;
for (let i = 0; i < length; i++) {
this.component.actionHandler(actions[i], this.component);
}
}
}
return length > 0;
}
}
exports.default = TouchInteractive;
},{"../../../../Runtime":1,"../../TouchManager":125,"./Subcomponent":146}],148:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ViewManager_1 = require("./ViewManager");
const ViewProcess_1 = require("./ViewProcess");
const ViewState_1 = require("./ViewState");
const ComponentCreator_1 = require("./ComponentCreator");
const components_1 = require("./components");
const views_1 = require("./views");
const actions_1 = require("./actions");
const TouchManager_1 = require("./TouchManager");
exports.default = {
ViewManager: ViewManager_1.default,
TRANSITION: ViewManager_1.TRANSITION,
ViewProcess: ViewProcess_1.default,
ViewState: ViewState_1.default,
ComponentCreator: ComponentCreator_1.default,
components: components_1.default,
views: views_1.default,
actions: actions_1.default,
TouchManager: TouchManager_1.default,
GESTURE: TouchManager_1.GESTURE
};
},{"./ComponentCreator":122,"./TouchManager":125,"./ViewManager":127,"./ViewProcess":128,"./ViewState":129,"./actions":131,"./components":143,"./views":157}],149:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../../log");
exports.default = log_1.default.createChild('GUI');
},{"../../log":75}],150:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../../Runtime");
const MenuView_1 = require("./MenuView");
const ContactButton_1 = require("../components/ContactButton");
const MenuButton_1 = require("../components/MenuButton");
const ActionData_1 = require("../actions/ActionData");
const View_1 = require("./View");
const log_1 = require("./log");
const log = log_1.default.createChild('ContatcsView');
class ContactsView extends MenuView_1.default {
constructor() {
super(...arguments);
this.sortLoopList = null;
this.determineCheck = null;
this._type = ContactsView.DEFAULT_TYPE;
this.showNotALoopMemberButton = false;
this._loopMembers = null;
}
static get DEFAULT_TYPE() { return 'ContactsView'; }
applyData() {
if (this._viewConfig) {
if (typeof this._viewConfig.sortLoopList === 'function') {
this.sortLoopList = this._viewConfig.sortLoopList;
}
if (this._viewConfig.hasOwnProperty('showNotALoopMemberButton')) {
this.showNotALoopMemberButton = this._viewConfig.showNotALoopMemberButton;
}
}
super.applyData();
}
destroy() {
this._loopMembers = null;
this.sortLoopList = null;
this.showNotALoopMemberButton = false;
this.determineCheck = null;
super.destroy();
}
loadData(loadAssetsOnComplete = true) {
if (!this._loopMembers) {
Runtime_1.default.instance.kb.loop.loadLoop((err, loop) => {
if (err) {
log.error('loadData() : kb.loop.loadLoop return an error', err);
this.emit(View_1.STATE.LOAD_ERROR);
return;
}
if (loop) {
this._loopMembers = loop;
super.loadData(loadAssetsOnComplete);
}
else {
log.error('loadData() : kb.loop.loadLoop return loop as null');
this.emit(View_1.STATE.LOAD_ERROR);
return;
}
});
}
else {
super.loadData(loadAssetsOnComplete);
}
}
createListComponents(list) {
if (this.showNotALoopMemberButton) {
const notInLoopButton = MenuButton_1.default.createFromConfig({
type: MenuButton_1.default.ACTION_BIG,
id: 'notInLoop',
label: 'Not a Loop\nMember',
colors: MenuButton_1.Colors.DEFAULT,
iconSrc: 'core://resources/actionIcons/not-in-loop.png',
action: {
type: ActionData_1.default.UTTERANCE,
data: {
utterance: 'notInLoop'
}
}
});
list.addComponent(notInLoopButton);
}
if (this._loopMembers) {
let loopList = this._loopMembers;
if (!this.sortLoopList) {
this.sortLoopList = this.removeInvalidLoopers;
}
loopList = this.sortLoopList(loopList);
let willToggle = false;
if (this._viewConfig && this._viewConfig.hasOwnProperty('listDefault')) {
if (this._viewConfig.listDefault.hasOwnProperty('willToggle')) {
willToggle = this._viewConfig.listDefault.willToggle;
}
}
const length = loopList.length;
let contactButton;
let looper;
let i;
for (i = 0; i < length; i++) {
looper = loopList[i];
contactButton = new ContactButton_1.default();
contactButton.assignLooper(looper);
if (this.determineCheck) {
contactButton.toggle(this.determineCheck(looper));
}
contactButton.willToggle = willToggle;
contactButton.applyButtonType();
list.addComponent(contactButton);
}
}
}
removeInvalidLoopers(loopList) {
if (loopList) {
const length = loopList.length;
let i = length - 1;
for (i; i >= 0; i--) {
if (loopList[i].isJibo || !loopList[i].data.hasOwnProperty('firstName')) {
loopList.splice(i, 1);
}
}
}
return loopList;
}
}
exports.default = ContactsView;
},{"../../../Runtime":1,"../actions/ActionData":130,"../components/ContactButton":134,"../components/MenuButton":141,"./MenuView":153,"./View":156,"./log":158}],151:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const View_1 = require("./View");
const ViewManager_1 = require("../ViewManager");
const Runtime_1 = require("../../../Runtime");
class EyeView extends View_1.default {
constructor() {
super();
this._type = EyeView.DEFAULT_TYPE;
this.id = 'eyeView';
this.soundSet = 'main';
this._category = View_1.CATEGORY.EYE;
this.borderNeeded = false;
this.closeOnSwipeDown = false;
}
static get DEFAULT_TYPE() { return 'EyeView'; }
open(callback, transitionType) {
if (transitionType !== ViewManager_1.TRANSITION.NONE) {
transitionType = ViewManager_1.TRANSITION.IN;
}
this._showEye();
super.open(callback, transitionType);
}
pause(flag = true, pauseOptions) {
super.pause(flag, pauseOptions);
if (!flag) {
this._showEye();
}
}
close(callback, transitionType) {
if (transitionType !== ViewManager_1.TRANSITION.NONE) {
transitionType = ViewManager_1.TRANSITION.OUT;
}
super.close(callback, transitionType);
}
_showEye() {
const eye = Runtime_1.default.instance.face.eye;
this.stage.addChild(eye);
eye.active = true;
}
}
exports.default = EyeView;
},{"../../../Runtime":1,"../ViewManager":127,"./View":156}],152:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const View_1 = require("./View");
const Clip_1 = require("../components/Clip");
const FaceRenderer_1 = require("../../FaceRenderer");
const Runtime_1 = require("../../../Runtime");
class ImageView extends View_1.default {
constructor() {
super();
this.scaleToFit = true;
this._type = ImageView.DEFAULT_TYPE;
this._clip = null;
}
static get DEFAULT_TYPE() { return 'ImageView'; }
get clip() {
return this._clip;
}
assignConfig(viewConfig) {
if (viewConfig) {
super.assignConfig(viewConfig);
if (viewConfig['scaleToFit']) {
this.scaleToFit = viewConfig['scaleToFit'];
}
if (viewConfig['image']) {
this.imageDescriptor = viewConfig['image'];
}
}
}
applyData() {
this._clip = new Clip_1.default();
if (this.imageDescriptor) {
this._clip.addAssetDescriptorObject(this.imageDescriptor);
}
this.addComponent(this._clip);
}
loaded() {
super.createDisplay(this._stage, this._assets);
this.positionClip();
Runtime_1.default.instance.face.plugins.prepare.upload(this.ready.bind(this));
}
destroy() {
this._clip = null;
super.destroy();
}
positionClip() {
let xCoord = FaceRenderer_1.default.WIDTH / 2;
let yCoord = FaceRenderer_1.default.HEIGHT / 2;
let display = this._clip.display;
let ratio = display.width / display.height;
let screenRatio = FaceRenderer_1.default.WIDTH / FaceRenderer_1.default.HEIGHT;
let width;
let height;
if (display.width > FaceRenderer_1.default.WIDTH || display.height > FaceRenderer_1.default.HEIGHT) {
if (display.width > FaceRenderer_1.default.WIDTH) {
width = FaceRenderer_1.default.WIDTH;
height = width / ratio;
}
if (display.height > FaceRenderer_1.default.HEIGHT) {
height = FaceRenderer_1.default.HEIGHT;
width = height * ratio;
}
}
else {
if (this.scaleToFit) {
if (ratio > screenRatio) {
width = FaceRenderer_1.default.WIDTH;
height = width / ratio;
}
else {
height = FaceRenderer_1.default.HEIGHT;
width = height * ratio;
}
}
else {
width = display.width;
height = display.height;
}
}
xCoord -= width / 2;
yCoord -= height / 2;
let transformData = {
scaleX: width / display.width,
scaleY: height / display.height
};
this._clip.setTargetPosition(xCoord, yCoord);
this._clip.setTransformData = transformData;
this._clip.applyPosition();
}
}
function isImageView(view) {
return view instanceof ImageView;
}
exports.isImageView = isImageView;
exports.default = ImageView;
},{"../../../Runtime":1,"../../FaceRenderer":99,"../components/Clip":133,"./View":156}],153:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const View_1 = require("./View");
const Label_1 = require("../components/Label");
const MenuButton_1 = require("../components/MenuButton");
const List_1 = require("../components/List");
const ListProgress_1 = require("../components/ListProgress");
const FaceRenderer_1 = require("../../FaceRenderer");
const Runtime_1 = require("../../../Runtime");
const ViewManager_1 = require("../ViewManager");
const EyeView_1 = require("./EyeView");
const log_1 = require("./log");
const log = log_1.default.createChild('MenuView');
class MenuView extends View_1.default {
constructor() {
super(...arguments);
this._type = MenuView.DEFAULT_TYPE;
this._title = null;
this._list = null;
this._listProgress = null;
this._buttonLabels = null;
}
static get DEFAULT_TYPE() { return 'MenuView'; }
get list() {
return this._list;
}
get titleLabel() {
return this._title;
}
assignConfig(viewConfig) {
if (viewConfig) {
super.assignConfig(viewConfig);
if (viewConfig['useEyeTransitions']) {
this.addEyeTransitions();
}
}
}
applyData() {
this._list = new List_1.default();
this.addComponent(this._list);
this.createListComponents(this._list);
const menuButton = this._list.getComponentByIndex(0);
const listConfig = (this._viewConfig) ? Object.assign({}, this._viewConfig) : {};
listConfig.id = 'list';
listConfig.type = List_1.default.DEFAULT_TYPE;
if (!listConfig.elementsPerPage) {
listConfig.elementsPerPage = 3;
}
if (!listConfig.elementDimensions && menuButton) {
listConfig.elementDimensions = menuButton.dimensions;
}
delete listConfig.title;
delete listConfig.assets;
delete listConfig.list;
if (this._viewConfig) {
if (this._viewConfig.title) {
this._title = new Label_1.default();
this._title.id = 'title';
this._title.text = this._viewConfig.title;
this._title.style = Label_1.default.createFontStyle(100, 'Proxima Nova Soft', '#FFFFFF', 'bold');
this._title.bounds = { width: FaceRenderer_1.default.WIDTH - (MenuView.TITLE_MARGIN * 2), height: MenuView.TITLE_HEIGHT };
this.addComponent(this._title);
}
if (this._viewConfig.hasOwnProperty('progress') && this._viewConfig.progress) {
this._listProgress = new ListProgress_1.default();
this.addComponent(this._listProgress);
let listProgressConfig = typeof this._viewConfig.progress === 'object' ? this._viewConfig.progress : {};
if (!listProgressConfig.hasOwnProperty('position')) {
Object.assign(listProgressConfig, {
position: {
x: 'LEFT',
y: 'BOTTOM',
margin: {
x: MenuView.LISTPROGRESS_LEFT_MARGIN,
y: MenuView.LISTPROGRESS_BOTTOM_MARGIN
}
}
});
}
this._listProgress.assignConfig(listProgressConfig);
}
}
this._list.assignConfig(listConfig);
if (menuButton && menuButton.hasOwnProperty('label')) {
this._buttonLabels = [];
let buttonLabel;
for (let i = 0; i < this._list.elementsPerPage; i++) {
buttonLabel = new Label_1.default();
buttonLabel.id = 'buttonLabel' + i;
buttonLabel.style = Label_1.default.createFontStyle(50, 'Proxima Nova Light', '#FFFFFF', '', 'center');
buttonLabel.bounds = { width: listConfig.elementDimensions.width, height: MenuView.LABEL_HEIGHT };
this.addComponent(buttonLabel);
this._buttonLabels.push(buttonLabel);
}
}
}
createListComponents(list) {
if (this._viewConfig) {
const defaultElementData = this._viewConfig.listDefault || {};
const componentType = defaultElementData.menuButtonType || MenuButton_1.default.ACTION;
if (!defaultElementData.type) {
defaultElementData.type = componentType;
}
list.createComponentsFromConfigs(this._viewConfig.list, defaultElementData);
}
else {
log.warn('createListComponents() this._viewConfig was not defined, but is required.');
}
}
addEyeTransitions() {
this.addTransition(EyeView_1.default.DEFAULT_TYPE, true, this.openFromEye, ViewManager_1.TRANSITION.NONE);
this.addTransition(EyeView_1.default.DEFAULT_TYPE, false, this.closeToEye, ViewManager_1.TRANSITION.NONE);
}
loaded() {
this.positionComponents();
super.createDisplay(this._stage, this._assets);
if (this._listProgress) {
this._listProgress.updatePage(this._list.pageIndex, this._list.getPagesCount());
}
this.updateButtonLabels(false, false);
Runtime_1.default.instance.face.plugins.prepare.upload(this.ready.bind(this));
}
destroy() {
this._title = null;
this._list = null;
this._listProgress = null;
this._buttonLabels = null;
super.destroy();
}
actionHandler(action, fromComponent) {
if (!this._inputLocked) {
switch (action.type) {
case List_1.default.PAGED:
if (this._listProgress) {
this._listProgress.updatePage(this._list.pageIndex, this._list.getPagesCount());
}
this.updateButtonLabels();
return;
case List_1.default.REMOVE_ELEMENT:
if (this._listProgress) {
this._listProgress.updatePage(this._list.pageIndex, this._list.getPagesCount());
}
this.updateButtonLabels(this._buttonLabels &&
(this._list.elementsPerPage < this._buttonLabels.length || (this._list.elementsPerPage === 1 && this._buttonLabels.length === 1)));
return;
case List_1.default.PAN:
this.fadeOutButtonLabels();
return;
}
super.actionHandler(action, fromComponent);
}
}
openFromEye(callback) {
let i;
const numChildren = this._stage.children.length;
for (i = 0; i < numChildren; i++) {
this._stage.children[i].visible = false;
}
const eye = Runtime_1.default.instance.face.eye;
this._stage.addChild(eye);
eye.active = false;
eye.visible = true;
const duration = ViewManager_1.default.TRANS_TIME * .7;
super.transitionFadeOutTo(() => {
this._stage.removeChild(eye);
eye.active = false;
for (i = 0; i < numChildren; i++) {
this._stage.children[i].visible = true;
}
super.openChildren(callback, ViewManager_1.TRANSITION.EYE, ViewManager_1.default.TRANS_TIME * .5);
this.updateButtonLabels(false, false);
}, 1.1, .8, .6, duration);
}
closeToEye(callback) {
const duration = ViewManager_1.default.TRANS_TIME * .7;
log.info('closeToEye() duration: ' + duration);
super.closeChildren(() => {
log.info('closeToEye() children closed successfully, start eye transition');
this.eyeOpenTransition(callback, duration);
}, ViewManager_1.TRANSITION.EYE, ViewManager_1.default.TRANS_TIME * .5);
}
updateConfig(configObject) {
if (this._list.stateChanged) {
configObject = this._list.updateConfig(configObject);
}
return super.updateConfig(configObject);
}
positionComponents(overrideTitleHeight) {
let titleTotalHeight = 0;
const titleBuffer = this._listProgress ? MenuView.TITLE_BUFFER - 25 : MenuView.TITLE_BUFFER;
if (overrideTitleHeight) {
titleTotalHeight = overrideTitleHeight + titleBuffer;
}
else if (this._title) {
titleTotalHeight = +this._title.getTextDimensions('Flat').height + titleBuffer;
}
let menuLabelTotalHeight = 0;
if (this._buttonLabels) {
menuLabelTotalHeight = +this._buttonLabels[0].getTextDimensions('Flat').height / 2 + MenuView.MENU_LABEL_BUFFER;
}
const groupBuffer = (FaceRenderer_1.default.HEIGHT - (+titleTotalHeight + +this._list.elementDimensions.height + +menuLabelTotalHeight)) / 2;
if (this._title) {
this._title.setTargetPosition(FaceRenderer_1.default.WIDTH / 2, groupBuffer);
this._title.setTargetAnchor(.5, 0);
}
this._list.axisPosition = +groupBuffer + +titleTotalHeight + (this._list.elementDimensions.height / 2);
if (this._listProgress) {
this._listProgress.targetPosition.y -= this._listProgress.getHeight();
}
this.positionButtonLabels();
}
positionButtonLabels() {
if (this._buttonLabels) {
const buttonLabelY = this._list.axisPosition + this._list.elementDimensions.height / 2 + MenuView.MENU_LABEL_BUFFER;
let buttonLabel;
for (let i = 0; i < this._buttonLabels.length; i++) {
buttonLabel = this._buttonLabels[i];
buttonLabel.setTargetPosition(+this._list.listStartPosition.x + (i * this._list.elementSpacing) + this._list.elementDimensions.width / 2, buttonLabelY, true);
buttonLabel.setTargetAnchor(.5, .5);
}
}
}
updateButtonLabels(labelRemovalNeeded = false, playTransition = true, duration = 200) {
if (!this._buttonLabels) {
return;
}
if (labelRemovalNeeded) {
let component = this.removeComponent(this._buttonLabels.pop());
if (component) {
component.destroy();
component = null;
}
}
this.positionButtonLabels();
const buttonComponents = this._list.getElementsByPage();
const length = buttonComponents.length;
if (playTransition) {
for (let i = 0; i < length; i++) {
let menuBtn = buttonComponents[i];
let buttonLabel = this._buttonLabels[i];
if (buttonLabel.text !== menuBtn.label) {
if (buttonLabel.display.alpha === 1) {
buttonLabel.close(() => {
buttonLabel.text = menuBtn.label;
buttonLabel.open(null, null, duration);
}, null, duration);
}
else {
buttonLabel.text = menuBtn.label;
buttonLabel.open(null, null, duration);
}
}
else if (buttonLabel.display.alpha < 1) {
buttonLabel.open(null, null, duration);
}
}
}
else {
for (let i = 0; i < length; i++) {
this._buttonLabels[i].text = buttonComponents[i].label;
}
}
}
fadeOutButtonLabels(duration = 100) {
if (!this._buttonLabels) {
return;
}
const buttonComponents = this._list.getElementsByPage();
const length = buttonComponents.length;
for (let i = 0; i < length; i++) {
let buttonLabel = this._buttonLabels[i];
buttonLabel.close(null, null, duration, 'sineInOut');
}
}
eyeOpenTransition(callback, duration) {
log.info('eyeOpenTransition() duration: ' + duration);
const eye = Runtime_1.default.instance.face.eye;
this._stage.addChild(eye);
eye.active = false;
eye.visible = true;
super.transitionFadeInFrom(callback, 1.1, .8, .6, duration);
}
}
MenuView.LISTPROGRESS_LEFT_MARGIN = 45;
MenuView.LISTPROGRESS_BOTTOM_MARGIN = 40;
MenuView.TITLE_MARGIN = 80;
MenuView.TITLE_BUFFER = 100;
MenuView.TITLE_HEIGHT = 160;
MenuView.LABEL_HEIGHT = 120;
MenuView.MENU_LABEL_BUFFER = 60;
function isMenuView(view) {
return view instanceof MenuView;
}
exports.isMenuView = isMenuView;
exports.default = MenuView;
},{"../../../Runtime":1,"../../FaceRenderer":99,"../ViewManager":127,"../components/Label":138,"../components/List":139,"../components/ListProgress":140,"../components/MenuButton":141,"./EyeView":151,"./View":156,"./log":158}],154:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const TweenManager_1 = require("../../tween/TweenManager");
const FaceRenderer_1 = require("../../FaceRenderer");
const ViewManager_1 = require("../ViewManager");
class PauseOverlay {
constructor(options) {
this.alpha = .7;
this.duration = ViewManager_1.default.TRANS_TIME;
this.type = 'sineOut';
this._isOpen = false;
if (options) {
this.applyOptions(options);
}
else {
this.applyDefaults();
}
}
applyOptions(options) {
if (options.hasOwnProperty('alpha')) {
this.alpha = options.alpha;
}
if (options.hasOwnProperty('duration')) {
this.duration = options.duration;
}
if (options.hasOwnProperty('type')) {
this.type = options.type;
}
}
applyDefaults() {
this.alpha = .7;
this.duration = ViewManager_1.default.TRANS_TIME;
this.type = 'sineOut';
}
open(container) {
if (!this._isOpen) {
this._isOpen = true;
if (!this._overlay) {
this._overlay = new PIXI.Graphics();
this._overlay.beginFill(0x000000);
this._overlay.drawRect(0, 0, FaceRenderer_1.default.WIDTH, FaceRenderer_1.default.HEIGHT);
}
container.addChild(this._overlay);
TweenManager_1.default.stop(this._overlay);
if (this.duration > 0 && this.alpha > 0) {
this._overlay.alpha = 0;
TweenManager_1.default.play(this._overlay, {
to: { alpha: this.alpha },
duration: this.duration,
ease: this.type
});
}
else {
this._overlay.alpha = this.alpha;
}
}
}
close() {
if (this._isOpen) {
this._isOpen = false;
if (this._overlay) {
TweenManager_1.default.stop(this._overlay);
if (this.duration > 0 && this._overlay.alpha > 0) {
TweenManager_1.default.play(this._overlay, {
to: { alpha: 0 },
duration: this.duration,
ease: this.type
}, () => {
this._overlay.parent.removeChild(this._overlay);
});
}
else {
this._overlay.parent.removeChild(this._overlay);
}
}
}
}
destroy() {
if (this._overlay) {
TweenManager_1.default.stop(this._overlay);
if (this._overlay.parent) {
this._overlay.parent.removeChild(this._overlay);
}
this._overlay = null;
}
}
}
exports.default = PauseOverlay;
},{"../../FaceRenderer":99,"../../tween/TweenManager":174,"../ViewManager":127}],155:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const View_1 = require("./View");
const Label_1 = require("../components/Label");
const FaceRenderer_1 = require("../../FaceRenderer");
class TextView extends View_1.default {
constructor() {
super();
this.style = null;
this.margins = null;
this._type = TextView.DEFAULT_TYPE;
this._text = null;
this._label = null;
}
static get DEFAULT_TYPE() { return 'TextView'; }
get text() {
return this._text;
}
set text(message) {
this._text = message;
if (this._label) {
this._label.text = message;
}
}
get label() {
return this._label;
}
assignConfig(viewConfig) {
if (viewConfig) {
super.assignConfig(viewConfig);
if (viewConfig['text']) {
this._text = viewConfig['text'];
}
if (viewConfig.hasOwnProperty('style')) {
this.style = new PIXI.TextStyle(viewConfig.style);
if (this.style.fontSize) {
this.style.fontSize = Number(this.style.fontSize) || this.style.fontSize;
}
}
if (viewConfig.hasOwnProperty('margins')) {
this.margins = { width: Number(viewConfig.margins.width), height: Number(viewConfig.margins.height) };
}
}
}
applyData() {
this._label = new Label_1.default();
this._label.id = 'text';
let style = this.style || TextView.DEFAULT_STYLE.clone();
this.margins = this.margins || { width: TextView.TEXT_MARGIN_X, height: TextView.TEXT_MARGIN_Y };
this._label.bounds = { width: FaceRenderer_1.default.WIDTH - (this.margins.width * 2), height: FaceRenderer_1.default.HEIGHT - (this.margins.height * 2) };
style.wordWrapWidth = this._label.bounds.width;
this._label.style = style;
this._label.text = this._text;
this._label.setTargetPosition(FaceRenderer_1.default.WIDTH / 2, FaceRenderer_1.default.HEIGHT / 2);
this._label.setTargetAnchor(.5, .5);
this.addComponent(this._label);
}
destroy() {
this._text = null;
this._label = null;
super.destroy();
}
}
TextView.DEFAULT_STYLE = new PIXI.TextStyle({
fontSize: 100,
fontFamily: "Proxima Nova Soft",
fill: "#FFFFFF",
fontStyle: 'normal',
wordWrap: true,
align: 'center'
});
TextView.TEXT_MARGIN_X = 80;
TextView.TEXT_MARGIN_Y = 80;
function isTextView(view) {
return view instanceof TextView;
}
exports.isTextView = isTextView;
exports.default = TextView;
},{"../../FaceRenderer":99,"../components/Label":138,"./View":156}],156:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../../Runtime");
const ViewState_1 = require("../ViewState");
const ComponentGroup_1 = require("../ComponentGroup");
const ViewManager_1 = require("../ViewManager");
const TouchManager_1 = require("../TouchManager");
const ActionData_1 = require("../actions/ActionData");
const FaceRenderer_1 = require("../../FaceRenderer");
const TweenManager_1 = require("../../tween/TweenManager");
const PauseOverlay_1 = require("./PauseOverlay");
const ViewGlobalEvents_1 = require("../ViewGlobalEvents");
const log_1 = require("./log");
const log = log_1.default.createChild('View');
var STATE;
(function (STATE) {
STATE["INITIALIZED"] = "initialized";
STATE["DATA_LOADED"] = "data_loaded";
STATE["ASSETS_LOADED"] = "assets_loaded";
STATE["LOADED"] = "loaded";
STATE["OPENED"] = "opened";
STATE["CLOSED"] = "closed";
STATE["DESTROYED"] = "destroyed";
STATE["LOAD_ERROR"] = "load_error";
})(STATE = exports.STATE || (exports.STATE = {}));
var CATEGORY;
(function (CATEGORY) {
CATEGORY["GUI"] = "gui";
CATEGORY["DISPLAY"] = "display";
CATEGORY["EYE"] = "eye";
})(CATEGORY = exports.CATEGORY || (exports.CATEGORY = {}));
class View extends ComponentGroup_1.default {
constructor() {
super();
this.assetManifest = null;
this.pausedParent = null;
this.pauseOverlay = null;
this.closeOnSwipeDown = true;
this.willPauseParent = false;
this.pauseOptions = null;
this.soundSet = 'skill';
this.transitionStageOnly = false;
this.borderNeeded = true;
this.transitionHandler = null;
this.viewStateStacked = false;
this._type = View.DEFAULT_TYPE;
this._category = CATEGORY.GUI;
this._stage = null;
this._viewManager = null;
this._configPath = '';
this._viewConfig = null;
this._status = '';
this._viewState = null;
this._assetLoad = null;
this._loadedAssets = [];
this._assetLoadQueue = null;
this._assetLoadRequests = null;
this._transitionsMap = null;
this._assets = {};
}
static get DEFAULT_TYPE() {
return 'View';
}
static get BACK() {
return 'back';
}
static get EMPTY() {
return 'empty';
}
static get PAUSED() {
return 'paused';
}
get stage() {
return this._stage;
}
get viewManager() {
return this._viewManager;
}
get assets() {
return this._assets;
}
get type() {
return this._type;
}
get state() {
return this._status;
}
get category() {
return this._category;
}
init(viewManager, loadAssetsOnComplete = true) {
this._viewManager = viewManager;
this._stage = new PIXI.Container();
this.status = STATE.INITIALIZED;
this.loadData(loadAssetsOnComplete);
}
loadData(loadAssetsOnComplete = true) {
const proceed = () => {
this.applyData();
this.assetManifest = this.resolveAssetDescriptors(this.assetDescriptors);
this.status = STATE.DATA_LOADED;
if (loadAssetsOnComplete) {
this.loadAssets();
}
};
this.loadConfig()
.then(() => {
proceed();
})
.catch((err) => {
log.error('loadData() failure loading data', err);
this.emit(STATE.LOAD_ERROR);
});
}
loadConfig() {
return new Promise((resolve, reject) => {
if (!this._viewConfig && this._configPath) {
this._assetLoad = Runtime_1.default.instance.loader.load({
src: this._configPath
}, (err, configResult) => {
this._assetLoad = null;
if (err) {
reject(new Error('Error loading config path:' + err.message));
}
else if (configResult) {
if (configResult.hasOwnProperty('viewConfig')) {
this._viewConfig = Object.assign(configResult.viewConfig, this._viewConfig);
this.assignConfig(this._viewConfig);
}
if (configResult.hasOwnProperty('componentConfigs')) {
this.componentConfigs = configResult.componentConfigs;
}
resolve(this);
}
});
}
else {
resolve(this);
}
});
}
applyData() {
super.createComponentsFromConfigs(this.componentConfigs);
}
loadAssets(loadedOnComplete = true) {
if (this.assetManifest && this.assetManifest.length > 0) {
this._assetLoad = Runtime_1.default.instance.loader.load(this.assetManifest, {
complete: (err, results) => {
this._assetLoad = null;
if (err) {
log.error('loadAssets() failure loading assets', err);
this.emit(STATE.LOAD_ERROR);
}
Object.assign(this._assets, results);
this.status = STATE.ASSETS_LOADED;
if (loadedOnComplete) {
this.loaded();
}
},
maxLoads: 1,
autoStart: false
});
this._assetLoad.start();
this._loadedAssets.push(...this._assetLoad.tokens);
}
else {
this.status = STATE.ASSETS_LOADED;
if (loadedOnComplete) {
this.loaded();
}
}
}
loaded() {
this.createDisplay(this._stage, this._assets);
Runtime_1.default.instance.face.plugins.prepare.upload(this.ready.bind(this));
}
ready() {
if (this.closeOnSwipeDown) {
this.setupSwipeDownToClose();
}
super.ready();
TouchManager_1.default.instance.createRequiredGestures(this);
this.status = STATE.LOADED;
}
set status(status) {
if (status !== this._status) {
this._status = status;
if (this.viewManager) {
this.viewManager.events.view.emit(new ViewGlobalEvents_1.ViewResult(this, status));
}
this.emit(this._status, this);
}
}
pause(flag = true, pauseOptions) {
if (!flag) {
TouchManager_1.default.instance.createRequiredGestures(this);
}
super.lockInput(flag);
if (flag) {
if (!this.pauseOverlay) {
this.pauseOverlay = new PauseOverlay_1.default(pauseOptions);
}
else {
this.pauseOverlay.applyDefaults();
if (pauseOptions) {
this.pauseOverlay.applyOptions(pauseOptions);
}
}
this.pauseOverlay.open(this.stage);
}
else {
if (this.pauseOverlay) {
this.pauseOverlay.close();
}
}
}
destroy() {
if (this.state === STATE.DESTROYED) {
log.warn('destroy() : view already destroyed: ' + this.id);
return;
}
else {
this.status = STATE.DESTROYED;
}
super.destroy();
if (this.pauseOverlay) {
this.pauseOverlay.destroy();
}
if (this._stage) {
const eye = Runtime_1.default.instance.face.eye;
if (eye) {
if (eye.parent && eye.parent === this._stage) {
this._stage.removeChild(eye);
eye.active = false;
}
}
else {
log.warn('destroy() Runtime.instance.face.eye was null, should not be possible');
}
TweenManager_1.default.stop(this._stage);
if (this._stage.parent) {
this._stage.parent.removeChild(this._stage);
}
this._stage.destroy({ children: true });
}
this._stage = null;
this._configPath = null;
this._viewState = null;
this._viewConfig = null;
this.pausedParent = null;
this._viewManager = null;
this._assetLoadRequests = null;
if (this._assetLoad) {
this._assetLoad.cancel();
this._assetLoad = null;
}
Runtime_1.default.instance.loader.unload(this._loadedAssets);
this._loadedAssets = null;
this.assetManifest = null;
Runtime_1.default.instance.face.plugins.prepare.completes.length = 0;
Runtime_1.default.instance.face.plugins.prepare.queue.length = 0;
TouchManager_1.default.instance.removeAllGestures();
}
destroyAll() {
if (this.pausedParent) {
this.pausedParent.destroyAll();
}
this.destroy();
}
addAssets(assets, callback) {
let isLoaded = true;
if (!this._assetLoadQueue) {
this._assetLoadQueue = [];
this._assetLoadRequests = [];
}
if (assets.hasOwnProperty('src') && assets.hasOwnProperty('id')) {
if (this.addAssetToQueue(assets)) {
isLoaded = false;
}
}
else if (Array.isArray(assets)) {
for (let i = 0; i < assets.length; i++) {
if (this.addAssetToQueue(assets[i])) {
isLoaded = false;
}
}
}
else if (assets) {
for (let key in assets) {
if (assets.hasOwnProperty(key)) {
if (this.addAssetToQueue(assets[key])) {
isLoaded = false;
}
}
}
}
if (isLoaded) {
if (callback) {
callback();
}
}
else {
this._assetLoadRequests.push({ assets: assets, callback: callback });
if (!this._assetLoad && this._assetLoadQueue.length > 0) {
this._assetLoad = Runtime_1.default.instance.loader.load(this._assetLoadQueue, {
taskDone: (result, original, load) => {
if (this._assetLoadQueue.length > 0) {
const tokens = load.addAssets(this._assetLoadQueue);
if (tokens.length) {
this._loadedAssets.push(...tokens);
}
this._assetLoadQueue.length = 0;
}
},
complete: (err, results) => {
this._assetLoad.removeAllListeners();
this._assetLoad = null;
if (this._status !== STATE.DESTROYED) {
let assetRequest;
let i = this._assetLoadRequests.length - 1;
if (err) {
log.warn('addAssets() error while loading asset(s) ', err);
this.emit(STATE.LOAD_ERROR);
for (i; i >= 0; i--) {
assetRequest = this._assetLoadRequests[i];
this._assetLoadRequests.splice(i, 1);
if (assetRequest.callback) {
if (this.checkForAssets(assetRequest.assets)) {
assetRequest.callback();
}
else {
this.removeMissingAssets(assetRequest.assets);
assetRequest.callback(err);
}
}
}
}
else {
Object.assign(this._assets, results);
for (i; i >= 0; i--) {
assetRequest = this._assetLoadRequests[i];
if (this.checkForAssets(assetRequest.assets)) {
this._assetLoadRequests.splice(i, 1);
if (assetRequest.callback) {
assetRequest.callback();
}
}
}
}
}
},
maxLoads: 0,
autoStart: false
});
this._assetLoadQueue.length = 0;
this._assetLoad.start();
this._loadedAssets.push(...this._assetLoad.tokens);
}
}
}
removeAssets(assets) {
if (assets.hasOwnProperty('src') && assets.hasOwnProperty('id')) {
this.removeAsset(assets);
}
else if (Array.isArray(assets)) {
for (let i = 0; i < assets.length; i++) {
this.removeAsset(assets[i]);
}
}
else if (assets) {
for (let key in assets) {
if (assets.hasOwnProperty(key)) {
this.removeAsset(assets[key]);
}
}
}
}
resolveAssetDescriptors(assetQueue) {
let idCheck = {};
let assetDscrpt;
let i = assetQueue.length - 1;
for (i; i >= 0; i--) {
assetDscrpt = assetQueue[i];
this.setAssetDescriptorDefaults(assetDscrpt);
if (assetDscrpt.hasOwnProperty('id')) {
if (idCheck.hasOwnProperty(assetDscrpt.id)) {
assetQueue.splice(i, 1);
continue;
}
idCheck[assetDscrpt.id] = assetDscrpt;
}
else if (assetDscrpt.hasOwnProperty('src')) {
if (idCheck.hasOwnProperty(assetDscrpt.src)) {
assetQueue.splice(i, 1);
continue;
}
idCheck[assetDscrpt.src] = assetDscrpt;
}
}
idCheck = null;
return assetQueue;
}
addTransition(viewType, openFrom, myTransition, theirTransition, stackDirection) {
if (!this._transitionsMap) {
this._transitionsMap = {};
}
if (myTransition || theirTransition) {
let transByView = this._transitionsMap[viewType];
if (!transByView) {
transByView = {};
this._transitionsMap[viewType] = transByView;
}
let transByViewStyle;
if (openFrom) {
transByViewStyle = transByView[0];
if (!transByViewStyle) {
transByViewStyle = {};
transByView[0] = transByViewStyle;
}
}
else {
transByViewStyle = transByView[1];
if (!transByViewStyle) {
transByViewStyle = {};
transByView[1] = transByViewStyle;
}
}
if (!stackDirection) {
if (myTransition) {
transByViewStyle[0] = myTransition;
}
if (theirTransition) {
transByViewStyle[1] = theirTransition;
}
}
else {
let transByViewDirection = transByViewStyle[2];
if (!transByViewDirection) {
transByViewStyle[2] = transByViewDirection = {};
}
let transByViewDirectionsStyle = transByViewDirection[stackDirection];
if (!transByViewDirectionsStyle) {
transByViewDirection[stackDirection] = transByViewDirectionsStyle = {};
}
if (myTransition) {
transByViewDirectionsStyle[0] = myTransition;
}
if (theirTransition) {
transByViewDirectionsStyle[1] = theirTransition;
}
}
}
}
applyTransitions(view, openFrom = true, stackDirection) {
if (this._transitionsMap) {
let type;
let isView = true;
if (typeof view === 'string') {
type = view;
isView = false;
}
else {
type = view.type;
}
let transByView = this._transitionsMap[type];
if (transByView) {
let transByViewStyle;
if (openFrom) {
transByViewStyle = transByView[0];
}
else {
transByViewStyle = transByView[1];
}
if (transByViewStyle) {
let myTransition;
let theirTransition;
if (stackDirection) {
const transByViewDirection = transByViewStyle[2];
if (transByViewDirection) {
const transByViewDirectionStyle = transByViewDirection[stackDirection];
if (transByViewDirectionStyle) {
myTransition = transByViewDirectionStyle[0];
theirTransition = transByViewDirectionStyle[1];
}
}
}
if (!myTransition) {
myTransition = transByViewStyle[0];
}
if (!theirTransition) {
theirTransition = transByViewStyle[1];
}
if (myTransition) {
this.transitionHandler = myTransition;
}
if (isView && theirTransition) {
view.transitionHandler = theirTransition;
}
}
}
}
}
open(callback, transitionType) {
this._viewManager.borderVisible = this.borderNeeded;
const onOpened = () => {
this.status = STATE.OPENED;
if (callback) {
callback();
}
};
if (this.transitionHandler) {
if (typeof this.transitionHandler === 'string') {
transitionType = this.transitionHandler;
this.transitionHandler = null;
}
else {
this.transitionHandler(onOpened, this);
this.transitionHandler = null;
return;
}
}
switch (transitionType) {
case ViewManager_1.TRANSITION.UP:
if (this.transitionStageOnly) {
this.transitionVerticalIn(true, onOpened);
break;
}
case ViewManager_1.TRANSITION.DOWN:
if (this.transitionStageOnly) {
this.transitionVerticalIn(false, onOpened);
break;
}
super.openChildren(onOpened, transitionType);
break;
case ViewManager_1.TRANSITION.RIGHT:
this.transitionHorizontalIn(true, onOpened);
break;
case ViewManager_1.TRANSITION.LEFT:
this.transitionHorizontalIn(false, onOpened);
break;
case ViewManager_1.TRANSITION.IN:
this.transitionFadeIn(onOpened);
break;
case ViewManager_1.TRANSITION.OUT:
this.transitionFadeOut(onOpened);
break;
default:
onOpened();
break;
}
}
close(callback, transitionType) {
const onClosed = () => {
this.status = STATE.CLOSED;
if (callback) {
callback();
}
};
if (this.transitionHandler) {
if (typeof this.transitionHandler === 'string') {
transitionType = this.transitionHandler;
this.transitionHandler = null;
}
else {
this.transitionHandler(onClosed, this);
this.transitionHandler = null;
return;
}
}
switch (transitionType) {
case ViewManager_1.TRANSITION.UP:
if (this.transitionStageOnly) {
this.transitionVerticalOut(true, onClosed);
break;
}
case ViewManager_1.TRANSITION.DOWN:
if (this.transitionStageOnly) {
this.transitionVerticalOut(false, onClosed);
break;
}
super.closeChildren(onClosed, transitionType);
break;
case ViewManager_1.TRANSITION.RIGHT:
this.transitionHorizontalOut(true, onClosed);
break;
case ViewManager_1.TRANSITION.LEFT:
this.transitionHorizontalOut(false, onClosed);
break;
case ViewManager_1.TRANSITION.IN:
this.transitionFadeIn(onClosed);
break;
case ViewManager_1.TRANSITION.OUT:
this.transitionFadeOut(onClosed);
break;
default:
onClosed();
break;
}
}
transitionVerticalIn(up, callback, moveEase = 'backOut', tweenTime = ViewManager_1.default.TRANS_TIME) {
const targetY = this._stage.y;
let originY = (up) ? +FaceRenderer_1.default.HEIGHT + +this._stage.y : this._stage.y - FaceRenderer_1.default.HEIGHT;
TweenManager_1.default.play(this._stage, {
to: { y: targetY },
from: { y: originY },
duration: tweenTime,
ease: moveEase
}, callback);
}
transitionVerticalOut(up, callback, moveEase = 'backIn', tweenTime = ViewManager_1.default.TRANS_TIME) {
let targetY = (up) ? this._stage.y - FaceRenderer_1.default.HEIGHT : +this._stage.y + +FaceRenderer_1.default.HEIGHT;
TweenManager_1.default.play(this._stage, {
to: { y: targetY },
duration: tweenTime,
ease: moveEase
}, callback);
}
transitionHorizontalIn(forward, callback, moveEase = 'backOut', tweenTime = ViewManager_1.default.TRANS_TIME) {
const targetX = this._stage.x;
let originX = (forward) ? this._stage.x - FaceRenderer_1.default.WIDTH : +this._stage.x + +FaceRenderer_1.default.WIDTH;
TweenManager_1.default.play(this._stage, {
to: { x: targetX },
from: { x: originX },
duration: tweenTime,
ease: moveEase
}, callback);
}
transitionHorizontalOut(forward, callback, moveEase = 'backIn', tweenTime = ViewManager_1.default.TRANS_TIME) {
let targetX = (forward) ? +this._stage.x + +FaceRenderer_1.default.WIDTH : this._stage.x - FaceRenderer_1.default.WIDTH;
TweenManager_1.default.play(this._stage, {
to: { x: targetX },
duration: tweenTime,
ease: moveEase
}, callback);
}
transitionFadeIn(callback, scaleEase = 'backOut', fadeEase = 'sineOut', tweenTime = ViewManager_1.default.TRANS_TIME) {
this._stage.pivot.x = this._stage.x = FaceRenderer_1.default.WIDTH / 2;
this._stage.pivot.y = this._stage.y = FaceRenderer_1.default.HEIGHT / 2;
TweenManager_1.default.play(this._stage, {
to: {
'scale.x': 1,
'scale.y': 1
},
from: {
'scale.x': 0,
'scale.y': 0
},
duration: tweenTime,
ease: scaleEase
}, () => {
TweenManager_1.default.stop(this._stage);
this._stage.alpha = 1;
this._stage.pivot.x = 0;
this._stage.pivot.y = 0;
this._stage.x = 0;
this._stage.y = 0;
callback();
});
TweenManager_1.default.play(this._stage, {
to: { alpha: 1 },
from: { alpha: 0 },
duration: tweenTime,
ease: fadeEase
});
}
transitionFadeOut(callback, scaleEase = 'backIn', fadeEase = 'sineIn', tweenTime = ViewManager_1.default.TRANS_TIME) {
this._stage.pivot.x = this._stage.x = FaceRenderer_1.default.WIDTH / 2;
this._stage.pivot.y = this._stage.y = FaceRenderer_1.default.HEIGHT / 2;
TweenManager_1.default.play(this._stage, {
to: {
'scale.x': 0,
'scale.y': 0
},
duration: tweenTime,
ease: scaleEase
}, () => {
TweenManager_1.default.stop(this._stage);
this._stage.alpha = 0;
this._stage.pivot.x = 0;
this._stage.pivot.y = 0;
this._stage.x = 0;
this._stage.y = 0;
callback();
});
TweenManager_1.default.play(this._stage, {
to: { alpha: 0 },
duration: tweenTime,
ease: fadeEase
});
}
transitionFadeOutTo(callback, maxScale = 1.1, targetScale = .8, targetAlpha = .6, tweenTime = ViewManager_1.default.TRANS_TIME / 2) {
this._stage.pivot.x = this._stage.x = FaceRenderer_1.default.WIDTH / 2;
this._stage.pivot.y = this._stage.y = FaceRenderer_1.default.HEIGHT / 2;
TweenManager_1.default.play(this._stage, {
to: {
'scale.x': maxScale,
'scale.y': maxScale,
},
duration: tweenTime * .7,
ease: 'cubicInOut'
}, () => {
TweenManager_1.default.play(this._stage, {
to: {
'scale.x': targetScale,
'scale.y': targetScale,
alpha: targetAlpha
},
duration: tweenTime * .3,
ease: 'cubicIn'
}, () => {
this._stage.scale.x = 1;
this._stage.scale.y = 1;
this._stage.alpha = 1;
callback();
});
});
}
transitionFadeInFrom(callback, maxScale = 1.1, initialScale = .8, initialAlpha = .6, tweenTime = ViewManager_1.default.TRANS_TIME / 2) {
this._stage.pivot.x = this._stage.x = FaceRenderer_1.default.WIDTH / 2;
this._stage.pivot.y = this._stage.y = FaceRenderer_1.default.HEIGHT / 2;
TweenManager_1.default.play(this._stage, {
to: {
'scale.x': maxScale,
'scale.y': maxScale,
alpha: 1
},
from: {
'scale.x': initialScale,
'scale.y': initialScale,
alpha: initialAlpha
},
duration: tweenTime * .2,
ease: 'cubicOut'
}, () => {
TweenManager_1.default.play(this._stage, {
to: {
'scale.x': 1,
'scale.y': 1
},
duration: tweenTime * .8,
ease: 'cubicInOut'
}, () => {
callback();
});
});
}
actionHandler(action, fromComponent) {
if (!this.inputLocked) {
if (action.type === ActionData_1.default.EVENT) {
if (action.data) {
if (action.data.hasOwnProperty('event')) {
this.emit(action.data.event, action.data);
this.viewManager.events.view.emit(new ViewGlobalEvents_1.ViewResult(this, action.data.event, action.data));
}
else {
log.info('actionHandler() action of type: ' + ActionData_1.default.EVENT + ' must specify an event to fire within data');
}
}
return;
}
else if (action.type === ActionData_1.default.CALLBACK) {
if (action.data) {
if (action.data.hasOwnProperty('callback')) {
action.data['callback']();
}
else {
log.info('actionHandler() action of type: ' + ActionData_1.default.CALLBACK + ' must specify a callback within data');
}
}
return;
}
else if (action.type === ActionData_1.default.SOUND) {
if (action.data) {
let soundId = action.data.id;
const soundSrc = action.data.src;
if (!soundId) {
if (soundSrc) {
soundId = soundSrc;
}
else {
log.info('actionHandler() action of type: ' + ActionData_1.default.SOUND + ' had neither id nor src were provided for the sound.');
return;
}
}
if (Runtime_1.default.instance.sound.exists(this.soundSet + '_' + soundId)) {
Runtime_1.default.instance.sound.play(this.soundSet + '_' + soundId);
}
else if (Runtime_1.default.instance.sound.exists(soundId)) {
Runtime_1.default.instance.sound.play(soundId);
}
else if (soundSrc) {
this.addAssets({
id: soundId,
src: soundSrc,
type: 'sound'
}, (err) => {
if (!err) {
Runtime_1.default.instance.sound.play(soundId);
}
});
}
else {
log.info('actionHandler() action of type: ' + ActionData_1.default.SOUND + ' was not pre-loaded and no src was provided.');
}
}
return;
}
else {
this._viewManager.actionHandler(action, fromComponent);
}
}
}
actionEnactor(action) {
if (this._inputLocked) {
return false;
}
if (action.type === ActionData_1.default.VERBAL_COMMAND) {
switch (action.data.intent) {
case 'close':
if (this.closeOnSwipeDown && this.hasActions(TouchManager_1.GESTURE.SWIPE_DOWN)) {
this.triggerActions(TouchManager_1.GESTURE.SWIPE_DOWN);
return true;
}
break;
}
}
return super.actionEnactor(action);
}
setupSwipeDownToClose() {
if (!super.getActions(TouchManager_1.GESTURE.SWIPE_DOWN)) {
super.addAction(ActionData_1.default.EVENT, { event: View.BACK }, false, false, TouchManager_1.GESTURE.SWIPE_DOWN);
super.addAction(ActionData_1.default.CLOSE_VIEW, null, false, false, TouchManager_1.GESTURE.SWIPE_DOWN);
}
}
assignConfig(viewConfig) {
if (viewConfig) {
super.assignConfig(viewConfig);
if (viewConfig.hasOwnProperty('ignoreSwipeDown')) {
this.closeOnSwipeDown = !viewConfig.ignoreSwipeDown;
}
if (viewConfig.hasOwnProperty('soundSet')) {
this.soundSet = viewConfig.soundSet;
}
if (viewConfig.hasOwnProperty('transitionStageOnly')) {
this.transitionStageOnly = viewConfig.transitionStageOnly;
}
if (viewConfig.hasOwnProperty('category')) {
this._category = viewConfig.category;
}
if (viewConfig.hasOwnProperty('pauseParent')) {
log.warn("Deprecation :: Usage of 'pauseParent' is deprecated, please use 'pause' assigning either a boolean or PauseOptions Object");
this.willPauseParent = viewConfig.pauseParent;
}
if (viewConfig.hasOwnProperty('pauseOptions')) {
log.warn("Deprecation :: Usage of 'pauseOptions' is deprecated, please use 'pause' assigning either a boolean or PauseOptions Object");
this.willPauseParent = true;
this.pauseOptions = (viewConfig.pauseOptions);
}
if (viewConfig.hasOwnProperty('pause')) {
if (typeof viewConfig.pause === 'string') {
this.willPauseParent = viewConfig.pause === 'true';
}
else if (typeof viewConfig.pause === 'boolean') {
this.willPauseParent = !!viewConfig.pause;
}
else {
this.willPauseParent = true;
this.pauseOptions = (viewConfig.pause);
}
}
if (viewConfig.hasOwnProperty('border')) {
this.borderNeeded = viewConfig.border;
}
}
}
applyState(viewState) {
this._viewState = viewState;
if (viewState.id && !this.id) {
this.id = viewState.id;
}
if (viewState.viewConfig) {
this._viewConfig = viewState.viewConfig;
this.assignConfig(this._viewConfig);
}
if (viewState.componentConfigs) {
this.componentConfigs = viewState.componentConfigs;
}
if (viewState.configPath) {
this._configPath = viewState.configPath;
}
}
createState() {
let viewState = this._viewState || new ViewState_1.default(this.type);
if (this._configPath) {
viewState.configPath = this._configPath;
}
viewState.id = this.id;
this._viewConfig = this.updateConfig(this._viewConfig);
if (this._viewConfig) {
viewState.viewConfig = this._viewConfig;
if (this.id) {
viewState.viewConfig['id'] = this.id;
}
}
viewState.componentConfigs = this.componentConfigs;
return viewState;
}
setAssetDescriptorDefaults(asset) {
asset.upload = asset.upload !== undefined ? !!asset.upload : true;
if (typeof asset.cache !== 'string') {
asset.cache = Runtime_1.default.instance.loader.activeCache;
}
return asset;
}
addAssetToQueue(asset) {
if (!this._assets[asset.id]) {
if (!this.assetManifest.some((element) => {
return element.id === asset.id;
})) {
this.setAssetDescriptorDefaults(asset);
this._assetLoadQueue.push(asset);
this.assetManifest.push(asset);
}
return true;
}
return false;
}
removeAsset(asset) {
this.removeFromManifest(asset);
if (this._assetLoad && !this._assetLoad.running) {
this._assetLoad = null;
}
if (this._assetLoadRequests) {
for (let i = this._assetLoadRequests.length - 1; i >= 0; i--) {
let assetRequest = this._assetLoadRequests[i];
if (this.checkForAssetRequest(assetRequest, asset)) {
this._assetLoadRequests.splice(i, 1);
if (assetRequest.callback) {
assetRequest.callback(new Error('asset manual removed, asset request will not be completed'));
}
}
}
}
}
removeFromManifest(asset) {
let index = this.assetManifest.findIndex((item) => {
return item.id === asset.id;
});
if (index !== -1) {
this.assetManifest.splice(index, 1);
}
index = this._loadedAssets.findIndex((token) => {
return token.id === asset.id;
});
const token = this._loadedAssets[index];
if (index !== -1) {
this._loadedAssets.splice(index, 1);
}
Runtime_1.default.instance.loader.unload(token);
delete this._assets[asset.id];
}
checkForAssetRequest(assets, asset) {
if (assets.hasOwnProperty('src') && assets.hasOwnProperty('id')) {
return assets.id === asset.id;
}
else if (Array.isArray(assets)) {
for (let i = 0; i < assets.length; i++) {
if (assets[i].id === asset.id) {
return true;
}
}
}
else if (assets) {
for (let key in assets) {
if (assets.hasOwnProperty(key)) {
if (assets[key].id === asset.id) {
return true;
}
}
}
}
return false;
}
checkForAssets(assets) {
if (assets.hasOwnProperty('src') && assets.hasOwnProperty('id')) {
if (!this._assets[assets.id]) {
return false;
}
}
else if (Array.isArray(assets)) {
for (let i = 0; i < assets.length; i++) {
if (!this._assets[assets[i].id]) {
return false;
}
}
}
else if (assets) {
for (let key in assets) {
if (assets.hasOwnProperty(key)) {
if (!this._assets[assets[key].id]) {
return false;
}
}
}
}
return true;
}
removeMissingAssets(assets) {
let asset;
if (assets.hasOwnProperty('src') && assets.hasOwnProperty('id')) {
if (!this._assets[assets.id]) {
this.removeFromManifest(assets);
}
}
else if (Array.isArray(assets)) {
for (let i = 0; i < assets.length; i++) {
asset = assets[i];
if (!this._assets[asset.id]) {
this.removeFromManifest(asset);
}
}
}
else if (assets) {
for (let key in assets) {
if (assets.hasOwnProperty(key)) {
asset = assets[key];
if (!this._assets[asset.id]) {
this.removeFromManifest(asset);
}
}
}
}
}
}
View.STATE = STATE;
View.CATEGORY = CATEGORY;
exports.default = View;
},{"../../../Runtime":1,"../../FaceRenderer":99,"../../tween/TweenManager":174,"../ComponentGroup":123,"../TouchManager":125,"../ViewGlobalEvents":126,"../ViewManager":127,"../ViewState":129,"../actions/ActionData":130,"./PauseOverlay":154,"./log":158}],157:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const View_1 = require("./View");
const MenuView_1 = require("./MenuView");
const EyeView_1 = require("./EyeView");
const ImageView_1 = require("./ImageView");
const ContactsView_1 = require("./ContactsView");
const TextView_1 = require("./TextView");
exports.default = {
View: View_1.default,
STATE: View_1.STATE,
CATEGORY: View_1.CATEGORY,
MenuView: MenuView_1.default,
EyeView: EyeView_1.default,
ImageView: ImageView_1.default,
ContactsView: ContactsView_1.default,
TextView: TextView_1.default
};
},{"./ContactsView":150,"./EyeView":151,"./ImageView":152,"./MenuView":153,"./TextView":155,"./View":156}],158:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
const log = log_1.default.createChild('Views');
exports.default = log;
},{"../log":149}],159:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("pixi.js");
require("pixi-animate");
require('pixi-compressed-textures');
PIXI.glCore.VertexArrayObject.FORCE_NATIVE = true;
const FaceRenderer_1 = require("./FaceRenderer");
exports.FaceRenderer = FaceRenderer_1.default;
const tasks_1 = require("./tasks");
exports.tasks = tasks_1.default;
const animation_1 = require("./animation");
exports.animation = animation_1.default;
const tween_1 = require("./tween");
exports.tween = tween_1.default;
const input_1 = require("./input");
exports.input = input_1.default;
const gui_1 = require("./gui");
exports.gui = gui_1.default;
const eye_1 = require("./eye");
exports.eye = eye_1.default;
},{"./FaceRenderer":99,"./animation":106,"./eye":119,"./gui":148,"./input":161,"./tasks":171,"./tween":175,"pixi-animate":undefined,"pixi-compressed-textures":undefined,"pixi.js":undefined}],160:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const electron_1 = require("../../utils/electron");
const log_1 = require("../log");
const FaceRenderer_1 = require("../FaceRenderer");
let HammerJS;
if (electron_1.default) {
HammerJS = require('hammerjs');
}
class GestureManager {
constructor(renderer) {
this._hammerManager = null;
this._log = null;
this._hammerManager = new HammerJS.Manager(renderer.view);
this._log = log_1.default.createChild('GestureManager');
}
static init(renderer) {
return new GestureManager(renderer);
}
get hammer() {
return HammerJS;
}
stop() {
this._hammerManager.stop();
}
addStageGesture(hammerType, gestureOptions, gestureCallback) {
if (!this._hammerManager) {
throw new Error("The pixi HammerJS Manager is null. Has init been called?");
}
if (!gestureOptions.event) {
throw new Error("Invalid event string.");
}
let hammerResult = this._hammerManager.get(gestureOptions.event);
if (hammerResult) {
if (this._hammerManager.handlers[gestureOptions.event].indexOf(gestureCallback) === -1) {
this._hammerManager.handlers[gestureOptions.event].push(gestureCallback);
}
}
else {
hammerResult = new hammerType(gestureOptions);
this._hammerManager.add(hammerResult);
this._hammerManager.on(gestureOptions.event, gestureCallback);
}
return hammerResult;
}
removeStageGesture(gestureRecognizer) {
if (gestureRecognizer.hasOwnProperty('options')) {
this._hammerManager.off(gestureRecognizer.options.event);
this._hammerManager.remove(gestureRecognizer);
}
}
spoofGesture(gestureEvent = 'tap', xPos = 0, yPos = 0) {
this._log.info("spoofing gesture", gestureEvent.toLowerCase(), xPos, yPos);
this._hammerManager.emit(gestureEvent.toLowerCase(), { pointers: [{ clientX: xPos, clientY: yPos }] });
}
spoofGestureWithOptions(gestureEvent = 'tap', options = {}) {
this._hammerManager.emit(gestureEvent, options);
}
spoofFullPanGesture(panLeft = true) {
const pointers = [FaceRenderer_1.default.WIDTH * 0.75, FaceRenderer_1.default.WIDTH * 0.5, FaceRenderer_1.default.WIDTH * 0.25];
const movements = [-31, -198, -31].map(move => panLeft ? move : move * -1);
(panLeft ? pointers : pointers.reverse()).forEach((val, index, array) => {
this._hammerManager.emit(GestureManager.PAN, { isFinal: false, srcEvent: { movementX: movements[index] }, pointers: [{ x: val, clientY: 310 }] });
if (index === array.length - 1) {
this._hammerManager.emit(GestureManager.PAN, { isFinal: true, pointers: [{ x: val, clientY: 310 }] });
}
});
}
}
GestureManager.PAN = 'pan';
GestureManager.PANSTART = 'panstart';
GestureManager.PANMOVE = 'panmove';
GestureManager.PANEND = 'panend';
GestureManager.PANCANCEL = 'pancancel';
GestureManager.PANLEFT = 'panleft';
GestureManager.PANRIGHT = 'panright';
GestureManager.PANUP = 'panup';
GestureManager.PANDOWN = 'pandown';
GestureManager.SWIPE = 'swipe';
GestureManager.SWIPELEFT = 'swipeleft';
GestureManager.SWIPERIGHT = 'swiperight';
GestureManager.SWIPEUP = 'swipeup';
GestureManager.SWIPEDOWN = 'swipedown';
GestureManager.TAP = 'tap';
exports.default = GestureManager;
},{"../../utils/electron":205,"../FaceRenderer":99,"../log":162,"hammerjs":undefined}],161:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const GestureManager_1 = require("./GestureManager");
exports.default = {
GestureManager: GestureManager_1.default
};
},{"./GestureManager":160}],162:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
exports.default = log_1.default.createChild('Rendering');
},{"../log":75}],163:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_loader_1 = require("jibo-loader");
class ColorAlphaTask extends jibo_loader_1.Task {
static test(asset) {
return !!asset.src && !!asset.alpha && /\.(jpg|png|jpeg|gif)$/i.test(asset.src) && /\.(png|gif)$/i.test(asset.alpha);
}
static mergeAlpha(rgbImage, alphaImage, canvas) {
if (!canvas) {
canvas = document.createElement("canvas");
}
canvas.width = Math.max(alphaImage.width, rgbImage.width);
canvas.height = Math.max(alphaImage.height, rgbImage.height);
const ctx = canvas.getContext("2d");
ctx.save();
ctx.drawImage(rgbImage, 0, 0);
ctx.globalCompositeOperation = "destination-in";
ctx.drawImage(alphaImage, 0, 0);
ctx.restore();
return canvas;
}
constructor(manager, asset) {
super(manager, asset, asset.color);
this.src = this.prepare(asset.src);
this.alpha = this.prepare(asset.alpha);
}
start(callback) {
this.load({
_alpha: this.alpha,
_src: this.src
}, (err, results) => {
if (err) {
return callback(err);
}
callback(null, ColorAlphaTask.mergeAlpha(results._src, results._alpha));
results._src.src = results._alpha.src = '';
});
}
}
exports.default = ColorAlphaTask;
},{"jibo-loader":undefined}],164:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_loader_1 = require("jibo-loader");
const Runtime_1 = require("../../Runtime");
const log_1 = require("./log");
const workerPool = [];
class CompressedImageTask extends jibo_loader_1.Task {
static test(asset) {
return asset.src && /(\.dds|\.crn)$/.test(asset.src);
}
constructor(manager, asset) {
super(manager, asset, asset.src);
this.src = this.prepare(asset.src);
}
start(callback) {
if ((/\.crn$/.test(this.src))) {
this.unCrunch(this.src, callback);
return;
}
const xhr = new XMLHttpRequest();
xhr.addEventListener('load', (ev) => {
const output = PIXI.compressedTextures.CompressedImage.loadFromArrayBuffer(xhr.response, this.src);
callback(null, output);
}, false);
xhr.addEventListener('error', function (err) {
log_1.default.warn('CompressedImageTask.start had an XHR error: ', err);
callback(err);
});
xhr.open('GET', this.src, true);
xhr.responseType = 'arraybuffer';
xhr.send();
}
unCrunch(data, callback) {
let loader = workerPool.pop() || new Worker(Runtime_1.default.instance.utils.PathUtils.getAssetUri('jibo://resources/workerJS/webgl-texture-util.js'));
loader.onmessage = (msg) => {
loader.onmessage = null;
workerPool.push(loader);
if (msg.data.error) {
callback(msg.data.error);
return;
}
const data = msg.data;
let output;
const CompressedImage = PIXI.compressedTextures.CompressedImage;
if (data.format) {
output = new CompressedImage(this.src, data.data, 'CRN', data.width, data.height, data.levels, data.format);
}
else {
output = CompressedImage.loadFromArrayBuffer(data.data, this.src);
}
output.preserveSource = false;
callback(null, output);
};
loader.postMessage({ src: data });
}
}
exports.default = CompressedImageTask;
},{"../../Runtime":1,"./log":172,"jibo-loader":undefined}],165:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_loader_1 = require("jibo-loader");
const jibo_plugins_1 = require("jibo-plugins");
const KeysLoader_1 = require("../animation/KeysLoader");
class AnimDataTask extends jibo_loader_1.Task {
static test(asset) {
return asset.type === "keys-data" && !!asset.root &&
(!!asset.src && /\.keys$/i.test(asset.src));
}
constructor(manager, asset) {
super(manager, asset, asset.src);
this.src = this.prepare(asset.src);
this.root = asset.root;
}
start(callback) {
let root = jibo_plugins_1.PathUtils.findRoot();
const loader = new KeysLoader_1.default(this.src, root, this.id);
loader.load(callback);
}
}
exports.default = AnimDataTask;
},{"../animation/KeysLoader":102,"jibo-loader":undefined,"jibo-plugins":undefined}],166:[function(require,module,exports){
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_loader_1 = require("jibo-loader");
const jibo_plugins_1 = require("jibo-plugins");
const Sound_1 = require("../../sound/Sound");
const Timeline_1 = require("../animation/Timeline");
const path = require("path");
const KeysData_1 = require("../animation/KeysData");
const KeysLoader_1 = require("../animation/KeysLoader");
const async = require("async");
const jibo_cai_utils_1 = require("jibo-cai-utils");
const fs = require("fs");
const log_1 = require("./log");
const jiboKeyframes = require('jibo-keyframes');
class KeysTask extends jibo_loader_1.Task {
static test(asset) {
return asset.type === "keys" && !!asset.root &&
((!!asset.src && /\.keys$/i.test(asset.src)) || !!asset.data);
}
constructor(manager, asset) {
super(manager, asset, asset.src);
this.needsCache = true;
this.src = this.prepare(asset.src);
this.options = asset.options;
this.data = asset.data;
this.root = asset.root;
this.upload = asset.upload === undefined ? true : asset.upload;
}
start(callback) {
const keys = new KeysData_1.default(this.id, this.src, this.cache);
keys.root = this.root;
this.dataSupplied = !!this.data;
let assetFileFound = false;
let label = 'Data load';
async.waterfall([
(done) => __awaiter(this, void 0, void 0, function* () {
let root = jibo_plugins_1.PathUtils.findRoot();
let projectName = jibo_plugins_1.PathUtils.getProjectName(root);
const parent = jibo_plugins_1.PathUtils.findRoot(path.resolve(this.src));
const assetPack = jibo_plugins_1.PathUtils.getProjectName(parent);
keys.assetPack = assetPack === projectName ? '' : assetPack;
if (this.data) {
done(null, this.data);
}
else {
let animSrc = yield jibo_cai_utils_1.PromiseUtils.promisify(cb => jiboKeyframes.getAnimFilePath(this.src, cb));
let assetSrc = yield jibo_cai_utils_1.PromiseUtils.promisify(cb => jiboKeyframes.getAssetsFilePath(this.src, cb));
if (animSrc) {
keys.dotAnimSrc = animSrc;
}
if (animSrc && assetSrc) {
label = `Assets file load ${assetSrc}`;
console.time(label);
assetFileFound = true;
const data = fs.readFileSync(assetSrc, 'utf8');
let json = JSON.parse(data);
done(null, json);
}
else {
label = `Keys file load ${this.src}`;
console.time(label);
const loader = new KeysLoader_1.default(this.src, root, this.id);
loader.load(done);
}
}
}),
(data, done) => {
log_1.default.debug(label);
console.timeEnd(label);
console.time('Asset loading');
this.data = data;
let assets;
if (assetFileFound) {
assets = this.convertAssetPaths(data, keys);
}
else {
keys.data = data;
assets = this.getAssetsFromKeys(keys);
}
if (!assets.length) {
return done(null, {});
}
this.load(assets, done);
},
(results, done) => {
console.timeEnd('Asset loading');
for (let id in results) {
if (results[id] instanceof Timeline_1.default) {
keys.addTimeline(id, results[id]);
}
else if (results[id] instanceof Sound_1.default) {
keys.addSound(id, results[id]);
}
else if (results[id] instanceof PIXI.Texture) {
keys.addTexture(id, results[id]);
}
}
done();
}
], (err, results) => {
if (err) {
keys.destroy();
callback(err);
return;
}
callback(null, keys);
});
}
getAssetsFromKeys(keys) {
const assets = [];
keys.data.layers.forEach((layer) => {
layer.keyframes.forEach((keyframe) => {
const AudioEvent = keyframe.value.AudioEvent;
const Pixi = keyframe.value.Pixi;
const Texture = keyframe.value.Texture;
if (AudioEvent) {
assets.push({
id: AudioEvent.file,
type: 'sound',
src: jibo_plugins_1.PathUtils.getAudioUri(AudioEvent.file, keys.assetPack, keys.root),
cache: this.cache
});
}
else if (Pixi) {
assets.push({
id: Pixi,
type: 'timeline',
upload: this.upload,
src: jibo_plugins_1.PathUtils.getTimelineUri(Pixi, keys.assetPack, keys.root),
cache: this.cache
});
}
else if (jibo_plugins_1.PathUtils.isImage(Texture)) {
const src = jibo_plugins_1.PathUtils.getAssetUri(Texture, keys.assetPack, keys.root);
assets.push({
id: src,
type: 'texture',
src: src,
cache: this.cache
});
}
});
});
return assets;
}
convertAssetPaths(data, keys) {
const assets = [];
data.forEach((assetObj) => {
switch (assetObj.type) {
case 'sound':
assetObj.src = jibo_plugins_1.PathUtils.getAudioUri(assetObj.src, keys.assetPack, keys.root);
break;
case 'timeline':
assetObj.upload = this.upload;
assetObj.src = jibo_plugins_1.PathUtils.getTimelineUri(assetObj.src, keys.assetPack, keys.root);
break;
case 'texture':
assetObj.src = jibo_plugins_1.PathUtils.getAssetUri(assetObj.src, keys.assetPack, keys.root);
assetObj.id = assetObj.src;
break;
case 'metadata':
return;
}
assetObj.cache = this.cache;
assets.push(assetObj);
});
return assets;
}
}
exports.default = KeysTask;
},{"../../sound/Sound":192,"../animation/KeysData":101,"../animation/KeysLoader":102,"../animation/Timeline":105,"./log":172,"async":undefined,"fs":undefined,"jibo-cai-utils":undefined,"jibo-keyframes":undefined,"jibo-loader":undefined,"jibo-plugins":undefined,"path":undefined}],167:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_loader_1 = require("jibo-loader");
const Shapes_1 = require("../animation/Shapes");
class ShapesTask extends jibo_loader_1.Task {
static test(asset) {
return asset.type === "shapes" && !!asset.src && /\.shapes\.(json|txt)$/i.test(asset.src);
}
constructor(manager, asset) {
super(manager, asset, asset.src);
this.src = this.prepare(asset.src);
}
start(callback) {
this.simpleLoad(this.src, (err, results) => {
if (err) {
return callback(err);
}
callback(null, new Shapes_1.default(this.id, results));
});
}
}
exports.default = ShapesTask;
},{"../animation/Shapes":103,"jibo-loader":undefined}],168:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_loader_1 = require("jibo-loader");
const Runtime_1 = require("../../Runtime");
const Spritesheet_1 = require("../animation/Spritesheet");
const path = require("path");
class SpritesheetTask extends jibo_loader_1.Task {
static test(asset) {
return asset.type === "spritesheet" && !!asset.src && /\.(json)$/i.test(asset.src);
}
constructor(manager, asset) {
super(manager, asset, asset.src);
this.needsCache = true;
this.src = this.prepare(asset.src);
this.upload = !!asset.upload;
}
start(callback) {
this.simpleLoad(this.src, (err, data) => {
if (err) {
return callback(err);
}
if (typeof data !== "object" || !data.meta || !data.frames) {
return callback(new Error('Spritesheet is not a valid format'));
}
const imgSrc = path.join(path.dirname(this.src), data.meta.image);
this.load(imgSrc, (err, image) => {
if (err) {
return callback(err);
}
const baseTexture = new PIXI.BaseTexture(image);
baseTexture.imageUrl = imgSrc;
if (this.upload) {
Runtime_1.default.instance.face.textureManager.updateTexture(baseTexture);
}
callback(null, new Spritesheet_1.default(baseTexture, data.frames, data.meta.scale || 1));
});
});
}
}
exports.default = SpritesheetTask;
},{"../../Runtime":1,"../animation/Spritesheet":104,"jibo-loader":undefined,"path":undefined}],169:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_loader_1 = require("jibo-loader");
const ColorAlphaTask_1 = require("./ColorAlphaTask");
const Runtime_1 = require("../../Runtime");
class TextureTask extends jibo_loader_1.Task {
static test(asset) {
return asset.type === "texture" && !!asset.src;
}
constructor(manager, asset) {
super(manager, asset, asset.src);
this.needsCache = true;
this.src = this.prepare(asset.src);
this.alpha = asset.alpha ? this.prepare(asset.alpha) : null;
this.upload = !!asset.upload;
this.format = 'image';
}
start(callback) {
const assets = {};
assets._color = {
src: this.src,
remote: this.remote,
timeout: this.timeout,
format: this.format
};
if (this.alpha) {
assets._alpha = {
src: this.alpha,
remote: this.remote,
timeout: this.timeout,
format: this.format
};
}
this.load(assets, (err, results) => {
if (err) {
return callback(err);
}
let image;
if (!results._alpha) {
image = results._color;
}
else {
image = ColorAlphaTask_1.default.mergeAlpha(results._color, results._alpha);
}
const baseTexture = new PIXI.BaseTexture(image);
baseTexture.imageUrl = this.src;
const texture = new PIXI.Texture(baseTexture);
if (this.upload) {
Runtime_1.default.instance.face.textureManager.updateTexture(texture);
}
callback(null, texture);
});
}
}
exports.default = TextureTask;
},{"../../Runtime":1,"./ColorAlphaTask":163,"jibo-loader":undefined}],170:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_loader_1 = require("jibo-loader");
const Timeline_1 = require("../animation/Timeline");
const jibo_plugins_1 = require("jibo-plugins");
const path = require("path");
const vm = require("vm");
const Runtime_1 = require("../../Runtime");
class TimelineTask extends jibo_loader_1.Task {
static test(asset) {
return asset.type === "timeline" && !!asset.src && /\.js$/i.test(asset.src);
}
constructor(manager, asset) {
super(manager, asset, asset.src);
this.needsCache = true;
this.src = this.prepare(asset.src);
this.upload = !!asset.upload;
this.instance = asset.instance !== undefined ? !!asset.instance : true;
}
start(callback) {
const timeline = new Timeline_1.default();
this.load({
src: this.src,
format: 'text'
}, (err, result) => {
if (this.status !== jibo_loader_1.Task.RUNNING) {
return;
}
if (err) {
return callback(err);
}
let library;
const oldFromFrame = PIXI.Texture.fromFrame;
try {
const context = {
module: { exports: {} },
PIXI: PIXI
};
PIXI.Texture.fromFrame = timeline.getTexture.bind(timeline);
vm.runInNewContext(result, context);
library = context.module.exports;
PIXI.Texture.fromFrame = oldFromFrame;
}
catch (e) {
PIXI.Texture.fromFrame = oldFromFrame;
return callback(e);
}
timeline.library = library;
const assets = this.getAssets(timeline);
if (assets.length) {
this.load(assets, (err, results) => {
if (err) {
return callback(err);
}
if (this.upload && Runtime_1.default.instance.face) {
timeline.upload(Runtime_1.default.instance.face, () => {
callback(null, timeline);
});
}
else {
callback(null, timeline);
}
});
}
else {
callback(null, timeline);
}
});
}
getAssets(timeline) {
let basePath = this.src;
if (jibo_plugins_1.PathUtils.getAssetPack(basePath)) {
basePath = jibo_plugins_1.PathUtils.getAssetUri(basePath);
}
basePath = path.dirname(basePath);
const results = [];
const assets = timeline.library.stage.assets;
for (let id in assets) {
let src = assets[id];
if (src.search(/\.shapes\.(txt|json)$/i) > -1) {
results.push({
id: id,
src: path.join(basePath, src),
type: 'shapes',
complete: (err, result) => {
if (err) {
return;
}
timeline.addShapes(result);
}
});
}
else if (src.search(/\.(png|jpg|gif|dds|crn)$/i) > -1) {
results.push({
id: id,
src: path.join(basePath, src),
type: 'texture',
complete: (err, result) => {
if (err) {
return;
}
timeline.addTexture(result, id);
},
cache: this.cache
});
}
else if (src.search(/\.json$/i) > -1) {
results.push({
id: id,
src: path.join(basePath, src),
type: 'spritesheet',
complete: (err, result) => {
if (err) {
return;
}
timeline.addSpritesheet(result);
},
cache: this.cache
});
}
}
return results;
}
}
exports.default = TimelineTask;
},{"../../Runtime":1,"../animation/Timeline":105,"jibo-loader":undefined,"jibo-plugins":undefined,"path":undefined,"vm":undefined}],171:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const TextureTask_1 = require("./TextureTask");
const ColorAlphaTask_1 = require("./ColorAlphaTask");
const TimelineTask_1 = require("./TimelineTask");
const ShapesTask_1 = require("./ShapesTask");
const KeysTask_1 = require("./KeysTask");
const KeysDataTask_1 = require("./KeysDataTask");
const SpritesheetTask_1 = require("./SpritesheetTask");
const CompressedImageTask_1 = require("./CompressedImageTask");
exports.default = {
ColorAlphaTask: ColorAlphaTask_1.default,
TimelineTask: TimelineTask_1.default,
ShapesTask: ShapesTask_1.default,
TextureTask: TextureTask_1.default,
KeysTask: KeysTask_1.default,
KeysDataTask: KeysDataTask_1.default,
SpritesheetTask: SpritesheetTask_1.default,
CompressedImageTask: CompressedImageTask_1.default
};
},{"./ColorAlphaTask":163,"./CompressedImageTask":164,"./KeysDataTask":165,"./KeysTask":166,"./ShapesTask":167,"./SpritesheetTask":168,"./TextureTask":169,"./TimelineTask":170}],172:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
exports.default = log_1.default.createChild('Tasks');
},{"../log":162}],173:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
const eases = require("eases");
const log_1 = require("./log");
const log = log_1.default.createChild('Tween');
class Tween extends events_1.EventEmitter {
constructor() {
super(...arguments);
this._complete = null;
this._inProcess = false;
}
init(target, options, complete) {
options = Object.assign({
duration: 500,
ease: 'linear',
delay: 0,
to: null,
from: null
}, options || {});
if (!eases[options.ease]) {
throw new Error(`'${options.ease}' is not a defined ease.`);
}
this._target = target;
this._end = !options.to ? this.endDefaults(options.from) : options.to;
this._start = !options.from ? this.startDefaults(this._end) : options.from;
if (!this._end || !this._start || !this.validate(this._end, this._start)) {
log.error("given start and end values that are incompatible to: %O, from: %O", this._end, this._start);
throw new Error('Start and end values for tween are incompatible.');
}
this._time = 0;
this._elapsed = 0;
this._ease = eases[options.ease];
this._delay = options.delay;
this._duration = options.duration;
this._complete = complete;
this.assign(this._start);
process.nextTick(() => {
this.emit('change', this._target);
});
}
reset() {
this.removeAllListeners();
this._complete = null;
this._target = null;
this._ease = null;
this._time = 0;
this._delay = 0;
this._elapsed = 0;
this._duration = 0;
this.paused = false;
this._inProcess = false;
}
get delay() {
return this._delay;
}
set delay(value) {
this._delay = value;
}
get duration() {
return this._duration;
}
get time() {
return this._time;
}
get target() {
return this._target;
}
get inProcess() {
return this._inProcess;
}
completed() {
this._inProcess = true;
this.assign(this._end);
if (this._complete) {
this._complete();
this._complete = null;
}
this.emit('complete', this._target);
}
update(elapsed) {
if (this.paused) {
return;
}
this._elapsed += elapsed;
const startTime = this._elapsed - this._delay;
const localElapsedTime = Math.max(0, Math.min(startTime, this._duration));
if (localElapsedTime >= 0 && localElapsedTime <= this._duration) {
this._time = localElapsedTime / this._duration;
}
const modified = this._ease(this._time);
for (let prop in this._start) {
if (typeof this._start[prop] !== 'number') {
continue;
}
this.assignValue(prop, this.lerp(this._start[prop], this._end[prop], modified));
}
this.emit('change', this._target);
}
assign(values) {
for (let prop in values) {
this.assignValue(prop, values[prop]);
}
}
assignValue(prop, value) {
if (prop.indexOf('.') < 0) {
this._target[prop] = value;
}
else {
const parts = prop.split('.');
let target = this._target;
while (parts.length > 1) {
target = target[parts.shift()];
if (!target) {
throw new Error(`Property '${prop}' is invalid on target.`);
}
}
target[parts.shift()] = value;
}
}
lerp(v0, v1, t) {
return (1.0 - t) * v0 + t * v1;
}
startDefaults(to) {
const start = {};
for (let prop in to) {
if (prop.indexOf('.') < 0) {
start[prop] = this._target[prop];
}
else {
const parts = prop.split('.');
let target = this._target;
while (parts.length > 1) {
target = target[parts.shift()];
if (!target) {
throw new Error(`Property '${prop}' is invalid on target.`);
}
}
start[prop] = target[parts.shift()];
}
}
return start;
}
endDefaults(from) {
const end = {};
for (let prop in from) {
if (prop.indexOf('.') < 0) {
end[prop] = this._target[prop];
}
else {
const parts = prop.split('.');
let target = this._target;
while (parts.length > 1) {
target = target[parts.shift()];
if (!target) {
throw new Error(`Property '${prop}' is invalid on target.`);
}
}
end[prop] = target[parts.shift()];
}
}
return end;
}
validate(obj1, obj2) {
const a1 = Object.keys(obj1);
const a2 = Object.keys(obj2);
const result = a1.filter((val) => {
return a2.indexOf(val) < 0;
});
return result.length === 0;
}
}
exports.default = Tween;
},{"./log":176,"eases":undefined,"events":undefined}],174:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Tween_1 = require("./Tween");
const assert = require("assert");
const async = require("async");
class TweenManager {
static play(target, options, complete) {
assert.equal(typeof target, 'object', 'target must be an object');
const tween = this._create();
tween.init(target, options, complete);
this._tweens.push(tween);
return tween;
}
static playSet(targets, options, setOptions) {
if (typeof setOptions === "function") {
setOptions = {
complete: setOptions
};
}
setOptions = Object.assign({
focus: 0,
delay: 0,
focusIsLast: false,
complete: null,
completeOnFirst: false
}, setOptions || {});
const startDelay = options.delay || 0;
const tasks = [];
let focus = setOptions.focus;
const delay = setOptions.delay;
const focusIsLast = !!setOptions.focusIsLast;
const complete = setOptions.complete;
let completeOnFirst = (complete !== null) && !!setOptions.completeOnFirst;
const numTargets = targets.length;
if (focus >= numTargets) {
focus = numTargets - 1;
}
else if (focus < 0) {
focus = 0;
}
const delays = new Array(numTargets);
delays.fill(0);
if (delay > 0) {
delays[focus] = 0;
let maxDelay = 0;
let currentDelay = delay;
for (let i = focus - 1; i >= 0; i--) {
delays[i] = currentDelay;
maxDelay = Math.max(currentDelay, maxDelay);
currentDelay += delay;
}
currentDelay = delay;
for (let i = focus + 1; i < numTargets; i++) {
delays[i] = currentDelay;
maxDelay = Math.max(currentDelay, maxDelay);
currentDelay += delay;
}
if (focusIsLast) {
delays.forEach((d, i) => {
delays[i] = maxDelay - d;
});
}
}
delays.forEach((d, i) => {
const target = targets[i];
const localOptions = Object.assign({}, options);
localOptions.delay = startDelay + d;
const tween = this.play(target, localOptions);
tween.paused = true;
tasks.push((done) => {
tween.paused = false;
tween.once('complete', () => {
done(null);
if (completeOnFirst) {
completeOnFirst = false;
if (complete) {
complete();
}
}
});
});
});
if (completeOnFirst) {
async.parallel(tasks);
}
else {
async.parallel(tasks, () => {
if (complete) {
complete();
}
});
}
}
static stop(target) {
const tweens = this._tweens;
if (!target) {
while (tweens.length) {
this._pool(tweens.pop());
}
}
else {
for (let i = tweens.length - 1, tween; i >= 0; i--) {
tween = tweens[i];
if (tween.target === target) {
if (!tween.inProcess) {
this._pool(tween);
}
}
}
}
}
static stopCheck(check, against) {
const tweens = this._tweens;
for (let i = tweens.length - 1, tween; i >= 0; i--) {
tween = tweens[i];
if (check(tween.target, against)) {
if (!tween.inProcess) {
this._pool(tween);
}
}
}
}
static set paused(paused) {
this._tweens.forEach((tween) => {
tween.paused = paused;
});
}
static update(elapsed) {
const tweens = this._tweens;
for (let i = tweens.length - 1, tween; i >= 0; i--) {
tween = tweens[i];
if (tween) {
if (tween.time >= 0 && tween.time < 1) {
tween.update(elapsed);
}
if (tween.time >= 1) {
tween.completed();
this._pool(tween);
}
}
}
}
static _pool(tween) {
const i = this._tweens.indexOf(tween);
tween.reset();
if (i > -1) {
this._tweens.splice(i, 1);
this._tweensPool.push(tween);
}
}
static _create() {
if (this._tweensPool.length) {
return this._tweensPool.pop();
}
return new Tween_1.default();
}
}
TweenManager._tweens = [];
TweenManager._tweensPool = [];
exports.default = TweenManager;
},{"./Tween":173,"assert":undefined,"async":undefined}],175:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const TweenManager_1 = require("./TweenManager");
const Tween_1 = require("./Tween");
exports.default = {
TweenManager: TweenManager_1.default,
Tween: Tween_1.default
};
},{"./Tween":173,"./TweenManager":174}],176:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../../log");
exports.default = log_1.default.createChild('GUI');
},{"../../log":75}],177:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class SessionManager {
constructor() {
this.token = "abcdef";
}
}
exports.default = SessionManager;
},{}],178:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_typed_events_1 = require("jibo-typed-events");
class GlobalEvent extends jibo_typed_events_1.Event {
constructor(name) {
super(name);
this._subscriberOff = [];
this._subscriberOn = [];
}
checkLastListener() {
if (this.listenerCount() === 0) {
this.emitNoListeners();
}
}
onNoListeners(handler) {
this._subscriberOff.push(handler);
return this;
}
emitNoListeners() {
let copy = this._subscriberOff.slice();
for (let i = 0; i < copy.length; i++) {
let handler = copy[i];
handler();
}
}
onAddedListener(handler) {
this._subscriberOn.push(handler);
return this;
}
emitAddListener() {
let copy = this._subscriberOn.slice();
for (let i = 0; i < copy.length; i++) {
let handler = copy[i];
handler();
}
}
on(handler) {
this.emitAddListener();
return super.on(handler);
}
once(handler) {
this.emitAddListener();
return super.once(handler);
}
addListener(handler) {
this.emitAddListener();
return super.addListener(handler);
}
removeListener(handler) {
const result = super.removeListener(handler);
this.checkLastListener();
return result;
}
off(handler) {
const result = super.removeListener(handler);
this.checkLastListener();
return result;
}
removeAllListeners() {
this.emitNoListeners();
return super.removeAllListeners();
}
removeFirstListener() {
const result = super.removeFirstListener();
this.checkLastListener();
return result;
}
removeLastListener() {
const result = super.removeLastListener();
this.checkLastListener();
return result;
}
}
exports.GlobalEvent = GlobalEvent;
},{"jibo-typed-events":undefined}],179:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_typed_events_1 = require("jibo-typed-events");
const GlobalEvent_1 = require("./GlobalEvent");
const SharedGlobalEvents_1 = require("./SharedGlobalEvents");
const jibo_common_types_1 = require("jibo-common-types");
const jibo_client_framework_1 = require("jibo-client-framework");
const jetstream_client_1 = require("@jibo/jetstream-client");
var ListenResult = jetstream_client_1.types.ListenResult;
const Runtime_1 = require("../../Runtime");
const log_1 = require("./log");
class GlobalEvents extends jibo_typed_events_1.EventContainer {
constructor() {
super();
this.log = log_1.default.createChild('Global');
this.eventsWithHandlers = new Set();
this.global = new jibo_typed_events_1.Event(`Any global event`);
this.voiceStop = new GlobalEvent_1.GlobalEvent(jibo_common_types_1.GlobalCommand.STOP);
this.help = new GlobalEvent_1.GlobalEvent(jibo_common_types_1.GlobalCommand.HELP);
this.sleep = new GlobalEvent_1.GlobalEvent(jibo_common_types_1.GlobalCommand.SLEEP);
this.pause = new GlobalEvent_1.GlobalEvent(jibo_common_types_1.GlobalCommand.PAUSE);
this.volume = new GlobalEvent_1.GlobalEvent(jibo_common_types_1.GlobalCommand.VOLUME);
this.whatCanIDo = new GlobalEvent_1.GlobalEvent(jibo_common_types_1.GlobalCommand.WHATCANIDO);
this.holdOn = new GlobalEvent_1.GlobalEvent(jibo_common_types_1.GlobalCommand.HOLDON);
this.overHere = new GlobalEvent_1.GlobalEvent(jibo_common_types_1.GlobalCommand.OVERHERE);
this.skillLaunch = new jibo_typed_events_1.Event('skill-launch');
this.skillRelaunch = new jibo_typed_events_1.Event('skill-relaunch');
this.touchStop = new GlobalEvent_1.GlobalEvent('TOUCH');
this.shared = new SharedGlobalEvents_1.default();
this.voiceEvents = [
this.help,
this.voiceStop,
this.sleep,
this.pause,
this.whatCanIDo,
this.holdOn,
this.volume,
this.overHere
];
this.setGlobalEvents();
this.eventHandlers = {
'global': this.onGlobal.bind(this),
'skill-launch': this.onSkillLaunch.bind(this),
'skill-relaunch': this.onSkillRelaunch.bind(this),
'non-interrupting-global': this.onNonInterrupting.bind(this),
};
this._initializeTouchListener();
}
init(service, cb) {
service.host = '127.0.0.1';
const globalUrl = "ws:" + service.host + ":" + service.port + "/globals";
this._httpInterface = "http://" + service.host + ":" + service.port;
this._globalSocket = new jibo_client_framework_1.WSClient(globalUrl);
this._globalSocket.on('error', (err) => {
this.log.warn("error connecting to server ", err);
});
this._globalSocket.on('message', (data) => {
this.onMessage(data);
});
this.shared.init();
cb();
}
announceGlobalHandler(action, canHandle) {
this.log.info(`setting ${action} to ${canHandle}`);
let body = {
"action": action,
"canHandle": canHandle,
};
let request = new XMLHttpRequest();
body = JSON.stringify(body);
request.open("POST", this._httpInterface + '/global', true);
request.send(body);
return;
}
setGlobalEvents() {
this.voiceEvents.forEach((globalEvent) => {
globalEvent.setMode(jibo_typed_events_1.EmitterMode.LAST_HANDLER);
globalEvent.onNoListeners(() => {
this.announceGlobalHandler(jibo_common_types_1.GlobalCommand[globalEvent.name], false);
this.eventsWithHandlers.delete(globalEvent.name);
});
globalEvent.onAddedListener(() => {
this.log.info("adding listener for ", globalEvent.name);
this.eventsWithHandlers.add(globalEvent.name);
this.announceGlobalHandler(jibo_common_types_1.GlobalCommand[globalEvent.name], true);
});
});
}
onMessage(data) {
if (data.status !== "OK") {
this.log.warn("GlobalEvents returned status", data.status);
}
else {
let handler = this.eventHandlers[data.message];
if (handler) {
handler(data);
}
}
}
onGlobal(data) {
const result = ListenResult.fromJSON(data.result);
this.log.info("global data from ssm", result);
let action = result.nlu.intent;
if (action.match(/^volume/)) {
action = 'volume';
}
const event = this._getGlobalEvent(action);
let analyticsAction;
let analyticsData = {};
action = action.toUpperCase();
switch (action) {
case jibo_common_types_1.GlobalCommand.STOP:
analyticsAction = 'Stop';
analyticsData.type = 'speech';
break;
case jibo_common_types_1.GlobalCommand.SLEEP:
analyticsAction = 'Go To Sleep';
break;
case jibo_common_types_1.GlobalCommand.VOLUME:
analyticsAction = 'Volume';
analyticsData.type = 'speech';
break;
}
if (analyticsAction) {
Runtime_1.default.instance.analytics.track(`Global ${analyticsAction}`, analyticsData);
}
if (event) {
this.log.info("accessing global", action, "command");
event.emit(result);
this.global.emit({
name: action,
data: result
});
}
else {
this.log.error("No global event found:", action);
}
return;
}
onSkillRelaunch(data) {
const result = ListenResult.fromJSON(data.result);
this.log.info("skill relaunch command from Global Service", result);
let action = result.intent;
let skill = result.match.skillID;
if (result.transID && !result.match.onRobot) {
result.cloudSkillResponse = Runtime_1.default.instance.jetstream.getCloudSkillResponse(result.transID);
}
let analyticsAction;
let analyticsData = {};
if (action) {
action = action.toUpperCase();
switch (action) {
case jibo_common_types_1.GlobalCommand.HELP:
case jibo_common_types_1.GlobalCommand.WHATCANIDO:
analyticsAction = 'WCYD';
break;
}
}
if (!analyticsAction && (skill === '@be/main-menu')) {
analyticsAction = 'Main Menu';
analyticsData.type = 'speech';
}
if (analyticsAction) {
Runtime_1.default.instance.analytics.track(`Global ${analyticsAction}`, analyticsData);
}
this.skillRelaunch.emit(result);
}
onNonInterrupting(data) {
this.shared.nonInterruptingGlobal.emit();
}
onSkillLaunch(data) {
this.skillLaunch.emit(ListenResult.fromJSON(data.result));
}
_getGlobalEvent(eventName) {
let event = null;
this.voiceEvents.forEach((globalEvent) => {
if (globalEvent.name === eventName || globalEvent.name === jibo_common_types_1.GlobalCommandMap.get(eventName)) {
event = globalEvent;
}
});
return event;
}
_initializeTouchListener() {
this.touchStop.setMode(jibo_typed_events_1.EmitterMode.LAST_HANDLER);
}
}
exports.default = GlobalEvents;
},{"../../Runtime":1,"./GlobalEvent":178,"./SharedGlobalEvents":180,"./log":182,"@jibo/jetstream-client":undefined,"jibo-client-framework":undefined,"jibo-common-types":undefined,"jibo-typed-events":undefined}],180:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_typed_events_1 = require("jibo-typed-events");
const jetstream_client_1 = require("@jibo/jetstream-client");
const Runtime_1 = require("../../Runtime");
class SharedGlobalEvents {
constructor() {
this.hjOnly = new jibo_typed_events_1.Event('Received only a "hey jibo"');
this.noGlobalMatch = new jibo_typed_events_1.Event('Parsed against global grammar and no result');
this.nonInterruptingGlobal = new jibo_typed_events_1.Event('GL global command complete that did not interrupt state');
this.screenGesture = new jibo_typed_events_1.Event('Touch manager received a screen gesture');
}
init() {
const jetstream = Runtime_1.default.instance.jetstream;
jetstream.events.globalTurnResult.on((result) => {
if (result.status === jetstream_client_1.types.TurnResultType.TIMEOUT || result.status === jetstream_client_1.types.TurnResultType.FAILED) {
this.hjOnly.emit(result);
return;
}
if (result.status === jetstream_client_1.types.TurnResultType.SUCCEEDED) {
const annotation = result.result.asr ? result.result.asr.annotation : null;
if (annotation === jetstream.types.ASRAnnotation.GARBAGE ||
annotation === jetstream.types.ASRAnnotation.SOS_TIMEOUT ||
annotation === jetstream.types.ASRAnnotation.MAX_SPEECH_TIMEOUT) {
this.hjOnly.emit(result);
return;
}
if ((result.result.state === jetstream.types.ListenResultState.noMatch) ||
(!result.result.match && result.result.nlu.rules.indexOf('launch') >= 0)) {
this.noGlobalMatch.emit(result);
return;
}
}
});
jetstream.events.hjOnly.on(() => {
this.hjOnly.emit();
});
}
}
exports.default = SharedGlobalEvents;
},{"../../Runtime":1,"@jibo/jetstream-client":undefined,"jibo-typed-events":undefined}],181:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const GlobalEvents_1 = require("./GlobalEvents");
exports.default = {
GlobalEvents: GlobalEvents_1.default
};
},{"./GlobalEvents":179}],182:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../../log");
exports.default = log_1.default.createChild('Events');
},{"../../log":75}],183:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const SessionManager_1 = require("./SessionManager");
const Media_1 = require("./media/Media");
const GlobalEvents_1 = require("./events/GlobalEvents");
const kb = require("jibo-kb");
const RemoteService_1 = require("./remote/RemoteService");
exports.default = {
GlobalEvents: GlobalEvents_1.default,
SessionManager: SessionManager_1.default,
Media: Media_1.default,
kb,
RemoteService: RemoteService_1.default
};
},{"./SessionManager":177,"./events/GlobalEvents":179,"./media/Media":184,"./remote/RemoteService":190,"jibo-kb":undefined}],184:[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 Runtime_1 = require("../../Runtime");
const jibo_service_clients_1 = require("jibo-service-clients");
const MediaModel_1 = require("./MediaModel");
const MediaNode_1 = require("./MediaNode");
const decorators_1 = require("../../utils/decorators");
var CameraID = jibo_service_clients_1.media.CameraID;
exports.CameraID = CameraID;
var PhotoType = jibo_service_clients_1.media.PhotoType;
exports.PhotoType = PhotoType;
const log_1 = require("./log");
var FilterFlipMethod;
(function (FilterFlipMethod) {
FilterFlipMethod[FilterFlipMethod["IDENTITY"] = 0] = "IDENTITY";
FilterFlipMethod[FilterFlipMethod["HORIZONTAL"] = 1] = "HORIZONTAL";
FilterFlipMethod[FilterFlipMethod["VERTICAL"] = 2] = "VERTICAL";
})(FilterFlipMethod = exports.FilterFlipMethod || (exports.FilterFlipMethod = {}));
var ThumbnailType;
(function (ThumbnailType) {
ThumbnailType["thumb"] = "thumb";
ThumbnailType["thumb_robot"] = "thumb_robot";
})(ThumbnailType = exports.ThumbnailType || (exports.ThumbnailType = {}));
class Media {
constructor() {
this.isInitialized = false;
this.CameraID = CameraID;
this.PhotoType = PhotoType;
this.ThumbnailType = ThumbnailType;
this.mediaService = jibo_service_clients_1.media;
this.mediaManagerService = jibo_service_clients_1.mediaManager;
}
init(callback) {
let records = Runtime_1.default.instance.records;
for (let i = 0; i < records.length; i++) {
if (records[i].name === 'media-proxy') {
let record = records[i];
this.proxyUrl = `http://${record.host}:${record.port}`;
break;
}
}
if (this.proxyUrl) {
log_1.default.info('proxyUrl', this.proxyUrl);
}
else {
log_1.default.error('could not find media-manager service');
}
let kb = Runtime_1.default.instance.kb;
kb.registerModelClass('jibo/media', MediaModel_1.default);
kb.registerNodeClass('media', MediaNode_1.default, 'jibo/media');
kb.media = kb.createModel('/jibo/media');
this.isInitialized = true;
process.nextTick(callback);
}
takePhoto(params, callback) {
if (typeof params === 'function') {
callback = params;
params = {};
}
let camera = params.camera;
if (camera !== undefined && camera !== CameraID.LEFT && camera !== CameraID.RIGHT) {
camera = undefined;
}
if (camera === undefined) {
camera = CameraID.RIGHT;
}
let photoType = params.photoType;
if (photoType !== undefined && (params.photoType < PhotoType.DEBUG || params.photoType > PhotoType.FOUR_MP)) {
photoType = undefined;
}
if (photoType === undefined) {
params.photoType = PhotoType.SNAP;
}
let undistort = params.undistort;
if (undistort === undefined) {
undistort = true;
}
else {
undistort = !!undistort;
}
let flip = params.flip;
if (flip === undefined) {
flip = true;
}
else {
flip = !!flip;
}
let colorCorrection = params.colorCorrection;
if (colorCorrection === undefined) {
colorCorrection = true;
}
else {
colorCorrection = !!colorCorrection;
}
let filters = [];
if (undistort) {
filters.push({
kind: 'undistort',
config: {}
});
}
if (flip) {
filters.push({
kind: 'flip',
config: {
method: FilterFlipMethod.HORIZONTAL
}
});
}
if (colorCorrection) {
filters.push({
'kind': 'brightness_contrast',
'config': {
'brightness': 0.08,
'contrast': -0.1
}
});
filters.push({
'kind': 'vibrance',
'config': {
'amount': 0.1
}
});
filters.push({
'kind': 'hue_saturation',
'config': {
'hue': 0,
'saturation': 0.05
}
});
filters.push({
'kind': 'rgb_curve',
'config': {
'red': [[0.1, 0], [0.5, 0.48], [1, 1]],
'blue': [[0.1, 0], [0.5, 0.51], [1, 1]],
'green': [[0.1, 0], [0.5, 0.5], [1, 1]]
}
});
}
if (params.filters) {
filters = filters.concat(params.filters);
}
let store = false;
this.mediaService.takePhoto(camera, photoType, filters, store, (err, data) => {
if (err) {
callback(err);
}
else {
let response = {
id: data.id,
url: this.getPreviewUrl(data.id)
};
callback(null, response);
}
});
}
storePhoto(one, two, three) {
let id;
let buffer;
let params;
let callback;
if (typeof one === 'string' || one instanceof Buffer) {
if (one instanceof Buffer) {
buffer = one;
}
else {
id = one;
}
if (typeof two === 'function') {
params = {};
callback = two;
}
else {
params = two;
callback = three;
}
}
else {
params = one;
callback = two;
}
id = id || params.id;
buffer = buffer || params.buffer;
if ((!buffer && !id) || (id && buffer)) {
throw new Error('storePhoto requires either id or buffer');
}
let thumbnails = {};
thumbnails[ThumbnailType.thumb] = [720, 405];
thumbnails[ThumbnailType.thumb_robot] = [330, 330];
let timer = performance.now();
this.mediaService.storePhoto(buffer, id, thumbnails, (err, data) => {
if (err) {
callback(err);
}
else {
Runtime_1.default.instance.kb.media.storePhoto(data, (err, response) => {
let elapsed = Math.round(performance.now() - timer);
console.warn('storePhoto total time took ' + elapsed + 'ms');
callback(err, response);
});
}
});
}
deletePhoto(id, callback) {
let immediate = true;
let deleteLocal = true;
let deleteRemote = false;
let mediaType = this.mediaManagerService.MediaType.image;
let timer = performance.now();
this.mediaManagerService.delete(id, immediate, deleteLocal, deleteRemote, mediaType, (err) => {
if (err) {
log_1.default.iferr(err);
callback(err);
}
else {
Runtime_1.default.instance.kb.media.deletePhoto(id, (err) => {
let elapsed = Math.round(performance.now() - timer);
log_1.default.info('local deletePhoto took ' + elapsed + 'ms');
callback();
});
}
});
}
getPhoto(id, callback) {
let url = this.getUrl(id);
Runtime_1.default.instance.loader.load({
format: 'image',
src: url,
type: 'texture'
}, callback);
}
getUrl(contentId) {
return `${this.proxyUrl}/proxy/media/photo/get?id=${contentId}`;
}
getPreviewUrl(id) {
return this.mediaService.getPreviewUrl(id);
}
setViewfinder(one, two, three) {
let enable;
let params;
let callback;
if (one !== null && typeof one === 'object') {
params = one;
callback = two;
enable = params.enable;
}
else if (!three && typeof two === 'function') {
enable = one;
callback = two;
params = {};
}
else {
enable = one;
params = two;
callback = three;
}
let assignIfDefined = (source, target, keys) => {
keys.forEach((key) => {
if (source[key] !== undefined) {
target[key] = source[key];
}
});
};
let data = { enable: enable };
assignIfDefined(params, data, ['camera', 'height', 'width', 'x', 'y']);
this.mediaService.setViewfinder(data, callback);
}
getViewfinder(callback) {
this.mediaService.getViewfinder(callback);
}
}
__decorate([
decorators_1.promisify,
decorators_1.isInitialized
], Media.prototype, "takePhoto", null);
__decorate([
decorators_1.promisify,
decorators_1.isInitialized
], Media.prototype, "storePhoto", null);
__decorate([
decorators_1.promisify
], Media.prototype, "deletePhoto", null);
__decorate([
decorators_1.promisify,
decorators_1.isInitialized
], Media.prototype, "getPhoto", null);
__decorate([
decorators_1.promisify,
decorators_1.isInitialized
], Media.prototype, "setViewfinder", null);
__decorate([
decorators_1.promisify,
decorators_1.isInitialized
], Media.prototype, "getViewfinder", null);
exports.Media = Media;
exports.default = Media;
},{"../../Runtime":1,"../../utils/decorators":204,"./MediaModel":185,"./MediaNode":187,"./log":188,"jibo-service-clients":undefined}],185:[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 axios_1 = require("axios");
const Runtime_1 = require("../../Runtime");
const decorators_1 = require("../../utils/decorators");
const MediaNode_1 = require("./MediaNode");
const Media_1 = require("./Media");
var Media_2 = require("./Media");
exports.ThumbnailType = Media_2.ThumbnailType;
const jibo_service_clients_1 = require("jibo-service-clients");
var MediaType = jibo_service_clients_1.mediaManager.MediaType;
const jibo_kb_1 = require("jibo-kb");
const MediaModelEvents_1 = require("./MediaModelEvents");
const jibo_client_framework_1 = require("jibo-client-framework");
const log_1 = require("./log");
const log = log_1.default.createChild('Model');
class MediaModel extends jibo_kb_1.Model {
constructor(kbNames, httpUrl = null) {
super(kbNames, httpUrl);
this.MediaNode = MediaNode_1.default;
this.MediaType = MediaType;
this.ThumbnailType = Media_1.ThumbnailType;
this.events = new MediaModelEvents_1.default();
this._listenForWSMessages();
}
static _processError(err) {
if (err.response) {
let description = `HTTP Error Code ${err.response.status}`;
if (err.response.data) {
description += err.response.data;
}
return new Error(description);
}
else {
return new Error(err.request
? 'No response received'
: 'Unknown error');
}
}
loadMedia(callback) {
this.loadMediaAll((err, media) => {
if (!err) {
callback(null, this._onlyNotDeleted(media));
}
else {
callback(err);
}
});
}
loadMediaAll(callback) {
this.loadRoot(null, (err, rootNode) => {
log.iferr(err, 'loadRoot');
if (!err && rootNode) {
let mediaIds = rootNode.getEdges('media');
this.load(mediaIds, (err, nodes) => {
log.iferr(err, 'load');
callback(err, nodes);
});
}
else {
callback(err);
}
});
}
loadThumbnail(mediaNode, two, three) {
let type;
let callback;
if (typeof two === 'function') {
type = null;
callback = two;
}
else {
type = two;
callback = three;
}
type = type || Media_1.ThumbnailType.thumb_robot;
let thumbId = mediaNode.getThumbnailId(type);
this.load(thumbId, callback);
}
getThumbnailUrl(mediaNode, type) {
type = type || Media_1.ThumbnailType.thumb_robot;
let thumbId = mediaNode.getThumbnailId(type);
return Runtime_1.default.instance.media.getUrl(thumbId);
}
downloadThumbnails(ids, callback) {
let url = `${this.httpUrl}/v1/media/downloadThumbnails`;
let params = {
ids: ids,
type: 'image'
};
axios_1.default.post(url, params)
.then(res => callback && callback(null), (err) => {
log.error('request.post', url, err);
if (callback) {
callback(MediaModel._processError(err));
}
});
}
downloadPhoto(id, callback) {
let url = `${this.httpUrl}/v1/media/downloadPhoto`;
let params = {
id: id,
type: 'image'
};
axios_1.default.post(url, params).then(res => callback && callback(null), (err) => {
log.error('request.post', url, err);
if (callback) {
callback(MediaModel._processError(err));
}
});
}
storePhoto(data, callback) {
let url = `${this.httpUrl}/v1/media/storePhoto`;
let params = data;
axios_1.default.post(url, params).then(res => callback && callback(null, res.data), (err) => {
log.error('request.post', url, err);
if (callback) {
callback(MediaModel._processError(err));
}
});
}
deletePhoto(id, callback) {
let url = `${this.httpUrl}/v1/media/deletePhoto`;
let params = {
id: id
};
axios_1.default.post(url, params).then(res => callback && callback(null), (err) => {
log.error('request.post', url, err);
if (callback) {
callback(MediaModel._processError(err));
}
});
}
_listenForWSMessages() {
this._wsClient = new jibo_client_framework_1.WSClient(this.httpUrl);
this._wsClient.on('message', this._wsMessageReceived.bind(this));
}
_wsMessageReceived(message) {
switch (message) {
case 'MediaListChanged':
log.info('MediaModel: received MediaListChanged event; emitting MediaModelEvents.mediaListChanged');
this.events.mediaListChanged.emit();
break;
}
}
_onlyNotDeleted(media) {
return media.filter((media) => { return media && !media.data.isDeleted; });
}
}
__decorate([
decorators_1.promisify
], MediaModel.prototype, "loadMedia", null);
__decorate([
decorators_1.promisify
], MediaModel.prototype, "loadMediaAll", null);
__decorate([
decorators_1.promisify
], MediaModel.prototype, "loadThumbnail", null);
__decorate([
decorators_1.promisify
], MediaModel.prototype, "downloadThumbnails", null);
__decorate([
decorators_1.promisify
], MediaModel.prototype, "downloadPhoto", null);
__decorate([
decorators_1.promisify
], MediaModel.prototype, "storePhoto", null);
__decorate([
decorators_1.promisify
], MediaModel.prototype, "deletePhoto", null);
exports.default = MediaModel;
},{"../../Runtime":1,"../../utils/decorators":204,"./Media":184,"./MediaModelEvents":186,"./MediaNode":187,"./log":188,"axios":undefined,"jibo-client-framework":undefined,"jibo-kb":undefined,"jibo-service-clients":undefined}],186:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_typed_events_1 = require("jibo-typed-events");
class MediaModelEvents extends jibo_typed_events_1.EventContainer {
constructor() {
super(...arguments);
this.mediaListChanged = new jibo_typed_events_1.Event('Media list has changed');
}
}
exports.default = MediaModelEvents;
},{"jibo-typed-events":undefined}],187:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_kb_1 = require("jibo-kb");
const Media_1 = require("./Media");
var Media_2 = require("./Media");
exports.ThumbnailType = Media_2.ThumbnailType;
class MediaNode extends jibo_kb_1.Node {
get id() {
return this._id;
}
get loopId() {
return this.data.loopId;
}
get url() {
return this.data.url;
}
getThumbnailId(type) {
type = type || Media_1.ThumbnailType.thumb_robot;
return this.getEdges(Media_1.ThumbnailType[type])[0];
}
}
exports.default = MediaNode;
},{"./Media":184,"jibo-kb":undefined}],188:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../../log");
exports.default = log_1.default.createChild('Media');
},{"../../log":75}],189:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IncomingTypes;
(function (IncomingTypes) {
IncomingTypes["CONNECTED"] = "connected";
IncomingTypes["DISCONNECTED"] = "disconnected";
IncomingTypes["SEND_ERROR"] = "sendError";
})(IncomingTypes = exports.IncomingTypes || (exports.IncomingTypes = {}));
},{}],190:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_client_framework_1 = require("jibo-client-framework");
const jibo_typed_events_1 = require("jibo-typed-events");
const jibo_command_library_1 = require("jibo-command-library");
const jibo_command_protocol_1 = require("jibo-command-protocol");
const Runtime_1 = require("../../Runtime");
const timer = require("application-metrics");
const Messages_1 = require("./Messages");
const log_1 = require("../../log");
const log = log_1.default.createChild('RemoteService');
exports.REMOTE_SESSION = 'remote';
class RemoteService {
constructor() {
this._blockCloseResponse = false;
this.onMessageIn = this.onMessageIn.bind(this);
this.onMessageOut = this.onMessageOut.bind(this);
this.onConnectionEnded = this.onConnectionEnded.bind(this);
this._remoteSocket = null;
jibo_command_library_1.default.createInstance(Runtime_1.default.instance);
this._remoteConnection = this.createCommandConnector(exports.REMOTE_SESSION, false);
this.sessionDiscarded = new jibo_typed_events_1.Event('Remote session closed');
}
init(service, cb) {
service.host = '127.0.0.1';
const url = "ws:" + service.host + ":" + service.port;
this._remoteSocket = new jibo_client_framework_1.WSClient(url);
this._remoteSocket.on('error', (err) => {
log.warn("error connecting to server ", err);
});
this._remoteSocket.on('message', this.onMessageIn);
cb();
}
createCommandConnector(id, startReady = true) {
if (jibo_command_library_1.default.instance) {
return jibo_command_library_1.default.instance.createCommandConnector(id, startReady);
}
else {
log.warn('createCommandConnector : CommandLibrary.instance is not yet defined');
return null;
}
}
ready() {
this._remoteConnection.ready(true);
log.debug('Command Performance : time to remote skill ready : ' + timer.stop('onMessageIn::CONNECTED') + 'ms');
}
closeConnection(code = jibo_command_protocol_1.DisconnectCode.RobotError) {
if (!this._remoteConnection.disconnect(code)) {
this.onConnectionEnded(code);
}
log.info('disconnected with code', code);
}
handleVideo(assetUrl, videoType) {
const message = {
type: 'message',
status: 'handleAsset',
asset: {
assetUrl: assetUrl,
type: 'video',
videoType
}
};
this.onMessageOut(message);
}
handlePhoto(assetUrl, photoUrl) {
const message = {
type: 'message',
status: 'handleAsset',
asset: {
assetUrl: assetUrl,
type: 'photo',
photoUrl: photoUrl
}
};
this.onMessageOut(message);
}
cancelAsset(assetUrl) {
const message = {
type: 'message',
status: 'cancelAsset',
asset: {
assetUrl: assetUrl
}
};
this.onMessageOut(message);
}
onMessageIn(message) {
let data;
try {
if (typeof message === 'string') {
data = JSON.parse(message);
}
else {
data = message;
}
}
catch (e) {
log.warn('Unable to parse json message from SSM Remote service');
return;
}
this._blockCloseResponse = true;
if (data.type === 'message') {
const message = data;
switch (message.status) {
case Messages_1.IncomingTypes.CONNECTED:
timer.start('onMessageIn::CONNECTED');
this.connectToCommandLibrary(message);
break;
case Messages_1.IncomingTypes.DISCONNECTED:
if (!message.wasError) {
this.closeConnection();
}
else {
this._remoteConnection.awaitReconnect();
}
break;
case Messages_1.IncomingTypes.SEND_ERROR:
this._remoteConnection.responseFailed(message.message);
break;
}
}
else {
this._remoteConnection.sendMessage(data);
}
this._blockCloseResponse = false;
}
connectToCommandLibrary(message) {
log.info('sendConnectionEvent message:', message);
let aco;
if (message && message.appData && message.appData.aco) {
aco = message.appData.aco;
}
else {
log.warn('No ACO sent with connection message, using a default ACO');
aco = {
version: jibo_command_protocol_1.ProtocolVersions.v1,
sourceId: 'testApp',
commandSet: [
jibo_command_protocol_1.CommandTypes.GetConfig,
jibo_command_protocol_1.CommandTypes.LookAt,
jibo_command_protocol_1.CommandTypes.Say,
jibo_command_protocol_1.CommandTypes.TakePhoto,
jibo_command_protocol_1.CommandTypes.Video,
],
streamSet: [
jibo_command_protocol_1.StreamTypes.Entity,
jibo_command_protocol_1.StreamTypes.Motion,
],
keepAliveTimeout: 10 * 1000,
recoveryTimeout: 20 * 1000,
remoteConfig: {
hideVisualCue: false,
inactivityTimeout: 10 * 60 * 1000
}
};
}
log.info('sendConnectionEvent aco:', aco);
this._remoteConnection.connect(aco, this.onMessageOut, this.onConnectionEnded);
let intent = aco.remoteConfig.hideVisualCue ? 'silentRemote' : 'normalRemote';
if (!this._remoteConnection.isReady) {
log.info('connected. Request skill redirect to @be/remote');
const parseResults = new Runtime_1.default.instance.jetstream.types.ListenResult({
text: '',
confidence: 1
}, {
entities: {},
rules: null,
intent: intent,
}, {
skillID: '@be/remote',
onRobot: true
});
const launchMessage = {
type: 'message',
status: 'launchSkill',
result: parseResults
};
this.onMessageOut(launchMessage);
}
}
onMessageOut(message) {
if (this._remoteSocket) {
this._remoteSocket.send(JSON.stringify(message));
}
else {
log.warn('onMessageOut : remote socket is null, cannot send message');
}
}
onConnectionEnded(code = jibo_command_protocol_1.DisconnectCode.RobotError) {
this._remoteConnection.ready(false);
this.sessionDiscarded.emit();
if (!this._blockCloseResponse) {
const reason = jibo_command_protocol_1.DisconnectReason[code];
const message = {
type: 'message',
status: 'close',
code,
reason
};
this.onMessageOut(message);
}
}
}
exports.default = RemoteService;
},{"../../Runtime":1,"../../log":75,"./Messages":189,"application-metrics":undefined,"jibo-client-framework":undefined,"jibo-command-library":undefined,"jibo-command-protocol":undefined,"jibo-typed-events":undefined}],191:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class ChainBuilder {
constructor(_context) {
this._context = _context;
this._firstNode = null;
this._lastNode = null;
this._nodes = {};
}
destroy() {
this._nodes = null;
this._context = null;
this._firstNode = null;
this._lastNode = null;
}
nodes() {
return this._nodes;
}
first() {
return this._firstNode;
}
last() {
return this._lastNode;
}
_addNode(node, properties) {
const lastIsBufferSource = this._lastNode && ('playbackRate' in this._lastNode);
if (lastIsBufferSource) {
this._bufferSourceDst = node;
}
if (this._lastNode) {
this._lastNode.connect(node);
}
if (!this._firstNode) {
this._firstNode = node;
}
this._lastNode = node;
for (let property in properties) {
node[property] = properties[property];
}
return this;
}
cloneBufferSource() {
console.assert(this._nodes.bufferSource, "No buffersource presents. Add one.");
const orig = this._nodes.bufferSource;
const clone = this._context.createBufferSource();
clone.buffer = orig.buffer;
clone.playbackRate.value = orig.playbackRate.value;
clone.loop = orig.loop;
clone.connect(this._bufferSourceDst);
return clone;
}
bufferSource(properties) {
const node = this._context.createBufferSource();
this._nodes.bufferSource = node;
return this._addNode(node, properties);
}
panner(properties) {
const node = this._context.createStereoPanner();
this._nodes.panner = node;
return this._addNode(node, properties);
}
analyser(properties) {
const node = this._context.createAnalyser();
this._nodes.analyser = node;
return this._addNode(node, properties);
}
gainNode(properties) {
const node = this._context.createGain();
this._nodes.gainNode = node;
return this._addNode(node, properties);
}
}
exports.default = ChainBuilder;
},{}],192:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ChainBuilder_1 = require("./ChainBuilder");
const SoundInstance_1 = require("./SoundInstance");
const Runtime_1 = require("../Runtime");
const jibo_plugins_1 = require("jibo-plugins");
const path = require("path");
const log_1 = require("./log");
class Sound {
constructor(context, options) {
if (typeof options === "string" || options instanceof ArrayBuffer) {
options = { src: options };
}
else if (options instanceof ArrayBuffer) {
options = { srcBuffer: options };
}
options = Object.assign({
autoPlay: false,
block: false,
src: null,
preload: false,
volume: 1,
panning: 0,
complete: null,
loaded: null,
loop: false,
useXHR: false
}, options || {});
this._context = context;
this._ctx = this._context.context;
this._chain = new ChainBuilder_1.default(this._ctx)
.bufferSource()
.gainNode()
.analyser()
.panner();
this.isLoaded = false;
this.isPlaying = false;
this.autoPlay = options.autoPlay;
this.block = options.block;
this.preload = options.preload;
this.complete = options.complete;
this.loaded = options.loaded;
this.src = options.src;
this.srcBuffer = options.srcBuffer;
this.useXHR = options.useXHR;
this._instances = [];
this._chain.last().connect(this._context._entryNode());
this._source = this._chain.nodes().bufferSource;
this._gainNode = this._chain.nodes().gainNode;
this._analyser = this._chain.nodes().analyser;
this._panner = this._chain.nodes().panner;
console.assert(this._source, "No bufferSource: not yet supported");
console.assert(this._gainNode, "No gainNode: not yet supported");
console.assert(this._analyser, "No analyser: not yet supported");
console.assert(this._panner, "No panner: not yet supported");
this.volume = options.volume;
this.panning = options.panning;
this.loop = options.loop;
if (this.preload) {
this._beginPreload();
}
}
_beginPreload() {
if (this.src) {
this.useXHR ? this.loadUrl() : this.loadPath();
}
else if (this.srcBuffer) {
this.decode(this.srcBuffer);
}
else if (this.loaded) {
this.loaded(new Error("sound.src or sound.srcBuffer must be set"));
}
else {
log_1.default.warn('sound.src or sound.srcBuffer must be set');
}
}
destroy() {
this._chain.last().disconnect();
this._chain.destroy();
this._chain = null;
this._context = null;
this._ctx = null;
this._source = null;
this._removeInstances();
this._instances = null;
}
get isPlayable() {
return this.isLoaded && !!this._source && !!this._source.buffer;
}
get nodes() {
return this._chain.nodes();
}
get volume() {
return this._gainNode.gain.value;
}
set volume(volume) {
this._gainNode.gain.value = volume;
}
get loop() {
return this._source.loop;
}
set loop(loop) {
this._source.loop = !!loop;
}
get buffer() {
return this._source.buffer;
}
set buffer(buffer) {
this._source.buffer = buffer;
}
get panning() {
return this._panner.pan;
}
set panning(pan) {
this._panner.pan.value = pan;
}
get instances() {
return this._instances;
}
play(options) {
if (typeof options === "function") {
options = { complete: options };
}
options = Object.assign({
complete: null,
loaded: null,
offset: 0
}, options || {});
if (!this.isPlayable) {
this.autoPlay = true;
if (!this.isLoaded) {
const loaded = options.loaded;
if (loaded) {
this.loaded = loaded;
}
this._beginPreload();
}
return;
}
if (this.block) {
this._removeInstances();
}
const instance = SoundInstance_1.default.create(this._chain);
this._instances.push(instance);
this.isPlaying = true;
instance.once('complete', () => {
this._onComplete(instance);
if (options.complete) {
options.complete(this);
}
});
instance.play(options.offset);
return instance;
}
_onComplete(instance) {
if (this._instances) {
const index = this._instances.indexOf(instance);
if (index > -1) {
this._instances.splice(index, 1);
}
this.isPlaying = this._instances.length > 0;
}
instance.destroy();
}
stop() {
if (!this.isPlayable) {
this.autoPlay = false;
return this;
}
this.isPlaying = false;
this._instances.forEach(function (instance) {
instance.stop();
});
return this;
}
pause() {
this._instances.forEach(function (instance) {
instance.paused = true;
});
this.isPlaying = false;
return this;
}
resume() {
this._instances.forEach(function (instance) {
instance.paused = false;
});
this.isPlaying = this._instances.length > 0;
return this;
}
_removeInstances() {
this._instances.forEach(function (instance) {
instance.destroy();
});
this._instances.length = 0;
}
loadUrl() {
const request = new XMLHttpRequest();
let src = this.src;
if (!jibo_plugins_1.PathUtils.isURL(src)) {
src = Runtime_1.default.instance.sound.baseUrl + src;
}
request.open('GET', src, true);
request.responseType = 'arraybuffer';
request.onload = () => {
this.isLoaded = true;
this.srcBuffer = request.response;
this.decode(request.response);
};
request.send();
}
loadPath() {
const fs = require('fs');
let src = this.src;
if (!path.isAbsolute(src)) {
src = jibo_plugins_1.PathUtils.getAssetUri(src, undefined, Runtime_1.default.instance.sound.basePath);
}
fs.readFile(src, (err, data) => {
if (err) {
log_1.default.error('problem reading file', err);
if (this.loaded) {
this.loaded(new Error(`File not found ${this.src}`));
}
return;
}
const arrayBuffer = new ArrayBuffer(data.length);
const view = new Uint8Array(arrayBuffer);
for (let i = 0; i < data.length; ++i) {
view[i] = data[i];
}
this.decode(arrayBuffer);
});
}
decode(arrayBuffer) {
this._ctx.decodeAudioData(arrayBuffer)
.then((buffer) => {
this.isLoaded = true;
this.buffer = buffer;
if (this.loaded) {
this.loaded(null, this);
}
if (this.autoPlay) {
this.play(this.complete);
}
}, (err) => {
if (this.loaded) {
this.loaded(new Error(`Unable to decode file ${err}`));
}
});
}
}
exports.default = Sound;
},{"../Runtime":1,"./ChainBuilder":191,"./SoundInstance":194,"./log":198,"fs":undefined,"jibo-plugins":undefined,"path":undefined}],193:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class SoundContext {
constructor() {
this._ctx = new AudioContext();
this._gainNode = this._ctx.createGain();
this._compressor = this._ctx.createDynamicsCompressor();
this._gainNode.connect(this._compressor);
this._compressor.connect(this._ctx.destination);
this.volume = 1;
this.muted = false;
this.paused = false;
}
destroy() {
this._ctx = null;
this._gainNode = null;
this._compressor = null;
}
get context() {
return this._ctx;
}
get muted() {
return this._muted;
}
set muted(muted) {
this._muted = !!muted;
this._gainNode.gain.value = this._muted ? 0 : this._volume;
}
set volume(volume) {
this._volume = volume;
if (!this._muted) {
this._gainNode.gain.value = this._volume;
}
}
get volume() {
return this._volume;
}
set paused(paused) {
if (paused && this._ctx.state === 'running') {
this._ctx.suspend();
}
else if (!paused && this._ctx.state === 'suspended') {
this._ctx.resume();
}
this._paused = paused;
}
get paused() {
return this._paused;
}
_entryNode() {
return this._gainNode;
}
toggleMute() {
this.muted = !this.muted;
return this._muted;
}
}
exports.default = SoundContext;
},{}],194:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
let id = 0;
class SoundInstance extends events_1.EventEmitter {
constructor(chain) {
super();
this.id = id++;
this._chain = null;
this._startTime = 0;
this._paused = false;
this._currentPosition = 0;
this.init(chain);
}
static create(chain) {
if (SoundInstance._pool.length > 0) {
let sound = SoundInstance._pool.pop();
sound.init(chain);
return sound;
}
else {
return new SoundInstance(chain);
}
}
init(chain) {
this._chain = chain;
}
stop() {
if (this._source) {
this._source.onended = null;
this._source.stop();
this._source = null;
}
}
play(offset) {
this._source = this._chain.cloneBufferSource();
this._startTime = Date.now();
this._source.onended = this._onComplete.bind(this);
this._source.start(0, offset || 0);
}
get paused() {
return this._paused;
}
set paused(paused) {
if (paused !== this._paused) {
this._paused = paused;
if (paused) {
this.stop();
this._currentPosition = Date.now() - this._startTime;
}
else {
this.play(this._currentPosition / 1000);
}
}
}
_onComplete() {
if (this._source) {
this._source.onended = null;
}
this._source = null;
this.emit('complete', this);
}
destroy() {
this.removeAllListeners('complete');
this.stop();
if (this._source) {
this._source.onended = null;
}
this._source = null;
this._chain = null;
this._startTime = 0;
this._paused = false;
this._currentPosition = 0;
if (SoundInstance._pool.indexOf(this) < 0) {
SoundInstance._pool.push(this);
}
}
toString() {
return '[SoundInstance id=' + this.id + ']';
}
}
SoundInstance._pool = [];
exports.default = SoundInstance;
},{"events":undefined}],195:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const SoundContext_1 = require("./SoundContext");
const Sound_1 = require("./Sound");
const SoundInstance_1 = require("./SoundInstance");
const SoundUtils_1 = require("./SoundUtils");
const SoundTask_1 = require("./tasks/SoundTask");
const Runtime_1 = require("../Runtime");
const jibo_log_1 = require("jibo-log");
class SoundPlugin {
constructor() {
this.basePath = '';
this.baseUrl = '';
this._context = new SoundContext_1.default();
this._sounds = {};
this.SoundUtils = SoundUtils_1.default;
this.Sound = Sound_1.default;
this.SoundInstance = SoundInstance_1.default;
Runtime_1.default.instance.loader.register(SoundTask_1.default, 50);
this.log = new jibo_log_1.Log('SoundPlugin');
}
init(done) {
done();
}
get context() {
return this._context;
}
add(alias, options) {
if (this._sounds[alias]) {
this.log.warn(`Sound with alias ${alias} already exists.`);
}
const sound = this._sounds[alias] = new Sound_1.default(this.context, options);
return sound;
}
addMap(map, globalOptions) {
let results = {};
for (let a in map) {
let options;
if (typeof map[a] === "string" || map[a] instanceof ArrayBuffer) {
options = { src: map[a] };
}
else {
options = map[a];
}
results[a] = this.add(a, Object.assign(options, globalOptions || {}));
}
return results;
}
remove(alias) {
if (this.exists(alias, true)) {
this._sounds[alias].destroy();
}
delete this._sounds[alias];
return this;
}
pauseAll() {
this._context.paused = true;
return this;
}
resumeAll() {
this._context.paused = false;
return this;
}
muteAll() {
this._context.muted = true;
return this;
}
unmuteAll() {
this._context.muted = false;
return this;
}
removeAll() {
for (let alias in this._sounds) {
this._sounds[alias].destroy();
}
return this;
}
stopAll() {
for (let alias in this._sounds) {
this._sounds[alias].stop();
}
return this;
}
exists(alias, assert = false) {
const exists = !!this._sounds[alias];
if (assert && !exists) {
this.log.warn(`No sound matching alias '${alias}'.`);
}
return exists;
}
sound(alias) {
this.exists(alias, true);
return this._sounds[alias];
}
play(alias, options) {
Runtime_1.default.instance.performance.log('JiboSoundPlayEvent', alias);
this.log.debug("Starting to Playback Sound with alias:" + alias);
let sound = this.sound(alias);
return (sound ? sound.play(options) : null);
}
stop(alias) {
let sound = this.sound(alias);
return (sound ? sound.stop() : null);
}
pause(alias) {
let sound = this.sound(alias);
return (sound ? sound.pause() : null);
}
resume(alias) {
let sound = this.sound(alias);
return (sound ? sound.resume() : null);
}
destroy() {
this.removeAll();
this._sounds = null;
this._context = null;
}
}
Runtime_1.default.registerPlugin(SoundPlugin, 'sound', {
api: true,
electron: true
});
exports.default = SoundPlugin;
},{"../Runtime":1,"./Sound":192,"./SoundContext":193,"./SoundInstance":194,"./SoundUtils":196,"./tasks/SoundTask":199,"jibo-log":undefined}],196:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Sound_1 = require("./Sound");
const Runtime_1 = require("../Runtime");
const uuid = require("uuid");
class SoundUtils {
static sineTone(hertz, seconds) {
const soundContext = Runtime_1.default.instance.sound.context;
const sound = new Sound_1.default(soundContext, {
block: true
});
hertz = hertz || 200;
seconds = seconds || 1;
const nChannels = 1;
const sampleRate = 48000;
const amplitude = 2;
const buffer = soundContext.context.createBuffer(nChannels, seconds * sampleRate, sampleRate);
const fArray = buffer.getChannelData(0);
for (let i = 0; i < fArray.length; i++) {
let time = i / buffer.sampleRate;
let angle = hertz * time * Math.PI;
fArray[i] = Math.sin(angle) * amplitude;
}
sound.buffer = buffer;
sound.isLoaded = true;
return sound;
}
static playOnce(src, callback) {
const alias = uuid.v4();
Runtime_1.default.instance.loader.load({
type: 'sound',
id: alias,
src: src,
complete: (err, sound) => {
if (err) {
if (callback) {
callback(err);
}
return;
}
sound.play((sound) => {
Runtime_1.default.instance.sound.remove(alias);
if (callback) {
callback(null);
}
});
}
});
return alias;
}
static addClipSounds(clip, labelPrefix = 'playAudio', separator = '-') {
const labels = clip.labels;
for (let i = 0; i < labels.length; ++i) {
const label = labels[i].label;
if (label.startsWith(labelPrefix + separator)) {
const alias = label.split(separator)[1];
clip.addAction(() => {
Runtime_1.default.instance.sound.play(alias);
}, label);
}
}
return clip;
}
}
exports.default = SoundUtils;
},{"../Runtime":1,"./Sound":192,"uuid":undefined}],197:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Sound_1 = require("./Sound");
exports.Sound = Sound_1.default;
const SoundContext_1 = require("./SoundContext");
exports.SoundContext = SoundContext_1.default;
const ChainBuilder_1 = require("./ChainBuilder");
exports.ChainBuilder = ChainBuilder_1.default;
const SoundPlugin_1 = require("./SoundPlugin");
exports.SoundPlugin = SoundPlugin_1.default;
const SoundInstance_1 = require("./SoundInstance");
exports.SoundInstance = SoundInstance_1.default;
const SoundUtils_1 = require("./SoundUtils");
exports.SoundUtils = SoundUtils_1.default;
const tasks_1 = require("./tasks");
exports.tasks = tasks_1.default;
},{"./ChainBuilder":191,"./Sound":192,"./SoundContext":193,"./SoundInstance":194,"./SoundPlugin":195,"./SoundUtils":196,"./tasks":200}],198:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
exports.default = log_1.default.createChild('Sound');
},{"../log":75}],199:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../../Runtime");
const jibo_loader_1 = require("jibo-loader");
const jibo_plugins_1 = require("jibo-plugins");
const path = require("path");
const log_1 = require("../log");
const log = log_1.default.createChild('SoundTask');
class SoundTask extends jibo_loader_1.Task {
static test(asset) {
return !!asset.src && /\.(mp3|m4a|wav|ogg|oga|aif)$/i.test(asset.src);
}
constructor(manager, asset) {
super(manager, asset, asset.src);
this.src = this.prepare(asset.src);
this.block = !!asset.block;
this.volume = asset.volume || 1;
this.panning = asset.panning || 0;
this.loop = !!asset.loop;
this.autoPlay = !!asset.autoPlay;
this.useXHR = asset.remote === true || jibo_plugins_1.PathUtils.isURL(this.src);
}
start(callback) {
const alias = this.id || path.parse(this.src).name;
const soundPlugin = Runtime_1.default.instance.sound;
if (soundPlugin.exists(alias)) {
const sound = soundPlugin.sound(alias);
if (sound.src === this.src) {
return callback(null, sound);
}
else {
log.info(`Overwriting existing sound (alias: ${alias})`);
soundPlugin.remove(alias);
}
}
const sound = soundPlugin.add(alias, {
src: this.src,
preload: true,
block: this.block,
loop: this.loop,
volume: this.volume,
panning: this.panning,
autoPlay: this.autoPlay,
useXHR: this.useXHR,
loaded: callback
});
sound.__baseDestroy = sound.destroy;
sound.destroy = function () {
if (this.__destroyed) {
return;
}
this.__destroyed = true;
soundPlugin.remove(alias);
this.__baseDestroy(true);
};
}
}
exports.default = SoundTask;
},{"../../Runtime":1,"../log":198,"jibo-loader":undefined,"jibo-plugins":undefined,"path":undefined}],200:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const SoundTask_1 = require("./SoundTask");
exports.default = {
SoundTask: SoundTask_1.default
};
},{"./SoundTask":199}],201:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class DelayedCall {
constructor(parent, callback, delay, options) {
options = Object.assign({
repeat: false,
autoDestroy: true,
useFrames: false
}, options || {});
this.parent = parent;
this._callback = callback;
this._delay = delay;
this._timer = delay;
this._repeat = !!options.repeat;
this._autoDestroy = !!options.autoDestroy;
this._useFrames = !!options.useFrames;
this._paused = false;
this._update = this.update.bind(this);
this.enabled = true;
}
update(elapsed) {
if (!this._callback) {
this.destroy();
return;
}
this._timer -= this._useFrames ? 1 : elapsed;
if (this._timer <= 0) {
this._callback(this);
if (this._repeat) {
this._timer += this._delay;
}
else if (this._autoDestroy) {
this.destroy();
}
else {
this.enabled = false;
}
}
}
restart() {
if (!this._callback) {
return;
}
if (!this.enabled) {
this.enabled = true;
}
this._timer = this._delay;
this._paused = false;
}
stop() {
this.enabled = false;
this._paused = false;
}
set enabled(value) {
this._enabled = value;
this.parent.removeListener('update', this._update);
if (value) {
this.parent.on('update', this._update);
}
}
get enabled() {
return this._enabled;
}
get paused() {
return this._paused;
}
set paused(value) {
if (!this._callback) {
return;
}
if (this._paused && !value) {
this._paused = false;
if (!this.enabled) {
this.enabled = true;
}
}
else if (value) {
if (this.enabled) {
this._paused = true;
this.enabled = false;
}
}
}
destroy() {
this.stop();
this._callback = null;
}
}
exports.default = DelayedCall;
},{}],202:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const DelayedCall_1 = require("./DelayedCall");
const EventEmitter = require("jibo-eventemitter3");
class Timer extends EventEmitter {
constructor() {
super();
this.update = this.update.bind(this);
this._paused = true;
this._updateCount = 0;
}
start() {
if (this._paused) {
this.emit('pause', false);
this.emit('resumed');
this._paused = false;
this._lastUpdate = performance.now();
this.update();
}
}
stop() {
if (!this._paused) {
this.emit('pause', true);
this.emit('paused');
this._paused = true;
if (this._frameRequest) {
cancelAnimationFrame(this._frameRequest);
this._frameRequest = null;
}
}
}
update() {
if (this._paused) {
return;
}
const now = performance.now();
const elapsed = now - this._lastUpdate;
this._updateCount++;
this._lastUpdate = now;
this._frameRequest = requestAnimationFrame(this.update);
this.emit('update', elapsed);
}
get paused() {
return this._paused;
}
setTimeout(callback, delay, useFrames = false, autoDestroy = true) {
return new DelayedCall_1.default(this, callback, delay, {
repeat: false,
autoDestroy: autoDestroy,
useFrames: useFrames
});
}
clearTimeout(call) {
call.destroy();
}
setInterval(callback, delay, useFrames = false) {
return new DelayedCall_1.default(this, callback, delay, {
repeat: true,
autoDestroy: false,
useFrames: useFrames
});
}
nextTick(callback, autoDestroy = true) {
return new DelayedCall_1.default(this, callback, 1, {
repeat: false,
autoDestroy: autoDestroy,
useFrames: true
});
}
clearInterval(call) {
call.destroy();
}
destroy() {
this.removeAllListeners();
this.stop();
}
}
exports.default = Timer;
},{"./DelayedCall":201,"jibo-eventemitter3":undefined}],203:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Runtime_1 = require("../Runtime");
function run(parentLog, forceWithoutWifi = false) {
const log = parentLog.createChild('Wipe');
return new Promise((resolve, reject) => {
Runtime_1.default.instance.systemManager.getMode((err, curMode) => {
if (err) {
log.error("Wipe - getMode error: ", err);
reject(err);
}
else if (curMode === 'normal') {
log.info("Wipe- current mode is " + curMode + ". Setting to oobe.");
Runtime_1.default.instance.systemManager.setMode('oobe', (err) => {
if (err) {
log.error("Wipe - setMode error: ", err);
reject(err);
}
else {
resolve(true);
}
});
}
else {
log.info("Wipe- current mode is " + curMode + " Not setting to oobe.");
resolve(false);
}
});
})
.then((wasNormalMode) => {
if (forceWithoutWifi && !Runtime_1.default.instance.wifi.isConnected()) {
return;
}
return new Promise((resolve, reject) => {
log.info("Wipe - suspending loop...");
Runtime_1.default.instance.kb.loop.suspend((err) => {
if (err) {
log.error("Wipe - suspend loop error:", err);
if (err.toString().includes('LOOP_NOT_FOUND')) {
log.warn('Loop not found; Continuing with wipe...');
resolve();
}
if (wasNormalMode) {
Runtime_1.default.instance.systemManager.setMode('normal', () => {
reject(err);
});
}
else {
reject(err);
}
}
else {
resolve();
}
});
});
})
.then(() => {
return new Promise((resolve) => {
log.info("Wipe - system manager wipe...");
Runtime_1.default.instance.systemManager.wipe((err) => {
if (err) {
log.error("Wipe error:", err);
}
resolve();
});
});
})
.then(() => {
if (forceWithoutWifi && !Runtime_1.default.instance.wifi.isConnected()) {
return;
}
return new Promise((resolve) => {
log.info("Wipe - force upload of logs...");
Runtime_1.default.instance.systemManager.forceLogs((err) => {
if (err) {
log.error("Wipe - force log upload error:", err);
}
resolve();
});
});
})
.then(() => {
return new Promise((resolve) => {
log.info("Wipe - clearing credentials...");
Runtime_1.default.instance.systemManager.setCredentials({
"accessKeyId": "",
"secretAccessKey": "",
"region": ""
}, (err) => {
if (err) {
log.error("Wipe - set credentials error: ", err);
}
resolve();
});
});
})
.then(() => {
return new Promise((resolve) => {
log.info("Wipe - clearing wi-fi networks...");
Runtime_1.default.instance.wifi.removeAllNetworks((err) => {
if (err) {
log.error("Wipe - clear wifi networks error: ", err);
}
resolve();
});
});
})
.catch((err) => {
throw err;
});
}
exports.default = {
run
};
},{"../Runtime":1}],204:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function configurable(value) {
return function (target, propertyKey) {
let descriptor = Object.getOwnPropertyDescriptor(target, propertyKey);
descriptor.configurable = value;
Object.defineProperty(target, propertyKey, descriptor);
};
}
exports.configurable = configurable;
function writable(value) {
return function (target, propertyKey) {
let descriptor = Object.getOwnPropertyDescriptor(target, propertyKey);
descriptor.writable = value;
Object.defineProperty(target, propertyKey, descriptor);
};
}
exports.writable = writable;
function enumerable(value) {
return function (target, propertyKey) {
let descriptor = Object.getOwnPropertyDescriptor(target, propertyKey);
descriptor.enumerable = value;
Object.defineProperty(target, propertyKey, descriptor);
};
}
exports.enumerable = enumerable;
function constant(target, propertyKey) {
let descriptor = Object.getOwnPropertyDescriptor(target, propertyKey);
descriptor.writable = false;
descriptor.configurable = false;
Object.defineProperty(target, propertyKey, descriptor);
}
exports.constant = constant;
function isInitialized(target, propertyKey, descriptor) {
let originalMethod = descriptor.value;
descriptor.value = function () {
let args = Array.from(arguments);
if (!this.isInitialized) {
let callback = args.slice(0, -1)[0];
let err = new Error(`${this.constructor.name} class instance is not initialized`);
callback(err);
return undefined;
}
else {
return originalMethod.apply(this, args);
}
};
return descriptor;
}
exports.isInitialized = isInitialized;
function promisify(target, propertyKey, descriptor) {
let originalMethod = descriptor.value;
descriptor.value = function () {
let result;
let args = Array.from(arguments);
let callbackArg = args[args.length - 1];
if (typeof callbackArg === 'function') {
result = originalMethod.apply(this, args);
}
else {
result = new Promise((resolve, reject) => {
let callback = function (err, arg) {
if (err) {
reject(err);
}
else {
resolve(arg);
}
};
let newArgs = args.concat(callback);
originalMethod.apply(this, newArgs);
});
}
return result;
};
return descriptor;
}
exports.promisify = promisify;
function promisify_n(argNum) {
function doPromisify(target, propertyKey, descriptor) {
let originalMethod = descriptor.value;
descriptor.value = function () {
let result;
let args = Array.from(arguments);
if (argNum < 1 || argNum > originalMethod.length) {
throw new Error('promisify_n decorator given invalid argument number');
}
let callbackArg = args[argNum - 1];
if (typeof callbackArg === 'function') {
result = originalMethod.apply(this, args);
}
else {
result = new Promise((resolve, reject) => {
let callback = function (err, arg) {
if (err) {
reject(err);
}
else {
resolve(arg);
}
};
let newArgs = args.slice(0, argNum - 1).concat(callback).concat(args.slice(argNum - 1));
originalMethod.apply(this, newArgs);
});
}
return result;
};
return descriptor;
}
return doPromisify;
}
exports.promisify_n = promisify_n;
},{}],205:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = !!process.versions.electron;
},{}],206:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Timer_1 = require("./Timer");
const DelayedCall_1 = require("./DelayedCall");
const perf_1 = require("./perf");
const WipeUtil_1 = require("./WipeUtil");
const jibo_plugins_1 = require("jibo-plugins");
const jibo_data_utils_1 = require("jibo-data-utils");
const log_1 = require("./log");
jibo_data_utils_1.initLog(log_1.default);
exports.default = {
Timer: Timer_1.default,
DelayedCall: DelayedCall_1.default,
perf: perf_1.default,
PathUtils: jibo_plugins_1.PathUtils,
WipeUtil: WipeUtil_1.default,
Location: jibo_data_utils_1.Location,
LocationUtils: jibo_data_utils_1.LocationUtils,
Timezone: jibo_data_utils_1.Timezone,
DateTime: jibo_data_utils_1.DateTime,
DateTimeUtils: jibo_data_utils_1.DateTimeUtils
};
},{"./DelayedCall":201,"./Timer":202,"./WipeUtil":203,"./log":208,"./perf":213,"jibo-data-utils":undefined,"jibo-plugins":undefined}],207:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jibo_data_utils_1 = require("jibo-data-utils");
const Runtime_1 = require("../../Runtime");
const log_1 = require("../log");
const log = log_1.default.createChild('Location');
class HomeLocation extends jibo_data_utils_1.Location {
static init() {
jibo_data_utils_1.setHome(new HomeLocation());
}
constructor() {
super();
this.needsTimezone = true;
const jibo = Runtime_1.default.instance;
this._kbInit = jibo.kb.onInit()
.then(() => {
this._kb = jibo.kb.createModel('/jibo/location');
return this._kb.loadRoot();
})
.then((node) => {
this._rootNode = node;
});
this._kbInit.then(() => {
jibo.kb.robot.events.robotUpdated.on(() => {
setTimeout(() => {
this.readFromKB();
}, 3000);
});
return this.readFromKB();
});
}
fetch(callback) {
this._kbInit.then(() => {
return this.readFromKB();
})
.then(() => {
super.fetch(callback);
}, (err) => {
callback(err, null);
});
}
readFromKB() {
return this._kb.load(this._rootNode.getEdges(['home', 'timezone']))
.then((nodes) => {
const data = nodes[0].data;
this.city = data.city;
this.state = data.state;
this.stateAbbr = data.stateAbbr;
this.country = data.country;
this.countryCode = data.countryCode;
this.lat = data.lat;
this.lng = data.lng;
if (this.state && !this.stateAbbr) {
const fullState = jibo_data_utils_1.LocationUtils.getFullState(this.state.toLowerCase());
if (fullState) {
this.stateAbbr = this.state;
this.state = fullState;
}
}
const jibo = Runtime_1.default.instance;
jibo.systemManager.getMode((err, mode) => {
if (mode === 'int-developer') {
log.info('Read location from KB: ', data);
}
});
this.timezone = new jibo_data_utils_1.Timezone(nodes[1].data);
})
.catch((err) => {
log.warn('Unable to load home location from KB', err);
this.city = 'boston';
this.stateAbbr = 'ma';
this.state = 'Massachusetts';
this.country = 'usa';
this.countryCode = 'US';
this.lat = 42.313352;
this.lng = -71.1273681;
this.timezone = new jibo_data_utils_1.Timezone({
offsetUTC: -18000000,
name: "Eastern Standard Time",
id: "America/New_York",
__type: "Timezone"
});
});
}
}
exports.default = HomeLocation;
},{"../../Runtime":1,"../log":208,"jibo-data-utils":undefined}],208:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../log");
exports.default = log_1.default.createChild('Util');
},{"../log":75}],209:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const SerialTimer_1 = require("./SerialTimer");
const assert = require('assert');
let singleton = null;
class GlobalPerfTimer {
static init() {
assert(singleton === null, 'GlobalPerfTimer.init() should only be called once');
return GlobalPerfTimer.reset();
}
static reset() {
singleton = new SerialTimer_1.default('jibo');
return singleton;
}
static get() {
return singleton;
}
}
exports.default = GlobalPerfTimer;
},{"./SerialTimer":212,"assert":undefined}],210:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const PerformanceTimer_1 = require("./PerformanceTimer");
class ParallelTimer extends PerformanceTimer_1.default {
constructor(name, parent) {
super(name, PerformanceTimer_1.default.TimerTypes.PARALLEL, parent);
}
}
exports.default = ParallelTimer;
},{"./PerformanceTimer":211}],211:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert = require('assert');
const TimerTypes = {
SERIAL: "SERIAL",
PARALLEL: "PARALLEL"
};
class PerformanceTimer {
constructor(name, type, parent) {
this.name = name;
this.type = type;
this.parent = parent;
this.start = this.now();
this.children = [];
if (this.parent) {
this.parent.children.push(this);
}
}
static get TimerTypes() {
return TimerTypes;
}
stop() {
assert(!this.end, "PerformanceTimer.stop() was called twice.");
this.end = this.now();
}
getTimings() {
assert(this !== null, "PerformanceTimer.printTimings() called without there being any timing data");
return _getTimings(this, "");
}
now() {
return typeof performance !== 'undefined' ?
performance.now() : Date.now();
}
}
function _getTimings(parentTimer, indentLevel) {
let timerTypeSymbol = '-';
if (!parentTimer.parent) {
timerTypeSymbol = " ";
}
else if (parentTimer.parent.type === TimerTypes.PARALLEL) {
timerTypeSymbol = "~";
}
let output = "";
output += `${indentLevel}${timerTypeSymbol} "${parentTimer.name}" ${(parentTimer.end - parentTimer.start).toFixed(1)}ms\n`;
if (parentTimer.type === TimerTypes.PARALLEL) {
parentTimer.children.sort((a, b) => {
return (a.end - a.start) < (b.end - b.start);
});
}
parentTimer.children.forEach((childTimer) => {
output += _getTimings(childTimer, indentLevel + "\t");
});
return output;
}
exports.default = PerformanceTimer;
},{"assert":undefined}],212:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const PerformanceTimer_1 = require("./PerformanceTimer");
class SerialTimer extends PerformanceTimer_1.default {
constructor(name, parent) {
super(name, PerformanceTimer_1.default.TimerTypes.SERIAL, parent);
}
}
exports.default = SerialTimer;
},{"./PerformanceTimer":211}],213:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const GlobalPerfTimer_1 = require("./GlobalPerfTimer");
const PerformanceTimer_1 = require("./PerformanceTimer");
const ParallelTimer_1 = require("./ParallelTimer");
const SerialTimer_1 = require("./SerialTimer");
exports.default = {
GlobalPerfTimer: GlobalPerfTimer_1.default,
PerformanceTimer: PerformanceTimer_1.default,
ParallelTimer: ParallelTimer_1.default,
SerialTimer: SerialTimer_1.default
};
},{"./GlobalPerfTimer":209,"./ParallelTimer":210,"./PerformanceTimer":211,"./SerialTimer":212}],214:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const electron_1 = require("./utils/electron");
const events_1 = require("./services/events");
const GlobalPerfTimer_1 = require("./utils/perf/GlobalPerfTimer");
const plugins_1 = require("./plugins");
const Runtime_1 = require("./Runtime");
const SerialTimer_1 = require("./utils/perf/SerialTimer");
const services_1 = require("./services");
const utils_1 = require("./utils");
const deprecation_1 = require("./deprecation");
const root = global;
GlobalPerfTimer_1.default.init();
const timer = new SerialTimer_1.default('jibo required', GlobalPerfTimer_1.default.get());
if (!root.jibo) {
const classes = {
events: events_1.default,
plugins: plugins_1.default,
Runtime: Runtime_1.default,
services: services_1.default,
utils: utils_1.default,
};
if (electron_1.default) {
const rendering = require('./rendering');
const bt = require('./bt');
const flow = require('./flow');
const sound = require('./sound');
Object.assign(classes, {
bt,
flow,
rendering,
sound,
});
}
deprecation_1.default(classes);
root.jibo = new Runtime_1.default(classes);
}
timer.stop();
module.exports = root.jibo;
},{"./Runtime":1,"./bt":48,"./deprecation":65,"./flow":73,"./plugins":98,"./rendering":159,"./services":183,"./services/events":181,"./sound":197,"./utils":206,"./utils/electron":205,"./utils/perf/GlobalPerfTimer":209,"./utils/perf/SerialTimer":212}]},{},[214])(214)
});
//# sourceMappingURL=jibo.js.map