Skip to content

Instantly share code, notes, and snippets.

@anantn
anantn / xpcom_file_io.js
Created August 23, 2012 09:36
XPCOM File I/O
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 / pc_xpcshell_test.js
Created July 27, 2012 05:58
PeerConnection in XPCShell
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;
@anantn
anantn / gUM_hack.html
Created July 12, 2012 05:30
Example getUserMedia Usage
<!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 / gist:2871209
Created June 4, 2012 22:30
Add popup blocking to android getUserMedia({picture})
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 / owa_receipt.js
Created February 18, 2012 08:28
How to verify a Mozilla Apps receipt
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 / getusermedia_picture.html
Created February 17, 2012 09:12
Take a picture with getUserMedia
<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");