I'm trying to make a call using peerJs library.
In my app, I have 2 types of users: Client and Streamer. Only clients can call to the streamers. And when the client calls, he emits only audio stream, and the streamer needs to emit audio and video stream;
So what am I doing is next:
part on my Client component:
public peer;
public outGoingCall;
public incomingStream = new BehaviourSubject(null);
ngOnInit() {
this.peer = new Peer();
}
public callToPeer(peerId, localClientStream) {
this.outGoingCall = this.peer.call(peerId, localClientStream);
this.outGoingCall.on('stream', (remoteStream: MediaStream) => {
console.log('incoming stream from streamer ', remoteStream);
// so here in console I see incoming stream and it is active;
// but when I apply it in video tag I don't see anything! Why?
this.incomingStream.next(remoteStream);
});
}
HTML file for Client component:
<div class="call-holder" *ngIf="incomingStream | async as stream">
<video [srcObject]="stream" autoplay></video>
...
</div>
here code of Streamer component:
public peer;
public clientsCall;
public incomingClientsStream = new BehaviourSubject(null);
ngOnInit() {
this.peer = new Peer('streamer-1'); // exact id for this streamer;
this.peer.on('call', (mediaCon) => {
console.log('incoming call from Client');
// Allow only a single media
if (this.clientsCall && this.clientsCall.open) {
mediaCon.close();
}
mediaCon.on('stream', (streamFromClient: MediaStream) => {
console.log('stream from client ', streamFromClient);
this.incomingClientsStream.next(streamFromClient);
});
mediaCon.on('close', (some) => {
console.log(some);
console.log('client closed connections');
});
this.clientsCall = mediaCon;
});
}
public answerTheCall() {
navigator.mediaDevices.getUserMedia({audio: true, video: true})
.then((localStream) => this.clientsCall.answer(localStream));
}
in streamers HTML file I listen the audio that comes from client and it works:
<div *ngIf="(incomingStream | async) as clientStream">
<audio [srcObject]="clientStream" autoplay></audio>
</div>
So the thing is, when I answer the call from a client and sending to him my local stream, I can see it from the Streamer's page but not on the Clients page. Why? Why I don't receive stream from streamer?