Skip to content

Commit

Permalink
Fix websocket and use DynamicController instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Dec 4, 2023
1 parent 9ca1403 commit c4d3a2c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
21 changes: 21 additions & 0 deletions backend/src/controllers/DynamicController.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include <drogon/HttpController.h>

class DynamicController : public drogon::HttpController<DynamicController>
{
public:
METHOD_LIST_BEGIN
ADD_METHOD_TO(DynamicController::load, "/room/{1}", drogon::Get);
METHOD_LIST_END
void load(const drogon::HttpRequestPtr& req,
std::function<void(const drogon::HttpResponsePtr&)>&& callback,
std::string&& room_name);
};

void DynamicController::load(const drogon::HttpRequestPtr& req,
std::function<void(const drogon::HttpResponsePtr&)>&& callback,
std::string&& arg1)
{
// The 'room' page is dynamically generated locally, so we don't have a specific file to serve.
callback(drogon::HttpResponse::newFileResponse(drogon::app().getDocumentRoot() + "/dynamic.html"));
}
24 changes: 0 additions & 24 deletions backend/src/controllers/Room.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion backend/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <drogon/HttpAppFramework.h>

// Controllers must be included before main
#include "controllers/Room.hpp"
#include "controllers/DynamicController.hpp"
#include "controllers/WebSocketChat.hpp"

int main()
Expand Down
4 changes: 2 additions & 2 deletions raspberry_pi/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ std::string get_websocket_url()
std::optional<int> maybe_port = GET_CONFIG_VALUE(port);
if (maybe_port.has_value())
{
return "ws://" + GET_CONFIG_VALUE(host) + ":" + std::to_string(maybe_port.value()) + "/room?room_name=" + GET_CONFIG_VALUE(code);
return "ws://" + GET_CONFIG_VALUE(host) + ":" + std::to_string(maybe_port.value()) + "/ws/room?room_name=" + GET_CONFIG_VALUE(code);
}
return "ws://" + GET_CONFIG_VALUE(host) + "/room/" + GET_CONFIG_VALUE(code);
return "ws://" + GET_CONFIG_VALUE(host) + "/ws/room?room_name=" + GET_CONFIG_VALUE(code);
}

// Car is a global variable so that car.terminate() can be called on exit
Expand Down

0 comments on commit c4d3a2c

Please sign in to comment.