25.02.2013 Views

Peter Lubbers - Pro HTML 5 Programming

Pro HTML 5 Programming

Pro HTML 5 Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

266<br />

CHAPTER 11 ■ THE FUTURE OF <strong>HTML</strong>5<br />

Unlike the other mobile device events, the touch events need to represent that there are multiple<br />

points of data—the many potential fingers—present at the same time. As such, the API for touch<br />

handling is a little bit more complex as shown in Listing 11-2.<br />

Listing 11-2. Touch API<br />

function touchMove(event) {<br />

// the touches list contains an entry for every finger currently touching the screen<br />

var touches = event.touches;<br />

// the changedTouches list contains only those finger touches modified at this<br />

// moment in time, either by being added, removed, or repositioned<br />

varchangedTouches = event.changedTouches;<br />

// targetTouches contains only those touches which are placed in the node<br />

// where this listener is registered<br />

vartargetTouches = event.targetTouches;<br />

// once you have the touches you'd like to track, you can reference<br />

// most attributes you would normally get from other event objects<br />

varfirstTouch = touches[0];<br />

varfirstTouchX = firstTouch.pageX;<br />

varfirstTouchY = firstTouch.pageY;<br />

}<br />

// register one of the touch listeners for our example<br />

node.addEventListener("touchmove", touchMove, false);<br />

You may find that the device’s native event handling interferes with your handling of the touch and<br />

gesture events. In those cases, you should make the following call:<br />

event.preventDefault();<br />

This overrides the behavior of the default browser interface and handles the event yourself. Until the<br />

mobile events are standardized, it is recommended that you consult the documentation of the devices<br />

you are targeting with your application.<br />

Peer-to-Peer Networking<br />

We haven’t seen the end of advanced networking in web applications either. With both HTTP and<br />

WebSocket, there is a client (the browser or other user agent) and a server (the host of the URL). Peer-topeer<br />

(P2P) networking allows clients to communicate directly. This is often more efficient than sending<br />

all data through a server. Efficiency, of course, reduces hosting costs and improves application<br />

performance. P2P should make for faster multiplayer games and collaboration software.<br />

Another immediate application for P2P combined with the device element is efficient video chat in<br />

<strong>HTML</strong>5. In peer-to-peer video chat, conversation partners would be able to send data directly to each<br />

other without routing through a central server. Outside of <strong>HTML</strong>5, P2P video chat has been wildly<br />

popular in applications like Skype. Because of the high bandwidth required by streaming video, it is<br />

likely that neither of those applications would have been possible without peer-to-peer communication.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!