Web Technologies VU (706.704)
Total Page:16
File Type:pdf, Size:1020Kb
Web Technologies VU (706.704) Vedran Sabol ISDS, TU Graz Nov 09, 2020 Vedran Sabol (ISDS, TU Graz) Web Technologies Nov 09, 2020 1 / 68 Outline 1 Introduction 2 Drawing in the Browser (SVG, 3D) 3 Audio and Video 4 Javascript APIs 5 JavaScript Changes Vedran Sabol (ISDS, TU Graz) Web Technologies Nov 09, 2020 2 / 68 HTML5 - Part II Web Technologies (706.704) Vedran Sabol ISDS, TU Graz Nov 09, 2020 Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 3 / 68 Drawing in the Browser (SVG, 3D) SVG Scalable Vector Graphics (SVG) Web standard for vector graphics (as opposed to canvas - raster-based) Declarative style (as opposed to canvas rendering - procedural) Developed by W3C (http://www.w3.org/Graphics/SVG/) XML application (SVG DTD) http://www.w3.org/TR/SVG11/svgdtd.html SVG is supported by all current browsers Editors Inkscape and svg-edit (Web App) Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 4 / 68 Drawing in the Browser (SVG, 3D) SVG Features Basic shapes: rectangles, circles, ellipses, path, etc. Painting: filling, stroking, etc. Text Example - simple shapes Grouping of basic shapes Transformation: translation, rotation, scale, skew Example - grouping and transforms Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 5 / 68 Drawing in the Browser (SVG, 3D) SVG Features Colors: true color, transparency, gradients, etc. Clipping, masking Filter effects Interactivity: user events Scripting, i.e. JavaScript, supports DOM Animation: attributes, transforms, colors, motion (along paths) Raster images may be embedded (JPEG, GIF, ...) Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 6 / 68 Drawing in the Browser (SVG, 3D) SVG Examples and Tutorials Geoinformation systems: Yosemiti Further resources W3C SVG Reference MDN SVG Element Reference SVG Basics Tutorial SVG Tutorial Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 7 / 68 Drawing in the Browser (SVG, 3D) 3D in browser Many less successful approaches in the past: VRML, Java3D Separate projects by Google, Mozilla and others Khronos Group: Google, Mozilla, Apple, Opera etc (120 members) WebGL: based on OpenGL ES 2.0 (OGL subset) Javascript interface to OpenGL Since OpenGL drivers are installed everywhere ! browser native 3D without plugins WebGL uses canvas element for the graphics context Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 8 / 68 Drawing in the Browser (SVG, 3D) WebGL: examples WebGL examples 22 Experimental WebGL Demo Examples Three.js library: adds a scene graph layer incl. utilities Three.js examples Quake 2 Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 9 / 68 Drawing in the Browser (SVG, 3D) WebGL Good browser support by all browsers in the latest version (incl. mobile) 3D applications possible using WebGL and other HTML5 technologies Shader support (except compute shaders) WebGL 2 (since 2017) based on OGL ES 3.0 Support only by Chrome, Firefox and Opera Further reading Learning WebGL WebGL Tutorial WebGL Fundamentals Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 10 / 68 Audio and Video Video and Audio New elements for video and audio It works only if the format is compatible and if the codecs are integrated in the browser Format wars H.264 (MPEG-4 AVC) most commonly used video format covered by patents (MPEG LA) supported by (almost) all browser-platform combinations Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 11 / 68 Audio and Video Video and audio Initially recommended format Ogg (Theora - video, Vorbis - audio) Free and open protocols (Xiph.Org foundation) not supported by Microsoft IE and Apple WebM avoids MPEG LA patents originaly VP8 - video, Vorbis - audio recently updated to VP9 - video, Opus - audio Royalty-free, open video and audio for HTML5 Support by Google, Opera, Mozilla Partial support by Edge and Safari Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 12 / 68 Audio and Video Video Specify multiple sources in different formats, browser picks format Not advisable: browser detection - complicated, error prone (versions, platforms) ... <video poster="video.jpg" width="640" height="360" controls> <source src="video.mp4" type="video/mp4" /> <source src="video.webm" type="video/webm" /> <source src="video.ogv" type="video/ogg" /> Browser does not support HTML5 video. </video> ... Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 13 / 68 Audio and Video Video: further info and examples As with any other element you can use Javascript to manipulate the element (script your own controls) You can use CSS to style videos, etc. Attributes: autoplay, controls, loop, muted, poster YouTube - browser support YouTube example Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 14 / 68 Audio and Video Audio ... <audio> <source src="test.mp3" type="audio/mpeg" /> <source src="test.ogg" type="audio/ogg" /> </audio> ... Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 15 / 68 Audio and Video Audio: further info and examples Similarly to video you can manipulate the audio element with Javascript and CSS JPlayer, JPlayer Audio Cross-platform, open source player library for HTML5 with Flash fallback, if video and audio tags not supported Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 16 / 68 Javascript APIs HTML5 and Javascript HTML5 is not only markup but combination of markup, presentation (CSS3) and behavior (Javascript) New Javascript APIs Evolved in the last 10 years of the Web development Possibility to write Web Apps Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 17 / 68 Javascript APIs APIs Geolocation: retrieve geographical location (subject to user approval) AppCache: specify which files to cache (available when offline) FileSystem API: access to a sandboxed file system Storage APIs: go far beyond what is possible with cookies Web Storage, Web SQL, Indexed DB Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 18 / 68 Javascript APIs APIs Web Workers: background running scripts WebSocket: bi-directional communication protocol Drag & Drop History: API for manipulating browser history Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 19 / 68 Javascript APIs Geolocation Collects all available location information WLAN, GSM, (mobile) Internet provider Retrieves the geographical coordinates latitude, longitude, accuracy (optionally: altitude, speed, heading) Forward that info to a Geo data provider, e.g. Google Maps Applications, e.g. find local information Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 20 / 68 Javascript APIs Geolocation Privacy concerns However, browsers typically ask for permissions Better protection of privacy then e.g. smartphones Example if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(myPos) { ... } } Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 21 / 68 Javascript APIs AppCache Standard browser cache unreliable AppCache: makes Web applications accessible offline Possibility to specify which files should (or should not) be cached Advantages Faster browsing as cached resources are served locally Reduced server and network load Offline browsing of the full site Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 22 / 68 Javascript APIs AppCache To enable the cache for your application you need to specify manifest attribute in every HTML page you want to cache <html manifest="example.appcache"> ... </html> Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 23 / 68 Javascript APIs AppCache In the manifest file you specify which files to cache CACHE MANIFEST index.html stylesheet.css images/logo.png scripts/main.js Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 24 / 68 Javascript APIs AppCache CACHE MANIFEST CACHE: /favicon.ico index.html stylesheet.css images/logo.png scripts/main.js NETWORK: login.php /myapi http://api.twitter.com FALLBACK: /main.py /static.html images/large/ images/offline.jpg *.html /offline.html Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 25 / 68 Javascript APIs AppCache Cached content will be shown until until one of the following happens Cache is cleared (user) Manifest file is changed on the server (comment change will do) Programatically via API check update is ready, swap cache, reload page Further Reading var appCache = window.applicationCache; appCache.update(); ... if (appCache.status == window.applicationCache.UPDATEREADY) { appCache.swapCache(); window.location.reload(); } Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 26 / 68 Javascript APIs FileSystem API Files and directories: creating, navigating, writing, reading, renaming, moving, deleting etc. Complex, powerful API As of today full support in Chrome and recently Opera Access to a sandboxed section of the user's local file system Web apps cannot see each other files or the native file system Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 27 / 68 Javascript APIs FileSystem API Access to a sandboxed file system: LocalFileSystem API LocalFileSystem asynchronous API (and LocalFileSystemSync synchronous API for WebWorkers) Implemented by Window (and WorkerGlobalScope) Create (TEMPORARY or PERSISTENT) storage of requested size window.requestFileSystem(type, size, onInit, onError) Vedran Sabol (ISDS, TU Graz) HTML5 - Part II Nov 09, 2020 28 / 68 Javascript APIs FileSystem API Navigating directory structure DirectoryReader: read the entries in a directory FileEntry, DirectoryEntry: represents a file/directory, properties, manipulation (remove, copy, move...) Support by Chrome and Opera (W3C stopped standardization)