Socket.io Uncaught TypeError: Cannot read property 'apply' of undefined












2















A particular event doesn’t work in my socket.io programming. The rest works fine. This is where the problem occurs:



First html file



 socket.on('connect', () => {socket.emit('phone', 'phone');});


Server file



io.on('connection', function(socket){ 
io.on('phone', function(socket, data){
io.emit('stuurbedrijfsnaam', 'stuurbedrijfsnaam');
});
});


2nd html file



socket.on('stuurbedrijfsnaam', function(socket){
socket.emit('stuurbedrijfsnaam',bedrijfsnaam)
})


This is the full error given by google chrome:



index.js:83 Uncaught TypeError: Cannot read property 'apply' of undefined
at r.emit (index.js:83)
at r.onevent (index.js:83)
at r.onpacket (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.ondecoded (index.js:83)
at a.<anonymous> (index.js:83)
at a.r.emit (index.js:83)
at a.add (index.js:83)
at r.ondata (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.onPacket (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.onPacket (index.js:83)
at r.onData (index.js:83)
at WebSocket.ws.onmessage (index.js:83)


It references index.js:83, which is inside a folder made by socket.io itself. There are lines 81, 82 and 83:



Backoff.prototype.setJitter = function(jitter){
this.jitter = jitter;
};


Hope I gave enough resources. It would be cool if someone’s help me out. Thanks!










share|improve this question

























  • We don't see all your code - please post all the code you are using so we can help fix your problem.

    – Jack Bashford
    Nov 15 '18 at 2:20
















2















A particular event doesn’t work in my socket.io programming. The rest works fine. This is where the problem occurs:



First html file



 socket.on('connect', () => {socket.emit('phone', 'phone');});


Server file



io.on('connection', function(socket){ 
io.on('phone', function(socket, data){
io.emit('stuurbedrijfsnaam', 'stuurbedrijfsnaam');
});
});


2nd html file



socket.on('stuurbedrijfsnaam', function(socket){
socket.emit('stuurbedrijfsnaam',bedrijfsnaam)
})


This is the full error given by google chrome:



index.js:83 Uncaught TypeError: Cannot read property 'apply' of undefined
at r.emit (index.js:83)
at r.onevent (index.js:83)
at r.onpacket (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.ondecoded (index.js:83)
at a.<anonymous> (index.js:83)
at a.r.emit (index.js:83)
at a.add (index.js:83)
at r.ondata (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.onPacket (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.onPacket (index.js:83)
at r.onData (index.js:83)
at WebSocket.ws.onmessage (index.js:83)


It references index.js:83, which is inside a folder made by socket.io itself. There are lines 81, 82 and 83:



Backoff.prototype.setJitter = function(jitter){
this.jitter = jitter;
};


Hope I gave enough resources. It would be cool if someone’s help me out. Thanks!










share|improve this question

























  • We don't see all your code - please post all the code you are using so we can help fix your problem.

    – Jack Bashford
    Nov 15 '18 at 2:20














2












2








2








A particular event doesn’t work in my socket.io programming. The rest works fine. This is where the problem occurs:



First html file



 socket.on('connect', () => {socket.emit('phone', 'phone');});


Server file



io.on('connection', function(socket){ 
io.on('phone', function(socket, data){
io.emit('stuurbedrijfsnaam', 'stuurbedrijfsnaam');
});
});


2nd html file



socket.on('stuurbedrijfsnaam', function(socket){
socket.emit('stuurbedrijfsnaam',bedrijfsnaam)
})


This is the full error given by google chrome:



index.js:83 Uncaught TypeError: Cannot read property 'apply' of undefined
at r.emit (index.js:83)
at r.onevent (index.js:83)
at r.onpacket (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.ondecoded (index.js:83)
at a.<anonymous> (index.js:83)
at a.r.emit (index.js:83)
at a.add (index.js:83)
at r.ondata (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.onPacket (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.onPacket (index.js:83)
at r.onData (index.js:83)
at WebSocket.ws.onmessage (index.js:83)


It references index.js:83, which is inside a folder made by socket.io itself. There are lines 81, 82 and 83:



Backoff.prototype.setJitter = function(jitter){
this.jitter = jitter;
};


Hope I gave enough resources. It would be cool if someone’s help me out. Thanks!










share|improve this question
















A particular event doesn’t work in my socket.io programming. The rest works fine. This is where the problem occurs:



First html file



 socket.on('connect', () => {socket.emit('phone', 'phone');});


Server file



io.on('connection', function(socket){ 
io.on('phone', function(socket, data){
io.emit('stuurbedrijfsnaam', 'stuurbedrijfsnaam');
});
});


2nd html file



socket.on('stuurbedrijfsnaam', function(socket){
socket.emit('stuurbedrijfsnaam',bedrijfsnaam)
})


This is the full error given by google chrome:



index.js:83 Uncaught TypeError: Cannot read property 'apply' of undefined
at r.emit (index.js:83)
at r.onevent (index.js:83)
at r.onpacket (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.ondecoded (index.js:83)
at a.<anonymous> (index.js:83)
at a.r.emit (index.js:83)
at a.add (index.js:83)
at r.ondata (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.onPacket (index.js:83)
at r.<anonymous> (index.js:83)
at r.emit (index.js:83)
at r.onPacket (index.js:83)
at r.onData (index.js:83)
at WebSocket.ws.onmessage (index.js:83)


It references index.js:83, which is inside a folder made by socket.io itself. There are lines 81, 82 and 83:



Backoff.prototype.setJitter = function(jitter){
this.jitter = jitter;
};


Hope I gave enough resources. It would be cool if someone’s help me out. Thanks!







javascript socket.io






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 12:54







user10654908

















asked Nov 15 '18 at 2:09









user10654908user10654908

112




112













  • We don't see all your code - please post all the code you are using so we can help fix your problem.

    – Jack Bashford
    Nov 15 '18 at 2:20



















  • We don't see all your code - please post all the code you are using so we can help fix your problem.

    – Jack Bashford
    Nov 15 '18 at 2:20

















We don't see all your code - please post all the code you are using so we can help fix your problem.

– Jack Bashford
Nov 15 '18 at 2:20





We don't see all your code - please post all the code you are using so we can help fix your problem.

– Jack Bashford
Nov 15 '18 at 2:20












1 Answer
1






active

oldest

votes


















2














The cause of this error is that you're trying to call .emit() via the socket argument of your custom event handlers, which is incorrect usage according to the documentation for socket.io client side API.



Consider revising your client side code as follows by removing the socket argument from your handlers to cause .emit() to be called on the actual socket instance:



socket.on('stuurbedrijfsnaam', function(){ // remove 'socket' here

// cause emit() to be called on actual socket instance
socket.emit('stuurbedrijfsnaam',bedrijfsnaam)
})


The reason socket.emit('phone', 'phone'); in your first html file is that emit() is called on the original socket instance, rather than via a socket argument passed to the event handler, as you are doing in your seconds html file.



Hope that helps!






share|improve this answer
























  • Does not work, unfortunately. Apparently, the arguments were not the problem. But thanks a lot for the extended answer!

    – user10654908
    Nov 17 '18 at 10:53











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311432%2fsocket-io-uncaught-typeerror-cannot-read-property-apply-of-undefined%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














The cause of this error is that you're trying to call .emit() via the socket argument of your custom event handlers, which is incorrect usage according to the documentation for socket.io client side API.



Consider revising your client side code as follows by removing the socket argument from your handlers to cause .emit() to be called on the actual socket instance:



socket.on('stuurbedrijfsnaam', function(){ // remove 'socket' here

// cause emit() to be called on actual socket instance
socket.emit('stuurbedrijfsnaam',bedrijfsnaam)
})


The reason socket.emit('phone', 'phone'); in your first html file is that emit() is called on the original socket instance, rather than via a socket argument passed to the event handler, as you are doing in your seconds html file.



Hope that helps!






share|improve this answer
























  • Does not work, unfortunately. Apparently, the arguments were not the problem. But thanks a lot for the extended answer!

    – user10654908
    Nov 17 '18 at 10:53
















2














The cause of this error is that you're trying to call .emit() via the socket argument of your custom event handlers, which is incorrect usage according to the documentation for socket.io client side API.



Consider revising your client side code as follows by removing the socket argument from your handlers to cause .emit() to be called on the actual socket instance:



socket.on('stuurbedrijfsnaam', function(){ // remove 'socket' here

// cause emit() to be called on actual socket instance
socket.emit('stuurbedrijfsnaam',bedrijfsnaam)
})


The reason socket.emit('phone', 'phone'); in your first html file is that emit() is called on the original socket instance, rather than via a socket argument passed to the event handler, as you are doing in your seconds html file.



Hope that helps!






share|improve this answer
























  • Does not work, unfortunately. Apparently, the arguments were not the problem. But thanks a lot for the extended answer!

    – user10654908
    Nov 17 '18 at 10:53














2












2








2







The cause of this error is that you're trying to call .emit() via the socket argument of your custom event handlers, which is incorrect usage according to the documentation for socket.io client side API.



Consider revising your client side code as follows by removing the socket argument from your handlers to cause .emit() to be called on the actual socket instance:



socket.on('stuurbedrijfsnaam', function(){ // remove 'socket' here

// cause emit() to be called on actual socket instance
socket.emit('stuurbedrijfsnaam',bedrijfsnaam)
})


The reason socket.emit('phone', 'phone'); in your first html file is that emit() is called on the original socket instance, rather than via a socket argument passed to the event handler, as you are doing in your seconds html file.



Hope that helps!






share|improve this answer













The cause of this error is that you're trying to call .emit() via the socket argument of your custom event handlers, which is incorrect usage according to the documentation for socket.io client side API.



Consider revising your client side code as follows by removing the socket argument from your handlers to cause .emit() to be called on the actual socket instance:



socket.on('stuurbedrijfsnaam', function(){ // remove 'socket' here

// cause emit() to be called on actual socket instance
socket.emit('stuurbedrijfsnaam',bedrijfsnaam)
})


The reason socket.emit('phone', 'phone'); in your first html file is that emit() is called on the original socket instance, rather than via a socket argument passed to the event handler, as you are doing in your seconds html file.



Hope that helps!







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 2:40









Dacre DennyDacre Denny

12.7k41031




12.7k41031













  • Does not work, unfortunately. Apparently, the arguments were not the problem. But thanks a lot for the extended answer!

    – user10654908
    Nov 17 '18 at 10:53



















  • Does not work, unfortunately. Apparently, the arguments were not the problem. But thanks a lot for the extended answer!

    – user10654908
    Nov 17 '18 at 10:53

















Does not work, unfortunately. Apparently, the arguments were not the problem. But thanks a lot for the extended answer!

– user10654908
Nov 17 '18 at 10:53





Does not work, unfortunately. Apparently, the arguments were not the problem. But thanks a lot for the extended answer!

– user10654908
Nov 17 '18 at 10:53




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311432%2fsocket-io-uncaught-typeerror-cannot-read-property-apply-of-undefined%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues