@futomi 
futomi.hatano
• 
• 
•
(function watchGamepad() { 
vargamepads = navigator.getGamepads(); 
varbuttons = gamepads[0].buttons; 
// Do something 
window.requestAnimationFrame(watchGamepad); 
})();
• 
• 
• 
• 
• 
• 
• 
•
navigator.requestMIDIAccess().then( 
function(midiaccess) { 
// 出力ポートのMIDIPort(MIDIOutput)オブジェクトを取得 
varoutput_list= midiaccess.outputs(); 
varoutput = output_list[0]; 
// MIDIメッセージ送信(ノートオン, チャネル0, ド(C4)の音, ベロシティ70) 
output.send(new Uint8Array([144, 60, 70])); 
}, 
function() { console.log("Error"); } 
); 
1 
メッセージ値 
チャネル番号 
ステータスバイト 
0 
ノート番号 
0 
ベロシティ 
128以上 
127以下 
127以下
• 
•
• 
• 
• 
•
varhello = new NDEFRecordText("hello world", "en-US", "UTF-8"); 
navigator.nfc.ontagfound= function(e) { 
window.console.log('NFC Tag found!'); 
vartag = e.tag; 
tag.writeNDEF(new NDEFMessage([hello])); 
} 
navigator.nfc.startPoll().catch( 
function(e) { 
window.console.error(e); 
});
• 
• 
• 
• 
• 
• 
• 
•
• 
• 
• 
navigator.geolocation.getCurrentPosition(function(pos) { 
console.log("緯度: " + pos.coords.latitude); 
console.log("経度: " + pos.coords.longitude); 
console.log("GPS高度: " + pos.coords.altitude); 
});
• 
•
• 
• 
•
• 
• 
window.addEventListener("devicelight", function(event) { 
console.log(event.value+ " ルクス"); 
}, false);
• 
// 物体の接近検知 
window.addEventListener("userproximity", function(event) { 
if(event.near=== true) {console.log("物体が接近");} 
}, false); 
// 物体までの距離検知 
window.addEventListener("deviceproximity", function(event) { 
console.log("距離: " + event.value+ " cm); 
}, false);
• 
// 1 
navigator.vibrate(1000); 
// 120.5 
navigator.vibrate([1000, 500, 1000]); 
// 
navigator.vibrate(0);
• 
navigator.battery.addEventListener("levelchange", function() { 
console.log(":" + navigator.battery.level); 
}, false); 
navigator.battery.addEventListener("chargingchange", function() { 
if(navigator.battery.charging=== true) { 
console.log(""); 
} 
}, false);
• 
• 
• 
• 
• 
•
• 
• 
• 
• 
• 
• 
• 
• 
•
• 
• 
• 
• 
• 
• 
• 
• 
•
• 
• 
• 
•
@futomi 
futomi.hatano

ウェブ標準デバイス系 API 総集編 2014

  • 1.
  • 3.
  • 6.
    (function watchGamepad() { vargamepads = navigator.getGamepads(); varbuttons = gamepads[0].buttons; // Do something window.requestAnimationFrame(watchGamepad); })();
  • 7.
    • • • • • • • •
  • 8.
    navigator.requestMIDIAccess().then( function(midiaccess) { // 出力ポートのMIDIPort(MIDIOutput)オブジェクトを取得 varoutput_list= midiaccess.outputs(); varoutput = output_list[0]; // MIDIメッセージ送信(ノートオン, チャネル0, ド(C4)の音, ベロシティ70) output.send(new Uint8Array([144, 60, 70])); }, function() { console.log("Error"); } ); 1 メッセージ値 チャネル番号 ステータスバイト 0 ノート番号 0 ベロシティ 128以上 127以下 127以下
  • 9.
  • 11.
  • 12.
    varhello = newNDEFRecordText("hello world", "en-US", "UTF-8"); navigator.nfc.ontagfound= function(e) { window.console.log('NFC Tag found!'); vartag = e.tag; tag.writeNDEF(new NDEFMessage([hello])); } navigator.nfc.startPoll().catch( function(e) { window.console.error(e); });
  • 13.
    • • • • • • • •
  • 15.
    • • • navigator.geolocation.getCurrentPosition(function(pos) { console.log("緯度: " + pos.coords.latitude); console.log("経度: " + pos.coords.longitude); console.log("GPS高度: " + pos.coords.altitude); });
  • 16.
  • 17.
  • 18.
    • • window.addEventListener("devicelight",function(event) { console.log(event.value+ " ルクス"); }, false);
  • 19.
    • // 物体の接近検知 window.addEventListener("userproximity", function(event) { if(event.near=== true) {console.log("物体が接近");} }, false); // 物体までの距離検知 window.addEventListener("deviceproximity", function(event) { console.log("距離: " + event.value+ " cm); }, false);
  • 20.
    • // 1 navigator.vibrate(1000); // 120.5 navigator.vibrate([1000, 500, 1000]); // navigator.vibrate(0);
  • 21.
    • navigator.battery.addEventListener("levelchange", function(){ console.log(":" + navigator.battery.level); }, false); navigator.battery.addEventListener("chargingchange", function() { if(navigator.battery.charging=== true) { console.log(""); } }, false);
  • 22.
    • • • • • •
  • 24.
    • • • • • • • • •
  • 25.
    • • • • • • • • •
  • 26.
  • 27.