Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@
'target_name': 'webrtc',
'sources': [
'src/event/createsessiondescriptionevent.cc',
'src/event/setsessiondescriptionevent.cc',
'src/event/emitterevent.cc',
'src/event/peerconnectioniceevent.cc',
'src/event/datachannelevent.cc',
'src/event/mediastreamevent.cc',
'src/event/messageevent.cc',
'src/event/eventqueue.cc',
'src/globals.cc',
'src/module.cc',
'src/eventemitter.cc',
'src/observer/createsessiondescriptionobserver.cc',
'src/observer/setsessiondescriptionobserver.cc',
'src/observer/peerconnectionobserver.cc',
'src/observer/datachannelobserver.cc',
'src/rtccertificate.cc',
'src/rtcicecandidate.cc',
'src/rtcpeerconnection.cc',
'src/rtcsessiondescription.cc',
'src/rtcdatachannel.cc',
'src/rtcmediastream.cc',
],
'include_dirs' : [
'build/include',
Expand Down
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
'use strict';

module.exports = require('bindings')('webrtc');
const EventEmitter = require('events').EventEmitter;
const webrtc = require('bindings')('webrtc');

function inherit(cl,parent) {
for( var k in parent.prototype ) {
cl.prototype[k] = parent.prototype[k];
}
}

var EventTarget = function(){};
inherit(EventTarget, EventEmitter);
EventTarget.prototype.addEventListener = EventEmitter.prototype.on;

[webrtc.RTCPeerConnection, webrtc.RTCDataChannel].map((cl)=>{
inherit(cl, EventTarget);
});

module.exports = webrtc;
34 changes: 34 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
#define ERROR_PROPERTY_NOT_BOOLEAN(NAME) \
"The '" << NAME << "' property is not a boolean."

#define ERROR_PROPERTY_NOT_OBJECT(NAME) \
"The '" << NAME << "' property is not an object."

#define ERROR_PROPERTY_NOT_ARRAY(NAME) \
"The '" << NAME << "' property is not an object."

#define ERROR_PROPERTY_NOT_UINT8ARRAY(NAME) \
"The '" << NAME << "' property is not a Uint8Array."

Expand All @@ -56,6 +62,9 @@
#define ERROR_ARGUMENT_NOT_FUNCTION(INDEX, NAME) \
"parameter " << INDEX << " ('" << NAME << "') is not a function."

#define ERROR_ARGUMENT_NOT_STRING(INDEX, NAME) \
"parameter " << INDEX << " ('" << NAME << "') is not a string."

#ifdef DEBUG
#define CONSTRUCTOR_HEADER(NAME) \
LOG(LS_INFO) << __PRETTY_FUNCTION__; \
Expand Down Expand Up @@ -116,6 +125,14 @@
\
Local<Function> N = info[I].As<v8::Function>();

#define ASSERT_STRING_ARGUMENT(I, N) \
if (!info[I]->IsString()) { \
errorStream << ERROR_ARGUMENT_NOT_STRING(I + 1, #N); \
return Nan::ThrowTypeError(errorStream.str().c_str()); \
} \
\
String::Utf8Value N(info[I]->ToString());

#define ASSERT_REJECT_OBJECT_ARGUMENT(I, N) \
if (!info[I]->IsObject()) { \
errorStream << ERROR_ARGUMENT_NOT_OBJECT(I + 1, #N); \
Expand Down Expand Up @@ -168,6 +185,23 @@
\
Local<Boolean> S(V->ToBoolean());

#define ASSERT_PROPERTY_OBJECT(N, V, S) \
if (!V->IsObject()) { \
errorStream << ERROR_PROPERTY_NOT_OBJECT(N); \
return Nan::ThrowTypeError(errorStream.str().c_str()); \
} \
\
Local<Object> S(V->ToObject());

#define ASSERT_PROPERTY_ARRAY(N, V, S) \
if (!V->IsArray()) { \
errorStream << ERROR_PROPERTY_NOT_ARRAY(N); \
return Nan::ThrowTypeError(errorStream.str().c_str()); \
} \
\
Local<Array> S = Local<Array>::Cast(V);


#define ASSERT_REJECT_PROPERTY_BOOLEAN(N, V, S) \
if (!V->IsBoolean()) { \
errorStream << ERROR_PROPERTY_NOT_BOOLEAN(N); \
Expand Down
41 changes: 41 additions & 0 deletions src/event/datachannelevent.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2017 Axel Isouard <axel@isouard.fr>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "common.h"
#include "datachannelevent.h"
#include "eventemitter.h"
#include "rtcdatachannel.h"

using namespace v8;

static const char kChannel[] = "channel";

DataChannelEvent::DataChannelEvent(EventEmitter *eventEmitter,
const rtc::scoped_refptr<webrtc::DataChannelInterface> &datachannel)
: EmitterEvent(eventEmitter), _channel(datachannel) {
}

void DataChannelEvent::Handle() {
Nan::HandleScope scope;

// FIXME: make proper DataChannelEvent ?
Local<Object> e = Nan::New<Object>();
// FIXME: move to observer ?
Nan::Persistent<Object> channel(RTCDataChannel::Create(_channel));
e->Set(LOCAL_STRING(kChannel), Nan::New(channel));

_eventEmitter->EmitData(LOCAL_STRING(_type), e);
}
38 changes: 38 additions & 0 deletions src/event/datachannelevent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2017 Axel Isouard <axel@isouard.fr>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef EVENT_DATACHANNELEVENT_H_
#define EVENT_DATACHANNELEVENT_H_

#include "emitterevent.h"
#include "eventemitter.h"
#include <webrtc/api/jsep.h>
#include <webrtc/api/datachannelinterface.h>

using namespace v8;

class DataChannelEvent : public EmitterEvent {
public:
explicit DataChannelEvent(EventEmitter *eventEmitter,
const rtc::scoped_refptr<webrtc::DataChannelInterface>& datachannel);

void Handle();

private:
const rtc::scoped_refptr<webrtc::DataChannelInterface> _channel;
};

#endif // EVENT_DATACHANNELEVENT_H_
32 changes: 32 additions & 0 deletions src/event/emitterevent.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2017 Axel Isouard <axel@isouard.fr>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "common.h"
#include "emitterevent.h"

using namespace v8;

EmitterEvent::EmitterEvent(EventEmitter *eventEmitter)
: _eventEmitter(eventEmitter) {}

void EmitterEvent::Handle() {
Nan::HandleScope scope;
_eventEmitter->Emit(LOCAL_STRING(_type));
}

void EmitterEvent::SetType(const std::string &type) {
_type = type;
}
37 changes: 37 additions & 0 deletions src/event/emitterevent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2017 Axel Isouard <axel@isouard.fr>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef EVENT_EMITTEREVENT_H_
#define EVENT_EMITTEREVENT_H_

#include "event.h"
#include "eventemitter.h"

using namespace v8;

class EmitterEvent : public Event {
public:
explicit EmitterEvent(EventEmitter *eventEmitter);

void Handle();
void SetType(const std::string& type);

protected:
EventEmitter *_eventEmitter;
std::string _type;
};

#endif // EVENT_EMITTEREVENT_H_
41 changes: 41 additions & 0 deletions src/event/mediastreamevent.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2017 Axel Isouard <axel@isouard.fr>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "common.h"
#include "mediastreamevent.h"
#include "eventemitter.h"
#include "rtcmediastream.h"

using namespace v8;

static const char kStream[] = "stream";

MediaStreamEvent::MediaStreamEvent(EventEmitter *eventEmitter,
const rtc::scoped_refptr<webrtc::MediaStreamInterface> &mediastream)
: EmitterEvent(eventEmitter), _mediastream(mediastream) {
}

void MediaStreamEvent::Handle() {
Nan::HandleScope scope;

// FIXME: make proper MediaStreamEvent ?
Local<Object> e = Nan::New<Object>();
// FIXME: move to observer ?
Nan::Persistent<Object> mediastream(RTCMediaStream::Create(_mediastream));
e->Set(LOCAL_STRING(kStream), Nan::New(mediastream));

_eventEmitter->EmitData(LOCAL_STRING(_type), e);
}
38 changes: 38 additions & 0 deletions src/event/mediastreamevent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2017 Axel Isouard <axel@isouard.fr>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef EVENT_MEDIASTREAMEVENT_H_
#define EVENT_MEDIASTREAMEVENT_H_

#include "emitterevent.h"
#include "eventemitter.h"
#include <webrtc/api/jsep.h>
#include <webrtc/api/mediastreaminterface.h>

using namespace v8;

class MediaStreamEvent : public EmitterEvent {
public:
explicit MediaStreamEvent(EventEmitter *eventEmitter,
const rtc::scoped_refptr<webrtc::MediaStreamInterface>& datachannel);

void Handle();

private:
const rtc::scoped_refptr<webrtc::MediaStreamInterface> _mediastream;
};

#endif // EVENT_MEDIASTREAMEVENT_H_
39 changes: 39 additions & 0 deletions src/event/messageevent.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2017 Axel Isouard <axel@isouard.fr>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "common.h"
#include "messageevent.h"
#include "eventemitter.h"

using namespace v8;

static const char kData[] = "data";

MessageEvent::MessageEvent(EventEmitter *eventEmitter)
: EmitterEvent(eventEmitter) {}

void MessageEvent::Handle() {
Nan::HandleScope scope;

// FIXME: make proper MessageData ?
Local<Object> e = Nan::New<Object>();
e->Set(LOCAL_STRING(kData), LOCAL_STRING(_data));
_eventEmitter->EmitData(LOCAL_STRING(_type), e);
}

void MessageEvent::SetData(const std::string& data) {
_data = data;
}
Loading