Skip to content

Commit c38ba27

Browse files
committed
fix the bug of stucking when open too much videos
1 parent 6cca79f commit c38ba27

File tree

9 files changed

+206
-74
lines changed

9 files changed

+206
-74
lines changed

Diff for: .vscode/settings.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"MicroPython.executeButton": [
3+
{
4+
"text": "",
5+
"tooltip": "Run",
6+
"alignment": "left",
7+
"command": "extension.executeFile",
8+
"priority": 3.5
9+
}
10+
],
11+
"MicroPython.syncButton": [
12+
{
13+
"text": "$(sync)",
14+
"tooltip": "sync",
15+
"alignment": "left",
16+
"command": "extension.execute",
17+
"priority": 4
18+
}
19+
]
20+
}

Diff for: client/.vscode/settings.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"MicroPython.executeButton": [
3+
{
4+
"text": "",
5+
"tooltip": "Run",
6+
"alignment": "left",
7+
"command": "extension.executeFile",
8+
"priority": 3.5
9+
}
10+
],
11+
"MicroPython.syncButton": [
12+
{
13+
"text": "$(sync)",
14+
"tooltip": "sync",
15+
"alignment": "left",
16+
"command": "extension.execute",
17+
"priority": 4
18+
}
19+
]
20+
}

Diff for: client/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"react": "^16.8.4",
1111
"react-dom": "^16.8.4",
1212
"react-dplayer": "^0.2.3",
13+
"react-player": "^2.7.0",
1314
"react-scripts": "2.1.8"
1415
},
1516
"scripts": {

Diff for: client/src/App.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class App extends Component {
1212
>
1313
</NestedList>
1414
<p style={{color:'grey'}}><small><small>
15-
Made by <a href="https://github.com/yingshaoxo" target="_blank" style={{color:'red'}}>yingshaoxo</a>
15+
Made by <a href="https://yingshaoxo.blogspot.com" target="_blank" style={{color:'red'}}>yingshaoxo</a>
1616
</small></small></p>
1717
</div>
1818
);

Diff for: client/src/List.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class NestedList extends React.Component {
195195
<div>
196196
<List
197197
component="nav"
198-
subheader={<ListSubheader component="div">Welcome to Local Show</ListSubheader>}
198+
subheader={<ListSubheader component="div">Welcome to the Local Show</ListSubheader>}
199199
className={classes.root}
200200
>
201201
{

Diff for: client/src/Popup.js

+69-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { unmountComponentAtNode } from "react-dom";
23
import PropTypes from 'prop-types';
34
import Button from '@material-ui/core/Button';
45
import Dialog from '@material-ui/core/Dialog';
@@ -9,8 +10,9 @@ import DialogTitle from '@material-ui/core/DialogTitle';
910
import withMobileDialog from '@material-ui/core/withMobileDialog';
1011

1112
import DPlayer from "react-dplayer";
13+
import ReactPlayer from 'react-player';
1214

13-
import {HOST} from './Const';
15+
import { HOST } from './Const';
1416
const MEDIA_BASE = HOST + 'media/'
1517

1618
class MyVideoPlayer extends React.Component {
@@ -22,21 +24,22 @@ class MyVideoPlayer extends React.Component {
2224
return (
2325
<div>
2426
{
25-
(this.state.show)?
26-
<DPlayer
27-
video={{
28-
url: this.props.target_url
29-
}}
30-
autoplay='true'
31-
preload='metadata'
27+
(this.state.show) ?
28+
<ReactPlayer
29+
url={this.props.target_url}
30+
ref={this.props.dplayerRef}
31+
controls={true}
32+
width={"100%"}
33+
height={"80%"}
34+
playing={true}
3235
onError={() => {
3336
console.log("Something went wroung...")
3437
this.setState({
3538
show: false,
3639
})
3740
}}
3841
/>
39-
:
42+
:
4043
null
4144
}
4245
</div>
@@ -45,13 +48,42 @@ class MyVideoPlayer extends React.Component {
4548
}
4649

4750
class ResponsiveDialog extends React.Component {
51+
constructor(props) {
52+
super(props)
53+
this.dplayerRef = React.createRef()
54+
}
55+
4856
get_target_url = () => {
4957
var root_folder = this.props.parentState.info['root_folder']
5058
var path = this.props.parentState.selected_file_path
5159
var target_url = MEDIA_BASE + path.replace(root_folder, "")
5260
return target_url
5361
}
5462

63+
to_do_a_refresh = () => {
64+
const API_BASE = HOST + 'api/'
65+
const API_FUNCTION_GET_INFO = 'info/'
66+
const API_FUNCTION_GET_FILES = 'files/'
67+
const API_FUNCTION_UPDATE_FILES = 'update/'
68+
69+
var url = `${API_BASE}${API_FUNCTION_GET_FILES}`;
70+
return fetch(url, {
71+
method: "POST",
72+
mode: "cors",
73+
cache: "no-cache",
74+
headers: {
75+
"Content-Type": "application/json",
76+
},
77+
})
78+
.then(
79+
response => response.json()
80+
)
81+
.then(result => {
82+
//console.log(result)
83+
})
84+
//.catch(error => console.log(error));
85+
}
86+
5587
render() {
5688
//you can let it auto decide by setting fullScreen={fullScreen}
5789
const { fullScreen } = this.props;
@@ -62,39 +94,56 @@ class ResponsiveDialog extends React.Component {
6294
fullScreen={false}
6395
maxWidth={"lg"}
6496
open={this.props.parentState.keep_popup_open}
65-
onClose={this.props.handlePopupClose}
97+
onClose={() => {
98+
try {
99+
//console.log(this.dplayerRef.current.getActivePlayer())
100+
//console.log(Object.getOwnPropertyNames(this.dplayerRef.current.getActivePlayer()))
101+
//this.dplayerRef.current.playing = false
102+
//console.log(Object.getOwnPropertyNames(this.dplayerRef.current.dp))
103+
} catch {
104+
}
105+
this.props.handlePopupClose()
106+
//this.to_do_a_refresh()
107+
}}
66108
aria-labelledby="responsive-dialog-title"
67109
>
68-
<DialogTitle
110+
<DialogTitle
69111
id="responsive-dialog-title"
70112
style={{
71113
wordWrap: 'break-word',
72114
}}
73115
>
74116
{this.props.parentState.selected_file_name}
75117
</DialogTitle>
76-
<DialogContent>
118+
<DialogContent
119+
style={{
120+
display: "flex",
121+
justifyContent: "center",
122+
alignItems: "center"
123+
}}
124+
>
77125
<MyVideoPlayer
126+
dplayerRef={this.dplayerRef}
78127
target_url={this.get_target_url()}
79128
/>
80129
</DialogContent>
81130
<DialogActions>
82-
<Button
131+
<Button
83132
onClick={() => {
84133
console.log(this.get_target_url())
85134
window.open(this.get_target_url(), "_blank")
86-
}}
87-
color="primary"
135+
}}
136+
color="primary"
88137
>
89-
Download
138+
Download
90139
</Button>
91-
<Button
140+
<Button
92141
onClick={() => {
93142
var file_url = this.get_target_url().replace("https://", "").replace("http://", "")
94143
var intent_url = `intent://${file_url}#Intent;action=android.intent.action.VIEW;scheme=http;type=video/mp4;end`
95144
window.open(intent_url, "_blank")
96-
}}
97-
color="primary"
145+
}}
146+
color="primary"
98147
autoFocus
99148
>
100149
Play
@@ -110,4 +159,4 @@ ResponsiveDialog.propTypes = {
110159
fullScreen: PropTypes.bool.isRequired,
111160
};
112161

113-
export default withMobileDialog({breakpoint: 'xm'})(ResponsiveDialog);
162+
export default withMobileDialog({ breakpoint: 'xm' })(ResponsiveDialog);

Diff for: client/yarn.lock

+32-1
Original file line numberDiff line numberDiff line change
@@ -3119,6 +3119,11 @@ deepmerge@^3.0.0:
31193119
resolved "http://registry.npm.taobao.org/deepmerge/download/deepmerge-3.2.0.tgz#58ef463a57c08d376547f8869fdc5bcee957f44e"
31203120
integrity sha1-WO9GOlfAjTdlR/iGn9xbzulX9E4=
31213121

3122+
deepmerge@^4.0.0:
3123+
version "4.2.2"
3124+
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
3125+
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==
3126+
31223127
default-gateway@^2.6.0:
31233128
version "2.7.2"
31243129
resolved "http://registry.npm.taobao.org/default-gateway/download/default-gateway-2.7.2.tgz#b7ef339e5e024b045467af403d50348db4642d0f"
@@ -6211,6 +6216,11 @@ load-json-file@^2.0.0:
62116216
pify "^2.0.0"
62126217
strip-bom "^3.0.0"
62136218

6219+
load-script@^1.0.0:
6220+
version "1.0.0"
6221+
resolved "https://registry.yarnpkg.com/load-script/-/load-script-1.0.0.tgz#0491939e0bee5643ee494a7e3da3d2bac70c6ca4"
6222+
integrity sha1-BJGTngvuVkPuSUp+PaPSuscMbKQ=
6223+
62146224
loader-fs-cache@^1.0.0:
62156225
version "1.0.1"
62166226
resolved "http://registry.npm.taobao.org/loader-fs-cache/download/loader-fs-cache-1.0.1.tgz#56e0bf08bd9708b26a765b68509840c8dec9fdbc"
@@ -6409,6 +6419,11 @@ mem@^4.0.0:
64096419
mimic-fn "^1.0.0"
64106420
p-is-promise "^2.0.0"
64116421

6422+
memoize-one@^5.1.1:
6423+
version "5.1.1"
6424+
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.1.1.tgz#047b6e3199b508eaec03504de71229b8eb1d75c0"
6425+
integrity sha512-HKeeBpWvqiVJD57ZUAsJNm71eHTykffzcLZVYWiVfQeI1rJtuEaS7hQiEpWfVVk18donPwJEcFKIkCmPJNOhHA==
6426+
64126427
memory-fs@^0.4.0, memory-fs@~0.4.1:
64136428
version "0.4.1"
64146429
resolved "http://registry.npm.taobao.org/memory-fs/download/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552"
@@ -8161,7 +8176,7 @@ prompts@^0.1.9:
81618176
kleur "^2.0.1"
81628177
sisteransi "^0.1.1"
81638178

8164-
prop-types@^15.6.0, prop-types@^15.6.2:
8179+
prop-types@^15.6.0, prop-types@^15.6.2, prop-types@^15.7.2:
81658180
version "15.7.2"
81668181
resolved "http://registry.npm.taobao.org/prop-types/download/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
81678182
integrity sha1-UsQedbjIfnK52TYOAga5ncv/psU=
@@ -8436,6 +8451,11 @@ react-event-listener@^0.6.2:
84368451
prop-types "^15.6.0"
84378452
warning "^4.0.1"
84388453

8454+
react-fast-compare@^3.0.1:
8455+
version "3.2.0"
8456+
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.0.tgz#641a9da81b6a6320f270e89724fb45a0b39e43bb"
8457+
integrity sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA==
8458+
84398459
react-is@^16.6.3, react-is@^16.7.0, react-is@^16.8.1:
84408460
version "16.8.4"
84418461
resolved "http://registry.npm.taobao.org/react-is/download/react-is-16.8.4.tgz#90f336a68c3a29a096a3d648ab80e87ec61482a2"
@@ -8446,6 +8466,17 @@ react-lifecycles-compat@^3.0.2, react-lifecycles-compat@^3.0.4:
84468466
resolved "http://registry.npm.taobao.org/react-lifecycles-compat/download/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
84478467
integrity sha1-TxonOv38jzSIqMUWv9p4+HI1I2I=
84488468

8469+
react-player@^2.7.0:
8470+
version "2.7.0"
8471+
resolved "https://registry.yarnpkg.com/react-player/-/react-player-2.7.0.tgz#7f25c83b6111770adbae51679f7ad27fb0fa0269"
8472+
integrity sha512-S+d9EfFCb2UlDBKf5U8jTgVQI3QCRfZ8k7kFUgpYLrSjLuowdV/NyZAKprplUNJEho1LmdwtqsDKg21kMIVymw==
8473+
dependencies:
8474+
deepmerge "^4.0.0"
8475+
load-script "^1.0.0"
8476+
memoize-one "^5.1.1"
8477+
prop-types "^15.7.2"
8478+
react-fast-compare "^3.0.1"
8479+
84498480
84508481
version "2.1.8"
84518482
resolved "http://registry.npm.taobao.org/react-scripts/download/react-scripts-2.1.8.tgz#21195bb928b2c0462aa98b2d32edf7d034cff2a9"

Diff for: src/main.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"time"
1212

1313
"github.com/gin-contrib/cors"
14-
"github.com/gin-gonic/contrib/static"
1514
"github.com/gin-gonic/gin"
1615
"github.com/mdp/qrterminal"
1716

@@ -59,7 +58,8 @@ func main() {
5958
router.StaticFS("/ui/", box.HTTPBox())
6059

6160
// Serve target files
62-
router.Use(static.Serve("/media", static.LocalFile(MEDIA_PATH, true)))
61+
//router.Use(static.Serve("/media", static.LocalFile(MEDIA_PATH, true)))
62+
router.StaticFS("/media", http.Dir(MEDIA_PATH))
6363

6464
// Setup route group for the API
6565
api := router.Group("/api/")
@@ -80,6 +80,7 @@ func main() {
8080
api.Any("files/", func(c *gin.Context) {
8181
//whatever := c.Query("name")
8282
c.JSON(http.StatusOK, file_dict)
83+
runtime.GC()
8384
})
8485
}
8586

@@ -116,5 +117,15 @@ func main() {
116117
}()
117118

118119
// Start and run the server
119-
router.Run(":5000")
120+
//router.Run(":5000")
121+
122+
s := &http.Server{
123+
Addr: ":5000",
124+
Handler: router,
125+
ReadTimeout: 1 * time.Second,
126+
WriteTimeout: 1 * time.Second,
127+
IdleTimeout: 1 * time.Second,
128+
MaxHeaderBytes: 1 << 20,
129+
}
130+
s.ListenAndServe()
120131
}

Diff for: src/rice-box.go

+48-48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)