Last active
May 3, 2016 13:44
-
-
Save peaBerberian/761305f1901711833f0ab9b8351afa0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Brainstorm pour l'ecoute de la remote | |
// ---- Remote instanciation | |
const remote = new RemoteListener(); | |
// RemoteListener being a class with the method listen (only method?) | |
// ---- Remote calls | |
// wip | |
// Listening to remote keys via the listen method. | |
// for 1..n arguments: | |
// | |
// - n argument is an object representing the options | |
// if not an object, no filter. We redirect every event for the chosen | |
// key | |
// if we have an object, we begin to filter. Even if nothing is put in | |
// it. | |
// | |
// - if argument n is an object, the 1 to n-1 arguments must be the key | |
// names. | |
// if argument n is not an object, the 1 to n arguments must be the key | |
// names. | |
// if not specified, every keys is listened with the specified options. | |
// Complex example with 3 keys and every option set | |
remote.listen('Forward', 'Rewind', 'Exit', { | |
// events to listen to (keyup or keydown). | |
// Can be a single string or an array | |
// Default: listen to nothing | |
events: ['push', 'release'], | |
// listen to when keys are pressed with a given interval. | |
// Default: we don't listen to them. | |
press: { | |
// if key still pressed after 500ms emit a 'keypress'. | |
// Default: 0ms | |
after: 500, | |
// emit the 'keypress' every 100ms after these 500ms | |
// Default: No interval, only on after if press is defined. | |
interval: 100 | |
} | |
}); | |
// ---- Remote object response: | |
// keypress | |
{ | |
// name of the key pressed | |
keyName: 'Forward', | |
// event (push | release | press) | |
event: 'press', | |
// amount of time the key has been pressed (multiple of the throttle | |
// argument) | |
// 0 for keydown | |
// Could also be something like occurence: 5 if the throttle is 100ms, I | |
// don't know. | |
timepress: 500 | |
} | |
// keydown | |
{ | |
keyName: 'Forward', | |
event: 'push', | |
timepress: 0 | |
} | |
// keyup | |
{ | |
keyName: 'Forward', | |
event: 'release', | |
timepress: 1000 | |
} | |
// Real life example | |
// simple case: pump up the volume on keydown, no press: | |
remote.listen('VolUp', { | |
events: 'push' | |
}).subscribe(() => { | |
raiseVolume(); | |
}); | |
// medium case: raise volume on keydown, with 'press' event sent every 50ms | |
// from 400ms | |
remote.listen('VolUp', { | |
events: 'push', | |
press: { | |
after: 400, | |
interval: 50 | |
} | |
}).subscribe(() => { | |
raiseVolume(); | |
}); | |
// complex case: fast forwarding with multiple levels | |
remote.listen('Forward', { | |
press: [ | |
{ | |
after: 100, | |
interval: 500 | |
}, | |
{ | |
after: 500, | |
interval: 100 | |
} | |
] | |
}).subscribe((keyEvt) => { | |
const { timepress } = keyEvt; | |
if (timepress < 100) { | |
onShortForward(); | |
} else if (timepress < 500) { | |
onMediumForward(); | |
} else if (timepress < 1000) { | |
onLongForward(); | |
} else { | |
onVeryLongForward(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment