Whenever a change occurs to Forklifts, Routes or Warehouse, it'll be broadcast to any socket connected to /subscribe
When a forklift starts up, it should establish and maintain a connection to this socket to receive routes, and transmit feedback.
JSON:
{
type: PackageTypesEnum, // The packagetype, used for identifying the body.
body: {
// Object
}
}enum PackageTypes {
route = "route", // A single instance of Route
routes = "routes", // An array of instances of Route
forkliftInfo = "forkliftInfo", // A single instance of ForkliftInfo
forkliftInfos = "forkliftInfos", // ...
order = "order",
orders = "orders",
warehouse = "warehouse",
json = "json", // A body of valid json, but invalid type
other = "other" // A body of something other than json
}Note: json and other are strictly for error-handling, and should not be used as package types when transmitting.
Examples include how to send objects using WebSocket, as well as the plain-text that is sent.
let webSocket = new WebSocket(new ws("ws://localhost:3000/forkifts/{forkliftId}/init"));
webSocket.sendForkliftInfo(forkliftInfo);webSocket.on(WebSocket.packageTypes.forkliftInfo, (forkliftInfo) => {
// This is called whenever a package of type 'forkliftInfo' is received.
console.log(forkliftInfo);
}){
type: "forkliftInfo",
body: JSON.stringify(forkliftInfo)
}