-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
this.sendSocketNotification is not a function #196
Comments
Really interested in your module! I am not sure (I am glad my Wunderlist module works at all). I think it has something to do with the My timer: My function:
|
On my phone, so not a well formatted reply. The reason of your issue is that within the setTimout closure, this no longer points to your module instance. This is a common thing in JavaScript. To solve this, create a helper variable before your create the timer:
And then in the timer closure use:
|
Would |
I think so, yes. You can easily find out by logging this.
|
And just to be clear. You can of course use any helper variable name. I prefer 'self' because I do a lot of Swift programming. But a lot of people use 'var that=this;' in JavaScript. |
Many thanks to both of you! This is my first time using Node so I used your Wunderlist module frequently as a reference (and as a starting point). I just tried adding |
Use |
The Log.log helper does not work in the node helper as you might have noticed. :)
Should work. Note: to send a notification from the node helper to the front end, the frontend first needs to send a message (to open the connection.) |
Check this module for simple socket messages: https://github.com/MichMich/mmm-systemtemperature |
Probably should have thought to just try the default |
Scratch that, it is reaching node_helper. So the issue must be somewhere in there. I'll keep looking. |
Double scratch that, only the first one is reaching node helper. Losing my mind over here :P |
Can you post your code somewhere? So I can take a quick look? (Still on my phone, so I can only point you in the right direction.) |
It is here: https://github.com/SamLewis0602/MMM-Traffic |
Ah, the way you use it, you shouldn't use self. (Only within a closure this is nessecery) So only the sendSocketNotification in start is correctly fired. The others probably generate an error. Check your web inspector console. |
(I'd really love to explain it better. But typing on a phone is a b*tch) |
Works in my module that way :/ At least I am doing the same thing in the Node helper script. |
I almost wish they were generating errors because then I'd have a place to look, but I'm not getting any errors on the console. I'm confused why it works in |
Well not the exact same line but a duplicate. |
Also, the way you are currently building it, you can only use the module once. If you want to show two routes by adding the module to your config twice with a different destination, you're gonna have a bad time. ;) |
No, on one spot u use self. In start u use this. In this case: use this. |
Right but self is just a proxy for this that I could pass to the function right? |
The method in the interval is being called, and I logged |
On the place where you use self, self does not exist. It only exists in start. |
Hmmm that's weird. |
I passed self as a parameter at the end of the setIntervall call. |
You are making it unnecessary difficult. Try this:
|
That's what I had originally, and that's when I got the |
Which left me very confused after an hour of digging, hence my post here :) |
Ok ... you did it: you got me out of bed! ;) |
I've got to go to class so I'll have to mess with it some more later. Get some sleep! Thanks again for the help. |
I'll let you know if I am able to figure anything out. |
Ok, the issue is solved: there was a huge bug that caused the issue that only the last configured module could keep sending socketNotifications. This is solved now. I close this issue, but feel free to keep using this issue if you need any help building your module. |
Great! Everything is working now. Thanks again for your help! |
Okay, I've updated it to work for multiple instances of the module and everything is working based on my tests. Please check it out and let me know if you have any suggestions! I was thinking of adding an option to show the destination in small, dim text on a line underneath the current view, in case people want to be able to easily differentiate between routes if they have multiple. What do you both (or anyone else reading this) think? |
Also here is another link to the code so you don't have to go searching through the conversation above: https://github.com/SamLewis0602/MMM-Traffic |
the address might be a bit long but it could be dimmed out nickname of the locations like the card in google now or could do both if no "nickname" is set for the origin/dest use the address ( i've not tested the module yet but will tonight ) |
Ah that's a good idea. Maybe just something like a |
Okay, support for |
@paviro: If in the handler itself you don't need the original setTimeout(
this.handler.bind(this),
this.config.updateIntervall
); or setTimeout(
function(){
//doSomething
}.bind(this),
this.config.updateIntervall
); |
Great work @SamLewis0602! I'm using your module on my mirror. My girlfriend asked me for this features a few days ago! :) I ended you a pull request with multi language support. This way it can be used in other languages as well. I'll continue further question/issues in your repro te keep everything in one place. :) |
Don't forget to add your module to the wiki, so that others can find it! Will give it a try later, thanks for your work!
|
@CFenner will try that thanks! |
I seem to be having a similar issue that I can't figure out.. Just setup the Mirror and looking to write some modules. Trying to get the notifications to work before I start building out code and it isn't working. In my module.js file I do the following in the start method I do the following
In the node_helper.js the code is as follows
I never see any notifications reached.. I even tried to pass this in grabPhotos() and then use self, but it did not work... Stumped for a few hours. not sure what the issue is. Thanks! EDIT: I installed the mmm-systemtemperature module also to step through it. it does not work either. Was something messed up in the last update? I did a git pull and it states I have the latest. |
You are running |
I have tried with To make sure I didn't have any code issues. I installed the mmm-systemtemperature module, and it does not work either. Making me thing maybe its something else? |
What version of node are you running? |
The version I have is v6.2.1 |
Do all the other default modules work? |
Could shrare your repository somewhere so I can try? |
Sure! I made a pastebin with both the files since I don't have a repo set up for it yet on github. The link is good for 24 hrs. after that I set it to expire. At this point, the UI is not wired up. I'm just trying to get the notifications to work and checking for messages in the console. Once I get that working, I will be coding it up to parse an RSS feed from Flickr and pull images to rotate through. thanks for your help! |
No need to try the repository. Not sure what the problem was, but I Part of the my issue was that I expected the console.log to write to the My module is complete at this time, it loads images from Flickr and If people are interested in this, I can upload it to my github. Thanks!! On Sat, Jul 16, 2016 at 10:26 AM, Michael Teeuw notifications@github.com
|
I have just about finished my Traffic module to get current commute time, but I'm having difficulty sending a socket notification other than the initial one in my
start
function. The project can be found here and the issue lies inMMM-Traffic.js
.I send a socket notification in
start
which queries the google maps api innode_helper.js
then sends a socket notification back toMMM-Traffic.js
which will then callupdateDom()
. I'm usingupdateCommute()
as a proxy for setInterval that will send the initial socket notification at the user defined interval, but I am getting an error saying that this.sendSocketNotification is not a function. Any ideas?The text was updated successfully, but these errors were encountered: