-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
119 lines (108 loc) · 3.21 KB
/
index.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
// @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'
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,
}) {
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,
initChannel(namespace: string) {
return GoogleCast.initChannel(namespace)
},
sendMessage(namespace: string, message: string) {
return GoogleCast.sendMessage(message, namespace)
},
// 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,
}