Niranjan B Prithviraj
Single threading bringing you down?
"Main thread"
var worker = new Worker('/js/worker.js');
worker.addEventListener('message', function(e) {
console.log(e.data);
}, false);
worker.postMessage({'cmd':'start'});
worker.postMessage({'cmd':'stop'});
worker.postMessage({'cmd':'get'});
"Worker thread"
self.addEventListener('message', function(e) {
self.postMessage({'msg':'WORKER STARTED'});
}, false);
Flash? That's so 2003.
<video style="width:600px;height:400px;"></video>
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
var constraints = {audio: true, video: true};
var video = document.querySelector("video");
function successCallback(stream) {
window.stream = stream; // stream available to console
if (window.URL) {
video.src = window.URL.createObjectURL(stream);
} else {
video.src = stream;
}
video.play();
}
function errorCallback(error){
console.log("navigator.getUserMedia error: ", error);
}
navigator.getUserMedia(constraints, successCallback, errorCallback);
Pop-ups are cool again.
function notify() {
var havePermission = window.webkitNotifications.checkPermission();
if (havePermission == 0) {
// 0 is PERMISSION_ALLOWED
var notification = window.webkitNotifications.createNotification(
'http://localhost:3000/notifications',
'Chrome notification!',
'Ola!'
);
notification.show();
} else {
window.webkitNotifications.requestPermission();
}
}
Animation, Sound, Assets management
<canvas id="myCanvas" width="500" height="500"></canvas>
<script src="http://code.createjs.com/createjs-2013.05.14.min.js"></script>
var stage = new createjs.Stage("myCanvas");
vck2013-2.pngar ball = new createjs.Shape();
ball.addEventListener("click", handleClick);
ball.graphics.beginFill("#000").drawCircle(0, 0, 50);
ball.x = 50;
ball.y = 200;
stage.addChild(ball);
stage.update();
Quit long polling.
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('ws://localhost:3000/websocket_res');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
NIRANJAN B PRITHVIRAJ
niranjanprithviraj.com | @nbprithv
github.com/nbprithv/openhack2013-decks
Brought to you by reveal.js