-
-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Socket Emits Multiple Times when Each Time page re renders #518
Comments
I have been facing same issue But Haven't found any solution yet |
I have been facing same issue..... |
Hey @eyesmarty Speaking about the issue, you might need to change the configuration a bit. There multiple ways to avoid this:
created(){
// in addition to this line
this.$socket.$subscribe("offer", (offer) => {
console.log("offer");
this.onOffer(offer);
});
},
beforeDestroy() {
// you always need this one
this.$socket.$unsubscribe("offer");
}
sockets: {
offer(offer) { // `offer()` is the name of the even you'd want to subscribe to
console.log("offer");
this.onOffer(offer);
}
} You can even inline all your code here (no need for sockets: {
offer(offer) {
if (this.creator) return;
this.rtcPeerConnection = new RTCPeerConnection(this.iceServers);
this.rtcPeerConnection.onicecandidate = this.onIceCandidateFunction;
// this.rtcPeerConnection.ontrack = onTrackFunction;
this.rtcPeerConnection.addStream(this.userStream);
this.rtcPeerConnection.setRemoteDescription(offer);
this.rtcPeerConnection.createAnswer(
(answer) => {
this.rtcPeerConnection.setLocalDescription(answer);
this.$socket.client.emit("answer", answer, this.roomName);
console.log("answer")
},
(error) => {
console.log(error);
}
);
}
}, Let me know if it helped to resolve your issue. Anyway, I'll add this point to the docs in order to help others. |
When I leave component in which i have implemented socket.client.emit and visit that component again the emit event triggers twice if i do the same the emit event triggers three times and so on.
I am using it to implement webrtc and each time user visits that page emit event triggers that many times
Kindly Let me know how to solve this issue
i have tried this.$socket.client.off("created") but it doesn't seem to be working
Sample Code
the answer event is triggered as many times as many times the component is re-rendered
I have been stuck in this issue since long time kindle provide some guidence
Thanks in Advance
The text was updated successfully, but these errors were encountered: