ウェブ標準デバイス系 api 総集編 2014
TRANSCRIPT
@futomi futomi.hatano
•
•
•
(function watchGamepad() {var gamepads = navigator.getGamepads();var buttons = gamepads[0].buttons;// Do somethingwindow.requestAnimationFrame(watchGamepad);
})();
••
•
•
•
••
•
navigator.requestMIDIAccess().then(function(midiaccess) {
// 出力ポートのMIDIPort(MIDIOutput)オブジェクトを取得var output_list = midiaccess.outputs();var output = output_list[0];// MIDIメッセージ送信 (ノートオン, チャネル0, ド(C4)の音, ベロシティ70)output.send(new Uint8Array([144, 60, 70]));
},function() { console.log("Error"); }
);
1
メッセージ値 チャネル番号
ステータスバイト
0
ノート番号
0
ベロシティ
128以上 127以下 127以下
•
•
••
••
var hello = new NDEFRecordText("hello world", "en-US", "UTF-8");
navigator.nfc.ontagfound = function(e) {window.console.log('NFC Tag found!');var tag = 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);
•
// 1navigator.vibrate(1000);
// 1 2 0.5navigator.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