Giter Site home page Giter Site logo

Increasing intervals about teleframe HOT 10 CLOSED

call-me-matt avatar call-me-matt commented on May 28, 2024 1
Increasing intervals

from teleframe.

Comments (10)

gegu avatar gegu commented on May 28, 2024 1

I'd enjoy it.

Thought about the description in the wiki

You can edit the Wiki page yourself 😃

PS: You re-opened the issue?

Yes, because @LukeSkywalker92 has marked the extension as a enhancement and I also think it's a feature that is interesting for everyone. I am currently looking for an easy way to install addons that are interesting for everyone. There are some ideas already, but not yet fully realized.
So that the topic is not forgotten, I have reopened the issue.

from teleframe.

call-me-matt avatar call-me-matt commented on May 28, 2024

Here is a first implementation in form of an addon:
Any comments?
How should I submit my code?

/**
 * introduces quicker image changes after interactions and slows down with time
 * @param  {AddonBase inherited} interface   object to register and send events
 */

// import interval from config.json
var fs = require('fs');
var configfile = fs.readFileSync("./config/config.json", "utf8");
var config = JSON.parse(configfile);
var maxInterval = (config.interval) ? config.interval:45000;
const additionalChanges = (config.imageCount) ? config.imageCount:30;
var counter = 1;

const functionFlexIntervals = (interface) => {

  //interface.registerListener('newImage', (sender, type) => counter = 1);

  interface.registerListener('images-loaded', () => counter = 1);

  interface.registerListener('imageDeleted', () => counter = 1);

  interface.registerListener('paused', (status) => counter = 1);

  interface.registerListener('muted', (status) => counter = 1);

  interface.registerListener('recordStopped', () => counter = 1);

  interface.registerListener('unstarImage', index => counter = 1);

  interface.registerListener('starImage', index => counter = 1);

  interface.registerListener('changedActiveImage', index => {
        // introduce an additional picture change:
        if (counter < additionalChanges) {
		var additionalChange = Math.round(maxInterval*counter/additionalChanges);
                interface.logger.info("additional change in: " + additionalChange);
		setTimeout(() => { interface.sendEvent('next'); }, additionalChange);
		counter += 1;
	};
  });
};

/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {
  module.exports = functionFlexIntervals;
}

from teleframe.

gegu avatar gegu commented on May 28, 2024

Nice idea, exactly for these requirements the addon interface was implemented.

A few hints:
You do not need to read the configuration file itself. The configuration is provided by the addon interface and all keys have a valid value. So you can access the values directly.

For example:

//...


const functionFlexIntervals = (interface) => {
  var config;
  var counter = 1;

  interface.registerListener('teleFrame-ready', teleFrameObjects => {
    config = teleFrameObjects.config;
  });

//...

  interface.registerListener('changedActiveImage', index => {
    // introduce an additional picture change:
    if (counter < config.imageCount) {
      var additionalChange = Math.round(config.interval*counter/config.imageCount);
      interface.logger.info("additional change in: " + additionalChange);
      setTimeout(() => { interface.sendEvent('next'); }, additionalChange);
      counter += 1;
    };
  });

How should I submit my code?

Please create a repository for the addon yourself and we will link it on the Available TeleFrame addons - wiki page.

from teleframe.

call-me-matt avatar call-me-matt commented on May 28, 2024

Cool!
Here you go:
https://github.com/call-me-matt/teleframe-flexintervals

from teleframe.

gegu avatar gegu commented on May 28, 2024

It' s done.

from teleframe.

gegu avatar gegu commented on May 28, 2024

Another little hint:
You can specify the events you want to listen to using an array if you want to do the same thing every time.

interface.registerListener([
  'images-loaded', 'imageDeleted', 'paused', 'muted', 
  'recordStopped', 'unstarImage', 'starImage'
], index => counter = 1);

from teleframe.

call-me-matt avatar call-me-matt commented on May 28, 2024

Thank you so much for your help.
I really like this addon-interface.

Thought about the description in the wiki, maybe "introduces quicker image changes which slow down with time" is a catchier description.

PS: You re-opened the issue?

from teleframe.

call-me-matt avatar call-me-matt commented on May 28, 2024

is there a way to detect if a picture or video is shown?
(call-me-matt/teleframe-flexintervals#3)

from teleframe.

gegu avatar gegu commented on May 28, 2024

I suppose you've noticed the problem with video playback time. It almost drove me crazy yesterday, too.

You can use interface.images[index].src to check for .mp4

These changes should solve the problem

@@ -68,13 +68,16 @@ const functionFlexIntervals = (interface) => {
     }
     const additionalChange = Math.max(minChangeTime, Math.round(config.interval*counter/config.imageCount));
     nextChangeTime = new Date().getTime() + additionalChange;
     // introduce an additional picture change:
     if (!isPaused && counter < config.imageCount) {
-      setChangeTimer(additionalChange);
+      // ignore videos because the duration is unknown
+      if (!interface.images[index].src.match(/\.mp4$/i)) {
+        setChangeTimer(additionalChange);
+      }
       counter += 1;
-    };
+    }
   });
 };

from teleframe.

call-me-matt avatar call-me-matt commented on May 28, 2024

Great, thank you

from teleframe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.