Skip to content

Commit

Permalink
Add ResponseBuilder support for AudioItemMetadata, bumping version to…
Browse files Browse the repository at this point in the history
… 2.0.3
  • Loading branch information
Zhang authored and tianrenz committed May 3, 2018
1 parent 59dbf49 commit c6b3fe3
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 12 deletions.
5 changes: 4 additions & 1 deletion ask-sdk-core/lib/response/ResponseBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
interfaces,
Response,
} from 'ask-sdk-model';
import AudioItemMetadata = interfaces.audioplayer.AudioItemMetadata;

/**
* An interface which helps building a response.
Expand Down Expand Up @@ -113,13 +114,15 @@ export interface ResponseBuilder {
* This property is required and allowed only when the playBehavior is ENQUEUE.
* This is used to prevent potential race conditions if requests to progress
* through a playlist and change tracks occur at the same time.
* @param {interfaces.audioplayer.AudioItemMetadata} audioItemMetadata Metadata that can be displayed on screen enabled devices
* @returns {ResponseBuilder}
*/
addAudioPlayerPlayDirective(playBehavior : interfaces.audioplayer.PlayBehavior,
url : string,
token : string,
offsetInMilliseconds : number,
expectedPreviousToken? : string) : this;
expectedPreviousToken? : string,
audioItemMetadata? : AudioItemMetadata) : this;
/**
* Adds an AudioPlayer Stop directive - Stops the current audio Playback
* @returns {ResponseBuilder}
Expand Down
8 changes: 7 additions & 1 deletion ask-sdk-core/lib/response/ResponseFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import DelegateDirective = dialog.DelegateDirective;
import ElicitSlotDirective = dialog.ElicitSlotDirective;
import ConfirmSlotDirective = dialog.ConfirmSlotDirective;
import ConfirmIntentDirective = dialog.ConfirmIntentDirective;
import AudioItemMetadata = interfaces.audioplayer.AudioItemMetadata;

/**
* Responsible for building JSON responses using ask-sdk-model as per the Alexa skills kit interface
Expand Down Expand Up @@ -205,7 +206,8 @@ export class ResponseFactory {
url : string,
token : string,
offsetInMilliseconds : number,
expectedPreviousToken? : string) : ResponseBuilder {
expectedPreviousToken? : string,
audioItemMetadata? : AudioItemMetadata) : ResponseBuilder {
const stream : Stream = {
url,
token,
Expand All @@ -220,6 +222,10 @@ export class ResponseFactory {
stream,
};

if (audioItemMetadata) {
audioItem.metadata = audioItemMetadata;
}

const playDirective : PlayDirective = {
type : 'AudioPlayer.Play',
playBehavior,
Expand Down
2 changes: 1 addition & 1 deletion ask-sdk-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ask-sdk-core",
"version": "2.0.2",
"version": "2.0.3",
"description": "Core package for Alexa Skills Kit SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
48 changes: 47 additions & 1 deletion ask-sdk-core/tst/response/ResponseFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,15 @@ describe('ResponseFactory', () => {
const behavior : PlayBehavior = 'ENQUEUE';
const audioSource = 'https://url/to/audiosource';
const audioToken = 'audio token';
const previousToken = 'previous token';
const offset = 10000;
const previousToken = 'previous token';
const audioItemMetadata = {
title : 'title',
subtitle : 'subtitle',
art : new ImageHelper().withDescription('description').addImageInstance('fakeUrl.com').getImage(),
backgroundImage : new ImageHelper().withDescription('description').addImageInstance('fakeUrl.com').getImage(),
};

const expectResponse1 = {
directives : [
{ audioItem : {
Expand Down Expand Up @@ -375,8 +382,47 @@ describe('ResponseFactory', () => {
},
],
};

const expectResponse3 = {
directives: [
{
audioItem: {
metadata: {
art: {
contentDescription: 'description',
sources: [
{
url: 'fakeUrl.com',
},
],
},
backgroundImage: {
contentDescription: 'description',
sources: [
{
url: 'fakeUrl.com',
},
],
},
subtitle: 'subtitle',
title: 'title',
},
stream: {
expectedPreviousToken: 'previous token',
offsetInMilliseconds: 10000,
token: 'audio token',
url: 'https://url/to/audiosource',
},
},
playBehavior: 'ENQUEUE',
type: 'AudioPlayer.Play',
},
],
};

expect(ResponseFactory.init().addAudioPlayerPlayDirective(behavior, audioSource, audioToken, offset, previousToken).getResponse()).to.deep.equals(expectResponse1);
expect(ResponseFactory.init().addAudioPlayerPlayDirective(behavior, audioSource, audioToken, offset).getResponse()).to.deep.equals(expectResponse2);
expect(ResponseFactory.init().addAudioPlayerPlayDirective(behavior, audioSource, audioToken, offset, previousToken, audioItemMetadata).getResponse()).to.deep.equals(expectResponse3);
});

it('should build response with AudioPlayer.Stop directive', () => {
Expand Down
4 changes: 2 additions & 2 deletions ask-sdk-dynamodb-persistence-adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ask-sdk-dynamodb-persistence-adapter",
"version": "2.0.1",
"version": "2.0.3",
"description": "DynamoDB based implementation package of PersistenceAdapter interface in ASK SDK v2 for Node.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -33,7 +33,7 @@
"@types/chai": "^4.1.2",
"@types/mocha": "^5.0.0",
"@types/node": "^9.6.1",
"ask-sdk-core": "^2.0.0",
"ask-sdk-core": "^2.0.3",
"ask-sdk-model": "^1.0.0",
"aws-sdk-mock": "^1.7.0",
"chai": "^4.1.2",
Expand Down
4 changes: 2 additions & 2 deletions ask-sdk-v1adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ask-sdk-v1adapter",
"version": "2.0.2",
"version": "2.0.3",
"description": "Adapter from v1 Alexa Node.js SDK to v2",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -36,7 +36,7 @@
"@types/mocha": "^5.0.0",
"@types/node": "^9.6.1",
"@types/sinon": "^4.3.0",
"ask-sdk": "^2.0.0",
"ask-sdk": "^2.0.3",
"chai": "^4.1.2",
"del": "^3.0.0",
"gulp": "^4.0.0",
Expand Down
6 changes: 3 additions & 3 deletions ask-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ask-sdk",
"version": "2.0.1",
"version": "2.0.3",
"description": "Standard distribution package for Alexa Skills Kit SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -24,8 +24,8 @@
"SDK"
],
"dependencies": {
"ask-sdk-core": "^2.0.0",
"ask-sdk-dynamodb-persistence-adapter": "^2.0.0",
"ask-sdk-core": "^2.0.3",
"ask-sdk-dynamodb-persistence-adapter": "^2.0.3",
"ask-sdk-model": "^1.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"ask-sdk-dynamodb-persistence-adapter",
"ask-sdk-v1adapter"
],
"version": "independent"
"version": "2.0.3"
}

0 comments on commit c6b3fe3

Please sign in to comment.