Skip to content

Instantly share code, notes, and snippets.

@ramirezd42
ramirezd42 / ex_0.js
Created October 25, 2017 05:03
ex_0 js
var addon = require('bindings')('hello');
console.log(addon.hello()); // 'world'
#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());
}
@ramirezd42
ramirezd42 / ex_1.js
Created October 25, 2017 05:01
ex_1 js
var addon = require('bindings')('addon');
addon(function(msg){
console.log(msg); // 'hello world'
});
#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 January 25, 2016 07:30
Delay Effect with Web Audio API
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 => {