Browse Source

优化双目视频流返回

master
胡超1 1 year ago
parent
commit
05d29914b3
  1. 15
      CPF_Cef/Common/WebSocketClientWithHeartbeat.cs
  2. 8
      CPF_Cef/FrmMain.cs
  3. 2
      CPF_Cef/Parame.cs

15
CPF_Cef/Common/WebSocketClientWithHeartbeat.cs

@ -20,6 +20,7 @@ namespace AksWebBrowser.Common
private readonly string _serverUri; private readonly string _serverUri;
private readonly ClientWebSocket _webSocket = new ClientWebSocket(); private readonly ClientWebSocket _webSocket = new ClientWebSocket();
public string funName = string.Empty; public string funName = string.Empty;
public bool isstop = true;
//开启定时 //开启定时
System.Timers.Timer timer = new System.Timers.Timer(30000); System.Timers.Timer timer = new System.Timers.Timer(30000);
public WebSocketClientWithHeartbeat() public WebSocketClientWithHeartbeat()
@ -44,7 +45,7 @@ namespace AksWebBrowser.Common
/// <returns></returns> /// <returns></returns>
private async Task ReceiveMessages() private async Task ReceiveMessages()
{ {
while (true) while (isstop)
{ {
if (_webSocket.State == WebSocketState.Open) if (_webSocket.State == WebSocketState.Open)
{ {
@ -67,6 +68,7 @@ namespace AksWebBrowser.Common
string functionName = jo["functionName"].ToString(); string functionName = jo["functionName"].ToString();
if (functionName == "LiveDetectResult") if (functionName == "LiveDetectResult")
{ {
Log.Error("LiveDetectResult" + "活检准备");
string status = string.Empty; string status = string.Empty;
if (body.Contains("success")) if (body.Contains("success"))
{ {
@ -106,6 +108,7 @@ namespace AksWebBrowser.Common
} }
else if (functionName == "CF_FaceCompare") else if (functionName == "CF_FaceCompare")
{ {
Log.Error("CF_FaceCompare" + "活检返回");
//停止活检 //停止活检
Send("{\"function\":\"CF_StopLiveDetect\"}", "CF_StopLiveDetect"); Send("{\"function\":\"CF_StopLiveDetect\"}", "CF_StopLiveDetect");
//关闭摄像头 //关闭摄像头
@ -124,9 +127,11 @@ namespace AksWebBrowser.Common
Parame.socket.Send(results); Parame.socket.Send(results);
// 断开连接 // 断开连接
_webSocket.Dispose(); _webSocket.Dispose();
isstop = false;
} }
else if (functionName == "VideoStream") else if (functionName == "VideoStream")
{ {
Log.Error("VideoStream" + "视频返回");
string VideoBase64 = jo["VideoBase64"].ToString(); string VideoBase64 = jo["VideoBase64"].ToString();
string src = "data:image/jpg;base64," + VideoBase64; string src = "data:image/jpg;base64," + VideoBase64;
string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100121" + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + src + "\"}"; string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100121" + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + src + "\"}";
@ -149,7 +154,7 @@ namespace AksWebBrowser.Common
/// <returns></returns> /// <returns></returns>
private async Task SendHeartbeats() private async Task SendHeartbeats()
{ {
while (true) while (isstop)
{ {
if (_webSocket.State == WebSocketState.Open) if (_webSocket.State == WebSocketState.Open)
{ {
@ -159,7 +164,7 @@ namespace AksWebBrowser.Common
var heartbeat = "{\"function\":\"Heartbeat\"}"; var heartbeat = "{\"function\":\"Heartbeat\"}";
var sendBuffer = System.Text.Encoding.UTF8.GetBytes(heartbeat); var sendBuffer = System.Text.Encoding.UTF8.GetBytes(heartbeat);
await _webSocket.SendAsync(new ArraySegment<byte>(sendBuffer), WebSocketMessageType.Text, true, CancellationToken.None); await _webSocket.SendAsync(new ArraySegment<byte>(sendBuffer), WebSocketMessageType.Text, true, CancellationToken.None);
await Task.Delay(TimeSpan.FromSeconds(6), CancellationToken.None); //根据需要设置心跳间隔 await Task.Delay(TimeSpan.FromSeconds(10), CancellationToken.None); //根据需要设置心跳间隔
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -210,6 +215,9 @@ namespace AksWebBrowser.Common
Send("{\"function\":\"CF_CloseCamera\"}", "CF_CloseCamera"); Send("{\"function\":\"CF_CloseCamera\"}", "CF_CloseCamera");
string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100120" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "活体检测超时." + "\"}"; string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100120" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "活体检测超时." + "\"}";
Parame.socket.Send(results); Parame.socket.Send(results);
// 断开连接
_webSocket.Dispose();
isstop = false;
} }
catch { } catch { }
finally { } finally { }
@ -225,6 +233,7 @@ namespace AksWebBrowser.Common
{ {
if (_webSocket.State == WebSocketState.Open) if (_webSocket.State == WebSocketState.Open)
{ {
isstop = false;
await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None); await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None);
} }
} }

8
CPF_Cef/FrmMain.cs

@ -35,8 +35,8 @@ namespace AksWebBrowser
Title = "控申业务专用浏览器"; Title = "控申业务专用浏览器";
CanResize = false; CanResize = false;
ShowInTaskbar = true; ShowInTaskbar = true;
WindowState = WindowState.FullScreen; //WindowState = WindowState.FullScreen;
//WindowState = WindowState.Maximized; WindowState = WindowState.Maximized;
Children.Add( Children.Add(
new Border new Border
@ -81,8 +81,8 @@ namespace AksWebBrowser
//浏览器大小 //浏览器大小
Parame.webBrowser.Width = w; Parame.webBrowser.Width = w;
Parame.webBrowser.Height = h; Parame.webBrowser.Height = h;
Parame.webBrowser.Url = "http://143.169.62.3:8096/#/main-out";//天府新区 //Parame.webBrowser.Url = "http://143.169.62.3:8096/#/main-out";//天府新区
//Parame.webBrowser.Url = "http://192.168.0.234:8096/#/main-out"; Parame.webBrowser.Url = "http://192.168.0.234:8096/#/main-out";
//Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out"; //Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out";
//Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html"; //Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html";
//开发者工具暂时只能支持Windows //开发者工具暂时只能支持Windows

2
CPF_Cef/Parame.cs

@ -19,7 +19,7 @@ namespace AksWebBrowser
public static Window frm { get; set; } public static Window frm { get; set; }
public static List<Func> FuncObject { get; set; } public static List<Func> FuncObject { get; set; }
//接口地址 //接口地址
public static string apiUrl = "http://143.169.62.3:8098";//"http://192.168.0.234:8098";// public static string apiUrl = "http://192.168.0.234:8098";//"http://143.169.62.3:8098";//
//授权key //授权key
public static string key = "1"; public static string key = "1";
//硬件Ip //硬件Ip

Loading…
Cancel
Save