diff options
Diffstat (limited to 'localwebsite/handlers')
-rw-r--r-- | localwebsite/handlers/MiscHandler.php | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/localwebsite/handlers/MiscHandler.php b/localwebsite/handlers/MiscHandler.php index e5f09b0..2cf37e9 100644 --- a/localwebsite/handlers/MiscHandler.php +++ b/localwebsite/handlers/MiscHandler.php @@ -67,41 +67,71 @@ class MiscHandler extends RequestHandler $tab = $high ? 'high' : 'low'; - $hls_opts = [ - 'startPosition' => -1, - - // // https://github.com/video-dev/hls.js/issues/3884#issuecomment-842380784 - 'liveSyncDuration' => 2, - 'liveMaxLatencyDuration' => 3, - 'maxLiveSyncPlaybackRate' => 2, - 'liveDurationInfinity' => true, + // h264 + $js_hls_config = [ + 'opts' => [ + 'startPosition' => -1, + + // // https://github.com/video-dev/hls.js/issues/3884#issuecomment-842380784 + 'liveSyncDuration' => 2, + 'liveMaxLatencyDuration' => 3, + 'maxLiveSyncPlaybackRate' => 2, + 'liveDurationInfinity' => true, + ], + 'debugVideoEvents' => !!$video_events, ]; - if ($hls_debug) - $hls_opts['debug'] = true; + $js_hls_config['debug'] = true; - $this->tpl->add_static('hls.js'); - // $this->tpl->add_external_static('js', 'https://cdn.jsdelivr.net/npm/hls.js@latest'); + // h265 + $js_h265webjs_config = [ + // https://github.com/numberwolf/h265web.js/blob/master/README_EN.MD#freetoken + 'token' => 'base64:QXV0aG9yOmNoYW5neWFubG9uZ3xudW1iZXJ3b2xmLEdpdGh1YjpodHRwczovL2dpdGh1Yi5jb20vbnVtYmVyd29sZixFbWFpbDpwb3JzY2hlZ3QyM0Bmb3htYWlsLmNvbSxRUTo1MzEzNjU4NzIsSG9tZVBhZ2U6aHR0cDovL3h2aWRlby52aWRlbyxEaXNjb3JkOm51bWJlcndvbGYjODY5NCx3ZWNoYXI6bnVtYmVyd29sZjExLEJlaWppbmcsV29ya0luOkJhaWR1', + ]; - $hls_host = config::get('cam_hls_host'); - $hls_proto = config::get('cam_hls_proto'); + $js_config = [ + 'isLow' => $tab == 'low', + 'proto' => config::get('cam_hls_proto'), + 'host' => config::get('cam_hls_host'), + 'camIds' => $camera_ids, + 'camLabels' => array_map(fn($id) => $config['cam_list']['labels'][$id], $camera_ids) + ]; + + $cams_by_type = []; + $include_h264 = false; + $include_h265 = false; + foreach ($camera_ids as $camera_id) { + $var_name = 'include_'.$config['cam_list']['full'][$camera_id]['type']; + $cams_by_type[$camera_id] = $config['cam_list']['full'][$camera_id]['type']; + $$var_name = true; + } + if ($include_h264) { + $js_config['hlsConfig'] = $js_hls_config; + $this->tpl->add_static('hls.js'); + } + if ($include_h265) { + $js_config['h265webjsConfig'] = $js_h265webjs_config; + $this->tpl->add_static('h265webjs-dist/missile.js'); + $this->tpl->add_static('h265webjs-dist/h265webjs-v20221106.js'); + } + + $js_config['camsByType'] = $cams_by_type; $hls_key = config::get('cam_hls_access_key'); if ($hls_key) setcookie_safe('hls_key', $hls_key); - $cam_filter = function($id) use ($config, $camera_ids) { - return in_array($id, $camera_ids); - }; + // $cam_filter = function($id) use ($config, $camera_ids) { + // return in_array($id, $camera_ids); + // }; $this->tpl->set([ - 'hls_host' => $hls_host, - 'hls_proto' => $hls_proto, - 'hls_opts' => $hls_opts, - 'hls_access_key' => $config['cam_hls_access_key'], + 'js_config' => $js_config, + + // 'hls_access_key' => $config['cam_hls_access_key'], 'camera_param' => $camera_param, - 'cams' => array_values(array_filter($config['cam_list'][$tab], $cam_filter)), + // 'cams' => array_values(array_filter($config['cam_list'][$tab], $cam_filter)), 'tab' => $tab, 'video_events' => $video_events ]); |