Category 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 , , , .

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 , , , , , .

Firebug tool – part 001.

This tool help you to see and change online your webpage.
You can download it from firebug tool.
The official site tells us about the most popular and powerful web development tool:

  • Inspect HTML and modify style and layout in real-time
  • Use the most advanced JavaScript debugger available for any browser
  • Accurately analyze network usage and performance
  • Extend Firebug and add features to make Firebug even more powerful
  • Get the information you need to get it done with Firebug.

Today I will show you one simple example about how to use this tool.
The issue is: get the information you need to get it done with Firebug.
First you need to add this extension to your firefox browser.
Open website to test it.
Then press the F12 key to open the firebug window and press Enable button.
Select the Console tab. The window is change with two areas.
One to see the result of output command and one with editbox to write your commands.
Let’s start with some commands:

This command will get infos from browser and websites.

Posted in All, Commands, javascript, web. 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 , , , , , .