Skip to content

Commit bded3e5

Browse files
authored
Merge pull request #48 from apiad/develop
Develop
2 parents df52fd0 + a6d21b2 commit bded3e5

File tree

9 files changed

+146
-21
lines changed

9 files changed

+146
-21
lines changed

auditorium/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def publish(
2727
path: str,
2828
name: str,
2929
*,
30-
server: str = "wss://auditorium.apiad.net",
30+
server: str = "ws://auditorium.apiad.net",
3131
instance_name: str = "show"
3232
):
3333
show = Show.load(path, instance_name)

auditorium/server.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@
77
from fastapi import FastAPI, HTTPException
88
from starlette.responses import HTMLResponse
99
from starlette.websockets import WebSocket
10+
from starlette.staticfiles import StaticFiles
1011
import asyncio
1112
from jinja2 import Template
1213

1314
from .utils import path
1415
from .show import UpdateData
1516

1617
server = FastAPI()
18+
server.mount("/static", StaticFiles(directory=path("static")))
1719

1820
SERVERS: Dict[str, Tuple[asyncio.Queue, asyncio.Queue]] = {}
1921

20-
with open(path('templates/server.html')) as fp:
21-
TEMPLATE = Template(fp.read())
22-
2322

2423
@server.get("/")
2524
async def index():
25+
with open(path('templates/server.html')) as fp:
26+
TEMPLATE = Template(fp.read())
27+
2628
return HTMLResponse(TEMPLATE.render(servers_list=list(SERVERS)))
2729

2830

@@ -56,15 +58,29 @@ async def update(name: str, data: UpdateData):
5658
return response
5759

5860

61+
async def ping(name):
62+
try:
63+
queue_in, queue_out = SERVERS[name]
64+
await queue_in.put(dict(type="ping"))
65+
response = await queue_out.get()
66+
assert response['msg'] == 'pong'
67+
return True
68+
except:
69+
return False
70+
71+
5972
@server.websocket("/ws")
6073
async def ws(websocket: WebSocket):
6174
await websocket.accept()
6275
name = await websocket.receive_text()
6376

6477
if name in SERVERS:
65-
await websocket.send_json(dict(type="error", msg="Name is already taken."))
66-
await websocket.close()
67-
return
78+
alive = await ping(name)
79+
80+
if alive:
81+
await websocket.send_json(dict(type="error", msg="Name is already taken."))
82+
await websocket.close()
83+
return
6884

6985
print("Registering new server: ", name)
7086

auditorium/show.py

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def _do_ws_command(self, command):
107107
if command["type"] == "render":
108108
print("Rendering content")
109109
return dict(content=self.render())
110+
if command["type"] == "ping":
111+
print("Saying hello")
112+
return dict(msg="pong")
110113
elif command["type"] == "error":
111114
print("(!) %s" % command['msg'])
112115
raise websockets.exceptions.ConnectionClosedError(1006, command['msg'])

auditorium/static/css/server.css

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
body {
2+
font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
3+
padding: 0px;
4+
margin: 0px;
5+
6+
font-size: x-large;
7+
}
8+
9+
div.main {
10+
color: white;
11+
background-image: url("/static/img/banner.jpg");
12+
background-size: cover;
13+
text-align: center;
14+
margin: 0px;
15+
}
16+
17+
div.hero {
18+
background-color: rgba(0, 10, 20, 0.8);
19+
padding-top: 250px;
20+
padding-bottom: 250px;
21+
}
22+
23+
div.section {
24+
width: 900px;
25+
margin: auto;
26+
padding: 20px;
27+
}
28+
29+
div.footer {
30+
padding: 20px;
31+
text-align: center;
32+
color: white;
33+
background-color: rgba(0, 10, 20, 0.8);
34+
}
35+
36+
div.footer a {
37+
color: white;
38+
}
39+
40+
a.fork-me {
41+
position: absolute;
42+
right: 0px;
43+
top: 0px;
44+
}

auditorium/static/img/banner.jpg

944 KB
Loading

auditorium/templates/server.html

+28-9
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,36 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
77
<title>Auditorium</title>
8+
9+
<link href="https://fonts.googleapis.com/css?family=DM+Sans:300,400,700&display=swap" rel="stylesheet">
10+
<link rel="stylesheet" href="static/css/server.css">
811
</head>
912
<body>
10-
<h1>Welcome to Auditorium</h1>
1113

12-
<h3>The following slideshows have been registered:</h3>
13-
<ul>
14-
{% for name in servers_list %}
15-
<li>
16-
<a href="/{{ name }}/">{{ name }}</a>
17-
</li>
18-
{% endfor %}
19-
</ul>
14+
<a class="fork-me" href="https://github.com/apiad/auditorium"><img width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_white_ffffff.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"></a>
15+
16+
<div class="main">
17+
<div class="hero">
18+
19+
<h1>Auditorium</h1>
20+
<h2>A Python-powered slideshow generator with steroids</h2>
21+
22+
</div>
23+
</div>
24+
25+
<div class="section">
26+
<h3>The following slideshows have been registered:</h3>
27+
<ul>
28+
{% for name in servers_list %}
29+
<li>
30+
<a href="/{{ name }}/">{{ name }}</a>
31+
</li>
32+
{% endfor %}
33+
</ul>
34+
</div>
35+
36+
<div class="footer">
37+
Copyright 2020 - <a href="http://auditorium.apiad.net">auditorium.apiad.net</a>
38+
</div>
2039
</body>
2140
</html>

docs/history.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# History
22

3+
### v19.1.5
4+
5+
* Fixed automatic server address for `auditorium publish`.
6+
37
### v19.1.4
48

59
* Added command `auditorium server` that allows to proxy a slideshow through a public server.

docs/hosting.md

+43-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,48 @@ auditorium run [file] --host=0.0.0.0
1616
```
1717
Then give them your public IP address. In Linux, run `ip addr` to see it.
1818

19+
## Hosting freely with `auditorium publish`
20+
21+
If your audience cannot reach you on the local network, or the computer
22+
where the slideshow runs is not the one where you will be presenting, then
23+
you need a way to proxy your slideshow to a public URL.
24+
25+
Enter `auditorium publish`, a command (and related service) that will relay
26+
your slideshow to [auditorium.apiad.net](http://auditorium.apiad.net).
27+
The slideshow still runs on your computer, but it is connected through websockets
28+
with a server that renders the slide and proxies all incoming requests back to your machine.
29+
30+
To use it, simple run:
31+
32+
```bash
33+
auditorium publish [file] --name [your-slideshow-name]
34+
```
35+
36+
Then head over to `http://auditorium.apiad.net/your-slideshow-name/` and enjoy!
37+
38+
> **NOTE:** This service is provided as-is with no guarantees whatsoever. The service runs
39+
> on a development server that is restarted often (at least twice a day), so slideshows are **not** guaranteed to stay
40+
> up for a long time. Don't use this service in mission critical presentations.
41+
42+
If you need finer control then you can host the server yourself on your own infrastructure
43+
and thus ensure that it's online when you need it. Just run:
44+
45+
```bash
46+
auditorium server [--host HOST] [--port PORT]
47+
```
48+
49+
Make sure the server is publicly accessible. You'll probably use some kind of web server,
50+
or `--host 0.0.0.0` and `--port 80` which you can totally do since `auditorium` ships
51+
with `uvicorn` which is a fully fledged production web server.
52+
Then publish to your own address with:
53+
54+
```bash
55+
auditorium publish [file] --name [name] --server [ws://your-server:port] # or wss://
56+
```
57+
1958
## Hosting temporarily through `ngrok`
2059

21-
The second best option is to use [`ngrok`](https://ngrok.com/).
60+
Another option is to use [`ngrok`](https://ngrok.com/).
2261
It creates a tunnel between your computer and ngrok's servers, and gives you a public, secure (HTTPS)
2362
and free URL that back-tunnels to your `localhost:port`.
2463

@@ -29,11 +68,11 @@ usual `auditorium run [file]` and in another terminal run:
2968
ngrok http 6789
3069
```
3170

32-
It will answer with a temporal, autogenerated URL that you can give the audience.
71+
It will answer with a temporal, auto-generated URL that you can give the audience.
3372
The upside is that everything is being run on your computer but published through a public
3473
URL, which means anyone on the world can see it.
3574
The downside is that it only works for as long as you have `ngrok` running.
36-
Plus, everytime you run it, it generates a different public URL.
75+
Plus, every time you run it, it generates a different public URL.
3776
The do have paid plans for securing a custom domain.
3877

3978
## Hosting static files at Github Pages
@@ -54,7 +93,7 @@ The downside is no animations or interactive logic.
5493
Another option is to host the static presentation and backend at [now.sh](https://now.sh).
5594
If you don't know what [now.sh](https://now.sh) is, go and [read about it](https://zeit.co/docs) first.
5695

57-
This is actually how we host thed demo at [auditorium-demo.apiad.net](https://auditorium-demo.apiad.net).
96+
This is actually how we host the demo at [auditorium-demo.apiad.net](https://auditorium-demo.apiad.net).
5897
The [demo](https://github.com/apiad/auditorium/tree/master/demo) folder folder shows the layout you need to comply with for hosting a slideshow at [now.sh](https://now.sh), such that the backend logic works as well.
5998

6099
Make sure your `slideshow.py` (or whatever the name) slideshow file has the following line:

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "auditorium"
3-
version = "19.1.4"
3+
version = "19.1.5"
44
description = "A Python-powered slideshow maker with steroids."
55
authors = ["Alejandro Piad <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)