Server : 4 MeansManager - 17chuchu/AutomaticBicycleInterface GitHub Wiki
Table of Contents
MeansManager.py
MeansManager is a child class of WebSocket. It is used to connect to Means application that is used to direct the video stream from a bike to multiple clients. MeansManager is located in server/ServerApplication/component/MeansManager.py
Initializing
Run a Thread that will keep this class running. This code is located at server/ServerApplication/urls.py
.
MeansManager.initManager() #line 20
Port
MeansManager is a web socket server so it needs a port. You can customize its port number here.
meansport = 7100. #line 27
Register New Room
This function will register 2 rooms, one for a bike and one for a client. Then it will also send a JSON string package to Means application.
@staticmethod #line 89
def registerNewRoom(bikeid):
try:
if(MeansManager.currentmeans != None): #If the Means React app is connected.
bikeroomid = str(uuid.uuid4()).replace('-','') #Generate room id for a bike.
clientroomid = str(uuid.uuid4()).replace('-','') #Generate room id for a client.
data = dict() #Generate a package to be sent to a React app that will manage the video stream.
data['bikeroomid'] = bikeroomid
data['clientroomid'] = clientroomid
info = json.dumps(MeansComment.generateComment('registerNewRoom',data))
MeansManager.currentmeans.sendMessage(info)
BicycleManager.bicycleroom[bikeid] = bikeroomid #Send room id to BicycleManager
ClientManager.clientroom[bikeid] = clientroomid #Send room id to ClientManager
except Exception as e:
print("Message error is : " + e)
MeansComment.py
MeansComment is a class that provides a template to create packages of information to be sent to the Means React web application. MeansComment.py is located in server/ServerApplication/component/Comment/MeansComment.py
@staticmethod #line 7
def generateComment(topic, comment):
data = dict()
data['topic'] = topic. #Topic (String) that will define what function will take care of this pacakage such as 'registerNewRoom'
data['comment'] = comment #Data (String or Dictionary) that is needed to be sent such as room ids.
return data