-
Notifications
You must be signed in to change notification settings - Fork 6
/
playbackMetadata.js
27 lines (24 loc) · 1.34 KB
/
playbackMetadata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { PlaybackMetadataApiFactory } from "../museClient/api";
import PlaybackMetadataHandler from "../MuseDataHandlers/PlaybackMetadataHandler";
import {useRecoilState} from "recoil";
import playbackMetadataAtom from "../Recoil/playbackMetadataAtom";
/**
* Fetches current playback metadata from Sonos API and sets playbackMetadataAtom's state
* @param props.museClientConfig {JSON} Contains access token for Sonos API call
* @param props.groupId {string} Used to target specific group when calling Sonos API
*/
export default function PlayBackMetadata(props) {
// playbackMetadataResponse (unused) accesses and setPlaybackMetadataResponse modifies playbackMetadataAtom's state
const [playbackMetadataResponse, setPlaybackMetadataResponse] = useRecoilState(playbackMetadataAtom);
// Used to make playback metadata Sonos API calls with currently stored access token and configuration
const playBackMetadataApi = new PlaybackMetadataApiFactory(props.museClientConfig);
// Fetches current playback metadata from Sonos API, processes response through PlaybackMetadataHandler, and sets playbackMetadataAtom's state
playBackMetadataApi
.playbackMetadataGetMetadataStatus(props.groupId)
.then((res) => {
setPlaybackMetadataResponse(PlaybackMetadataHandler(res));
})
.catch(function (error) {
console.error("Error", error);
});
}