Implement interface for using web plotter from C++

It's not actually usable yet due to ODR violations created by
abseil being compiled into libwebrtc_full.a, but it does work based
on testing I've done with using websockets for data transfer.

Change-Id: I574570c7b5c85df9e53321bfb971a608d20b9803
diff --git a/aos/network/BUILD b/aos/network/BUILD
index bf2cb00..6053260 100644
--- a/aos/network/BUILD
+++ b/aos/network/BUILD
@@ -389,11 +389,11 @@
     hdrs = ["web_proxy.h"],
     copts = [
         "-DWEBRTC_POSIX",
-        "-Wno-unused-parameter",
     ],
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":connect_fbs",
+        ":gen_embedded",
         ":web_proxy_fbs",
         ":web_proxy_utils",
         "//aos/events:shm_event_loop",
@@ -419,7 +419,6 @@
     srcs = ["web_proxy_main.cc"],
     copts = [
         "-DWEBRTC_POSIX",
-        "-Wno-unused-parameter",
     ],
     data = [
         "//aos/network/www:files",
@@ -428,12 +427,9 @@
     ],
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
-        ":gen_embedded",
         ":web_proxy",
         "//aos:init",
         "//aos/events:shm_event_loop",
-        "//aos/seasocks:seasocks_logger",
-        "//third_party/seasocks",
         "@com_github_google_flatbuffers//:flatbuffers",
     ],
 )
@@ -446,16 +442,12 @@
     ],
     copts = [
         "-DWEBRTC_POSIX",
-        "-Wno-unused-parameter",
     ],
     deps = [
-        ":gen_embedded",
         ":web_proxy",
         "//aos:init",
         "//aos/events:simulated_event_loop",
         "//aos/events/logging:logger",
-        "//aos/seasocks:seasocks_logger",
-        "//third_party/seasocks",
         "@com_github_google_flatbuffers//:flatbuffers",
     ],
 )
diff --git a/aos/network/log_web_proxy_main.cc b/aos/network/log_web_proxy_main.cc
index dda9ae4..1942c57 100644
--- a/aos/network/log_web_proxy_main.cc
+++ b/aos/network/log_web_proxy_main.cc
@@ -9,21 +9,14 @@
 #include "aos/flatbuffer_merge.h"
 #include "aos/init.h"
 #include "aos/network/web_proxy.h"
-#include "aos/seasocks/seasocks_logger.h"
 #include "gflags/gflags.h"
 
-#include "internal/Embedded.h"
-#include "seasocks/Server.h"
-#include "seasocks/WebSocket.h"
-
 DEFINE_string(data_dir, "www", "Directory to serve data files from");
 DEFINE_string(node, "", "Directory to serve data files from");
 DEFINE_int32(buffer_size, -1, "-1 if infinite, in # of messages / channel.");
 
 int main(int argc, char **argv) {
   aos::InitGoogle(&argc, &argv);
-  // Make sure to reference this to force the linker to include it.
-  findEmbeddedContent("");
 
   const std::vector<std::string> unsorted_logfiles =
       aos::logger::FindLogs(argc, argv);
diff --git a/aos/network/web_proxy.cc b/aos/network/web_proxy.cc
index af1b646..5902d30 100644
--- a/aos/network/web_proxy.cc
+++ b/aos/network/web_proxy.cc
@@ -7,6 +7,7 @@
 #include "aos/seasocks/seasocks_logger.h"
 #include "api/create_peerconnection_factory.h"
 #include "glog/logging.h"
+#include "internal/Embedded.h"
 
 namespace aos {
 namespace web_proxy {
@@ -22,7 +23,7 @@
     return new rtc::RefCountedObject<DummySetSessionDescriptionObserver>();
   }
   virtual void OnSuccess() {}
-  virtual void OnFailure(webrtc::RTCError error) {}
+  virtual void OnFailure(webrtc::RTCError /*error*/) {}
 };
 
 }  // namespace
@@ -32,6 +33,8 @@
     : server_(server),
       config_(aos::CopyFlatBuffer(event_loop->configuration())),
       event_loop_(event_loop) {
+  // We need to reference findEmbeddedContent() to make the linker happy...
+  findEmbeddedContent("");
   const aos::Node *self = event_loop->node();
 
   for (uint i = 0; i < event_loop->configuration()->channels()->size(); ++i) {
@@ -276,11 +279,14 @@
 // Function called for web socket data. Parses the flatbuffer and
 // handles it appropriately.
 void Connection::HandleWebSocketData(const uint8_t *data, size_t size) {
-  const WebSocketMessage *message =
-      flatbuffers::GetRoot<WebSocketMessage>(data);
-  switch (message->payload_type()) {
+  const FlatbufferSpan<WebSocketMessage> message({data, size});
+  if (!message.Verify()) {
+    LOG(ERROR) << "Invalid WebsocketMessage received from browser.";
+    return;
+  }
+  switch (message.message().payload_type()) {
     case Payload::WebSocketSdp: {
-      const WebSocketSdp *offer = message->payload_as_WebSocketSdp();
+      const WebSocketSdp *offer = message.message().payload_as_WebSocketSdp();
       if (offer->type() != SdpType::OFFER) {
         LOG(WARNING) << "Got the wrong sdp type from client";
         break;
@@ -325,7 +331,7 @@
       break;
     }
     case Payload::WebSocketIce: {
-      const WebSocketIce *ice = message->payload_as_WebSocketIce();
+      const WebSocketIce *ice = message.message().payload_as_WebSocketIce();
       std::string candidate = ice->candidate()->str();
       std::string sdpMid = ice->sdpMid()->str();
       int sdpMLineIndex = ice->sdpMLineIndex();
diff --git a/aos/network/web_proxy.h b/aos/network/web_proxy.h
index ab524de..e6d47c4 100644
--- a/aos/network/web_proxy.h
+++ b/aos/network/web_proxy.h
@@ -178,7 +178,7 @@
       rtc::scoped_refptr<webrtc::DataChannelInterface> channel) override;
   void OnRenegotiationNeeded() override {}
   void OnIceConnectionChange(
-      webrtc::PeerConnectionInterface::IceConnectionState state) override {}
+      webrtc::PeerConnectionInterface::IceConnectionState /*state*/) override {}
   void OnIceGatheringChange(
       webrtc::PeerConnectionInterface::IceGatheringState) override {}
   void OnIceCandidate(const webrtc::IceCandidateInterface *candidate) override;
@@ -186,7 +186,7 @@
 
   // CreateSessionDescriptionObserver implementation
   void OnSuccess(webrtc::SessionDescriptionInterface *desc) override;
-  void OnFailure(webrtc::RTCError error) override {}
+  void OnFailure(webrtc::RTCError /*error*/) override {}
   // CreateSessionDescriptionObserver is a refcounted object
   void AddRef() const override {}
   // We handle ownership with a unique_ptr so don't worry about actually
@@ -198,7 +198,7 @@
   // DataChannelObserver implementation
   void OnStateChange() override;
   void OnMessage(const webrtc::DataBuffer &buffer) override;
-  void OnBufferedAmountChange(uint64_t sent_data_size) override {}
+  void OnBufferedAmountChange(uint64_t /*sent_data_size*/) override {}
 
  private:
   ::seasocks::WebSocket *sock_;
diff --git a/aos/network/web_proxy_main.cc b/aos/network/web_proxy_main.cc
index ddab5dc..06fe942 100644
--- a/aos/network/web_proxy_main.cc
+++ b/aos/network/web_proxy_main.cc
@@ -2,21 +2,14 @@
 #include "aos/flatbuffer_merge.h"
 #include "aos/init.h"
 #include "aos/network/web_proxy.h"
-#include "aos/seasocks/seasocks_logger.h"
 #include "gflags/gflags.h"
 
-#include "internal/Embedded.h"
-#include "seasocks/Server.h"
-#include "seasocks/WebSocket.h"
-
 DEFINE_string(config, "./config.json", "File path of aos configuration");
 DEFINE_string(data_dir, "www", "Directory to serve data files from");
 DEFINE_int32(buffer_size, 0, "-1 if infinite, in # of messages / channel.");
 
 int main(int argc, char **argv) {
   aos::InitGoogle(&argc, &argv);
-  // Make sure to reference this to force the linker to include it.
-  findEmbeddedContent("");
 
   aos::FlatbufferDetachedBuffer<aos::Configuration> config =
       aos::configuration::ReadConfig(FLAGS_config);