Remote.js远程控制库

联合创作 · 2023-09-22 10:58

Remote.js 是一个用来开发远程控制web应用程序的 JavaScript 库,无需额外的硬件支持。


可能的用途:



  1. Media controls


  2. Games - remote controlled, multi-player


  3. Slideshows


  4. Pranks


  5. Malware


  6. 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');
});
浏览 26
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报