I am having a problem with the networking of the project here: https://playcanvas.com/editor/scene/1171515. I have successfully gotten networking with building blocks to work, but now when I try to destroy blocks using the same networking method I get this error in the browser console:
Uncaught RangeError: Maximum call stack size exceeded
at t (socket.io.min.js:6)
at t (socket.io.min.js:6)
at t (socket.io.min.js:6)
at t (socket.io.min.js:6)
at t (socket.io.min.js:6)
at t (socket.io.min.js:6)
at t (socket.io.min.js:6)
at t (socket.io.min.js:6)
at t (socket.io.min.js:6)
at t (socket.io.min.js:6)
The socket.io.min.js:6 all shows the link to here: https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.1.3/socket.io.min.js
Here is my code for networking client side:
var Network = pc.createScript('network');
// static variables
Network.id = null;
Network.socket = null;
// initialize code called once per entity
Network.prototype.initialize = function() {
var socket = io.connect('https://chicken64.glitch.me'); // Glitch hosted server
Network.socket = socket;
var onPlayerBuildN = function(name, x, y, z, tagero){
//always directly after socket declairation
socket.emit('otherBuild', {Name:name, X:x, Y:y, Z:z, Tagero:tagero});
};
var onPlayerDestroy = function(destName){
socket.emit('otherDestroy', destName);
};
this.app.on("player:build", onPlayerBuildN);
this.app.on("blockDestroyed", onPlayerDestroy);
socket.on('buildFromOther', function(data){
pc.app.fire("player:build2", data.Oname, data.Ox, data.Oy, data.Oz, data.Otagero);
});
socket.on('destroyFromOther', function(car){
pc.app.fire("player:destroy", car.destName);
});
};
Here is my code for networking server side:
var server = require('http').createServer();
var options = {
cors: true
}
var io = require('socket.io')(server, options);
io.sockets.on('connection', function(socket) {
socket.on('otherBuild', function(data){
socket.broadcast.emit('buildFromOther', {Oname:data.Name,Ox:data.X,Oy:data.Y,Oz:data.Z,Otagero:data.Tagero});
//console.log(data.X + ", " + data.Y + " ," + data.Z);
});
socket.on('otherDestroy', function(car){
socket.broadcast.emit('destroyFromOther', car.destName);
});
});
console.log ('Server started');
server.listen(3000);
Here is the link for my server: https://glitch.com/edit/#!/chicken64?path=server.js%3A20%3A20
Any ideas on how to fix this?