forked from sonos/api-web-sample-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbackMetaDataComponent.jsx
75 lines (69 loc) · 2.69 KB
/
playbackMetaDataComponent.jsx
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from "react";
import { Component } from "react";
import PlayBackMetadata from "../../ControlAPIs/playbackMetadata";
import ImageComponent from "./imageComponent";
import ServiceLogoComponent from "./serviceLogoComponent";
/**
* Class component for displaying track metadata (track name, track image, artist, container)
*/
class PlaybackMetaDataComponent extends Component {
/**
* @param props.state {JSON} Accesses playbackMetadataAtom's state
* @param props.setState Modifies playbackMetadataAtom's state
* @param props.groupId {string} Used to target specific group when fetching current playback metadata from Sonos API
* @param props.museClientConfig {JSON} Contains access token for Sonos API call
*/
constructor(props) {
super(props);
this.volumeSlider = React.createRef();
// Resets playbackMetadataAtom to initial state
// getPlaybackMetaDataFlag = true ensures that new metadata is fetched on instantiation
this.props.setState({
getPlayBackMetaDataFlag: true,
trackName: null,
trackImage: null,
artistName: null,
containerName: null,
serviceId: null,
serviceName: null
});
}
/**
* If track image does not exist, a generic placeholder image is used. Otherwise, the currently stored track image is returned
* @returns {string} Track image src
*/
getImage = () => {
if (!this.props.state.trackImage) {
return require("../../../images/sonos.png");
} else {
return this.props.state.trackImage;
}
};
render() {
return (
<div className="play_back_metadata">
{/*
Fetches current playback metadata on playbackMetaDataComponent instantiation (only when getPlaybackMetaDataFlag is true)
PlaybackMetadata sets getPlaybackMetaDataFlag to false upon completion
*/}
{this.props.state.getPlayBackMetaDataFlag && (
<PlayBackMetadata
groupId={this.props.groupId}
museClientConfig={this.props.museClientConfig}
/>
)}
{/* Displays current track information based on the state of playbackMetadataAtom */}
<div className="track_details">
<div className="track_image">
<ImageComponent src={this.getImage()} alt="Song being played" />
</div>
<div className="track_name">{this.props.state.trackName}</div>
<div className="track_artist">{this.props.state.artistName}</div>
<div className="track_container">{this.props.state.containerName}</div>
<ServiceLogoComponent serviceId={this.props.state.serviceId} serviceName={this.props.state.serviceName} />
</div>
</div>
);
}
}
export default PlaybackMetaDataComponent;