|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|