-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved all globals to an "App" instance - now each execution of index.handler is entirely contained Removed API cals for getting server machine identifier and player IP since we now cache all of that in the DB Changed all references to "library 1" to a db-stored library URI - for now it just grabs the first tv library and uses that
- Loading branch information
1 parent
3714d4d
commit a0815eb
Showing
15 changed files
with
426 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,67 @@ | ||
/** | ||
* @module app | ||
* @module App | ||
*/ | ||
|
||
//var Plex = require('./plex').Plex; | ||
var AlexaSkill = require('alexa-app').app; | ||
var User = require('./user').User; | ||
|
||
var db = require('./db'); | ||
var stateMachine = require('./statemachine'); | ||
|
||
/** | ||
* @name module:app | ||
* Creates a new App object, which holds all of the various stateful objects necessary on each request | ||
* @constructor App | ||
* @classdesc Holds all of the various stateful objects necessary on each request | ||
*/ | ||
app = module.exports = { | ||
var App = function() { | ||
var Plex = require('./plex').Plex; | ||
|
||
/** @type {module:Plex~Plex} */ | ||
plex: null, | ||
this.plex = new Plex(this); | ||
/** @type {AlexaSkill} */ | ||
this.skill = new AlexaSkill('plex'); | ||
|
||
// TODO figure out how to properly jsdoc this so that it is recognized as an alexa-app.app object | ||
/** @type {Object} */ | ||
skill: null, | ||
/** @type {module:User~User} */ | ||
this.user = null; | ||
|
||
/** | ||
* How confident we need to be when trying to figure out which show a user is talkijng about | ||
* @const | ||
*/ | ||
CONFIDICE_CONFIRM_THRESHOLD: 0.4, | ||
this.CONFIDICE_CONFIRM_THRESHOLD = 0.4; | ||
|
||
/** | ||
* The invocation name used for this app. Used in many responses so put here in case it changes. | ||
* @const | ||
* @type {string} | ||
*/ | ||
INVOCATION_NAME: "the home theater" | ||
this.INVOCATION_NAME = "the home theater"; | ||
}; | ||
|
||
App.prototype.execute = function(event, callbacks) { | ||
var context = this; | ||
db.initializeUserRecord(event.session.user.userId).then(function(dbuser) { | ||
context.user = new User(context, dbuser); | ||
context.plex.pinAuth.token = context.user.authtoken; | ||
|
||
if(!context.user.authtoken) { | ||
return stateMachine.initSkillState(context, 'not-authed'); | ||
} else { | ||
return stateMachine.initSkillState(context, 'authed'); | ||
} | ||
}).then(function() { | ||
// Pass off the rest of the execution to the alexa-plex module which handles running intents | ||
// TODO: we're doing so much of our own app framework now that it might make sense to just take over the last few things that alexa-app is handling? | ||
// HUGE HACK to make this App object available to the Intent handlers running inside the alexa-app module. Another reason why the above note makes sense | ||
event._plex_app = context; | ||
context.skill.lambda()(event, callbacks); | ||
}).catch(function(err) { | ||
console.error(err); | ||
console.error(err.stack); | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
App: App | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.