我正在使用 Javascript 和 MVC .net 实现 twilio 视频通话功能。当我执行项目时,Web 浏览器会询问摄像头和麦克风权限,但它不显示摄像头。
我在文档中找不到任何相关的东西。 https://media.twiliocdn.com/sdk/js/video/releases/1.14.0/docs/index.html
如果有人能在这里找出错误,那就太好了。谢谢
索引.cshtml
@model twilioTest.Models.twilioVideoCall
@{
ViewBag.Title = "Index";
}
@{
ViewBag.Title = "Home Page";
}
<div class="jumbotron">
<p>test</p>
<div id="myCall"></div>
</div>
@section Scripts {
@Scripts.Render("~/bundles/jquery")
<script src="//media.twiliocdn.com/sdk/js/video/releases/2.7.0/twilio-video.min.js"></script>
<script>
const Video = Twilio.Video;
Video.connect('@Model.twilioToken', { name: '@Model.room.UniqueName' }).then(room => {
// debugger;
console.log('Connected to Room "%s"', room.name);
console.log('room.participants "%s"', JSON.stringify(room.localParticipant));
room.participants.forEach(participantConnected);
room.on('participantConnected', participantConnected);
room.on('participantDisconnected', participantDisconnected);
room.once('disconnected', error => room.participants.forEach(participantDisconnected));
});
function participantConnected(participant) {
// debugger;
console.log('test')
console.log('Participant "%s" connected', participant.identity);
const div = document.createElement('div');
div.id = participant.sid;
div.innerText = participant.identity;
participant.on('trackSubscribed', track => trackSubscribed(div, track));
participant.on('trackUnsubscribed', trackUnsubscribed);
participant.tracks.forEach(publication => {
if (publication.isSubscribed) {
trackSubscribed(div, publication.track);
}
});
$("#myCall").html(div);
// document.body.appendChild(div);
}
function participantDisconnected(participant) {
// debugger;
console.log('Participant "%s" disconnected', participant.identity);
document.getElementById(participant.sid).remove();
}
function trackSubscribed(div, track) {
// debugger;
div.appendChild(track.attach());
}
function trackUnsubscribed(track) {
// debugger;
track.detach().forEach(element => element.remove());
}
</script>
}
家庭控制器.cs
using System;
using System.Collections.Generic;
using Twilio;
using Twilio.Rest.Video.V1.Room;
using Twilio.Base;
using Twilio.Rest.Video.V1;
using Twilio.Jwt.AccessToken;
using System.Web.Mvc;
using twilioTest.Models;
namespace twilioTest.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
const string accountSid = "XXXXXXXXXX";
const string authToken = "XXXXXXXXXX";
var apiKeySid = "XXXXXXXXXX";
var apiKeySecret = "XXXXXXXXXX";
var identity = "test";
string roomName = "TESTROOM";
TwilioClient.Init(accountSid, authToken);
//create a Room
var room = RoomResource.Create(uniqueName: roomName);
//access token
var grant = new VideoGrant(); // Create a video grant for the token
grant.Room = roomName;
var grants = new HashSet<IGrant> { grant };
// Create an Access Token generator
var token = new Token(accountSid, apiKeySid, apiKeySecret, identity: identity, grants: grants);
// Serialize the token as a JWT
twilioVideoCall modelTwVidCall = new twilioVideoCall();
modelTwVidCall.room = room;
modelTwVidCall.twilioToken = token.ToJwt().ToString();
return View(modelTwVidCall);
}
}
}