Skip to content

Commit c2cc118

Browse files
committed
Simplify CORS and enhance video box for mobile devices
1 parent 4043b98 commit c2cc118

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

pystream/main.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,19 @@ def task() -> None:
2121

2222
def startup_tasks() -> None:
2323
"""Tasks that need to run during the API startup."""
24-
logger.info('Setting CORS policy.')
2524
origins = ["http://localhost.com", "https://localhost.com"]
2625
if config.env.website:
26+
logger.info('Setting CORS policy.')
2727
origins.extend([
2828
f"http://{config.env.website.host}",
2929
f"https://{config.env.website.host}",
3030
f"http://{config.env.website.host}/*",
3131
f"https://{config.env.website.host}/*"
3232
])
33-
app.add_middleware(
34-
CORSMiddleware,
35-
allow_origins=origins,
36-
allow_origin_regex='https://.*\.ngrok\.io/*', # noqa: W605
37-
allow_credentials=True,
38-
allow_methods=["*"],
39-
allow_headers=["*"],
40-
)
33+
kwargs = dict(allow_origins=origins)
34+
if config.env.ngrok_token:
35+
kwargs['allow_origin_regex'] = 'https://.*\.ngrok\.io/*' # noqa: W605
36+
app.add_middleware(CORSMiddleware, **kwargs)
4137
task()
4238

4339

pystream/templates/index.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,34 @@
7474
text-align: center;
7575
}
7676
</style>
77+
<!-- Size of video container and the player -->
78+
<style>
79+
#video-container {
80+
position: relative;
81+
width: 70%; /* fixme: 50 works for 24" and 27" screens, 70 works for mobile phones (choose a side) */
82+
height: 100%;
83+
margin-left: auto;
84+
margin-right: auto;
85+
display: block
86+
}
87+
#video-player {
88+
position: relative;
89+
width: 100%;
90+
height: 100%;
91+
margin-left: auto;
92+
margin-right: auto;
93+
display: block
94+
}
95+
</style>
7796
</head>
7897
<body>
7998
<button class="home" onclick="goHome()"><i class="fa fa-home"></i> Home</button>
8099
<button class="back" onclick="goBack()"><i class="fa fa-backward"></i> Back</button>
81100
<button class="logout" onclick="logOut()"><i class="fa fa-sign-out"></i> Logout</button>
82101
<br><br>
83102
<h1>{{title}}</h1>
103+
<div id="video-container">
84104
<video id="video-player"
85-
width="960" height="480"
86105
class="video-js"
87106
preload="auto"
88107
controls muted="muted"
@@ -96,6 +115,7 @@ <h1>{{title}}</h1>
96115
<a href="https://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
97116
</p>
98117
</video>
118+
</div>
99119
<script>
100120
let origin = window.location.origin; // Get the current origin using JavaScript
101121
let path = "{{ path }}"; // Get the path variable from Jinja template

0 commit comments

Comments
 (0)