Skip to content

FIX for refresh issue #2

Open
Open

Description

@kevsfastz

EDIT: After some testing with below it appears some URLs will not load after adding numbers such as the date and time suggested below. Adding a ? at the end of the URL appears to be a simple workaround.

It appears this happens to URL's that do not change when refreshed. I corrected the refresh issue by adding + new Date().getTime(); after the URL in the .js file:

`Module.register("MMM-iFrameReload",{
// Default module config.
defaults: {
url: "",
height:"800px",
width:"400%",
refreshInterval: 3600,
animationSpeed: 1000
},

// Define start sequence.
start: function() {
	Log.info("Starting module: " + this.name);
	this.scheduleUpdate(this.config.refreshInterval);
},
// Override dom generator.
getDom: function() {
	var iframe = document.createElement("IFRAME");
	iframe.style = "border:0"
	iframe.width = this.config.width;
	iframe.height = this.config.height;
	iframe.src =  this.config.url + new Date().getTime();
	return iframe;
},
scheduleUpdate: function(delay) {
	var nextLoad = this.config.refreshInterval;
	if (typeof delay !== "undefined" && delay >= 0) {
		nextLoad = delay * 1000; // Convert seconds to millis
	}
	var self = this;
	setTimeout(function() {
		self.updateFrame();
	}, 30000);
	},
updateFrame: function() {
	if (this.config.url === "") {
		Log.error("Tried to refresh, iFrameReload URL not set!");
		return;
	}
	// Change url to force refresh?
	this.src = this.config.url;
	Log.info("attempting to update dom for iFrameReload");
	Log.info('/"this/" module is: ' + this);
	this.updateDom(this.config.animationSpeed);
	this.scheduleUpdate(this.config.refreshInterval);
}

});`

Activity

  1. Cyan-Kali commented on Mar 10, 2017

    @Cyan-Kali

    Hi,

    I tried the fixes you suggested but nothing seems to work. I don´t think the module reloads at all. I set the update interval to 60 and the animation speed to 4000, but I never saw an animation. I now nothing about coding, I just go by trial and error. So here is what I did already:

    First I tried:
    adding
    iframe.src = this.config.url + new Date().getTime();
    in the section
    // Override dom generator.

    as you did in the example.
    After that, the stream does not load at all (I see only a rectangle).

    Then I tried:
    Adding "+ new Date().getTime();" to the other url in the js file:
    // Change url to force refresh?
    this.src = this.config.url + new Date().getTime();
    Now I see the stream again, but it does not seem to reload.

    Then I tried:
    the solution with adding the "?" to the url:
    First try:
    iframe.src = this.config.url?;
    in the section
    // Override dom generator.
    Again, this broke the stream (I see only a rectangle).

    Then I tried:
    // Change url to force refresh?
    this.src = this.config.url?;
    Now I see nothing at all, not even the rectangle.

    I´m sure I´m doing something wrong, can you tell me, what it is?
    I am trying to embed a foscam camera stream into my mirror by the way.

  2. fewieden commented on Apr 2, 2017

    @fewieden

    put iframe.setAttribute("timestamp", new Date().getTime()); between line 32 and 33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions