Interface : 3 SocketManager.js - 17chuchu/AutomaticBicycleInterface GitHub Wiki
This file will manage socket connection with django server. The WebSocket dependency is called ReconnectingWebSocket.
Table of Contents
Handle Action and Activity Code
Handle Action
These are actions that will handle incoming package. In this application, the whole dictionary (dictionary created from a JSON string) will be sent to each function.
static handlelogin = undefined
static handlecheckbike = undefined
static handleaskforvideo = undefined
static handleaskforcontrol = undefined
Acticity Code
These are codes that are used to identify packages and send them to the Handle Action that will handle them.
These codes should be the same as the one in ClientComment.py.
static activitycode = {
default : 0,
login : 1,
checkbike: 2,
askforvideo:3,
givedirection:4,
askforcontrol:5,
visitorlogin:6,
}
You can observe a function called initialize, which will initialize the socket connection and listen to incoming messages.
Other Code
You can also observe a function like this that will do the services such as login, check bike, and others.
This is one example.
static login(email,password)
{
const info = {email : email, password : password} // You can also change it to login with a Username and a Password. Ex: {username : email, password : password}
const data = JSON.stringify(info)
const pack = SocketManager.packMassage(SocketManager.activitycode.login,data) // Bundle the activity code with data and send them.
SocketManager.client.send(pack) // Send package to Django Server.
}