Skip to content

Commit 6931295

Browse files
committed
[Spotify] Only allow expected track to play
1 parent 8f82266 commit 6931295

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/plugins/spotify/connect.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ export default {
167167
play(uri?: string) {
168168
return ensureAuthenticated()
169169
.then(ensurePlayer)
170+
.tap(() => log.debug(`spotify.play(${uri})`))
171+
.then(() => {
172+
if (uri) {
173+
player.setExpectedURI(uri);
174+
}
175+
})
170176
.then(() => (uri ? [uri] : undefined))
171177
.then(uris => spotify.play({ uris }))
172178
.then(() => player.waitForPlayback(uri))

src/plugins/spotify/player.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ export default {
4646
.then(el => el.getText());
4747
},
4848

49+
setExpectedURI(id: string) {
50+
if (!driver) {
51+
return Promise.reject(new Error("No driver"));
52+
}
53+
54+
let d: Driver = driver;
55+
// Get the device ID
56+
return Promise.resolve()
57+
.then(() => d.findElement(By.id("expectedURI")))
58+
.tap(e => e.clear())
59+
.tap(e => e.sendKeys(id));
60+
},
61+
4962
getStatus() {
5063
if (!driver) {
5164
return Promise.reject(new Error("No driver"));

support/plugins/spotify/page.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<title>Spotify Web Player (loading)</title>
88
</head>
99
<body>
10+
<input type="text" id="expectedURI" />
11+
1012
<span id="device_id"></span>
1113
<span id="device_state">loading</span>
1214

@@ -48,6 +50,12 @@
4850
const track = state.track_window.current_track;
4951

5052
if (!state.paused) {
53+
if (track.uri != expectedURI.value) {
54+
console.log(
55+
`MISMATCHED TRACKS -- Expected ${expectedURI.value}, got ${track.id}`
56+
);
57+
player.pause().then(() => player.seek(0));
58+
}
5159
document.getElementById("device_state").innerText = "playing";
5260
} else {
5361
document.getElementById("device_state").innerText = "paused";

0 commit comments

Comments
 (0)