Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit ea934bb

Browse files
authored
Merge pull request #148 from codeoverflow-org/feature/spotify-sample
Add sample for spotify
2 parents 4d375ce + 7f3cd6b commit ea934bb

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { NodeCG } from "nodecg/types/server";
2+
import { requireService } from "nodecg-io-core/extension/serviceClientWrapper";
3+
import { SpotifyServiceClient } from "nodecg-io-spotify";
4+
5+
module.exports = function (nodecg: NodeCG) {
6+
nodecg.log.info("Sample bundle for spotify started");
7+
8+
const service = requireService<SpotifyServiceClient>(nodecg, "spotify");
9+
service?.onAvailable(async (client) => {
10+
nodecg.log.info("Client has been updated.");
11+
12+
const track = await client.getNativeClient().getMyCurrentPlayingTrack();
13+
const name = track.body.item?.name;
14+
const artists = track.body.item?.artists.map((a) => a.name);
15+
nodecg.log.info(`Currently playing "${name}" by "${artists}".`);
16+
});
17+
18+
service?.onUnavailable(() => nodecg.log.info("Client has been unset."));
19+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "spotify-current-song",
3+
"private": true,
4+
"version": "0.1.0",
5+
"nodecg": {
6+
"compatibleRange": "^1.1.1",
7+
"bundleDependencies": {
8+
"nodecg-io-spotify": "^0.1.0"
9+
}
10+
},
11+
"scripts": {
12+
"build": "tsc -b",
13+
"watch": "tsc -b -w",
14+
"clean": "tsc -b --clean"
15+
},
16+
"license": "MIT",
17+
"dependencies": {
18+
"nodecg-io-spotify": "^0.1.0",
19+
"nodecg-io-core": "^0.1.0",
20+
"@types/node": "^14.14.13",
21+
"nodecg": "^1.7.4",
22+
"typescript": "^4.1.3"
23+
}
24+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../tsconfig.common.json"
3+
}

0 commit comments

Comments
 (0)