Skip to content

Instantly share code, notes, and snippets.

Avatar

Dave Ramirez ramirezd42

View GitHub Profile
View ex_0.js
var addon = require('bindings')('hello');
console.log(addon.hello()); // 'world'
View ex_0.cpp
#include <nan.h>
void Method(const Nan::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(Nan::New("world").ToLocalChecked());
}
void Init(v8::Local<v8::Object> exports) {
exports->Set(Nan::New("hello").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(Method)->GetFunction());
}
View ex_1.js
var addon = require('bindings')('addon');
addon(function(msg){
console.log(msg); // 'hello world'
});
View ex_1.cpp
#include <nan.h>
void RunCallback(const Nan::FunctionCallbackInfo<v8::Value>& info) {
v8::Local<v8::Function> cb = info[0].As<v8::Function>();
const unsigned argc = 1;
v8::Local<v8::Value> argv[argc] = { Nan::New("hello world").ToLocalChecked() };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), cb, argc, argv);
}
void Init(v8::Local<v8::Object> exports, v8::Local<v8::Object> module) {
@ramirezd42
ramirezd42 / delay.js
Created Jan 25, 2016
Delay Effect with Web Audio API
View delay.js
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var streamNode;
var masterNode;
var bypassNode;
var delayNode;
var feedbackNode;
//request an audio MediaStream track and save a reference to it
navigator.mediaDevices.getUserMedia({audio: true})
.then(stream => {
You can’t perform that action at this time.