updated examples

Commit 18058f0 · patx · 2025-01-28T16:59:02-05:00

Changeset
18058f09fb1f3a3872f027fdb6b3ffe27b625a8e
Parents
618dda20d5a72881f7dc7caa599e5fe4db54534c

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/MicroPie.py b/MicroPie.py
index 8b4e192..a46d47b 100644
--- a/MicroPie.py
+++ b/MicroPie.py
@@ -30,7 +30,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """
-import asyncio
 import inspect
 import mimetypes
 import os
@@ -42,6 +41,7 @@ import uuid
 try:
     from jinja2 import Environment, FileSystemLoader
     JINJA_INSTALLED = True
+    import asyncio
 except ImportError:
     JINJA_INSTALLED = False
 
diff --git a/examples/hello_world/app.py b/examples/hello_world/app.py
index 1ded149..61a9a4b 100644
--- a/examples/hello_world/app.py
+++ b/examples/hello_world/app.py
@@ -3,7 +3,7 @@ from MicroPie import Server
 
 class Root(Server):
 
-    def index(self, name=None):
+    async def index(self, name=None):
         if name:
             return f'Hello {name}'
         return 'Hello ASGI World!'
diff --git a/examples/socketio/chatroom.py b/examples/socketio/chatroom.py
index da59e21..eca009c 100644
--- a/examples/socketio/chatroom.py
+++ b/examples/socketio/chatroom.py
@@ -56,5 +56,5 @@ async def message(sid, data):
 
 
 # Attach Socket.IO to the ASGI app
-app = MyApp()
-asgi_app = socketio.ASGIApp(sio, app)
+asgi_app = MyApp()
+app = socketio.ASGIApp(sio, app)
diff --git a/examples/socketio/webcam.py b/examples/socketio/webcam.py
index 8cb7078..dca2eba 100644
--- a/examples/socketio/webcam.py
+++ b/examples/socketio/webcam.py
@@ -60,5 +60,5 @@ async def leave_room(sid, data):
         print(f"{sid} left room for {username}")
 
 # Attach the Socket.IO server to the ASGI app
-app = MyApp()
-asgi_app = socketio.ASGIApp(sio, app)
+asgi_app = MyApp()
+app = socketio.ASGIApp(sio, app)
diff --git a/examples/streaming/templates/index.html b/examples/streaming/templates/index.html
deleted file mode 100644
index b710858..0000000
--- a/examples/streaming/templates/index.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Webcam Streaming</title>
-</head>
-<body>
-    <h1>Webcam Streaming App</h1>
-    <form method="post" action="/submit">
-        <input type="text" name="username" placeholder="Enter username" required>
-        <button type="submit" name="action" value="Start Streaming">Start Streaming</button>
-        <button type="submit" name="action" value="Watch Stream">Watch Stream</button>
-    </form>
-</body>
-</html>
-
diff --git a/examples/streaming/templates/stream.html b/examples/streaming/templates/stream.html
deleted file mode 100644
index a8a5e0c..0000000
--- a/examples/streaming/templates/stream.html
+++ /dev/null
@@ -1,36 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Streaming: {{ username }}</title>
-    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script>
-</head>
-<body>
-    <h1>Streaming as {{ username }}</h1>
-    <video id="webcam" autoplay playsinline></video>
-
-    <script>
-        const socket = io();
-        const username = "{{ username }}";
-        socket.emit('join', { username: username });
-
-        async function startWebcam() {
-            const stream = await navigator.mediaDevices.getUserMedia({ video: true });
-            document.getElementById('webcam').srcObject = stream;
-
-            const canvas = document.createElement('canvas');
-            const context = canvas.getContext('2d');
-
-            setInterval(() => {
-                context.drawImage(document.getElementById('webcam'), 0, 0, canvas.width, canvas.height);
-                let frame = canvas.toDataURL('image/webp');
-                socket.emit('stream', { username: username, frame: frame });
-            }, 100);
-        }
-
-        startWebcam();
-    </script>
-</body>
-</html>
-
diff --git a/examples/streaming/templates/watch.html b/examples/streaming/templates/watch.html
deleted file mode 100644
index 3cf8f2a..0000000
--- a/examples/streaming/templates/watch.html
+++ /dev/null
@@ -1,24 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Watching: {{ username }}</title>
-    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script>
-</head>
-<body>
-    <h1>Watching Stream of {{ username }}</h1>
-    <img id="videoFeed" style="width: 100%; max-width: 800px;">
-
-    <script>
-        const socket = io();
-        const username = "{{ username }}";
-        socket.emit('join', { username: username });
-
-        socket.on('broadcast', (data) => {
-            document.getElementById('videoFeed').src = data.frame;
-        });
-    </script>
-</body>
-</html>
-