среда, 20 марта 2013 г.

Building Vyclone's Interactive Experience with HTML5


uilding Vyclone's Interactive Experience with HTML5
The Web is more engaging and productive for consumers, as developers unlock the full potential of HTML5. In this guest blog post, Anton Molleda of Plain Concepts talks about his experience and learnings while developing Vcylone, a social video editing experience built on HTML5 and many of the new features in next generation browsers like Internet Explorer 10. Vcyclone builds on capabilities like pointer events, multi-touch gestures, and hardware accelerated canvas and CSS3 to make this Web site feel more like an app.
— Rob Mauceri, Group Program Manager, Internet Explorer
Hello everyone,
My name is Anton Molleda and I work for Plain Concepts. These last few months the team at Internet Explorer has been collaborating with the awesome crew that makes up the hot up and coming social video startup Vyclone. As a Web developer, having the opportunity to push the envelope with what the Web can do is one of my passion points. Fortunately, I’ve been lucky enough to help out on this project. And today, I want to share with you some key learning we had while we worked together to create a video editor on the Web for Vyclone, using just HTML5 and JavaScript!
Vyclone is a social video platform that lets you co-create, sync and edit multiple views of a shared moment, effortlessly.
When Vyclone first started, it solely focused on mobile devices. But soon they realized that while the recording experience is great from a phone, editing that video was limited due to the screen size and power of the device. Thanks to the progress done these last few years in modern browsers, HTML5 was a viable option as the way to go to create this new tool.
The core of Vyclone’s Web editor is composed of three parts:
The video preview: Where a low quality version of the cut the user is creating can be watched (on the left)
The vidgrid: Where all the available sources are presented to the user showing a given point and time (on the right)
And the timeline: Which indicates a linear view of which source is playing over the course of the video. A source playing during a certain amount of time is called a cut (shown above the player controls)
Vyclone's Web editor
As the user plays the video and starts adding new cuts to the timeline, the video preview switches to reflect the new source, and the vidgrid highlights the source file with triangle corners to identify to the user which video is selected.
So in building this out, we ran into a very interesting challenge with sheer amount of video manipulation, the performance we were getting back, and the user experience. Let’s dig into what we did to make this happen on the Web. So we’re using video, canvas and requestAnimationFrame (RAF). We have a video in the background that is played, and in each RAF we draw the active source into a canvas (in the video preview) or we calculate its new size and position into the vidgrid.
So far so good, but what happens when we let the user interact with it? For example, what happens when a user moves the timeline forward and back, or adds / removes video sources (cuts)? When we first started prototyping this out, we thought the standard approach would be to take care of that as soon as the event is fired - because that's the way we've been taught, right?
But what happens when those events can be fired tens of times per second, or even hundreds of times per second? And what if those handlers need to update the UI? Do we really need to force a layout refresh 130 times per second when the delta change could sometimes be less than a pixel? Talk about performance drag!
If your machine has an i7 with 8GB of RAM, you can probably afford computing power to do that. But what about people with an older rig? Or an ARM device? Those users will not have the same experience and will see the reaction time of the Web site slow way down.
Our first approach was to queue the action in the RAF but there were some problems with this approach, such as, you can RAF up the same function for the same "tick", effectively making things worse. To solve for this, our first approach was to have a variable that will tell us if the action was already queued up. Something like this:
var queued = false;
 
function myAction(){
   //your awesome code here
   queued = false;
}

function onEvent(evt){
   if(!queued){
      queued = true;
      requestAnimationFrame(myAction);
   }
}
This code is not bad but still has some problems. If you are doing something related with the event position (mouse or pointer) and a delta, you might find that you’ll struggle with this approach. The solution we used in the timeline is to accumulate the event value and process it on myAction:
var deltaX = 0,
    queued = false;
 
function myAction(){
   //your awesome code here uses deltaX
   deltaX = 0; // we reset the deltaX so it can be incremented 
               // next time onEvent is executed
   queued = false;
}
 
function onEvent(evt){
   if(!queued){
      queued = true;
      deltaX = evt.translationX; // in the case of a pointer, if you are 
                                 // using a mouse you will have to do some 
                                 // magic with pageX or similar :)
      requestAnimationFrame(myAction);
   }else{
      deltaX += evt.translationX;
   }
}
With this approach you should be pretty much ready to go. We kept adding functionality and then noticed some new problems popped up.
By handling those events when appropriate at each requestAnimationFrame we were able to achieve a higher level of responsiveness without sacrificing computing power. But since requestAnimationFrame executes the functions in the order, they are queued up so sometimes we were drawing before cleaning, or moving the timeline when we didn't have to and we had to create a lot of cumbersome code to make sure it got executed the order we wanted.
We saw that code wasn't very friendly and we were losing some cycles waiting for other actions to be performed so we decided to change again how we handled the input. It was at this moment that we thought about this as a game loop. If you’re not familiar in (simple) game architecture, the game loop is basically a continuous loop that gets executed regardless of the user interaction and splits apart when different events and actions should occur. From the Wikipedia article Game Programming, a simplified game loop in pseudo code could look like this:
while( user doesn't exit )
   check for user input
   run AI
   move enemies
   resolve collisions
   draw graphics
   play sounds
end while
That was exactly what we needed. Taking advantage of RAF we created a tick function that is executed continuously and inside this tick function we decide what we have to do depending on previous user input or other factors.
The simplified tick for the vidgrid is something like this:
   
function tick(){

   //we clean if we've changed the size of the quadrant
   if(needsClean){
      cleanCanvas();
   }

   // if we have to change the quadrant's frame because we are 
   // the active one (or the opposite)
   if(newFrame){
      drawFrame(); // we draw just the frame in a separate canvas so it
                   // doesn't need to be calculated all the time, and it 
                   // is still faster than copying from an image
   }

   //we draw the new frame if we are playing or seeking
   if(dirty){
      draw();
      drawFrameInQuadrant();
   }

   requestAnimationFrame(tick);
}
The values of needsClean, newFrame and dirty are updated on the event handlers (when the user is seeking, video playing, etc.).
It was this shift in the way we thought about the user interactions, going to a game loop mechanic, that allowed us to improve the performance and simplify our code in the editor.
Big takeaways, if you are building something is requires high interactivity and receives a lot of user input, think about how potentially using a game loop can make your life easier! It sure did for us. And if you haven’t had a chance to check out Vyclone’s sexy new Web editor (if I don’t say so myself), get going! Click ‘Remix’ on any video on Vyclone.com and you’ll see our Web editor. It works equally well with mouse or touch input. I highly recommend giving it a go on a Surface Pro!
Enjoy! Hit me up with some comments below if you have any questions!
— Anton Molleda, Plain Concepts

Imagining a More Engaging Web: 3rd Anniversary of IE Test Drive


As developers build on the full capabilities of HTML5, touch, and hardware accelerated graphics, the web today is more engaging for consumers than many imagined. The experiences developers are building today simply were not possible just a few years ago.
Saturday marked the third anniversary of the IE Test Drive site. What started as a few examples of hardware-accelerated HTML5 to help developers imagine the potential of the web, has grown to a collection of over 140 feature-packed demos. Test Drive gives you a taste of what’s possible with HTML5 and modern browsers on modern hardware: HTML5, CSS3, ECMAScript 5, touch, GPU-powered graphics, blazing performance, audio/video, mobile, games, and more.
The support you’ve shown is humbling – over the last three years the Test Drive has received over 130 million page views! That’s more than a page per second for the last three years! We’ve had a lot of fun building the demos, and thought we’d take a look back at some of our favorite demos along the way.
IE Test Drive
The IE Test Drive Site contains over 140 demos!

Demos

Audio ExplosionTouch, see, and hear IE10
CanvasPinballThe perfect work time break
ChalkboardIE10 takes other browsers to school
FishBowlHTML5, CSS3, Video, Audio, Canvas, Fish
FishIEStarted the fish revolution
Flying ImagesOur very first Test Drive!
GalacticOut of this world performance
Hamster Dance RevolutionGet ready to become addicted
Love is in the AirWe love you too
MinesweeperSpeed that’ll make your browser explode
Mr. Potato GunActions speak louder than marketing videos
Psychedelic BrowsingOur “highest” viewed demo after 2am
Speed ReadingHow fast can your browser speed read?
Touch EffectsTouch your way to a faster experience
Tracking ProtectionPutting your privacy first

Looking Ahead

IE10 continues to deliver the best performance for real world Web sites on your Windows device, and the Test Drive is a great place to experience what’s possible yourself. Take the Test Drive for a spin today and let us know what you think!
We’re always excited and humbled by the amazing experiences developers are building on the web every day. Thank you for your continued feedback and for using IE10.
— Jon Aneja, Program Manager, Internet Explorer

среда, 6 марта 2013 г.

W3C Web Performance: Continuing Performance Investments


The W3C Web Performance working group recently held the W3C Workshop on Performance on Thursday, November 8, 2012. The goal was to hear current challenges and proposals for new performance ideas for the working group to consider. There were 45 attendees from 21 organizations, including most browser manufactures (Microsoft, Google, and Mozilla), hardware organizations (Intel, Qualcomm, Nokia, Motorola), network organizations (Cisco, Akamai, F5), and top Web properties (GMail, Google Search, Bing, NetFlix, LinkedIn, Zynga, and more). Details on the presentations and discussions from the workshop can be found in this report.
Providing the ability to accurately measure the performance characteristics of Web applications and create power- and CPU-efficient applications is critical to Web performance. The W3C Web Performance working group worked on achieving those goals in its recently completed second chartered period. In under two years, the working group rapidly standardized and modern HTML5-enabled Web browsers implemented these eight interfaces: Navigation Timing, Resource Timing, User Timing, Performance Timeline, Page Visibility, Timing control for script-based animations, High Resolution Time and Efficient Script Yielding. Internet Explorer 10 is the first browser to support all eight of these new APIs.
The working group has since been focused on gathering data to understand which areas to focus on in its third chartered period. In addition to the Workshop on Performance, the working group has invited performance experts to its weekly conference calls and has broadly surveyed the performance community on ideas.
Based on all the data gathered these past few months, the Web Performance working group has decided to focus on the following areas in the third chartered period:
  • Timing Metrics The working group will continue to improve the Timing interfaces, Navigation Timing,Resource Timing, User Timing and Performance Timeline. For example, we will consider providing Web workers support in the Timing interfaces and including information on video byte ranges in Resource Timing.
  • Efficient Script Yielding The working group will continue to improve on power- and CPU-efficient APIs, like the setImmediate API defined in the Efficient Script Yielding specification.
  • Prerender The working group will standardized the prerender feature which allows navigations to appear almost “instantly” in cases where the browser has high confidence that a user will visit an URL.  The way this feature would work is that the browser will proactively navigate to a Web page in a hidden tab, when it sees the “prerender” link type or has high confidence that user will visit that link. When the user does visit that link, the browser will make the hidden tab visible, giving the perception of instant navigation.
  • Resource Priorities Today, browsers download resources in the priority order that they believe are most efficient in helping the page load occur quickly. However, developers may want to prioritize some resources over others. For example, downloading images above the fold may be of higher priority than those below the fold. Though, developers can give some hints to the browser on download priority, like using the “defer” and “async” attributes in markup, these concepts do not include most resources. To help the browser prioritize downloading resources, the working group is expanding the charter to include interoperable means for developers to give the browser hints on the download priority of resources.
  • Diagnostics Interfaces Developers are interested in learning how to make their Web applications faster and less error prone. The working group is expanding the charter to include interoperable means for developers to get browser diagnostics information on their Web applications. For example, using these interfaces a developer could understand where memory is leaking or what errors users are encountering on their Web applications.
  • Beacon Today, analytics scripts will block the current page from unloading by running in a loop in order to confirm that analytics data has been sent to a Web server. This behavior will delay the navigation to the next page, resulting in user perception of poor performance. To help developers avoid that pattern, the working group is expanding the charter to include an interoperable means for developers to asynchronously transfer data from the browser to a Web server, with a guarantee from the browser that the data will eventually be sent.
  • Display Performance Developers are interested in understanding the performance of their games and animations.
    The working group is expanding the charter to include interoperable means for developers to get frame rate and throughput of the display type of information.
This working group is a great example of how quickly new ideas can become interoperable standards that developers can depend on in modern HTML5-enabled browsers. Together with industry and community leaders who participate in the working group, we hope to continue to make rapid progress on interoperable standards that will benefit developers and everyone who uses the Web.
Jatinder Mann, Internet Explorer, Program Manager

Microsoft Security Bulletin MS12-077 – Critical


This security update resolves three privately reported vulnerabilities in Internet Explorer. The most severe vulnerabilities could allow remote code execution if a user views a specially crafted Web page using Internet Explorer. An attacker who successfully exploited these vulnerabilities could gain the same user rights as the current user. Users whose accounts are configured to have fewer user rights on the system could be less impacted than users who operate with administrative user rights.
This security update is rated Critical for Internet Explorer 9 and Internet Explorer 10 on Windows clients including the Internet Explorer 10 Release Preview for Windows 7 and Windows Server 2008 R2, and Moderate for Internet Explorer 9 and Internet Explorer 10 on Windows servers. This security update has no severity rating for Internet Explorer 6, Internet Explorer 7, and Internet Explorer 8, because the known attack vectors for the vulnerability discussed in this bulletin are blocked in a default configuration. However, as a defense-in-depth measure, Microsoft recommends that customers of this software apply this security update. For more information please see the full bulletin.
Microsoft Security Advisory (2755801) Update for Vulnerabilities in Adobe Flash Player in Internet Explorer 10
Microsoft is also releasing an update for Adobe Flash Player in Internet Explorer 10 on all supported editions of Windows 8, Windows Server 2012, and Windows RT. The update addresses the vulnerabilities in Adobe Flash Player by updating the affected Adobe Flash libraries contained within Internet Explorer 10. For more information please see the full advisory.
Most customers have automatic updating enabled and will not need to take any action because this security update will be downloaded and installed automatically. Customers who have not enabled automatic updating need to check for updates and install this update manually. For information about specific configuration options in automatic updating, see Microsoft Knowledge Base Article 294871.
For administrators and enterprise installations, or end users who want to install this security update manually, Microsoft recommends that customers apply the update immediately using update management software, or by checking for updates using the Microsoft Update service.
— Tyson Storey, Program Manager, Internet Explorer

Update to Alleged Information and Security Issue with Mouse Position Behavior


Over the last few days we’ve seen reports alleging abuse of a browser behavior regarding mouse position. Microsoft is working closely with other companies to address the concern of mouse position movement. From what we know now, the underlying issue has more to do with competition between analytics companies than consumer safety or privacy.
We are actively working to adjust this behavior in IE. There are similar capabilities available in other browsers. Analytics firms can expect to do viewpoint detection in IE similarly to how they do this in other browsers. We will update this blog with more information as it is available.
Online advertisers started a shift (link) “from a ‘served’ to a ‘viewable’ impression[s].” Many different analytics companies stepped up to compete in this space. That competition has had many public results, including lawsuits (link). One of the companies involved in this space is Spider.io, which recently reported an issue in IE involving mouse pointer information. Spider.io is an advertising analytics company. Their recent blog post, “There are two ways to measure ad viewability. There is only one right way,” makes their point of view very clear. Different analytics companies use different and equivalent methods to gather consumer information across different browsers on different devices.
The only reported active use of this behavior involves competitors to Spider.io providing analytics. The theoretical use of this behavior to compromise the safety or privacy of consumers is something Microsoft’s security team has discussed with researchers across the industry. We take these risks very seriously. Getting all the pieces to line up in order to take advantage of this behavior – serving an ad to a site that asks for a logon, the user using an on screen (or virtual) keyboard, knowing how that onscreen keyboard works – is hard to imagine. From investigating the specific behavior when mouse position data is visible outside the browser window, sites can view only the mouse state; they cannot view the actual content that the user is interacting with. From our conversations with security researchers across the industry, we see very little risk to consumers at this time. As we have stated previously, there are no reported cases of any consumer having their information compromised.  
—Dean Hachamovitch, Corporate Vice President, Internet Explorer
Update:
Since the time of our post – these additional security blogs provide a good and balanced overview with respect to this topic: Actionable Intelligence: The Mouse That Squeaked and Spider.io Warns of Massive IE Security Flaw; But is it Legit?

HTML 5.0 and Canvas 2D Reach Candidate Recommendation Status


Today marks an important milestone for Web development, as the W3C announced the publication of the Candidate Recommendation (CR) version of the HTML 5.0 and Canvas 2D specifications. The specifications are on track for finalization by 2014. We want to congratulate the W3C on this achievement and bringing these specifications forward.
Internet Explorer 10 already offers hardware-accelerated HTML 5.0 and Canvas 2D support allowing developers to build compelling, cross-browser Web applications with good performance. We look forward to working with the Web community to finalize interoperable specifications in a timely manner. At the same time, we are actively involved in defining the scope for HTML 5.1, which includes exciting multimedia and other features that will continue to advance Web experiences.
You can read more about the progress to-date with HTML 5.0 and Canvas 2.0 specification, the next steps toward reaching Final Recommendation status, and progress toward defining HTML 5.1.
-- Sandeep Singhal, Group Program Manager, Internet Explorer

Penguin Mark: Blazing Fast Holiday Fun


We don’t want the holiday season to pass without sharing another new HTML5 experience that makes the most of your PC hardware and the new touch capabilities in Windows 8.
Check out Penguin Mark and enjoy some GPU-powered holiday fun. This experience brings together hardware-accelerated HTML5 capabilities like canvas, CSS3 animations and transitions, audio, WOFF, power and performance APIs, and more. Be sure to turn your volume up for maximum entertainment. The faster your browser, the higher your Penguin Mark score goes.
Click to test your browser’s holiday spirit with Penguin Mark - screen shot of Penguin MarkClick to test your browser’s holiday spirit with Penguin Mark
With Windows 8, we delivered a whole new browserthat’s fast and fluid, and built for touch browsing. IE10 adds support for a broad range of developer capabilities, including new touch APIs, performance, HTML5, CSS3, JavaScript, and more. We continue to be amazed and delighted by what developers are building on HTML5 and excited to be part of it.
Thank you!
Your participation and feedback is an important part of how we build IE. Today we want to say thank you to everyone who browses the Web with Windows 8, is using IE9 or IE10 preview on Windows 7, runs the test drives, and shares your feedback with the IE team. We also want to thank the people and groups who make the standards process work, the broad community of Web developers, and enthusiastic consumers who work to move the Web forward.
From the entire IE team, we wish you a Happy Hardware-accelerated Holiday Season, and we look forward to another exciting year and more progress on the Web in 2013.
—Rob Mauceri, Group Program Manager, Internet Explorer