Socket.io Uncaught TypeError: Cannot read property 'apply' of undefined
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
add a comment |
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
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
add a comment |
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
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
javascript socket.io
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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!
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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!
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
add a comment |
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!
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
add a comment |
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!
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!
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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