Home | History | Annotate | Download | only in mediastream
      1 /*
      2  * Copyright (C) 2012 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer
     12  *    in the documentation and/or other materials provided with the
     13  *    distribution.
     14  * 3. Neither the name of Google Inc. nor the names of its contributors
     15  *    may be used to endorse or promote products derived from this
     16  *    software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "config.h"
     32 #include "modules/mediastream/RTCSessionDescription.h"
     33 
     34 #include "bindings/core/v8/Dictionary.h"
     35 #include "bindings/core/v8/ExceptionState.h"
     36 #include "core/dom/ExceptionCode.h"
     37 
     38 namespace blink {
     39 
     40 static bool verifyType(const String& type)
     41 {
     42     return type == "offer" || type == "pranswer" || type == "answer";
     43 }
     44 
     45 static String constructIllegalTypeExceptionMessage(const String& type)
     46 {
     47     return "Illegal value of attribute 'type' : " + type;
     48 }
     49 
     50 RTCSessionDescription* RTCSessionDescription::create(const Dictionary& descriptionInitDict, ExceptionState& exceptionState)
     51 {
     52     String type;
     53     bool ok = DictionaryHelper::get(descriptionInitDict, "type", type);
     54     if (ok && !verifyType(type)) {
     55         exceptionState.throwDOMException(TypeMismatchError, constructIllegalTypeExceptionMessage(type));
     56         return nullptr;
     57     }
     58 
     59     String sdp;
     60     DictionaryHelper::get(descriptionInitDict, "sdp", sdp);
     61 
     62     return new RTCSessionDescription(WebRTCSessionDescription(type, sdp));
     63 }
     64 
     65 RTCSessionDescription* RTCSessionDescription::create(WebRTCSessionDescription webSessionDescription)
     66 {
     67     return new RTCSessionDescription(webSessionDescription);
     68 }
     69 
     70 RTCSessionDescription::RTCSessionDescription(WebRTCSessionDescription webSessionDescription)
     71     : m_webSessionDescription(webSessionDescription)
     72 {
     73 }
     74 
     75 String RTCSessionDescription::type()
     76 {
     77     return m_webSessionDescription.type();
     78 }
     79 
     80 void RTCSessionDescription::setType(const String& type, ExceptionState& exceptionState)
     81 {
     82     if (verifyType(type))
     83         m_webSessionDescription.setType(type);
     84     else
     85         exceptionState.throwDOMException(TypeMismatchError, constructIllegalTypeExceptionMessage(type));
     86 }
     87 
     88 String RTCSessionDescription::sdp()
     89 {
     90     return m_webSessionDescription.sdp();
     91 }
     92 
     93 void RTCSessionDescription::setSdp(const String& sdp)
     94 {
     95     m_webSessionDescription.setSDP(sdp);
     96 }
     97 
     98 WebRTCSessionDescription RTCSessionDescription::webSessionDescription()
     99 {
    100     return m_webSessionDescription;
    101 }
    102 
    103 } // namespace blink
    104