Remote.js远程控制库
Remote.js 是一个用来开发远程控制web应用程序的 JavaScript 库,无需额外的硬件支持。
可能的用途:
-
Media controls
-
Games - remote controlled, multi-player
-
Slideshows
-
Pranks
-
Malware
-
Interesting browser extensions
数据发射器:
var signals = ['cat', 'HIDE CONTENT', 'github']; var t = Remote.transmitter(signals); // ideally, signals would be emitted when buttons are clicked document.querySelector('#cat-button').addEventListener('click', function() { t.emit('cat'); }); document.querySelector('#github-button').addEventListener('click', function() { t.emit('github'); }); // signals can be emitted any way you like, though setTimeout(function() { t.emit('foo'); }, 5000);
接收器:
var signals = ['cat', 'HIDE CONTENT', 'foo']; var r = Remote.receiver(signals); r.on('cat', function(error, signal) { if (!error) alert('Cats are mini-Tigers!'); }); r.on('HIDE CONTENT', function(error, signal) { document.querySelector('#content').style.display = 'none'; }); r.on('github', function(error, signal) { window.open('https://github.com'); });
评论