forked from hosek/react-native-google-cast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoogleCast.js
197 lines (185 loc) · 5.02 KB
/
GoogleCast.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// @flow
import {
DeviceEventEmitter,
NativeEventEmitter,
NativeModules,
Platform,
} from 'react-native'
const { RNGoogleCast: GoogleCast } = NativeModules
export default {
getCastDevice() {
return GoogleCast.getCastDevice()
},
getCastState() {
return GoogleCast.getCastState().then(
state =>
['NoDevicesAvailable', 'NotConnected', 'Connecting', 'Connected'][
state
],
)
},
castMedia(params) {
return GoogleCast.castMedia(params)
},
/**
* Ends the current session.
*
* This is an asynchronous operation.
*
* Resolves if the operation has been started successfully, rejects if there is no session currently established or if the operation could not be started.
*
* @param {Boolean} stopCasting Whether casting of content on the receiver should be stopped when the session is ended.
* @returns {Promise}
*/
endSession(stopCasting = false) {
return GoogleCast.endSession(stopCasting)
},
/**
* Begins (or resumes) playback of the current media item.
*/
play: GoogleCast.play,
/**
* Pauses playback of the current media item.
*/
pause: GoogleCast.pause,
/**
* Stops playback of the current media item.
*/
stop: GoogleCast.stop,
/**
* Seeks to a new position within the current media item.
*
* @param {number} playPosition
*/
seek(playPosition) {
return GoogleCast.seek(playPosition)
},
launchExpandedControls: GoogleCast.launchExpandedControls,
/**
* Displays the Expanded Controls screen programmatically. Users can also open it by clicking on Mini Controls.
*
* @returns `true` if the Expanded Controls were shown, `false` if it was not shown.
*/
showExpandedControls() {
return GoogleCast.showExpandedControls()
},
/**
* If it has not been shown before, presents a fullscreen modal view controller that calls attention to the Cast button and displays some brief instructional text about its use.
*
* By default, the overlay is only displayed once. To change this, pass `once: false` in the options.
*
* @returns Promise that becomes `true` if the view controller was shown, `false` if it was not shown because it had already been shown before, or if the Cast Button was not found.
*/
showIntroductoryOverlay(options){
return GoogleCast.showIntroductoryOverlay({ once: true, ...options })
},
setVolume(volume) {
return GoogleCast.setVolume(volume)
},
setDeviceMuted(muted) {
return GoogleCast.setDeviceMuted(muted)
},
initChannel(namespace) {
return GoogleCast.initChannel(namespace)
},
sendMessage(namespace, message) {
return GoogleCast.sendMessage(message, namespace)
},
showCastPicker(){
GoogleCast.showCastPicker()
},
/**
* Get available routes.
*
* @returns map of route ids and names.
*/
getRoutes() {
return GoogleCast.getRoutes()
},
/**
* Select route.
*
* @returns success.
*/
selectRoute(id) {
return GoogleCast.selectRoute(id)
},
/**
* Get actual playing stream metadata.
*
* @returns success.
*/
getMediaInfo() {
return GoogleCast.getMediaInfo()
},
/**
* Get actual remote player state.
*
* @returns success.
*/
getMediaStatus() {
return GoogleCast.getMediaStatus()
},
/**
* Get actual volume.
*
* @returns success.
*/
getVolume() {
return GoogleCast.getVolume()
},
/**
* Is device muted.
*
* @returns muted.
*/
isMuted() {
return GoogleCast.isMuted()
},
/**
* Disconnect.
*
* @returns success.
*/
unselectRoute() {
return GoogleCast.unselectRoute()
},
/**
* Skip the x miliseconds.
*
* @param {number} interval
*/
skip(interval) {
return GoogleCast.skip(interval)
},
/**
* Enable/disable subtitles, optionally selecting a preferred subtitle language.
*
* @param {boolean} enabled
* @param {boolean} languageCode
*/
toggleSubtitles(enabled, languageCode) {
return GoogleCast.toggleSubtitles(enabled, languageCode)
},
// TODO use the same native event interface instead of hacking it here
EventEmitter:
Platform.OS === 'ios'
? new NativeEventEmitter(GoogleCast)
: DeviceEventEmitter,
SESSION_STARTING: GoogleCast.SESSION_STARTING,
SESSION_STARTED: GoogleCast.SESSION_STARTED,
SESSION_START_FAILED: GoogleCast.SESSION_START_FAILED,
SESSION_SUSPENDED: GoogleCast.SESSION_SUSPENDED,
SESSION_RESUMING: GoogleCast.SESSION_RESUMING,
SESSION_RESUMED: GoogleCast.SESSION_RESUMED,
SESSION_ENDING: GoogleCast.SESSION_ENDING,
SESSION_ENDED: GoogleCast.SESSION_ENDED,
MEDIA_STATUS_UPDATED: GoogleCast.MEDIA_STATUS_UPDATED,
MEDIA_PLAYBACK_STARTED: GoogleCast.MEDIA_PLAYBACK_STARTED,
MEDIA_PLAYBACK_ENDED: GoogleCast.MEDIA_PLAYBACK_ENDED,
MEDIA_PROGRESS_UPDATED: GoogleCast.MEDIA_PROGRESS_UPDATED,
MEDIA_METADATA_CHANGED: GoogleCast.MEDIA_METADATA_CHANGED,
CHANNEL_CONNECTED: GoogleCast.CHANNEL_CONNECTED,
CHANNEL_DISCONNECTED: GoogleCast.CHANNEL_DISCONNECTED,
CHANNEL_MESSAGE_RECEIVED: GoogleCast.CHANNEL_MESSAGE_RECEIVED,
}