【发布时间】:2019-02-21 18:15:45
【问题描述】:
我正在尝试使用 WebRTC 和 typescript,因为 typescript 很棒,而 webrtc 甚至更棒...我正在使用 VS Code 在 Angular 6 的上下文中执行此操作。
这似乎不是天作之合(可能是因为我不了解其中任何一个组成部分)。
我很难找到任何使用 typescript for webrtc 的示例,但是当我开始尝试翻译一个普通的 javascript 示例时,我注意到方法和属性似乎至少在 Visual Studio Code 中被识别。但我没有走多远。
您可以在下面看到我试图将一个简单的示例翻译成打字稿。
createConnection ()
{
// window.localConnection = localConnection = new RTCPeerConnection(servers);
this.localConnection = new RTCPeerConnection();
console.log(this.sendChannel);
// sendChannel = localConnection.createDataChannel('sendDataChannel');
var sendChannel = this.localConnection.createDataChannel('sendDataChannel');
console.log(this.sendChannel);
// localConnection.onicecandidate = e => {
// onIceCandidate(localConnection, e);
// };
// sendChannel.onopen = onSendChannelStateChange;
// sendChannel.onclose = onSendChannelStateChange;
// window.remoteConnection = remoteConnection = new RTCPeerConnection(servers);
// console.log('Created remote peer connection object remoteConnection');
// remoteConnection.onicecandidate = e => {
// onIceCandidate(remoteConnection, e);
// };
// remoteConnection.ondatachannel = receiveChannelCallback;
// localConnection.createOffer().then(
// gotDescription1,
// onCreateSessionDescriptionError
// );
// startButton.disabled = true;
// closeButton.disabled = false;
}
关于 sendChannel 的定义我得到这个错误:
src/app/app.component.ts(48,44):错误 TS2339:“RTCPeerConnection”类型上不存在属性“createDataChannel”。
第一个日志的控制台日志是:
RTCPeerConnection { localDescription:null,currentLocalDescription:null,pendingLocalDescription:null,remoteDescription:null,currentRemoteDescription:null,pendingRemoteDescription:null,signalingState:“稳定”,canTrickleIceCandidates:null,iceGatheringState:“new”,iceConnectionState:“new” }
第二次记录为 null。
感谢任何提示或提示,了解我为什么会收到此错误以及如何修复它。
更新:添加了 git repositoryng se 来报告问题。
git clone https://github.com/wokawaka/typescriptwebrtctest
npm install
ng serve --open
【问题讨论】:
-
什么浏览器?例如,Edge 不支持 RTCDataChannel。
-
我在 VS Code 中遇到错误,但使用的是 Firefox(最新版本)。
标签: typescript webrtc