Network API• 仕様が固まり、実装がすすんでいるもの • Online / offline state • XMLHttpRequest (XHR) • Sever Sent Event • WebSocket• 使用策定中 • Network Information API
19.
On-line state• Check current network state if (navigator.onLine) { // network is online }• event window.addEventListener(“online”, function() { // network status changes to online }, true);
20.
Server Sent Event• 定期的にサーバーと通信を行う• Cross Domain Acessは現在規格制定中 • おそらく、XHRと同様になる
21.
Server Sent Event (Server)• MIME Type • text/event-stream • クライアント側はAcceptヘッダで送信 • サーバー側はContent-Typeで送信• データ形式 • id: <識別ID> • data: <送信内容> • retry: <ミリ秒> 次の秒後にリクエストを投げるかを指 定
22.
Server Sent Event (client)// http://<server>/events にリクエストvar source = new EventSource("/events");source.addEventLitener( "message", function(e) { document.body.innerHTML += e.data; }, false);
Touch Eventfunction handleStart(event){ var touches = event.changedTouches; var x = touches[0].pageX; var y = touches[0].pageY;}function handleEnd(event) { …}function startup() { var el = document.getElementById("canvas"); el.addEventListener("touchstart", handleStart, false); el.addEventListener("touchend", handleEnd, false); el.addEventListener("touchmove", handleMove, false);}
その他APIs•Personal Information • Contact API – address book • Calendar API – calendar• Communication • Messaging API – email / SMS • P2P• Graphics • Media Query
41.
API for mediaquery• Media Query • 画面の解像度などでCSSを切り替える <link rel="stylesheet" type="text/css" media="screen and (min-device-width: 480px)" href="480px.css“>
42.
API for mediaquery• MatchMedia • DOMでmedia queryを利用する if (window.matchMedia( "(min-device-width: 400px)").matches) { // min-device-width < 400px } else { } // イベントリスナ形式 window.matchMedia( "(min-width: 400px)").addListener( function() { });
43.
APIs•セキュリティを考慮すべき場所においては、仕様 策定には非常に慎重 • Contact API • Messaging API• ユーザーに許可を求める方式は正しいのか? • Web Appsに関しては?