描述:
此说明文档描述demo具体的代码实现过程
代码实现:
1、net 4.6环境实现
1初始化
_clientWebSocket = new ClientWebSocket();
OnMessage += ReceivedMessage;
OnCalling += ReceivedCalling;
OnCloseCalling += ReceivedCloseCalling;
btnAnswer.Enabled = false;
s_PgNotifyOutHandler = new pgLiveSDK.callbackNotifyOut(PgCallBack);//PP透消息回调
2、处理回调信息
通话sdk回调
public void PgCallBack(IntPtr ptrAction, IntPtr ptrText)
{
string sAction = Marshal.PtrToStringAuto(ptrAction);
string sText = Marshal.PtrToStringAuto(ptrText);
System.Diagnostics.Debug.WriteLine(sText);
if (!string.IsNullOrEmpty(sText))
{
//if (!string.IsNullOrEmpty(LocalSessions.ppTalkingAccount) && sText.Contains(LocalSessions.ppTalkingAccount))
//{
// LogManagement.Write($"对讲视频连接回调:{sText}", LoggerEnum.VideoLogger, LoggerLevel.Info);
//}
//if (!string.IsNullOrEmpty(LocalSessions.ppWholeSceneAccount) && sText.Contains(LocalSessions.ppWholeSceneAccount))
//{
// LogManagement.Write($"全景视频连接回调:{sText}", LoggerEnum.VideoLogger, LoggerLevel.Info);
//}
}
}
消息中心回调
private void ReceivedMessage(string msg)
{
try
{
LogManagement.Write($"[{ConnectArgsModel.UserNo}]收到服务器指令:[{msg}]");
Dictionary<string, string> data = JsonConvert.DeserializeObject<Dictionary<string, string>>(msg);
if (data["actionType"]?.ToString() =="login")
{
if (data["relust"]?.ToString()=="1")
{
toolStripStatusLabel.Text = "登录成功";
}
}else if (data["actionType"]?.ToString() == "pullData")
{
var sessionPullMsg = data["sessionPullMsg"];
Dictionary<string, string> resdata = JsonConvert.DeserializeObject<Dictionary<string, string>>(sessionPullMsg);
var actionname = resdata["actionname"];
//接收呼叫指令
if (actionname == "applycall")
{
var account = resdata["account"];
ConnectArgsModel.Account = account;//对讲房间号
OnCalling?.Invoke(resdata);
}
if (actionname == "closecall")
{
OnCloseCalling?.Invoke();
}
}
}
catch (Exception ex)
{
LogManagement.Write($"异常:{ex.Message}\n{ex.StackTrace}", LoggerLevel.Error);
}
}
3、接听、挂断处理
private void btnAnswer_Click(object sender, EventArgs e)
{
try
{
if (btnAnswer.Text == "接听")
{
btnAnswer.Text = "挂断";
}
else
{
//挂断
pgLiveSDK.DevClose(_iLiveInstID1);
pgLiveSDK.LiveClean(_iLiveInstID1);
_iLiveInstID1=0;
btnAnswer.Text = "接听";
btnAnswer.Enabled = false;
return;
}
IntPtr picHandle = picVideo.Handle;
byte[] retValue = new byte[1024];
//pgLiveSDK.LiveClean(_iLiveInstID1);
int iRet = pgLiveSDK.LiveInit(ConnectArgsModel.PgServer, ConnectArgsModel.ppmonitorType, ref _iLiveInstID1, retValue, s_PgNotifyOutHandler);
if (iRet != 0)
{
MessageBox.Show("对讲视频初始化失败");
return;
}
byte[] retValue2 = new byte[1024];
//pgLiveSDK.DevClose(_iLiveInstID1);
int iRet2 = pgLiveSDK.DevOpen(_iLiveInstID1, ConnectArgsModel.Account, picHandle, "", "", retValue2);
if (iRet2 != 0)
{
MessageBox.Show("对讲视频打开失败");
return;
}
}
catch (Exception ex)
{
LogManagement.Write($"异常:{ex.Message}\n{ex.StackTrace}", LoggerLevel.Error);
}
}
- demo下载
对讲demo.zip
下载地址:http://doc.cpyht.com/server/index.php?s=/api/attachment/visitFile&sign=2e8d557937e24c1d46edc5f3ac716a34
作者:郭祥西 创建时间:2024-04-10 17:44
最后编辑:郭祥西 更新时间:2024-11-07 15:18
最后编辑:郭祥西 更新时间:2024-11-07 15:18