|
21 | 21 | #include "common.h" |
22 | 22 | #include "globals.h" |
23 | 23 | #include "observer/createsessiondescriptionobserver.h" |
| 24 | +#include "observer/setsessiondescriptionobserver.h" |
24 | 25 | #include "observer/peerconnectionobserver.h" |
25 | 26 | #include "rtccertificate.h" |
26 | 27 | #include "rtcpeerconnection.h" |
| 28 | +#include "rtcsessiondescription.h" |
27 | 29 |
|
28 | 30 | Nan::Persistent<FunctionTemplate> RTCPeerConnection::constructor; |
29 | 31 |
|
30 | 32 | static const char sRTCPeerConnection[] = "RTCPeerConnection"; |
31 | 33 |
|
32 | 34 | static const char kCreateOffer[] = "createOffer"; |
| 35 | +static const char kSetLocalDescription[] = "setLocalDescription"; |
| 36 | +static const char kCreateDataChannel[] = "createDataChannel"; |
33 | 37 | static const char kGenerateCertificate[] = "generateCertificate"; |
34 | 38 |
|
35 | 39 | static const char kIceServers[] = "iceServers"; |
@@ -90,6 +94,8 @@ NAN_MODULE_INIT(RTCPeerConnection::Init) { |
90 | 94 |
|
91 | 95 | Local<ObjectTemplate> prototype = ctor->InstanceTemplate(); |
92 | 96 | Nan::SetMethod(prototype, kCreateOffer, CreateOffer); |
| 97 | + Nan::SetMethod(prototype, kSetLocalDescription, SetLocalDescription); |
| 98 | + Nan::SetMethod(prototype, kCreateDataChannel, CreateDataChannel); |
93 | 99 |
|
94 | 100 | Local<ObjectTemplate> tpl = ctor->InstanceTemplate(); |
95 | 101 | Nan::SetAccessor(tpl, LOCAL_STRING(kConnectionState), |
@@ -132,7 +138,6 @@ NAN_METHOD(RTCPeerConnection::New) { |
132 | 138 | CONSTRUCTOR_HEADER("RTCPeerConnection") |
133 | 139 | webrtc::FakeConstraints constraints; |
134 | 140 | webrtc::PeerConnectionInterface::RTCConfiguration _config; |
135 | | - webrtc::PeerConnectionInterface::IceServer server; |
136 | 141 |
|
137 | 142 | if (info.Length() > 0) { |
138 | 143 | ASSERT_OBJECT_ARGUMENT(0, config); |
@@ -223,6 +228,38 @@ NAN_METHOD(RTCPeerConnection::CreateOffer) { |
223 | 228 | object->_peerConnection->CreateOffer(observer, &constraints); |
224 | 229 | } |
225 | 230 |
|
| 231 | +NAN_METHOD(RTCPeerConnection::SetLocalDescription) { |
| 232 | + METHOD_HEADER("RTCPeerConnection", "setLocalDescription"); |
| 233 | + UNWRAP_OBJECT(RTCPeerConnection, object); |
| 234 | + |
| 235 | + rtc::scoped_refptr<webrtc::SetSessionDescriptionObserver> observer; |
| 236 | + |
| 237 | + // FIXME: Promise implementation only |
| 238 | + DECLARE_PROMISE_RESOLVER; |
| 239 | + ASSERT_REJECT_OBJECT_ARGUMENT(0, sessionDescription); |
| 240 | + |
| 241 | + // FIXME: validate it's a RTCSessionDescription object |
| 242 | + RTCSessionDescription* _sessionDescription = Nan::ObjectWrap::Unwrap<RTCSessionDescription>(sessionDescription); |
| 243 | + |
| 244 | + observer = SetSessionDescriptionObserver::Create( |
| 245 | + new Nan::Persistent<Promise::Resolver>(resolver)); |
| 246 | + |
| 247 | + object->_peerConnection->SetLocalDescription(observer, _sessionDescription->_sessionDescription); |
| 248 | + |
| 249 | +} |
| 250 | + |
| 251 | +NAN_METHOD(RTCPeerConnection::CreateDataChannel) { |
| 252 | + METHOD_HEADER("RTCPeerConnection", "setLocalDescription"); |
| 253 | + UNWRAP_OBJECT(RTCPeerConnection, object); |
| 254 | + |
| 255 | + ASSERT_STRING_ARGUMENT(0, name); |
| 256 | + |
| 257 | + const webrtc::DataChannelInit init; |
| 258 | + |
| 259 | + object->_peerConnection->CreateDataChannel(*name, &init); |
| 260 | + |
| 261 | +} |
| 262 | + |
226 | 263 | NAN_GETTER(RTCPeerConnection::GetConnectionState) { |
227 | 264 | info.GetReturnValue().Set(LOCAL_STRING("new")); |
228 | 265 | } |
|
0 commit comments