From 612c71aa25a76b603ad1184a352f228817d1f820 Mon Sep 17 00:00:00 2001 From: Luciano Iam Date: Tue, 14 Apr 2020 22:54:41 +0200 Subject: WebSockets: allow serving SVG files using libwebsockets < 3 --- libs/surfaces/websockets/server.cc | 21 ++++++++++++++++----- libs/surfaces/websockets/server.h | 13 ++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) (limited to 'libs/surfaces/websockets') diff --git a/libs/surfaces/websockets/server.cc b/libs/surfaces/websockets/server.cc index 62d56f437c..7f52b261de 100644 --- a/libs/surfaces/websockets/server.cc +++ b/libs/surfaces/websockets/server.cc @@ -57,20 +57,22 @@ WebsocketsServer::WebsocketsServer (ArdourSurface::ArdourWebsockets& surface) #if LWS_LIBRARY_VERSION_MAJOR >= 3 proto.tx_packet_size = 0; #endif + _lws_proto[0] = proto; memset (&_lws_proto[1], 0, sizeof (lws_protocols)); - // '/' is served by a static index.html file in the surface data directory - // inside it there is a 'builtin' subdirectory that contains all built-in - // surfaces so there is no need to create a dedicated mount point for them - // list of surfaces is available as a dynamically generated json file + /* '/' is served by a static index.html file in the surface data directory + * inside it there is a 'builtin' subdirectory that contains all built-in + * surfaces so there is no need to create a dedicated mount point for them + * list of surfaces is available as a dynamically generated json file + */ memset (&_lws_mnt_index, 0, sizeof (lws_http_mount)); _lws_mnt_index.mountpoint = "/"; _lws_mnt_index.mountpoint_len = strlen (_lws_mnt_index.mountpoint); _lws_mnt_index.origin_protocol = LWSMPRO_FILE; _lws_mnt_index.origin = _resources.index_dir ().c_str (); - // user defined surfaces in the user config directory + /* user defined surfaces in the user config directory */ memset (&_lws_mnt_user, 0, sizeof (lws_http_mount)); _lws_mnt_user.mountpoint = "/user"; _lws_mnt_user.mountpoint_len = strlen (_lws_mnt_user.mountpoint); @@ -86,6 +88,15 @@ WebsocketsServer::WebsocketsServer (ArdourSurface::ArdourWebsockets& surface) _lws_info.uid = -1; _lws_info.gid = -1; _lws_info.user = this; + +#if LWS_LIBRARY_VERSION_MAJOR < 3 + /* older libwebsockets does not define mime type for svg files */ + memset (&_lws_vhost_opt, 0, sizeof (lws_protocol_vhost_options)); + _lws_vhost_opt.name = ".svg"; + _lws_vhost_opt.value = "image/svg+xml"; + _lws_mnt_index.extra_mimetypes = &_lws_vhost_opt; + _lws_mnt_user.extra_mimetypes = &_lws_vhost_opt; +#endif } int diff --git a/libs/surfaces/websockets/server.h b/libs/surfaces/websockets/server.h index c849b29ad9..677ef21780 100644 --- a/libs/surfaces/websockets/server.h +++ b/libs/surfaces/websockets/server.h @@ -62,11 +62,14 @@ public: void update_all_clients (const NodeState&, bool); private: - struct lws_protocols _lws_proto[2]; - struct lws_http_mount _lws_mnt_index; - struct lws_http_mount _lws_mnt_user; - struct lws_context_creation_info _lws_info; - struct lws_context* _lws_context; +#if LWS_LIBRARY_VERSION_MAJOR < 3 + struct lws_protocol_vhost_options _lws_vhost_opt; +#endif + struct lws_protocols _lws_proto[2]; + struct lws_http_mount _lws_mnt_index; + struct lws_http_mount _lws_mnt_user; + struct lws_context_creation_info _lws_info; + struct lws_context* _lws_context; Glib::RefPtr _channel; -- cgit v1.2.3