Tag Archives: javascript

JavaScript – geolocation.

This is a simple java script to take the geolocation and show it on webpage.
The example start with a default HTML 5 page and the part from tags scripts get the geolocation and using innerHTML is show on webpage.
To see the location then is need to use this: navigator.geolocation.getCurrentPosition.

Posted in All, HTML 5, javascript. Tagged with , , , , , .

JavaScript – toggle button example.

Is a simple example about toggle button.
You need to start with input button and then get the state of this

Then add the type and id and style.
You can remove the text-indent: -9999px; and Toggle button if you don’t want to see text to this toggle button.
Let’s see the full source code and how is working.
The part after hr tag with button and paragraph tag id=output is just for tested the toggle button.
You can make a html file and put this source code to test it.

Posted in All, javascript, Programming. Tagged with , , , .

Website tool for processing language.

The Studio SketchPad aims to be a open studio for individuals learning to sketch beautiful code on the web canvas with  Processing and  EtherPad.
The default licensing adopted for the sketches are the Creative Commons Attribution-ShareAlike 3.0 Unported license.
Today I will come with this tutorial about hoe to use this tool.
First you need to open all three websites from this tutorial.
The Studio SketchPad come with a good web tool to test the Processing Visualization Language with Etherpad.
About Etherpad is a highly customizable Open Source online editor providing collaborative editing in really real-time.
Open your account from Studio SketchPad. From Home menu add your first new sketch from right top of the website. If the website come with the Untitled source code the run it. This will show you how is working.
The base of the processing code is two functions: setup and draw.
The setup function will set all you need to run the draw function.
Let’s see my code:

I put comments into my source code to understand some of the processing language functions.
The variable and math are simple. Variables have a global or local “scope”. for example variables declared outside of setup() and draw() are global variables.
NOTE: If a local variable is declared with the same name as a global variable, the program will use the local variable to make its calculations within the current scope.
You can see the result here and also you can search on my website similar tutorials with processing.

Posted in All, Processing.js, Programming, web. Tagged with , , , , , , , .

WebRTC – one simple first example webcam – part 002.

As you know already the WebRTC allow us provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs.The WebRTC components have been optimized to best serve this purpose.
You also need to put tunneling WebRTC over TCP because that tunneling it matters.
But today I will show you just a simple first example about webcam and WebRTC.
The HTML5 file is very simple:

You need to have a video tag with id for identification tag named “player”. You can put anything you like into areas of id’s, but that will reflect the part of javascript.
The autoplay segment code will start the running part of video tag.
You see the HTML file come with two references to files: webcam.css and webcam.js.
The webcam.css will allow you to add a more stylized part of HTML file and that will reflect the output.
The webcam.js will allow you to make WebRTC communications over internet…
Let’s start with css file:

The body and player parts are used to make changes into HTML output.
The body is a default for HTML tag body and for id’s is used # and the named id’s.
For example: If you named your tags like word, next, pass, all the id’s will be #word, #next, #pass, #all.
Anyway. this allow you just stylized your HTML output.
To have a real communication then you need javascript.
This javascript can be part of HTML files into two ways.
First is to put into HTML5 and that has some limits.
The next step is to use another javascript that is loaded by HTML file.
My example uses the best HTML format HTML5 encoding.
You can see into my example the HTML load the webcam.js script into area of head tag.
Let’s see the javascript file:

I create an object named mediaOptions. The objects can be also created like that format: var car = new Object();
I used achieved with: var mediaOptions = { audio: false, video: true };
This variable object will can be started or not.
This is part of two if statements and will return the getUserMedia function.
The next step is to give all infos and data to make all running:
navigator.getUserMedia(mediaOptions, success, function(e) {

function success(stream){
var video = document.querySelector(“#player”);
video.src = window.URL.createObjectURL(stream);

The MediaStream object that contains the media stream is allow by success and the callback of getUserMedia.
That function – success put into video tag the output of your webcam.
Your browser allow you to see the webcam by running this: HTML5, javascript and css.
If you read my old webrtc-first-steps-part-001 example you will see is more complex.
The main reason was to see the global area and then to understand how simple is to write code.
Most part of my previous tutorial are also very important parts.
That will increase the strength into areas. This source code is also good, but not great.
To have a good secure then you need to use more … (like tunneling).

Posted in All, HTML 5, javascript, web, WebRTC. Tagged with , , , , , .

WebSocket – First steps – part 001.

I do not think that is so sought after. Most people prefer products WebRTC.
Also on good reason of using WebRTC instead of Websocket is latency of streaming.
Is the protocol for two-way communication with a remote host.
The WebSocket interface and defines a full-duplex communication channel and operates through a single socket over the Web. The WebSocket detects the presence of a proxy server.
The next step is to automatically sets up a tunnel to pass through the proxy.
The tunnel is established by issuing an HTTP CONNECT statement to the proxy server.
Let’s see one simple example:

It is one simple open, close and sending message with websocket and javascript show events.
The most important part is to define the websocket:

The next steps is to use it with default javascript event system and window show message.

Posted in All, HTML 5, javascript. Tagged with , , , , , .