-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.js
110 lines (108 loc) · 5.33 KB
/
events.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const Spotify = require('./Spotify');
import { NativeEventEmitter } from 'react-native';
import { AudioStreaming, Auth } from './constants';
export default registerEventHandlers = (dispatch) => {
const spotifyEmitter = new NativeEventEmitter(Spotify);
/*
SPTAudioControllerDelegate
*/
const logoutSubscription = spotifyEmitter.addListener('audioStreamingDidLogout', (body) => {
dispatch({
type: AudioStreaming.SPOTIFY_audioStreamingDidLogout,
});
Spotify.stopWithError();
});
const receiveErrorSubscription = spotifyEmitter.addListener('audioStreamingDidReceiveError', (body) => {
console.log('Spotify: Error:', body);
switch (body.error) {
case 8:
return dispatch({
type: Auth.SPOTIFY_AUTH_FAILURE,
});
default:
}
});
const loginSubscription = spotifyEmitter.addListener('audioStreamingDidLogin', (body) => {
dispatch({
type: AudioStreaming.SPOTIFY_audioStreamingDidLogin,
});
});
const tempConnectionErrorSubscription = spotifyEmitter.addListener('audioStreamingDidEncounterTemporaryConnectionError', (body) => {
console.log('Spotify: temp connection error:', body);
});
const messageSubscription = spotifyEmitter.addListener('audioStreamingdidReceiveMessage', (body) => {
console.log('Spotify: message:', body);
});
const disconnectSubscription = spotifyEmitter.addListener('audioStreamingDidDisconnect', (body) => {
console.log('Spotify: disconnect', body);
});
const reconnectSubscription = spotifyEmitter.addListener('audioStreamingDidReconnect', (body) => {
console.log('Spotify: reconnect', body);
});
/*
SPTAudioStreamingPlaybackDelegate
*/
const audioStreamingDidReceivePlaybackEventSubscription = spotifyEmitter.addListener('audioStreamingDidReceivePlaybackEvent', (body) => {
console.log('Spotify: audioStreamingDidReceivePlaybackEvent', body);
});
const audioStreamingDidChangePositionSubscription = spotifyEmitter.addListener('audioStreamingDidChangePosition', (body) => {
dispatch({
type: AudioStreaming.SPOTIFY_audioStreamingDidChangePosition,
position: body.position,
});
});
const audioStreamingDidChangePlaybackStatusSubscription = spotifyEmitter.addListener('audioStreamingDidChangePlaybackStatus', (body) => {
dispatch({
type: AudioStreaming.SPOTIFY_audioStreamingDidChangePlaybackStatus,
isPlaying: body.isPlaying,
})
});
const audioStreamingDidSeekToPositionSubscription = spotifyEmitter.addListener('audioStreamingDidSeekToPosition', (body) => {
console.log('Spotify: audioStreamingDidSeekToPosition', body);
dispatch({
type: AudioStreaming.SPOTIFY_audioStreamingDidSeekToPosition,
position: body.position,
});
});
const audioStreamingDidChangeVolumeSubscription = spotifyEmitter.addListener('audioStreamingDidChangeVolume', (body) => {
console.log('Spotify: audioStreamingDidChangeVolume', body);
});
const audioStreamingDidChangeShuffleStatusSubscription = spotifyEmitter.addListener('audioStreamingDidChangeShuffleStatus', (body) => {
console.log('Spotify: audioStreamingDidChangeShuffleStatus', body);
});
const audioStreamingDidChangeRepeatStatusSubscription = spotifyEmitter.addListener('audioStreamingDidChangeRepeatStatus', (body) => {
console.log('Spotify: audioStreamingDidChangeRepeatStatus', body);
});
const audioStreamingDidChangeMetadataSubscription = spotifyEmitter.addListener('audioStreamingDidChangeMetadata', (body) => {
dispatch({
type: AudioStreaming.SPOTIFY_audioStreamingDidChangeMetadata,
prevTrack: body.prevTrack,
currentTrack: body.currentTrack,
nextTrack: body.nextTrack,
});
});
const audioStreamingDidStartPlayingTrackSubscription = spotifyEmitter.addListener('audioStreamingDidStartPlayingTrack', (body) => {
console.log('Spotify: audioStreamingDidStartPlayingTrack', body);
});
const audioStreamingDidStopPlayingTrackSubscription = spotifyEmitter.addListener('audioStreamingDidStopPlayingTrack', (body) => {
console.log('Spotify: audioStreamingDidStopPlayingTrack', body);
});
const audioStreamingDidSkipToNextTrackSubscription = spotifyEmitter.addListener('audioStreamingDidSkipToNextTrack', (body) => {
console.log('Spotify: audioStreamingDidSkipToNextTrack', body);
});
const audioStreamingDidSkipToPreviousTrackSubscription = spotifyEmitter.addListener('audioStreamingDidSkipToPreviousTrack', (body) => {
console.log('Spotify: audioStreamingDidSkipToPreviousTrack', body);
});
const audioStreamingDidBecomeActivePlaybackDeviceSubscription = spotifyEmitter.addListener('audioStreamingDidBecomeActivePlaybackDevice', (body) => {
console.log('Spotify: audioStreamingDidBecomeActivePlaybackDevice', body);
});
const audioStreamingDidBecomeInactivePlaybackDeviceSubscription = spotifyEmitter.addListener('audioStreamingDidBecomeInactivePlaybackDevice', (body) => {
console.log('Spotify: audioStreamingDidBecomeInactivePlaybackDevice', body);
});
const audioStreamingDidLosePermissionForPlaybackSubscription = spotifyEmitter.addListener('audioStreamingDidLosePermissionForPlayback', (body) => {
console.log('Spotify: audioStreamingDidLosePermissionForPlayback', body);
});
const audioStreamingDidPopQueueSubscription = spotifyEmitter.addListener('audioStreamingDidPopQueue', (body) => {
console.log('Spotify: audioStreamingDidPopQueue', body);
});
}