Tuesday, January 15, 2019

WebRTC : WebAssembly role


WebAssembly in WebRTC will enable vendors to create differentiation in their products, probably favoring the more established, larger players.
WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications.

WebAssembly is a JVM for your browser. The same as Java is a language that gets compiled into a binary code that then gets interpreted and executed on a virtual machine, WebAssembly, or Wasm, allows developers to take the hard core languages (which means virtually any language), “compile” it to a binary representation that a Wasm virtual machine can execute efficiently. And this Wasm virtual machine just happen to be available on all web browsers.


WebAssembly allows vendors to do some really cool things – things that just weren’t possible to do with JavaScript. JavaScript is kinda slow compared to using C/C++ and a lot of hard core stuff that’s already written in C/C++ can now be ported/migrated/compiled using WebAssembly and used inside a browser.

Construct 3 decided to use Opus in browsers. Even when it isn’t available – by implementing Opus with Wasm
Zoom uses WebAssembly in order NOT to use WebRTC (probably because it doesn’t want to transcode at the edge of its network)
Unity, the popular gaming engine has adopted Wasm for its Unity WebGL target


Below are some more use case

Multiparty voice and video communications for online gaming – mainly more control on how streams are created, consumed and controlled
Improved support in mobile networks – the ability to manage and switch across network connections
Better support for media servers
New file sharing capabilities
Internet of Things – giving some love, care and attention to the data channel
Funny hats – enabling AI (computer vision) on video streams
Machine learning – like funny hats, but a bit more generic in its nature and requirements
Virtual reality – ability to synchronize audio/video with the data channel


references:
https://bloggeek.me/webassembly-in-webrtc/

Javascript : How to play short beep file?

Below is an awesome method. we are passing in the audio data itself as arguments. Now to get this audio base 64 data, the below site can be used. Nice one!

https://dopiaza.org/tools/datauri/index.php

function beep() {
    var snd = new Audio("data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQwAEaYLWfkWgAI0wWs/ItAAAGDgYtAgAyN+QWaAAihwMWm4G8QQRDiMcCBcH3Cc+CDv/7xA4Tvh9Rz/y8QADBwMWgQAZG/ILNAARQ4GLTcDeIIIhxGOBAuD7hOfBB3...."); 
    snd.play();
}
beep();


references:
https://stackoverflow.com/questions/879152/how-do-i-make-javascript-beep

Sails JS : Disabling CORS

Below was my config/cors.js configuration to allow all origins

allRoutes: true,
origin: '*',
credentials: false,
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
headers: 'content-type,apikey,token'

apikey, token were the extra headers passed in from app side.

references:
https://medium.com/@makarakao/sails-js-cors-problem-954f94ccf676

Wednesday, January 9, 2019

AWS: Ubuntu synching with NTP server

Below are the few steps

Connect to your instance and use apt to install the chrony package.
ubuntu:~$ sudo apt install chrony

Open the /etc/chrony/chrony.conf file using a text editor (such as vim or nano). Add the following line before any other server or pool statements that are already present in the file, and save your changes:

server 169.254.169.123 prefer iburst

Restart the chrony service.
ubuntu:~$ sudo /etc/init.d/chrony restart

Verify that chrony is using the 169.254.169.123 IP address to synchronize the time.

ubuntu:~$ chronyc sources -v

210 Number of sources = 7

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 169.254.169.123               3   6    17    12    +15us[  +57us] +/-  320us
^- tbag.heanet.ie                1   6    17    13  -3488us[-3446us] +/- 1779us
^- ec2-12-34-231-12.eu-west-     2   6    17    13   +893us[ +935us] +/- 7710us
^? 2a05:d018:c43:e312:ce77:6     0   6     0   10y     +0ns[   +0ns] +/-    0ns
^? 2a05:d018:d34:9000:d8c6:5     0   6     0   10y     +0ns[   +0ns] +/-    0ns
^? tshirt.heanet.ie              0   6     0   10y     +0ns[   +0ns] +/-    0ns
^? bray.walcz.net                0   6     0   10y     +0ns[   +0ns] +/-    0ns

Verify the time synchronization metrics that are reported by chrony.

ubuntu:~$ chronyc tracking

Reference ID    : 169.254.169.123 (169.254.169.123)
Stratum         : 4
Ref time (UTC)  : Wed Nov 29 07:41:57 2017
System time     : 0.000000011 seconds slow of NTP time
Last offset     : +0.000041659 seconds
RMS offset      : 0.000041659 seconds
Frequency       : 10.141 ppm slow
Residual freq   : +7.557 ppm
Skew            : 2.329 ppm
Root delay      : 0.000544 seconds
Root dispersion : 0.000631 seconds
Update interval : 2.0 seconds
Leap status     : Normal



references:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html

AWS how to reboot instance?


Its pretty easy. An instance reboot is equivalent to an operating system reboot. In most cases, it takes only a few minutes to reboot your instance. When you reboot an instance, it remains on the same physical host, so your instance keeps its public DNS name (IPv4), private IPv4 address, IPv6 address (if applicable), and any data on its instance store volumes.

Rebooting an instance doesn't start a new instance billing period (with a minimum one-minute charge), unlike stopping and restarting your instance.

AWS recommend that you use the Amazon EC2 console, a command line tool, or the Amazon EC2 API to reboot your instance instead of running the operating system reboot command from your instance. If you use the Amazon EC2 console, a command line tool, or the Amazon EC2 API to reboot your instance, we perform a hard reboot if the instance does not cleanly shut down within four minutes. If you use AWS CloudTrail, then using Amazon EC2 to reboot your instance also creates an API record of when your instance was rebooted.

To reboot an instance using the console

Open the Amazon EC2 console.

In the navigation pane, choose Instances.

Select the instance and choose Actions, Instance State, Reboot.

Choose Yes, Reboot when prompted for confirmation.


references:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-reboot.html

Firebase : What is the main reason for this error?

I was deploying an AWS sails js app on Ubuntu EC2 instance and came across the below issue. Definitely the credential to the firebase was all correct, so the only issue left out was the time on the EC2 instance.

Amazingly it was 6 mins ahead of the GMT.

chronyc tracking
Reference ID    : 169.254.169.123 (169.254.169.123)
Stratum         : 4
Ref time (UTC)  : Wed Jan  9 18:07:53 2019
System time     : 386.305358887 seconds fast of NTP time
Last offset     : 0.000310425 seconds
RMS offset      : 0.000310425 seconds
Frequency       : 0.000 ppm fast
Residual freq   : 74.519 ppm
Skew            : 1000000.000 ppm
Root delay      : 0.000746 seconds
Root dispersion : 19.008415 seconds
Update interval : 0.0 seconds
Leap status     : Normal


Reading few posts, i could sense that the EC2 was not using NTP server time. Installed the NTP server sync on EC2 and after a reboot of the instance, the time was only off by a few nano millis!

[2019-01-09T18:18:20.225Z]  @firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: invalid_grant (Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values and use a clock with skew to account for clock differences between systems.)\". There are two likely causes: (1) your server time is not properly synced or (2) your certificate key file has been revoked. To solve (1), re-sync the time on your server. To solve (2), make sure the key ID for your key file is still present at https://console.firebase.google.com/iam-admin/serviceaccounts/project. If not, generate a new key file at https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk."}

Tuesday, January 8, 2019

Firebase: How to set up a custom domain?

Need to navigate to https://console.firebase.google.com/u/0/project//hosting/main

Press on Connect Domain. This will show up a text field to enter the domain name. Once enter the domain, Google prepares a TXT record value to be added in big rock or the domain name providers page. In the Domain name providers page, enter the host as @ or leave empty and set the value as the value given by Google. Also add a CNMAe record with the domain that firebase temporarily gives. After this, press on verify. It is said that sometimes the TXT record refresh take max upto 72 hrs, but practically in my case, it just took only 30 mins. Once the verification is done successfully, Google gave 2 A records that had to be added to the Name providers. This is going to take some time to reflect it seems. Still waiting for it.

references:
https://console.firebase.google.com/u/0/project/pinkymind-6e0d9/hosting/main