SlideShare a Scribd company logo
Massive Data
in JavaScript
by Sergiu Gordienco, 5 July 2015
What is Blob ?
How it is used
in JavaScript
var aFileParts = ['<a id="a"><b id="b">hey!</b></a>'];
// the blob
var oMyBlob = new Blob(aFileParts, {type : 'text/html'});
Easily work with streams
with buffers & don’t care
about joining data while
we receive it
var aFileParts = ['<a id="a"><b id="b">hey!</b></a>'];
// the blob
var oMyBlob = new Blob(aFileParts, {type : 'text/html'});
Blobs can be converted
into data resources with
available URL
var blobURL = window.URL.createObjectURL(new Blob(...))
// and can be used as simple resources
var req = new XMLHttpRequest(); req.onload = calback_f;
req.open('get', blobURL); req.send( .. or send blob ..);
Lets start from
popular APIs
JavaScript
File API
We get files from <input type=”file” />, and
Drag & Drop events
We can get File as
» String / Array .. etc
» Blob
» Stream
var reader = new FileReader();
reader.addEventListener("loadend", callback_f );
reader.readAsArrayBuffer(file_object);
You want to parse
2Gb of data?
slice it, parse by parts
var reader = new FileReader(); reader.addEventListener("loadend", callback_f );
reader.readAsArrayBuffer(
file_object.slice(0, 4096) // reading first 4Kb
);
JavaScript
WebSocket API
Events: onopen, onerror, onclose, onmessage
Methods: send(), close()
Important Attrs: url, readyState, bufferedAmount
void send(
in DOMString data
);
void send(
in ArrayBuffer data
);
void send(
in Blob data
);
When you have possibility use blobs for sending
files, and arraybuffer for stream data,
do not forget about bufferedAmount
Huge Algorithm?
browser blocked?
performance issues?
:’( My code works,
just wait to compile 30Mb of CSV file
Workers
or
Waiters
CPU is available and we will work :P
JavaScript
Workers
parallel processes
… factory495 = new Worker(..), factory496 =
new Worker(..), factory497 = new Worker( ...
var worker = new Worker("ak47-vs-mk4.js");
var worker = new Worker("my-csv-builder.js");
}:[ Hey !!! how about this??
My algorithm is in the memory!!!
Starting a parallel worker
var worker = new Worker("ak47-vs-mk4.js");
var worker = new Worker("my-csv-builder.js");
}:[ Hey !!! how about this??
My algorithm is in the memory!!!
Starting a parallel worker
var blob = new Blob(["... your javascript code ..."
], {type: 'text/javascript'});
// webkit handling
var URL = window.URL || window.webkitURL;
// create the virtual file
var code = URL.createObjectURL(blob);
// create the worker
var worker = new Worker(code);
// for communication use code below, direct contact is not allowed
self.addEventListener('message', messageReceived);
function messageReceived(e) {
self.postMessage('I am HERE !');
}
And remeber
every Worker can
have subWorkers
… subFactory495 = new Worker(..),
subFactory496 = new Worker(..), subFac...
RTC Data Channelvar peerConnection = new RTCPeerConnection();
// Establish your peer connection using your signaling channel here
var dataChannel =
peerConnection.createDataChannel("myLabel", dataChannelOptions);
dataChannel.onerror = function (error) {
console.log("Data Channel Error:", error);
};
dataChannel.onmessage = function (event) {
console.log("Got Data Channel Message:", event.data);
};
dataChannel.onopen = function () {
dataChannel.send("Hello World!");
};
dataChannel.onclose = function () {
console.log("The Data Channel is Closed");
};
Nota Bene:
Firefox supports chunks with maximum 16Kb size
SCTP ( Stream Control Transmission Protocol )
ordered - guarantee order or not
maxRetransmitTime - maximum time to try and retransmit a failed
message (forces unreliable mode)
maxRetransmits - maximum number of times to try and
retransmit a failed message (forces unreliable mode)
protocol - subprotocol to be used
id - provide your own ID for the channel
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkit... || navigator.moz... || navigator.ms...;
audioContext = window.AudioContext || window.webkit… || ...
GetUserMedia
AudioContext
recording audio data
callback_success retrieve stream object
callback_error retrieve error object
Requesting Audio Stream
navigator.getUserMedia(
{audio:true},
callback_success,
callback_error
);
after we set recorder.onaudioprocess
we will connect recorder using
volume.connect (recorder);
recorder.connect (context.destination);
After retrieving Audio Stream
// build Audio context
// create an audioInput as a stream source
// create the gain mode ( volume / createGain )
// connect audioInput to gain mode
// build an recorder using createJavaScriptNode
bufferSize, numInputChannels, numOutputChannels
Allowed BufferSize
256, 512, 1024, 2048, 4096, 8192, or 16384
From the start we will describe some
small functions that we will use often
Now we are ready to
record sound
and save it in a file
Thanks :)

More Related Content

What's hot

Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1
Artificial Intelligence Institute at UofSC
 
Pracitcal AJAX
Pracitcal AJAXPracitcal AJAX
Pracitcal AJAX
jherr
 
Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2
Artificial Intelligence Institute at UofSC
 
How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...
How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...
How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...
Anton
 
Html5
Html5Html5
Ajax
AjaxAjax
Ajax
jainaman
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM Manipulations
Ynon Perek
 
Rust vs. Go: qual è il linguaggio più adatto al tuo progetto?
Rust vs. Go: qual è il linguaggio più adatto al tuo progetto?Rust vs. Go: qual è il linguaggio più adatto al tuo progetto?
Rust vs. Go: qual è il linguaggio più adatto al tuo progetto?
Claudio Capobianco
 
Web Scrapping with Python
Web Scrapping with PythonWeb Scrapping with Python
Web Scrapping with Python
Miguel Miranda de Mattos
 
Scrapy talk at DataPhilly
Scrapy talk at DataPhillyScrapy talk at DataPhilly
Scrapy talk at DataPhilly
obdit
 
N hidden gems in hippo forge and experience plugins (dec17)
N hidden gems in hippo forge and experience plugins (dec17)N hidden gems in hippo forge and experience plugins (dec17)
N hidden gems in hippo forge and experience plugins (dec17)
Woonsan Ko
 
JavaScript and BOM events
JavaScript and BOM eventsJavaScript and BOM events
JavaScript and BOM events
Jussi Pohjolainen
 
handout-05b
handout-05bhandout-05b
handout-05b
tutorialsruby
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
Websecurify
 
Scrapy workshop
Scrapy workshopScrapy workshop
Scrapy workshop
Karthik Ananth
 
mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.
Oleg Shanyuk
 
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)
Sammy Fung
 
AJAX
AJAXAJAX
N hidden gems you didn't know hippo delivery tier and hippo (forge) could give
N hidden gems you didn't know hippo delivery tier and hippo (forge) could giveN hidden gems you didn't know hippo delivery tier and hippo (forge) could give
N hidden gems you didn't know hippo delivery tier and hippo (forge) could give
Woonsan Ko
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-C
Juio Barros
 

What's hot (20)

Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1
 
Pracitcal AJAX
Pracitcal AJAXPracitcal AJAX
Pracitcal AJAX
 
Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2
 
How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...
How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...
How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...
 
Html5
Html5Html5
Html5
 
Ajax
AjaxAjax
Ajax
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM Manipulations
 
Rust vs. Go: qual è il linguaggio più adatto al tuo progetto?
Rust vs. Go: qual è il linguaggio più adatto al tuo progetto?Rust vs. Go: qual è il linguaggio più adatto al tuo progetto?
Rust vs. Go: qual è il linguaggio più adatto al tuo progetto?
 
Web Scrapping with Python
Web Scrapping with PythonWeb Scrapping with Python
Web Scrapping with Python
 
Scrapy talk at DataPhilly
Scrapy talk at DataPhillyScrapy talk at DataPhilly
Scrapy talk at DataPhilly
 
N hidden gems in hippo forge and experience plugins (dec17)
N hidden gems in hippo forge and experience plugins (dec17)N hidden gems in hippo forge and experience plugins (dec17)
N hidden gems in hippo forge and experience plugins (dec17)
 
JavaScript and BOM events
JavaScript and BOM eventsJavaScript and BOM events
JavaScript and BOM events
 
handout-05b
handout-05bhandout-05b
handout-05b
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
 
Scrapy workshop
Scrapy workshopScrapy workshop
Scrapy workshop
 
mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.
 
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)
 
AJAX
AJAXAJAX
AJAX
 
N hidden gems you didn't know hippo delivery tier and hippo (forge) could give
N hidden gems you didn't know hippo delivery tier and hippo (forge) could giveN hidden gems you didn't know hippo delivery tier and hippo (forge) could give
N hidden gems you didn't know hippo delivery tier and hippo (forge) could give
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-C
 

Similar to Video WebChat Conference Tool

JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
philogb
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
philogb
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
vito jeng
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
David Padbury
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
rajivmordani
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
Michael Girouard
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templating
bcruhl
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
n|u - The Open Security Community
 
UNO based ODF Toolkit API
UNO based ODF Toolkit APIUNO based ODF Toolkit API
UNO based ODF Toolkit API
Alexandro Colorado
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
Robert Nyman
 
JavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the PlatformJavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the Platform
Robert Nyman
 
HTML5 & The Open Web - at Nackademin
HTML5 & The Open Web -  at NackademinHTML5 & The Open Web -  at Nackademin
HTML5 & The Open Web - at Nackademin
Robert Nyman
 
maxbox starter72 multilanguage coding
maxbox starter72 multilanguage codingmaxbox starter72 multilanguage coding
maxbox starter72 multilanguage coding
Max Kleiner
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docxcase3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
tidwellveronique
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Alive Kuo
 
Modern JavaScript Programming
Modern JavaScript Programming Modern JavaScript Programming
Modern JavaScript Programming
Wildan Maulana
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps Offline
Pedro Morais
 
e-suap - client technologies- english version
e-suap - client technologies- english versione-suap - client technologies- english version
e-suap - client technologies- english version
Sabino Labarile
 

Similar to Video WebChat Conference Tool (20)

JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templating
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
 
UNO based ODF Toolkit API
UNO based ODF Toolkit APIUNO based ODF Toolkit API
UNO based ODF Toolkit API
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
 
JavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the PlatformJavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the Platform
 
HTML5 & The Open Web - at Nackademin
HTML5 & The Open Web -  at NackademinHTML5 & The Open Web -  at Nackademin
HTML5 & The Open Web - at Nackademin
 
maxbox starter72 multilanguage coding
maxbox starter72 multilanguage codingmaxbox starter72 multilanguage coding
maxbox starter72 multilanguage coding
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docxcase3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Modern JavaScript Programming
Modern JavaScript Programming Modern JavaScript Programming
Modern JavaScript Programming
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps Offline
 
e-suap - client technologies- english version
e-suap - client technologies- english versione-suap - client technologies- english version
e-suap - client technologies- english version
 

Video WebChat Conference Tool

  • 1. Massive Data in JavaScript by Sergiu Gordienco, 5 July 2015
  • 2. What is Blob ? How it is used in JavaScript var aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // the blob var oMyBlob = new Blob(aFileParts, {type : 'text/html'});
  • 3. Easily work with streams with buffers & don’t care about joining data while we receive it var aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // the blob var oMyBlob = new Blob(aFileParts, {type : 'text/html'});
  • 4. Blobs can be converted into data resources with available URL var blobURL = window.URL.createObjectURL(new Blob(...)) // and can be used as simple resources var req = new XMLHttpRequest(); req.onload = calback_f; req.open('get', blobURL); req.send( .. or send blob ..);
  • 6. JavaScript File API We get files from <input type=”file” />, and Drag & Drop events
  • 7. We can get File as » String / Array .. etc » Blob » Stream var reader = new FileReader(); reader.addEventListener("loadend", callback_f ); reader.readAsArrayBuffer(file_object);
  • 8. You want to parse 2Gb of data? slice it, parse by parts var reader = new FileReader(); reader.addEventListener("loadend", callback_f ); reader.readAsArrayBuffer( file_object.slice(0, 4096) // reading first 4Kb );
  • 9. JavaScript WebSocket API Events: onopen, onerror, onclose, onmessage Methods: send(), close() Important Attrs: url, readyState, bufferedAmount
  • 10. void send( in DOMString data ); void send( in ArrayBuffer data ); void send( in Blob data ); When you have possibility use blobs for sending files, and arraybuffer for stream data, do not forget about bufferedAmount
  • 11. Huge Algorithm? browser blocked? performance issues? :’( My code works, just wait to compile 30Mb of CSV file
  • 12. Workers or Waiters CPU is available and we will work :P
  • 13. JavaScript Workers parallel processes … factory495 = new Worker(..), factory496 = new Worker(..), factory497 = new Worker( ...
  • 14. var worker = new Worker("ak47-vs-mk4.js"); var worker = new Worker("my-csv-builder.js"); }:[ Hey !!! how about this?? My algorithm is in the memory!!! Starting a parallel worker
  • 15. var worker = new Worker("ak47-vs-mk4.js"); var worker = new Worker("my-csv-builder.js"); }:[ Hey !!! how about this?? My algorithm is in the memory!!! Starting a parallel worker
  • 16. var blob = new Blob(["... your javascript code ..." ], {type: 'text/javascript'}); // webkit handling var URL = window.URL || window.webkitURL; // create the virtual file var code = URL.createObjectURL(blob); // create the worker var worker = new Worker(code); // for communication use code below, direct contact is not allowed self.addEventListener('message', messageReceived); function messageReceived(e) { self.postMessage('I am HERE !'); }
  • 17. And remeber every Worker can have subWorkers … subFactory495 = new Worker(..), subFactory496 = new Worker(..), subFac...
  • 18. RTC Data Channelvar peerConnection = new RTCPeerConnection(); // Establish your peer connection using your signaling channel here var dataChannel = peerConnection.createDataChannel("myLabel", dataChannelOptions); dataChannel.onerror = function (error) { console.log("Data Channel Error:", error); }; dataChannel.onmessage = function (event) { console.log("Got Data Channel Message:", event.data); }; dataChannel.onopen = function () { dataChannel.send("Hello World!"); }; dataChannel.onclose = function () { console.log("The Data Channel is Closed"); };
  • 19. Nota Bene: Firefox supports chunks with maximum 16Kb size SCTP ( Stream Control Transmission Protocol ) ordered - guarantee order or not maxRetransmitTime - maximum time to try and retransmit a failed message (forces unreliable mode) maxRetransmits - maximum number of times to try and retransmit a failed message (forces unreliable mode) protocol - subprotocol to be used id - provide your own ID for the channel
  • 20. navigator.getUserMedia = navigator.getUserMedia || navigator.webkit... || navigator.moz... || navigator.ms...; audioContext = window.AudioContext || window.webkit… || ... GetUserMedia AudioContext recording audio data
  • 21. callback_success retrieve stream object callback_error retrieve error object Requesting Audio Stream navigator.getUserMedia( {audio:true}, callback_success, callback_error );
  • 22. after we set recorder.onaudioprocess we will connect recorder using volume.connect (recorder); recorder.connect (context.destination); After retrieving Audio Stream // build Audio context // create an audioInput as a stream source // create the gain mode ( volume / createGain ) // connect audioInput to gain mode // build an recorder using createJavaScriptNode bufferSize, numInputChannels, numOutputChannels
  • 23.
  • 24.
  • 25. Allowed BufferSize 256, 512, 1024, 2048, 4096, 8192, or 16384
  • 26. From the start we will describe some small functions that we will use often Now we are ready to record sound and save it in a file
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.