Skip to content

Commit

Permalink
Merge pull request #48 from apiad/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
apiad authored Jan 2, 2020
2 parents df52fd0 + a6d21b2 commit bded3e5
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 21 deletions.
2 changes: 1 addition & 1 deletion auditorium/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def publish(
path: str,
name: str,
*,
server: str = "wss://auditorium.apiad.net",
server: str = "ws://auditorium.apiad.net",
instance_name: str = "show"
):
show = Show.load(path, instance_name)
Expand Down
28 changes: 22 additions & 6 deletions auditorium/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@
from fastapi import FastAPI, HTTPException
from starlette.responses import HTMLResponse
from starlette.websockets import WebSocket
from starlette.staticfiles import StaticFiles
import asyncio
from jinja2 import Template

from .utils import path
from .show import UpdateData

server = FastAPI()
server.mount("/static", StaticFiles(directory=path("static")))

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

with open(path('templates/server.html')) as fp:
TEMPLATE = Template(fp.read())


@server.get("/")
async def index():
with open(path('templates/server.html')) as fp:
TEMPLATE = Template(fp.read())

return HTMLResponse(TEMPLATE.render(servers_list=list(SERVERS)))


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


async def ping(name):
try:
queue_in, queue_out = SERVERS[name]
await queue_in.put(dict(type="ping"))
response = await queue_out.get()
assert response['msg'] == 'pong'
return True
except:
return False


@server.websocket("/ws")
async def ws(websocket: WebSocket):
await websocket.accept()
name = await websocket.receive_text()

if name in SERVERS:
await websocket.send_json(dict(type="error", msg="Name is already taken."))
await websocket.close()
return
alive = await ping(name)

if alive:
await websocket.send_json(dict(type="error", msg="Name is already taken."))
await websocket.close()
return

print("Registering new server: ", name)

Expand Down
3 changes: 3 additions & 0 deletions auditorium/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def _do_ws_command(self, command):
if command["type"] == "render":
print("Rendering content")
return dict(content=self.render())
if command["type"] == "ping":
print("Saying hello")
return dict(msg="pong")
elif command["type"] == "error":
print("(!) %s" % command['msg'])
raise websockets.exceptions.ConnectionClosedError(1006, command['msg'])
Expand Down
44 changes: 44 additions & 0 deletions auditorium/static/css/server.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
body {
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";
padding: 0px;
margin: 0px;

font-size: x-large;
}

div.main {
color: white;
background-image: url("/static/img/banner.jpg");
background-size: cover;
text-align: center;
margin: 0px;
}

div.hero {
background-color: rgba(0, 10, 20, 0.8);
padding-top: 250px;
padding-bottom: 250px;
}

div.section {
width: 900px;
margin: auto;
padding: 20px;
}

div.footer {
padding: 20px;
text-align: center;
color: white;
background-color: rgba(0, 10, 20, 0.8);
}

div.footer a {
color: white;
}

a.fork-me {
position: absolute;
right: 0px;
top: 0px;
}
Binary file added auditorium/static/img/banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 28 additions & 9 deletions auditorium/templates/server.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,36 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Auditorium</title>

<link href="https://fonts.googleapis.com/css?family=DM+Sans:300,400,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="static/css/server.css">
</head>
<body>
<h1>Welcome to Auditorium</h1>

<h3>The following slideshows have been registered:</h3>
<ul>
{% for name in servers_list %}
<li>
<a href="/{{ name }}/">{{ name }}</a>
</li>
{% endfor %}
</ul>
<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>

<div class="main">
<div class="hero">

<h1>Auditorium</h1>
<h2>A Python-powered slideshow generator with steroids</h2>

</div>
</div>

<div class="section">
<h3>The following slideshows have been registered:</h3>
<ul>
{% for name in servers_list %}
<li>
<a href="/{{ name }}/">{{ name }}</a>
</li>
{% endfor %}
</ul>
</div>

<div class="footer">
Copyright 2020 - <a href="http://auditorium.apiad.net">auditorium.apiad.net</a>
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions docs/history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# History

### v19.1.5

* Fixed automatic server address for `auditorium publish`.

### v19.1.4

* Added command `auditorium server` that allows to proxy a slideshow through a public server.
Expand Down
47 changes: 43 additions & 4 deletions docs/hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,48 @@ auditorium run [file] --host=0.0.0.0
```
Then give them your public IP address. In Linux, run `ip addr` to see it.

## Hosting freely with `auditorium publish`

If your audience cannot reach you on the local network, or the computer
where the slideshow runs is not the one where you will be presenting, then
you need a way to proxy your slideshow to a public URL.

Enter `auditorium publish`, a command (and related service) that will relay
your slideshow to [auditorium.apiad.net](http://auditorium.apiad.net).
The slideshow still runs on your computer, but it is connected through websockets
with a server that renders the slide and proxies all incoming requests back to your machine.

To use it, simple run:

```bash
auditorium publish [file] --name [your-slideshow-name]
```

Then head over to `http://auditorium.apiad.net/your-slideshow-name/` and enjoy!

> **NOTE:** This service is provided as-is with no guarantees whatsoever. The service runs
> on a development server that is restarted often (at least twice a day), so slideshows are **not** guaranteed to stay
> up for a long time. Don't use this service in mission critical presentations.
If you need finer control then you can host the server yourself on your own infrastructure
and thus ensure that it's online when you need it. Just run:

```bash
auditorium server [--host HOST] [--port PORT]
```

Make sure the server is publicly accessible. You'll probably use some kind of web server,
or `--host 0.0.0.0` and `--port 80` which you can totally do since `auditorium` ships
with `uvicorn` which is a fully fledged production web server.
Then publish to your own address with:

```bash
auditorium publish [file] --name [name] --server [ws://your-server:port] # or wss://
```

## Hosting temporarily through `ngrok`

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

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

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

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

This is actually how we host thed demo at [auditorium-demo.apiad.net](https://auditorium-demo.apiad.net).
This is actually how we host the demo at [auditorium-demo.apiad.net](https://auditorium-demo.apiad.net).
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.

Make sure your `slideshow.py` (or whatever the name) slideshow file has the following line:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "auditorium"
version = "19.1.4"
version = "19.1.5"
description = "A Python-powered slideshow maker with steroids."
authors = ["Alejandro Piad <alepiad@gmail.com>"]
license = "MIT"
Expand Down

0 comments on commit bded3e5

Please sign in to comment.