Guest User

Untitled

a guest
Apr 27th, 2024
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. # When we grab a WebRTC offer from out browser client for single camera.
  2. @app.route('/rtcoffer/<cam>', methods=['GET', 'POST'])
  3. @login_required
  4. def webRTCOFFER(cam):
  5. thisUUID = str(uuid.uuid4()) # Generate a UUID for this session.
  6.  
  7. # Get current user (Static currently)
  8. thisUser = current_user.username
  9.  
  10. global webRTCThread
  11.  
  12. # Get Docker IP
  13. # Get Name's Docker IP with username and password
  14. myCursor.execute("Select dockerIP from localcameras where name='{0}'".format(cam))
  15. dockerIP = myCursor.fetchone()
  16. dockerIPString = ''.join(dockerIP)
  17.  
  18. # Always create a new event loop for this session.
  19. rtcloop = asyncio.new_event_loop()
  20.  
  21. # Add generated info to userUUIDAssociation
  22. # UUID, user[0], pingtime[1], rtcloopObject[2], userInTrackControl[3], camName[4], rtcPeer[5], microphoneStreamFuture[6] (6 appended)
  23. # MODIFY SO 5 BECOMES the WEBRTC PEER and 6 is MICROPHONE
  24. userUUIDAssociations[thisUUID] = [thisUser, 0, rtcloop, False, cam]
  25.  
  26. # Get SDP from client and set set objects
  27. parsedSDP = userUUIDAssociations[thisUUID][2].run_until_complete(singleWebRtcStart(thisUUID, dockerIPString, cam, request))
  28.  
  29. # Continue running that loop forever to keep AioRTC Objects In Memory Executing, while shifting it to
  30. # Another thread so we don't block the code.
  31. webRTCThread = Thread(target=userUUIDAssociations[thisUUID][2].run_forever)
  32. webRTCThread.start()
  33.  
  34. print("Creating watchdog task")
  35. # # asyncio.run(startWatchdog(thisUUID))
  36. rtcWatchDogThread = Thread(target=asyncio.run, args=(startWatchdog(thisUUID), ))
  37. rtcWatchDogThread.start()
  38. print("Watchdog task created")
  39.  
  40. # Return Our Parsed SDP to the client
  41. return parsedSDP.encode()
Advertisement
Add Comment
Please, Sign In to add comment