Skip to content

Commit

Permalink
当无人观看流事件发生时,清理一次playersessionlist
Browse files Browse the repository at this point in the history
  • Loading branch information
chatop committed Nov 28, 2020
1 parent d7e7138 commit e4310ff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 4 additions & 2 deletions StreamMediaServerKeeper/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,14 @@ private static bool checkMediaServerBin(string filePath)
public static void KillSelf(string message = "")
{
Logger.Logger.Fatal("异常情况,结束自己进程..." + "-> " + message);
string fileName = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
Environment.Exit(0);
/*string fileName = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
Process[] processes = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(fileName));
if (processes.Length > 0)
{
processes[0].Kill();
}
}*/

}


Expand Down
2 changes: 1 addition & 1 deletion StreamNodeWebApi/AutoTasker/StreamNodeKeeperMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private void Monitor()
{
try
{
for (int i = Common.MediaServerList.Count - 1; i <= 0; i--)
for (int i = Common.MediaServerList.Count - 1; i >= 0; i--)
{
if (Common.MediaServerList[i] != null && Common.MediaServerList[i].Health)
{
Expand Down
20 changes: 20 additions & 0 deletions StreamNodeWebApi/Controllers/WebHookController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Net;
using CommonFunction.ManageStructs;
using CommonFunctions;
using CommonFunctions.ManageStructs;
using CommonFunctions.WebApiStructs.Request;
Expand Down Expand Up @@ -140,6 +141,25 @@ public ResToWebHookOnStreamChange OnStreamChange(ReqForWebHookOnStreamChange req
[AuthVerify]
public ResToWebHookOnStreamNoneReader OnStreamNoneReader(ReqForWebHookOnStreamNoneReader req)
{
lock (Common.PlayerSessionListLock)
{
for (int i = Common.PlayerSessions.Count - 1; i >= 0; i--)
{
if (Common.PlayerSessions[i] != null &&
Common.PlayerSessions[i].App!.Equals(req.App) &&
Common.PlayerSessions[i].Vhost!.Equals(req.Vhost)
&& Common.PlayerSessions[i].StreamId!
.Equals(req.Stream) && Common.PlayerSessions[i]
.MediaServerId!.Equals(req.MediaServerId))
{
Common.PlayerSessions[i] = null!;
break;
}
}

Common.RemoveNull(Common.PlayerSessions);
}

return new ResToWebHookOnStreamNoneReader()
{
Code = 0,
Expand Down

0 comments on commit e4310ff

Please sign in to comment.