BrianHepler / MMM-Selfieshot

Taking a Selfie with USB cam on MagicMirror.
MIT License
8 stars 6 forks source link

No display #5

Closed haithem-bhk closed 4 years ago

haithem-bhk commented 4 years ago

Hello, i've only been messing around with Magic Mirror for about a week so i'm pretty new, i made a module to send a notification ("SELFIE_SHOOT") at the start, but there's no feed.

checking the console i found the following error :

Uncaught (in promise) TypeError: Cannot read property 'classList' of null

at Class.shoot (MMM-Selfieshot.js:193)
at Class.notificationReceived (MMM-Selfieshot.js:177)
at sendNotification (main.js:96)
at Object.sendNotification (main.js:526)
at Class.sendNotification (module.js:367)
at Class.getDom (note.js:7)
at main.js:111
at new Promise (<anonymous>)
at updateDom (main.js:110)
at main.js:52

(i have tested the USB camera on the raspberry and it works fine outside magic mirror) EDIT : I have tested the CURL method, and was able to take a selfie that's stored in the photos folder and the timer appears on screen, but i still want to use the notification method to make the display appear

BrianHepler commented 4 years ago

Hmm. Curious. Could you please send me the portion of your config.js for MMM-Selfieshot? I want to try and duplicate your issue.

BrianHepler commented 4 years ago

Yeah I found something. I'm on it.

BrianHepler commented 4 years ago

It's entirely possible that you're attempting to trigger the selfie before the MagicMirror has finished laying out all of the modules. Looking at the code, that line is trying to find the DIV object with the SELFIE id value and it's coming up zilch.

The solution here is to delay your notification until after your module receives the DOM_OBJECTS_CREATED notification. Additionally, I'll put in some checks to make sure that it errors gracefully if it receives a notification too early.

Also, I found an error where if you include a location for the module but don't tell it to put the touch button in place, it crashes. Thanks for pointing me at that general area. Now I have to go fix that.

BrianHepler commented 4 years ago

Example code:

notificationReceived: function(noti, payload, sender) {
    if (noti == "DOM_OBJECTS_CREATED") {
        this.sendNotification("SELFIE_SHOOT", 
                     {
                          option: {
                               shootCountdown: 1,
                               displayResult: false,
                               playShutter: false,
                               displayCountdown: false,
                           }
                      }
              );
        }
}
BrianHepler commented 4 years ago

If you're still having problems, feel free to reopen the issue.