I'm implementing video conferencing using native WebRTC.
I have tried to implement video conferencing on plain javascript and it works well. As signalling server I'm using ASP .NET Core with SignalR. Front-end part consists of Angular 6 with CLI.
On the first step I'm receiving my local video stream and attach it to video tag.
This is my ts file
private getMedia(): void {
navigator.mediaDevices
.getUserMedia({
audio: true,
video: true
})
.then((stream: MediaStream) => {
this.localVideo.nativeElement.srcObject = stream;
// this.localVideo.nativeElement.play();
this.localStream = stream;
this.callButton = false;
this.pc1 = new RTCPeerConnection({
iceServers: this.iceServers
});
this.pc1.onicecandidate = e => this.onIceCandidate(e);
this.pc1.oniceconnectionstatechange = e => this.onIceStateChange(e);
this.pc1.onaddstream = e => this.gotRemoteStream(e);
this.pc1.addStream(stream);
})
.catch(e => alert(`getUserMedia() error: ${e.name}`));
}
This is my component template:
<div class="col-md-8">
<div class="row">
<div class="col-md-12">
<h2 class="text-center">Invite to conversation</h2>
<div class="form-group text-center">
<input type="text" class="form-control" readonly/>
<button type="button" class="btn">Copy a link</button>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<video autoplay="autoplay" id="remoteVideo" #remoteVideo></video>
</div>
</div>
<div class="row">
<button (click)="call()" type="button" class="btn btn-info" [disabled]="callButton">Call</button>
<button type="button" class="btn btn-success">Answer</button>
<button type="button" class="btn">Hangup</button>
</div>
<div class="row">
<div class="col-md-12">
<video autoplay="autoplay" style="width: 300px; height: 300px;" #localVideo></video>
</div>
</div>
</div>
Then I have exchange with descriptors and candidates. Finally, I receive remote stream and attach it to srcObject property of video tag.
private gotRemoteStream(e: any): void {
this.remoteVideo.nativeElement.srcObject = e.stream;
this.remoteVideo.nativeElement.play();
}
gotRemoteStream is firing, but video is not showing. Maybe somebody had the same problem? Many thanks!