| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 return 0; | 325 return 0; |
| 326 } | 326 } |
| 327 | 327 |
| 328 rtcConfiguration->appendCertificate(certificate->certificateShallowC
opy()); | 328 rtcConfiguration->appendCertificate(certificate->certificateShallowC
opy()); |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 return rtcConfiguration; | 332 return rtcConfiguration; |
| 333 } | 333 } |
| 334 | 334 |
| 335 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options,
ExceptionState& exceptionState) | 335 RTCOfferOptions* RTCPeerConnection::parseOfferOptions(const Dictionary& options) |
| 336 { | 336 { |
| 337 if (options.isUndefinedOrNull()) | 337 if (options.isUndefinedOrNull()) |
| 338 return 0; | 338 return 0; |
| 339 | 339 |
| 340 Vector<String> propertyNames; | 340 Vector<String> propertyNames; |
| 341 options.getPropertyNames(propertyNames); | 341 options.getPropertyNames(propertyNames); |
| 342 | 342 |
| 343 // Treat |options| as MediaConstraints if it is empty or has "optional" or "
mandatory" properties for compatibility. | 343 // Treat |options| as MediaConstraints if it is empty or has "optional" or "
mandatory" properties for compatibility. |
| 344 // TODO(jiayl): remove constraints when RTCOfferOptions reaches Stable and c
lient code is ready. | 344 // TODO(jiayl): remove constraints when RTCOfferOptions reaches Stable and c
lient code is ready. |
| 345 if (propertyNames.isEmpty() || propertyNames.contains("optional") || propert
yNames.contains("mandatory")) | 345 if (propertyNames.isEmpty() || propertyNames.contains("optional") || propert
yNames.contains("mandatory")) |
| 346 return 0; | 346 return 0; |
| 347 | 347 |
| 348 int32_t offerToReceiveVideo = -1; | 348 int32_t offerToReceiveVideo = -1; |
| 349 int32_t offerToReceiveAudio = -1; | 349 int32_t offerToReceiveAudio = -1; |
| 350 bool voiceActivityDetection = true; | 350 bool voiceActivityDetection = true; |
| 351 bool iceRestart = false; | 351 bool iceRestart = false; |
| 352 | 352 |
| 353 if (DictionaryHelper::get(options, "offerToReceiveVideo", offerToReceiveVide
o) && offerToReceiveVideo < 0) { | 353 if (DictionaryHelper::get(options, "offerToReceiveVideo", offerToReceiveVide
o) && offerToReceiveVideo < 0) |
| 354 exceptionState.throwTypeError("Invalid offerToReceiveVideo"); | 354 offerToReceiveVideo = 0; |
| 355 return 0; | 355 if (DictionaryHelper::get(options, "offerToReceiveAudio", offerToReceiveAudi
o) && offerToReceiveAudio < 0) |
| 356 } | 356 offerToReceiveAudio = 0; |
| 357 | |
| 358 if (DictionaryHelper::get(options, "offerToReceiveAudio", offerToReceiveAudi
o) && offerToReceiveAudio < 0) { | |
| 359 exceptionState.throwTypeError("Invalid offerToReceiveAudio"); | |
| 360 return 0; | |
| 361 } | |
| 362 | |
| 363 DictionaryHelper::get(options, "voiceActivityDetection", voiceActivityDetect
ion); | 357 DictionaryHelper::get(options, "voiceActivityDetection", voiceActivityDetect
ion); |
| 364 DictionaryHelper::get(options, "iceRestart", iceRestart); | 358 DictionaryHelper::get(options, "iceRestart", iceRestart); |
| 365 | 359 |
| 366 RTCOfferOptions* rtcOfferOptions = RTCOfferOptions::create(offerToReceiveVid
eo, offerToReceiveAudio, voiceActivityDetection, iceRestart); | 360 RTCOfferOptions* rtcOfferOptions = RTCOfferOptions::create(offerToReceiveVid
eo, offerToReceiveAudio, voiceActivityDetection, iceRestart); |
| 367 return rtcOfferOptions; | 361 return rtcOfferOptions; |
| 368 } | 362 } |
| 369 | 363 |
| 370 RTCPeerConnection* RTCPeerConnection::create(ExecutionContext* context, const Di
ctionary& rtcConfiguration, const Dictionary& mediaConstraints, ExceptionState&
exceptionState) | 364 RTCPeerConnection* RTCPeerConnection::create(ExecutionContext* context, const Di
ctionary& rtcConfiguration, const Dictionary& mediaConstraints, ExceptionState&
exceptionState) |
| 371 { | 365 { |
| 372 if (mediaConstraints.isObject()) | 366 if (mediaConstraints.isObject()) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 } | 425 } |
| 432 } | 426 } |
| 433 | 427 |
| 434 RTCPeerConnection::~RTCPeerConnection() | 428 RTCPeerConnection::~RTCPeerConnection() |
| 435 { | 429 { |
| 436 // This checks that close() or stop() is called before the destructor. | 430 // This checks that close() or stop() is called before the destructor. |
| 437 // We are assuming that a wrapper is always created when RTCPeerConnection i
s created. | 431 // We are assuming that a wrapper is always created when RTCPeerConnection i
s created. |
| 438 ASSERT(m_closed || m_stopped); | 432 ASSERT(m_closed || m_stopped); |
| 439 } | 433 } |
| 440 | 434 |
| 441 void RTCPeerConnection::createOffer(ExecutionContext* context, RTCSessionDescrip
tionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCallback, co
nst Dictionary& rtcOfferOptions, ExceptionState& exceptionState) | 435 void RTCPeerConnection::createOffer(ExecutionContext* context, RTCSessionDescrip
tionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCallback, co
nst Dictionary& rtcOfferOptions) |
| 442 { | 436 { |
| 443 if (errorCallback) | 437 ASSERT(successCallback); |
| 444 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferLegac
yFailureCallback); | 438 ASSERT(errorCallback); |
| 445 else | 439 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferLegacyFai
lureCallback); |
| 446 Deprecation::countDeprecation(context, UseCounter::RTCPeerConnectionCrea
teOfferLegacyNoFailureCallback); | 440 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) |
| 447 | |
| 448 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | |
| 449 return; | 441 return; |
| 450 | 442 |
| 451 ASSERT(successCallback); | 443 RTCOfferOptions* offerOptions = parseOfferOptions(rtcOfferOptions); |
| 452 | |
| 453 RTCOfferOptions* offerOptions = parseOfferOptions(rtcOfferOptions, exception
State); | |
| 454 if (exceptionState.hadException()) | |
| 455 return; | |
| 456 | |
| 457 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr
eate(executionContext(), this, successCallback, errorCallback); | 444 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr
eate(executionContext(), this, successCallback, errorCallback); |
| 458 | 445 |
| 459 if (offerOptions) { | 446 if (offerOptions) { |
| 460 if (offerOptions->offerToReceiveAudio() != -1 || offerOptions->offerToRe
ceiveVideo() != -1) | 447 if (offerOptions->offerToReceiveAudio() != -1 || offerOptions->offerToRe
ceiveVideo() != -1) |
| 461 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL
egacyOfferOptions); | 448 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL
egacyOfferOptions); |
| 462 else if (errorCallback) | 449 else |
| 463 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL
egacyCompliant); | 450 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL
egacyCompliant); |
| 464 | 451 |
| 465 m_peerHandler->createOffer(request, offerOptions); | 452 m_peerHandler->createOffer(request, offerOptions); |
| 466 } else { | 453 } else { |
| 467 MediaErrorState mediaErrorState; | 454 MediaErrorState mediaErrorState; |
| 468 WebMediaConstraints constraints = MediaConstraintsImpl::create(context,
rtcOfferOptions, mediaErrorState); | 455 WebMediaConstraints constraints = MediaConstraintsImpl::create(context,
rtcOfferOptions, mediaErrorState); |
| 469 if (mediaErrorState.hadException()) { | 456 // Report constraints parsing errors via the callback, but ignore unknow
n/unsupported constraints as they |
| 470 mediaErrorState.raiseException(exceptionState); | 457 // would be silently discarded by WebIDL. |
| 458 if (mediaErrorState.canGenerateException()) { |
| 459 String errorMsg = mediaErrorState.getErrorMessage(); |
| 460 asyncCallErrorCallback(errorCallback, DOMException::create(Operation
Error, errorMsg)); |
| 471 return; | 461 return; |
| 472 } | 462 } |
| 473 | 463 |
| 474 if (!constraints.isEmpty()) | 464 if (!constraints.isEmpty()) |
| 475 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL
egacyConstraints); | 465 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL
egacyConstraints); |
| 476 else if (errorCallback) | 466 else |
| 477 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL
egacyCompliant); | 467 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateOfferL
egacyCompliant); |
| 478 | 468 |
| 479 m_peerHandler->createOffer(request, constraints); | 469 m_peerHandler->createOffer(request, constraints); |
| 480 } | 470 } |
| 481 } | 471 } |
| 482 | 472 |
| 483 void RTCPeerConnection::createAnswer(ExecutionContext* context, RTCSessionDescri
ptionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCallback, c
onst Dictionary& mediaConstraints, ExceptionState& exceptionState) | 473 void RTCPeerConnection::createAnswer(ExecutionContext* context, RTCSessionDescri
ptionCallback* successCallback, RTCPeerConnectionErrorCallback* errorCallback, c
onst Dictionary& mediaConstraints) |
| 484 { | 474 { |
| 485 if (errorCallback) | 475 ASSERT(successCallback); |
| 486 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega
cyFailureCallback); | 476 ASSERT(errorCallback); |
| 487 else | 477 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLegacyFa
ilureCallback); |
| 488 Deprecation::countDeprecation(context, UseCounter::RTCPeerConnectionCrea
teAnswerLegacyNoFailureCallback); | |
| 489 | |
| 490 if (mediaConstraints.isObject()) | 478 if (mediaConstraints.isObject()) |
| 491 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega
cyConstraints); | 479 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega
cyConstraints); |
| 492 else if (errorCallback) | 480 else |
| 493 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega
cyCompliant); | 481 UseCounter::count(context, UseCounter::RTCPeerConnectionCreateAnswerLega
cyCompliant); |
| 494 | 482 |
| 495 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 483 if (callErrorCallbackIfSignalingStateClosed(m_signalingState, errorCallback)
) |
| 496 return; | 484 return; |
| 497 | 485 |
| 498 ASSERT(successCallback); | |
| 499 | |
| 500 MediaErrorState mediaErrorState; | 486 MediaErrorState mediaErrorState; |
| 501 WebMediaConstraints constraints = MediaConstraintsImpl::create(context, medi
aConstraints, mediaErrorState); | 487 WebMediaConstraints constraints = MediaConstraintsImpl::create(context, medi
aConstraints, mediaErrorState); |
| 502 if (mediaErrorState.hadException()) { | 488 // Report constraints parsing errors via the callback, but ignore unknown/un
supported constraints as they |
| 503 mediaErrorState.raiseException(exceptionState); | 489 // would be silently discarded by WebIDL. |
| 490 if (mediaErrorState.canGenerateException()) { |
| 491 String errorMsg = mediaErrorState.getErrorMessage(); |
| 492 asyncCallErrorCallback(errorCallback, DOMException::create(OperationErro
r, errorMsg)); |
| 504 return; | 493 return; |
| 505 } | 494 } |
| 506 | 495 |
| 507 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr
eate(executionContext(), this, successCallback, errorCallback); | 496 RTCSessionDescriptionRequest* request = RTCSessionDescriptionRequestImpl::cr
eate(executionContext(), this, successCallback, errorCallback); |
| 508 m_peerHandler->createAnswer(request, constraints); | 497 m_peerHandler->createAnswer(request, constraints); |
| 509 } | 498 } |
| 510 | 499 |
| 511 ScriptPromise RTCPeerConnection::setLocalDescription(ScriptState* scriptState, c
onst RTCSessionDescriptionInit& sessionDescriptionInit) | 500 ScriptPromise RTCPeerConnection::setLocalDescription(ScriptState* scriptState, c
onst RTCSessionDescriptionInit& sessionDescriptionInit) |
| 512 { | 501 { |
| 513 if (m_signalingState == SignalingStateClosed) | 502 if (m_signalingState == SignalingStateClosed) |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 { | 1121 { |
| 1133 visitor->trace(m_localStreams); | 1122 visitor->trace(m_localStreams); |
| 1134 visitor->trace(m_remoteStreams); | 1123 visitor->trace(m_remoteStreams); |
| 1135 visitor->trace(m_dispatchScheduledEventRunner); | 1124 visitor->trace(m_dispatchScheduledEventRunner); |
| 1136 visitor->trace(m_scheduledEvents); | 1125 visitor->trace(m_scheduledEvents); |
| 1137 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac
e(visitor); | 1126 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac
e(visitor); |
| 1138 ActiveDOMObject::trace(visitor); | 1127 ActiveDOMObject::trace(visitor); |
| 1139 } | 1128 } |
| 1140 | 1129 |
| 1141 } // namespace blink | 1130 } // namespace blink |
| OLD | NEW |