-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
205 lines (186 loc) · 4.98 KB
/
index.js
File metadata and controls
205 lines (186 loc) · 4.98 KB
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
198
199
200
201
202
203
204
205
// @flow
import {
DeviceEventEmitter,
NativeEventEmitter,
NativeModules,
Platform,
} from 'react-native'
const { RNGoogleCast: GoogleCast } = NativeModules
import CastButton from './CastButton'
export { CastButton }
type CastDevice = {
id: string,
version: string,
name: string,
model: string,
}
type CastState =
| 'NoDevicesAvailable'
| 'NotConnected'
| 'Connecting'
| 'Connected'
type TextTrackStyle = {
backgroundColor?: string,
edgeColor?: string,
edgeType?: 'depressed' | 'dropShadow' | 'none' | 'outline' | 'raised',
fontFamily?: string,
fontGenericFamily?:
| 'casual'
| 'cursive'
| 'monoSansSerif'
| 'monoSerif'
| 'sansSerif'
| 'serif'
| 'smallCaps',
fontScale?: number,
fontStyle?: 'bold' | 'boldItalic' | 'italic' | 'normal',
foregroundColor?: string,
windowColor?: string,
windowCornerRadius?: number,
windowType?: 'none' | 'normal' | 'rounded',
}
export default {
getCastDevice(): Promise<CastDevice> {
return GoogleCast.getCastDevice()
},
getCastState(): Promise<CastState> {
return GoogleCast.getCastState().then(
state =>
['NoDevicesAvailable', 'NotConnected', 'Connecting', 'Connected'][
state
],
)
},
castMedia(params: {
mediaUrl: string,
title?: string,
subtitle?: string,
studio?: string,
imageUrl?: string,
posterUrl?: string,
contentType?: string,
streamDuration?: number,
playPosition?: number,
isLive?: boolean,
customData?: Object,
textTrackStyle?: TextTrackStyle,
}) {
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: Boolean = false): Promise {
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: number) {
return GoogleCast.seek(playPosition)
},
launchExpandedControls: GoogleCast.launchExpandedControls,
showIntroductoryOverlay: GoogleCast.showIntroductoryOverlay,
setVolume(volume: number) {
return GoogleCast.setVolume(volume)
},
initChannel(namespace: string) {
return GoogleCast.initChannel(namespace)
},
sendMessage(namespace: string, message: string) {
return GoogleCast.sendMessage(message, namespace)
},
showCastPicker(){
GoogleCast.showCastPicker()
},
/**
* Get available routes.
*
* @returns map of route ids and names.
*/
getRoutes(): Promise<Array<{ id: string, name: string }>> {
return GoogleCast.getRoutes()
},
/**
* Select route.
*
* @returns success.
*/
selectRoute(id: string): Promise<boolean> {
return GoogleCast.selectRoute(id)
},
/**
* Get actual playing stream metadata.
*
* @returns success.
*/
getMediaInfo(): Promise<string> {
return GoogleCast.getMediaInfo()
},
/**
* Get actual volume.
*
* @returns success.
*/
getVolume(): Promise<number> {
return GoogleCast.getVolume()
},
/**
* Disconnect.
*
* @returns success.
*/
unselectRoute(): Promise<number> {
return GoogleCast.unselectRoute()
},
/**
* Enable/disable subtitles, optionally selecting a preferred subtitle language.
*
* @param {boolean} enabled
* @param {boolean} languageCode
*/
toggleSubtitles(enabled: boolean, languageCode?: string) {
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,
CHANNEL_CONNECTED: GoogleCast.CHANNEL_CONNECTED,
CHANNEL_DISCONNECTED: GoogleCast.CHANNEL_DISCONNECTED,
CHANNEL_MESSAGE_RECEIVED: GoogleCast.CHANNEL_MESSAGE_RECEIVED,
}