forked from phobal/ivideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideo.js
137 lines (133 loc) · 3.65 KB
/
Video.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
// @flow
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { webview, ipcRenderer } from 'electron';
import Channel from './Channel';
import ToolBar from './ToolBar';
import * as sourceActions from '../actions/source';
class VideoPlay extends PureComponent < Props > {
constructor(props) {
super(props);
this.handleSwitchChannel = this.handleSwitchChannel.bind(this);
this.onComeback = this.onComeback.bind(this);
this.onSourceSelected = this.onSourceSelected.bind(this);
this.onSwitchSource = this.onSwitchSource.bind(this);
}
state = {
channel: [],
url: 'https://v.qq.com',
freeUrl: [],
selectedUrl: 'http://vip.jlsprh.com/index.php?url=',
isFullScreen: false,
}
componentDidMount() {
this.props.actions.getAllVideoSource();
const webview = this.webview;
webview.addEventListener('dom-ready', () => {
this.setTitle();
});
webview.addEventListener('new-window', (obj) => {
const { freeUrl } = this.state;
this.setState({
url: `${obj.url}`
});
});
webview.addEventListener('will-navigate', (obj) => {
this.setState({
url: `${obj.url}`
});
});
ipcRenderer.on('enter-full-screen', (e, msg) => {
this.setState({
isFullScreen: msg
});
});
}
componentWillReceiveProps(nextProps) {
const { source } = nextProps;
if(source) {
this.setState({
channel: source.platformlist,
freeUrl: source.list
});
}
}
handleSwitchChannel(value) {
this.setState({
url: value.key
});
}
setTitle() {
const title = this.webview.getTitle();
this.setState({
title,
});
}
onComeback() {
this.webview.goBack();
}
onSourceSelected(value) {
const selectedUrl = this.state.freeUrl.find(d => {
if (d.name === value) {
return d.url;
}
})
this.setState({
selectedUrl,
});
}
onSwitchSource() {
const { selectedUrl } = this.state;
const currentVideoUrl = this.webview.getURL();
this.setState({
url: `${selectedUrl.url}${currentVideoUrl}`
});
}
render() {
const { channel, url, freeUrl, title, isFullScreen } = this.state;
const isHiddenStyle = isFullScreen ? { display: 'none'} : { display: 'flex'};
return (
<div style={{ display: 'flex' }}>
<div style={{ minWidth: '150px', ...isHiddenStyle }}>
<Channel
channel={channel}
handleSwitchChannel={this.handleSwitchChannel}
/>
</div>
<div style={{ height: '100vh', width: isFullScreen ? '100vw' : 'calc(100vw - 150px)', display: 'flex', flexDirection: 'column' }}>
<div style={{ height: '60px', ...isHiddenStyle }}>
<ToolBar
onComeback={this.onComeback}
onSourceSelected={this.onSourceSelected}
onSwitchSource={this.onSwitchSource}
freeUrl={freeUrl}
title={title}
/>
</div>
<webview
ref={ (webview) => {this.webview = webview} }
title="腾讯视频"
style={{ height: isFullScreen ? '100vh' : 'calc(100vh - 60px)', width: '100%' }}
src={url}
allowpopups="true"
>
</webview>
</div>
</div>
);
}
}
function mapDispatchToProps(dispatch) {
return {
actions: {
...bindActionCreators(sourceActions, dispatch),
},
}
}
function mapStateToProps(state) {
return {
source: state.source
}
}
export default connect(mapStateToProps, mapDispatchToProps)(VideoPlay);