Skip to content

Instantly share code, notes, and snippets.

Anant Narayanan anantn

Block or report user

Report or block anantn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@anantn
anantn / getusermedia_picture.html
Created Feb 17, 2012
Take a picture with getUserMedia
View getusermedia_picture.html
<html>
<body>
<video id="v" width="300" height="300"></video>
<input id="b" type="button" disabled="true" value="Take Picture"></input>
<canvas id="c" style="display:none;" width="300" height="300"></canvas>
</body>
<script>
navigator.getUserMedia({video: true}, function(stream) {
var video = document.getElementById("v");
var canvas = document.getElementById("c");
@anantn
anantn / owa_receipt.js
Created Feb 18, 2012
How to verify a Mozilla Apps receipt
View owa_receipt.js
function doVerifyReceipt(cb, options) {
navigator.mozApps.getSelf(function(app) {
var record = app.receipt;
if (!record) {
cb({"error": "Application not installed"});
return;
}
if (typeof cb !== "function") {
throw "Callback not provided in doVerifyReceipt";
@anantn
anantn / gist:2871209
Created Jun 4, 2012
Add popup blocking to android getUserMedia({picture})
View gist:2871209
diff --git a/content/media/MediaEngineDefault.cpp b/content/media/MediaEngineDefault.cpp
--- a/content/media/MediaEngineDefault.cpp
+++ b/content/media/MediaEngineDefault.cpp
@@ -1,13 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MediaEngineDefault.h"
+#include "nsDOMFile.h"
@anantn
anantn / gUM_hack.html
Created Jul 12, 2012
Example getUserMedia Usage
View gUM_hack.html
<!DOCTYPE html public "✰">
<html>
<head>
<meta charset="utf-8">
<title>getUserMedia Video Example</title>
</head>
<body>
<button type="button" onclick="toggle()">
Toggle Video
</button>
@anantn
anantn / pc_xpcshell_test.js
Created Jul 27, 2012
PeerConnection in XPCShell
View pc_xpcshell_test.js
const Cc = Components.classes;
const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports);
let gScriptDone = false;
View xpcom_file_io.js
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/NetUtil.jsm");
// Let's enumerate all available files in ~
function getHomeDir() {
let home = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
home.initWithPath("~");
if (!home.isDirectory()) {
alert("that seems wrong...");
@anantn
anantn / getUserMediaDevices.html
Created Sep 18, 2012
navigator.mozGetUserMediaDevices Example
View getUserMediaDevices.html
<html>
<body>
<h1>Device Test</h1>
<ul id="contents">
</ul>
<video id="tehvideo"/>
<audio id="tehaudio"/>
<script>
var devices;
var nav = navigator.QueryInterface(Components.interfaces.nsINavigatorUserMedia);
@anantn
anantn / tamejs_gum.js
Created Oct 18, 2012
TameJS wrapper for getUserMedia
View tamejs_gum.js
function myGetUserMedia(constraints, cb)
{
function errCb(code)
{
cb(code, null);
}
function successCb(stream)
{
@anantn
anantn / datachannels.js
Created Oct 31, 2012
Data Channel Example
View datachannels.js
/**
* Assume we've connected a PeerConnection with a friend - usually with audio
* and/or video. For the time being, always at least include a 'fake' audio
* stream - this will be fixed soon.
*
* connectDataConnection is a temporary function that will soon disappear.
* The two sides need to use inverted copies of the two numbers (eg. 5000, 5001
* on one side, 5001, 5000 on the other)
*/
pc.connectDataConnection(5001, 5000);
@anantn
anantn / firebase_detect_data.js
Created Dec 18, 2012
Firebase: Detecting if data exists. This snippet detects if a user ID is already taken
View firebase_detect_data.js
function go() {
var userId = prompt('Username?', 'Guest');
checkIfUserExists(userId);
}
var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users';
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
You can’t perform that action at this time.