-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHostProtocolBridge.cpp
More file actions
30 lines (26 loc) · 1.07 KB
/
Copy pathHostProtocolBridge.cpp
File metadata and controls
30 lines (26 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "HostProtocolBridge.h"
#include <type_traits>
std::optional<HostDispatchResult> DispatchHostInboundMessageJson(
const std::wstring& jsonText,
const ClientCallbackRegistry& callbacks) {
// Parse the raw WebView2 JSON payload into a typed message before touching app logic.
const auto message = ParseHostInboundMessageJson(jsonText);
if (!message.has_value()) {
return std::nullopt;
}
HostDispatchResult result;
std::visit([&](const auto& payload) {
using T = std::decay_t<decltype(payload)>;
if constexpr (std::is_same_v<T, PageReadyMessage>) {
result.isPageReady = true;
}
else if constexpr (std::is_same_v<T, QuestionMessage>) {
// Question ids are the bridge contract between the page/server and native callback registry.
const auto answerText = callbacks.Invoke(payload.id);
if (answerText.has_value()) {
result.answer = AnswerMessage{ payload.id, answerText.value() };
}
}
}, message.value());
return result;
}