You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
I am using FastAPI with socketIO and using socket emit(Javascript) for sending client button "onclick" event to server which listens to this event and then emits some data after calculation. This works perfectly fine on laptop browser, however when I tested upon mobile browser(Chrome), the button click does not work. I tested on mobile browser with a simple Javascript alert after removing the emit function and it works. So it appears like, the issue is with socket emit.
Here is my Server Code:
from fastapi import FastAPI, Request
import json
from fastapi_socketio import SocketManager
import uvicorn
import time
import subprocess
import asyncio
from fastapi.templating import Jinja2Templates
from fastapi.responses import HTMLResponse
import socketio
from fastapi.staticfiles import StaticFiles
app = FastAPI()
sio = socketio.AsyncServer(cors_allowed_origins='*', async_mode='asgi')
socketio_app = socketio.ASGIApp(sio, app)
templates = Jinja2Templates(directory="templates")
app.mount("/static", StaticFiles(directory="static"), name="static")
@sio.on('my_event')
async def servermessage(data):
data = asyncio.create_task(ssh())
while True:
if data.done():
value = data.result()
await sio.emit('response',"SSH Status:" + " " + value)
break
else:
await sio.emit('response', "SSH Status:" + " " + "Please Wait..")
async def ssh():
cmd1 = 'systemctl status sshd| grep Active | awk -F " " \'{print$2}\''
listing1 = subprocess.run(cmd1,stdout=subprocess.PIPE,shell=True,universal_newlines=True)
result = listing1.stdout
await asyncio.sleep(8)
return result
@app.get("/", response_class=HTMLResponse)
async def main(request: Request):
return templates.TemplateResponse("base.html", {"request":request})
Hello,
I am using FastAPI with socketIO and using socket emit(Javascript) for sending client button "onclick" event to server which listens to this event and then emits some data after calculation. This works perfectly fine on laptop browser, however when I tested upon mobile browser(Chrome), the button click does not work. I tested on mobile browser with a simple Javascript alert after removing the emit function and it works. So it appears like, the issue is with socket emit.
Here is my Server Code:
Here is my Javascript
The text was updated successfully, but these errors were encountered: