-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgooglecast-v3.js
executable file
·96 lines (87 loc) · 2.71 KB
/
googlecast-v3.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
import React, { PureComponent } from 'react'
import ReactNative, { Platform, DeviceEventEmitter, NativeModules, requireNativeComponent, UIManager, View, ViewPropTypes } from 'react-native'
import PropTypes from 'prop-types'
const NativeGoogleCastV3 = NativeModules.GoogleCastV3
const GoogleCastV3Handler = {
...NativeGoogleCastV3,
send: (a, b) => {
(b === undefined)
? NativeGoogleCastV3.send(NativeGoogleCastV3.namespace, a)
: NativeGoogleCastV3.send(a, b)
},
resetMediaMetadata: () => {
NativeGoogleCastV3.resetMediaMetadata()
},
setMediaMetadata: (title, subtitle, imageUri) => {
NativeGoogleCastV3.setMediaMetadata(title, subtitle, imageUri)
},
loadVideo: (videoUri) => {
NativeGoogleCastV3.loadVideo(videoUri)
},
loadAudio: (audioUri) => {
NativeGoogleCastV3.loadAudio(audioUri)
},
getMediaState: ( callback ) => {
NativeGoogleCastV3.getMediaState( callback )
},
togglePlayState: () => {
NativeGoogleCastV3.togglePlayState()
},
seek: (position) => {
NativeGoogleCastV3.seek(position)
},
resetCasting: () => {
NativeGoogleCastV3.resetCasting();
},
disconnect: () => {
NativeGoogleCastV3.disconnect();
},
addCastStateListener: (fn) => {
const subscription = DeviceEventEmitter.addListener('googleCastStateChanged', fn)
NativeGoogleCastV3.triggerStateChange()
return subscription
},
addCastMessageListener: (fn) => DeviceEventEmitter.addListener('googleCastMessage', fn),
addProgressListener: (fn) => DeviceEventEmitter.addListener('googleCastProgress', fn),
addCastPlayerStateListener: (fn) => DeviceEventEmitter.addListener('googleCastPlayerState', fn),
}
const stub = {
NO_DEVICES_AVAILABLE: 1,
NOT_CONNECTED: 2,
CONNECTING: 3,
CONNECTED: 4,
PLAYER_STATE_UNKNOWN: 0,
PLAYER_STATE_IDLE: 1,
PLAYER_STATE_PLAYING: 2,
PLAYER_STATE_PAUSED: 3,
PLAYER_STATE_BUFFERING: 4,
send: () => { },
addCastStateListener: (fn) => {
fn(stub.NO_DEVICES_AVAILABLE)
},
addCastMessageListener: () => { },
addProgressListener: () => { },
addCastPlayerStateListener: () => { },
getCurrentDevice: () => Promise.resolve(null)
}
export const GoogleCastV3 = (Platform.OS === 'android') ? GoogleCastV3Handler : stub
class CastButton extends PureComponent {
static propTypes = {
...ViewPropTypes,
color: PropTypes.string,
}
click = () => {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
UIManager.getViewManagerConfig('CastButton').Commands.click,
[],
)
}
render() {
return (
<NativeCastButton {...this.props} />
);
}
}
const NativeCastButton = requireNativeComponent('CastButton', CastButton)
export default (Platform.OS === 'android') ? CastButton : View