refactor: Rename WebRTC signaling functions and update deployment script for debug version

This commit is contained in:
Adam Shiervani 2025-04-08 14:59:20 +02:00 committed by Siyuan Miao
parent c1aa96c69c
commit 3c973ed272
4 changed files with 12 additions and 11 deletions

View File

@ -272,7 +272,7 @@ func runWebsocketClient() error {
// set the metrics when we successfully connect to the cloud. // set the metrics when we successfully connect to the cloud.
cloudResetMetrics(true) cloudResetMetrics(true)
return handleWebRTCSignalWsConnection(c, true) return handleWebRTCSignalWsMessages(c, true)
} }
func authenticateSession(ctx context.Context, c *websocket.Conn, req WebRTCSessionRequest) error { func authenticateSession(ctx context.Context, c *websocket.Conn, req WebRTCSessionRequest) error {

View File

@ -67,10 +67,10 @@ make build_dev
cd bin cd bin
# Kill any existing instances of the application # Kill any existing instances of the application
ssh "${REMOTE_USER}@${REMOTE_HOST}" "killall jetkvm_app || true" ssh "${REMOTE_USER}@${REMOTE_HOST}" "killall jetkvm_app_debug || true"
# Copy the binary to the remote host # Copy the binary to the remote host
cat jetkvm_app | ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > $REMOTE_PATH/jetkvm_app" cat jetkvm_app | ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > $REMOTE_PATH/jetkvm_app_debug"
# Deploy and run the application on the remote host # Deploy and run the application on the remote host
ssh "${REMOTE_USER}@${REMOTE_HOST}" ash <<EOF ssh "${REMOTE_USER}@${REMOTE_HOST}" ash <<EOF
@ -81,16 +81,16 @@ export LD_LIBRARY_PATH=/oem/usr/lib:\$LD_LIBRARY_PATH
# Kill any existing instances of the application # Kill any existing instances of the application
killall jetkvm_app || true killall jetkvm_app || true
killall jetkvm_app || true killall jetkvm_app_debug || true
# Navigate to the directory where the binary will be stored # Navigate to the directory where the binary will be stored
cd "$REMOTE_PATH" cd "$REMOTE_PATH"
# Make the new binary executable # Make the new binary executable
chmod +x jetkvm_app chmod +x jetkvm_app_debug
# Run the application in the background # Run the application in the background
PION_LOG_TRACE=jetkvm,cloud ./jetkvm_app PION_LOG_TRACE=jetkvm,cloud ./jetkvm_app_debug
EOF EOF
echo "Deployment complete." echo "Deployment complete."

View File

@ -232,9 +232,10 @@ export default function KvmIdRoute() {
const isSettingRemoteAnswerPending = useRef(false); const isSettingRemoteAnswerPending = useRef(false);
const makingOffer = useRef(false); const makingOffer = useRef(false);
console.log("isondevice", isOnDevice);
const { sendMessage } = useWebSocket( const { sendMessage } = useWebSocket(
isOnDevice isOnDevice
? `ws://192.168.1.77/webrtc/signaling` ? `ws://${window.location.host}/webrtc/signaling`
: `${CLOUD_API.replace("http", "ws")}/webrtc/signaling?id=${params.id}`, : `${CLOUD_API.replace("http", "ws")}/webrtc/signaling?id=${params.id}`,
{ {
heartbeat: true, heartbeat: true,

8
web.go
View File

@ -93,12 +93,12 @@ func setupRouter() *gin.Engine {
// A Prometheus metrics endpoint. // A Prometheus metrics endpoint.
r.GET("/metrics", gin.WrapH(promhttp.Handler())) r.GET("/metrics", gin.WrapH(promhttp.Handler()))
r.GET("/webrtc/signaling", handleWebRTCSignal)
// Protected routes (allows both password and noPassword modes) // Protected routes (allows both password and noPassword modes)
protected := r.Group("/") protected := r.Group("/")
protected.Use(protectedMiddleware()) protected.Use(protectedMiddleware())
{ {
protected.GET("/webrtc/signaling", handLocalWebRTCSignal)
protected.POST("/webrtc/session", handleWebRTCSession) protected.POST("/webrtc/session", handleWebRTCSession)
protected.POST("/cloud/register", handleCloudRegister) protected.POST("/cloud/register", handleCloudRegister)
protected.GET("/cloud/state", handleCloudState) protected.GET("/cloud/state", handleCloudState)
@ -126,7 +126,7 @@ func setupRouter() *gin.Engine {
// TODO: support multiple sessions? // TODO: support multiple sessions?
var currentSession *Session var currentSession *Session
func handleWebRTCSignal(c *gin.Context) { func handLocalWebRTCSignal(c *gin.Context) {
cloudLogger.Infof("new websocket connection established") cloudLogger.Infof("new websocket connection established")
// Create WebSocket options with InsecureSkipVerify to bypass origin check // Create WebSocket options with InsecureSkipVerify to bypass origin check
wsOptions := &websocket.AcceptOptions{ wsOptions := &websocket.AcceptOptions{
@ -141,14 +141,14 @@ func handleWebRTCSignal(c *gin.Context) {
// Now use conn for websocket operations // Now use conn for websocket operations
defer wsCon.Close(websocket.StatusNormalClosure, "") defer wsCon.Close(websocket.StatusNormalClosure, "")
err = handleWebRTCSignalWsConnection(wsCon, false) err = handleWebRTCSignalWsMessages(wsCon, false)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
} }
func handleWebRTCSignalWsConnection(wsCon *websocket.Conn, isCloudConnection bool) error { func handleWebRTCSignalWsMessages(wsCon *websocket.Conn, isCloudConnection bool) error {
runCtx, cancelRun := context.WithCancel(context.Background()) runCtx, cancelRun := context.WithCancel(context.Background())
defer cancelRun() defer cancelRun()