Permalink
Browse files

Initial commit

  • Loading branch information...
jpemartins committed Apr 27, 2012
0 parents commit 2794447b793a9930c4c576de411782af08942f2f
Showing with 42,132 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +143 −0 Makefile
  3. BIN bin/sample
  4. +28 −0 index.js
  5. BIN lib/webrtc.a
  6. +12 −0 package.json
  7. +170 −0 src/binding.cc
  8. +57 −0 src/defaults.cc
  9. +29 −0 src/defaults.h
  10. +92 −0 src/helloworld.cc
  11. +61 −0 src/main.cc
  12. +49 −0 src/observer.cc
  13. +79 −0 src/observer.h
  14. +482 −0 src/peerconnection_client.cc
  15. +109 −0 src/peerconnection_client.h
  16. +40,817 −0 src/tags
@@ -0,0 +1,4 @@
+*.o
+webrtc.node
+deps/webrtc
+build/
143 Makefile
@@ -0,0 +1,143 @@
+WEBRTC_ROOT_PATH = deps/webrtc/stable
+
+DEFS= -D_LARGEFILE_SOURCE \
+ -D_FILE_OFFSET_BITS=64 \
+ -DWEBRTC_TARGET_PC \
+ -DWEBRTC_LINUX \
+ -DWEBRTC_THREAD_RR \
+ -DEXPAT_RELATIVE_PATH \
+ -DWEBRTC_RELATIVE_PATH \
+ -DLINUX \
+ -DPOSIX \
+ -D__STDC_FORMAT_MACROS \
+ -DDYNAMIC_ANNOTATIONS_ENABLED=1 \
+ -DWTF_USE_DYNAMIC_ANNOTATIONS=1
+
+# Flags passed to all source files.
+# -fvisibility=hidden NodeJS Does not like it
+CFLAGS= -pthread \
+ -fno-exceptions \
+ -fno-strict-aliasing \
+ -Wall \
+ -Wno-unused-parameter \
+ -Wno-missing-field-initializers \
+ -Wextra \
+ -Wno-unused-parameter \
+ -Wno-missing-field-initializers \
+ -I/usr/include/atk-1.0 \
+ -I/usr/include/pango-1.0 \
+ -I/usr/include/gio-unix-2.0/ \
+ -I/usr/include/glib-2.0 \
+ -I/usr/lib/i386-linux-gnu/glib-2.0/include \
+ -I/usr/include/freetype2 \
+ -I/usr/include/libpng12 \
+ -I/usr/include/gtk-2.0 \
+ -I/usr/lib/gtk-2.0/include \
+ -I/usr/include/cairo \
+ -I/usr/include/gdk-pixbuf-2.0 \
+ -I/usr/include/pixman-1 \
+ -g
+
+CCFLAGS = -fno-rtti \
+ -fno-threadsafe-statics \
+ -fvisibility-inlines-hidden \
+ -Wsign-compare \
+ -D_LARGEFILE_SOURCE \
+ -D_FILE_OFFSET_BITS=64
+
+INCLUDE_DIRS = -I/usr/include/nodejs/ \
+ -I$(WEBRTC_ROOT_PATH)/third_party/libjingle/source \
+ -I$(WEBRTC_ROOT_PATH)/third_party_mods/libjingle/source \
+ -I$(WEBRTC_ROOT_PATH)/src
+
+BUILD_DIR = build/
+NODE_MODULE = webrtc.node
+
+NODE_FLAGS = -o$(BUILD_DIR)/$(NODE_MODULE)
+FLAGS = -obin/sample
+
+WEBRTC_OBJS = $(BUILD_DIR)/defaults.o $(BUILD_DIR)/observer.o
+
+NODE_OBJS = $(WEBRTC_OBJS) $(BUILD_DIR)/binding.o
+SAMPLE_OBJS = $(WEBRTC_OBJS) $(BUILD_DIR)/main.o
+
+WEBRTC_LIB = lib/webrtc.a
+WEBRTC_LIBS := $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/third_party_mods/libjingle/libjingle_app.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/third_party/libsrtp/libsrtp.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/third_party_mods/libjingle/libjsoncpp.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libvideo_capture_module.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libwebrtc_utility.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libaudio_coding_module.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libCNG.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/common_audio/libsignal_processing.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libG711.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libG722.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libiLBC.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libiSAC.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libiSACFix.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libPCM16B.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libNetEq.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/common_audio/libresampler.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/common_audio/libvad.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/system_wrappers/source/libsystem_wrappers.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libwebrtc_video_coding.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libwebrtc_i420.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libwebrtc_vp8.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/common_video/libwebrtc_libyuv.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/third_party/libyuv/libyuv.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/third_party/libvpx/libvpx.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libvideo_render_module.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/video_engine/libvideo_engine_core.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/common_video/libwebrtc_jpeg.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/third_party/libjpeg_turbo/libjpeg_turbo.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libmedia_file.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/librtp_rtcp.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libudp_transport.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libvideo_processing.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libvideo_processing_sse2.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/voice_engine/libvoice_engine_core.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libaudio_conference_mixer.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libaudio_processing.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libaec.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libapm_util.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libaec_sse2.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libaecm.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libagc.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libns.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libaudioproc_debug_proto.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/third_party/protobuf/libprotobuf_lite.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/src/modules/libaudio_device.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/third_party_mods/libjingle/libjingle_p2p.a \
+ $(WEBRTC_ROOT_PATH)/out/Debug/obj.target/third_party_mods/libjingle/libjingle.a \
+
+NODE_WEBRTC_LDFLAGS = -pthread -Wl,-z,noexecstack -fPIC -L/usr/lib/i386-linux-gnu -m32 $(NODE_FLAGS) -Wl,--start-group $(NODE_OBJS) $(WEBRTC_LIBS) -Wl,--end-group -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lm -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lX11 -lXext -lexpat -ldl -lasound -lpulse -shared
+
+WEBRTC_LDFLAGS = -pthread -Wl,-z,noexecstack -fPIC -L/usr/lib/i386-linux-gnu -m32 $(FLAGS) -Wl,--start-group $(SAMPLE_OBJS) $(WEBRTC_LIBS) -Wl,--end-group -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lm -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lX11 -lXext -lexpat -ldl -lasound -lpulse
+
+all: binding sample node_module
+
+sample:
+ g++ $(WEBRTC_LDFLAGS)
+
+node_module:
+ g++ $(DEFS) $(CFLAGS) $(CCFLAGS) $(INCLUDE_DIRS) src/binding.cc -c -o $(BUILD_DIR)/binding.o
+ g++ $(NODE_WEBRTC_LDFLAGS)
+ node --debug index.js
+
+binding:
+ g++ $(DEFS) $(CFLAGS) $(CCFLAGS) $(INCLUDE_DIRS) src/defaults.cc -c -o $(BUILD_DIR)/defaults.o
+ g++ $(DEFS) $(CFLAGS) $(CCFLAGS) $(INCLUDE_DIRS) src/peerconnection_client.cc -c -o $(BUILD_DIR)/peerconnection_client.o
+ g++ $(DEFS) $(CFLAGS) $(CCFLAGS) $(INCLUDE_DIRS) src/observer.cc -c -o $(BUILD_DIR)/observer.o
+ g++ $(DEFS) $(CFLAGS) $(CCFLAGS) $(INCLUDE_DIRS) src/main.cc -c -o $(BUILD_DIR)/main.o
+
+webrtc:
+ cd $(WEBRTC_ROOT_PATH) && python src/build/merge_libs.py out/Debug/ webrtc-debug-merged.a
+ cp $(WEBRTC_ROOT_PATH)/webrtc-debug-merged.a lib/webrtc-debug.a
+
+clean:
+ rm -rf build/*
+
+cleanall: clean
+ rm lib/webrtc-debug-merged.a
+
+.PHONY: sample node_module
Binary file not shown.
@@ -0,0 +1,28 @@
+// BEGIN NODE
+var webrtc = require("./webrtc")
+ , colors = require("colors");
+// END NODE
+//
+var peerconnection;
+
+console.log("dumping <WebRTC> native module:".blue);
+console.dir(webrtc);
+
+console.log("dumping <PeerConnection> object:".blue);
+console.dir(peerconnection = new webrtc.PeerConnection("STUN stun.l.google.com:19302"));
+
+console.log("<PeerConnection> methods invoke:".grey);
+console.log("PeerConnection.addStream():".grey + peerconnection.addStream("audio_label"));
+console.log("PeerConnection.connect():".grey + peerconnection.connect());
+/*
+console.log(peerconnection.addStream());
+console.log(peerconnection.send());
+console.log(peerconnection.close());
+*/
+
+
+/* JUST TO HOLD THE EVENT LOOP */
+require('http').createServer(function (req, res) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.end('\n');
+}).listen(1337, "127.0.0.1");
Binary file not shown.
@@ -0,0 +1,12 @@
+{
+ "name": "node-webrtc"
+ , "version": "0.0.1"
+ , "description": "WebRTC in Node.JS!"
+ , "keywords": []
+ , "author": "João Martins <joao.marcal.martins@gmail.com>"
+ , "dependencies": {
+ "colors": "latest"
+ }
+ , "main": "index"
+ , "engines": { "node": "0.6.x" }
+}
@@ -0,0 +1,170 @@
+/* This code is PUBLIC DOMAIN, and is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. See the accompanying
+ * LICENSE file.
+ */
+
+#include <v8.h>
+#include <node.h>
+
+#include "defaults.h"
+
+// PeerConnection
+#include "talk/app/webrtc/peerconnection.h"
+#include "talk/app/webrtc/peerconnectionfactory.h"
+#include "talk/base/common.h"
+#include "talk/base/logging.h"
+#include "talk/p2p/client/basicportallocator.h"
+#include "talk/session/phone/videorendererfactory.h"
+
+#include "talk/base/scoped_ptr.h"
+
+#define WARN(msg) fprintf(stderr, "\033[01;33m native:%s \033[00m\n", msg)
+#define INFO(msg) fprintf(stderr, "\033[01;34m native:%s \033[00m\n", msg)
+
+using namespace node;
+using namespace v8;
+
+/*
+template<typename VOICE, typename VIDEO>
+class MediaEngineImpl<VOICE, VIDEO>: public cricket::CompositeMediaEngine<VOICE, VIDEO> {
+};
+*/
+
+class ObserverImpl: public webrtc::PeerConnectionObserver {
+ void OnSignalingMessage(const std::string& msg) {
+ WARN("onsignalling message");
+ }
+
+ void OnAddStream(const std::string& stream_id, bool video) {
+ WARN("onaddstream");
+ }
+
+ void OnRemoveStream(const std::string& stream_id, bool video) {
+ WARN("onremovestream");
+ }
+};
+
+class PeerConnection: ObjectWrap {
+ private:
+ talk_base::scoped_ptr<webrtc::PeerConnectionFactory> connection_factory;
+ talk_base::scoped_ptr<talk_base::Thread> worker_thread;
+ talk_base::scoped_ptr<cricket::PortAllocator> port_allocator;
+
+ ObserverImpl observer;
+ talk_base::scoped_ptr<webrtc::PeerConnection> connection;
+
+ public:
+
+ static Persistent<FunctionTemplate> function_template;
+
+ static void Init(Handle<Object> target) {
+ HandleScope scope;
+
+ Local<FunctionTemplate> t = FunctionTemplate::New(New);
+
+ function_template = Persistent<FunctionTemplate>::New(t);
+ function_template->SetClassName(String::NewSymbol("PeerConnection"));
+ function_template->InstanceTemplate()->SetInternalFieldCount(1);
+
+ NODE_SET_PROTOTYPE_METHOD(function_template, "addStream", AddStream);
+ NODE_SET_PROTOTYPE_METHOD(function_template, "send", Send);
+ NODE_SET_PROTOTYPE_METHOD(function_template, "connect", Connect);
+ NODE_SET_PROTOTYPE_METHOD(function_template, "close", Close);
+
+ target->Set(String::NewSymbol("PeerConnection"), function_template->GetFunction());
+ }
+
+
+ PeerConnection() {
+ INFO("new PeerConnection");
+
+ worker_thread.reset(new talk_base::Thread());
+ worker_thread->SetName("WorkerThread", &observer);
+ worker_thread->Start();
+
+ connection_factory.reset(new webrtc::PeerConnectionFactory(worker_thread.get()));
+ connection_factory->Initialize();
+
+ port_allocator.reset(new cricket::BasicPortAllocator(
+ new talk_base::BasicNetworkManager(),
+ talk_base::SocketAddress("stun.l.google.com", 19302),
+ talk_base::SocketAddress(),
+ talk_base::SocketAddress(),
+ talk_base::SocketAddress()));
+
+ connection.reset(connection_factory->CreatePeerConnection(
+ port_allocator.get(), worker_thread.get()));
+
+ connection.get();
+
+ connection->RegisterObserver(&observer);
+ }
+
+ Handle<Boolean> AddStream(Local<String> label) {
+ return Boolean::New(connection->AddStream(*v8::String::Utf8Value(label), false));
+ }
+
+ void Send(Local<String> text) {
+ }
+
+ Handle<Boolean> Connect() {
+ return Boolean::New(connection->Connect());
+ }
+
+ Handle<Boolean> Close() {
+ return Boolean::New(connection->Close());
+ }
+
+ ~PeerConnection() {
+ }
+
+ static Handle<Value> New(const Arguments& args) {
+ HandleScope scope;
+ PeerConnection* peerconnection = new PeerConnection();
+ peerconnection->Wrap(args.This());
+ peerconnection->Ref();
+ return args.This();
+ }
+
+ static Handle<Value> Send(const Arguments& args) {
+ HandleScope scope;
+ PeerConnection* peerconnection = ObjectWrap::Unwrap<PeerConnection>(args.This());
+ peerconnection->Send(args[0]->ToString());
+ return scope.Close(args.This());
+ }
+
+ static Handle<Value> Connect(const Arguments& args) {
+ HandleScope scope;
+
+ PeerConnection* peerconnection = ObjectWrap::Unwrap<PeerConnection>(args.This());
+ Handle<Boolean> result = peerconnection->Connect();
+ return scope.Close(result);
+ }
+
+ static Handle<Value> Close(const Arguments& args) {
+ HandleScope scope;
+
+ PeerConnection* peerconnection = ObjectWrap::Unwrap<PeerConnection>(args.This());
+ peerconnection->Unref();
+
+ Handle<Boolean> result = peerconnection->Close();
+ return scope.Close(result);
+ }
+
+ static Handle<Value> AddStream(const Arguments& args) {
+ HandleScope scope;
+ PeerConnection* peerconnection = ObjectWrap::Unwrap<PeerConnection>(args.This());
+ Handle<Boolean> result = peerconnection->AddStream(args[0]->ToString());
+ return scope.Close(result);
+ }
+};
+
+Persistent<FunctionTemplate> PeerConnection::function_template;
+
+extern "C" {
+ static void init (Handle<Object> target) {
+ PeerConnection::Init(target);
+ }
+
+ NODE_MODULE(webrtc, init);
+}
Oops, something went wrong.

0 comments on commit 2794447

Please sign in to comment.