|
16 | 16 |
|
17 | 17 | #include "../../../plugins/protocol_lws_rtc_camera/protocol_lws_rtc_camera.h" |
18 | 18 | #include "../../../plugins/protocol_lws_webrtc/protocol_lws_webrtc.h" |
| 19 | +#include "../../../include/libwebsockets/lws-auth-device-client.h" |
| 20 | + |
| 21 | +static struct lws_auth_device_client_api *auth_api; |
19 | 22 |
|
20 | 23 | enum { |
21 | 24 | LWS_SW_HEIGHT, |
@@ -75,18 +78,13 @@ app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link, |
75 | 78 | return -1; |
76 | 79 | } |
77 | 80 |
|
78 | | - if (!devices_copy) |
79 | | - devices_copy = strdup(devs_list); |
80 | | - |
81 | | - char *p = devices_copy; |
82 | | - char *token; |
83 | | - |
84 | | - while ((token = strsep(&p, ","))) { |
85 | | - lwsl_notice("Attaching %s to WebRTC mixer\n", token); |
86 | | - if (cam_ops->attach(vh, url, token, client_name, app_width, app_height)) |
87 | | - lwsl_err("Failed to queue attach for %s\n", token); |
| 81 | + if (!auth_api || !auth_api->start_auth_flow) { |
| 82 | + lwsl_err("auth_api not populated by plugin\n"); |
| 83 | + return -1; |
88 | 84 | } |
89 | 85 |
|
| 86 | + auth_api->start_auth_flow(vh, url, "camshow"); |
| 87 | + |
90 | 88 | break; |
91 | 89 | } |
92 | 90 | return 0; |
@@ -118,6 +116,40 @@ set_clock(lws_usec_t us) |
118 | 116 | return 0; |
119 | 117 | } |
120 | 118 |
|
| 119 | +static void start_app_attach(struct lws_vhost *vh, const char *logical_name, const char *access_token) |
| 120 | +{ |
| 121 | + char *devices_copy_local = strdup(devs_list); |
| 122 | + char *p = devices_copy_local, *token; |
| 123 | + |
| 124 | + while ((token = strsep(&p, ","))) { |
| 125 | + lwsl_notice("Attaching %s to WebRTC mixer\n", token); |
| 126 | + if (cam_ops->attach(vh, url, token, client_name, app_width, app_height, access_token)) |
| 127 | + lwsl_err("Failed to queue attach for %s\n", token); |
| 128 | + } |
| 129 | + |
| 130 | + free(devices_copy_local); |
| 131 | +} |
| 132 | + |
| 133 | +static void pairing_indication(struct lws_vhost *vh, const char *logical_name, int start) |
| 134 | +{ |
| 135 | + lwsl_notice("\n\n*** BLINK BLINK BLINK: Identify triggered by Admin for %s ***\n\n", logical_name); |
| 136 | +} |
| 137 | + |
| 138 | +static void display_code(struct lws_vhost *vh, const char *logical_name, const char *user_code) |
| 139 | +{ |
| 140 | + lwsl_notice("\n\n=======================================\n"); |
| 141 | + lwsl_notice(" PAIRING REQUIRED FOR %s\n", logical_name); |
| 142 | + lwsl_notice(" User Code: %s\n", user_code); |
| 143 | + lwsl_notice("=======================================\n\n"); |
| 144 | +} |
| 145 | + |
| 146 | +static struct lws_auth_device_client_ops auth_ops = { |
| 147 | + .abi_version = LWS_AUTH_DEVICE_CLIENT_ABI_VERSION, |
| 148 | + .auth_success = start_app_attach, |
| 149 | + .pairing_indication = pairing_indication, |
| 150 | + .display_code = display_code, |
| 151 | +}; |
| 152 | + |
121 | 153 | static const lws_system_ops_t system_ops = { |
122 | 154 | .set_clock = set_clock, |
123 | 155 | }; |
@@ -162,6 +194,11 @@ main(int argc, const char **argv) |
162 | 194 |
|
163 | 195 | info.system_ops = &system_ops; |
164 | 196 |
|
| 197 | + static const struct lws_protocols protocols[] = { |
| 198 | + { NULL, NULL, 0, 0, 0, NULL, 0 } |
| 199 | + }; |
| 200 | + info.protocols = protocols; |
| 201 | + |
165 | 202 | /* Wire up cert trust bundle so wss:// connections can verify the peer */ |
166 | 203 | info.client_ssl_ca_filepath = "/etc/ssl/certs/ca-certificates.crt"; |
167 | 204 |
|
@@ -201,7 +238,13 @@ main(int argc, const char **argv) |
201 | 238 | static struct lws_protocol_vhost_options pvo_cam_status = { &pvo_ops, NULL, "status", "ok" }; |
202 | 239 | static struct lws_protocol_vhost_options pvo = { &pvo_cam_v4l2, &pvo_cam_status, "lws-rtc-camera", "" }; |
203 | 240 |
|
204 | | - vinfo.pvo = &pvo; |
| 241 | + /* For lws-auth-device-client */ |
| 242 | + static struct lws_protocol_vhost_options pvo_auth_api = { NULL, NULL, "lws-auth-client-api", (void *)&auth_api }; |
| 243 | + static struct lws_protocol_vhost_options pvo_auth_ops = { &pvo_auth_api, NULL, "app-auth-ops", (void *)&auth_ops }; |
| 244 | + static struct lws_protocol_vhost_options pvo_auth_status = { &pvo_auth_ops, NULL, "status", "ok" }; |
| 245 | + static struct lws_protocol_vhost_options pvo_auth = { &pvo, &pvo_auth_status, "lws-auth-device-client", "" }; |
| 246 | + |
| 247 | + vinfo.pvo = &pvo_auth; |
205 | 248 |
|
206 | 249 | cx = lws_create_context(&info); |
207 | 250 | if (!cx) { |
|
0 commit comments