准备工作:1、进入声网官网:https://www.agora.io 登录进入开发者后台创建一个项目,并获取项目的App ID,在Recording Server IP or Domain填写录制服务器的ip以及端口号,录制服务器我用的是Centos。
2、准备两台电脑,必须支持摄像头与麦克风,必须在谷歌浏览器上运行。
直接官网下载web-sdk无插件版demo,在谷歌浏览器上打开,输入App ID,channelId随意、check两端必须都勾上(先勾上的为房主),点击join,实现通话。
注意:如果出现getUserMedia failed的提示,可以尝试降低画面质量,如找到并替换下面这行代码:
localStream.setVideoProfile('720p');-->localStream.setVideoProfile('360p_3');
3、录制启用时,如果声网上录制的log日志提示Permission deny 则开放整个录制sdk文件夹的所有权限
直接贴代码
后台:
[HttpGet]
public ActionResult Meeting(int dId)
{
string userData = ((FormsIdentity)User.Identity).Ticket.UserData;
LoginUser user = Common.GetUser(userData);
try
{
MeetingRecord model = meetingRecordRepository.Get(m => m.dId == dId && m.UserId == user.UserId && m.Statu == MeetingStatus.Meeting);
if (model != null)
{
ViewBag.CannelName = model.dId.ToString() + Convert.ToDateTime(model.BeginDate).ToString("HHmmss");//自定义唯一频道名称,会用于在录制服务器上查找录制文件
ViewBag.MeetingId = model.MeetingId;
return View("Meeting");
}
else
return Content("<script>alert('通话已结束或不存在!');window.location.href='videocenter';</script>");
}
catch
{
return Content("<script>alert('操作失败,请重试!');window.location.href='videocenter';</script>");
}
}
前端:
@{
ViewBag.Title = "视频通话";
int meetingId = (int)ViewBag.MeetingId;
string cannelName = ViewBag.CannelName;
string appId = System.Configuration.ConfigurationManager.AppSettings["AgoraAppId"].ToString();
}
@section Head{
<script type="text/javascript" src="@Url.Content("~/content/meeting/AgoraRTCSDK-1.13.0.js")"></script>
<script type="text/javascript" src="@Url.Content("~/scripts/jquery.loadmask.min.js")"></script>
}
<div id="tabs">
<div class="section-header">
<div class="title">
@ViewBag.Title - <a href="@Url.Action("videocenter")">返回</a>
</div>
<div class="options">
<input type="button" id="startRecord" value="开启录制" οnclick="StartRecord()" />
<input type="button" id="stopAndQuit" οnclick="stopAndQuit()" style="display: none"
value="保存录制并结束会话" />
<input type="button" id="leave" οnclick="leave()" value="结束会话" />
</div>
</div>
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all">
<div id="div_device" class="panel panel-default" style="display: none">
<div class="select">
<label for="audioSource">
Audio source:
</label>
<select id="audioSource">
</select>
</div>
<div class="select">
<label for="videoSource">
Video source:
</label>
<select id="videoSource">
</select>
</div>
</div>
<div id="div_join" style="display:none">
<div class="panel-body">
访问密钥:
<input id="key" type="text" value="@appId" size="36" class="text ui-widget-content ui-corner-all" />
通讯频道:
<input id="channel" type="text" value="@cannelName" size="4" class="text ui-widget-content ui-corner-all" />
Host:
<input id="video" type="checkbox" checked />
<input type="button" id="join" class="btn btn-primary" οnclick="join()" value="呼叫" />
@*<button id="publish" class="btn btn-primary" οnclick="publish()">Publish</button>
<button