At a high-level, this backend intends to create a server, instantiate websockets, and then use those websockets to send data in the form of a JSON-RPC object between the server and the client.
The data that is sent to the client from the server comes from buoys in the pacific ocean. They are intended to supply the information that will allow for Surfline's rating system to rate the current surf conditions at your favorite surf spot.
This backend serves the following purposes.
The server allows for the instantiation of a new server, the creation of an 'inBuoy' websocket and a 'outBuoy' websocket for sending jsonrpc objects that contain buoys data and subsequently receiving jsonrpc response objects that notify the server that the objects have been received properly.
The storage file allows for buoys to be stored using indivual methods like 'addBuoy', 'updateBuoyData', and'subscribeToBuoys'.
- addBuoy stores buoys objects
- updateBuoyData adds new information, including swell height and period to the added buoys.
- subscribeToBuoys allows for the addition of buoys within the map bounds
The index file is used to create the new server which will allow for the websockets to active and send data to the front end once it's receieved from the buoys.
The JSON_RPC file builds all methods through which these objecst will be sent and recieved.
- Build Request buils a JSONRPC request
- Build Response builds the 'ok' response from a sucessfully requested JSON RPC object
Here is an example of that request, response exchange...
- Create all methods through which JSON-RPC objects will be sent
- JSON-RPC Request
{
"jsonrpc": "2.0",
"method": "addBuoy",
"params": {
"name": "SAN PEDRO",
"lat": 33.618,
"lon": -118.317
},
"id": "3f052f4f-2f4a-46d8-aee7-fb6639942795"
}
- JSON-RPC Response
{
"jsonrpc": "2.0",
"result": "ok",
"id": "3f052f4f-2f4a-46d8-aee7-fb6639942795"
}
- Build Notification builds the buoy update notification for incoming new buoy data
- Build Error, builds all of the potential JSON RPC response errors (invalid JSON, request object, method etc.)
The test directory was used to for the follwing purposes.
- Test the exchange of json-rpc objects, request and response.
- Testing that a client was active and capable of being sent messages
- Test server for sending all of the aforementioned steps\
In order run the app take the following steps..
- In the command line, within the 'buoy_app' directory, run 'node index.js'
- In your web browser open the project test page (https://www.surfline.com/careers/engineers/take-home-projects/buoys-tests/start.html#)
- Enter ws://localhost:8080/inBuoy into the host field
- Click the connect button.
- Clone down the code within the front end repository (https://github.com/jackgrossman18/Surfline-Project-Frontend)
- Navigate to the surflinebuoys directory
- Run npm install, then npm run start
- Go back to the project tests webpage, then run tests
- Navigate back to the webmap that should have opened automatically within your browser.
- You should see styled buoys, click on them to access the current conditions