Long running tasks - json parsing from url



  • Good day,
    I’ve been spending some time reviewing the module development page.
    Reading through the MMM-JSON-Feed module documentation in the 3rd party modules section of the github, I was hoping to get some insight into why parsing json through the module is giving me trouble.

    I have created an endpoint plugin form my emby media server which returns a json object as follows:

    {"MediaNames":["Family Guy","Nashville","Stargate: Origins","Stargate Atlantis","Stargate Universe","Lethal Weapon","Black Lightning","Arrow","Young Sheldon","This Is Us","Legion","Marvel's Agents of S.H.I.E.L.D.","The Flash","Supergirl","Gotham","Agents of S.H.I.E.L.D.","Archer (2009)","The Big Bang Theory","The Walking Dead","Supernatural","Legends of Tomorrow"]}
    

    I believe I have run into problems because the json object returned from my server endpoint may need to parse asynchronously. No matter how many attempts to request info from my url, no json is parsed from the feed module.

    I’ve attempted to rewrite the request portion of the 'helper module", several different ways to parse the json from the url properly, but alas no joy.
    My brain hurts now from reading so much Stackoverflow… lol!
    I have two questions that might help me:

    1. is there a log available for MM, or a way to show the console readout, to help search for errors.

    2. Does the version of Nodejs that the MM is built on allow for async/await operators in functions? If not does anyone have an example of using promises in module development to return a long-running task and have the information return back to the modules primary js file, to display on the mirror?

    Many thanks,

    chef



  • @chef Hi Chef!

    Yes, I recently had the same “issues”. Pretty much everything using/parsing JSON are Promises, almost by default, but listen to this. You can probably ignore most of this, including any async/await stuff. Please look how my Flights module is parsing the promises from the API. If not there, look at the api itself. In addition you might even wanna use the Tabulator thing for your own purpose.



  • Thank you for the direction. It would seem that after a full day of mucking about, I have finally got it. Horray!
    Emby Media Server now has a place on my mirror.

    I’ll have to go tell the guys over there about. I have a feeling this Magic Mirror might catch on over there, especially now that there will be an official Emby plugin for it.

    Thank you again @E3V3A for taking the time to show some direction.

    Chef