Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HTML5 mit WebSockets und node.js im Einsatz

HTML5 mit WebSockets und node.js im Einsatz

Thorsten Rinne

June 03, 2012
Tweet

More Decks by Thorsten Rinne

Other Decks in Technology

Transcript

  1. Thorsten Rinne • 35 Jahre • Diplom-Informatiker (FH) • Senior

    Developer @ Yatego GmbH • Twitter: @ThorstenRinne
  2. Sebastian Springer • 29 Jahre • Diplom-Informatiker (FH) • Senior

    Developer / Team Lead @ Mayflower GmbH • Twitter: @basti_springer
  3. „HTML5 is about moving from documents to applications and from

    hacks to solutions.“ Chris Heilmann (Mozilla) auf Twitter
  4. - Der Browser ist kostenlos - Das Web ersetzt das

    OS - Java bringt Web Apps - 4 Versionen in 7 Jahren - „kostenlos“ mit OS - 1995: 6 Entwickler - 1999: 1000 Entwickler - 6 Versionen in 6 Jahren Netscape verlor den „Krieg“ ...
  5. $sql = ‘SELECT * FROM users‘; $result = $conn->query($sql); vs.

    var query = ‘SELECT * FROM users‘; db.query(query, function(err, results, fields) {...}; );
  6. Webserver Code var http = require(‘http‘); http.createServer( function(req, res) {

    res.writeHead( 200, {‘Content-Type‘: ‘text/plain‘} ); res.end(‘Hello, World‘); }).listen(1337, ‘127.0.0.1‘);
  7. Bibliotheken als NPM • Socket.IO • Backbone.js • Underscore.js •

    express • Common.js • MySQL, redis, CouchDB
  8. WebSockets if ("WebSocket" in window) { var ws = new

    WebSocket("ws://example.com/service"); ws.onopen = function() { // WebSocket is connected. // You can send data by send() method. ws.send("message to send"); // .... }; ws.onmessage = function (evt) { var received_msg = evt.data; }; ws.onclose = function() { // WebSocket is closed }; } else { // the browser doesn't support WebSockets. }
  9. GET /demo HTTP/1.1 Upgrade: WebSocket Connection: Upgrade Host: example.com Origin:

    http://example.com Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5 Sec-WebSocket-Key2: 12998 5 Y3 1 .P00 ^n:ds[4U HTTP/1.1 101 WebSocket Protocol Handshake Upgrade: WebSocket Connection: Upgrade Sec-WebSocket-Origin: http://example.com Sec-WebSocket-Location: ws://example.com/demo Sec-WebSocket-Protocol: sample 8jKS'y:G*Co,Wxa- Client Server
  10. WebWorker var worker = new Worker('backgroundtask.js'); worker.onmessage = function(event) {

    alert(event.data); }; self.onmessage = function(event) { // Do some heavy work self.postMessage('Hello, Berlin'); } backgroundtask.js main.js
  11. <form> <input type="text" name="msg" value="My message" id="msg"> <input type="submit"> <h2>Ziel

    iFrame:</h2> <iframe id="iframe" src="postmessage.html"></iframe> </form> <script> var win = document.getElementById("iframe").contentWindow; addEvent( document.getElementsByTagName('form')[0], 'submit', function (e) { if (e.preventDefault) e.preventDefault(); win.postMessage(document.getElementById("msg").value, "http://phpconference.de"); e.returnValue = false; return false; }); </script> WebMessaging
  12. Geolocation if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( function(position) { var lat =

    position.coords.latitude; var lng = position.coords.longitude; var options = { position: new google.maps.LatLng(lat, lng) } var marker = new google.maps.Marker(options); marker.setMap(map); }); }
  13. Web Storage ‣„kurzlebige“ Daten ‣sessionStorage Object ‣wird beim Schließen des

    Browsers gelöscht ‣„langlebige“ Daten ‣localStorage Objekt ‣wird nicht beim Schließen des Browsers gelöscht ‣produziert File I/O, läuft synchron Safari/Chrome Firefox IE Opera 2 MB 5 MB ~ 200MB 5 MB 4 MB
  14. Web Storage <p>This page was requested <b> <script> if (!sessionStorage.pageCounter)

    { sessionStorage.setItem('pageCounter',0); } sessionStorage.setItem('pageCounter', parseInt(sessionStorage.pageCounter)+1); document.write(sessionStorage.pageCounter); </script> </b> times.</p> <p> <input value="sessionStorage leeren" type="button" onClick="sessionStorage.clear();location.reload(true);"> <input value="Seite laden" type="button" onClick="location.reload(true);"> </p>
  15. <link rel="alternate" type="application/atom+xml" title="My Weblog feed" href="http://www.phpconference.de/feed/"> <link rel="search" type="application/opensearchdescription+xml"

    title="My Weblog search" href="http://www.phpconference.de/opensearch.xml"> <link rel="icon" href="/favicon.ico"> <link rel="pingback" href="http://www.phpconference.de/xmlrpc.php"> <link rel="prefetch" href="http://www.phpconference.de/main.php"> <link rel="archives" href="http://www.phpconference.de/archive/"> <link rel="external" href="http://www.php.net"> <link rel="license" href="http://www.gnu.org/licenses/gpl.html"> <link rel="nofollow" href="http://www.ruby-lang.org">
  16. HTML 5 Microdata sind maschinenlesbare Daten in HTML. <div itemscope>

    <p> Mein Name ist <span itemprop="name">Thorsten</span>. </p> </div>
  17. Browser Support WOFF TTF OTF EOT SVG Safari Chrome Firefox

    IE Opera iOS x x x x x x x x x x x x x x x
  18. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do

    eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Multi-column layouts
  19. 30 % 64 % 64 % 69 % 69 %

    79 % IE9 Mobile Safari Safari 5.1 Firefox 12 Opera 11.6 Chrome 19
  20. Was uns 2012 noch erwartet... • Internet Explorer 10 mit

    Windows 8 (64% HTML5 Support) • Safari 5.2 mit OS X Mountain Lion (74% HTML5 Support) • Opera 12 (72% HTML5 Support) • viele neue Chrome- und Firefox-Versionen • Chrome on Android im TV • evtl. Mobile Safari im TV
  21. • CSS Pre-Processor • sehr nahe am CSS Syntax •

    Erweiterung zu CSS • nach dem DRY Schema entworfen
  22. a { background: #f00; color: #fff; display: block; &:hover {

    background: #05761d; } &:visited { background: #fffc00; } } a { background: #f00; color: #fff; display: block; } a:hover { background: #05761d; } a:visited { background: #fffc00; } Nesting
  23. .tweets { background: #f00; ul { color: #fff; } li

    { display: block; } } .tweets { background: #f00; } .tweets ul { color: #fff; } .tweets li { display: block; } Nesting
  24. // Grays @black: #000; @grayDarker: #222; @grayDark: #333; @gray: #555;

    @grayLight: #999; @grayLighter: #eee; @white: #fff; Variables
  25. .module() { background: #fff; color: rgb(45, 45, 45); font-size: 14px;

    padding: 12px; } .rounded(@radius: 5px) { -webkit-border-radius: @radius; -moz-border-radius: @radius; -o-border-radius: @radius; -ms-border-radius: @radius; border-radius: @radius; } Mixins
  26. Kontakt Sebastian Springer sebastian.springer@mayflower.de Mayflower GmbH Mannhardtstr. 6 80538 München

    Deutschland @basti_springer https://github.com/sspringer82 Thorsten Rinne [email protected] Yatego GmbH Kobellstr. 15 80336 München Deutschland @ThorstenRinne https://github.com/thorsten