Skip to content

"Connecting over 4G" is not working using "https://rtcbot.dev" #38

@marakhi

Description

@marakhi

Hello @dkumor,

I was able to run all the program in tutorial till "Connecting over 4G" section on local network. For "Connecting over 4G" section I choose to use server you create which is "https://rtcbot.dev" but it is not working(Says no active connection). I have a feeling that I missing something here. I have laptop with Ubuntu OS and RTCBOT installed on it. I am running server side of the code on this laptop and it is connected to my home wifi. I have Raspberry PI with RTCBOT installed and connected to cellular 5G hotspot. I am running my Remote/Robot side of the code here on Raspberry Pi. I have also tested to see if my cellular network provider allow me to stream by running server and Remote/Robot code on local network using 5G data. Please see below my Server side and Remote/Robot side codes. "Connecting over 4G" section running fine on my local network be it my home wifi or 5G hotspot.

=============SERVER CODE ========================

from aiohttp import web
routes = web.RouteTableDef()

from rtcbot import Websocket, getRTCBotJS

# Serve the RTCBot javascript library at /rtcbot.js
@routes.get("/rtcbot.js")
async def rtcbotjs(request):
    return web.Response(content_type="application/javascript", text=getRTCBotJS())

@routes.get("/")
async def index(request):
    return web.Response(
        content_type="text/html",
        text="""
    <html>
        <head>
            <title>RTCBot: Remote Video</title>
            <script src="/rtcbot.js"></script>
        </head>
        <body style="text-align: center;padding-top: 30px;">
            <video autoplay playsinline muted controls></video>
            <p>
            Open the browser's developer tools to see console messages (CTRL+SHIFT+C)
            </p>
            <script>
                var conn = new rtcbot.RTCConnection();

                conn.video.subscribe(function(stream) {
                    document.querySelector("video").srcObject = stream;
                });

                async function connect() {
                    let offer = await conn.getLocalDescription();

                    // POST the information to /connect
                    let response = await fetch("https://rtcbot.dev/Marakhi123", {
                        method: "POST",
                        cache: "no-cache",
                        body: JSON.stringify(offer)
                    });

                    await conn.setRemoteDescription(await response.json());

                    console.log("Ready!");
                }
                connect();

            </script>
        </body>
    </html>
    """)

async def cleanup(app=None):
    global ws
    if ws is not None:
        c = ws.close()
        if c is not None:
            await c

app = web.Application()
app.add_routes(routes)
app.on_shutdown.append(cleanup)
web.run_app(app)  

================Remote Code==================

import asyncio
from rtcbot import Websocket, RTCConnection, PiCamera

cam = PiCamera()
conn = RTCConnection()
conn.video.putSubscription(cam)

# Connect establishes a websocket connection to the server,
# and uses it to send and receive info to establish webRTC connection.
async def connect():
    ws = Websocket("https://rtcbot.dev/Marakhi123")
    remoteDescription = await ws.get()
    robotDescription = await conn.getLocalDescription(remoteDescription)
    ws.put_nowait(robotDescription)
    print("Started WebRTC")
    await ws.close()


asyncio.ensure_future(connect())
try:
    asyncio.get_event_loop().run_forever()
finally:
    cam.close()
    conn.close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions