UNPKG

meshblu-connector-skype

Version:
105 lines (87 loc) 3.11 kB
// Generated by CoffeeScript 1.12.7 (function() { var EndSkypeState, EventEmitter, MessageToState, StartSkypeState, StateManager, _, debug, bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; _ = require('lodash'); StateManager = require('./index'); EventEmitter = require('events').EventEmitter; debug = require("debug")("meshblu-connector-skype:message-to-state"); StartSkypeState = { desiredState: { videoEnabled: true, audioEnabled: true, meeting: { url: null } }, autoLaunchSkype: true }; EndSkypeState = { desiredState: { meeting: null }, autoLaunchSkype: true }; MessageToState = (function(superClass) { extend(MessageToState, superClass); function MessageToState(arg) { this.stateManager = (arg != null ? arg : {}).stateManager; this.autoLaunchSkype = bind(this.autoLaunchSkype, this); this.onConfig = bind(this.onConfig, this); this.onMessage = bind(this.onMessage, this); this.start = bind(this.start, this); if (this.stateManager == null) { this.stateManager = new StateManager(); } this.stateManager.on('update', (function(_this) { return function(config) { return _this.emit('update', config); }; })(this)); } MessageToState.prototype.start = function(callback) { return this.stateManager.start({ autoLaunchSkype: true }, callback); }; MessageToState.prototype.onMessage = function(message) { var config, jobType, type; type = message.metadata.route[0].type; if (type === 'configure.sent') { return this.onConfig(message); } message = message.data; jobType = _.get(message, 'metadata.jobType'); debug("message received", JSON.stringify({ message: message, jobType: jobType }, null, 2)); if (jobType === 'start-skype') { config = _.cloneDeep(StartSkypeState); } if (jobType === 'end-skype') { config = _.cloneDeep(EndSkypeState); } debug({ "sending config": JSON.stringify(config, null, 2) }); if (config != null) { return this.stateManager.onConfig(config); } return console.log("I don't know what this message means: " + jobType); }; MessageToState.prototype.onConfig = function(config) { return this.stateManager.onConfig(config.data); }; MessageToState.prototype.autoLaunchSkype = function() { return this.stateManager.onConfig({ autoLaunchSkype: true }); }; return MessageToState; })(EventEmitter); module.exports = MessageToState; }).call(this); //# sourceMappingURL=message-to-state.js.map