i’m building a video chat app using peerjs with ionic angular. its working like i wanted except i cant end the call. here’s how i call other user
call(userId: string, partnerId: string) {
const conn = this.peer.connect(partnerId);
console.log(userId);
conn.on('open', () => {
conn.on('data', (data) => {
console.log(data);
})
conn.send(userId);
})
if (this.myEl.classList.contains('disableCall')) {
console.log('Show');
this.myEl.classList.add('showCall');
this.partnerEl.classList.add('showCall');
this.myEl.classList.remove('disableCall');
this.partnerEl.classList.remove('disableCall');
}
conn.on("close", function () {
conn.close();
this.hideCall = false;
this.hideCallLogin = false;
console.log('Di hentikan oleh penerima');
if (this.myEl.classList.contains('showCall')) {
console.log('Hide');
this.myEl.classList.remove('showCall');
this.partnerEl.classList.remove('showCall');
this.myEl.classList.add('disableCall');
this.partnerEl.classList.add('disableCall');
}
});
this.hideCallLogin = false;
if (this.peer.destroyed == false) {
const call = this.peer.call(partnerId, this.myStream);
call.on('stream', (stream) => {
this.partnerEl.srcObject = stream;
this.hideCall = true;
if (call.peerConnection.connectionState == 'connecting') {
this.swapVideo('my-video');
}
});
} else {
this.createPeer(this.userId);
const call = this.peer.call(partnerId, this.myStream);
call.on('stream', (stream) => {
this.partnerEl.srcObject = stream;
this.hideCall = true;
this.hideCallLogin = false;
});
}
}
and here’s how i wait for an answer
wait() {
this.peer.on('call', (call) => {
//change this to a modal for confirm a call
var acceptsCall = confirm(partner + " is calling, do you want to accept it ?");
if (acceptsCall) {
call.answer(this.myStream); // Answer the call with an A/V stream.
call.on('stream', (stream) => {
this.partnerEl.srcObject = stream;
this.status = 'Connected';
this.hideCallLogin = false;
this.swapVideo('my-video');
});
}
});
if (this.myEl.classList.contains('disableCall')) {
console.log('Show');
this.partnerEl.classList.add('showCall');
this.myEl.classList.add('showCall');
this.partnerEl.classList.remove('disableCall');
this.myEl.classList.remove('disableCall');
}
//getting partner id
let partner = '';
this.peer.on('connection', (conn) => {
conn.on('open', () => {
conn.on('data', (data) => {
partner = data;
})
})
conn.on('close', () => {
conn.close();
console.log(this.status);
this.hideCall = false;
this.hideCallLogin = false;
console.log('Di hentikan oleh penelpon');
if (this.myEl.classList.contains('showCall')) {
console.log('Hide');
this.myEl.classList.remove('showCall');
this.partnerEl.classList.remove('showCall');
this.myEl.classList.add('disableCall');
this.partnerEl.classList.add('disableCall');
}
})
})
}
i use this code to terminate all connection
this.peer.disconnect();
this.peer.destroy();
with this code i cant close call between 2 peers at the same time, if someone on a call with other user and he ended the call nothing happen, but if other user ended the call as well then the connection is terminate. that’s not what it supposed to be, maybe i did something wrong but where is it? any thoughts would be very helpful
1 post - 1 participant