@@ -1016,8 +1016,9 @@ SpotifyWebApi.prototype = {
1016
1016
* Get the Current User's Recently Played Tracks
1017
1017
* @param {Object } [options] Options, being type, after, limit, before.
1018
1018
* @param {requestCallback } [callback] Optional callback method to be called instead of the promise.
1019
- * @returns {Promise|undefined } A promise that if successful, resolves into a paging object of tracks,
1020
- * otherwise an error. Not returned if a callback is given.
1019
+ * @returns {Promise|undefined } A promise that if successful, resolves into a paging object of play history objects,
1020
+ * otherwise an error. Not returned if a callback is given. Note that the response will be empty
1021
+ * in case the user has enabled private session.
1021
1022
*/
1022
1023
getMyRecentlyPlayedTracks : function ( options , callback ) {
1023
1024
return WebApiRequest . builder ( this . getAccessToken ( ) )
@@ -1028,9 +1029,9 @@ SpotifyWebApi.prototype = {
1028
1029
} ,
1029
1030
1030
1031
/**
1031
- * Get the Current User's Connect Devices
1032
+ * Get the Current User's Available Devices
1032
1033
* @param {requestCallback } [callback] Optional callback method to be called instead of the promise.
1033
- * @returns {Promise|undefined } A promise that if successful, resolves into a paging object of tracks ,
1034
+ * @returns {Promise|undefined } A promise that if successful, resolves into an array of device objects ,
1034
1035
* otherwise an error. Not returned if a callback is given.
1035
1036
*/
1036
1037
getMyDevices : function ( callback ) {
@@ -1056,8 +1057,8 @@ SpotifyWebApi.prototype = {
1056
1057
} ,
1057
1058
1058
1059
/**
1059
- * Get the Current User's Current Playback State
1060
- * @param {Object } [options] Options, being market.
1060
+ * Get Information About The User's Current Playback State
1061
+ * @param {Object } [options] Options, being market and additional_types .
1061
1062
* @param {requestCallback } [callback] Optional callback method to be called instead of the promise.
1062
1063
* @returns {Promise|undefined } A promise that if successful, resolves into a paging object of tracks,
1063
1064
* otherwise an error. Not returned if a callback is given.
@@ -1072,17 +1073,19 @@ SpotifyWebApi.prototype = {
1072
1073
1073
1074
/**
1074
1075
* Transfer a User's Playback
1075
- * @param {Object } [options] Options, being market.
1076
+ * @param {string[] } [deviceIds] An _array_ containing a device ID on which playback should be started/transferred.
1077
+ * (NOTE: The API is currently only supporting a single device ID.)
1078
+ * @param {Object } [options] Options, the only one being 'play'.
1076
1079
* @param {requestCallback } [callback] Optional callback method to be called instead of the promise.
1077
- * @returns {Promise|undefined } A promise that if successful, resolves into a paging object of tracks ,
1080
+ * @returns {Promise|undefined } A promise that if successful, resolves into an empty response ,
1078
1081
* otherwise an error. Not returned if a callback is given.
1079
1082
*/
1080
- transferMyPlayback : function ( options , callback ) {
1083
+ transferMyPlayback : function ( deviceIds , options , callback ) {
1081
1084
return WebApiRequest . builder ( this . getAccessToken ( ) )
1082
1085
. withPath ( '/v1/me/player' )
1083
1086
. withHeaders ( { 'Content-Type' : 'application/json' } )
1084
1087
. withBodyParameters ( {
1085
- device_ids : options . deviceIds ,
1088
+ device_ids : deviceIds ,
1086
1089
play : ! ! options . play
1087
1090
} )
1088
1091
. build ( )
@@ -1093,8 +1096,8 @@ SpotifyWebApi.prototype = {
1093
1096
* Starts o Resumes the Current User's Playback
1094
1097
* @param {Object } [options] Options, being device_id, context_uri, offset, uris, position_ms.
1095
1098
* @param {requestCallback } [callback] Optional callback method to be called instead of the promise.
1096
- * @example playbackResume ({context_uri: 'spotify:album:5ht7ItJgpBH7W6vJ5BqpPr'}).then(...)
1097
- * @returns {Promise|undefined } A promise that if successful, resolves into a paging object of tracks ,
1099
+ * @example play ({context_uri: 'spotify:album:5ht7ItJgpBH7W6vJ5BqpPr'}).then(...)
1100
+ * @returns {Promise|undefined } A promise that if successful, resolves into an empty response ,
1098
1101
* otherwise an error. Not returned if a callback is given.
1099
1102
*/
1100
1103
play : function ( options , callback ) {
@@ -1120,10 +1123,10 @@ SpotifyWebApi.prototype = {
1120
1123
1121
1124
/**
1122
1125
* Pauses the Current User's Playback
1123
- * @param {Object } [options] Options, for now device_id,
1126
+ * @param {Object } [options] Options, being device_id. If left empty will target the user's currently active device.
1124
1127
* @param {requestCallback } [callback] Optional callback method to be called instead of the promise.
1125
- * @example playbackPause ().then(...)
1126
- * @returns {Promise|undefined } A promise that if successful, resolves into a paging object of tracks ,
1128
+ * @example pause ().then(...)
1129
+ * @returns {Promise|undefined } A promise that if successful, resolves into an empty response ,
1127
1130
* otherwise an error. Not returned if a callback is given.
1128
1131
*/
1129
1132
pause : function ( options , callback ) {
@@ -1142,29 +1145,37 @@ SpotifyWebApi.prototype = {
1142
1145
1143
1146
/**
1144
1147
* Skip the Current User's Playback To Previous Track
1148
+ * @param {Object } [options] Options, being device_id. If left empty will target the user's currently active device.
1145
1149
* @param {requestCallback } [callback] Optional callback method to be called instead of the promise.
1146
- * @example playbackPrevious ().then(...)
1147
- * @returns {Promise|undefined } A promise that if successful, resolves into a paging object of tracks ,
1150
+ * @example skipToPrevious ().then(...)
1151
+ * @returns {Promise|undefined } A promise that if successful, resolves into an empty response ,
1148
1152
* otherwise an error. Not returned if a callback is given.
1149
1153
*/
1150
1154
skipToPrevious : function ( callback ) {
1151
1155
return WebApiRequest . builder ( this . getAccessToken ( ) )
1152
1156
. withPath ( '/v1/me/player/previous' )
1157
+ . withQueryParameters (
1158
+ options && options . device_id ? { device_id : options . device_id } : null
1159
+ )
1153
1160
. withHeaders ( { 'Content-Type' : 'application/json' } )
1154
1161
. build ( )
1155
1162
. execute ( HttpManager . post , callback ) ;
1156
1163
} ,
1157
1164
1158
1165
/**
1159
1166
* Skip the Current User's Playback To Next Track
1167
+ * @param {Object } [options] Options, being device_id. If left empty will target the user's currently active device.
1160
1168
* @param {requestCallback } [callback] Optional callback method to be called instead of the promise.
1161
- * @example playbackNext ().then(...)
1162
- * @returns {Promise|undefined } A promise that if successful, resolves into a paging object of tracks ,
1169
+ * @example skipToNext ().then(...)
1170
+ * @returns {Promise|undefined } A promise that if successful, resolves into an empty response ,
1163
1171
* otherwise an error. Not returned if a callback is given.
1164
1172
*/
1165
1173
skipToNext : function ( callback ) {
1166
1174
return WebApiRequest . builder ( this . getAccessToken ( ) )
1167
1175
. withPath ( '/v1/me/player/next' )
1176
+ . withQueryParameters (
1177
+ options && options . device_id ? { device_id : options . device_id } : null
1178
+ )
1168
1179
. withHeaders ( { 'Content-Type' : 'application/json' } )
1169
1180
. build ( )
1170
1181
. execute ( HttpManager . post , callback ) ;
@@ -1174,7 +1185,7 @@ SpotifyWebApi.prototype = {
1174
1185
* Seeks to the given position in the user’s currently playing track.
1175
1186
*
1176
1187
* @param {number } positionMs The position in milliseconds to seek to. Must be a positive number.
1177
- * @param {Object } options A JSON object with options that can be passed .
1188
+ * @param {Object } options Options, being device_id. If left empty will target the user's currently active device .
1178
1189
* @param {function(Object,Object) } callback An optional callback that receives 2 parameters. The first
1179
1190
* one is the error object (null if no error), and the second is the value if the request succeeded.
1180
1191
* @return {Object } Null if a callback is provided, a `Promise` object otherwise
@@ -1197,45 +1208,56 @@ SpotifyWebApi.prototype = {
1197
1208
1198
1209
/**
1199
1210
* Set Repeat Mode On The Current User's Playback
1200
- * @param {Object } [options] Options, being state (track, context, off).
1211
+ * @param {string } [state] State (track, context, or off)
1212
+ * @param {Object } [options] Options, being device_id. If left empty will target the user's currently active device.
1201
1213
* @param {requestCallback } [callback] Optional callback method to be called instead of the promise.
1202
- * @example playbackRepeat ({state: 'context'}).then(...)
1203
- * @returns {Promise|undefined } A promise that if successful, resolves into a paging object of tracks ,
1214
+ * @example setRepeat ({state: 'context'}).then(...)
1215
+ * @returns {Promise|undefined } A promise that if successful, resolves into an empty response ,
1204
1216
* otherwise an error. Not returned if a callback is given.
1205
1217
*/
1206
- setRepeat : function ( options , callback ) {
1218
+ setRepeat : function ( state , options , callback ) {
1219
+ var params = {
1220
+ state : state
1221
+ } ;
1222
+ if ( options && 'device_id' in options ) {
1223
+ /* jshint camelcase: false */
1224
+ params . device_id = options . device_id ;
1225
+ }
1207
1226
return WebApiRequest . builder ( this . getAccessToken ( ) )
1208
1227
. withPath ( '/v1/me/player/repeat' )
1209
- . withQueryParameters ( {
1210
- state : options . state || 'off'
1211
- } )
1228
+ . withQueryParameters ( params )
1212
1229
. build ( )
1213
1230
. execute ( HttpManager . put , callback ) ;
1214
1231
} ,
1215
1232
1216
1233
/**
1217
1234
* Set Shuffle Mode On The Current User's Playback
1218
- * @param {Object } [options] Options, being state (true, false).
1235
+ * @param {string } [state] State (true, false)
1236
+ * @param {Object } [options] Options, being device_id. If left empty will target the user's currently active device.
1219
1237
* @param {requestCallback } [callback] Optional callback method to be called instead of the promise.
1220
- * @example playbackShuffle ({state: 'false'}).then(...)
1221
- * @returns {Promise|undefined } A promise that if successful, resolves into a paging object of tracks ,
1238
+ * @example setShuffle ({state: 'false'}).then(...)
1239
+ * @returns {Promise|undefined } A promise that if successful, resolves into an empty response ,
1222
1240
* otherwise an error. Not returned if a callback is given.
1223
1241
*/
1224
- setShuffle : function ( options , callback ) {
1242
+ setShuffle : function ( state , options , callback ) {
1243
+ var params = {
1244
+ state : state
1245
+ } ;
1246
+ if ( options && 'device_id' in options ) {
1247
+ /* jshint camelcase: false */
1248
+ params . device_id = options . device_id ;
1249
+ }
1225
1250
return WebApiRequest . builder ( this . getAccessToken ( ) )
1226
1251
. withPath ( '/v1/me/player/shuffle' )
1227
- . withQueryParameters ( {
1228
- state : options . state || 'false'
1229
- } )
1252
+ . withQueryParameters ( params )
1230
1253
. build ( )
1231
1254
. execute ( HttpManager . put , callback ) ;
1232
1255
} ,
1233
1256
1234
1257
/**
1235
1258
* Set the volume for the user’s current playback device.
1236
- *
1237
- * @param {number } volumePercent The volume to set. Must be a value from 0 to 100 inclusive.
1238
- * @param {Object } options A JSON object with options that can be passed.
1259
+ * @param {number } volumePercent The volume to set. Must be a value from 0 to 100.
1260
+ * @param {Object } options Options, being device_id. If left empty will target the user's currently active device.
1239
1261
* @param {function(Object,Object) } callback An optional callback that receives 2 parameters. The first
1240
1262
* one is the error object (null if no error), and the second is the value if the request succeeded.
1241
1263
* @return {Object } Null if a callback is provided, a `Promise` object otherwise
0 commit comments