diff --git a/.gitignore b/.gitignore index ffb0e5b3..37c326cd 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,4 @@ /3rdpart/media-server/.idea/ /ios/ /cmake-build-* +/3rdpart/ZLToolKit/cmake-build-mq/ diff --git a/3rdpart/assert.h b/3rdpart/assert.h index c3b4b1c2..00369393 100644 --- a/3rdpart/assert.h +++ b/3rdpart/assert.h @@ -12,19 +12,22 @@ #define ZLMEDIAKIT_ASSERT_H #include + +#ifdef __cplusplus +extern "C" { +#endif +extern void Assert_Throw(int failed, const char *exp, const char *func, const char *file, int line); +#ifdef __cplusplus +} +#endif + +#define CHECK(exp) Assert_Throw(!(exp), #exp, __FUNCTION__, __FILE__, __LINE__) + #ifndef NDEBUG #ifdef assert #undef assert #endif//assert - #ifdef __cplusplus - extern "C" { - #endif - extern void Assert_Throw(int failed, const char *exp, const char *func, const char *file, int line); - #ifdef __cplusplus - } - #endif - #define assert(exp) Assert_Throw(!(exp), #exp, __FUNCTION__, __FILE__, __LINE__); #else #define assert(e) ((void)0) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0db8dcea..b3a53a41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ option(ENABLE_TESTS "Enable Tests" true) option(ENABLE_SERVER "Enable Server" true) option(ENABLE_MEM_DEBUG "Enable Memory Debug" false) option(ENABLE_ASAN "Enable Address Sanitize" false) +option(ENABLE_WEBRTC "Enable WebRTC" true) if (ENABLE_MEM_DEBUG) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-wrap,free -Wl,-wrap,malloc -Wl,-wrap,realloc -Wl,-wrap,calloc") @@ -86,6 +87,10 @@ if (OPENSSL_FOUND AND ENABLE_OPENSSL) include_directories(${OPENSSL_INCLUDE_DIR}) add_definitions(-DENABLE_OPENSSL) list(APPEND LINK_LIB_LIST ${OPENSSL_LIBRARIES}) + if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND OPENSSL_USE_STATIC_LIBS) + list(APPEND LINK_LIB_LIST dl) + endif() + else() message(WARNING "openssl未找到,rtmp将不支持flash播放器,https/wss/rtsps/rtmps也将失效") endif () @@ -224,6 +229,24 @@ if(ENABLE_API) add_subdirectory(api) endif() +if (ENABLE_WEBRTC) + #查找srtp是否安装 + find_package(SRTP QUIET) + if (SRTP_FOUND) + message(STATUS "found library:${SRTP_LIBRARIES}") + include_directories(${SRTP_INCLUDE_DIRS}) + list(APPEND LINK_LIB_LIST ${SRTP_LIBRARIES}) + + add_definitions(-DENABLE_WEBRTC) + include_directories(./webrtc) + file(GLOB SRC_WEBRTC_LIST ./webrtc/*.cpp ./webrtc/*.h ./webrtc/*.hpp) + add_library(webrtc ${SRC_WEBRTC_LIST}) + list(APPEND LINK_LIB_LIST webrtc) + else () + message(WARNING "srtp未找到, webrtc相关功能打开失败") + endif () +endif () + if (NOT IOS) #测试程序 if(ENABLE_TESTS) diff --git a/cmake/FindSRTP.cmake b/cmake/FindSRTP.cmake new file mode 100644 index 00000000..8d88f405 --- /dev/null +++ b/cmake/FindSRTP.cmake @@ -0,0 +1,55 @@ +############################################################################ +# FindSRTP.txt +# Copyright (C) 2014 Belledonne Communications, Grenoble France +# +############################################################################ +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################ +# +# - Find the SRTP include file and library +# +# SRTP_FOUND - system has SRTP +# SRTP_INCLUDE_DIRS - the SRTP include directory +# SRTP_LIBRARIES - The libraries needed to use SRTP + +set(_SRTP_ROOT_PATHS + ${CMAKE_INSTALL_PREFIX} + ) + +find_path(SRTP_INCLUDE_DIRS + NAMES srtp2/srtp.h + HINTS _SRTP_ROOT_PATHS ${SRTP_PREFIX} + PATH_SUFFIXES include + ) + +if(SRTP_INCLUDE_DIRS) + set(HAVE_SRTP_SRTP_H 1) +endif() + +find_library(SRTP_LIBRARIES + NAMES srtp2 + HINTS ${_SRTP_ROOT_PATHS} ${SRTP_PREFIX} + PATH_SUFFIXES bin lib + ) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SRTP + DEFAULT_MSG + SRTP_INCLUDE_DIRS SRTP_LIBRARIES HAVE_SRTP_SRTP_H + ) + +mark_as_advanced(SRTP_INCLUDE_DIRS SRTP_LIBRARIES HAVE_SRTP_SRTP_H) \ No newline at end of file diff --git a/conf/config.ini b/conf/config.ini index 10aeab53..3826090d 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -140,7 +140,7 @@ charSet=utf-8 #http链接超时时间 keepAliveSecond=30 #http请求体最大字节数,如果post的body太大,则不适合缓存body在内存 -maxReqSize=4096 +maxReqSize=40960 #404网页内容,用户可以自定义404网页 notFound=404 Not Found

您访问的资源不存在!


ZLMediaKit-4.0
#http服务器监听端口 @@ -210,13 +210,23 @@ port=10000 #rtp超时时间,单位秒 timeoutSec=15 +[rtc] +#rtc播放推流、播放超时时间 +timeoutSec=15 +#本机对rtc客户端的可见ip,作为服务器时一般为公网ip,置空时,会自动获取网卡ip +externIP= +#设置remb比特率,非0时关闭twcc并开启remb。该设置在rtc推流时有效,可以控制推流画质 +rembBitRate=1000000 + [rtsp] #rtsp专有鉴权方式是采用base64还是md5方式 authBasic=0 -#rtsp拉流代理是否是直接代理模式 +#rtsp拉流、推流代理是否是直接代理模式 #直接代理后支持任意编码格式,但是会导致GOP缓存无法定位到I帧,可能会导致开播花屏 #并且如果是tcp方式拉流,如果rtp大于mtu会导致无法使用udp方式代理 #假定您的拉流源地址不是264或265或AAC,那么你可以使用直接代理的方式来支持rtsp代理 +#如果你是rtsp推拉流,但是rtc播放,也建议关闭直接代理模式, +#因为直接代理时,rtp中可能没有sps pps,会导致rtc无法播放 #默认开启rtsp直接代理,rtmp由于没有这些问题,是强制开启直接代理的 directProxy=1 #rtsp必须在此时间内完成握手,否则服务器会断开链接,单位秒 diff --git a/package/rpm/ZLMediaKit.spec b/package/rpm/ZLMediaKit.spec index 58b2b633..61c5f86b 100644 --- a/package/rpm/ZLMediaKit.spec +++ b/package/rpm/ZLMediaKit.spec @@ -2,10 +2,12 @@ %global use_devtoolset 0 %bcond_without faac %bcond_without x264 +%bcond_without webrtc %else %global use_devtoolset 1 %bcond_with faac %bcond_with x264 +%bcond_with webrtc %endif %bcond_without openssl @@ -22,8 +24,12 @@ URL: https://github.com/xia-chu/ZLMediaKit Source0: %{name}-%{version}.tar.xz %if %{with openssl} +%if 0%{?rhel} <= 7 && %{with webrtc} +BuildRequires: openssl11-devel +%else BuildRequires: openssl-devel %endif +%endif %if %{with mysql} BuildRequires: mysql-devel @@ -37,6 +43,10 @@ BuildRequires: faac-devel BuildRequires: x264-devel %endif +%if %{with webrtc} +BuildRequires: libsrtp-devel >= 2.0 +%endif + %if 0%{?use_devtoolset} BuildRequires: devtoolset-8-gcc-c++ %endif @@ -88,6 +98,10 @@ pushd %{_target_platform} -DENABLE_MYSQL:BOOL=%{with mysql} \ -DENABLE_FAAC:BOOL=%{with faac} \ -DENABLE_X264:BOOL=%{with x264} \ + -DENABLE_WEBRTC:BOOL=%{with webrtc} \ +%if %{with webrtc} && 0%{?rhel} <= 7 + -DOPENSSL_ROOT_DIR:STRING="/usr/lib64/openssl11;/usr/include/openssl11" \ +%endif -DENABLE_MP4:BOOL=ON \ -DENABLE_RTPPROXY:BOOL=ON \ -DENABLE_API:BOOL=ON \ diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 6e0af5e1..8ae6ff28 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -48,4 +48,8 @@ else() install(TARGETS MediaServer DESTINATION ${INSTALL_PATH_EXECUTABLE}) endif() -target_link_libraries(MediaServer jsoncpp ${LINK_LIB_LIST}) +if (CMAKE_SYSTEM_NAME MATCHES "Linux") + target_link_libraries(MediaServer -Wl,--start-group jsoncpp ${LINK_LIB_LIST} -Wl,--end-group) +else () + target_link_libraries(MediaServer jsoncpp ${LINK_LIB_LIST}) +endif () diff --git a/server/WebApi.cpp b/server/WebApi.cpp index be694d2a..3666fed1 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -37,6 +37,9 @@ #if defined(ENABLE_RTPPROXY) #include "Rtp/RtpServer.h" #endif +#ifdef ENABLE_WEBRTC +#include "../webrtc/WebRtcTransport.h" +#endif using namespace toolkit; using namespace mediakit; @@ -126,6 +129,26 @@ static HttpApi toApi(const function &cb) { }); } +static HttpApi toApi(const function &cb) { + return [cb](const Parser &parser, const HttpSession::HttpResponseInvoker &invoker, SockInfo &sender) { + GET_CONFIG(string, charSet, Http::kCharSet); + HttpSession::KeyValue headerOut; + headerOut["Content-Type"] = string("application/json; charset=") + charSet; + + Json::Value val; + val["code"] = API::Success; + + cb(sender, parser.getHeader(), headerOut, parser, val, invoker); + }; +} + +static HttpApi toApi(const function &cb) { + return toApi([cb](API_ARGS_STRING_ASYNC) { + cb(API_ARGS_VALUE); + invoker(200, headerOut, val.toStyledString()); + }); +} + void api_regist(const string &api_path, const function &func) { s_map_api.emplace(api_path, toApi(func)); } @@ -142,6 +165,14 @@ void api_regist(const string &api_path, const function &func){ + s_map_api.emplace(api_path, toApi(func)); +} + +void api_regist(const string &api_path, const function &func){ + s_map_api.emplace(api_path, toApi(func)); +} + //获取HTTP请求中url参数、content参数 static ApiArgsType getAllArgs(const Parser &parser) { ApiArgsType allArgs; @@ -380,8 +411,15 @@ void installWebApi() { int changed = API::Success; for (auto &pr : allArgs) { if (ini.find(pr.first) == ini.end()) { +#if 1 //没有这个key continue; +#else + // 新增配置选项,为了动态添加多个ffmpeg cmd 模板 + ini[pr.first] = pr.second; + // 防止changed变化 + continue; +#endif } if (ini[pr.first] == pr.second) { continue; @@ -1161,6 +1199,90 @@ void installWebApi() { #endif }); +#ifdef ENABLE_WEBRTC + api_regist("/index/api/webrtc",[](API_ARGS_STRING_ASYNC){ + CHECK_ARGS("app", "stream"); + + auto offer_sdp = allArgs.Content(); + auto type = allArgs.getUrlArgs()["type"]; + MediaInfo info(StrPrinter << "rtc://" << headerIn["Host"] << "/" << allArgs.getUrlArgs()["app"] << "/" << allArgs.getUrlArgs()["stream"] << "?" << allArgs.Params()); + + //设置返回类型 + headerOut["Content-Type"] = HttpFileManager::getContentType(".json"); + //设置跨域 + headerOut["Access-Control-Allow-Origin"] = "*"; + + if (type.empty() || !strcasecmp(type.data(), "play")) { + Broadcast::AuthInvoker authInvoker = [invoker, offer_sdp, val, info, headerOut](const string &err) mutable { + try { + auto src = dynamic_pointer_cast(MediaSource::find(RTSP_SCHEMA, info._vhost, info._app, info._streamid)); + if (!src) { + throw runtime_error("流不存在"); + } + if (!err.empty()) { + throw runtime_error(StrPrinter << "播放鉴权失败:" << err); + } + auto rtc = WebRtcTransportImp::create(EventPollerPool::Instance().getPoller()); + rtc->attach(src, info, true); + val["sdp"] = rtc->getAnswerSdp(offer_sdp); + val["type"] = "answer"; + invoker(200, headerOut, val.toStyledString()); + } catch (std::exception &ex) { + val["code"] = API::Exception; + val["msg"] = ex.what(); + invoker(200, headerOut, val.toStyledString()); + } + }; + + //广播通用播放url鉴权事件 + auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, info, authInvoker, sender); + if (!flag) { + //该事件无人监听,默认不鉴权 + authInvoker(""); + } + return; + } + + if (!strcasecmp(type.data(), "push")) { + Broadcast::PublishAuthInvoker authInvoker = [invoker, offer_sdp, val, info, headerOut](const string &err, bool enableHls, bool enableMP4) mutable { + try { + auto src = dynamic_pointer_cast(MediaSource::find(RTSP_SCHEMA, info._vhost, info._app, info._streamid)); + if (src) { + throw std::runtime_error("已经在推流"); + } + if (!err.empty()) { + throw runtime_error(StrPrinter << "推流鉴权失败:" << err); + } + auto push_src = std::make_shared(info._vhost, info._app, info._streamid); + push_src->setProtocolTranslation(enableHls, enableMP4); + auto rtc = WebRtcTransportImp::create(EventPollerPool::Instance().getPoller()); + push_src->setListener(rtc); + rtc->attach(push_src, info, false); + val["sdp"] = rtc->getAnswerSdp(offer_sdp); + val["type"] = "answer"; + invoker(200, headerOut, val.toStyledString()); + } catch (std::exception &ex) { + val["code"] = API::Exception; + val["msg"] = ex.what(); + invoker(200, headerOut, val.toStyledString()); + } + }; + + //rtsp推流需要鉴权 + auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPublish, info, authInvoker, sender); + if (!flag) { + //该事件无人监听,默认不鉴权 + GET_CONFIG(bool, toHls, General::kPublishToHls); + GET_CONFIG(bool, toMP4, General::kPublishToMP4); + authInvoker("", toHls, toMP4); + } + return; + } + + throw ApiRetException("不支持该类型", API::InvalidArgs); + }); +#endif + ////////////以下是注册的Hook API//////////// api_regist("/index/hook/on_publish",[](API_ARGS_MAP){ //开始推流事件 diff --git a/server/WebApi.h b/server/WebApi.h index 0cf2ec39..48b4580f 100755 --- a/server/WebApi.h +++ b/server/WebApi.h @@ -85,6 +85,8 @@ using ApiArgsType = map; #define API_ARGS_MAP_ASYNC API_ARGS_MAP, const HttpSession::HttpResponseInvoker &invoker #define API_ARGS_JSON SockInfo &sender, HttpSession::KeyValue &headerIn, HttpSession::KeyValue &headerOut, Json::Value &allArgs, Json::Value &val #define API_ARGS_JSON_ASYNC API_ARGS_JSON, const HttpSession::HttpResponseInvoker &invoker +#define API_ARGS_STRING SockInfo &sender, HttpSession::KeyValue &headerIn, HttpSession::KeyValue &headerOut, const Parser &allArgs, Json::Value &val +#define API_ARGS_STRING_ASYNC API_ARGS_STRING, const HttpSession::HttpResponseInvoker &invoker #define API_ARGS_VALUE sender, headerIn, headerOut, allArgs, val //注册http请求参数是map类型的http api @@ -97,6 +99,11 @@ void api_regist(const string &api_path, const function &fun //注册http请求参数是Json::Value类型,但是可以异步回复的的http api void api_regist(const string &api_path, const function &func); +//注册http请求参数是http原始请求信息的http api +void api_regist(const string &api_path, const function &func); +//注册http请求参数是http原始请求信息的异步回复的http api +void api_regist(const string &api_path, const function &func); + template bool checkArgs(Args &&args, First &&first) { return !args[first].empty(); @@ -107,6 +114,16 @@ bool checkArgs(Args &&args, First &&first, KeyTypes &&...keys) { return !args[first].empty() && checkArgs(std::forward(args), std::forward(keys)...); } +template +bool checkArgs(const Parser &args, First &&first) { + return !args.getUrlArgs()[first].empty(); +} + +template +bool checkArgs(const Parser &args, First &&first, KeyTypes &&...keys) { + return !args.getUrlArgs()[first].empty() && checkArgs(args, std::forward(keys)...); +} + //检查http参数是否为空的宏 #define CHECK_ARGS(...) \ if(!checkArgs(allArgs,##__VA_ARGS__)){ \ diff --git a/server/main.cpp b/server/main.cpp index 75264ff3..4bbf189f 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -25,6 +25,7 @@ #include "Rtp/RtpServer.h" #include "WebApi.h" #include "WebHook.h" +#include "../webrtc/Sdp.h" #if defined(ENABLE_VERSION) #include "Version.h" diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 56c1aa10..8d2ff3b4 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -35,6 +35,7 @@ string getOriginTypeString(MediaOriginType type){ SWITCH_CASE(ffmpeg_pull); SWITCH_CASE(mp4_vod); SWITCH_CASE(device_chn); + SWITCH_CASE(rtc_push); default : return "unknown"; } } diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index 5ca1d5aa..c16acba1 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -45,7 +45,8 @@ enum class MediaOriginType : uint8_t { pull, ffmpeg_pull, mp4_vod, - device_chn + device_chn, + rtc_push, }; string getOriginTypeString(MediaOriginType type); diff --git a/src/Extension/AAC.cpp b/src/Extension/AAC.cpp index 72c3fb3e..84308355 100644 --- a/src/Extension/AAC.cpp +++ b/src/Extension/AAC.cpp @@ -205,7 +205,7 @@ public: if (bitrate) { _printer << "b=AS:" << bitrate << "\r\n"; } - _printer << "a=rtpmap:" << payload_type << " mpeg4-generic/" << sample_rate << "/" << channels << "\r\n"; + _printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << sample_rate << "/" << channels << "\r\n"; string configStr; char buf[4] = {0}; diff --git a/src/Extension/CommonRtp.cpp b/src/Extension/CommonRtp.cpp index 039bf93d..e009816a 100644 --- a/src/Extension/CommonRtp.cpp +++ b/src/Extension/CommonRtp.cpp @@ -69,7 +69,7 @@ CommonRtpEncoder::CommonRtpEncoder(CodecId codec, uint32_t ssrc, uint32_t mtu_si } void CommonRtpEncoder::inputFrame(const Frame::Ptr &frame){ - auto stamp = frame->dts(); + auto stamp = frame->pts(); auto ptr = frame->data() + frame->prefixSize(); auto len = frame->size() - frame->prefixSize(); auto remain_size = len; diff --git a/src/Extension/Frame.cpp b/src/Extension/Frame.cpp index db5272a9..62753f59 100644 --- a/src/Extension/Frame.cpp +++ b/src/Extension/Frame.cpp @@ -11,7 +11,7 @@ #include "Frame.h" #include "H264.h" #include "H265.h" - +#include "Common/Parser.h" using namespace std; using namespace toolkit; @@ -106,30 +106,50 @@ Frame::Ptr Frame::getCacheAbleFrame(const Frame::Ptr &frame){ return std::make_shared(frame); } -#define SWITCH_CASE(codec_id) case codec_id : return #codec_id -const char *getCodecName(CodecId codecId) { +TrackType getTrackType(CodecId codecId) { switch (codecId) { - SWITCH_CASE(CodecH264); - SWITCH_CASE(CodecH265); - SWITCH_CASE(CodecAAC); - SWITCH_CASE(CodecG711A); - SWITCH_CASE(CodecG711U); - SWITCH_CASE(CodecOpus); - SWITCH_CASE(CodecL16); - default : return "unknown codec"; +#define XX(name, type, value, str) case name : return type; + CODEC_MAP(XX) +#undef XX + default : return TrackInvalid; } } -TrackType getTrackType(CodecId codecId){ - switch (codecId){ - case CodecH264: - case CodecH265: return TrackVideo; - case CodecAAC: - case CodecG711A: - case CodecG711U: - case CodecOpus: - case CodecL16: return TrackAudio; - default: return TrackInvalid; +const char *getCodecName(CodecId codec) { + switch (codec) { +#define XX(name, type, value, str) case name : return str; + CODEC_MAP(XX) +#undef XX + default : return "invalid"; + } +} + +#define XX(name, type, value, str) {str, name}, +static map codec_map = {CODEC_MAP(XX)}; +#undef XX + +CodecId getCodecId(const string &str){ + auto it = codec_map.find(str); + return it == codec_map.end() ? CodecInvalid : it->second; +} + +static map track_str_map = { + {"video", TrackVideo}, + {"audio", TrackAudio}, + {"application", TrackApplication} +}; + +TrackType getTrackType(const string &str) { + auto it = track_str_map.find(str); + return it == track_str_map.end() ? TrackInvalid : it->second; +} + +const char* getTrackString(TrackType type){ + switch (type) { + case TrackVideo : return "video"; + case TrackAudio : return "audio"; + case TrackApplication : return "application"; + default: return "invalid"; } } @@ -171,16 +191,23 @@ bool FrameMerger::willFlush(const Frame::Ptr &frame) const{ } switch (frame->getCodecId()) { case CodecH264 : { - if (H264_TYPE(frame->data()[frame->prefixSize()]) == H264Frame::NAL_B_P) { - //如果是264的b/p帧,那么也刷新输出 + auto type = H264_TYPE(frame->data()[frame->prefixSize()]); + if ((frame->data()[frame->prefixSize()+1]&0x80) !=0 && type >=H264Frame::NAL_B_P && type<=H264Frame::NAL_IDR ) {// sei aud pps sps 不判断 + //264 新一帧的开始,刷新输出 return true; + }else{ + // 不刷新输出 + return false; } break; } case CodecH265 : { - if (H265_TYPE(frame->data()[frame->prefixSize()]) == H265Frame::NAL_TRAIL_R) { - //如果是265的TRAIL_R帧,那么也刷新输出 + auto type = H265_TYPE(frame->data()[frame->prefixSize()]); + if ((type>=H265Frame::NAL_TRAIL_R &&type<= H265Frame::NAL_RSV_IRAP_VCL23) && ( (frame->data()[frame->prefixSize()+2]>>7 & 0x01) != 0)) { + //first_slice_segment_in_pic_flag is frame start return true; + }else{ + return false; } break; } @@ -217,8 +244,33 @@ void FrameMerger::doMerge(BufferLikeString &merged, const Frame::Ptr &frame) con default: /*不可达*/ assert(0); break; } } - +bool FrameMerger::shouldDrop(const Frame::Ptr &frame) const{ + switch (frame->getCodecId()) { + case CodecH264:{ + auto type = H264_TYPE(frame->data()[frame->prefixSize()]); + if(type == H264Frame::NAL_SEI || type == H264Frame::NAL_AUD){ + // 防止吧AUD或者SEI当成一帧 + return true; + } + break; + } + case CodecH265: { + //如果是新的一帧,前面的缓存需要输出 + auto type = H265_TYPE(frame->data()[frame->prefixSize()]); + if(type == H265Frame::NAL_AUD || type == H265Frame::NAL_SEI_PREFIX || type == H265Frame::NAL_SEI_SUFFIX){ + // 防止吧AUD或者SEI当成一帧 + return true; + } + break; + } + default: break; + } + return false; +} void FrameMerger::inputFrame(const Frame::Ptr &frame, const onOutput &cb) { + if(shouldDrop(frame)){ + return; + } if (willFlush(frame)) { Frame::Ptr back = _frameCached.back(); Buffer::Ptr merged_frame = back; diff --git a/src/Extension/Frame.h b/src/Extension/Frame.h index bed1d00e..95a5ec6d 100644 --- a/src/Extension/Frame.h +++ b/src/Extension/Frame.h @@ -21,26 +21,52 @@ using namespace toolkit; namespace mediakit{ -typedef enum { - CodecInvalid = -1, - CodecH264 = 0, - CodecH265, - CodecAAC, - CodecG711A, - CodecG711U, - CodecOpus, - CodecL16, - CodecMax = 0x7FFF -} CodecId; - typedef enum { TrackInvalid = -1, TrackVideo = 0, TrackAudio, TrackTitle, - TrackMax = 3 + TrackApplication, + TrackMax } TrackType; +#define CODEC_MAP(XX) \ + XX(CodecH264, TrackVideo, 0, "H264") \ + XX(CodecH265, TrackVideo, 1, "H265") \ + XX(CodecAAC, TrackAudio, 2, "mpeg4-generic") \ + XX(CodecG711A, TrackAudio, 3, "PCMA") \ + XX(CodecG711U, TrackAudio, 4, "PCMU") \ + XX(CodecOpus, TrackAudio, 5, "opus") \ + XX(CodecL16, TrackAudio, 6, "L16") \ + XX(CodecVP8, TrackVideo, 7, "VP8") \ + XX(CodecVP9, TrackVideo, 8, "VP9") \ + XX(CodecAV1, TrackVideo, 9, "AV1X") + +typedef enum { + CodecInvalid = -1, +#define XX(name, type, value, str) name = value, + CODEC_MAP(XX) +#undef XX + CodecMax +} CodecId; + +/** + * 字符串转媒体类型转 + */ +TrackType getTrackType(const string &str); + +/** + * 媒体类型转字符串 + */ +const char* getTrackString(TrackType type); + +/** + * 根据SDP中描述获取codec_id + * @param str + * @return + */ +CodecId getCodecId(const string &str); + /** * 获取编码器名称 */ @@ -449,6 +475,7 @@ public: private: bool willFlush(const Frame::Ptr &frame) const; void doMerge(BufferLikeString &buffer, const Frame::Ptr &frame) const; + bool shouldDrop(const Frame::Ptr &frame) const; private: int _type; diff --git a/src/Extension/G711.cpp b/src/Extension/G711.cpp index da86d5a2..eab141ce 100644 --- a/src/Extension/G711.cpp +++ b/src/Extension/G711.cpp @@ -33,7 +33,7 @@ public: if (bitrate) { _printer << "b=AS:" << bitrate << "\r\n"; } - _printer << "a=rtpmap:" << payload_type << (codecId == CodecG711A ? " PCMA/" : " PCMU/") << sample_rate << "/" << channels << "\r\n"; + _printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << sample_rate << "/" << channels << "\r\n"; _printer << "a=control:trackID=" << (int)TrackAudio << "\r\n"; } diff --git a/src/Extension/H264.cpp b/src/Extension/H264.cpp index b7bd1e29..1db1f676 100644 --- a/src/Extension/H264.cpp +++ b/src/Extension/H264.cpp @@ -181,17 +181,15 @@ void H264Track::inputFrame_l(const Frame::Ptr &frame){ _pps = string(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize()); break; } - case H264Frame::NAL_IDR: { - insertConfigFrame(frame); - VideoTrack::inputFrame(frame); - break; - } case H264Frame::NAL_AUD: { //忽略AUD帧; break; } default: + if (frame->keyFrame()) { + insertConfigFrame(frame); + } VideoTrack::inputFrame(frame); break; } @@ -235,7 +233,7 @@ public: if (bitrate) { _printer << "b=AS:" << bitrate << "\r\n"; } - _printer << "a=rtpmap:" << payload_type << " H264/" << 90000 << "\r\n"; + _printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << 90000 << "\r\n"; _printer << "a=fmtp:" << payload_type << " packetization-mode=1; profile-level-id="; char strTemp[1024]; @@ -281,7 +279,8 @@ Sdp::Ptr H264Track::getSdp() { //////////////////////////////////////////////////////////////////////////////////////////////////// bool H264Frame::keyFrame() const { - return H264_TYPE(_buffer[_prefix_size]) == H264Frame::NAL_IDR; + //多slice 一帧的情况下检查 first_mb_in_slice 是否为0 表示其为一帧的开始 + return H264_TYPE(_buffer[_prefix_size]) == H264Frame::NAL_IDR && (_buffer[_prefix_size + 1] & 0x80); } bool H264Frame::configFrame() const { diff --git a/src/Extension/H264Rtmp.cpp b/src/Extension/H264Rtmp.cpp index ca58472a..b3426fe8 100644 --- a/src/Extension/H264Rtmp.cpp +++ b/src/Extension/H264Rtmp.cpp @@ -183,7 +183,7 @@ void H264RtmpEncoder::inputFrame(const Frame::Ptr &frame) { } } - if(_lastPacket && (_lastPacket->time_stamp != frame->dts() || type == H264Frame::NAL_B_P)) { + if(_lastPacket && (_lastPacket->time_stamp != frame->dts() || ((pcData[1]&0x80) != 0 && type>=H264Frame::NAL_B_P && type<=H264Frame::NAL_IDR))) { RtmpCodec::inputRtmp(_lastPacket); _lastPacket = nullptr; } @@ -214,10 +214,6 @@ void H264RtmpEncoder::inputFrame(const Frame::Ptr &frame) { _lastPacket->buffer.append((char *) &size, 4); _lastPacket->buffer.append(pcData, iLen); _lastPacket->body_size = _lastPacket->buffer.size(); - if (type == H264Frame::NAL_B_P) { - RtmpCodec::inputRtmp(_lastPacket); - _lastPacket = nullptr; - } } void H264RtmpEncoder::makeVideoConfigPkt() { diff --git a/src/Extension/H264Rtp.cpp b/src/Extension/H264Rtp.cpp index 54a7fc5c..0db7585a 100644 --- a/src/Extension/H264Rtp.cpp +++ b/src/Extension/H264Rtp.cpp @@ -184,53 +184,109 @@ H264RtpEncoder::H264RtpEncoder(uint32_t ssrc, uint32_t mtu, uint32_t sample_rate : RtpInfo(ssrc, mtu, sample_rate, pt, interleaved) { } -void H264RtpEncoder::inputFrame(const Frame::Ptr &frame) { - auto ptr = frame->data() + frame->prefixSize(); - auto len = frame->size() - frame->prefixSize(); - auto pts = frame->pts(); - auto nal_type = H264_TYPE(ptr[0]); - auto packet_size = getMaxSize() - 2; +void H264RtpEncoder::insertConfigFrame(uint32_t pts){ + if (!_sps || !_pps) { + return; + } + //gop缓存从sps开始,sps、pps后面还有时间戳相同的关键帧,所以mark bit为false + packRtp(_sps->data() + _sps->prefixSize(), _sps->size() - _sps->prefixSize(), pts, false, true); + packRtp(_pps->data() + _pps->prefixSize(), _pps->size() - _pps->prefixSize(), pts, false, false); +} - //末尾5bit为nalu type,固定为28(FU-A) - auto fu_char_0 = (ptr[0] & (~0x1F)) | 28; - auto fu_char_1 = nal_type; - FuFlags *fu_flags = (FuFlags *) (&fu_char_1); - fu_flags->start_bit = 1; - - //超过MTU则按照FU-A模式打包 - if (len > packet_size + 1) { - size_t offset = 1; - while (!fu_flags->end_bit) { - if (!fu_flags->start_bit && len <= offset + packet_size) { - //FU-A end - packet_size = len - offset; - fu_flags->end_bit = 1; - } - - //传入nullptr先不做payload的内存拷贝 - auto rtp = makeRtp(getTrackType(), nullptr, packet_size + 2, fu_flags->end_bit, pts); - //rtp payload 负载部分 - uint8_t *payload = rtp->getPayload(); - //FU-A 第1个字节 - payload[0] = fu_char_0; - //FU-A 第2个字节 - payload[1] = fu_char_1; - //H264 数据 - memcpy(payload + 2, (uint8_t *) ptr + offset, packet_size); - //输入到rtp环形缓存 - RtpCodec::inputRtp(rtp, fu_flags->start_bit && nal_type == H264Frame::NAL_IDR); - - offset += packet_size; - fu_flags->start_bit = 0; - } +void H264RtpEncoder::packRtp(const char *ptr, size_t len, uint32_t pts, bool is_mark, bool gop_pos){ + if (len + 3 <= getMaxSize()) { + //STAP-A模式打包小于MTU + packRtpStapA(ptr, len, pts, is_mark, gop_pos); } else { - //如果帧长度不超过mtu, 则按照Single NAL unit packet per H.264 方式打包 - makeH264Rtp(ptr, len, false, false, pts); + //STAP-A模式打包会大于MTU,所以采用FU-A模式 + packRtpFu(ptr, len, pts, is_mark, gop_pos); } } -void H264RtpEncoder::makeH264Rtp(const void* data, size_t len, bool mark, bool gop_pos, uint32_t uiStamp) { - RtpCodec::inputRtp(makeRtp(getTrackType(), data, len, mark, uiStamp), gop_pos); +void H264RtpEncoder::packRtpFu(const char *ptr, size_t len, uint32_t pts, bool is_mark, bool gop_pos){ + auto packet_size = getMaxSize() - 2; + if (len <= packet_size + 1) { + //小于FU-A打包最小字节长度要求,采用STAP-A模式 + packRtpStapA(ptr, len, pts, is_mark, gop_pos); + return; + } + + //末尾5bit为nalu type,固定为28(FU-A) + auto fu_char_0 = (ptr[0] & (~0x1F)) | 28; + auto fu_char_1 = H264_TYPE(ptr[0]); + FuFlags *fu_flags = (FuFlags *) (&fu_char_1); + fu_flags->start_bit = 1; + + size_t offset = 1; + while (!fu_flags->end_bit) { + if (!fu_flags->start_bit && len <= offset + packet_size) { + //FU-A end + packet_size = len - offset; + fu_flags->end_bit = 1; + } + + //传入nullptr先不做payload的内存拷贝 + auto rtp = makeRtp(getTrackType(), nullptr, packet_size + 2, fu_flags->end_bit && is_mark, pts); + //rtp payload 负载部分 + uint8_t *payload = rtp->getPayload(); + //FU-A 第1个字节 + payload[0] = fu_char_0; + //FU-A 第2个字节 + payload[1] = fu_char_1; + //H264 数据 + memcpy(payload + 2, (uint8_t *) ptr + offset, packet_size); + //输入到rtp环形缓存 + RtpCodec::inputRtp(rtp, gop_pos); + + offset += packet_size; + fu_flags->start_bit = 0; + } +} + +void H264RtpEncoder::packRtpStapA(const char *ptr, size_t len, uint32_t pts, bool is_mark, bool gop_pos){ + //如果帧长度不超过mtu,为了兼容性 webrtc,采用STAP-A模式打包 + auto rtp = makeRtp(getTrackType(), nullptr, len + 3, is_mark, pts); + uint8_t *payload = rtp->getPayload(); + //STAP-A + payload[0] = (ptr[0] & (~0x1F)) | 24; + payload[1] = (len >> 8) & 0xFF; + payload[2] = len & 0xff; + memcpy(payload + 3, (uint8_t *) ptr, len); + + RtpCodec::inputRtp(rtp, gop_pos); +} + +void H264RtpEncoder::inputFrame(const Frame::Ptr &frame) { + auto ptr = frame->data() + frame->prefixSize(); + switch (H264_TYPE(ptr[0])) { + case H264Frame::NAL_AUD: + case H264Frame::NAL_SEI : { + return; + } + case H264Frame::NAL_SPS: { + _sps = Frame::getCacheAbleFrame(frame); + return; + } + case H264Frame::NAL_PPS: { + _pps = Frame::getCacheAbleFrame(frame); + return; + } + default: break; + } + + if (_last_frame) { + //如果时间戳发生了变化,那么markbit才置true + inputFrame_l(_last_frame, _last_frame->pts() != frame->pts()); + } + _last_frame = Frame::getCacheAbleFrame(frame); +} + +void H264RtpEncoder::inputFrame_l(const Frame::Ptr &frame, bool is_mark){ + if (frame->keyFrame()) { + //保证每一个关键帧前都有SPS与PPS + insertConfigFrame(frame->pts()); + } + packRtp(frame->data() + frame->prefixSize(), frame->size() - frame->prefixSize(), frame->pts(), is_mark, false); } }//namespace mediakit diff --git a/src/Extension/H264Rtp.h b/src/Extension/H264Rtp.h index d727a0c1..430718e9 100644 --- a/src/Extension/H264Rtp.h +++ b/src/Extension/H264Rtp.h @@ -82,7 +82,16 @@ public: void inputFrame(const Frame::Ptr &frame) override; private: - void makeH264Rtp(const void *pData, size_t uiLen, bool bMark, bool gop_pos, uint32_t uiStamp); + void insertConfigFrame(uint32_t pts); + void inputFrame_l(const Frame::Ptr &frame, bool is_mark); + void packRtp(const char *data, size_t len, uint32_t pts, bool is_mark, bool gop_pos); + void packRtpFu(const char *data, size_t len, uint32_t pts, bool is_mark, bool gop_pos); + void packRtpStapA(const char *data, size_t len, uint32_t pts, bool is_mark, bool gop_pos); + +private: + Frame::Ptr _sps; + Frame::Ptr _pps; + Frame::Ptr _last_frame; }; }//namespace mediakit{ diff --git a/src/Extension/H265.cpp b/src/Extension/H265.cpp index e2967567..a4b2dde6 100644 --- a/src/Extension/H265.cpp +++ b/src/Extension/H265.cpp @@ -64,10 +64,11 @@ bool H265Frame::configFrame() const { } bool H265Frame::isKeyFrame(int type, const char *ptr) { - if (!ptr || type != NAL_IDR_W_RADL) { - return type >= NAL_BLA_W_LP && type <= NAL_RSV_IRAP_VCL23; + if(ptr){ + return (((*((uint8_t *) ptr + 2)) >> 7) & 0x01) == 1 && (type == NAL_IDR_N_LP || type == NAL_IDR_W_RADL); } - return (((*((uint8_t *) ptr + 2)) >> 7) & 0x01) == 1; + return false; + } H265Frame::H265Frame(){ @@ -254,7 +255,7 @@ public: if (bitrate) { _printer << "b=AS:" << bitrate << "\r\n"; } - _printer << "a=rtpmap:" << payload_type << " H265/" << 90000 << "\r\n"; + _printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << 90000 << "\r\n"; _printer << "a=fmtp:" << payload_type << " "; _printer << "sprop-vps="; _printer << encodeBase64(strVPS) << "; "; diff --git a/src/Extension/H265Rtmp.cpp b/src/Extension/H265Rtmp.cpp index 3a8c32ab..84dddad6 100644 --- a/src/Extension/H265Rtmp.cpp +++ b/src/Extension/H265Rtmp.cpp @@ -165,11 +165,11 @@ void H265RtmpEncoder::inputFrame(const Frame::Ptr &frame) { } } - if(type == H265Frame::NAL_SEI_PREFIX || type == H265Frame::NAL_SEI_SUFFIX){ - return; + if(type == H265Frame::NAL_SEI_PREFIX || type == H265Frame::NAL_SEI_SUFFIX || type == H265Frame::NAL_AUD){ + return;// 防止sei aud 作为一帧 } - if (_lastPacket && (_lastPacket->time_stamp != frame->dts() || type == H265Frame::NAL_TRAIL_R)) { + if (_lastPacket && (_lastPacket->time_stamp != frame->dts() || (type >=H264Frame::NAL_B_P && type<=H264Frame::NAL_IDR && (pcData[2]>>7 &0x01) !=0))) { RtmpCodec::inputRtmp(_lastPacket); _lastPacket = nullptr; } diff --git a/src/Extension/L16.cpp b/src/Extension/L16.cpp index e6c778ac..8194dfa3 100644 --- a/src/Extension/L16.cpp +++ b/src/Extension/L16.cpp @@ -33,7 +33,7 @@ public: if (bitrate) { _printer << "b=AS:" << bitrate << "\r\n"; } - _printer << "a=rtpmap:" << payload_type << " L16/" << sample_rate << "/" << channels << "\r\n"; + _printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << sample_rate << "/" << channels << "\r\n"; _printer << "a=control:trackID=" << (int)TrackAudio << "\r\n"; } diff --git a/src/Extension/Opus.cpp b/src/Extension/Opus.cpp index 275354cb..03e107a9 100644 --- a/src/Extension/Opus.cpp +++ b/src/Extension/Opus.cpp @@ -31,7 +31,7 @@ public: if (bitrate) { _printer << "b=AS:" << bitrate << "\r\n"; } - _printer << "a=rtpmap:" << payload_type << " opus/" << sample_rate << "/" << channels << "\r\n"; + _printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << sample_rate << "/" << channels << "\r\n"; _printer << "a=control:trackID=" << (int)TrackAudio << "\r\n"; } diff --git a/src/Rtcp/Rtcp.cpp b/src/Rtcp/Rtcp.cpp index 2e0b21db..c7c5a277 100644 --- a/src/Rtcp/Rtcp.cpp +++ b/src/Rtcp/Rtcp.cpp @@ -9,8 +9,10 @@ */ #include +#include #include "Rtcp.h" #include "Util/logger.h" +#include "RtcpFCI.h" namespace mediakit { @@ -32,8 +34,26 @@ const char *sdesTypeToStr(SdesType type){ } } +const char *psfbTypeToStr(PSFBType type) { + switch (type){ +#define SWITCH_CASE(key, value) case PSFBType::key : return #value "(" #key ")"; + PSFB_TYPE_MAP(SWITCH_CASE) +#undef SWITCH_CASE + default: return "unknown payload-specific fb message fmt type"; + } +} + +const char *rtpfbTypeToStr(RTPFBType type) { + switch (type){ +#define SWITCH_CASE(key, value) case RTPFBType::key : return #value "(" #key ")"; + RTPFB_TYPE_MAP(SWITCH_CASE) +#undef SWITCH_CASE + default: return "unknown transport layer feedback messages fmt type"; + } +} + static size_t alignSize(size_t bytes) { - return (size_t)((bytes + 3) / 4) << 2; + return (size_t)((bytes + 3) >> 2 ) << 2; } static void setupHeader(RtcpHeader *rtcp, RtcpType type, size_t report_count, size_t total_bytes) { @@ -45,23 +65,46 @@ static void setupHeader(RtcpHeader *rtcp, RtcpType type, size_t report_count, si //items总个数 rtcp->report_count = report_count; rtcp->pt = (uint8_t) type; - //不包含rtcp头的长度 - rtcp->length = htons((uint16_t)((total_bytes / 4) - 1)); + rtcp->setSize(total_bytes); +} + +static void setupPadding(RtcpHeader *rtcp, size_t padding_size) { + if (padding_size) { + rtcp->padding = 1; + ((uint8_t *) rtcp)[rtcp->getSize() - 1] = padding_size & 0xFF; + } else { + rtcp->padding = 0; + } } ///////////////////////////////////////////////////////////////////////////// -void RtcpHeader::net2Host() { - length = ntohs(length); -} - string RtcpHeader::dumpHeader() const{ _StrPrinter printer; printer << "version:" << version << "\r\n"; - printer << "padding:" << padding << "\r\n"; - printer << "report_count:" << report_count << "\r\n"; + if (padding) { + printer << "padding:" << padding << " " << getPaddingSize() << "\r\n"; + } else { + printer << "padding:" << padding << "\r\n"; + } + + switch ((RtcpType)pt) { + case RtcpType::RTCP_RTPFB : { + printer << "report_count:" << rtpfbTypeToStr((RTPFBType) report_count) << "\r\n"; + break; + } + case RtcpType::RTCP_PSFB : { + printer << "report_count:" << psfbTypeToStr((PSFBType) report_count) << "\r\n"; + break; + } + default : { + printer << "report_count:" << report_count << "\r\n"; + break; + } + } + printer << "pt:" << rtcpTypeToStr((RtcpType)pt) << "\r\n"; - printer << "length:" << length << "\r\n"; + printer << "size:" << getSize() << "\r\n"; printer << "--------\r\n"; return std::move(printer); } @@ -82,10 +125,39 @@ string RtcpHeader::dumpString() const { RtcpSdes *rtcp = (RtcpSdes *)this; return rtcp->dumpString(); } - default: return StrPrinter << dumpHeader() << hexdump((char *)this + sizeof(*this), length << 2); + + case RtcpType::RTCP_RTPFB: + case RtcpType::RTCP_PSFB: { + RtcpFB *rtcp = (RtcpFB *)this; + return rtcp->dumpString(); + } + + case RtcpType::RTCP_BYE: { + RtcpBye *rtcp = (RtcpBye *)this; + return rtcp->dumpString(); + } + + default: return StrPrinter << dumpHeader() << hexdump((char *)this + sizeof(*this), getSize() - sizeof(*this)); } } +size_t RtcpHeader::getSize() const { + //加上rtcp头长度 + return (1 + ntohs(length)) << 2; +} + +size_t RtcpHeader::getPaddingSize() const{ + if (!padding) { + return 0; + } + return ((uint8_t *) this)[getSize() - 1]; +} + +void RtcpHeader::setSize(size_t size) { + //不包含rtcp头的长度 + length = htons((uint16_t)((size >> 2) - 1)); +} + void RtcpHeader::net2Host(size_t len){ switch ((RtcpType)pt) { case RtcpType::RTCP_SR: { @@ -105,6 +177,20 @@ void RtcpHeader::net2Host(size_t len){ sdes->net2Host(len); break; } + + case RtcpType::RTCP_RTPFB: + case RtcpType::RTCP_PSFB: { + RtcpFB *fb = (RtcpFB *)this; + fb->net2Host(len); + break; + } + + case RtcpType::RTCP_BYE: { + RtcpBye *bye = (RtcpBye *)this; + bye->net2Host(len); + break; + } + default: throw std::runtime_error(StrPrinter << "未处理的rtcp包:" << rtcpTypeToStr((RtcpType) this->pt)); } } @@ -115,13 +201,17 @@ vector RtcpHeader::loadFromBytes(char *data, size_t len){ char *ptr = data; while (remain > (ssize_t) sizeof(RtcpHeader)) { RtcpHeader *rtcp = (RtcpHeader *) ptr; - auto rtcp_len = (1 + ntohs(rtcp->length)) << 2; + auto rtcp_len = rtcp->getSize(); + if (remain < (ssize_t)rtcp_len) { + WarnL << "非法的rtcp包,声明的长度超过实际数据长度"; + break; + } try { rtcp->net2Host(rtcp_len); ret.emplace_back(rtcp); } catch (std::exception &ex) { //不能处理的rtcp包,或者无法解析的rtcp包,忽略掉 - WarnL << ex.what(); + WarnL << ex.what() << ",长度为:" << rtcp_len; } ptr += rtcp_len; remain -= rtcp_len; @@ -133,7 +223,6 @@ class BufferRtcp : public Buffer { public: BufferRtcp(std::shared_ptr rtcp) { _rtcp = std::move(rtcp); - _size = (htons(_rtcp->length) + 1) << 2; } ~BufferRtcp() override {} @@ -143,11 +232,10 @@ public: } size_t size() const override { - return _size; + return _rtcp->getSize(); } private: - std::size_t _size; std::shared_ptr _rtcp; }; @@ -158,9 +246,11 @@ Buffer::Ptr RtcpHeader::toBuffer(std::shared_ptr rtcp) { ///////////////////////////////////////////////////////////////////////////// std::shared_ptr RtcpSR::create(size_t item_count) { - auto bytes = alignSize(sizeof(RtcpSR) - sizeof(ReportItem) + item_count * sizeof(ReportItem)); + auto real_size = sizeof(RtcpSR) - sizeof(ReportItem) + item_count * sizeof(ReportItem); + auto bytes = alignSize(real_size); auto ptr = (RtcpSR *) new char[bytes]; setupHeader(ptr, RtcpType::RTCP_SR, item_count, bytes); + setupPadding(ptr, bytes - real_size); return std::shared_ptr(ptr, [](RtcpSR *ptr) { delete[] (char *) ptr; }); @@ -202,21 +292,17 @@ if (size < kMinSize) { \ throw std::out_of_range(StrPrinter << rtcpTypeToStr((RtcpType)pt) << " 长度不足:" << size << " < " << kMinSize); \ } -#define CHECK_LENGTH(size, item_count) \ +#define CHECK_REPORT_COUNT(item_count) \ /*修正个数,防止getItemList时内存越界*/ \ if (report_count != item_count) { \ WarnL << rtcpTypeToStr((RtcpType)pt) << " report_count 字段不正确,已修正为:" << (int)report_count << " -> " << item_count; \ report_count = item_count; \ -} \ -if ((size_t) (length + 1) << 2 != size) { \ - WarnL << rtcpTypeToStr((RtcpType)pt) << " length字段不正确:" << (size_t) (length + 1) << 2 << " != " << size; \ } void RtcpSR::net2Host(size_t size) { static const size_t kMinSize = sizeof(RtcpSR) - sizeof(items); CHECK_MIN_SIZE(size, kMinSize); - RtcpHeader::net2Host(); ssrc = ntohl(ssrc); ntpmsw = ntohl(ntpmsw); ntplsw = ntohl(ntplsw); @@ -231,7 +317,7 @@ void RtcpSR::net2Host(size_t size) { ++ptr; ++item_count; } - CHECK_LENGTH(size, item_count); + CHECK_REPORT_COUNT(item_count); } vector RtcpSR::getItemList(){ @@ -272,9 +358,11 @@ void ReportItem::net2Host() { ///////////////////////////////////////////////////////////////////////////// std::shared_ptr RtcpRR::create(size_t item_count) { - auto bytes = alignSize(sizeof(RtcpRR) - sizeof(ReportItem) + item_count * sizeof(ReportItem)); + auto real_size = sizeof(RtcpRR) - sizeof(ReportItem) + item_count * sizeof(ReportItem); + auto bytes = alignSize(real_size); auto ptr = (RtcpRR *) new char[bytes]; setupHeader(ptr, RtcpType::RTCP_RR, item_count, bytes); + setupPadding(ptr, bytes - real_size); return std::shared_ptr(ptr, [](RtcpRR *ptr) { delete[] (char *) ptr; }); @@ -296,7 +384,6 @@ string RtcpRR::dumpString() const{ void RtcpRR::net2Host(size_t size) { static const size_t kMinSize = sizeof(RtcpRR) - sizeof(items); CHECK_MIN_SIZE(size, kMinSize); - RtcpHeader::net2Host(); ssrc = ntohl(ssrc); ReportItem *ptr = &items; @@ -306,7 +393,7 @@ void RtcpRR::net2Host(size_t size) { ++ptr; ++item_count; } - CHECK_LENGTH(size, item_count); + CHECK_REPORT_COUNT(item_count); } vector RtcpRR::getItemList() { @@ -326,7 +413,7 @@ void SdesItem::net2Host() { } size_t SdesItem::totalBytes() const{ - return alignSize(minSize() + length); + return alignSize(minSize() + txt_len); } size_t SdesItem::minSize() { @@ -337,30 +424,32 @@ string SdesItem::dumpString() const{ _StrPrinter printer; printer << "ssrc:" << ssrc << "\r\n"; printer << "type:" << sdesTypeToStr((SdesType) type) << "\r\n"; - printer << "length:" << (int) length << "\r\n"; - printer << "text:" << (length ? string(&text, length) : "") << "\r\n"; + printer << "txt_len:" << (int) txt_len << "\r\n"; + printer << "text:" << (txt_len ? string(text, txt_len) : "") << "\r\n"; return std::move(printer); } ///////////////////////////////////////////////////////////////////////////// -std::shared_ptr RtcpSdes::create(const std::initializer_list &item_text) { +std::shared_ptr RtcpSdes::create(const std::vector &item_text) { size_t item_total_size = 0; for (auto &text : item_text) { //统计所有SdesItem对象占用的空间 item_total_size += alignSize(SdesItem::minSize() + (0xFF & text.size())); } - auto bytes = alignSize(sizeof(RtcpSdes) - sizeof(SdesItem) + item_total_size); + auto real_size = sizeof(RtcpSdes) - sizeof(SdesItem) + item_total_size; + auto bytes = alignSize(real_size); auto ptr = (RtcpSdes *) new char[bytes]; auto item_ptr = &ptr->items; for (auto &text : item_text) { - item_ptr->length = (0xFF & text.size()); + item_ptr->txt_len = (0xFF & text.size()); //确保赋值\0为RTCP_SDES_END - memcpy(&(item_ptr->text), text.data(), item_ptr->length + 1); + memcpy(item_ptr->text, text.data(), item_ptr->txt_len + 1); item_ptr = (SdesItem *) ((char *) item_ptr + item_ptr->totalBytes()); } setupHeader(ptr, RtcpType::RTCP_SDES, item_text.size(), bytes); + setupPadding(ptr, bytes - real_size); return std::shared_ptr(ptr, [](RtcpSdes *ptr) { delete [] (char *) ptr; }); @@ -381,7 +470,6 @@ string RtcpSdes::dumpString() const { void RtcpSdes::net2Host(size_t size) { static const size_t kMinSize = sizeof(RtcpSdes) - sizeof(items); CHECK_MIN_SIZE(size, kMinSize); - RtcpHeader::net2Host(); SdesItem *ptr = &items; int item_count = 0; for(int i = 0; i < (int)report_count && (char *)(ptr) + SdesItem::minSize() <= (char *)(this) + size; ++i){ @@ -389,7 +477,7 @@ void RtcpSdes::net2Host(size_t size) { ptr = (SdesItem *) ((char *) ptr + ptr->totalBytes()); ++item_count; } - CHECK_LENGTH(size, item_count); + CHECK_REPORT_COUNT(item_count); } vector RtcpSdes::getItemList() { @@ -402,4 +490,202 @@ vector RtcpSdes::getItemList() { return ret; } +//////////////////////////////////////////////////////////////////// + +std::shared_ptr RtcpFB::create_l(RtcpType type, int fmt, const void *fci, size_t fci_len) { + if (!fci) { + fci_len = 0; + } + auto real_size = sizeof(RtcpFB) + fci_len; + auto bytes = alignSize(real_size); + auto ptr = (RtcpFB *) new char[bytes]; + if (fci && fci_len) { + memcpy((char *)ptr + sizeof(RtcpFB), fci, fci_len); + } + setupHeader(ptr, type, fmt, bytes); + setupPadding(ptr, bytes - real_size); + return std::shared_ptr((RtcpFB *) ptr, [](RtcpFB *ptr) { + delete[] (char *) ptr; + }); +} + +std::shared_ptr RtcpFB::create(PSFBType fmt, const void *fci, size_t fci_len) { + return RtcpFB::create_l(RtcpType::RTCP_PSFB, (int)fmt, fci, fci_len); +} + +std::shared_ptr RtcpFB::create(RTPFBType fmt, const void *fci, size_t fci_len) { + return RtcpFB::create_l(RtcpType::RTCP_RTPFB, (int)fmt, fci, fci_len); +} + +const void *RtcpFB::getFciPtr() const { + return (uint8_t *) &ssrc_media + sizeof(ssrc_media); +} + +size_t RtcpFB::getFciSize() const { + auto fci_len = (ssize_t) getSize() - getPaddingSize() - sizeof(RtcpFB); + CHECK(fci_len >= 0); + return fci_len; +} + +string RtcpFB::dumpString() const { + _StrPrinter printer; + printer << RtcpHeader::dumpHeader(); + printer << "ssrc:" << ssrc << "\r\n"; + printer << "ssrc_media:" << ssrc_media << "\r\n"; + switch ((RtcpType) pt) { + case RtcpType::RTCP_PSFB : { + switch ((PSFBType) report_count) { + case PSFBType::RTCP_PSFB_SLI : { + auto &fci = getFci(); + printer << "fci:" << psfbTypeToStr((PSFBType) report_count) << " " << fci.dumpString(); + break; + } + case PSFBType::RTCP_PSFB_PLI : { + getFciSize(); + printer << "fci:" << psfbTypeToStr((PSFBType) report_count); + break; + } + + case PSFBType::RTCP_PSFB_FIR : { + auto &fci = getFci(); + printer << "fci:" << psfbTypeToStr((PSFBType) report_count) << " " << fci.dumpString(); + break; + } + + case PSFBType::RTCP_PSFB_REMB : { + auto &fci = getFci(); + printer << "fci:" << psfbTypeToStr((PSFBType) report_count) << " " << fci.dumpString(); + break; + } + default:{ + printer << "fci:" << psfbTypeToStr((PSFBType) report_count) << " " << hexdump(getFciPtr(), getFciSize()); + break; + } + } + break; + } + case RtcpType::RTCP_RTPFB : { + switch ((RTPFBType) report_count) { + case RTPFBType::RTCP_RTPFB_NACK : { + auto &fci = getFci(); + printer << "fci:" << rtpfbTypeToStr((RTPFBType) report_count) << " " << fci.dumpString(); + break; + } + case RTPFBType::RTCP_RTPFB_TWCC : { + auto &fci = getFci(); + printer << "fci:" << rtpfbTypeToStr((RTPFBType) report_count) << " " << fci.dumpString(getFciSize()); + break; + } + default: { + printer << "fci:" << rtpfbTypeToStr((RTPFBType) report_count) << " " << hexdump(getFciPtr(), getFciSize()); + break; + } + } + break; + } + default: /*不可达*/ assert(0); break; + } + return std::move(printer); +} + +void RtcpFB::net2Host(size_t size) { + static const size_t kMinSize = sizeof(RtcpFB); + CHECK_MIN_SIZE(size, kMinSize); + ssrc = ntohl(ssrc); + ssrc_media = ntohl(ssrc_media); +} + +//////////////////////////////////////////////////////////////////// + +std::shared_ptr RtcpBye::create(const std::vector &ssrcs, const string &reason) { + assert(reason.size() <= 0xFF); + auto real_size = sizeof(RtcpHeader) + sizeof(uint32_t) * ssrcs.size() + 1 + reason.size(); + auto bytes = alignSize(real_size); + auto ptr = (RtcpBye *) new char[bytes]; + setupHeader(ptr, RtcpType::RTCP_BYE, ssrcs.size(), bytes); + setupPadding(ptr, bytes - real_size); + + auto ssrc_ptr = ((RtcpBye *) ptr)->ssrc; + for (auto ssrc : ssrcs) { + *ssrc_ptr = htonl(ssrc); + ++ssrc_ptr; + } + + if (!reason.empty()) { + uint8_t *reason_len_ptr = (uint8_t *) ptr + sizeof(RtcpHeader) + sizeof(uint32_t) * ssrcs.size(); + *reason_len_ptr = reason.size() & 0xFF; + memcpy(reason_len_ptr + 1, reason.data(), *reason_len_ptr); + } + + return std::shared_ptr(ptr, [](RtcpBye *ptr) { + delete[] (char *) ptr; + }); +} + +vector RtcpBye::getSSRC() { + vector ret; + auto ssrc_ptr = ssrc; + for (size_t i = 0; i < report_count; ++i) { + ret.emplace_back(ssrc_ptr); + ssrc_ptr += 1; + } + return ret; +} + +string RtcpBye::getReason() const { + auto *reason_len_ptr = &reason_len + sizeof(ssrc) * (report_count - 1); + if (reason_len_ptr + 1 >= (uint8_t *) this + getSize()) { + return ""; + } + return string((char *) reason_len_ptr + 1, *reason_len_ptr); +} + +string RtcpBye::dumpString() const { + _StrPrinter printer; + printer << RtcpHeader::dumpHeader(); + for(auto ssrc : ((RtcpBye *)this)->getSSRC()) { + printer << "ssrc:" << *ssrc << "\r\n"; + } + printer << "reason:" << getReason(); + return std::move(printer); +} + +void RtcpBye::net2Host(size_t size) { + static const size_t kMinSize = sizeof(RtcpHeader); + CHECK_MIN_SIZE(size, kMinSize); + auto ssrc_ptr = ssrc; + size_t offset = kMinSize; + size_t i = 0; + for (; i < report_count && offset + sizeof(ssrc) <= size; ++i) { + *ssrc_ptr = ntohl(*ssrc_ptr); + ssrc_ptr += 1; + offset += sizeof(ssrc); + } + //修正ssrc个数 + CHECK_REPORT_COUNT(i); + + if (offset < size) { + uint8_t *reason_len_ptr = &reason_len + sizeof(ssrc) * (report_count - 1); + if (reason_len_ptr + 1 + *reason_len_ptr > (uint8_t *) this + size) { + WarnL << "invalid rtcp bye reason length"; + //修正reason_len长度 + *reason_len_ptr = ((uint8_t *) this + size - reason_len_ptr - 1) & 0xFF; + } + } +} + +#if 0 +#include "Util/onceToken.h" + +static toolkit::onceToken token([](){ + auto bye = RtcpBye::create({1,2,3,4,5,6}, "this is a bye reason"); + auto buffer = RtcpHeader::toBuffer(bye); + + auto rtcps = RtcpHeader::loadFromBytes(buffer->data(), buffer->size()); + for(auto rtcp : rtcps){ + std::cout << rtcp->dumpString() << std::endl; + } +}); +#endif + }//namespace mediakit \ No newline at end of file diff --git a/src/Rtcp/Rtcp.h b/src/Rtcp/Rtcp.h index dbf4c769..efb591c1 100644 --- a/src/Rtcp/Rtcp.h +++ b/src/Rtcp/Rtcp.h @@ -25,8 +25,7 @@ namespace mediakit { #pragma pack(push, 1) #endif // defined(_WIN32) -//https://datatracker.ietf.org/doc/rfc3550 - +//http://www.networksorcery.com/enp/protocol/rtcp.htm #define RTCP_PT_MAP(XX) \ XX(RTCP_FIR, 192) \ XX(RTCP_NACK, 193) \ @@ -43,7 +42,8 @@ namespace mediakit { XX(RTCP_AVB, 208) \ XX(RTCP_RSI, 209) \ XX(RTCP_TOKEN, 210) - + +//https://tools.ietf.org/html/rfc3550#section-6.5 #define SDES_TYPE_MAP(XX) \ XX(RTCP_SDES_END, 0) \ XX(RTCP_SDES_CNAME, 1) \ @@ -55,6 +55,63 @@ namespace mediakit { XX(RTCP_SDES_NOTE, 7) \ XX(RTCP_SDES_PRIVATE, 8) +//https://datatracker.ietf.org/doc/rfc4585/?include_text=1 +//6.3. Payload-Specific Feedback Messages +// +// Payload-Specific FB messages are identified by the value PT=PSFB as +// RTCP message type. +// +// Three payload-specific FB messages are defined so far plus an +// application layer FB message. They are identified by means of the +// FMT parameter as follows: +// +// 0: unassigned +// 1: Picture Loss Indication (PLI) +// 2: Slice Loss Indication (SLI) +// 3: Reference Picture Selection Indication (RPSI) +// 4: FIR https://tools.ietf.org/html/rfc5104#section-4.3.1.1 +// 5: TSTR https://tools.ietf.org/html/rfc5104#section-4.3.2.1 +// 6: TSTN https://tools.ietf.org/html/rfc5104#section-4.3.2.1 +// 7: VBCM https://tools.ietf.org/html/rfc5104#section-4.3.4.1 +// 8-14: unassigned +// 15: REMB / Application layer FB (AFB) message, https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03 +// 16-30: unassigned +// 31: reserved for future expansion of the sequence number space +#define PSFB_TYPE_MAP(XX) \ + XX(RTCP_PSFB_PLI, 1) \ + XX(RTCP_PSFB_SLI, 2) \ + XX(RTCP_PSFB_RPSI, 3) \ + XX(RTCP_PSFB_FIR, 4) \ + XX(RTCP_PSFB_TSTR, 5)\ + XX(RTCP_PSFB_TSTN, 6)\ + XX(RTCP_PSFB_VBCM, 7) \ + XX(RTCP_PSFB_REMB, 15) + +//https://tools.ietf.org/html/rfc4585#section-6.2 +//6.2. Transport Layer Feedback Messages +// +// Transport layer FB messages are identified by the value RTPFB as RTCP +// message type. +// +// A single general purpose transport layer FB message is defined in +// this document: Generic NACK. It is identified by means of the FMT +// parameter as follows: +// +// 0: unassigned +// 1: Generic NACK +// 2: reserved https://tools.ietf.org/html/rfc5104#section-4.2 +// 3: TMMBR https://tools.ietf.org/html/rfc5104#section-4.2.1.1 +// 4: TMMBN https://tools.ietf.org/html/rfc5104#section-4.2.2.1 +// 5-14: unassigned +// 15 transport-cc https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01 +// 16-30: unassigned +// 31: reserved for future expansion of the identifier number space +#define RTPFB_TYPE_MAP(XX) \ + XX(RTCP_RTPFB_NACK, 1) \ + XX(RTCP_RTPFB_TMMBR, 3) \ + XX(RTCP_RTPFB_TMMBN, 4) \ + XX(RTCP_RTPFB_TWCC, 15) + //rtcp类型枚举 enum class RtcpType : uint8_t { #define XX(key, value) key = value, @@ -69,6 +126,20 @@ enum class SdesType : uint8_t { #undef XX }; +//psfb类型枚举 +enum class PSFBType : uint8_t { +#define XX(key, value) key = value, + PSFB_TYPE_MAP(XX) +#undef XX +}; + +//rtpfb类型枚举 +enum class RTPFBType : uint8_t { +#define XX(key, value) key = value, + RTPFB_TYPE_MAP(XX) +#undef XX +}; + /** * RtcpType转描述字符串 */ @@ -79,6 +150,16 @@ const char *rtcpTypeToStr(RtcpType type); */ const char *sdesTypeToStr(SdesType type); +/** + * psfb枚举转描述字符串 + */ +const char *psfbTypeToStr(PSFBType type); + +/** + * rtpfb枚举转描述字符串 + */ +const char *rtpfbTypeToStr(RTPFBType type); + class RtcpHeader { public: #if __BYTE_ORDER == __BIG_ENDIAN @@ -91,13 +172,15 @@ public: #else //reception report count uint32_t report_count: 5; - //padding,固定为0 + //padding,末尾是否有追加填充 uint32_t padding: 1; //版本号,固定为2 uint32_t version: 2; #endif //rtcp类型,RtcpType uint32_t pt: 8; + +private: //长度 uint32_t length: 16; @@ -124,11 +207,23 @@ public: */ string dumpString() const; -protected: /** - * 网络字节序转换为主机字节序 + * 根据length字段获取rtcp总长度 */ - void net2Host(); + size_t getSize() const; + + /** + * 后面追加padding数据长度 + */ + size_t getPaddingSize() const; + + /** + * 设置rtcp length字段 + * @param size rtcp总长度,单位字节 + */ + void setSize(size_t size); + +protected: /** * 打印字段详情 @@ -389,9 +484,9 @@ public: //SdesType uint8_t type; //text长度股,可以为0 - uint8_t length; + uint8_t txt_len; //不定长 - char text; + char text[1]; //最后以RTCP_SDES_END结尾 //只字段为占位字段,不代表真实位置 uint8_t end; @@ -434,7 +529,7 @@ public: * @param item_text SdesItem列表,只赋值length和text部分 * @return SDES包 */ - static std::shared_ptr create(const std::initializer_list &item_text); + static std::shared_ptr create(const std::vector &item_text); /** * 获取SdesItem对象指针列表 @@ -456,6 +551,142 @@ private: void net2Host(size_t size); } PACKED; +// https://tools.ietf.org/html/rfc4585#section-6.1 +// 6.1. Common Packet Format for Feedback Messages +// +// All FB messages MUST use a common packet format that is depicted in +// Figure 3: +// +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// |V=2|P| FMT | PT | length | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | SSRC of packet sender | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | SSRC of media source | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// : Feedback Control Information (FCI) : +// : : +// rtcpfb和psfb的数据结构一致 +class RtcpFB : public RtcpHeader { +public: + friend class RtcpHeader; + uint32_t ssrc; + uint32_t ssrc_media; + +public: + /** + * 创建psfb类型的反馈包 + */ + static std::shared_ptr create(PSFBType fmt, const void *fci = nullptr, size_t fci_len = 0); + + /** + * 创建rtpfb类型的反馈包 + */ + static std::shared_ptr create(RTPFBType fmt, const void *fci = nullptr, size_t fci_len = 0); + + /** + * fci转换成某对象指针 + * @tparam Type 对象类型 + * @return 对象指针 + */ + template + const Type& getFci() const{ + auto fci_data = getFciPtr(); + auto fci_len = getFciSize(); + Type *fci = (Type *) fci_data; + fci->check(fci_len); + return *fci; + } + + /** + * 获取fci指针 + */ + const void *getFciPtr() const; + + /** + * 获取fci数据长度 + */ + size_t getFciSize() const; + +private: + /** + * 打印字段详情 + * 使用net2Host转换成主机字节序后才可使用此函数 + */ + string dumpString() const; + + /** + * 网络字节序转换为主机字节序 + * @param size 字节长度,防止内存越界 + */ + void net2Host(size_t size); + +private: + static std::shared_ptr create_l(RtcpType type, int fmt, const void *fci, size_t fci_len); +} PACKED; + +//BYE +/* + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |V=2|P| SC | PT=BYE=203 | length | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | SSRC/CSRC | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + : ... : + +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ +(opt) | length | reason for leaving ... + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +*/ + +class RtcpBye : public RtcpHeader { +public: + friend class RtcpHeader; + /* 变长,根据count决定有多少个ssrc */ + uint32_t ssrc[1]; + + /** 中间可能有若干个 ssrc **/ + + /* 可选 */ + uint8_t reason_len; + char reason[1]; + +public: + /** + * 创建bye包 + * @param ssrc ssrc列表 + * @param reason 原因 + * @return rtcp bye包 + */ + static std::shared_ptr create(const std::vector &ssrc, const string &reason); + + /** + * 获取ssrc列表 + */ + vector getSSRC(); + + /** + * 获取原因 + */ + string getReason() const; + +private: + /** + * 打印字段详情 + * 使用net2Host转换成主机字节序后才可使用此函数 + */ + string dumpString() const; + + /** + * 网络字节序转换为主机字节序 + * @param size 字节长度,防止内存越界 + */ + void net2Host(size_t size); +} PACKED; + #if defined(_WIN32) #pragma pack(pop) #endif // defined(_WIN32) diff --git a/src/Rtcp/RtcpFCI.cpp b/src/Rtcp/RtcpFCI.cpp new file mode 100644 index 00000000..dd7f2457 --- /dev/null +++ b/src/Rtcp/RtcpFCI.cpp @@ -0,0 +1,517 @@ +/* + * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#include "RtcpFCI.h" +#include "Util/logger.h" +using namespace toolkit; + +namespace mediakit { + +void FCI_SLI::check(size_t size){ + CHECK(size >= kSize); +} + +FCI_SLI::FCI_SLI(uint16_t first, uint16_t number, uint8_t pic_id) { + //13 bits + first &= 0x1FFF; + //13 bits + number &= 0x1FFF; + //6 bits + pic_id &= 0x3F; + data = (first << 19) | (number << 6) | pic_id; + data = htonl(data); +} + +uint16_t FCI_SLI::getFirst() const { + return ntohl(data) >> 19; +} + +uint16_t FCI_SLI::getNumber() const { + return (ntohl(data) >> 6) & 0x1FFF; +} + +uint8_t FCI_SLI::getPicID() const { + return ntohl(data) & 0x3F; +} + +string FCI_SLI::dumpString() const { + return StrPrinter << "First:" << getFirst() << ", Number:" << getNumber() << ", PictureID:" << (int)getPicID(); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void FCI_FIR::check(size_t size){ + CHECK(size >= kSize); +} + +uint32_t FCI_FIR::getSSRC() const{ + return ntohl(ssrc); +} + +uint8_t FCI_FIR::getSeq() const{ + return seq_number; +} + +uint32_t FCI_FIR::getReserved() const{ + return (reserved[0] << 16) | (reserved[1] << 8) | reserved[2]; +} + +string FCI_FIR::dumpString() const { + return StrPrinter << "ssrc:" << getSSRC() << ", seq_number:" << (int)getSeq() << ", reserved:" << getReserved(); +} + +FCI_FIR::FCI_FIR(uint32_t ssrc, uint8_t seq_number, uint32_t reserved) { + this->ssrc = htonl(ssrc); + this->seq_number = seq_number; + this->reserved[0] = (reserved >> 16) & 0xFF; + this->reserved[1] = (reserved >> 8) & 0xFF; + this->reserved[2] = reserved & 0xFF; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +static const char kRembMagic[] = "REMB"; + +void FCI_REMB::check(size_t size){ + CHECK(size >= kSize); + CHECK(memcmp(magic, kRembMagic, sizeof(magic)) == 0); + auto num_ssrc = bitrate[0]; + auto expect_size = kSize + 4 * num_ssrc; + CHECK(size >= expect_size); +} + +string FCI_REMB::create(const vector &ssrcs, uint32_t bitrate) { + CHECK(ssrcs.size() > 0 && ssrcs.size() <= 0xFF); + string ret; + ret.resize(kSize + ssrcs.size() * 4); + FCI_REMB *thiz = (FCI_REMB *) ret.data(); + memcpy(thiz->magic, kRembMagic, sizeof(magic)); + + /* bitrate --> BR Exp/BR Mantissa */ + uint8_t b = 0; + uint8_t exp = 0; + uint32_t mantissa = 0; + for (b = 0; b < 32; b++) { + if (bitrate <= ((uint32_t) 0x3FFFF << b)) { + exp = b; + break; + } + } + if (b > 31) { + b = 31; + } + mantissa = bitrate >> b; + //Num SSRC (8 bits) + thiz->bitrate[0] = ssrcs.size() & 0xFF; + //BR Exp (6 bits)/BR Mantissa (18 bits) + thiz->bitrate[1] = (uint8_t) ((exp << 2) + ((mantissa >> 16) & 0x03)); + //BR Mantissa (18 bits) + thiz->bitrate[2] = (uint8_t) (mantissa >> 8); + //BR Mantissa (18 bits) + thiz->bitrate[3] = (uint8_t) (mantissa); + + //设置ssrc列表 + auto ptr = thiz->ssrc_feedback; + for (auto ssrc : ssrcs) { + *(ptr++) = htonl(ssrc); + } + return ret; +} + +uint32_t FCI_REMB::getBitRate() const { + uint8_t exp = (bitrate[1] >> 2) & 0x3F; + uint32_t mantissa = (bitrate[1] & 0x03) << 16; + mantissa += (bitrate[2] << 8); + mantissa += (bitrate[3]); + return mantissa << exp; +} + +vector FCI_REMB::getSSRC() { + vector ret; + auto num_ssrc = bitrate[0]; + auto ptr = ssrc_feedback; + while (num_ssrc--) { + ret.emplace_back(ntohl(*ptr++)); + } + return ret; +} + +string FCI_REMB::dumpString() const { + _StrPrinter printer; + printer << "bitrate:" << getBitRate() << ", ssrc:"; + for (auto &ssrc : ((FCI_REMB *) this)->getSSRC()) { + printer << ssrc << " "; + } + return std::move(printer); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +FCI_NACK::FCI_NACK(uint16_t pid_h, const vector &type) { + uint16_t blp_h = 0; + int i = kBitSize; + for (auto item : type) { + --i; + if (item) { + blp_h |= (1 << i); + } + } + blp = htons(blp_h); + pid = htons(pid_h); +} + +void FCI_NACK::check(size_t size){ + CHECK(size >= kSize); +} + +uint16_t FCI_NACK::getPid() const { + return ntohs(pid); +} + +uint16_t FCI_NACK::getBlp() const { + return ntohs(blp); +} + +vector FCI_NACK::getBitArray() const { + vector ret; + ret.resize(kBitSize + 1); + //nack第一个包丢包 + ret[0] = true; + + auto blp_h = getBlp(); + for (size_t i = 0; i < kBitSize; ++i) { + ret[i + 1] = blp_h & (1 << (kBitSize - i - 1)); + } + return ret; +} + +string FCI_NACK::dumpString() const { + _StrPrinter printer; + printer << "pid:" << getPid() << ",blp:" << getBlp() << ",bit array:"; + for (auto flag : getBitArray()) { + printer << flag << " "; + } + return std::move(printer); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class RunLengthChunk { +public: + static size_t constexpr kSize = 2; + // 0 1 + // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // |T| S | Run Length | + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +#if __BYTE_ORDER == __BIG_ENDIAN + uint16_t type: 1; + uint16_t symbol: 2; + uint16_t run_length_high: 5; +#else + // Run Length 高5位 + uint16_t run_length_high: 5; + //参考SymbolStatus定义 + uint16_t symbol: 2; + //固定为0 + uint16_t type: 1; +#endif + // Run Length 低8位 + uint16_t run_length_low: 8; + + //获取Run Length + uint16_t getRunLength() const; + //构造函数 + RunLengthChunk(SymbolStatus status, uint16_t run_length); + //打印本对象 + string dumpString() const; +} PACKED; + +RunLengthChunk::RunLengthChunk(SymbolStatus status, uint16_t run_length) { + type = 0; + symbol = (uint8_t)status & 0x03; + run_length_high = (run_length >> 8) & 0x1F; + run_length_low = run_length & 0xFF; +} + +uint16_t RunLengthChunk::getRunLength() const { + CHECK(type == 0); + return run_length_high << 8 | run_length_low; +} + +string RunLengthChunk::dumpString() const{ + _StrPrinter printer; + printer << "run length chunk, symbol:" << (int)symbol << ", run length:" << getRunLength(); + return std::move(printer); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class StatusVecChunk { +public: + static size_t constexpr kSize = 2; + // 0 1 + // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // |T|S| symbol list | + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +#if __BYTE_ORDER == __BIG_ENDIAN + uint16_t type: 1; + uint16_t symbol: 1; + uint16_t symbol_list_high: 6; +#else + // symbol_list 高6位 + uint16_t symbol_list_high: 6; + //symbol_list中元素是1个还是2个bit + uint16_t symbol: 1; + //固定为1 + uint16_t type: 1; +#endif + // symbol_list 低8位 + uint16_t symbol_list_low: 8; + + //获取symbollist + vector getSymbolList() const; + //构造函数 + StatusVecChunk(const vector &status); + //打印本对象 + string dumpString() const; +} PACKED; + +StatusVecChunk::StatusVecChunk(const vector &status) { + uint16_t value = 0; + type = 1; + if (status.size() == 14) { + symbol = 0; + } else if (status.size() == 7) { + symbol = 1; + } else { + //非法 + CHECK(0); + } + int i = 13; + for (auto &item : status) { + CHECK(item <= SymbolStatus::reserved); + if (!symbol) { + CHECK(item <= SymbolStatus::small_delta); + value |= (int) item << i; + --i; + } else { + value |= (int) item << (i - 1); + i -= 2; + } + } + symbol_list_low = value & 0xFF; + symbol_list_high = (value >> 8 ) & 0x1F; +} + +vector StatusVecChunk::getSymbolList() const { + CHECK(type == 1); + vector ret; + auto thiz = ntohs(*((uint16_t *) this)); + if (symbol == 0) { + //s = 0 时,表示symbollist的每一个bit能表示一个数据包的到达状态 + for (int i = 13; i >= 0; --i) { + SymbolStatus status = (SymbolStatus) ((bool) (thiz & (1 << i))); + ret.emplace_back(status); + } + } else { + //s = 1 时,表示symbollist每两个bit表示一个数据包的状态 + for (int i = 12; i >= 0; i -= 2) { + SymbolStatus status = (SymbolStatus) ((thiz & (3 << i)) >> i); + ret.emplace_back(status); + } + } + return ret; +} + +string StatusVecChunk::dumpString() const { + _StrPrinter printer; + printer << "status vector chunk, symbol:" << (int) symbol << ", symbol list:"; + auto vec = getSymbolList(); + for (auto &item : vec) { + printer << (int) item << " "; + } + return std::move(printer); +} + +/////////////////////////////////////////////////////// + +void FCI_TWCC::check(size_t size){ + CHECK(size >= kSize); +} + +uint16_t FCI_TWCC::getBaseSeq() const { + return ntohs(base_seq); +} + +uint16_t FCI_TWCC::getPacketCount() const { + return ntohs(pkt_status_count); +} + +uint32_t FCI_TWCC::getReferenceTime() const { + uint32_t ret = 0; + ret |= ref_time[0] << 16; + ret |= ref_time[1] << 8; + ret |= ref_time[2]; + return ret; +} +//3.1.5. Receive Delta +// +// Deltas are represented as multiples of 250us: +// +// o If the "Packet received, small delta" symbol has been appended to +// the status list, an 8-bit unsigned receive delta will be appended +// to recv delta list, representing a delta in the range [0, 63.75] +// ms. +// +// o If the "Packet received, large or negative delta" symbol has been +// appended to the status list, a 16-bit signed receive delta will be +// appended to recv delta list, representing a delta in the range +// [-8192.0, 8191.75] ms. +// +// o If the delta exceeds even the larger limits, a new feedback +// message must be used, where the 24-bit base receive delta can +// cover very large gaps. +// +// The smaller receive delta upper bound of 63.75 ms means that this is +// only viable at about 1000/25.5 ~= 16 packets per second and above. +// With a packet size of 1200 bytes/packet that amounts to a bitrate of +// about 150 kbit/s. +// +// The 0.25 ms resolution means that up to 4000 packets per second can +// be represented. With a 1200 bytes/packet payload, that amounts to +// 38.4 Mbit/s payload bandwidth. + +static int16_t getRecvDelta(SymbolStatus status, uint8_t *&ptr, const uint8_t *end){ + int16_t delta = 0; + switch (status) { + case SymbolStatus::not_received : { + //丢包, recv delta为0个字节 + break; + } + case SymbolStatus::small_delta : { + CHECK(ptr + 1 <= end); + //时间戳增量小于256, recv delta为1个字节 + delta = *ptr; + ptr += 1; + break; + } + case SymbolStatus::large_delta : { + CHECK(ptr + 2 <= end); + //时间戳增量256~65535间,recv delta为2个字节 + delta = *ptr << 8 | *(ptr + 1); + ptr += 2; + break; + } + case SymbolStatus::reserved : { + //没有时间戳 + break; + } + default: + //这个逻辑分支不可达到 + CHECK(0); + break; + } + return delta; +} + +map > FCI_TWCC::getPacketChunkList(size_t total_size) const { + map > ret; + auto ptr = (uint8_t *) this + kSize; + auto end = (uint8_t *) this + total_size; + CHECK(ptr < end); + auto seq = getBaseSeq(); + auto rtp_count = getPacketCount(); + for (uint8_t i = 0; i < rtp_count;) { + CHECK(ptr + RunLengthChunk::kSize <= end); + RunLengthChunk *chunk = (RunLengthChunk *) ptr; + if (!chunk->type) { + //RunLengthChunk + for (auto j = 0; j < chunk->getRunLength(); ++j) { + ret.emplace(seq++, std::make_pair((SymbolStatus) chunk->symbol, 0)); + if (++i >= rtp_count) { + break; + } + } + } else { + //StatusVecChunk + StatusVecChunk *chunk = (StatusVecChunk *) ptr; + for (auto &symbol : chunk->getSymbolList()) { + ret.emplace(seq++, std::make_pair(symbol, 0)); + if (++i >= rtp_count) { + break; + } + } + } + ptr += 2; + } + for (auto &pr : ret) { + CHECK(ptr <= end); + pr.second.second = 250 * getRecvDelta(pr.second.first, ptr, end); + } + return ret; +} + +string FCI_TWCC::dumpString(size_t total_size) const { + _StrPrinter printer; + auto map = getPacketChunkList(total_size); + printer << "twcc fci, base_seq:" << getBaseSeq() << ", pkt_status_count:" << getPacketCount() << ", ref time:" << getReferenceTime() << ", fb count:" << (int)fb_pkt_count << "\n"; + for (auto &pr : map) { + printer << "rtp seq:" << pr.first <<", packet status:" << (int)(pr.second.first) << ", delta:" << pr.second.second << "\n"; + } + return std::move(printer); +} + +}//namespace mediakit + +#if 1 +using namespace mediakit; +void testFCI() { + { + FCI_SLI fci(8191, 0, 63); + InfoL << hexdump(&fci, FCI_SLI::kSize) << fci.dumpString(); + } + { + FCI_FIR fci(123456, 139, 456789); + InfoL << hexdump(&fci, FCI_FIR::kSize) << fci.dumpString(); + } + { + auto str = FCI_REMB::create({1234, 2345, 5678}, 4 * 1024 * 1024); + FCI_REMB *ptr = (FCI_REMB *) str.data(); + InfoL << hexdump(str.data(), str.size()) << ptr->dumpString(); + } + { + FCI_NACK nack(1234, vector({1, 0, 0, 0, 1, 0, 1, 0, 1, 0})); + InfoL << hexdump(&nack, FCI_NACK::kSize) << nack.dumpString(); + } + + { + RunLengthChunk chunk(SymbolStatus::large_delta, 8024); + InfoL << hexdump(&chunk, RunLengthChunk::kSize) << chunk.dumpString(); + } + + auto lam = [](const initializer_list &lst) { + vector ret; + for (auto &num : lst) { + ret.emplace_back((SymbolStatus) num); + } + return ret; + }; + { + StatusVecChunk chunk(lam({0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1})); + InfoL << hexdump(&chunk, StatusVecChunk::kSize) << chunk.dumpString(); + } + { + StatusVecChunk chunk(lam({0, 1, 2, 2, 0, 1, 2})); + InfoL << hexdump(&chunk, StatusVecChunk::kSize) << chunk.dumpString(); + } +} +#endif \ No newline at end of file diff --git a/src/Rtcp/RtcpFCI.h b/src/Rtcp/RtcpFCI.h new file mode 100644 index 00000000..1b68e457 --- /dev/null +++ b/src/Rtcp/RtcpFCI.h @@ -0,0 +1,369 @@ +/* + * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef ZLMEDIAKIT_RTCPFCI_H +#define ZLMEDIAKIT_RTCPFCI_H + +#include "Rtcp.h" +#include "assert.h" + +namespace mediakit { + +/////////////////////////////////////////// PSFB //////////////////////////////////////////////////// + +//PSFB fmt = 2 +//https://tools.ietf.org/html/rfc4585#section-6.3.2.2 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | First | Number | PictureID | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +//First: 13 bits +// The macroblock (MB) address of the first lost macroblock. The MB +// numbering is done such that the macroblock in the upper left +// corner of the picture is considered macroblock number 1 and the +// number for each macroblock increases from left to right and then +// from top to bottom in raster-scan order (such that if there is a +// total of N macroblocks in a picture, the bottom right macroblock +// is considered macroblock number N). +// +// Number: 13 bits +// The number of lost macroblocks, in scan order as discussed above. +// +// PictureID: 6 bits +// The six least significant bits of the codec-specific identifier +// that is used to reference the picture in which the loss of the +// macroblock(s) has occurred. For many video codecs, the PictureID +// is identical to the Temporal Reference. +class FCI_SLI { +public: + static size_t constexpr kSize = 4; + + FCI_SLI(uint16_t first, uint16_t number, uint8_t pic_id); + + void check(size_t size); + uint16_t getFirst() const; + uint16_t getNumber() const; + uint8_t getPicID() const; + string dumpString() const; + +private: + uint32_t data; +} PACKED; + +//PSFB fmt = 3 +//https://tools.ietf.org/html/rfc4585#section-6.3.3.2 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | PB |0| Payload Type| Native RPSI bit string | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | defined per codec ... | Padding (0) | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +class FCI_RPSI { +public: + //The number of unused bits required to pad the length of the RPSI + // message to a multiple of 32 bits. + uint8_t pb; + +#if __BYTE_ORDER == __BIG_ENDIAN + //0: 1 bit + // MUST be set to zero upon transmission and ignored upon reception. + uint8_t zero : 1; + //Payload Type: 7 bits + // Indicates the RTP payload type in the context of which the native + // RPSI bit string MUST be interpreted. + uint8_t pt : 7; +#else + uint8_t pt: 7; + uint8_t zero: 1; +#endif + + // Native RPSI bit string: variable length + // The RPSI information as natively defined by the video codec. + char bit_string[5]; + + //Padding: #PB bits + // A number of bits set to zero to fill up the contents of the RPSI + // message to the next 32-bit boundary. The number of padding bits + // MUST be indicated by the PB field. + uint8_t padding; + + static size_t constexpr kSize = 8; +} PACKED; + +//PSFB fmt = 4 +//https://tools.ietf.org/html/rfc5104#section-4.3.1.1 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | SSRC | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Seq nr. | Reserved | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +class FCI_FIR { +public: + static size_t constexpr kSize = 8; + + FCI_FIR(uint32_t ssrc, uint8_t seq_number, uint32_t reserved = 0); + + void check(size_t size); + uint32_t getSSRC() const; + uint8_t getSeq() const; + uint32_t getReserved() const; + string dumpString() const; + +private: + uint32_t ssrc; + uint8_t seq_number; + uint8_t reserved[3]; +} PACKED; + +//PSFB fmt = 5 +//https://tools.ietf.org/html/rfc5104#section-4.3.2.1 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | SSRC | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Seq nr. | Reserved | Index | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +class FCI_TSTR { +public: + static size_t constexpr kSize = 8; + + void check(size_t size) { + CHECK(size == kSize); + } + +private: + uint8_t data[kSize]; +} PACKED; + +//PSFB fmt = 6 +//https://tools.ietf.org/html/rfc5104#section-4.3.2.1 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | SSRC | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Seq nr. | Reserved | Index | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +class FCI_TSTN : public FCI_TSTR{ + +} PACKED; + +//PSFB fmt = 7 +//https://tools.ietf.org/html/rfc5104#section-4.3.4.1 +//0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | SSRC | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Seq nr. |0| Payload Type| Length | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | VBCM Octet String.... | Padding | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +class FCI_VBCM { +public: + static size_t constexpr kSize = 12; + + void check(size_t size) { + CHECK(size == kSize); + } + +private: + uint8_t data[kSize]; +} PACKED; + +//PSFB fmt = 15 +//https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Unique identifier 'R' 'E' 'M' 'B' | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Num SSRC | BR Exp | BR Mantissa | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | SSRC feedback | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | ... | +// Num SSRC (8 bits): Number of SSRCs in this message. +// +// BR Exp (6 bits): The exponential scaling of the mantissa for the +// maximum total media bit rate value, ignoring all packet +// overhead. The value is an unsigned integer [0..63], as +// in RFC 5104 section 4.2.2.1. +// +// BR Mantissa (18 bits): The mantissa of the maximum total media bit +// rate (ignoring all packet overhead) that the sender of +// the REMB estimates. The BR is the estimate of the +// traveled path for the SSRCs reported in this message. +// The value is an unsigned integer in number of bits per +// second. +// +// SSRC feedback (32 bits) Consists of one or more SSRC entries which +// this feedback message applies to. +class FCI_REMB { +public: + static size_t constexpr kSize = 8; + + static string create(const std::vector &ssrcs, uint32_t bitrate); + void check(size_t size); + string dumpString() const; + uint32_t getBitRate() const; + vector getSSRC(); + +private: + //Unique identifier 'R' 'E' 'M' 'B' + char magic[4]; + //Num SSRC (8 bits)/BR Exp (6 bits)/ BR Mantissa (18 bits) + uint8_t bitrate[4]; + // SSRC feedback (32 bits) Consists of one or more SSRC entries which + // this feedback message applies to. + uint32_t ssrc_feedback[1]; +} PACKED; + +/////////////////////////////////////////// RTPFB //////////////////////////////////////////////////// + +//RTPFB fmt = 1 +//https://tools.ietf.org/html/rfc4585#section-6.2.1 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | PID | BLP | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +class FCI_NACK { +public: + static constexpr size_t kSize = 4; + static constexpr size_t kBitSize = 16; + + FCI_NACK(uint16_t pid_h, const vector &type); + + void check(size_t size); + uint16_t getPid() const; + uint16_t getBlp() const; + //返回丢包列表,总长度17,第一个包必丢 + vector getBitArray() const; + string dumpString() const; + +private: + // The PID field is used to specify a lost packet. The PID field + // refers to the RTP sequence number of the lost packet. + uint16_t pid; + // bitmask of following lost packets (BLP): 16 bits + uint16_t blp; +} PACKED; + +//RTPFB fmt = 3 +//https://tools.ietf.org/html/rfc5104#section-4.2.1.1 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | SSRC | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | MxTBR Exp | MxTBR Mantissa |Measured Overhead| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +class FCI_TMMBR { +public: + static size_t constexpr kSize = 8; + + void check(size_t size) { + CHECK(size == kSize); + } + +private: + //SSRC (32 bits): The SSRC value of the media sender that is + // requested to obey the new maximum bit rate. + uint32_t ssrc; + + // MxTBR Exp (6 bits): The exponential scaling of the mantissa for the + // maximum total media bit rate value. The value is an + // unsigned integer [0..63]. + // MxTBR Mantissa (17 bits): The mantissa of the maximum total media + // bit rate value as an unsigned integer. + // Measured Overhead (9 bits): The measured average packet overhead + // value in bytes. The measurement SHALL be done according + // to the description in section 4.2.1.2. The value is an + // unsigned integer [0..511]. + uint32_t max_tbr; +} PACKED; + +//RTPFB fmt = 4 +// https://tools.ietf.org/html/rfc5104#section-4.2.2.1 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | SSRC | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | MxTBR Exp | MxTBR Mantissa |Measured Overhead| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +class FCI_TMMBN : public FCI_TMMBR{ +public: + +} PACKED; + +enum class SymbolStatus : uint8_t{ + //Packet not received + not_received = 0, + //Packet received, small delta (所谓small detal是指能用一个字节表示的数值) + small_delta = 1, + // Packet received, large ornegative delta (large即是能用两个字节表示的数值) + large_delta = 2, + //Reserved + reserved = 3 +}; + +//RTPFB fmt = 15 +//https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#section-3.1 +//https://zhuanlan.zhihu.com/p/206656654 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | base sequence number | packet status count | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | reference time | fb pkt. count | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | packet chunk | packet chunk | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// . . +// . . +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | packet chunk | recv delta | recv delta | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// . . +// . . +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | recv delta | recv delta | zero padding | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +class FCI_TWCC{ +public: + static size_t constexpr kSize = 8; + + void check(size_t size); + string dumpString(size_t total_size) const; + uint16_t getBaseSeq() const; + uint32_t getReferenceTime() const; + uint16_t getPacketCount() const; + map > getPacketChunkList(size_t total_size) const; + +private: + //base sequence number,基础序号,本次反馈的第一个包的序号;也就是RTP扩展头的序列号 + uint16_t base_seq; + //packet status count, 包个数,本次反馈包含多少个包的状态;从基础序号开始算 + uint16_t pkt_status_count; + //reference time,基准时间,绝对时间;计算该包中每个媒体包的到达时间都要基于这个基准时间计算 + uint8_t ref_time[3]; + //feedback packet count,反馈包号,本包是第几个transport-cc包,每次加1 | + uint8_t fb_pkt_count; +} PACKED; + +} //namespace mediakit +#endif //ZLMEDIAKIT_RTCPFCI_H diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 7591ff63..9a4658a5 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -463,6 +463,9 @@ void RtmpSession::onRtmpChunk(RtmpPacket::Ptr packet) { std::string type = dec.load(); if (type == "@setDataFrame") { setMetaData(dec); + } else if (type == "onMetaData") { + //兼容某些不规范的推流器 + _publisher_metadata = dec.load(); } else { TraceP(this) << "unknown notify:" << type; } diff --git a/src/Rtsp/RtpReceiver.h b/src/Rtsp/RtpReceiver.h index a5f1eaa0..24cf8fb8 100644 --- a/src/Rtsp/RtpReceiver.h +++ b/src/Rtsp/RtpReceiver.h @@ -21,7 +21,7 @@ using namespace toolkit; namespace mediakit { -template +template class PacketSortor { public: PacketSortor() = default; diff --git a/src/Rtsp/Rtsp.cpp b/src/Rtsp/Rtsp.cpp index 492eb644..bd2f165c 100644 --- a/src/Rtsp/Rtsp.cpp +++ b/src/Rtsp/Rtsp.cpp @@ -458,18 +458,27 @@ size_t RtpHeader::getExtSize() const { return 0; } auto ext_ptr = &payload + getCsrcSize(); - uint16_t reserved = AV_RB16(ext_ptr); + //uint16_t reserved = AV_RB16(ext_ptr); //每个ext占用4字节 return AV_RB16(ext_ptr + 2) << 2; } +uint16_t RtpHeader::getExtReserved() const{ + //rtp有ext + if (!ext) { + return 0; + } + auto ext_ptr = &payload + getCsrcSize(); + return AV_RB16(ext_ptr); +} + uint8_t *RtpHeader::getExtData() { if (!ext) { return nullptr; } auto ext_ptr = &payload + getCsrcSize(); //多出的4个字节分别为reserved、ext_len - return ext_ptr + 4 + getExtSize(); + return ext_ptr + 4; } size_t RtpHeader::getPayloadOffset() const { @@ -521,6 +530,10 @@ RtpHeader* RtpPacket::getHeader(){ return (RtpHeader*)(data() + RtpPacket::kRtpTcpHeaderSize); } +string RtpPacket::dumpString() const{ + return ((RtpPacket *) this)->getHeader()->dumpString(size() - RtpPacket::kRtpTcpHeaderSize); +} + uint16_t RtpPacket::getSeq(){ return ntohs(getHeader()->seq); } diff --git a/src/Rtsp/Rtsp.h b/src/Rtsp/Rtsp.h index 884176e1..aa3b81fb 100644 --- a/src/Rtsp/Rtsp.h +++ b/src/Rtsp/Rtsp.h @@ -119,6 +119,8 @@ public: //返回ext字段字节长度 size_t getExtSize() const; + //返回ext reserved值 + uint16_t getExtReserved() const; //返回ext段首地址,不存在时返回nullptr uint8_t *getExtData(); @@ -150,7 +152,11 @@ public: kRtpTcpHeaderSize = 4 }; + //获取rtp头 RtpHeader* getHeader(); + //打印调试信息 + string dumpString() const; + //主机字节序的seq uint16_t getSeq(); //主机字节序的时间戳,已经转换为毫秒 diff --git a/src/Rtsp/RtspMediaSourceImp.h b/src/Rtsp/RtspMediaSourceImp.h index 8ca3df5a..37731f1e 100644 --- a/src/Rtsp/RtspMediaSourceImp.h +++ b/src/Rtsp/RtspMediaSourceImp.h @@ -56,7 +56,11 @@ public: //需要解复用rtp key_pos = _demuxer->inputRtp(rtp); } - RtspMediaSource::onWrite(std::move(rtp), key_pos); + GET_CONFIG(bool, directProxy, Rtsp::kDirectProxy); + if (directProxy) { + //直接代理模式才直接使用原始rtp + RtspMediaSource::onWrite(std::move(rtp), key_pos); + } } /** @@ -72,8 +76,10 @@ public: * @param enableMP4 是否mp4录制 */ void setProtocolTranslation(bool enableHls,bool enableMP4){ - //不重复生成rtsp - _muxer = std::make_shared(getVhost(), getApp(), getId(), _demuxer->getDuration(), false, true, enableHls, enableMP4); + GET_CONFIG(bool, directProxy, Rtsp::kDirectProxy); + //开启直接代理模式时,rtsp直接代理,不重复产生;但是有些rtsp推流端,由于sdp中已有sps pps,rtp中就不再包括sps pps, + //导致rtc无法播放,所以在rtsp推流rtc播放时,建议关闭直接代理模式 + _muxer = std::make_shared(getVhost(), getApp(), getId(), _demuxer->getDuration(), !directProxy, true, enableHls, enableMP4); _muxer->setMediaListener(getListener()); _muxer->setTrackListener(static_pointer_cast(shared_from_this())); //让_muxer对象拦截一部分事件(比如说录像相关事件) diff --git a/tests/test_rtcp_fci.cpp b/tests/test_rtcp_fci.cpp new file mode 100644 index 00000000..1dda1143 --- /dev/null +++ b/tests/test_rtcp_fci.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2016 The ZLToolKit project authors. All Rights Reserved. + * + * This file is part of ZLToolKit(https://github.com/xia-chu/ZLToolKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include "Util/logger.h" +#include "Rtcp/RtcpFCI.h" +using namespace std; +using namespace toolkit; +using namespace mediakit; + +extern void testFCI(); + +int main() { + Logger::Instance().add(std::make_shared()); + + testFCI(); + return 0; +} diff --git a/tests/test_rtcp_nack.cpp b/tests/test_rtcp_nack.cpp new file mode 100644 index 00000000..7463ce02 --- /dev/null +++ b/tests/test_rtcp_nack.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016 The ZLToolKit project authors. All Rights Reserved. + * + * This file is part of ZLToolKit(https://github.com/xia-chu/ZLToolKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include "Util/logger.h" +#include "Rtcp/RtcpFCI.h" +#include "../webrtc/WebRtcTransport.h" +using namespace std; +using namespace toolkit; +using namespace mediakit; + +extern void testFCI(); + +int main() { + Logger::Instance().add(std::make_shared()); + + srand((unsigned) time(NULL)); + + NackContext ctx; + for (int i = 1; i < 1000; ++i) { + if (i % (1 + (rand() % 30)) == 0) { + DebugL << "drop:" << i; + } else { + ctx.received(i); + + } + } + sleep(1); + return 0; +} diff --git a/webrtc/DtlsTransport.cpp b/webrtc/DtlsTransport.cpp new file mode 100644 index 00000000..8abb2a21 --- /dev/null +++ b/webrtc/DtlsTransport.cpp @@ -0,0 +1,1483 @@ +/** +ISC License + +Copyright © 2015, Iñaki Baz Castillo + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define MS_CLASS "RTC::DtlsTransport" +// #define MS_LOG_DEV_LEVEL 3 + +#include "DtlsTransport.hpp" +#include "logger.h" +#include +#include +#include +#include +#include +#include // std::sprintf(), std::fopen() +#include // std::memcpy(), std::strcmp() +#include "Util/util.h" + +#define LOG_OPENSSL_ERROR(desc) \ + do \ + { \ + if (ERR_peek_error() == 0) \ + MS_ERROR("OpenSSL error [desc:'%s']", desc); \ + else \ + { \ + int64_t err; \ + while ((err = ERR_get_error()) != 0) \ + { \ + MS_ERROR("OpenSSL error [desc:'%s', error:'%s']", desc, ERR_error_string(err, nullptr)); \ + } \ + ERR_clear_error(); \ + } \ + } while (false) + +/* Static methods for OpenSSL callbacks. */ + +inline static int onSslCertificateVerify(int /*preverifyOk*/, X509_STORE_CTX* /*ctx*/) +{ + MS_TRACE(); + + // Always valid since DTLS certificates are self-signed. + return 1; +} + +inline static unsigned int onSslDtlsTimer(SSL* /*ssl*/, unsigned int timerUs) +{ + if (timerUs == 0) + return 100000; + else if (timerUs >= 4000000) + return 4000000; + else + return 2 * timerUs; +} + +namespace RTC +{ + /* Static. */ + + // clang-format off + static constexpr int DtlsMtu{ 1350 }; + // AES-HMAC: http://tools.ietf.org/html/rfc3711 + static constexpr size_t SrtpMasterKeyLength{ 16 }; + static constexpr size_t SrtpMasterSaltLength{ 14 }; + static constexpr size_t SrtpMasterLength{ SrtpMasterKeyLength + SrtpMasterSaltLength }; + // AES-GCM: http://tools.ietf.org/html/rfc7714 + static constexpr size_t SrtpAesGcm256MasterKeyLength{ 32 }; + static constexpr size_t SrtpAesGcm256MasterSaltLength{ 12 }; + static constexpr size_t SrtpAesGcm256MasterLength{ SrtpAesGcm256MasterKeyLength + SrtpAesGcm256MasterSaltLength }; + static constexpr size_t SrtpAesGcm128MasterKeyLength{ 16 }; + static constexpr size_t SrtpAesGcm128MasterSaltLength{ 12 }; + static constexpr size_t SrtpAesGcm128MasterLength{ SrtpAesGcm128MasterKeyLength + SrtpAesGcm128MasterSaltLength }; + // clang-format on + + /* Class variables. */ + // clang-format off + std::map DtlsTransport::string2FingerprintAlgorithm = + { + { "sha-1", DtlsTransport::FingerprintAlgorithm::SHA1 }, + { "sha-224", DtlsTransport::FingerprintAlgorithm::SHA224 }, + { "sha-256", DtlsTransport::FingerprintAlgorithm::SHA256 }, + { "sha-384", DtlsTransport::FingerprintAlgorithm::SHA384 }, + { "sha-512", DtlsTransport::FingerprintAlgorithm::SHA512 } + }; + std::map DtlsTransport::fingerprintAlgorithm2String = + { + { DtlsTransport::FingerprintAlgorithm::SHA1, "sha-1" }, + { DtlsTransport::FingerprintAlgorithm::SHA224, "sha-224" }, + { DtlsTransport::FingerprintAlgorithm::SHA256, "sha-256" }, + { DtlsTransport::FingerprintAlgorithm::SHA384, "sha-384" }, + { DtlsTransport::FingerprintAlgorithm::SHA512, "sha-512" } + }; + std::map DtlsTransport::string2Role = + { + { "auto", DtlsTransport::Role::AUTO }, + { "client", DtlsTransport::Role::CLIENT }, + { "server", DtlsTransport::Role::SERVER } + }; + std::vector DtlsTransport::srtpCryptoSuites = + { + { RTC::SrtpSession::CryptoSuite::AEAD_AES_256_GCM, "SRTP_AEAD_AES_256_GCM" }, + { RTC::SrtpSession::CryptoSuite::AEAD_AES_128_GCM, "SRTP_AEAD_AES_128_GCM" }, + { RTC::SrtpSession::CryptoSuite::AES_CM_128_HMAC_SHA1_80, "SRTP_AES128_CM_SHA1_80" }, + { RTC::SrtpSession::CryptoSuite::AES_CM_128_HMAC_SHA1_32, "SRTP_AES128_CM_SHA1_32" } + }; + // clang-format on + + INSTANCE_IMP(DtlsTransport::DtlsEnvironment); + + /* Class methods. */ + + DtlsTransport::DtlsEnvironment::DtlsEnvironment() + { + MS_TRACE(); + + // Generate a X509 certificate and private key (unless PEM files are provided). + if (true /* + Settings::configuration.dtlsCertificateFile.empty() || + Settings::configuration.dtlsPrivateKeyFile.empty()*/) + { + GenerateCertificateAndPrivateKey(); + } + else + { + ReadCertificateAndPrivateKeyFromFiles(); + } + + // Create a global SSL_CTX. + CreateSslCtx(); + + // Generate certificate fingerprints. + GenerateFingerprints(); + } + + DtlsTransport::DtlsEnvironment::~DtlsEnvironment() + { + MS_TRACE(); + + if (privateKey) + EVP_PKEY_free(privateKey); + if (certificate) + X509_free(certificate); + if (sslCtx) + SSL_CTX_free(sslCtx); + } + + void DtlsTransport::DtlsEnvironment::GenerateCertificateAndPrivateKey() + { + MS_TRACE(); + + int ret{ 0 }; + EC_KEY* ecKey{ nullptr }; + X509_NAME* certName{ nullptr }; + std::string subject = + std::string("mediasoup") + std::to_string(rand() % 999999 + 100000); + + // Create key with curve. + ecKey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); + + if (!ecKey) + { + LOG_OPENSSL_ERROR("EC_KEY_new_by_curve_name() failed"); + + goto error; + } + + EC_KEY_set_asn1_flag(ecKey, OPENSSL_EC_NAMED_CURVE); + + // NOTE: This can take some time. + ret = EC_KEY_generate_key(ecKey); + + if (ret == 0) + { + LOG_OPENSSL_ERROR("EC_KEY_generate_key() failed"); + + goto error; + } + + // Create a private key object. + privateKey = EVP_PKEY_new(); + + if (!privateKey) + { + LOG_OPENSSL_ERROR("EVP_PKEY_new() failed"); + + goto error; + } + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) + ret = EVP_PKEY_assign_EC_KEY(privateKey, ecKey); + + if (ret == 0) + { + LOG_OPENSSL_ERROR("EVP_PKEY_assign_EC_KEY() failed"); + + goto error; + } + + // The EC key now belongs to the private key, so don't clean it up separately. + ecKey = nullptr; + + // Create the X509 certificate. + certificate = X509_new(); + + if (!certificate) + { + LOG_OPENSSL_ERROR("X509_new() failed"); + + goto error; + } + + // Set version 3 (note that 0 means version 1). + X509_set_version(certificate, 2); + + // Set serial number (avoid default 0). + ASN1_INTEGER_set( + X509_get_serialNumber(certificate), + static_cast(rand() % 999999 + 100000)); + + // Set valid period. + X509_gmtime_adj(X509_get_notBefore(certificate), -315360000); // -10 years. + X509_gmtime_adj(X509_get_notAfter(certificate), 315360000); // 10 years. + + // Set the public key for the certificate using the key. + ret = X509_set_pubkey(certificate, privateKey); + + if (ret == 0) + { + LOG_OPENSSL_ERROR("X509_set_pubkey() failed"); + + goto error; + } + + // Set certificate fields. + certName = X509_get_subject_name(certificate); + + if (!certName) + { + LOG_OPENSSL_ERROR("X509_get_subject_name() failed"); + + goto error; + } + + X509_NAME_add_entry_by_txt( + certName, "O", MBSTRING_ASC, reinterpret_cast(subject.c_str()), -1, -1, 0); + X509_NAME_add_entry_by_txt( + certName, "CN", MBSTRING_ASC, reinterpret_cast(subject.c_str()), -1, -1, 0); + + // It is self-signed so set the issuer name to be the same as the subject. + ret = X509_set_issuer_name(certificate, certName); + + if (ret == 0) + { + LOG_OPENSSL_ERROR("X509_set_issuer_name() failed"); + + goto error; + } + + // Sign the certificate with its own private key. + ret = X509_sign(certificate, privateKey, EVP_sha1()); + + if (ret == 0) + { + LOG_OPENSSL_ERROR("X509_sign() failed"); + + goto error; + } + + return; + + error: + + if (ecKey) + EC_KEY_free(ecKey); + + if (privateKey) + EVP_PKEY_free(privateKey); // NOTE: This also frees the EC key. + + if (certificate) + X509_free(certificate); + + MS_THROW_ERROR("DTLS certificate and private key generation failed"); + } + + void DtlsTransport::DtlsEnvironment::ReadCertificateAndPrivateKeyFromFiles() + { +#if 0 + MS_TRACE(); + + FILE* file{ nullptr }; + + file = fopen(Settings::configuration.dtlsCertificateFile.c_str(), "r"); + + if (!file) + { + MS_ERROR("error reading DTLS certificate file: %s", std::strerror(errno)); + + goto error; + } + + certificate = PEM_read_X509(file, nullptr, nullptr, nullptr); + + if (!certificate) + { + LOG_OPENSSL_ERROR("PEM_read_X509() failed"); + + goto error; + } + + fclose(file); + + file = fopen(Settings::configuration.dtlsPrivateKeyFile.c_str(), "r"); + + if (!file) + { + MS_ERROR("error reading DTLS private key file: %s", std::strerror(errno)); + + goto error; + } + + privateKey = PEM_read_PrivateKey(file, nullptr, nullptr, nullptr); + + if (!privateKey) + { + LOG_OPENSSL_ERROR("PEM_read_PrivateKey() failed"); + + goto error; + } + + fclose(file); + + return; + + error: + + MS_THROW_ERROR("error reading DTLS certificate and private key PEM files"); +#endif + } + + void DtlsTransport::DtlsEnvironment::CreateSslCtx() + { + MS_TRACE(); + + std::string dtlsSrtpCryptoSuites; + int ret; + + /* Set the global DTLS context. */ + + // Both DTLS 1.0 and 1.2 (requires OpenSSL >= 1.1.0). + sslCtx = SSL_CTX_new(DTLS_method()); + + if (!sslCtx) + { + LOG_OPENSSL_ERROR("SSL_CTX_new() failed"); + + goto error; + } + + ret = SSL_CTX_use_certificate(sslCtx, certificate); + + if (ret == 0) + { + LOG_OPENSSL_ERROR("SSL_CTX_use_certificate() failed"); + + goto error; + } + + ret = SSL_CTX_use_PrivateKey(sslCtx, privateKey); + + if (ret == 0) + { + LOG_OPENSSL_ERROR("SSL_CTX_use_PrivateKey() failed"); + + goto error; + } + + ret = SSL_CTX_check_private_key(sslCtx); + + if (ret == 0) + { + LOG_OPENSSL_ERROR("SSL_CTX_check_private_key() failed"); + + goto error; + } + + // Set options. + SSL_CTX_set_options( + sslCtx, + SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_NO_TICKET | SSL_OP_SINGLE_ECDH_USE | + SSL_OP_NO_QUERY_MTU); + + // Don't use sessions cache. + SSL_CTX_set_session_cache_mode(sslCtx, SSL_SESS_CACHE_OFF); + + // Read always as much into the buffer as possible. + // NOTE: This is the default for DTLS, but a bug in non latest OpenSSL + // versions makes this call required. + SSL_CTX_set_read_ahead(sslCtx, 1); + + SSL_CTX_set_verify_depth(sslCtx, 4); + + // Require certificate from peer. + SSL_CTX_set_verify( + sslCtx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, onSslCertificateVerify); + + // Set SSL info callback. + SSL_CTX_set_info_callback(sslCtx, [](const SSL* ssl, int where, int ret){ + static_cast(SSL_get_ex_data(ssl, 0))->OnSslInfo(where, ret); + }); + // Set ciphers. + ret = SSL_CTX_set_cipher_list( + sslCtx, "DEFAULT:!NULL:!aNULL:!SHA256:!SHA384:!aECDH:!AESGCM+AES256:!aPSK"); + + if (ret == 0) + { + LOG_OPENSSL_ERROR("SSL_CTX_set_cipher_list() failed"); + + goto error; + } + + // Enable ECDH ciphers. + // DOC: http://en.wikibooks.org/wiki/OpenSSL/Diffie-Hellman_parameters + // NOTE: https://code.google.com/p/chromium/issues/detail?id=406458 + // NOTE: https://bugs.ruby-lang.org/issues/12324 + + // For OpenSSL >= 1.0.2. + SSL_CTX_set_ecdh_auto(sslCtx, 1); + + // Set the "use_srtp" DTLS extension. + for (auto it = DtlsTransport::srtpCryptoSuites.begin(); + it != DtlsTransport::srtpCryptoSuites.end(); + ++it) + { + if (it != DtlsTransport::srtpCryptoSuites.begin()) + dtlsSrtpCryptoSuites += ":"; + + SrtpCryptoSuiteMapEntry* cryptoSuiteEntry = std::addressof(*it); + dtlsSrtpCryptoSuites += cryptoSuiteEntry->name; + } + + MS_DEBUG_2TAGS(dtls, srtp, "setting SRTP cryptoSuites for DTLS: %s", dtlsSrtpCryptoSuites.c_str()); + + // NOTE: This function returns 0 on success. + ret = SSL_CTX_set_tlsext_use_srtp(sslCtx, dtlsSrtpCryptoSuites.c_str()); + + if (ret != 0) + { + MS_ERROR( + "SSL_CTX_set_tlsext_use_srtp() failed when entering '%s'", dtlsSrtpCryptoSuites.c_str()); + LOG_OPENSSL_ERROR("SSL_CTX_set_tlsext_use_srtp() failed"); + + goto error; + } + + return; + + error: + + if (sslCtx) + { + SSL_CTX_free(sslCtx); + sslCtx = nullptr; + } + + MS_THROW_ERROR("SSL context creation failed"); + } + + void DtlsTransport::DtlsEnvironment::GenerateFingerprints() + { + MS_TRACE(); + + for (auto& kv : DtlsTransport::string2FingerprintAlgorithm) + { + const std::string& algorithmString = kv.first; + FingerprintAlgorithm algorithm = kv.second; + uint8_t binaryFingerprint[EVP_MAX_MD_SIZE]; + unsigned int size{ 0 }; + char hexFingerprint[(EVP_MAX_MD_SIZE * 3) + 1]; + const EVP_MD* hashFunction; + int ret; + + switch (algorithm) + { + case FingerprintAlgorithm::SHA1: + hashFunction = EVP_sha1(); + break; + + case FingerprintAlgorithm::SHA224: + hashFunction = EVP_sha224(); + break; + + case FingerprintAlgorithm::SHA256: + hashFunction = EVP_sha256(); + break; + + case FingerprintAlgorithm::SHA384: + hashFunction = EVP_sha384(); + break; + + case FingerprintAlgorithm::SHA512: + hashFunction = EVP_sha512(); + break; + + default: + MS_THROW_ERROR("unknown algorithm"); + } + + ret = X509_digest(certificate, hashFunction, binaryFingerprint, &size); + + if (ret == 0) + { + MS_ERROR("X509_digest() failed"); + MS_THROW_ERROR("Fingerprints generation failed"); + } + + // Convert to hexadecimal format in uppercase with colons. + for (unsigned int i{ 0 }; i < size; ++i) + { + std::sprintf(hexFingerprint + (i * 3), "%.2X:", binaryFingerprint[i]); + } + hexFingerprint[(size * 3) - 1] = '\0'; + + MS_DEBUG_TAG(dtls, "%-7s fingerprint: %s", algorithmString.c_str(), hexFingerprint); + + // Store it in the vector. + DtlsTransport::Fingerprint fingerprint; + + fingerprint.algorithm = DtlsTransport::GetFingerprintAlgorithm(algorithmString); + fingerprint.value = hexFingerprint; + + localFingerprints.push_back(fingerprint); + } + } + + /* Instance methods. */ + + DtlsTransport::DtlsTransport(EventPoller::Ptr poller,Listener* listener) : poller(std::move(poller)), listener(listener) + { + MS_TRACE(); + env = DtlsEnvironment::Instance().shared_from_this(); + + /* Set SSL. */ + + this->ssl = SSL_new(env->sslCtx); + + if (!this->ssl) + { + LOG_OPENSSL_ERROR("SSL_new() failed"); + + goto error; + } + + // Set this as custom data. + SSL_set_ex_data(this->ssl, 0, static_cast(this)); + + this->sslBioFromNetwork = BIO_new(BIO_s_mem()); + + if (!this->sslBioFromNetwork) + { + LOG_OPENSSL_ERROR("BIO_new() failed"); + + SSL_free(this->ssl); + + goto error; + } + + this->sslBioToNetwork = BIO_new(BIO_s_mem()); + + if (!this->sslBioToNetwork) + { + LOG_OPENSSL_ERROR("BIO_new() failed"); + + BIO_free(this->sslBioFromNetwork); + SSL_free(this->ssl); + + goto error; + } + + SSL_set_bio(this->ssl, this->sslBioFromNetwork, this->sslBioToNetwork); + + // Set the MTU so that we don't send packets that are too large with no fragmentation. + SSL_set_mtu(this->ssl, DtlsMtu); + DTLS_set_link_mtu(this->ssl, DtlsMtu); + + // Set callback handler for setting DTLS timer interval. + DTLS_set_timer_cb(this->ssl, onSslDtlsTimer); + + return; + + error: + + // NOTE: At this point SSL_set_bio() was not called so we must free BIOs as + // well. + if (this->sslBioFromNetwork) + BIO_free(this->sslBioFromNetwork); + + if (this->sslBioToNetwork) + BIO_free(this->sslBioToNetwork); + + if (this->ssl) + SSL_free(this->ssl); + + // NOTE: If this is not catched by the caller the program will abort, but + // this should never happen. + MS_THROW_ERROR("DtlsTransport instance creation failed"); + } + + DtlsTransport::~DtlsTransport() + { + MS_TRACE(); + + if (IsRunning()) + { + // Send close alert to the peer. + SSL_shutdown(this->ssl); + SendPendingOutgoingDtlsData(); + } + + if (this->ssl) + { + SSL_free(this->ssl); + + this->ssl = nullptr; + this->sslBioFromNetwork = nullptr; + this->sslBioToNetwork = nullptr; + } + + // Close the DTLS timer. + this->timer = nullptr; + } + + void DtlsTransport::Dump() const + { + MS_TRACE(); + + std::string state{ "new" }; + std::string role{ "none " }; + + switch (this->state) + { + case DtlsState::CONNECTING: + state = "connecting"; + break; + case DtlsState::CONNECTED: + state = "connected"; + break; + case DtlsState::FAILED: + state = "failed"; + break; + case DtlsState::CLOSED: + state = "closed"; + break; + default:; + } + + switch (this->localRole) + { + case Role::AUTO: + role = "auto"; + break; + case Role::SERVER: + role = "server"; + break; + case Role::CLIENT: + role = "client"; + break; + default:; + } + + MS_DUMP(""); + MS_DUMP(" state : %s", state.c_str()); + MS_DUMP(" role : %s", role.c_str()); + MS_DUMP(" handshake done: : %s", this->handshakeDone ? "yes" : "no"); + MS_DUMP(""); + } + + void DtlsTransport::Run(Role localRole) + { + MS_TRACE(); + + MS_ASSERT( + localRole == Role::CLIENT || localRole == Role::SERVER, + "local DTLS role must be 'client' or 'server'"); + + Role previousLocalRole = this->localRole; + + if (localRole == previousLocalRole) + { + MS_ERROR("same local DTLS role provided, doing nothing"); + + return; + } + + // If the previous local DTLS role was 'client' or 'server' do reset. + if (previousLocalRole == Role::CLIENT || previousLocalRole == Role::SERVER) + { + MS_DEBUG_TAG(dtls, "resetting DTLS due to local role change"); + + Reset(); + } + + // Update local role. + this->localRole = localRole; + + // Set state and notify the listener. + this->state = DtlsState::CONNECTING; + this->listener->OnDtlsTransportConnecting(this); + + switch (this->localRole) + { + case Role::CLIENT: + { + MS_DEBUG_TAG(dtls, "running [role:client]"); + + SSL_set_connect_state(this->ssl); + SSL_do_handshake(this->ssl); + SendPendingOutgoingDtlsData(); + SetTimeout(); + + break; + } + + case Role::SERVER: + { + MS_DEBUG_TAG(dtls, "running [role:server]"); + + SSL_set_accept_state(this->ssl); + SSL_do_handshake(this->ssl); + + break; + } + + default: + { + MS_ABORT("invalid local DTLS role"); + } + } + } + + bool DtlsTransport::SetRemoteFingerprint(Fingerprint fingerprint) + { + MS_TRACE(); + + MS_ASSERT( + fingerprint.algorithm != FingerprintAlgorithm::NONE, "no fingerprint algorithm provided"); + + this->remoteFingerprint = fingerprint; + + // The remote fingerpring may have been set after DTLS handshake was done, + // so we may need to process it now. + if (this->handshakeDone && this->state != DtlsState::CONNECTED) + { + MS_DEBUG_TAG(dtls, "handshake already done, processing it right now"); + + return ProcessHandshake(); + } + + return true; + } + + void DtlsTransport::ProcessDtlsData(const uint8_t* data, size_t len) + { + MS_TRACE(); + + int written; + int read; + + if (!IsRunning()) + { + MS_ERROR("cannot process data while not running"); + + return; + } + + // Write the received DTLS data into the sslBioFromNetwork. + written = + BIO_write(this->sslBioFromNetwork, static_cast(data), static_cast(len)); + + if (written != static_cast(len)) + { + MS_WARN_TAG( + dtls, + "OpenSSL BIO_write() wrote less (%zu bytes) than given data (%zu bytes)", + static_cast(written), + len); + } + + // Must call SSL_read() to process received DTLS data. + read = SSL_read(this->ssl, static_cast(DtlsTransport::sslReadBuffer), SslReadBufferSize); + + // Send data if it's ready. + SendPendingOutgoingDtlsData(); + + // Check SSL status and return if it is bad/closed. + if (!CheckStatus(read)) + return; + + // Set/update the DTLS timeout. + if (!SetTimeout()) + return; + + // Application data received. Notify to the listener. + if (read > 0) + { + // It is allowed to receive DTLS data even before validating remote fingerprint. + if (!this->handshakeDone) + { + MS_WARN_TAG(dtls, "ignoring application data received while DTLS handshake not done"); + + return; + } + + // Notify the listener. + this->listener->OnDtlsTransportApplicationDataReceived( + this, (uint8_t*)DtlsTransport::sslReadBuffer, static_cast(read)); + } + } + + void DtlsTransport::SendApplicationData(const uint8_t* data, size_t len) + { + MS_TRACE(); + + // We cannot send data to the peer if its remote fingerprint is not validated. + if (this->state != DtlsState::CONNECTED) + { + MS_WARN_TAG(dtls, "cannot send application data while DTLS is not fully connected"); + + return; + } + + if (len == 0) + { + MS_WARN_TAG(dtls, "ignoring 0 length data"); + + return; + } + + int written; + + written = SSL_write(this->ssl, static_cast(data), static_cast(len)); + + if (written < 0) + { + LOG_OPENSSL_ERROR("SSL_write() failed"); + + if (!CheckStatus(written)) + return; + } + else if (written != static_cast(len)) + { + MS_WARN_TAG( + dtls, "OpenSSL SSL_write() wrote less (%d bytes) than given data (%zu bytes)", written, len); + } + + // Send data. + SendPendingOutgoingDtlsData(); + } + + void DtlsTransport::Reset() + { + MS_TRACE(); + + int ret; + + if (!IsRunning()) + return; + + MS_WARN_TAG(dtls, "resetting DTLS transport"); + + // Stop the DTLS timer. + this->timer = nullptr; + + // We need to reset the SSL instance so we need to "shutdown" it, but we + // don't want to send a Close Alert to the peer, so just don't call + // SendPendingOutgoingDTLSData(). + SSL_shutdown(this->ssl); + + this->localRole = Role::NONE; + this->state = DtlsState::NEW; + this->handshakeDone = false; + this->handshakeDoneNow = false; + + // Reset SSL status. + // NOTE: For this to properly work, SSL_shutdown() must be called before. + // NOTE: This may fail if not enough DTLS handshake data has been received, + // but we don't care so just clear the error queue. + ret = SSL_clear(this->ssl); + + if (ret == 0) + ERR_clear_error(); + } + + inline bool DtlsTransport::CheckStatus(int returnCode) + { + MS_TRACE(); + + int err; + bool wasHandshakeDone = this->handshakeDone; + + err = SSL_get_error(this->ssl, returnCode); + + switch (err) + { + case SSL_ERROR_NONE: + break; + + case SSL_ERROR_SSL: + LOG_OPENSSL_ERROR("SSL status: SSL_ERROR_SSL"); + break; + + case SSL_ERROR_WANT_READ: + break; + + case SSL_ERROR_WANT_WRITE: + MS_WARN_TAG(dtls, "SSL status: SSL_ERROR_WANT_WRITE"); + break; + + case SSL_ERROR_WANT_X509_LOOKUP: + MS_DEBUG_TAG(dtls, "SSL status: SSL_ERROR_WANT_X509_LOOKUP"); + break; + + case SSL_ERROR_SYSCALL: + LOG_OPENSSL_ERROR("SSL status: SSL_ERROR_SYSCALL"); + break; + + case SSL_ERROR_ZERO_RETURN: + break; + + case SSL_ERROR_WANT_CONNECT: + MS_WARN_TAG(dtls, "SSL status: SSL_ERROR_WANT_CONNECT"); + break; + + case SSL_ERROR_WANT_ACCEPT: + MS_WARN_TAG(dtls, "SSL status: SSL_ERROR_WANT_ACCEPT"); + break; + + default: + MS_WARN_TAG(dtls, "SSL status: unknown error"); + } + + // Check if the handshake (or re-handshake) has been done right now. + if (this->handshakeDoneNow) + { + this->handshakeDoneNow = false; + this->handshakeDone = true; + + // Stop the timer. + this->timer = nullptr; + + // Process the handshake just once (ignore if DTLS renegotiation). + if (!wasHandshakeDone && this->remoteFingerprint.algorithm != FingerprintAlgorithm::NONE) + return ProcessHandshake(); + + return true; + } + // Check if the peer sent close alert or a fatal error happened. + else if (((SSL_get_shutdown(this->ssl) & SSL_RECEIVED_SHUTDOWN) != 0) || err == SSL_ERROR_SSL || err == SSL_ERROR_SYSCALL) + { + if (this->state == DtlsState::CONNECTED) + { + MS_DEBUG_TAG(dtls, "disconnected"); + + Reset(); + + // Set state and notify the listener. + this->state = DtlsState::CLOSED; + this->listener->OnDtlsTransportClosed(this); + } + else + { + MS_WARN_TAG(dtls, "connection failed"); + + Reset(); + + // Set state and notify the listener. + this->state = DtlsState::FAILED; + this->listener->OnDtlsTransportFailed(this); + } + + return false; + } + else + { + return true; + } + } + + inline void DtlsTransport::SendPendingOutgoingDtlsData() + { + MS_TRACE(); + + if (BIO_eof(this->sslBioToNetwork)) + return; + + int64_t read; + char* data{ nullptr }; + + read = BIO_get_mem_data(this->sslBioToNetwork, &data); // NOLINT + + if (read <= 0) + return; + + MS_DEBUG_DEV("%" PRIu64 " bytes of DTLS data ready to sent to the peer", read); + + // Notify the listener. + this->listener->OnDtlsTransportSendData( + this, reinterpret_cast(data), static_cast(read)); + + // Clear the BIO buffer. + // NOTE: the (void) avoids the -Wunused-value warning. + (void)BIO_reset(this->sslBioToNetwork); + } + + inline bool DtlsTransport::SetTimeout() + { + MS_TRACE(); + + MS_ASSERT( + this->state == DtlsState::CONNECTING || this->state == DtlsState::CONNECTED, + "invalid DTLS state"); + + int64_t ret; + struct timeval dtlsTimeout{ 0, 0 }; + uint64_t timeoutMs; + + // NOTE: If ret == 0 then ignore the value in dtlsTimeout. + // NOTE: No DTLSv_1_2_get_timeout() or DTLS_get_timeout() in OpenSSL 1.1.0-dev. + ret = DTLSv1_get_timeout(this->ssl, static_cast(&dtlsTimeout)); // NOLINT + + if (ret == 0) + return true; + + timeoutMs = (dtlsTimeout.tv_sec * static_cast(1000)) + (dtlsTimeout.tv_usec / 1000); + + if (timeoutMs == 0) + { + return true; + } + else if (timeoutMs < 30000) + { + MS_DEBUG_DEV("DTLS timer set in %" PRIu64 "ms", timeoutMs); + + weak_ptr weak_self = shared_from_this(); + this->timer = std::make_shared(timeoutMs / 1000.0f, [weak_self](){ + auto strong_self = weak_self.lock(); + if(strong_self){ + strong_self->OnTimer(); + } + return true; + }, this->poller); + + return true; + } + // NOTE: Don't start the timer again if the timeout is greater than 30 seconds. + else + { + MS_WARN_TAG(dtls, "DTLS timeout too high (%" PRIu64 "ms), resetting DLTS", timeoutMs); + + Reset(); + + // Set state and notify the listener. + this->state = DtlsState::FAILED; + this->listener->OnDtlsTransportFailed(this); + + return false; + } + } + + inline bool DtlsTransport::ProcessHandshake() + { + MS_TRACE(); + + MS_ASSERT(this->handshakeDone, "handshake not done yet"); + MS_ASSERT( + this->remoteFingerprint.algorithm != FingerprintAlgorithm::NONE, "remote fingerprint not set"); + + // Validate the remote fingerprint. + if (!CheckRemoteFingerprint()) + { + Reset(); + + // Set state and notify the listener. + this->state = DtlsState::FAILED; + this->listener->OnDtlsTransportFailed(this); + + return false; + } + + // Get the negotiated SRTP crypto suite. + RTC::SrtpSession::CryptoSuite srtpCryptoSuite = GetNegotiatedSrtpCryptoSuite(); + + if (srtpCryptoSuite != RTC::SrtpSession::CryptoSuite::NONE) + { + // Extract the SRTP keys (will notify the listener with them). + ExtractSrtpKeys(srtpCryptoSuite); + + return true; + } + + // NOTE: We assume that "use_srtp" DTLS extension is required even if + // there is no audio/video. + MS_WARN_2TAGS(dtls, srtp, "SRTP crypto suite not negotiated"); + + Reset(); + + // Set state and notify the listener. + this->state = DtlsState::FAILED; + this->listener->OnDtlsTransportFailed(this); + + return false; + } + + inline bool DtlsTransport::CheckRemoteFingerprint() + { + MS_TRACE(); + + MS_ASSERT( + this->remoteFingerprint.algorithm != FingerprintAlgorithm::NONE, "remote fingerprint not set"); + + X509* certificate; + uint8_t binaryFingerprint[EVP_MAX_MD_SIZE]; + unsigned int size{ 0 }; + char hexFingerprint[(EVP_MAX_MD_SIZE * 3) + 1]; + const EVP_MD* hashFunction; + int ret; + + certificate = SSL_get_peer_certificate(this->ssl); + + if (!certificate) + { + MS_WARN_TAG(dtls, "no certificate was provided by the peer"); + + return false; + } + + switch (this->remoteFingerprint.algorithm) + { + case FingerprintAlgorithm::SHA1: + hashFunction = EVP_sha1(); + break; + + case FingerprintAlgorithm::SHA224: + hashFunction = EVP_sha224(); + break; + + case FingerprintAlgorithm::SHA256: + hashFunction = EVP_sha256(); + break; + + case FingerprintAlgorithm::SHA384: + hashFunction = EVP_sha384(); + break; + + case FingerprintAlgorithm::SHA512: + hashFunction = EVP_sha512(); + break; + + default: + MS_ABORT("unknown algorithm"); + } + + // Compare the remote fingerprint with the value given via signaling. + ret = X509_digest(certificate, hashFunction, binaryFingerprint, &size); + + if (ret == 0) + { + MS_ERROR("X509_digest() failed"); + + X509_free(certificate); + + return false; + } + + // Convert to hexadecimal format in uppercase with colons. + for (unsigned int i{ 0 }; i < size; ++i) + { + std::sprintf(hexFingerprint + (i * 3), "%.2X:", binaryFingerprint[i]); + } + hexFingerprint[(size * 3) - 1] = '\0'; + + if (this->remoteFingerprint.value != hexFingerprint) + { + MS_WARN_TAG( + dtls, + "fingerprint in the remote certificate (%s) does not match the announced one (%s)", + hexFingerprint, + this->remoteFingerprint.value.c_str()); + X509_free(certificate); + return false; + } + + MS_DEBUG_TAG(dtls, "valid remote fingerprint"); + + // Get the remote certificate in PEM format. + + BIO* bio = BIO_new(BIO_s_mem()); + + // Ensure the underlying BUF_MEM structure is also freed. + // NOTE: Avoid stupid "warning: value computed is not used [-Wunused-value]" since + // BIO_set_close() always returns 1. + (void)BIO_set_close(bio, BIO_CLOSE); + + ret = PEM_write_bio_X509(bio, certificate); + + if (ret != 1) + { + LOG_OPENSSL_ERROR("PEM_write_bio_X509() failed"); + + X509_free(certificate); + BIO_free(bio); + + return false; + } + + BUF_MEM* mem; + + BIO_get_mem_ptr(bio, &mem); // NOLINT[cppcoreguidelines-pro-type-cstyle-cast] + + if (!mem || !mem->data || mem->length == 0u) + { + LOG_OPENSSL_ERROR("BIO_get_mem_ptr() failed"); + + X509_free(certificate); + BIO_free(bio); + + return false; + } + + this->remoteCert = std::string(mem->data, mem->length); + + X509_free(certificate); + BIO_free(bio); + + return true; + } + + inline void DtlsTransport::ExtractSrtpKeys(RTC::SrtpSession::CryptoSuite srtpCryptoSuite) + { + MS_TRACE(); + + size_t srtpKeyLength{ 0 }; + size_t srtpSaltLength{ 0 }; + size_t srtpMasterLength{ 0 }; + + switch (srtpCryptoSuite) + { + case RTC::SrtpSession::CryptoSuite::AES_CM_128_HMAC_SHA1_80: + case RTC::SrtpSession::CryptoSuite::AES_CM_128_HMAC_SHA1_32: + { + srtpKeyLength = SrtpMasterKeyLength; + srtpSaltLength = SrtpMasterSaltLength; + srtpMasterLength = SrtpMasterLength; + + break; + } + + case RTC::SrtpSession::CryptoSuite::AEAD_AES_256_GCM: + { + srtpKeyLength = SrtpAesGcm256MasterKeyLength; + srtpSaltLength = SrtpAesGcm256MasterSaltLength; + srtpMasterLength = SrtpAesGcm256MasterLength; + + break; + } + + case RTC::SrtpSession::CryptoSuite::AEAD_AES_128_GCM: + { + srtpKeyLength = SrtpAesGcm128MasterKeyLength; + srtpSaltLength = SrtpAesGcm128MasterSaltLength; + srtpMasterLength = SrtpAesGcm128MasterLength; + + break; + } + + default: + { + MS_ABORT("unknown SRTP crypto suite"); + } + } + + auto* srtpMaterial = new uint8_t[srtpMasterLength * 2]; + uint8_t* srtpLocalKey{ nullptr }; + uint8_t* srtpLocalSalt{ nullptr }; + uint8_t* srtpRemoteKey{ nullptr }; + uint8_t* srtpRemoteSalt{ nullptr }; + auto* srtpLocalMasterKey = new uint8_t[srtpMasterLength]; + auto* srtpRemoteMasterKey = new uint8_t[srtpMasterLength]; + int ret; + + ret = SSL_export_keying_material( + this->ssl, srtpMaterial, srtpMasterLength * 2, "EXTRACTOR-dtls_srtp", 19, nullptr, 0, 0); + + MS_ASSERT(ret != 0, "SSL_export_keying_material() failed"); + + switch (this->localRole) + { + case Role::SERVER: + { + srtpRemoteKey = srtpMaterial; + srtpLocalKey = srtpRemoteKey + srtpKeyLength; + srtpRemoteSalt = srtpLocalKey + srtpKeyLength; + srtpLocalSalt = srtpRemoteSalt + srtpSaltLength; + + break; + } + + case Role::CLIENT: + { + srtpLocalKey = srtpMaterial; + srtpRemoteKey = srtpLocalKey + srtpKeyLength; + srtpLocalSalt = srtpRemoteKey + srtpKeyLength; + srtpRemoteSalt = srtpLocalSalt + srtpSaltLength; + + break; + } + + default: + { + MS_ABORT("no DTLS role set"); + } + } + + // Create the SRTP local master key. + std::memcpy(srtpLocalMasterKey, srtpLocalKey, srtpKeyLength); + std::memcpy(srtpLocalMasterKey + srtpKeyLength, srtpLocalSalt, srtpSaltLength); + // Create the SRTP remote master key. + std::memcpy(srtpRemoteMasterKey, srtpRemoteKey, srtpKeyLength); + std::memcpy(srtpRemoteMasterKey + srtpKeyLength, srtpRemoteSalt, srtpSaltLength); + + // Set state and notify the listener. + this->state = DtlsState::CONNECTED; + this->listener->OnDtlsTransportConnected( + this, + srtpCryptoSuite, + srtpLocalMasterKey, + srtpMasterLength, + srtpRemoteMasterKey, + srtpMasterLength, + this->remoteCert); + + delete[] srtpMaterial; + delete[] srtpLocalMasterKey; + delete[] srtpRemoteMasterKey; + } + + inline RTC::SrtpSession::CryptoSuite DtlsTransport::GetNegotiatedSrtpCryptoSuite() + { + MS_TRACE(); + + RTC::SrtpSession::CryptoSuite negotiatedSrtpCryptoSuite = RTC::SrtpSession::CryptoSuite::NONE; + + // Ensure that the SRTP crypto suite has been negotiated. + // NOTE: This is a OpenSSL type. + SRTP_PROTECTION_PROFILE* sslSrtpCryptoSuite = SSL_get_selected_srtp_profile(this->ssl); + + if (!sslSrtpCryptoSuite) + return negotiatedSrtpCryptoSuite; + + // Get the negotiated SRTP crypto suite. + for (auto& srtpCryptoSuite : DtlsTransport::srtpCryptoSuites) + { + SrtpCryptoSuiteMapEntry* cryptoSuiteEntry = std::addressof(srtpCryptoSuite); + + if (std::strcmp(sslSrtpCryptoSuite->name, cryptoSuiteEntry->name) == 0) + { + MS_DEBUG_2TAGS(dtls, srtp, "chosen SRTP crypto suite: %s", cryptoSuiteEntry->name); + + negotiatedSrtpCryptoSuite = cryptoSuiteEntry->cryptoSuite; + } + } + + MS_ASSERT( + negotiatedSrtpCryptoSuite != RTC::SrtpSession::CryptoSuite::NONE, + "chosen SRTP crypto suite is not an available one"); + + return negotiatedSrtpCryptoSuite; + } + + inline void DtlsTransport::OnSslInfo(int where, int ret) + { + MS_TRACE(); + + int w = where & -SSL_ST_MASK; + const char* role; + + if ((w & SSL_ST_CONNECT) != 0) + role = "client"; + else if ((w & SSL_ST_ACCEPT) != 0) + role = "server"; + else + role = "undefined"; + + if ((where & SSL_CB_LOOP) != 0) + { + MS_DEBUG_TAG(dtls, "[role:%s, action:'%s']", role, SSL_state_string_long(this->ssl)); + } + else if ((where & SSL_CB_ALERT) != 0) + { + const char* alertType; + + switch (*SSL_alert_type_string(ret)) + { + case 'W': + alertType = "warning"; + break; + + case 'F': + alertType = "fatal"; + break; + + default: + alertType = "undefined"; + } + + if ((where & SSL_CB_READ) != 0) + { + MS_WARN_TAG(dtls, "received DTLS %s alert: %s", alertType, SSL_alert_desc_string_long(ret)); + } + else if ((where & SSL_CB_WRITE) != 0) + { + MS_DEBUG_TAG(dtls, "sending DTLS %s alert: %s", alertType, SSL_alert_desc_string_long(ret)); + } + else + { + MS_DEBUG_TAG(dtls, "DTLS %s alert: %s", alertType, SSL_alert_desc_string_long(ret)); + } + } + else if ((where & SSL_CB_EXIT) != 0) + { + if (ret == 0) + MS_DEBUG_TAG(dtls, "[role:%s, failed:'%s']", role, SSL_state_string_long(this->ssl)); + else if (ret < 0) + MS_DEBUG_TAG(dtls, "role: %s, waiting:'%s']", role, SSL_state_string_long(this->ssl)); + } + else if ((where & SSL_CB_HANDSHAKE_START) != 0) + { + MS_DEBUG_TAG(dtls, "DTLS handshake start"); + } + else if ((where & SSL_CB_HANDSHAKE_DONE) != 0) + { + MS_DEBUG_TAG(dtls, "DTLS handshake done"); + + this->handshakeDoneNow = true; + } + + // NOTE: checking SSL_get_shutdown(this->ssl) & SSL_RECEIVED_SHUTDOWN here upon + // receipt of a close alert does not work (the flag is set after this callback). + } + + inline void DtlsTransport::OnTimer() + { + MS_TRACE(); + + // Workaround for https://github.com/openssl/openssl/issues/7998. + if (this->handshakeDone) + { + MS_DEBUG_DEV("handshake is done so return"); + + return; + } + + DTLSv1_handle_timeout(this->ssl); + + // If required, send DTLS data. + SendPendingOutgoingDtlsData(); + + // Set the DTLS timer again. + SetTimeout(); + } +} // namespace RTC diff --git a/webrtc/DtlsTransport.hpp b/webrtc/DtlsTransport.hpp new file mode 100644 index 00000000..fb28a6a4 --- /dev/null +++ b/webrtc/DtlsTransport.hpp @@ -0,0 +1,254 @@ +/** +ISC License + +Copyright © 2015, Iñaki Baz Castillo + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MS_RTC_DTLS_TRANSPORT_HPP +#define MS_RTC_DTLS_TRANSPORT_HPP + +#include "SrtpSession.hpp" +#include +#include +#include +#include +#include +#include +#include "Poller/Timer.h" +#include "Poller/EventPoller.h" +using namespace toolkit; + +namespace RTC +{ + class DtlsTransport : public std::enable_shared_from_this + { + public: + enum class DtlsState + { + NEW = 1, + CONNECTING, + CONNECTED, + FAILED, + CLOSED + }; + + public: + enum class Role + { + NONE = 0, + AUTO = 1, + CLIENT, + SERVER + }; + + public: + enum class FingerprintAlgorithm + { + NONE = 0, + SHA1 = 1, + SHA224, + SHA256, + SHA384, + SHA512 + }; + + public: + struct Fingerprint + { + FingerprintAlgorithm algorithm{ FingerprintAlgorithm::NONE }; + std::string value; + }; + + private: + struct SrtpCryptoSuiteMapEntry + { + RTC::SrtpSession::CryptoSuite cryptoSuite; + const char* name; + }; + + class DtlsEnvironment : public std::enable_shared_from_this + { + public: + using Ptr = std::shared_ptr; + ~DtlsEnvironment(); + static DtlsEnvironment& Instance(); + + private: + DtlsEnvironment(); + void GenerateCertificateAndPrivateKey(); + void ReadCertificateAndPrivateKeyFromFiles(); + void CreateSslCtx(); + void GenerateFingerprints(); + + public: + X509* certificate{ nullptr }; + EVP_PKEY* privateKey{ nullptr }; + SSL_CTX* sslCtx{ nullptr }; + std::vector localFingerprints; + }; + + public: + class Listener + { + public: + // DTLS is in the process of negotiating a secure connection. Incoming + // media can flow through. + // NOTE: The caller MUST NOT call any method during this callback. + virtual void OnDtlsTransportConnecting(const RTC::DtlsTransport* dtlsTransport) = 0; + // DTLS has completed negotiation of a secure connection (including DTLS-SRTP + // and remote fingerprint verification). Outgoing media can now flow through. + // NOTE: The caller MUST NOT call any method during this callback. + virtual void OnDtlsTransportConnected( + const RTC::DtlsTransport* dtlsTransport, + RTC::SrtpSession::CryptoSuite srtpCryptoSuite, + uint8_t* srtpLocalKey, + size_t srtpLocalKeyLen, + uint8_t* srtpRemoteKey, + size_t srtpRemoteKeyLen, + std::string& remoteCert) = 0; + // The DTLS connection has been closed as the result of an error (such as a + // DTLS alert or a failure to validate the remote fingerprint). + virtual void OnDtlsTransportFailed(const RTC::DtlsTransport* dtlsTransport) = 0; + // The DTLS connection has been closed due to receipt of a close_notify alert. + virtual void OnDtlsTransportClosed(const RTC::DtlsTransport* dtlsTransport) = 0; + // Need to send DTLS data to the peer. + virtual void OnDtlsTransportSendData( + const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; + // DTLS application data received. + virtual void OnDtlsTransportApplicationDataReceived( + const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; + }; + + public: + static Role StringToRole(const std::string& role) + { + auto it = DtlsTransport::string2Role.find(role); + + if (it != DtlsTransport::string2Role.end()) + return it->second; + else + return DtlsTransport::Role::NONE; + } + static FingerprintAlgorithm GetFingerprintAlgorithm(const std::string& fingerprint) + { + auto it = DtlsTransport::string2FingerprintAlgorithm.find(fingerprint); + + if (it != DtlsTransport::string2FingerprintAlgorithm.end()) + return it->second; + else + return DtlsTransport::FingerprintAlgorithm::NONE; + } + static std::string& GetFingerprintAlgorithmString(FingerprintAlgorithm fingerprint) + { + auto it = DtlsTransport::fingerprintAlgorithm2String.find(fingerprint); + + return it->second; + } + static bool IsDtls(const uint8_t* data, size_t len) + { + // clang-format off + return ( + // Minimum DTLS record length is 13 bytes. + (len >= 13) && + // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes + (data[0] > 19 && data[0] < 64) + ); + // clang-format on + } + + private: + static std::map string2Role; + static std::map string2FingerprintAlgorithm; + static std::map fingerprintAlgorithm2String; + static std::vector srtpCryptoSuites; + + public: + DtlsTransport(EventPoller::Ptr poller, Listener* listener); + ~DtlsTransport(); + + public: + void Dump() const; + void Run(Role localRole); + std::vector& GetLocalFingerprints() const + { + return env->localFingerprints; + } + bool SetRemoteFingerprint(Fingerprint fingerprint); + void ProcessDtlsData(const uint8_t* data, size_t len); + DtlsState GetState() const + { + return this->state; + } + Role GetLocalRole() const + { + return this->localRole; + } + void SendApplicationData(const uint8_t* data, size_t len); + + private: + bool IsRunning() const + { + switch (this->state) + { + case DtlsState::NEW: + return false; + case DtlsState::CONNECTING: + case DtlsState::CONNECTED: + return true; + case DtlsState::FAILED: + case DtlsState::CLOSED: + return false; + } + + // Make GCC 4.9 happy. + return false; + } + void Reset(); + bool CheckStatus(int returnCode); + void SendPendingOutgoingDtlsData(); + bool SetTimeout(); + bool ProcessHandshake(); + bool CheckRemoteFingerprint(); + void ExtractSrtpKeys(RTC::SrtpSession::CryptoSuite srtpCryptoSuite); + RTC::SrtpSession::CryptoSuite GetNegotiatedSrtpCryptoSuite(); + + private: + void OnSslInfo(int where, int ret); + void OnTimer(); + + private: + DtlsEnvironment::Ptr env; + EventPoller::Ptr poller; + // Passed by argument. + Listener* listener{ nullptr }; + // Allocated by this. + SSL* ssl{ nullptr }; + BIO* sslBioFromNetwork{ nullptr }; // The BIO from which ssl reads. + BIO* sslBioToNetwork{ nullptr }; // The BIO in which ssl writes. + Timer::Ptr timer; + // Others. + DtlsState state{ DtlsState::NEW }; + Role localRole{ Role::NONE }; + Fingerprint remoteFingerprint; + bool handshakeDone{ false }; + bool handshakeDoneNow{ false }; + std::string remoteCert; + //最大不超过mtu + static constexpr int SslReadBufferSize{ 2000 }; + uint8_t sslReadBuffer[SslReadBufferSize]; +}; +} // namespace RTC + +#endif diff --git a/webrtc/IceServer.cpp b/webrtc/IceServer.cpp new file mode 100644 index 00000000..c976bcf0 --- /dev/null +++ b/webrtc/IceServer.cpp @@ -0,0 +1,526 @@ +/** +ISC License + +Copyright © 2015, Iñaki Baz Castillo + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define MS_CLASS "RTC::IceServer" +// #define MS_LOG_DEV_LEVEL 3 + +#include +#include "IceServer.hpp" + +namespace RTC +{ + /* Static. */ + /* Instance methods. */ + + IceServer::IceServer(Listener* listener, const std::string& usernameFragment, const std::string& password) + : listener(listener), usernameFragment(usernameFragment), password(password) + { + MS_TRACE(); + } + + void IceServer::ProcessStunPacket(RTC::StunPacket* packet, RTC::TransportTuple* tuple) + { + MS_TRACE(); + + // Must be a Binding method. + if (packet->GetMethod() != RTC::StunPacket::Method::BINDING) + { + if (packet->GetClass() == RTC::StunPacket::Class::REQUEST) + { + MS_WARN_TAG( + ice, + "unknown method %#.3x in STUN Request => 400", + static_cast(packet->GetMethod())); + + // Reply 400. + RTC::StunPacket* response = packet->CreateErrorResponse(400); + + response->Serialize(StunSerializeBuffer); + this->listener->OnIceServerSendStunPacket(this, response, tuple); + + delete response; + } + else + { + MS_WARN_TAG( + ice, + "ignoring STUN Indication or Response with unknown method %#.3x", + static_cast(packet->GetMethod())); + } + + return; + } + + // Must use FINGERPRINT (optional for ICE STUN indications). + if (!packet->HasFingerprint() && packet->GetClass() != RTC::StunPacket::Class::INDICATION) + { + if (packet->GetClass() == RTC::StunPacket::Class::REQUEST) + { + MS_WARN_TAG(ice, "STUN Binding Request without FINGERPRINT => 400"); + + // Reply 400. + RTC::StunPacket* response = packet->CreateErrorResponse(400); + + response->Serialize(StunSerializeBuffer); + this->listener->OnIceServerSendStunPacket(this, response, tuple); + + delete response; + } + else + { + MS_WARN_TAG(ice, "ignoring STUN Binding Response without FINGERPRINT"); + } + + return; + } + + switch (packet->GetClass()) + { + case RTC::StunPacket::Class::REQUEST: + { + // USERNAME, MESSAGE-INTEGRITY and PRIORITY are required. + if (!packet->HasMessageIntegrity() || (packet->GetPriority() == 0u) || packet->GetUsername().empty()) + { + MS_WARN_TAG(ice, "mising required attributes in STUN Binding Request => 400"); + + // Reply 400. + RTC::StunPacket* response = packet->CreateErrorResponse(400); + + response->Serialize(StunSerializeBuffer); + this->listener->OnIceServerSendStunPacket(this, response, tuple); + + delete response; + + return; + } + + // Check authentication. + switch (packet->CheckAuthentication(this->usernameFragment, this->password)) + { + case RTC::StunPacket::Authentication::OK: + { + if (!this->oldPassword.empty()) + { + MS_DEBUG_TAG(ice, "new ICE credentials applied"); + + this->oldUsernameFragment.clear(); + this->oldPassword.clear(); + } + + break; + } + + case RTC::StunPacket::Authentication::UNAUTHORIZED: + { + // We may have changed our usernameFragment and password, so check + // the old ones. + // clang-format off + if ( + !this->oldUsernameFragment.empty() && + !this->oldPassword.empty() && + packet->CheckAuthentication(this->oldUsernameFragment, this->oldPassword) == RTC::StunPacket::Authentication::OK + ) + // clang-format on + { + MS_DEBUG_TAG(ice, "using old ICE credentials"); + + break; + } + + MS_WARN_TAG(ice, "wrong authentication in STUN Binding Request => 401"); + + // Reply 401. + RTC::StunPacket* response = packet->CreateErrorResponse(401); + + response->Serialize(StunSerializeBuffer); + this->listener->OnIceServerSendStunPacket(this, response, tuple); + + delete response; + + return; + } + + case RTC::StunPacket::Authentication::BAD_REQUEST: + { + MS_WARN_TAG(ice, "cannot check authentication in STUN Binding Request => 400"); + + // Reply 400. + RTC::StunPacket* response = packet->CreateErrorResponse(400); + + response->Serialize(StunSerializeBuffer); + this->listener->OnIceServerSendStunPacket(this, response, tuple); + + delete response; + + return; + } + } + +#if 0 + // The remote peer must be ICE controlling. + if (packet->GetIceControlled()) + { + MS_WARN_TAG(ice, "peer indicates ICE-CONTROLLED in STUN Binding Request => 487"); + + // Reply 487 (Role Conflict). + RTC::StunPacket* response = packet->CreateErrorResponse(487); + + response->Serialize(StunSerializeBuffer); + this->listener->OnIceServerSendStunPacket(this, response, tuple); + + delete response; + + return; + } + +#endif + + MS_DEBUG_DEV( + "processing STUN Binding Request [Priority:%" PRIu32 ", UseCandidate:%s]", + static_cast(packet->GetPriority()), + packet->HasUseCandidate() ? "true" : "false"); + + // Create a success response. + RTC::StunPacket* response = packet->CreateSuccessResponse(); + + // Add XOR-MAPPED-ADDRESS. + response->SetXorMappedAddress(tuple); + + // Authenticate the response. + if (this->oldPassword.empty()) + response->Authenticate(this->password); + else + response->Authenticate(this->oldPassword); + + // Send back. + response->Serialize(StunSerializeBuffer); + this->listener->OnIceServerSendStunPacket(this, response, tuple); + + delete response; + + // Handle the tuple. + HandleTuple(tuple, packet->HasUseCandidate()); + + break; + } + + case RTC::StunPacket::Class::INDICATION: + { + MS_DEBUG_TAG(ice, "STUN Binding Indication processed"); + + break; + } + + case RTC::StunPacket::Class::SUCCESS_RESPONSE: + { + MS_DEBUG_TAG(ice, "STUN Binding Success Response processed"); + + break; + } + + case RTC::StunPacket::Class::ERROR_RESPONSE: + { + MS_DEBUG_TAG(ice, "STUN Binding Error Response processed"); + + break; + } + } + } + + bool IceServer::IsValidTuple(const RTC::TransportTuple* tuple) const + { + MS_TRACE(); + + return HasTuple(tuple) != nullptr; + } + + void IceServer::RemoveTuple(RTC::TransportTuple* tuple) + { + MS_TRACE(); + + RTC::TransportTuple* removedTuple{ nullptr }; + + // Find the removed tuple. + auto it = this->tuples.begin(); + + for (; it != this->tuples.end(); ++it) + { + RTC::TransportTuple* storedTuple = std::addressof(*it); + + if (memcmp(storedTuple, tuple, sizeof (RTC::TransportTuple)) == 0) + { + removedTuple = storedTuple; + + break; + } + } + + // If not found, ignore. + if (!removedTuple) + return; + + // Remove from the list of tuples. + this->tuples.erase(it); + + // If this is not the selected tuple, stop here. + if (removedTuple != this->selectedTuple) + return; + + // Otherwise this was the selected tuple. + this->selectedTuple = nullptr; + + // Mark the first tuple as selected tuple (if any). + if (this->tuples.begin() != this->tuples.end()) + { + SetSelectedTuple(std::addressof(*this->tuples.begin())); + } + // Or just emit 'disconnected'. + else + { + // Update state. + this->state = IceState::DISCONNECTED; + // Notify the listener. + this->listener->OnIceServerDisconnected(this); + } + } + + void IceServer::ForceSelectedTuple(const RTC::TransportTuple* tuple) + { + MS_TRACE(); + + MS_ASSERT( + this->selectedTuple, "cannot force the selected tuple if there was not a selected tuple"); + + auto* storedTuple = HasTuple(tuple); + + MS_ASSERT( + storedTuple, + "cannot force the selected tuple if the given tuple was not already a valid tuple"); + + // Mark it as selected tuple. + SetSelectedTuple(storedTuple); + } + + void IceServer::HandleTuple(RTC::TransportTuple* tuple, bool hasUseCandidate) + { + MS_TRACE(); + + switch (this->state) + { + case IceState::NEW: + { + // There should be no tuples. + MS_ASSERT( + this->tuples.empty(), "state is 'new' but there are %zu tuples", this->tuples.size()); + + // There shouldn't be a selected tuple. + MS_ASSERT(!this->selectedTuple, "state is 'new' but there is selected tuple"); + + if (!hasUseCandidate) + { + MS_DEBUG_TAG(ice, "transition from state 'new' to 'connected'"); + + // Store the tuple. + auto* storedTuple = AddTuple(tuple); + + // Mark it as selected tuple. + SetSelectedTuple(storedTuple); + // Update state. + this->state = IceState::CONNECTED; + // Notify the listener. + this->listener->OnIceServerConnected(this); + } + else + { + MS_DEBUG_TAG(ice, "transition from state 'new' to 'completed'"); + + // Store the tuple. + auto* storedTuple = AddTuple(tuple); + + // Mark it as selected tuple. + SetSelectedTuple(storedTuple); + // Update state. + this->state = IceState::COMPLETED; + // Notify the listener. + this->listener->OnIceServerCompleted(this); + } + + break; + } + + case IceState::DISCONNECTED: + { + // There should be no tuples. + MS_ASSERT( + this->tuples.empty(), + "state is 'disconnected' but there are %zu tuples", + this->tuples.size()); + + // There shouldn't be a selected tuple. + MS_ASSERT(!this->selectedTuple, "state is 'disconnected' but there is selected tuple"); + + if (!hasUseCandidate) + { + MS_DEBUG_TAG(ice, "transition from state 'disconnected' to 'connected'"); + + // Store the tuple. + auto* storedTuple = AddTuple(tuple); + + // Mark it as selected tuple. + SetSelectedTuple(storedTuple); + // Update state. + this->state = IceState::CONNECTED; + // Notify the listener. + this->listener->OnIceServerConnected(this); + } + else + { + MS_DEBUG_TAG(ice, "transition from state 'disconnected' to 'completed'"); + + // Store the tuple. + auto* storedTuple = AddTuple(tuple); + + // Mark it as selected tuple. + SetSelectedTuple(storedTuple); + // Update state. + this->state = IceState::COMPLETED; + // Notify the listener. + this->listener->OnIceServerCompleted(this); + } + + break; + } + + case IceState::CONNECTED: + { + // There should be some tuples. + MS_ASSERT(!this->tuples.empty(), "state is 'connected' but there are no tuples"); + + // There should be a selected tuple. + MS_ASSERT(this->selectedTuple, "state is 'connected' but there is not selected tuple"); + + if (!hasUseCandidate) + { + // If a new tuple store it. + if (!HasTuple(tuple)) + AddTuple(tuple); + } + else + { + MS_DEBUG_TAG(ice, "transition from state 'connected' to 'completed'"); + + auto* storedTuple = HasTuple(tuple); + + // If a new tuple store it. + if (!storedTuple) + storedTuple = AddTuple(tuple); + + // Mark it as selected tuple. + SetSelectedTuple(storedTuple); + // Update state. + this->state = IceState::COMPLETED; + // Notify the listener. + this->listener->OnIceServerCompleted(this); + } + + break; + } + + case IceState::COMPLETED: + { + // There should be some tuples. + MS_ASSERT(!this->tuples.empty(), "state is 'completed' but there are no tuples"); + + // There should be a selected tuple. + MS_ASSERT(this->selectedTuple, "state is 'completed' but there is not selected tuple"); + + if (!hasUseCandidate) + { + // If a new tuple store it. + if (!HasTuple(tuple)) + AddTuple(tuple); + } + else + { + auto* storedTuple = HasTuple(tuple); + + // If a new tuple store it. + if (!storedTuple) + storedTuple = AddTuple(tuple); + + // Mark it as selected tuple. + SetSelectedTuple(storedTuple); + } + + break; + } + } + } + + inline RTC::TransportTuple* IceServer::AddTuple(RTC::TransportTuple* tuple) + { + MS_TRACE(); + + // Add the new tuple at the beginning of the list. + this->tuples.push_front(*tuple); + + auto* storedTuple = std::addressof(*this->tuples.begin()); + + // Return the address of the inserted tuple. + return storedTuple; + } + + inline RTC::TransportTuple* IceServer::HasTuple(const RTC::TransportTuple* tuple) const + { + MS_TRACE(); + + // If there is no selected tuple yet then we know that the tuples list + // is empty. + if (!this->selectedTuple) + return nullptr; + + // Check the current selected tuple. + if (memcmp(selectedTuple, tuple, sizeof (RTC::TransportTuple)) == 0) + return this->selectedTuple; + + // Otherwise check other stored tuples. + for (const auto& it : this->tuples) + { + auto* storedTuple = const_cast(std::addressof(it)); + + if (memcmp(storedTuple, tuple, sizeof (RTC::TransportTuple)) == 0) + return storedTuple; + } + + return nullptr; + } + + inline void IceServer::SetSelectedTuple(RTC::TransportTuple* storedTuple) + { + MS_TRACE(); + + // If already the selected tuple do nothing. + if (storedTuple == this->selectedTuple) + return; + + this->selectedTuple = storedTuple; + + // Notify the listener. + this->listener->OnIceServerSelectedTuple(this, this->selectedTuple); + } +} // namespace RTC diff --git a/webrtc/IceServer.hpp b/webrtc/IceServer.hpp new file mode 100644 index 00000000..8b9742ad --- /dev/null +++ b/webrtc/IceServer.hpp @@ -0,0 +1,136 @@ +/** +ISC License + +Copyright © 2015, Iñaki Baz Castillo + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MS_RTC_ICE_SERVER_HPP +#define MS_RTC_ICE_SERVER_HPP + +#include "StunPacket.hpp" +#include "logger.h" +#include "Utils.hpp" +#include +#include +#include +#include + +using _TransportTuple = struct sockaddr; + +namespace RTC +{ + using TransportTuple = _TransportTuple; + class IceServer + { + public: + enum class IceState + { + NEW = 1, + CONNECTED, + COMPLETED, + DISCONNECTED + }; + + public: + class Listener + { + public: + virtual ~Listener() = default; + + public: + /** + * These callbacks are guaranteed to be called before ProcessStunPacket() + * returns, so the given pointers are still usable. + */ + virtual void OnIceServerSendStunPacket( + const RTC::IceServer* iceServer, const RTC::StunPacket* packet, RTC::TransportTuple* tuple) = 0; + virtual void OnIceServerSelectedTuple( + const RTC::IceServer* iceServer, RTC::TransportTuple* tuple) = 0; + virtual void OnIceServerConnected(const RTC::IceServer* iceServer) = 0; + virtual void OnIceServerCompleted(const RTC::IceServer* iceServer) = 0; + virtual void OnIceServerDisconnected(const RTC::IceServer* iceServer) = 0; + }; + + public: + IceServer(Listener* listener, const std::string& usernameFragment, const std::string& password); + + public: + void ProcessStunPacket(RTC::StunPacket* packet, RTC::TransportTuple* tuple); + const std::string& GetUsernameFragment() const + { + return this->usernameFragment; + } + const std::string& GetPassword() const + { + return this->password; + } + IceState GetState() const + { + return this->state; + } + RTC::TransportTuple* GetSelectedTuple() const + { + return this->selectedTuple; + } + void SetUsernameFragment(const std::string& usernameFragment) + { + this->oldUsernameFragment = this->usernameFragment; + this->usernameFragment = usernameFragment; + } + void SetPassword(const std::string& password) + { + this->oldPassword = this->password; + this->password = password; + } + bool IsValidTuple(const RTC::TransportTuple* tuple) const; + void RemoveTuple(RTC::TransportTuple* tuple); + // This should be just called in 'connected' or completed' state + // and the given tuple must be an already valid tuple. + void ForceSelectedTuple(const RTC::TransportTuple* tuple); + + private: + void HandleTuple(RTC::TransportTuple* tuple, bool hasUseCandidate); + /** + * Store the given tuple and return its stored address. + */ + RTC::TransportTuple* AddTuple(RTC::TransportTuple* tuple); + /** + * If the given tuple exists return its stored address, nullptr otherwise. + */ + RTC::TransportTuple* HasTuple(const RTC::TransportTuple* tuple) const; + /** + * Set the given tuple as the selected tuple. + * NOTE: The given tuple MUST be already stored within the list. + */ + void SetSelectedTuple(RTC::TransportTuple* storedTuple); + + private: + // Passed by argument. + Listener* listener{ nullptr }; + // Others. + std::string usernameFragment; + std::string password; + std::string oldUsernameFragment; + std::string oldPassword; + IceState state{ IceState::NEW }; + std::list tuples; + RTC::TransportTuple* selectedTuple{ nullptr }; + //最大不超过mtu + static constexpr size_t StunSerializeBufferSize{ 1600 }; + uint8_t StunSerializeBuffer[StunSerializeBufferSize]; + }; +} // namespace RTC + +#endif diff --git a/webrtc/RtpExt.cpp b/webrtc/RtpExt.cpp new file mode 100644 index 00000000..dd9a1e2e --- /dev/null +++ b/webrtc/RtpExt.cpp @@ -0,0 +1,564 @@ +/* + * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#include "RtpExt.h" +#include "Sdp.h" + +#if defined(_WIN32) +#pragma pack(push, 1) +#endif // defined(_WIN32) + +//https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01 +//https://tools.ietf.org/html/rfc5285 + +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | 0xBE | 0xDE | length=3 | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | ID | L=0 | data | ID | L=1 | data... +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// ...data | 0 (pad) | 0 (pad) | ID | L=3 | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | data | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +class RtpExtOneByte { +public: + static constexpr uint16_t kMinSize = 1; + size_t getSize() const; + uint8_t getId() const; + void setId(uint8_t id); + uint8_t* getData(); + +private: +#if __BYTE_ORDER == __BIG_ENDIAN + uint8_t id: 4; + uint8_t len: 4; +#else + uint8_t len: 4; + uint8_t id: 4; +#endif + uint8_t data[1]; +} PACKED; + +//0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | 0x100 |appbits| length=3 | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | ID | L=0 | ID | L=1 | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | data | 0 (pad) | ID | L=4 | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | data | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +class RtpExtTwoByte { +public: + static constexpr uint16_t kMinSize = 2; + + size_t getSize() const; + uint8_t getId() const; + void setId(uint8_t id); + uint8_t* getData(); + +private: + uint8_t id; + uint8_t len; + uint8_t data[1]; +} PACKED; + +#if defined(_WIN32) +#pragma pack(pop) +#endif // defined(_WIN32) + +////////////////////////////////////////////////////////////////// + +size_t RtpExtOneByte::getSize() const { + return len + 1; +} + +uint8_t RtpExtOneByte::getId() const { + return id; +} + +void RtpExtOneByte::setId(uint8_t in) { + id = in & 0x0F; +} + +uint8_t *RtpExtOneByte::getData() { + return data; +} + +////////////////////////////////////////////////////////////////// + +size_t RtpExtTwoByte::getSize() const { + return len; +} + +uint8_t RtpExtTwoByte::getId() const { + return id; +} + +void RtpExtTwoByte::setId(uint8_t in) { + id = in; +} + +uint8_t *RtpExtTwoByte::getData() { + return data; +} + +////////////////////////////////////////////////////////////////// + +static constexpr uint16_t kOneByteHeader = 0xBEDE; +static constexpr uint16_t kTwoByteHeader = 0x1000; + +template +static bool isOneByteExt(){ + return false; +} + +template<> +bool isOneByteExt(){ + return true; +} + +template +void appendExt(map &ret, uint8_t *ptr, const uint8_t *end) { + while (ptr < end) { + auto ext = reinterpret_cast(ptr); + if (ext->getId() == (uint8_t) RtpExtType::padding) { + //padding,忽略 + ++ptr; + continue; + } + //15类型的rtp ext为保留 + CHECK(ext->getId() < (uint8_t) RtpExtType::reserved); + CHECK(reinterpret_cast(ext) + Type::kMinSize <= end); + CHECK(ext->getData() + ext->getSize() <= end); + ret.emplace(ext->getId(), RtpExt(ext, isOneByteExt(), reinterpret_cast(ext->getData()), ext->getSize())); + ptr += Type::kMinSize + ext->getSize(); + } +} + +RtpExt::RtpExt(void *ext, bool one_byte_ext, const char *str, size_t size) { + _ext = ext; + _one_byte_ext = one_byte_ext; + _data = str; + _size = size; +} + +const char *RtpExt::data() const { + return _data; +} + +size_t RtpExt::size() const { + return _size; +} + +const char& RtpExt::operator[](size_t pos) const{ + CHECK(pos < _size); + return _data[pos]; +} + +RtpExt::operator std::string() const{ + return string(_data, _size); +} + +map RtpExt::getExtValue(const RtpHeader *header) { + map ret; + assert(header); + auto ext_size = header->getExtSize(); + if (!ext_size) { + return ret; + } + auto reserved = header->getExtReserved(); + auto ptr = const_cast(header)->getExtData(); + auto end = ptr + ext_size; + if (reserved == kOneByteHeader) { + appendExt(ret, ptr, end); + return ret; + } + if ((reserved & 0xFFF0) >> 4 == kTwoByteHeader) { + appendExt(ret, ptr, end); + return ret; + } + return ret; +} + +#define RTP_EXT_MAP(XX) \ + XX(ssrc_audio_level, "urn:ietf:params:rtp-hdrext:ssrc-audio-level") \ + XX(abs_send_time, "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time") \ + XX(transport_cc, "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01") \ + XX(sdes_mid, "urn:ietf:params:rtp-hdrext:sdes:mid") \ + XX(sdes_rtp_stream_id, "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id") \ + XX(sdes_repaired_rtp_stream_id, "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id") \ + XX(video_timing, "http://www.webrtc.org/experiments/rtp-hdrext/video-timing") \ + XX(color_space, "http://www.webrtc.org/experiments/rtp-hdrext/color-space") \ + XX(csrc_audio_level, "urn:ietf:params:rtp-hdrext:csrc-audio-level") \ + XX(framemarking, "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07") \ + XX(video_content_type, "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type") \ + XX(playout_delay, "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay") \ + XX(video_orientation, "urn:3gpp:video-orientation") \ + XX(toffset, "urn:ietf:params:rtp-hdrext:toffset") \ + XX(encrypt, "urn:ietf:params:rtp-hdrext:encrypt") + +#define XX(type, url) {RtpExtType::type , url}, +static map s_type_to_url = {RTP_EXT_MAP(XX)}; +#undef XX + + +#define XX(type, url) {url, RtpExtType::type}, +static unordered_map s_url_to_type = {RTP_EXT_MAP(XX)}; +#undef XX + +RtpExtType RtpExt::getExtType(const string &url) { + auto it = s_url_to_type.find(url); + if (it == s_url_to_type.end()) { + throw std::invalid_argument(string("未识别的rtp ext url类型:") + url); + } + return it->second; +} + +const string &RtpExt::getExtUrl(RtpExtType type) { + auto it = s_type_to_url.find(type); + if (it == s_type_to_url.end()) { + throw std::invalid_argument(string("未识别的rtp ext类型:") + to_string((int) type)); + } + return it->second; +} + +const char *RtpExt::getExtName(RtpExtType type) { +#define XX(type, url) case RtpExtType::type: return #type; + switch (type) { + RTP_EXT_MAP(XX) + default: return "unknown ext type"; + } +#undef XX +} + +string RtpExt::dumpString() const { + _StrPrinter printer; + switch (_type) { + case RtpExtType::ssrc_audio_level : { + bool vad; + printer << "audio level:" << (int) getAudioLevel(&vad) << ", vad:" << vad; + break; + } + case RtpExtType::abs_send_time : { + printer << "abs send time:" << getAbsSendTime(); + break; + } + case RtpExtType::transport_cc : { + printer << "twcc seq:" << getTransportCCSeq(); + break; + } + case RtpExtType::sdes_mid : { + printer << "sdes mid:" << getSdesMid(); + break; + } + case RtpExtType::sdes_rtp_stream_id : { + printer << "rtp stream id:" << getRtpStreamId(); + break; + } + case RtpExtType::sdes_repaired_rtp_stream_id : { + printer << "rtp repaired stream id:" << getRepairedRtpStreamId(); + break; + } + case RtpExtType::video_timing : { + uint8_t flags; + uint16_t encode_start, encode_finish, packetization_complete, last_pkt_left_pacer, reserved_net0, reserved_net1; + getVideoTiming(flags, encode_start, encode_finish, packetization_complete, last_pkt_left_pacer, + reserved_net0, reserved_net1); + printer << "video timing, flags:" << (int) flags + << ",encode:" << encode_start << "-" << encode_finish + << ",packetization_complete:" << packetization_complete + << ",last_pkt_left_pacer:" << last_pkt_left_pacer + << ",reserved_net0:" << reserved_net0 + << ",reserved_net1:" << reserved_net1; + break; + } + case RtpExtType::video_content_type : { + printer << "video content type:" << (int)getVideoContentType(); + break; + } + case RtpExtType::video_orientation : { + bool camera_bit, flip_bit, first_rotation, second_rotation; + getVideoOrientation(camera_bit, flip_bit, first_rotation, second_rotation); + printer << "video orientation:" << camera_bit << "-" << flip_bit << "-" << first_rotation << "-" << second_rotation; + break; + } + case RtpExtType::playout_delay : { + uint16_t min_delay, max_delay; + getPlayoutDelay(min_delay, max_delay); + printer << "playout delay:" << min_delay << "-" << max_delay; + break; + } + case RtpExtType::toffset : { + printer << "toffset:" << getTransmissionOffset(); + break; + } + case RtpExtType::framemarking : { + printer << "framemarking tid:" << (int)getFramemarkingTID(); + break; + } + default: { + printer << getExtName(_type) << ", hex:" << hexdump(data(), size()); + break; + } + } + return std::move(printer); +} + +//https://tools.ietf.org/html/rfc6464 +// 0 1 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | ID | len=0 |V| level | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// Figure 1: Sample Audio Level Encoding Using the +// One-Byte Header Format +// +// +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | ID | len=1 |V| level | 0 (pad) | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// Figure 2: Sample Audio Level Encoding Using the +// Two-Byte Header Format +uint8_t RtpExt::getAudioLevel(bool *vad) const{ + CHECK(_type == RtpExtType::ssrc_audio_level && size() >= 1); + auto &byte = (*this)[0]; + if (vad) { + *vad = byte & 0x80; + } + return byte & 0x7F; +} + +//http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +//Wire format: 1-byte extension, 3 bytes of data. total 4 bytes extra per packet (plus shared 4 bytes for all extensions present: 2 byte magic word 0xBEDE, 2 byte # of extensions). Will in practice replace the “toffset” extension so we should see no long term increase in traffic as a result. +// +//Encoding: Timestamp is in seconds, 24 bit 6.18 fixed point, yielding 64s wraparound and 3.8us resolution (one increment for each 477 bytes going out on a 1Gbps interface). +// +//Relation to NTP timestamps: abs_send_time_24 = (ntp_timestamp_64 >> 14) & 0x00ffffff ; NTP timestamp is 32 bits for whole seconds, 32 bits fraction of second. +// +//Notes: Packets are time stamped when going out, preferably close to metal. Intermediate RTP relays (entities possibly altering the stream) should remove the extension or set its own timestamp. +uint32_t RtpExt::getAbsSendTime() const { + CHECK(_type == RtpExtType::abs_send_time && size() >= 3); + uint32_t ret = 0; + ret |= (*this)[0] << 16; + ret |= (*this)[1] << 8; + ret |= (*this)[2]; + return ret; +} + +//https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | 0xBE | 0xDE | length=1 | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | ID | L=1 |transport-wide sequence number | zero padding | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +uint16_t RtpExt::getTransportCCSeq() const { + CHECK(_type == RtpExtType::transport_cc && size() >= 2); + uint16_t ret; + ret = (*this)[0] << 8; + ret |= (*this)[1]; + return ret; +} + +//https://tools.ietf.org/html/draft-ietf-avtext-sdes-hdr-ext-07 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | ID | len | SDES Item text value ... | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +string RtpExt::getSdesMid() const { + CHECK(_type == RtpExtType::sdes_mid && size() >= 1); + return *this; +} + + +//https://tools.ietf.org/html/draft-ietf-avtext-rid-06 +//用于simulcast +//3.1. RTCP 'RtpStreamId' SDES Extension +// +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// |RtpStreamId=TBD| length | RtpStreamId ... +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// +// The RtpStreamId payload is UTF-8 encoded and is not null-terminated. +// +// RFC EDITOR NOTE: Please replace TBD with the assigned SDES +// identifier value. + +//3.2. RTCP 'RepairedRtpStreamId' SDES Extension +// +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// |Repaired...=TBD| length | RepairRtpStreamId ... +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// +// The RepairedRtpStreamId payload is UTF-8 encoded and is not null- +// terminated. +// +// RFC EDITOR NOTE: Please replace TBD with the assigned SDES +// identifier value. + +string RtpExt::getRtpStreamId() const { + CHECK(_type == RtpExtType::sdes_rtp_stream_id && size() >= 1); + return *this; +} + +string RtpExt::getRepairedRtpStreamId() const { + CHECK(_type == RtpExtType::sdes_repaired_rtp_stream_id && size() >= 1); + return *this; +} + + +//http://www.webrtc.org/experiments/rtp-hdrext/video-timing +//Wire format: 1-byte extension, 13 bytes of data. Total 14 bytes extra per packet (plus 1-3 padding byte in some cases, plus shared 4 bytes for all extensions present: 2 byte magic word 0xBEDE, 2 byte # of extensions). +// +//First byte is a flags field. Defined flags: +// +//0x01 - extension is set due to timer. +//0x02 - extension is set because the frame is larger than usual. +//Both flags may be set at the same time. All remaining 6 bits are reserved and should be ignored. +// +//Next, 6 timestamps are stored as 16-bit values in big-endian order, representing delta from the capture time of a packet in ms. Timestamps are, in order: +// +//Encode start. +//Encode finish. +//Packetization complete. +//Last packet left the pacer. +//Reserved for network. +//Reserved for network (2). + +void RtpExt::getVideoTiming(uint8_t &flags, + uint16_t &encode_start, + uint16_t &encode_finish, + uint16_t &packetization_complete, + uint16_t &last_pkt_left_pacer, + uint16_t &reserved_net0, + uint16_t &reserved_net1) const { + CHECK(_type == RtpExtType::video_timing && size() >= 13); + flags = (*this)[0]; + encode_start = (*this)[1] << 8 | (*this)[2]; + encode_finish = (*this)[3] << 8 | (*this)[4]; + packetization_complete = (*this)[5] << 8 | (*this)[6]; + last_pkt_left_pacer = (*this)[7] << 8 | (*this)[8]; + reserved_net0 = (*this)[9] << 8 | (*this)[10]; + reserved_net1 = (*this)[11] << 8 | (*this)[12]; +} + + +//http://www.webrtc.org/experiments/rtp-hdrext/color-space +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | ID | L = 3 | primaries | transfer | matrix | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// |range+chr.sit. | +// +-+-+-+-+-+-+-+-+ + + +//http://www.webrtc.org/experiments/rtp-hdrext/video-content-type +//Values: +//0x00: Unspecified. Default value. Treated the same as an absence of an extension. +//0x01: Screenshare. Video stream is of a screenshare type. +//0x02: 摄像头? +//Notes: Extension shoud be present only in the last packet of key-frames. +// If attached to other packets it should be ignored. +// If extension is absent, Unspecified value is assumed. +uint8_t RtpExt::getVideoContentType() const { + CHECK(_type == RtpExtType::video_content_type && size() >= 1); + return (*this)[0]; +} + +//http://www.3gpp.org/ftp/Specs/html-info/26114.htm +void RtpExt::getVideoOrientation(bool &camera_bit, bool &flip_bit, bool &first_rotation, bool &second_rotation) const { + CHECK(_type == RtpExtType::video_orientation && size() >= 1); + uint8_t byte = (*this)[0]; + camera_bit = (byte & 0x08) >> 3; + flip_bit = (byte & 0x04) >> 2; + first_rotation = (byte & 0x02) >> 1; + second_rotation = byte & 0x01; +} + +//http://www.webrtc.org/experiments/rtp-hdrext/playout-delay +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +//| ID | len=2 | MIN delay | MAX delay | +//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +void RtpExt::getPlayoutDelay(uint16_t &min_delay, uint16_t &max_delay) const { + CHECK(_type == RtpExtType::playout_delay && size() >= 3); + uint32_t bytes = (*this)[0] << 16 | (*this)[1] << 8 | (*this)[2]; + min_delay = (bytes & 0x00FFF000) >> 12; + max_delay = bytes & 0x00000FFF; +} + +//urn:ietf:params:rtp-hdrext:toffset +//https://tools.ietf.org/html/rfc5450 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | ID | len=2 | transmission offset | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +uint32_t RtpExt::getTransmissionOffset() const { + CHECK(_type == RtpExtType::toffset && size() >= 3); + return (*this)[0] << 16 | (*this)[1] << 8 | (*this)[2]; +} + +//http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07 +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | ID=? | L=2 |S|E|I|D|B| TID | LID | TL0PICIDX | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +uint8_t RtpExt::getFramemarkingTID() const { + CHECK(_type == RtpExtType::framemarking && size() >= 3); + return (*this)[0] & 0x07; +} + +void RtpExt::setExtId(uint8_t ext_id) { + assert(ext_id > (int) RtpExtType::padding && ext_id <= (int) RtpExtType::reserved && _ext); + if (_one_byte_ext) { + auto ptr = reinterpret_cast(_ext); + ptr->setId(ext_id); + } else { + auto ptr = reinterpret_cast(_ext); + ptr->setId(ext_id); + } +} + +void RtpExt::clearExt(){ + assert(_ext); + if (_one_byte_ext) { + auto ptr = reinterpret_cast(_ext); + memset(ptr, (int) RtpExtType::padding, RtpExtOneByte::kMinSize + ptr->getSize()); + } else { + auto ptr = reinterpret_cast(_ext); + memset(ptr, (int) RtpExtType::padding, RtpExtTwoByte::kMinSize + ptr->getSize()); + } +} + +void RtpExt::setType(RtpExtType type) { + _type = type; +} + +RtpExtType RtpExt::getType() const { + return _type; +} \ No newline at end of file diff --git a/webrtc/RtpExt.h b/webrtc/RtpExt.h new file mode 100644 index 00000000..9520bac6 --- /dev/null +++ b/webrtc/RtpExt.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef ZLMEDIAKIT_RTPEXT_H +#define ZLMEDIAKIT_RTPEXT_H + +#include +#include +#include +#include "Common/macros.h" +#include "Rtsp/Rtsp.h" + +using namespace std; +using namespace mediakit; + +enum class RtpExtType : uint8_t { + padding = 0, + ssrc_audio_level = 1, + abs_send_time = 2, + transport_cc = 3, + sdes_mid = 4, + sdes_rtp_stream_id = 5, + sdes_repaired_rtp_stream_id = 6, + video_timing = 7, + color_space = 8, + //for firefox + csrc_audio_level = 9, + //svc ? + framemarking = 10, + video_content_type = 11, + playout_delay = 12, + video_orientation = 13, + toffset = 14, + reserved = 15, + // e2e ? + encrypt = reserved +}; + +class RtcMedia; + +//使用次对象的方法前需保证RtpHeader内存未释放 +class RtpExt { +public: + template + friend void appendExt(map &ret, uint8_t *ptr, const uint8_t *end); + + ~RtpExt() = default; + + static map getExtValue(const RtpHeader *header); + static RtpExtType getExtType(const string &url); + static const string& getExtUrl(RtpExtType type); + static const char *getExtName(RtpExtType type); + + void setType(RtpExtType type); + RtpExtType getType() const; + string dumpString() const; + + uint8_t getAudioLevel(bool *vad) const; + uint32_t getAbsSendTime() const; + uint16_t getTransportCCSeq() const; + string getSdesMid() const; + string getRtpStreamId() const; + string getRepairedRtpStreamId() const; + + void getVideoTiming(uint8_t &flags, + uint16_t &encode_start, + uint16_t &encode_finish, + uint16_t &packetization_complete, + uint16_t &last_pkt_left_pacer, + uint16_t &reserved_net0, + uint16_t &reserved_net1) const; + + uint8_t getVideoContentType() const; + + void getVideoOrientation(bool &camera_bit, + bool &flip_bit, + bool &first_rotation, + bool &second_rotation) const; + + void getPlayoutDelay(uint16_t &min_delay, uint16_t &max_delay) const; + + uint32_t getTransmissionOffset() const; + + uint8_t getFramemarkingTID() const; + + void setExtId(uint8_t ext_id); + void clearExt(); + +private: + RtpExt(void *ptr, bool one_byte_ext, const char *str, size_t size); + const char *data() const; + size_t size() const; + const char& operator[](size_t pos) const; + operator std::string() const; + +private: + void *_ext = nullptr; + const char *_data; + size_t _size; + bool _one_byte_ext = true; + RtpExtType _type = RtpExtType::padding; +}; + + +#endif //ZLMEDIAKIT_RTPEXT_H diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp new file mode 100644 index 00000000..bcf6acb6 --- /dev/null +++ b/webrtc/Sdp.cpp @@ -0,0 +1,1788 @@ +/* + * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#include "Sdp.h" +#include "Rtsp/Rtsp.h" +#include +using namespace mediakit; + +using onCreateSdpItem = function; +static map sdpItemCreator; + +template +void registerSdpItem(){ + onCreateSdpItem func = [](const string &key, const string &value) { + auto ret = std::make_shared(); + ret->parse(value); + return ret; + }; + Item item; + sdpItemCreator.emplace(item.getKey(), std::move(func)); +} + +class DirectionInterface { +public: + virtual RtpDirection getDirection() const = 0; +}; + +class SdpDirectionSendonly : public SdpItem, public DirectionInterface{ +public: + const char* getKey() const override { return getRtpDirectionString(getDirection());} + RtpDirection getDirection() const override {return RtpDirection::sendonly;} +}; + +class SdpDirectionRecvonly : public SdpItem, public DirectionInterface{ +public: + const char* getKey() const override { return getRtpDirectionString(getDirection());} + RtpDirection getDirection() const override {return RtpDirection::recvonly;} +}; + +class SdpDirectionSendrecv : public SdpItem, public DirectionInterface{ +public: + const char* getKey() const override { return getRtpDirectionString(getDirection());} + RtpDirection getDirection() const override {return RtpDirection::sendrecv;} +}; + +class SdpDirectionInactive : public SdpItem, public DirectionInterface{ +public: + const char* getKey() const override { return getRtpDirectionString(getDirection());} + RtpDirection getDirection() const override {return RtpDirection::inactive;} +}; + +class DirectionInterfaceImp : public SdpItem, public DirectionInterface{ +public: + DirectionInterfaceImp(RtpDirection direct){ + direction = direct; + } + const char* getKey() const override { return getRtpDirectionString(getDirection());} + RtpDirection getDirection() const override {return direction;} + +private: + RtpDirection direction; +}; + +static bool registerAllItem(){ + registerSdpItem >(); + registerSdpItem >(); + registerSdpItem >(); + registerSdpItem >(); + registerSdpItem >(); + registerSdpItem >(); + registerSdpItem >(); + registerSdpItem >(); + registerSdpItem >(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + registerSdpItem(); + return true; +} + +static map dtls_role_map = { + {"active", DtlsRole::active}, + {"passive", DtlsRole::passive}, + {"actpass", DtlsRole::actpass} +}; + +DtlsRole getDtlsRole(const string &str) { + auto it = dtls_role_map.find(str); + return it == dtls_role_map.end() ? DtlsRole::invalid : it->second; +} + +const char* getDtlsRoleString(DtlsRole role){ + switch (role) { + case DtlsRole::active : return "active"; + case DtlsRole::passive : return "passive"; + case DtlsRole::actpass : return "actpass"; + default: return "invalid"; + } +} + +static map direction_map = { + {"sendonly", RtpDirection::sendonly}, + {"recvonly", RtpDirection::recvonly}, + {"sendrecv", RtpDirection::sendrecv}, + {"inactive", RtpDirection::inactive} +}; + +RtpDirection getRtpDirection(const string &str) { + auto it = direction_map.find(str); + return it == direction_map.end() ? RtpDirection::invalid : it->second; +} + +const char* getRtpDirectionString(RtpDirection val){ + switch (val) { + case RtpDirection::sendonly : return "sendonly"; + case RtpDirection::recvonly : return "recvonly"; + case RtpDirection::sendrecv : return "sendrecv"; + case RtpDirection::inactive : return "inactive"; + default: return "invalid"; + } +} + +////////////////////////////////////////////////////////////////////////////////////////// + +string RtcSdpBase::toString() const { + _StrPrinter printer; + for (auto &item : items) { + printer << item->getKey() << "=" << item->toString() << "\r\n"; + } + return std::move(printer); +} + +RtpDirection RtcSdpBase::getDirection() const{ + for (auto &item : items) { + auto attr = dynamic_pointer_cast(item); + if (attr) { + auto dir = dynamic_pointer_cast(attr->detail); + if (dir) { + return dir->getDirection(); + } + } + } + return RtpDirection::invalid; +} + +SdpItem::Ptr RtcSdpBase::getItem(char key_c, const char *attr_key) const { + for (auto item : items) { + string key(1, key_c); + if (strcasecmp(item->getKey(), key.data()) == 0) { + if (!attr_key) { + return item; + } + auto attr = dynamic_pointer_cast(item); + if (attr && !strcasecmp(attr->detail->getKey() , attr_key)) { + return attr->detail; + } + } + } + return SdpItem::Ptr(); +} + +int RtcSdpBase::getVersion() const { + return atoi(getStringItem('v').data()); +} + +SdpOrigin RtcSdpBase::getOrigin() const { + return getItemClass('o'); +} + +string RtcSdpBase::getSessionName() const { + return getStringItem('s'); +} + +string RtcSdpBase::getSessionInfo() const { + return getStringItem('i'); +} + +SdpTime RtcSdpBase::getSessionTime() const{ + return getItemClass('t'); +} + +SdpConnection RtcSdpBase::getConnection() const { + return getItemClass('c'); +} + +SdpBandwidth RtcSdpBase::getBandwidth() const { + return getItemClass('b'); +} + +string RtcSdpBase::getUri() const { + return getStringItem('u'); +} + +string RtcSdpBase::getEmail() const { + return getStringItem('e'); +} + +string RtcSdpBase::getPhone() const { + return getStringItem('p'); +} + +string RtcSdpBase::getTimeZone() const { + return getStringItem('z'); +} + +string RtcSdpBase::getEncryptKey() const { + return getStringItem('k'); +} + +string RtcSdpBase::getRepeatTimes() const { + return getStringItem('r'); +} + +////////////////////////////////////////////////////////////////////// + +void RtcSessionSdp::parse(const string &str) { + static auto flag = registerAllItem(); + RtcSdpBase *media = nullptr; + auto lines = split(str, "\n"); + for(auto &line : lines){ + trim(line); + if(line.size() < 3 || line[1] != '='){ + continue; + } + auto key = line.substr(0, 1); + auto value = line.substr(2); + if (!strcasecmp(key.data(), "m")) { + medias.emplace_back(RtcSdpBase()); + media = &medias.back(); + } + + SdpItem::Ptr item; + auto it = sdpItemCreator.find(key); + if (it != sdpItemCreator.end()) { + item = it->second(key, value); + } else { + item = std::make_shared(key); + item->parse(value); + } + if (media) { + media->items.push_back(std::move(item)); + } else { + items.push_back(std::move(item)); + } + } +} + +string RtcSessionSdp::toString() const { + _StrPrinter printer; + printer << RtcSdpBase::toString(); + for (auto &media : medias) { + printer << media.toString(); + } + + return std::move(printer); +} + +////////////////////////////////////////////////////////////////////////////////////////// + +#define SDP_THROW() throw std::invalid_argument(StrPrinter << "解析sdp " << getKey() << " 字段失败:" << str) + +void SdpTime::parse(const string &str) { + if (sscanf(str.data(), "%" SCNu64 " %" SCNu64, &start, &stop) != 2) { + SDP_THROW(); + } +} + +string SdpTime::toString() const { + if (value.empty()) { + value = to_string(start) + " " + to_string(stop); + } + return SdpItem::toString(); +} + +void SdpOrigin::parse(const string &str) { + auto vec = split(str, " "); + if (vec.size() != 6) { + SDP_THROW(); + } + username = vec[0]; + session_id = vec[1]; + session_version = vec[2]; + nettype = vec[3]; + addrtype = vec[4]; + address = vec[5]; +} + +string SdpOrigin::toString() const { + if (value.empty()) { + value = username + " " + session_id + " " + session_version + " " + nettype + " " + addrtype + " " + address; + } + return SdpItem::toString(); +} + +void SdpConnection::parse(const string &str) { + auto vec = split(str, " "); + if (vec.size() != 3) { + SDP_THROW(); + } + nettype = vec[0]; + addrtype = vec[1]; + address = vec[2]; +} + +string SdpConnection::toString() const { + if (value.empty()) { + value = nettype + " " + addrtype + " " + address; + } + return SdpItem::toString(); +} + +void SdpBandwidth::parse(const string &str) { + auto vec = split(str, ":"); + if (vec.size() != 2) { + SDP_THROW(); + } + bwtype = vec[0]; + bandwidth = atoi(vec[1].data()); +} + +string SdpBandwidth::toString() const { + if (value.empty()) { + value = bwtype + ":" + to_string(bandwidth); + } + return SdpItem::toString(); +} + +void SdpMedia::parse(const string &str) { + auto vec = split(str, " "); + if (vec.size() < 4) { + SDP_THROW(); + } + type = getTrackType(vec[0]); + if (type == TrackInvalid) { + SDP_THROW(); + } + port = atoi(vec[1].data()); + proto = vec[2]; + for (size_t i = 3; i < vec.size(); ++i) { + auto pt = atoi(vec[i].data()); + if (type != TrackApplication && pt > 0xFF) { + SDP_THROW(); + } + fmts.emplace_back(pt); + } +} + +string SdpMedia::toString() const { + if (value.empty()) { + value = string(getTrackString(type)) + " " + to_string(port) + " " + proto; + for (auto fmt : fmts) { + value += ' '; + value += to_string(fmt); + } + } + return SdpItem::toString(); +} + +void SdpAttr::parse(const string &str) { + auto pos = str.find(':'); + auto key = pos == string::npos ? str : str.substr(0, pos); + auto value = pos == string::npos ? string() : str.substr(pos + 1); + auto it = sdpItemCreator.find(key); + if (it != sdpItemCreator.end()) { + detail = it->second(key, value); + } else { + detail = std::make_shared(key); + detail->parse(value); + } +} + +string SdpAttr::toString() const { + if (value.empty()) { + auto detail_value = detail->toString(); + if (detail_value.empty()) { + value = detail->getKey(); + } else { + value = string(detail->getKey()) + ":" + detail_value; + } + } + return SdpItem::toString(); +} + +void SdpAttrGroup::parse(const string &str) { + auto vec = split(str, " "); + if (vec.size() < 2) { + SDP_THROW(); + } + type = vec[0]; + vec.erase(vec.begin()); + mids = std::move(vec); +} + +string SdpAttrGroup::toString() const { + if (value.empty()) { + value = type; + for (auto mid : mids) { + value += ' '; + value += mid; + } + } + return SdpItem::toString(); +} + +void SdpAttrMsidSemantic::parse(const string &str) { + auto vec = split(str, " "); + if (vec.size() < 1) { + SDP_THROW(); + } + msid = vec[0]; + token = vec.size() > 1 ? vec[1] : ""; +} + +string SdpAttrMsidSemantic::toString() const { + if (value.empty()) { + if (token.empty()) { + value = string(" ") + msid; + } else { + value = string(" ") + msid + " " + token; + } + } + return SdpItem::toString(); +} + +void SdpAttrRtcp::parse(const string &str) { + auto vec = split(str, " "); + if (vec.size() != 4) { + SDP_THROW(); + } + port = atoi(vec[0].data()); + nettype = vec[1]; + addrtype = vec[2]; + address = vec[3]; +} + +string SdpAttrRtcp::toString() const { + if (value.empty()) { + value = to_string(port) + " " + nettype + " " + addrtype + " " + address; + } + return SdpItem::toString(); +} + +void SdpAttrIceOption::parse(const string &str){ + auto vec = split(str, " "); + for (auto &v : vec) { + if (!strcasecmp(v.data(), "trickle")) { + trickle = true; + continue; + } + if (!strcasecmp(v.data(), "renomination")) { + renomination = true; + continue; + } + } +} + +string SdpAttrIceOption::toString() const{ + if (value.empty()) { + if (trickle && renomination) { + value = "trickle renomination"; + } else if (trickle) { + value = "trickle"; + } else if (renomination) { + value = "renomination"; + } + } + return value; +} + +void SdpAttrFingerprint::parse(const string &str) { + auto vec = split(str, " "); + if (vec.size() != 2) { + SDP_THROW(); + } + algorithm = vec[0]; + hash = vec[1]; +} + +string SdpAttrFingerprint::toString() const { + if (value.empty()) { + value = algorithm + " " + hash; + } + return SdpItem::toString(); +} + +void SdpAttrSetup::parse(const string &str) { + role = getDtlsRole(str); + if (role == DtlsRole::invalid) { + SDP_THROW(); + } +} + +string SdpAttrSetup::toString() const { + if (value.empty()) { + value = getDtlsRoleString(role); + } + return SdpItem::toString(); +} + +void SdpAttrExtmap::parse(const string &str) { + char buf[128] = {0}; + char direction_buf[32] = {0}; + if (sscanf(str.data(), "%" SCNd8 "/%31[^ ] %127s", &id, direction_buf, buf) != 3) { + if (sscanf(str.data(), "%" SCNd8 " %127s", &id, buf) != 2) { + SDP_THROW(); + } + direction = RtpDirection::sendrecv; + } else { + direction = getRtpDirection(direction_buf); + } + ext = buf; +} + +string SdpAttrExtmap::toString() const { + if (value.empty()) { + if(direction == RtpDirection::invalid || direction == RtpDirection::sendrecv){ + value = to_string((int)id) + " " + ext; + } else { + value = to_string((int)id) + "/" + getRtpDirectionString(direction) + " " + ext; + } + } + return SdpItem::toString(); +} + +void SdpAttrRtpMap::parse(const string &str) { + char buf[32] = {0}; + if (sscanf(str.data(), "%" SCNu8 " %31[^/]/%" SCNd32 "/%" SCNd32, &pt, buf, &sample_rate, &channel) != 4) { + if (sscanf(str.data(), "%" SCNu8 " %31[^/]/%" SCNd32, &pt, buf, &sample_rate) != 3) { + SDP_THROW(); + } + if (getTrackType(getCodecId(buf)) == TrackAudio) { + //未指定通道数时,且为音频时,那么通道数默认为1 + channel = 1; + } + } + codec = buf; +} + +string SdpAttrRtpMap::toString() const { + if (value.empty()) { + value = to_string(pt) + " " + codec + "/" + to_string(sample_rate); + if (channel) { + value += '/'; + value += to_string(channel); + } + } + return SdpItem::toString(); +} + +void SdpAttrRtcpFb::parse(const string &str_in) { + auto str = str_in + "\n"; + char rtcp_type_buf[32] = {0}; + if (2 != sscanf(str.data(), "%" SCNu8 " %31[^\n]", &pt, rtcp_type_buf)) { + SDP_THROW(); + } + rtcp_type = rtcp_type_buf; +} + +string SdpAttrRtcpFb::toString() const { + if (value.empty()) { + value = to_string(pt) + " " + rtcp_type; + } + return SdpItem::toString(); +} + +void SdpAttrFmtp::parse(const string &str) { + auto pos = str.find(' '); + if (pos == string::npos) { + SDP_THROW(); + } + pt = atoi(str.substr(0, pos).data()); + auto vec = split(str.substr(pos + 1), ";"); + for (auto &item : vec) { + trim(item); + auto pos = item.find('='); + if(pos == string::npos){ + fmtp.emplace(std::make_pair(item, "")); + } else { + fmtp.emplace(std::make_pair(item.substr(0, pos), item.substr(pos + 1))); + } + } + if (fmtp.empty()) { + SDP_THROW(); + } +} + +string SdpAttrFmtp::toString() const { + if (value.empty()) { + value = to_string(pt); + int i = 0; + for (auto &pr : fmtp) { + value += (i++ ? ';' : ' '); + value += pr.first + "=" + pr.second; + } + } + return SdpItem::toString(); +} + +void SdpAttrSSRC::parse(const string &str_in) { + auto str = str_in + '\n'; + char attr_buf[32] = {0}; + char attr_val_buf[128] = {0}; + if (3 == sscanf(str.data(), "%" SCNu32 " %31[^:]:%127[^\n]", &ssrc, attr_buf, attr_val_buf)) { + attribute = attr_buf; + attribute_value = attr_val_buf; + } else if (2 == sscanf(str.data(), "%" SCNu32 " %31s[^\n]", &ssrc, attr_buf)) { + attribute = attr_buf; + } else { + SDP_THROW(); + } +} + +string SdpAttrSSRC::toString() const { + if (value.empty()) { + value = to_string(ssrc) + ' '; + value += attribute; + if (!attribute_value.empty()) { + value += ':'; + value += attribute_value; + } + } + return SdpItem::toString(); +} + +void SdpAttrSSRCGroup::parse(const string &str) { + auto vec = split(str, " "); + if (vec.size() >= 3) { + type = std::move(vec[0]); + CHECK(isFID() || isSIM()); + vec.erase(vec.begin()); + for (auto ssrc : vec) { + ssrcs.emplace_back((uint32_t)atoll(ssrc.data())); + } + } else { + SDP_THROW(); + } +} + +string SdpAttrSSRCGroup::toString() const { + if (value.empty()) { + value = type; + //最少要求2个ssrc + CHECK(ssrcs.size() >= 2); + for (auto &ssrc : ssrcs) { + value += ' '; + value += to_string(ssrc); + } + } + return SdpItem::toString(); +} + +void SdpAttrSctpMap::parse(const string &str) { + char subtypes_buf[64] = {0}; + if (3 == sscanf(str.data(), "%" SCNu16 " %63[^ ] %" SCNd32, &port, subtypes_buf, &streams)) { + subtypes = subtypes_buf; + } else { + SDP_THROW(); + } +} + +string SdpAttrSctpMap::toString() const { + if (value.empty()) { + value = to_string(port); + value += ' '; + value += subtypes; + value += ' '; + value += to_string(streams); + } + return SdpItem::toString(); +} + +void SdpAttrCandidate::parse(const string &str) { + char foundation_buf[40] = {0}; + char transport_buf[16] = {0}; + char address_buf[32] = {0}; + char type_buf[16] = {0}; + + // https://datatracker.ietf.org/doc/html/rfc5245#section-15.1 + if (7 != sscanf(str.data(), "%32[^ ] %" SCNu32 " %15[^ ] %" SCNu32 " %31[^ ] %" SCNu16 " typ %15[^ ]", + foundation_buf, &component, transport_buf, &priority, address_buf, &port, type_buf)) { + SDP_THROW(); + } + foundation = foundation_buf; + transport = transport_buf; + address = address_buf; + type = type_buf; + auto pos = str.find(type); + if (pos != string::npos) { + auto remain = str.substr(pos + type.size()); + trim(remain); + if (!remain.empty()) { + auto vec = split(remain, " "); + string key; + for (auto &item : vec) { + if (key.empty()) { + key = item; + } else { + arr.emplace_back(std::make_pair(std::move(key), std::move(item))); + } + } + } + } +} + +string SdpAttrCandidate::toString() const { + if (value.empty()) { + value = foundation + " " + to_string(component) + " " + transport + " " + to_string(priority) + + " " + address + " " + to_string(port) + " typ " + type; + for (auto &pr : arr) { + value += ' '; + value += pr.first; + value += ' '; + value += pr.second; + } + } + return SdpItem::toString(); +} + +void SdpAttrSimulcast::parse(const string &str) { + //https://www.meetecho.com/blog/simulcast-janus-ssrc/ + //a=simulcast:send/recv q;h;f + //a=simulcast:send/recv [rid=]q;h;f + //a=simulcast: recv h;m;l + // + auto vec = split(str, " "); + if (vec.size() != 2) { + SDP_THROW(); + } + direction = vec[0]; + rids = split(vec[1], ";"); +} + +string SdpAttrSimulcast::toString() const { + if (value.empty()) { + value = direction + " "; + bool first = true; + for (auto &rid : rids) { + if (first) { + first = false; + } else { + value += ';'; + } + value += rid; + } + } + return SdpItem::toString(); +} + +void SdpAttrRid::parse(const string &str) { + auto vec = split(str, " "); + CHECK(vec.size() >= 2); + rid = vec[0]; + direction = vec[1]; +} + +string SdpAttrRid::toString() const { + if (value.empty()) { + value = rid + " " + direction; + } + return SdpItem::toString(); +} + +void RtcSession::loadFrom(const string &str, bool check) { + RtcSessionSdp sdp; + sdp.parse(str); + + version = sdp.getVersion(); + origin = sdp.getOrigin(); + session_name = sdp.getSessionName(); + session_info = sdp.getSessionInfo(); + connection = sdp.getConnection(); + bandwidth = sdp.getBandwidth(); + time = sdp.getSessionTime(); + msid_semantic = sdp.getItemClass('a', "msid-semantic"); + for (auto &media : sdp.medias) { + auto mline = media.getItemClass('m'); + switch (mline.type) { + case TrackVideo: + case TrackAudio: + case TrackApplication: break; + default: throw std::invalid_argument(StrPrinter << "不识别的media类型:" << mline.toString()); + } + this->media.emplace_back(); + auto &rtc_media = this->media.back(); + rtc_media.type = mline.type; + rtc_media.mid = media.getStringItem('a', "mid"); + rtc_media.proto = mline.proto; + rtc_media.type = mline.type; + rtc_media.port = mline.port; + rtc_media.addr = media.getItemClass('c'); + rtc_media.ice_ufrag = media.getStringItem('a', "ice-ufrag"); + rtc_media.ice_pwd = media.getStringItem('a', "ice-pwd"); + rtc_media.role = media.getItemClass('a', "setup").role; + rtc_media.fingerprint = media.getItemClass('a', "fingerprint"); + if (rtc_media.fingerprint.empty()) { + rtc_media.fingerprint = sdp.getItemClass('a', "fingerprint"); + } + rtc_media.ice_lite = media.getItem('a', "ice-lite").operator bool(); + auto ice_options = media.getItemClass('a', "ice-options"); + rtc_media.ice_trickle = ice_options.trickle; + rtc_media.ice_renomination = ice_options.renomination; + rtc_media.candidate = media.getAllItem('a', "candidate"); + + if (mline.type == TrackType::TrackApplication) { + rtc_media.sctp_port = atoi(media.getStringItem('a', "sctp-port").data()); + rtc_media.sctpmap = media.getItemClass('a', "sctpmap"); + continue; + } + rtc_media.rtcp_addr = media.getItemClass('a', "rtcp"); + rtc_media.direction = media.getDirection(); + rtc_media.extmap = media.getAllItem('a', "extmap"); + rtc_media.rtcp_mux = media.getItem('a', "rtcp-mux").operator bool(); + rtc_media.rtcp_rsize = media.getItem('a', "rtcp-rsize").operator bool(); + + map rtc_ssrc_map; + auto ssrc_attr = media.getAllItem('a', "ssrc"); + for (auto &ssrc : ssrc_attr) { + auto &rtc_ssrc = rtc_ssrc_map[ssrc.ssrc]; + rtc_ssrc.ssrc = ssrc.ssrc; + if (!strcasecmp(ssrc.attribute.data(), "cname")) { + rtc_ssrc.cname = ssrc.attribute_value; + continue; + } + if (!strcasecmp(ssrc.attribute.data(), "msid")) { + rtc_ssrc.msid = ssrc.attribute_value; + continue; + } + if (!strcasecmp(ssrc.attribute.data(), "mslabel")) { + rtc_ssrc.mslabel = ssrc.attribute_value; + continue; + } + if (!strcasecmp(ssrc.attribute.data(), "label")) { + rtc_ssrc.label = ssrc.attribute_value; + continue; + } + } + + auto ssrc_groups = media.getAllItem('a', "ssrc-group"); + SdpAttrSSRCGroup *ssrc_group_sim = nullptr; + SdpAttrSSRCGroup *ssrc_group_fid = nullptr; + for (auto &group : ssrc_groups) { + if (group.isFID()) { + ssrc_group_fid = &group; + } else if (group.isSIM()) { + ssrc_group_sim = &group; + } + } + + if (ssrc_group_fid) { + //指定了ssrc-group:FID字段 + for (auto ssrc : ssrc_group_fid->ssrcs) { + auto it = rtc_ssrc_map.find(ssrc); + if (it == rtc_ssrc_map.end()) { + throw std::invalid_argument("a=ssrc-group:FID字段指定的ssrc未找到"); + } + rtc_media.rtp_rtx_ssrc.emplace_back(it->second); + } + CHECK(rtc_media.rtp_rtx_ssrc.size() == 2); + } else { + auto simulcast = media.getItemClass('a', "simulcast"); + if (simulcast.empty()) { + //没有指定ssrc-group:FID字段,也不是simulcast,那么只有1个或0个ssrc + if (rtc_ssrc_map.size() == 1) { + rtc_media.rtp_rtx_ssrc.emplace_back(rtc_ssrc_map.begin()->second); + } else if (rtc_ssrc_map.size() > 1) { + throw std::invalid_argument("sdp中不存在a=ssrc-group:FID字段,但是ssrc却大于1个"); + } + } else { + //开启simulcast + rtc_media.rtp_rids = simulcast.rids; + //simulcast最少要求2种方案 + CHECK(rtc_media.rtp_rids.size() >= 2); + } + } + + if (ssrc_group_sim) { + //指定了a=ssrc-group:SIM + for (auto ssrc : ssrc_group_sim->ssrcs) { + auto it = rtc_ssrc_map.find(ssrc); + if (it == rtc_ssrc_map.end()) { + throw std::invalid_argument("a=ssrc-group:SIM字段指定的ssrc未找到"); + } + rtc_media.rtp_ssrc_sim.emplace_back(it->second); + } + } else if (!rtc_media.rtp_rids.empty()) { + //未指定a=ssrc-group:SIM,但是指定了a=simulcast,且可能指定了ssrc + for (auto &attr : ssrc_attr) { + rtc_media.rtp_ssrc_sim.emplace_back(rtc_ssrc_map[attr.ssrc]); + } + } + + auto rtpmap_arr = media.getAllItem('a', "rtpmap"); + auto rtcpfb_arr = media.getAllItem('a', "rtcp-fb"); + auto fmtp_aar = media.getAllItem('a', "fmtp"); + //方便根据pt查找rtpmap,一个pt必有一条 + map rtpmap_map; + //方便根据pt查找rtcp-fb,一个pt可能有多条或0条 + multimap rtcpfb_map; + //方便根据pt查找fmtp,一个pt最多一条 + map fmtp_map; + + for (auto &rtpmap : rtpmap_arr) { + if (!rtpmap_map.emplace(rtpmap.pt, rtpmap).second) { + //添加失败,有多条 + throw std::invalid_argument(StrPrinter << "该pt存在多条a=rtpmap:" << rtpmap.pt); + } + } + for (auto &rtpfb : rtcpfb_arr) { + rtcpfb_map.emplace(rtpfb.pt, rtpfb); + } + for (auto &fmtp : fmtp_aar) { + if (!fmtp_map.emplace(fmtp.pt, fmtp).second) { + //添加失败,有多条 + throw std::invalid_argument(StrPrinter << "该pt存在多条a=fmtp:" << fmtp.pt); + } + } + for (auto &pt : mline.fmts) { + //遍历所有编码方案的pt + rtc_media.plan.emplace_back(); + auto &plan = rtc_media.plan.back(); + auto rtpmap_it = rtpmap_map.find(pt); + if (rtpmap_it == rtpmap_map.end()) { + plan.pt = pt; + plan.codec = RtpPayload::getName(pt); + plan.sample_rate = RtpPayload::getClockRate(pt); + plan.channel = RtpPayload::getAudioChannel(pt); + } else { + plan.pt = rtpmap_it->second.pt; + plan.codec = rtpmap_it->second.codec; + plan.sample_rate = rtpmap_it->second.sample_rate; + plan.channel = rtpmap_it->second.channel; + } + + auto fmtp_it = fmtp_map.find(pt); + if (fmtp_it != fmtp_map.end()) { + plan.fmtp = fmtp_it->second.fmtp; + } + for (auto rtpfb_it = rtcpfb_map.find(pt); + rtpfb_it != rtcpfb_map.end() && rtpfb_it->second.pt == pt; ++rtpfb_it) { + plan.rtcp_fb.emplace(rtpfb_it->second.rtcp_type); + } + } + } + + group = sdp.getItemClass('a', "group"); + if (check) { + checkValid(); + } +} + +std::shared_ptr wrapSdpAttr(SdpItem::Ptr item){ + auto ret = std::make_shared(); + ret->detail = std::move(item); + return ret; +} + +static void toRtsp(vector &items) { + for (auto it = items.begin(); it != items.end();) { + switch ((*it)->getKey()[0]) { + case 'v': + case 'o': + case 's': + case 'i': + case 't': + case 'c': + case 'b':{ + ++it; + break; + } + + case 'm': { + auto m = dynamic_pointer_cast(*it); + CHECK(m); + m->proto = "RTP/AVP"; + ++it; + break; + } + case 'a': { + auto attr = dynamic_pointer_cast(*it); + CHECK(attr); + if (!strcasecmp(attr->detail->getKey(), "rtpmap") + || !strcasecmp(attr->detail->getKey(), "fmtp")) { + ++it; + break; + } + } + default: { + it = items.erase(it); + break; + } + } + } +} + +string RtcSession::toRtspSdp() const{ + checkValid(); + RtcSession copy = *this; + copy.media.clear(); + for (auto &m : media) { + switch (m.type) { + case TrackAudio: + case TrackVideo: { + copy.media.emplace_back(m); + copy.media.back().plan.resize(1); + break; + } + default: + continue; + } + } + + copy.session_name = "zlmediakit rtsp stream from webrtc"; + auto sdp = copy.toRtcSessionSdp(); + toRtsp(sdp->items); + int i = 0; + for (auto &m : sdp->medias) { + toRtsp(m.items); + m.items.push_back(wrapSdpAttr(std::make_shared("control", string("trackID=") + to_string(i++)))); + } + return sdp->toString(); +} + +RtcSessionSdp::Ptr RtcSession::toRtcSessionSdp() const{ + RtcSessionSdp::Ptr ret = std::make_shared(); + auto &sdp = *ret; + sdp.items.emplace_back(std::make_shared >(to_string(version))); + sdp.items.emplace_back(std::make_shared(origin)); + sdp.items.emplace_back(std::make_shared >(session_name)); + if (!session_info.empty()) { + sdp.items.emplace_back(std::make_shared >(session_info)); + } + sdp.items.emplace_back(std::make_shared(time)); + if(connection.empty()){ + sdp.items.emplace_back(std::make_shared(connection)); + } + if (!bandwidth.empty()) { + sdp.items.emplace_back(std::make_shared(bandwidth)); + } + sdp.items.emplace_back(wrapSdpAttr(std::make_shared(group))); + sdp.items.emplace_back(wrapSdpAttr(std::make_shared(msid_semantic))); + for (auto &m : media) { + sdp.medias.emplace_back(); + auto &sdp_media = sdp.medias.back(); + auto mline = std::make_shared(); + mline->type = m.type; + mline->port = m.port; + mline->proto = m.proto; + for (auto &p : m.plan) { + mline->fmts.emplace_back(p.pt); + } + if (m.type == TrackApplication) { + mline->fmts.emplace_back(m.sctp_port); + } + sdp_media.items.emplace_back(std::move(mline)); + sdp_media.items.emplace_back(std::make_shared(m.addr)); + if (!m.rtcp_addr.empty()) { + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.rtcp_addr))); + } + + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.ice_ufrag))); + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.ice_pwd))); + if (m.ice_trickle || m.ice_renomination) { + auto attr = std::make_shared(); + attr->trickle = m.ice_trickle; + attr->renomination = m.ice_renomination; + sdp_media.items.emplace_back(wrapSdpAttr(attr)); + } + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.fingerprint))); + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.role))); + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.mid))); + if (m.ice_lite) { + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared("ice-lite"))); + } + for (auto &ext : m.extmap) { + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(ext))); + } + if (m.direction != RtpDirection::invalid) { + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.direction))); + } + if (m.rtcp_mux) { + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared("rtcp-mux"))); + } + if (m.rtcp_rsize) { + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared("rtcp-rsize"))); + } + + if(m.type != TrackApplication) { + for (auto &p : m.plan) { + auto rtp_map = std::make_shared(); + rtp_map->pt = p.pt; + rtp_map->codec = p.codec; + rtp_map->sample_rate = p.sample_rate; + rtp_map->channel = p.channel; + //添加a=rtpmap + sdp_media.items.emplace_back(wrapSdpAttr(std::move(rtp_map))); + + for (auto &fb : p.rtcp_fb) { + auto rtcp_fb = std::make_shared(); + rtcp_fb->pt = p.pt; + rtcp_fb->rtcp_type = fb; + //添加a=rtcp-fb + sdp_media.items.emplace_back(wrapSdpAttr(std::move(rtcp_fb))); + } + + if (!p.fmtp.empty()) { + auto fmtp = std::make_shared(); + fmtp->pt = p.pt; + fmtp->fmtp = p.fmtp; + //添加a=fmtp + sdp_media.items.emplace_back(wrapSdpAttr(std::move(fmtp))); + } + } + + { + //添加a=msid字段 + if (!m.rtp_rtx_ssrc.empty()) { + auto msid = std::make_shared(); + if (!m.rtp_rtx_ssrc[0].msid.empty()) { + msid->parse(m.rtp_rtx_ssrc[0].msid); + } else { + msid->parse("mslabel label"); + } + sdp_media.items.emplace_back(wrapSdpAttr(std::move(msid))); + } + } + + static auto addSSRCItem = [](const RtcSSRC &rtp_ssrc, vector &items) { + CHECK(!rtp_ssrc.empty()); + SdpAttrSSRC ssrc; + ssrc.ssrc = rtp_ssrc.ssrc; + + ssrc.attribute = "cname"; + ssrc.attribute_value = rtp_ssrc.cname; + items.emplace_back(wrapSdpAttr(std::make_shared(ssrc))); + + if (!rtp_ssrc.msid.empty()) { + ssrc.attribute = "msid"; + ssrc.attribute_value = rtp_ssrc.msid; + items.emplace_back(wrapSdpAttr(std::make_shared(ssrc))); + } + + if (!rtp_ssrc.mslabel.empty()) { + ssrc.attribute = "mslabel"; + ssrc.attribute_value = rtp_ssrc.mslabel; + items.emplace_back(wrapSdpAttr(std::make_shared(ssrc))); + } + + if (!rtp_ssrc.label.empty()) { + ssrc.attribute = "label"; + ssrc.attribute_value = rtp_ssrc.label; + items.emplace_back(wrapSdpAttr(std::make_shared(ssrc))); + } + }; + + { + auto group = std::make_shared(); + for (auto &ssrc : m.rtp_rtx_ssrc) { + //添加a=ssrc字段 + addSSRCItem(ssrc, sdp_media.items); + group->ssrcs.emplace_back(ssrc.ssrc); + } + if (group->ssrcs.size() >= 2) { + group->type = "FID"; + //生成a=ssrc-group:FID字段 + sdp_media.items.emplace_back(wrapSdpAttr(std::move(group))); + } + } + + { + if (m.rtp_ssrc_sim.size() >= 2) { + //simulcast 要求 2~3路 + auto group = std::make_shared(); + for (auto &ssrc : m.rtp_ssrc_sim) { + //添加simulcast的ssrc + addSSRCItem(ssrc, sdp_media.items); + group->ssrcs.emplace_back(ssrc.ssrc); + } + //添加a=ssrc-group:SIM字段 + group->type = "SIM"; + sdp_media.items.emplace_back(wrapSdpAttr(std::move(group))); + } + + if (m.rtp_rids.size() >= 2) { + auto simulcast = std::make_shared(); + simulcast->direction = "recv"; + simulcast->rids = m.rtp_rids; + sdp_media.items.emplace_back(wrapSdpAttr(std::move(simulcast))); + + for (auto &rid : m.rtp_rids) { + auto attr_rid = std::make_shared(); + attr_rid->rid = rid; + attr_rid->direction = "recv"; + sdp_media.items.emplace_back(wrapSdpAttr(std::move(attr_rid))); + } + } + } + + } else { + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.sctpmap))); + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared("sctp-port", to_string(m.sctp_port)))); + } + + for (auto &cand : m.candidate) { + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(cand))); + } + } + return ret; +} + +string RtcSession::toString() const{ + checkValid(); + return toRtcSessionSdp()->toString(); +} + +string RtcCodecPlan::getFmtp(const char *key) const{ + for (auto &item : fmtp) { + if (strcasecmp(item.first.data(), key) == 0) { + return item.second; + } + } + return ""; +} + +const RtcCodecPlan *RtcMedia::getPlan(uint8_t pt) const{ + for (auto &item : plan) { + if (item.pt == pt) { + return &item; + } + } + return nullptr; +} + +const RtcCodecPlan *RtcMedia::getPlan(const char *codec) const{ + for (auto &item : plan) { + if (strcasecmp(item.codec.data(), codec) == 0) { + return &item; + } + } + return nullptr; +} + +const RtcCodecPlan *RtcMedia::getRelatedRtxPlan(uint8_t pt) const{ + for (auto &item : plan) { + if (strcasecmp(item.codec.data(), "rtx") == 0) { + auto apt = atoi(item.getFmtp("apt").data()); + if (pt == apt) { + return &item; + } + } + } + return nullptr; +} + +uint32_t RtcMedia::getRtpSSRC() const { + if (rtp_rtx_ssrc.size()) { + return rtp_rtx_ssrc[0].ssrc; + } + return 0; +} + +uint32_t RtcMedia::getRtxSSRC() const { + if (rtp_rtx_ssrc.size() > 1) { + return rtp_rtx_ssrc[1].ssrc; + } + return 0; +} + +void RtcMedia::checkValid() const{ + CHECK(type != TrackInvalid); + CHECK(!mid.empty()); + CHECK(!proto.empty()); + CHECK(direction != RtpDirection::invalid || type == TrackApplication); + CHECK(!plan.empty() || type == TrackApplication ); +} + +void RtcMedia::checkValidSSRC() const { + bool send_rtp = (direction == RtpDirection::sendonly || direction == RtpDirection::sendrecv); + if (rtp_rids.empty() && rtp_ssrc_sim.empty()) { + //非simulcast时,检查有没有指定rtp ssrc + CHECK(!rtp_rtx_ssrc.empty() || !send_rtp); + } + +#if 0 + //todo 发现Firefox(88.0)在mac平台下,开启rtx后没有指定ssrc + auto rtx_plan = getPlan("rtx"); + if (rtx_plan) { + //开启rtx后必须指定rtx_ssrc + CHECK(rtp_rtx_ssrc.size() >= 2 || !send_rtp); + } +#endif +} + +void RtcSession::checkValid() const{ + CHECK(version == 0); + CHECK(!origin.empty()); + CHECK(!session_name.empty()); + CHECK(!msid_semantic.empty()); + CHECK(!media.empty()); + CHECK(group.mids.size() <= media.size()); + for (auto &item : media) { + item.checkValid(); + } +} + +void RtcSession::checkValidSSRC() const{ + for (auto &item : media) { + item.checkValidSSRC(); + } +} + +const RtcMedia *RtcSession::getMedia(TrackType type) const{ + for(auto &m : media){ + if(m.type == type){ + return &m; + } + } + return nullptr; +} + +bool RtcSession::haveSSRC() const { + for (auto &m : media) { + if (!m.rtp_rtx_ssrc.empty()) { + return true; + } + } + return false; +} + +bool RtcSession::supportRtcpFb(const string &name, TrackType type) const { + auto media = getMedia(type); + if (!media) { + return false; + } + auto &ref = media->plan[0].rtcp_fb; + return ref.find(name) != ref.end(); +} + +string const SdpConst::kTWCCRtcpFb = "transport-cc"; +string const SdpConst::kRembRtcpFb = "goog-remb"; + +void RtcConfigure::RtcTrackConfigure::enableTWCC(bool enable){ + if (!enable) { + rtcp_fb.erase(SdpConst::kTWCCRtcpFb); + extmap.erase(RtpExtType::transport_cc); + } else { + rtcp_fb.emplace(SdpConst::kTWCCRtcpFb); + extmap.emplace(RtpExtType::transport_cc); + } +} + +void RtcConfigure::RtcTrackConfigure::enableREMB(bool enable){ + if (!enable) { + rtcp_fb.erase(SdpConst::kRembRtcpFb); + extmap.erase(RtpExtType::abs_send_time); + } else { + rtcp_fb.emplace(SdpConst::kRembRtcpFb); + extmap.emplace(RtpExtType::abs_send_time); + } +} + +void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){ + enable = true; + rtcp_mux = true; + rtcp_rsize = false; + group_bundle = true; + support_rtx = true; + support_red = false; + support_ulpfec = false; + ice_lite = true; + ice_trickle = true; + ice_renomination = false; + switch (type) { + case TrackAudio: { + //此处调整偏好的编码格式优先级 + preferred_codec = {CodecAAC, CodecG711U, CodecG711A, CodecOpus}; + rtcp_fb = {SdpConst::kTWCCRtcpFb, SdpConst::kRembRtcpFb}; + extmap = { + RtpExtType::ssrc_audio_level, + RtpExtType::csrc_audio_level, + RtpExtType::abs_send_time, + RtpExtType::transport_cc, + //rtx重传rtp时,忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时,如果存在sdes_mid的ext,将导致无法播放 + //RtpExtType::sdes_mid, + RtpExtType::sdes_rtp_stream_id, + RtpExtType::sdes_repaired_rtp_stream_id + }; + break; + } + case TrackVideo: { + //此处调整偏好的编码格式优先级 + preferred_codec = {CodecH264, CodecH265, CodecAV1}; + rtcp_fb = {SdpConst::kTWCCRtcpFb, SdpConst::kRembRtcpFb, "nack", "ccm fir", "nack pli"}; + extmap = { + RtpExtType::abs_send_time, + RtpExtType::transport_cc, + //rtx重传rtp时,忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时,如果存在sdes_mid的ext,将导致无法播放 + //RtpExtType::sdes_mid, + RtpExtType::sdes_rtp_stream_id, + RtpExtType::sdes_repaired_rtp_stream_id, + RtpExtType::video_timing, + RtpExtType::color_space, + RtpExtType::video_content_type, + RtpExtType::playout_delay, + RtpExtType::video_orientation, + RtpExtType::toffset, + RtpExtType::framemarking + }; + break; + } + case TrackApplication: { + enable = false; + break; + } + default: break; + } +} + +void RtcConfigure::setDefaultSetting(string ice_ufrag, + string ice_pwd, + RtpDirection direction, + const SdpAttrFingerprint &fingerprint) { + video.setDefaultSetting(TrackVideo); + audio.setDefaultSetting(TrackAudio); + application.setDefaultSetting(TrackApplication); + + video.ice_ufrag = audio.ice_ufrag = application.ice_ufrag = ice_ufrag; + video.ice_pwd = audio.ice_pwd = application.ice_pwd = ice_pwd; + video.direction = audio.direction = application.direction = direction; + video.fingerprint = audio.fingerprint = application.fingerprint = fingerprint; +} + +void RtcConfigure::addCandidate(const SdpAttrCandidate &candidate, TrackType type) { + switch (type) { + case TrackAudio: { + audio.candidate.emplace_back(candidate); + break; + } + case TrackVideo: { + video.candidate.emplace_back(candidate); + break; + } + case TrackApplication: { + application.candidate.emplace_back(candidate); + break; + } + default: { + if (audio.group_bundle) { + audio.candidate.emplace_back(candidate); + } + if (video.group_bundle) { + video.candidate.emplace_back(candidate); + } + if (application.group_bundle) { + application.candidate.emplace_back(candidate); + } + break; + } + } +} + +void RtcConfigure::enableTWCC(bool enable, TrackType type){ + switch (type) { + case TrackAudio: { + audio.enableTWCC(enable); + break; + } + case TrackVideo: { + video.enableTWCC(enable); + break; + } + case TrackApplication: { + application.enableTWCC(enable); + break; + } + default: { + audio.enableTWCC(enable); + video.enableTWCC(enable); + application.enableTWCC(enable); + break; + } + } +} + +void RtcConfigure::enableREMB(bool enable, TrackType type){ + switch (type) { + case TrackAudio: { + audio.enableREMB(enable); + break; + } + case TrackVideo: { + video.enableREMB(enable); + break; + } + case TrackApplication: { + application.enableREMB(enable); + break; + } + default: { + audio.enableREMB(enable); + video.enableREMB(enable); + application.enableREMB(enable); + break; + } + } +} + +shared_ptr RtcConfigure::createAnswer(const RtcSession &offer){ + shared_ptr ret = std::make_shared(); + ret->version = offer.version; + //todo 此处设置会话id与会话地址,貌似没什么作用 + ret->origin = offer.origin; + ret->session_name = offer.session_name; + ret->msid_semantic = offer.msid_semantic; + matchMedia(ret, TrackAudio, offer.media, audio); + matchMedia(ret, TrackVideo, offer.media, video); + matchMedia(ret, TrackApplication, offer.media, application); + if (ret->media.empty()) { + throw std::invalid_argument("生成的answer sdp中媒体个数为0"); + } + + //设置音视频端口复用 + if (!offer.group.mids.empty()) { + for (auto &m : ret->media) { + ret->group.mids.emplace_back(m.mid); + } + } + return ret; +} + +void RtcConfigure::matchMedia(shared_ptr &ret, TrackType type, const vector &medias, const RtcTrackConfigure &configure){ + if (!configure.enable) { + return; + } + bool check_profile = true; + bool check_codec = true; + +RETRY: + + for (auto &codec : configure.preferred_codec) { + for (auto &offer_media : medias) { + if (offer_media.type != type) { + continue; + } + if (offer_media.ice_lite && configure.ice_lite) { + WarnL << "answer sdp配置为ice_lite模式,与offer sdp中的ice_lite模式冲突"; + continue; + } + const RtcCodecPlan *selected_plan = nullptr; + for (auto &plan : offer_media.plan) { + //先检查编码格式是否为偏好 + if (check_codec && getCodecId(plan.codec) != codec) { + continue; + } + //命中偏好的编码格式,然后检查规格 + if (check_profile && !onCheckCodecProfile(plan, codec)) { + continue; + } + //找到中意的codec + selected_plan = &plan; + break; + } + if (!selected_plan) { + //offer中该媒体的所有的codec都不支持 + continue; + } + RtcMedia answer_media; + answer_media.type = offer_media.type; + answer_media.mid = offer_media.mid; + answer_media.proto = offer_media.proto; + //todo(此处设置rtp端口,貌似没什么作用) + answer_media.port = offer_media.port; + //todo(此处设置rtp的ip地址,貌似没什么作用) + answer_media.addr = offer_media.addr; + //todo(此处设置rtcp地址,貌似没什么作用) + answer_media.rtcp_addr = offer_media.rtcp_addr; + answer_media.rtcp_mux = offer_media.rtcp_mux && configure.rtcp_mux; + answer_media.rtcp_rsize = offer_media.rtcp_rsize && configure.rtcp_rsize; + answer_media.ice_trickle = offer_media.ice_trickle && configure.ice_trickle; + answer_media.ice_renomination = offer_media.ice_renomination && configure.ice_renomination; + answer_media.ice_ufrag = configure.ice_ufrag; + answer_media.ice_pwd = configure.ice_pwd; + answer_media.fingerprint = configure.fingerprint; + answer_media.ice_lite = configure.ice_lite; + answer_media.candidate = configure.candidate; + answer_media.rtp_rids = offer_media.rtp_rids; + answer_media.rtp_ssrc_sim = offer_media.rtp_ssrc_sim; + switch (offer_media.role) { + case DtlsRole::actpass : + case DtlsRole::active : { + answer_media.role = DtlsRole::passive; + break; + } + case DtlsRole::passive : { + answer_media.role = DtlsRole::active; + break; + } + default: continue; + } + + switch (offer_media.direction) { + case RtpDirection::sendonly : { + if (configure.direction != RtpDirection::recvonly && + configure.direction != RtpDirection::sendrecv) { + //我们不支持接收 + continue; + } + answer_media.direction = RtpDirection::recvonly; + break; + } + case RtpDirection::recvonly : { + if (configure.direction != RtpDirection::sendonly && + configure.direction != RtpDirection::sendrecv) { + //我们不支持发送 + continue; + } + answer_media.direction = RtpDirection::sendonly; + break; + } + case RtpDirection::sendrecv : { + //对方支持发送接收,那么最终能力根据配置来决定 + answer_media.direction = configure.direction; + break; + } + default: continue; + } + + //添加媒体plan + answer_media.plan.emplace_back(*selected_plan); + onSelectPlan(answer_media.plan.back(), codec); + + set pt_selected = {selected_plan->pt}; + + //添加rtx,red,ulpfec plan + if (configure.support_red || configure.support_rtx || configure.support_ulpfec) { + for (auto &plan : offer_media.plan) { + if (!strcasecmp(plan.codec.data(), "rtx")) { + if (configure.support_rtx && atoi(plan.getFmtp("apt").data()) == selected_plan->pt) { + answer_media.plan.emplace_back(plan); + pt_selected.emplace(plan.pt); + } + continue; + } + if (!strcasecmp(plan.codec.data(), "red")) { + if (configure.support_red) { + answer_media.plan.emplace_back(plan); + pt_selected.emplace(plan.pt); + } + continue; + } + if (!strcasecmp(plan.codec.data(), "ulpfec")) { + if (configure.support_ulpfec) { + answer_media.plan.emplace_back(plan); + pt_selected.emplace(plan.pt); + } + continue; + } + } + } + + //对方和我方都支持的扩展,那么我们才支持 + for (auto &ext : offer_media.extmap) { + if (configure.extmap.find(RtpExt::getExtType(ext.ext)) != configure.extmap.end()) { + answer_media.extmap.emplace_back(ext); + } + } + + auto &rtcp_fb_ref = answer_media.plan[0].rtcp_fb; + rtcp_fb_ref.clear(); + //对方和我方都支持的rtcpfb,那么我们才支持 + for (auto &fp : selected_plan->rtcp_fb) { + if (configure.rtcp_fb.find(fp) != configure.rtcp_fb.end()) { + //对方该rtcp被我们支持 + rtcp_fb_ref.emplace(fp); + } + } + +#if 0 + //todo 此处为添加无效的plan,webrtc sdp通过调节plan pt顺序选择匹配的codec,意味着后面的codec其实放在sdp中是无意义的 + for (auto &plan : offer_media.plan) { + if (pt_selected.find(plan.pt) == pt_selected.end()) { + answer_media.plan.emplace_back(plan); + } + } +#endif + ret->media.emplace_back(answer_media); + return; + } + } + + if (check_profile) { + //如果是由于检查profile导致匹配失败,那么重试一次,且不检查profile + check_profile = false; + goto RETRY; + } + + if (check_codec) { + //如果是由于检查codec导致匹配失败,那么重试一次,且不检查codec + check_codec = false; + goto RETRY; + } +} + +void RtcConfigure::setPlayRtspInfo(const string &sdp){ + RtcSession session; + session.loadFrom(sdp, false); + for (auto &m : session.media) { + switch (m.type) { + case TrackVideo : { + _rtsp_video_plan = std::make_shared(m.plan[0]); + video.preferred_codec.clear(); + video.preferred_codec.emplace_back(getCodecId(_rtsp_video_plan->codec)); + break; + } + case TrackAudio : { + _rtsp_audio_plan = std::make_shared(m.plan[0]); + audio.preferred_codec.clear(); + audio.preferred_codec.emplace_back(getCodecId(_rtsp_audio_plan->codec)); + break; + } + default: break; + } + } +} + +static const string kProfile{"profile-level-id"}; +static const string kMode{"packetization-mode"}; + +bool RtcConfigure::onCheckCodecProfile(const RtcCodecPlan &plan, CodecId codec){ + if (_rtsp_audio_plan && codec == getCodecId(_rtsp_audio_plan->codec)) { + if (plan.sample_rate != _rtsp_audio_plan->sample_rate || plan.channel != _rtsp_audio_plan->channel) { + //音频采样率和通道数必须相同 + return false; + } + return true; + } + if (_rtsp_video_plan && codec == CodecH264 && getCodecId(_rtsp_video_plan->codec) == CodecH264) { + //h264时,profile-level-id + if (strcasecmp(_rtsp_video_plan->fmtp[kProfile].data(), const_cast(plan).fmtp[kProfile].data())) { + //profile-level-id 不匹配 + return false; + } + return true; + } + + return true; +} + +void RtcConfigure::onSelectPlan(RtcCodecPlan &plan, CodecId codec){ + if (_rtsp_video_plan && codec == CodecH264 && getCodecId(_rtsp_video_plan->codec) == CodecH264) { + //h264时,设置packetization-mod为一致 + auto mode = _rtsp_video_plan->fmtp[kMode]; + plan.fmtp[kMode] = mode.empty() ? "0" : mode; + } +} diff --git a/webrtc/Sdp.h b/webrtc/Sdp.h new file mode 100644 index 00000000..6ed2710a --- /dev/null +++ b/webrtc/Sdp.h @@ -0,0 +1,750 @@ +/* + * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef ZLMEDIAKIT_SDP_H +#define ZLMEDIAKIT_SDP_H + +#include +#include +#include "RtpExt.h" +#include "assert.h" +#include "Extension/Frame.h" +#include "Common/Parser.h" +using namespace std; +using namespace mediakit; + +//https://datatracker.ietf.org/doc/rfc4566/?include_text=1 +//https://blog.csdn.net/aggresss/article/details/109850434 +//https://aggresss.blog.csdn.net/article/details/106436703 +//Session description +// v= (protocol version) +// o= (originator and session identifier) +// s= (session name) +// i=* (session information) +// u=* (URI of description) +// e=* (email address) +// p=* (phone number) +// c=* (connection information -- not required if included in +// all media) +// b=* (zero or more bandwidth information lines) +// One or more time descriptions ("t=" and "r=" lines; see below) +// z=* (time zone adjustments) +// k=* (encryption key) +// a=* (zero or more session attribute lines) +// Zero or more media descriptions +// +// Time description +// t= (time the session is active) +// r=* (zero or more repeat times) +// +// Media description, if present +// m= (media name and transport address) +// i=* (media title) +// c=* (connection information -- optional if included at +// session level) +// b=* (zero or more bandwidth information lines) +// k=* (encryption key) +// a=* (zero or more media attribute lines) + +enum class RtpDirection { + invalid = -1, + //只发送 + sendonly, + //只接收 + recvonly, + //同时发送接收 + sendrecv, + //禁止发送数据 + inactive +}; + +enum class DtlsRole { + invalid = -1, + //客户端 + active, + //服务端 + passive, + //既可作做客户端也可以做服务端 + actpass, +}; + +enum class SdpType { + invalid = -1, + offer, + answer +}; + +DtlsRole getDtlsRole(const string &str); +const char* getDtlsRoleString(DtlsRole role); +RtpDirection getRtpDirection(const string &str); +const char* getRtpDirectionString(RtpDirection val); + +class SdpItem { +public: + using Ptr = std::shared_ptr; + virtual ~SdpItem() = default; + virtual void parse(const string &str) { + value = str; + } + virtual string toString() const { + return value; + } + virtual const char* getKey() const = 0; + + void reset() { + value.clear(); + } + +protected: + mutable string value; +}; + +template +class SdpString : public SdpItem{ +public: + SdpString() = default; + SdpString(string val) {value = std::move(val);} + // *=* + const char* getKey() const override { static string key(1, KEY); return key.data();} +}; + +class SdpCommon : public SdpItem { +public: + string key; + SdpCommon(string key) { this->key = std::move(key); } + SdpCommon(string key, string val) { + this->key = std::move(key); + this->value = std::move(val); + } + + const char* getKey() const override { return key.data();} +}; + +class SdpTime : public SdpItem{ +public: + //5.9. Timing ("t=") + // t= + uint64_t start {0}; + uint64_t stop {0}; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "t";} +}; + +class SdpOrigin : public SdpItem{ +public: + // 5.2. Origin ("o=") + // o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5 + // o= + string username {"-"}; + string session_id; + string session_version; + string nettype {"IN"}; + string addrtype {"IP4"}; + string address {"0.0.0.0"}; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "o";} + bool empty() const { + return username.empty() || session_id.empty() || session_version.empty() + || nettype.empty() || addrtype.empty() || address.empty(); + } +}; + +class SdpConnection : public SdpItem { +public: + // 5.7. Connection Data ("c=") + // c=IN IP4 224.2.17.12/127 + // c= + string nettype {"IN"}; + string addrtype {"IP4"}; + string address {"0.0.0.0"}; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "c";} + bool empty() const {return address.empty();} +}; + +class SdpBandwidth : public SdpItem { +public: + //5.8. Bandwidth ("b=") + //b=: + + //AS、CT + string bwtype {"AS"}; + uint32_t bandwidth {0}; + + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "b";} + bool empty() const {return bandwidth == 0;} +}; + +class SdpMedia : public SdpItem { +public: + // 5.14. Media Descriptions ("m=") + // m= ... + TrackType type; + uint16_t port; + //RTP/AVP:应用场景为视频/音频的 RTP 协议。参考 RFC 3551 + //RTP/SAVP:应用场景为视频/音频的 SRTP 协议。参考 RFC 3711 + //RTP/AVPF: 应用场景为视频/音频的 RTP 协议,支持 RTCP-based Feedback。参考 RFC 4585 + //RTP/SAVPF: 应用场景为视频/音频的 SRTP 协议,支持 RTCP-based Feedback。参考 RFC 5124 + string proto; + vector fmts; + + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "m";} +}; + +class SdpAttr : public SdpItem{ +public: + using Ptr = std::shared_ptr; + //5.13. Attributes ("a=") + //a= + //a=: + SdpItem::Ptr detail; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "a";} +}; + +class SdpAttrGroup : public SdpItem{ +public: + //a=group:BUNDLE line with all the 'mid' identifiers part of the + // BUNDLE group is included at the session-level. + //a=group:LS session level attribute MUST be included wth the 'mid' + // identifiers that are part of the same lip sync group. + string type {"BUNDLE"}; + vector mids; + void parse(const string &str) override ; + string toString() const override ; + const char* getKey() const override { return "group";} +}; + +class SdpAttrMsidSemantic : public SdpItem { +public: + //https://tools.ietf.org/html/draft-alvestrand-rtcweb-msid-02#section-3 + //3. The Msid-Semantic Attribute + // + // In order to fully reproduce the semantics of the SDP and SSRC + // grouping frameworks, a session-level attribute is defined for + // signalling the semantics associated with an msid grouping. + // + // This OPTIONAL attribute gives the message ID and its group semantic. + // a=msid-semantic: examplefoo LS + // + // + // The ABNF of msid-semantic is: + // + // msid-semantic-attr = "msid-semantic:" " " msid token + // token = + // + // The semantic field may hold values from the IANA registries + // "Semantics for the "ssrc-group" SDP Attribute" and "Semantics for the + // "group" SDP Attribute". + //a=msid-semantic: WMS 616cfbb1-33a3-4d8c-8275-a199d6005549 + string msid{"WMS"}; + string token; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "msid-semantic";} + bool empty() const { + return msid.empty(); + } +}; + +class SdpAttrRtcp : public SdpItem { +public: + // a=rtcp:9 IN IP4 0.0.0.0 + uint16_t port{0}; + string nettype {"IN"}; + string addrtype {"IP4"}; + string address {"0.0.0.0"}; + void parse(const string &str) override;; + string toString() const override; + const char* getKey() const override { return "rtcp";} + bool empty() const { + return address.empty() || !port; + } +}; + +class SdpAttrIceUfrag : public SdpItem { +public: + SdpAttrIceUfrag() = default; + SdpAttrIceUfrag(string str) {value = std::move(str);} + //a=ice-ufrag:sXJ3 + const char* getKey() const override { return "ice-ufrag";} +}; + +class SdpAttrIcePwd : public SdpItem { +public: + SdpAttrIcePwd() = default; + SdpAttrIcePwd(string str) {value = std::move(str);} + //a=ice-pwd:yEclOTrLg1gEubBFefOqtmyV + const char* getKey() const override { return "ice-pwd";} +}; + +class SdpAttrIceOption : public SdpItem { +public: + //a=ice-options:trickle + bool trickle{false}; + bool renomination{false}; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "ice-options";} +}; + +class SdpAttrFingerprint : public SdpItem { +public: + //a=fingerprint:sha-256 22:14:B5:AF:66:12:C7:C7:8D:EF:4B:DE:40:25:ED:5D:8F:17:54:DD:88:33:C0:13:2E:FD:1A:FA:7E:7A:1B:79 + string algorithm; + string hash; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "fingerprint";} + bool empty() const { return algorithm.empty() || hash.empty(); } +}; + +class SdpAttrSetup : public SdpItem { +public: + //a=setup:actpass + SdpAttrSetup() = default; + SdpAttrSetup(DtlsRole r) { role = r; } + DtlsRole role{DtlsRole::actpass}; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "setup";} +}; + +class SdpAttrMid : public SdpItem { +public: + SdpAttrMid() = default; + SdpAttrMid(string val) { value = std::move(val); } + //a=mid:audio + const char* getKey() const override { return "mid";} +}; + +class SdpAttrExtmap : public SdpItem { +public: + //https://aggresss.blog.csdn.net/article/details/106436703 + //a=extmap:1[/sendonly] urn:ietf:params:rtp-hdrext:ssrc-audio-level + uint8_t id; + RtpDirection direction{RtpDirection::invalid}; + string ext; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "extmap";} +}; + +class SdpAttrRtpMap : public SdpItem { +public: + //a=rtpmap:111 opus/48000/2 + uint8_t pt; + string codec; + uint32_t sample_rate; + uint32_t channel {0}; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "rtpmap";} +}; + +class SdpAttrRtcpFb : public SdpItem { +public: + //a=rtcp-fb:98 nack pli + //a=rtcp-fb:120 nack 支持 nack 重传,nack (Negative-Acknowledgment) 。 + //a=rtcp-fb:120 nack pli 支持 nack 关键帧重传,PLI (Picture Loss Indication) 。 + //a=rtcp-fb:120 ccm fir 支持编码层关键帧请求,CCM (Codec Control Message),FIR (Full Intra Request ),通常与 nack pli 有同样的效果,但是 nack pli 是用于重传时的关键帧请求。 + //a=rtcp-fb:120 goog-remb 支持 REMB (Receiver Estimated Maximum Bitrate) 。 + //a=rtcp-fb:120 transport-cc 支持 TCC (Transport Congest Control) 。 + uint8_t pt; + string rtcp_type; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "rtcp-fb";} +}; + +class SdpAttrFmtp : public SdpItem { +public: + //fmtp:96 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f + uint8_t pt; + map fmtp; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "fmtp";} +}; + +class SdpAttrSSRC : public SdpItem { +public: + //a=ssrc:3245185839 cname:Cx4i/VTR51etgjT7 + //a=ssrc:3245185839 msid:cb373bff-0fea-4edb-bc39-e49bb8e8e3b9 0cf7e597-36a2-4480-9796-69bf0955eef5 + //a=ssrc:3245185839 mslabel:cb373bff-0fea-4edb-bc39-e49bb8e8e3b9 + //a=ssrc:3245185839 label:0cf7e597-36a2-4480-9796-69bf0955eef5 + //a=ssrc: + //a=ssrc: : + //cname 是必须的,msid/mslabel/label 这三个属性都是 WebRTC 自创的,或者说 Google 自创的,可以参考 https://tools.ietf.org/html/draft-ietf-mmusic-msid-17, + // 理解它们三者的关系需要先了解三个概念:RTP stream / MediaStreamTrack / MediaStream : + //一个 a=ssrc 代表一个 RTP stream ; + //一个 MediaStreamTrack 通常包含一个或多个 RTP stream,例如一个视频 MediaStreamTrack 中通常包含两个 RTP stream,一个用于常规传输,一个用于 nack 重传; + //一个 MediaStream 通常包含一个或多个 MediaStreamTrack ,例如 simulcast 场景下,一个 MediaStream 通常会包含三个不同编码质量的 MediaStreamTrack ; + //这种标记方式并不被 Firefox 认可,在 Firefox 生成的 SDP 中一个 a=ssrc 通常只有一行,例如: + //a=ssrc:3245185839 cname:Cx4i/VTR51etgjT7 + + uint32_t ssrc; + string attribute; + string attribute_value; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "ssrc";} +}; + +class SdpAttrSSRCGroup : public SdpItem { +public: + //a=ssrc-group 定义参考 RFC 5576(https://tools.ietf.org/html/rfc5576) ,用于描述多个 ssrc 之间的关联,常见的有两种: + //a=ssrc-group:FID 2430709021 3715850271 + // FID (Flow Identification) 最初用在 FEC 的关联中,WebRTC 中通常用于关联一组常规 RTP stream 和 重传 RTP stream 。 + //a=ssrc-group:SIM 360918977 360918978 360918980 + // 在 Chrome 独有的 SDP munging 风格的 simulcast 中使用,将三组编码质量由低到高的 MediaStreamTrack 关联在一起。 + string type{"FID"}; + vector ssrcs; + + bool isFID() const { return type == "FID"; } + bool isSIM() const { return type == "SIM"; } + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "ssrc-group";} +}; + +class SdpAttrSctpMap : public SdpItem { +public: + //https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-05 + //a=sctpmap:5000 webrtc-datachannel 1024 + //a=sctpmap: sctpmap-number media-subtypes [streams] + uint16_t port; + string subtypes; + uint32_t streams; + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "sctpmap";} +}; + +class SdpAttrCandidate : public SdpItem { +public: + using Ptr = std::shared_ptr; + //https://tools.ietf.org/html/rfc5245 + //15.1. "candidate" Attribute + //a=candidate:4 1 udp 2 192.168.1.7 58107 typ host + //a=candidate:
typ + string foundation; + //传输媒体的类型,1代表RTP;2代表 RTCP。 + uint32_t component; + string transport {"udp"}; + uint32_t priority; + string address; + uint16_t port; + string type; + vector > arr; + + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "candidate";} +}; + +class SdpAttrMsid : public SdpItem{ +public: + const char* getKey() const override { return "msid";} +}; + +class SdpAttrExtmapAllowMixed : public SdpItem{ +public: + const char* getKey() const override { return "extmap-allow-mixed";} +}; + +class SdpAttrSimulcast : public SdpItem{ +public: + //https://www.meetecho.com/blog/simulcast-janus-ssrc/ + //https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-14 + const char* getKey() const override { return "simulcast";} + void parse(const string &str) override; + string toString() const override; + bool empty() const { return rids.empty(); } + string direction; + vector rids; +}; + +class SdpAttrRid : public SdpItem{ +public: + void parse(const string &str) override; + string toString() const override; + const char* getKey() const override { return "rid";} + string direction; + string rid; +}; + +class RtcSdpBase { +public: + vector items; + +public: + virtual ~RtcSdpBase() = default; + virtual string toString() const; + + int getVersion() const; + SdpOrigin getOrigin() const; + string getSessionName() const; + string getSessionInfo() const; + SdpTime getSessionTime() const; + SdpConnection getConnection() const; + SdpBandwidth getBandwidth() const; + + string getUri() const; + string getEmail() const; + string getPhone() const; + string getTimeZone() const; + string getEncryptKey() const; + string getRepeatTimes() const; + RtpDirection getDirection() const; + + template + cls getItemClass(char key, const char *attr_key = nullptr) const{ + auto item = dynamic_pointer_cast(getItem(key, attr_key)); + if (!item) { + return cls(); + } + return *item; + } + + string getStringItem(char key, const char *attr_key = nullptr) const{ + auto item = getItem(key, attr_key); + if (!item) { + return ""; + } + return item->toString(); + } + + SdpItem::Ptr getItem(char key, const char *attr_key = nullptr) const; + + template + vector getAllItem(char key_c, const char *attr_key = nullptr) const { + vector ret; + for (auto item : items) { + string key(1, key_c); + if (strcasecmp(item->getKey(), key.data()) == 0) { + if (!attr_key) { + auto c = dynamic_pointer_cast(item); + if (c) { + ret.emplace_back(*c); + } + } else { + auto attr = dynamic_pointer_cast(item); + if (attr && !strcasecmp(attr->detail->getKey(), attr_key)) { + auto c = dynamic_pointer_cast(attr->detail); + if (c) { + ret.emplace_back(*c); + } + } + } + } + } + return ret; + } +}; + +class RtcSessionSdp : public RtcSdpBase{ +public: + using Ptr = std::shared_ptr; + + vector medias; + void parse(const string &str); + string toString() const override; +}; + +////////////////////////////////////////////////////////////////// + +//ssrc相关信息 +class RtcSSRC{ +public: + uint32_t ssrc {0}; + string cname; + string msid; + string mslabel; + string label; + + bool empty() const {return ssrc == 0 && cname.empty();} +}; + +//rtc传输编码方案 +class RtcCodecPlan{ +public: + using Ptr = shared_ptr; + uint8_t pt; + string codec; + uint32_t sample_rate; + //音频时有效 + uint32_t channel = 0; + //rtcp反馈 + set rtcp_fb; + map fmtp; + + string getFmtp(const char *key) const; +}; + +//rtc 媒体描述 +class RtcMedia{ +public: + TrackType type{TrackType::TrackInvalid}; + string mid; + uint16_t port{0}; + SdpConnection addr; + string proto; + RtpDirection direction{RtpDirection::invalid}; + vector plan; + + //////// rtp //////// + vector rtp_rtx_ssrc; + + //////// simulcast //////// + vector rtp_ssrc_sim; + vector rtp_rids; + + //////// rtcp //////// + bool rtcp_mux{false}; + bool rtcp_rsize{false}; + SdpAttrRtcp rtcp_addr; + + //////// ice //////// + bool ice_trickle{false}; + bool ice_lite{false}; + bool ice_renomination{false}; + string ice_ufrag; + string ice_pwd; + std::vector candidate; + + //////// dtls //////// + DtlsRole role{DtlsRole::invalid}; + SdpAttrFingerprint fingerprint; + + //////// extmap //////// + vector extmap; + + //////// sctp //////////// + SdpAttrSctpMap sctpmap; + uint32_t sctp_port{0}; + + void checkValid() const; + //offer sdp,如果指定了发送rtp,那么应该指定ssrc + void checkValidSSRC() const; + const RtcCodecPlan *getPlan(uint8_t pt) const; + const RtcCodecPlan *getPlan(const char *codec) const; + const RtcCodecPlan *getRelatedRtxPlan(uint8_t pt) const; + uint32_t getRtpSSRC() const; + uint32_t getRtxSSRC() const; +}; + +class RtcSession{ +public: + using Ptr = std::shared_ptr; + + uint32_t version; + SdpOrigin origin; + string session_name; + string session_info; + SdpTime time; + SdpConnection connection; + SdpBandwidth bandwidth; + SdpAttrMsidSemantic msid_semantic; + vector media; + SdpAttrGroup group; + + void loadFrom(const string &sdp, bool check = true); + void checkValid() const; + //offer sdp,如果指定了发送rtp,那么应该指定ssrc + void checkValidSSRC() const; + string toString() const; + string toRtspSdp() const; + const RtcMedia *getMedia(TrackType type) const; + bool haveSSRC() const; + bool supportRtcpFb(const string &name, TrackType type = TrackType::TrackVideo) const; + +private: + RtcSessionSdp::Ptr toRtcSessionSdp() const; +}; + +class RtcConfigure { +public: + using Ptr = std::shared_ptr; + class RtcTrackConfigure { + public: + bool enable; + bool rtcp_mux; + bool rtcp_rsize; + bool group_bundle; + bool support_rtx; + bool support_red; + bool support_ulpfec; + bool ice_lite; + bool ice_trickle; + bool ice_renomination; + string ice_ufrag; + string ice_pwd; + + RtpDirection direction{RtpDirection::invalid}; + SdpAttrFingerprint fingerprint; + + set rtcp_fb; + set extmap; + vector preferred_codec; + vector candidate; + + void setDefaultSetting(TrackType type); + void enableTWCC(bool enable = true); + void enableREMB(bool enable = true); + }; + + RtcTrackConfigure video; + RtcTrackConfigure audio; + RtcTrackConfigure application; + + void setDefaultSetting(string ice_ufrag, + string ice_pwd, + RtpDirection direction, + const SdpAttrFingerprint &fingerprint); + void addCandidate(const SdpAttrCandidate &candidate, TrackType type = TrackInvalid); + + shared_ptr createAnswer(const RtcSession &offer); + + void setPlayRtspInfo(const string &sdp); + + void enableTWCC(bool enable = true, TrackType type = TrackInvalid); + void enableREMB(bool enable = true, TrackType type = TrackInvalid); + +private: + void matchMedia(shared_ptr &ret, TrackType type, const vector &medias, const RtcTrackConfigure &configure); + bool onCheckCodecProfile(const RtcCodecPlan &plan, CodecId codec); + void onSelectPlan(RtcCodecPlan &plan, CodecId codec); + +private: + RtcCodecPlan::Ptr _rtsp_video_plan; + RtcCodecPlan::Ptr _rtsp_audio_plan; +}; + +class SdpConst { +public: + static string const kTWCCRtcpFb; + static string const kRembRtcpFb; + +private: + SdpConst() = delete; + ~SdpConst() = delete; +}; + + +#endif //ZLMEDIAKIT_SDP_H diff --git a/webrtc/SrtpSession.cpp b/webrtc/SrtpSession.cpp new file mode 100644 index 00000000..7aa109c1 --- /dev/null +++ b/webrtc/SrtpSession.cpp @@ -0,0 +1,299 @@ +/** +ISC License + +Copyright © 2015, Iñaki Baz Castillo + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define MS_CLASS "RTC::SrtpSession" +// #define MS_LOG_DEV_LEVEL 3 + +#include "SrtpSession.hpp" +#include // std::memset(), std::memcpy() +#include "logger.h" +#include "Util/util.h" +#include "Util/logger.h" +using namespace toolkit; + +namespace RTC +{ + /* Static. */ + + static std::vector errors = { + // From 0 (srtp_err_status_ok) to 24 (srtp_err_status_pfkey_err). + "success (srtp_err_status_ok)", + "unspecified failure (srtp_err_status_fail)", + "unsupported parameter (srtp_err_status_bad_param)", + "couldn't allocate memory (srtp_err_status_alloc_fail)", + "couldn't deallocate memory (srtp_err_status_dealloc_fail)", + "couldn't initialize (srtp_err_status_init_fail)", + "can’t process as much data as requested (srtp_err_status_terminus)", + "authentication failure (srtp_err_status_auth_fail)", + "cipher failure (srtp_err_status_cipher_fail)", + "replay check failed (bad index) (srtp_err_status_replay_fail)", + "replay check failed (index too old) (srtp_err_status_replay_old)", + "algorithm failed test routine (srtp_err_status_algo_fail)", + "unsupported operation (srtp_err_status_no_such_op)", + "no appropriate context found (srtp_err_status_no_ctx)", + "unable to perform desired validation (srtp_err_status_cant_check)", + "can’t use key any more (srtp_err_status_key_expired)", + "error in use of socket (srtp_err_status_socket_err)", + "error in use POSIX signals (srtp_err_status_signal_err)", + "nonce check failed (srtp_err_status_nonce_bad)", + "couldn’t read data (srtp_err_status_read_fail)", + "couldn’t write data (srtp_err_status_write_fail)", + "error parsing data (srtp_err_status_parse_err)", + "error encoding data (srtp_err_status_encode_err)", + "error while using semaphores (srtp_err_status_semaphore_err)", + "error while using pfkey (srtp_err_status_pfkey_err)"}; +// clang-format on + +/* Static methods. */ + + const char *DepLibSRTP::GetErrorString(srtp_err_status_t code) { + // This throws out_of_range if the given index is not in the vector. + return errors.at(code); + } + + bool DepLibSRTP::IsError(srtp_err_status_t code) { + return (code != srtp_err_status_ok); + } + + INSTANCE_IMP(DepLibSRTP); + + DepLibSRTP::DepLibSRTP(){ + MS_TRACE(); + + MS_DEBUG_TAG(info, "libsrtp version: \"%s\"", srtp_get_version_string()); + + srtp_err_status_t err = srtp_init(); + +#if 0 + srtp_install_log_handler([](srtp_log_level_t level, + const char *msg, + void *data) { + printf("%s\n", msg); + }, nullptr); + srtp_set_debug_module("srtp", 1); + srtp_set_debug_module("hmac sha-1", 1); + srtp_set_debug_module("aes icm", 1); + srtp_set_debug_module("alloc", 1); + srtp_set_debug_module("stat test", 1); + srtp_set_debug_module("cipher", 1); + srtp_set_debug_module("auth func", 1); + srtp_set_debug_module("crypto kernel", 1); + srtp_list_debug_modules(); +#endif + + if (DepLibSRTP::IsError(err)) { + MS_THROW_ERROR("srtp_init() failed: %s", DepLibSRTP::GetErrorString(err)); + } + + // Set libsrtp event handler. + err = srtp_install_event_handler([](srtp_event_data_t *data){ + MS_TRACE(); + switch (data->event) + { + case event_ssrc_collision: + MS_WARN_TAG(srtp, "SSRC collision occurred"); + break; + + case event_key_soft_limit: + MS_WARN_TAG(srtp, "stream reached the soft key usage limit and will expire soon"); + break; + + case event_key_hard_limit: + MS_WARN_TAG(srtp, "stream reached the hard key usage limit and has expired"); + break; + + case event_packet_index_limit: + MS_WARN_TAG(srtp, "stream reached the hard packet limit (2^48 packets)"); + break; + } + }); + + if (DepLibSRTP::IsError(err)) + { + MS_THROW_ERROR("srtp_install_event_handler() failed: %s", DepLibSRTP::GetErrorString(err)); + } + } + + DepLibSRTP::~DepLibSRTP(){ + MS_TRACE(); + srtp_shutdown(); + } + + ///////////////////////////////////////////////////////////////////////////////////// + + /* Instance methods. */ + + SrtpSession::SrtpSession(Type type, CryptoSuite cryptoSuite, uint8_t* key, size_t keyLen) + { + _env = DepLibSRTP::Instance().shared_from_this(); + MS_TRACE(); + + srtp_policy_t policy; // NOLINT(cppcoreguidelines-pro-type-member-init) + + // Set all policy fields to 0. + std::memset(&policy, 0, sizeof(srtp_policy_t)); + + switch (cryptoSuite) + { + case CryptoSuite::AES_CM_128_HMAC_SHA1_80: + { + srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp); + srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); + + break; + } + + case CryptoSuite::AES_CM_128_HMAC_SHA1_32: + { + srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp); + // NOTE: Must be 80 for RTCP. + srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); + + break; + } + + case CryptoSuite::AEAD_AES_256_GCM: + { + srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtp); + srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtcp); + + break; + } + + case CryptoSuite::AEAD_AES_128_GCM: + { + srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtp); + srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtcp); + + break; + } + + default: + { + MS_ABORT("unknown SRTP crypto suite"); + } + } + + MS_ASSERT( + (int)keyLen == policy.rtp.cipher_key_len, + "given keyLen does not match policy.rtp.cipher_keyLen"); + + switch (type) + { + case Type::INBOUND: + policy.ssrc.type = ssrc_any_inbound; + break; + + case Type::OUTBOUND: + policy.ssrc.type = ssrc_any_outbound; + break; + } + + policy.ssrc.value = 0; + policy.key = key; + // Required for sending RTP retransmission without RTX. + policy.allow_repeat_tx = 1; + policy.window_size = 1024; + policy.next = nullptr; + + // Set the SRTP session. + srtp_err_status_t err = srtp_create(&this->session, &policy); + + if (DepLibSRTP::IsError(err)) + MS_THROW_ERROR("srtp_create() failed: %s", DepLibSRTP::GetErrorString(err)); + } + + SrtpSession::~SrtpSession() + { + MS_TRACE(); + + if (this->session != nullptr) + { + srtp_err_status_t err = srtp_dealloc(this->session); + + if (DepLibSRTP::IsError(err)) + MS_ABORT("srtp_dealloc() failed: %s", DepLibSRTP::GetErrorString(err)); + } + } + + bool SrtpSession::EncryptRtp(uint8_t* data, size_t* len) + { + MS_TRACE(); + srtp_err_status_t err = + srtp_protect(this->session, static_cast(data), reinterpret_cast(len)); + + if (DepLibSRTP::IsError(err)) + { + MS_WARN_TAG(srtp, "srtp_protect() failed: %s", DepLibSRTP::GetErrorString(err)); + + return false; + } + + return true; + } + + bool SrtpSession::DecryptSrtp(uint8_t* data, size_t* len) + { + MS_TRACE(); + + srtp_err_status_t err = + srtp_unprotect(this->session, static_cast(data), reinterpret_cast(len)); + + if (DepLibSRTP::IsError(err)) + { + MS_DEBUG_TAG(srtp, "srtp_unprotect() failed: %s", DepLibSRTP::GetErrorString(err)); + + return false; + } + + return true; + } + + bool SrtpSession::EncryptRtcp(uint8_t* data, size_t* len) + { + MS_TRACE(); + srtp_err_status_t err = srtp_protect_rtcp( + this->session, static_cast(data), reinterpret_cast(len)); + + if (DepLibSRTP::IsError(err)) + { + MS_WARN_TAG(srtp, "srtp_protect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err)); + + return false; + } + + return true; + } + + bool SrtpSession::DecryptSrtcp(uint8_t* data, size_t* len) + { + MS_TRACE(); + + srtp_err_status_t err = + srtp_unprotect_rtcp(this->session, static_cast(data), reinterpret_cast(len)); + + if (DepLibSRTP::IsError(err)) + { + MS_DEBUG_TAG(srtp, "srtp_unprotect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err)); + + return false; + } + + return true; + } +} // namespace RTC diff --git a/webrtc/SrtpSession.hpp b/webrtc/SrtpSession.hpp new file mode 100644 index 00000000..a50684e5 --- /dev/null +++ b/webrtc/SrtpSession.hpp @@ -0,0 +1,83 @@ +/** +ISC License + +Copyright © 2015, Iñaki Baz Castillo + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MS_RTC_SRTP_SESSION_HPP +#define MS_RTC_SRTP_SESSION_HPP + +#include "Utils.hpp" +#include +#include +#include + +namespace RTC +{ + class DepLibSRTP : public std::enable_shared_from_this + { + public: + using Ptr = std::shared_ptr; + ~DepLibSRTP(); + + static bool IsError(srtp_err_status_t code); + static const char *GetErrorString(srtp_err_status_t code); + static DepLibSRTP &Instance(); + + private: + DepLibSRTP(); + }; + + class SrtpSession + { + public: + enum class CryptoSuite + { + NONE = 0, + AES_CM_128_HMAC_SHA1_80 = 1, + AES_CM_128_HMAC_SHA1_32, + AEAD_AES_256_GCM, + AEAD_AES_128_GCM + }; + + public: + enum class Type + { + INBOUND = 1, + OUTBOUND + }; + + public: + SrtpSession(Type type, CryptoSuite cryptoSuite, uint8_t* key, size_t keyLen); + ~SrtpSession(); + + public: + bool EncryptRtp(uint8_t* data, size_t* len); + bool DecryptSrtp(uint8_t* data, size_t* len); + bool EncryptRtcp(uint8_t* data, size_t* len); + bool DecryptSrtcp(uint8_t* data, size_t* len); + void RemoveStream(uint32_t ssrc) + { + srtp_remove_stream(this->session, uint32_t{ htonl(ssrc) }); + } + + private: + // Allocated by this. + srtp_t session{ nullptr }; + DepLibSRTP::Ptr _env; + }; +} // namespace RTC + +#endif diff --git a/webrtc/StunPacket.cpp b/webrtc/StunPacket.cpp new file mode 100644 index 00000000..50120a70 --- /dev/null +++ b/webrtc/StunPacket.cpp @@ -0,0 +1,880 @@ +/** +ISC License + +Copyright © 2015, Iñaki Baz Castillo + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define MS_CLASS "RTC::StunPacket" +// #define MS_LOG_DEV_LEVEL 3 + +#include "StunPacket.hpp" +#include // std::snprintf() +#include // std::memcmp(), std::memcpy() + +namespace RTC +{ + static const uint32_t crc32Table[] = + { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d + }; + + inline uint32_t GetCRC32(const uint8_t *data, size_t size) { + uint32_t crc{0xFFFFFFFF}; + const uint8_t *p = data; + + while (size--) { + crc = crc32Table[(crc ^ *p++) & 0xFF] ^ (crc >> 8); + } + + return crc ^ ~0U; + } + + static std::string openssl_HMACsha1(const void *key, size_t key_len, const void *data, size_t data_len){ + std::string str; + str.resize(20); + unsigned int out_len; +#if defined(OPENSSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER > 0x10100000L) + //openssl 1.1.0新增api,老版本api作废 + HMAC_CTX *ctx = HMAC_CTX_new(); + HMAC_CTX_reset(ctx); + HMAC_Init_ex(ctx, key, (int)key_len, EVP_sha1(), NULL); + HMAC_Update(ctx, (unsigned char*)data, data_len); + HMAC_Final(ctx, (unsigned char *)str.data(), &out_len); + HMAC_CTX_reset(ctx); + HMAC_CTX_free(ctx); +#else + HMAC_CTX ctx; + HMAC_CTX_init(&ctx); + HMAC_Init_ex(&ctx, key, key_len, EVP_sha1(), NULL); + HMAC_Update(&ctx, (unsigned char*)data, data_len); + HMAC_Final(&ctx, (unsigned char *)str.data(), &out_len); + HMAC_CTX_cleanup(&ctx); +#endif //defined(OPENSSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER > 0x10100000L) + return str; + } + + /* Class variables. */ + + const uint8_t StunPacket::magicCookie[] = { 0x21, 0x12, 0xA4, 0x42 }; + + /* Class methods. */ + + StunPacket* StunPacket::Parse(const uint8_t* data, size_t len) + { + MS_TRACE(); + + if (!StunPacket::IsStun(data, len)) + return nullptr; + + /* + The message type field is decomposed further into the following + structure: + + 0 1 + 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ + |M |M |M|M|M|C|M|M|M|C|M|M|M|M| + |11|10|9|8|7|1|6|5|4|0|3|2|1|0| + +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ + + Figure 3: Format of STUN Message Type Field + + Here the bits in the message type field are shown as most significant + (M11) through least significant (M0). M11 through M0 represent a 12- + bit encoding of the method. C1 and C0 represent a 2-bit encoding of + the class. + */ + + // Get type field. + uint16_t msgType = Utils::Byte::Get2Bytes(data, 0); + + // Get length field. + uint16_t msgLength = Utils::Byte::Get2Bytes(data, 2); + + // length field must be total size minus header's 20 bytes, and must be multiple of 4 Bytes. + if ((static_cast(msgLength) != len - 20) || ((msgLength & 0x03) != 0)) + { + MS_WARN_TAG( + ice, + "length field + 20 does not match total size (or it is not multiple of 4 bytes), " + "packet discarded"); + + return nullptr; + } + + // Get STUN method. + uint16_t msgMethod = (msgType & 0x000f) | ((msgType & 0x00e0) >> 1) | ((msgType & 0x3E00) >> 2); + + // Get STUN class. + uint16_t msgClass = ((data[0] & 0x01) << 1) | ((data[1] & 0x10) >> 4); + + // Create a new StunPacket (data + 8 points to the received TransactionID field). + auto* packet = new StunPacket( + static_cast(msgClass), static_cast(msgMethod), data + 8, data, len); + + /* + STUN Attributes + + After the STUN header are zero or more attributes. Each attribute + MUST be TLV encoded, with a 16-bit type, 16-bit length, and value. + Each STUN attribute MUST end on a 32-bit boundary. As mentioned + above, all fields in an attribute are transmitted most significant + bit first. + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type | Length | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Value (variable) .... + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + + // Start looking for attributes after STUN header (Byte #20). + size_t pos{ 20 }; + // Flags (positions) for special MESSAGE-INTEGRITY and FINGERPRINT attributes. + bool hasMessageIntegrity{ false }; + bool hasFingerprint{ false }; + size_t fingerprintAttrPos; // Will point to the beginning of the attribute. + uint32_t fingerprint; // Holds the value of the FINGERPRINT attribute. + + // Ensure there are at least 4 remaining bytes (attribute with 0 length). + while (pos + 4 <= len) + { + // Get the attribute type. + auto attrType = static_cast(Utils::Byte::Get2Bytes(data, pos)); + + // Get the attribute length. + uint16_t attrLength = Utils::Byte::Get2Bytes(data, pos + 2); + + // Ensure the attribute length is not greater than the remaining size. + if ((pos + 4 + attrLength) > len) + { + MS_WARN_TAG(ice, "the attribute length exceeds the remaining size, packet discarded"); + + delete packet; + return nullptr; + } + + // FINGERPRINT must be the last attribute. + if (hasFingerprint) + { + MS_WARN_TAG(ice, "attribute after FINGERPRINT is not allowed, packet discarded"); + + delete packet; + return nullptr; + } + + // After a MESSAGE-INTEGRITY attribute just FINGERPRINT is allowed. + if (hasMessageIntegrity && attrType != Attribute::FINGERPRINT) + { + MS_WARN_TAG( + ice, + "attribute after MESSAGE-INTEGRITY other than FINGERPRINT is not allowed, " + "packet discarded"); + + delete packet; + return nullptr; + } + + const uint8_t* attrValuePos = data + pos + 4; + + switch (attrType) + { + case Attribute::USERNAME: + { + packet->SetUsername( + reinterpret_cast(attrValuePos), static_cast(attrLength)); + + break; + } + + case Attribute::PRIORITY: + { + // Ensure attribute length is 4 bytes. + if (attrLength != 4) + { + MS_WARN_TAG(ice, "attribute PRIORITY must be 4 bytes length, packet discarded"); + + delete packet; + return nullptr; + } + + packet->SetPriority(Utils::Byte::Get4Bytes(attrValuePos, 0)); + + break; + } + + case Attribute::ICE_CONTROLLING: + { + // Ensure attribute length is 8 bytes. + if (attrLength != 8) + { + MS_WARN_TAG(ice, "attribute ICE-CONTROLLING must be 8 bytes length, packet discarded"); + + delete packet; + return nullptr; + } + + packet->SetIceControlling(Utils::Byte::Get8Bytes(attrValuePos, 0)); + + break; + } + + case Attribute::ICE_CONTROLLED: + { + // Ensure attribute length is 8 bytes. + if (attrLength != 8) + { + MS_WARN_TAG(ice, "attribute ICE-CONTROLLED must be 8 bytes length, packet discarded"); + + delete packet; + return nullptr; + } + + packet->SetIceControlled(Utils::Byte::Get8Bytes(attrValuePos, 0)); + + break; + } + + case Attribute::USE_CANDIDATE: + { + // Ensure attribute length is 0 bytes. + if (attrLength != 0) + { + MS_WARN_TAG(ice, "attribute USE-CANDIDATE must be 0 bytes length, packet discarded"); + + delete packet; + return nullptr; + } + + packet->SetUseCandidate(); + + break; + } + + case Attribute::MESSAGE_INTEGRITY: + { + // Ensure attribute length is 20 bytes. + if (attrLength != 20) + { + MS_WARN_TAG(ice, "attribute MESSAGE-INTEGRITY must be 20 bytes length, packet discarded"); + + delete packet; + return nullptr; + } + + hasMessageIntegrity = true; + packet->SetMessageIntegrity(attrValuePos); + + break; + } + + case Attribute::FINGERPRINT: + { + // Ensure attribute length is 4 bytes. + if (attrLength != 4) + { + MS_WARN_TAG(ice, "attribute FINGERPRINT must be 4 bytes length, packet discarded"); + + delete packet; + return nullptr; + } + + hasFingerprint = true; + fingerprintAttrPos = pos; + fingerprint = Utils::Byte::Get4Bytes(attrValuePos, 0); + packet->SetFingerprint(); + + break; + } + + case Attribute::ERROR_CODE: + { + // Ensure attribute length >= 4bytes. + if (attrLength < 4) + { + MS_WARN_TAG(ice, "attribute ERROR-CODE must be >= 4bytes length, packet discarded"); + + delete packet; + return nullptr; + } + + uint8_t errorClass = Utils::Byte::Get1Byte(attrValuePos, 2); + uint8_t errorNumber = Utils::Byte::Get1Byte(attrValuePos, 3); + auto errorCode = static_cast(errorClass * 100 + errorNumber); + + packet->SetErrorCode(errorCode); + + break; + } + + default:; + } + + // Set next attribute position. + pos = + static_cast(Utils::Byte::PadTo4Bytes(static_cast(pos + 4 + attrLength))); + } + + // Ensure current position matches the total length. + if (pos != len) + { + MS_WARN_TAG(ice, "computed packet size does not match total size, packet discarded"); + + delete packet; + return nullptr; + } + + // If it has FINGERPRINT attribute then verify it. + if (hasFingerprint) + { + // Compute the CRC32 of the received packet up to (but excluding) the + // FINGERPRINT attribute and XOR it with 0x5354554e. + uint32_t computedFingerprint = GetCRC32(data, fingerprintAttrPos) ^ 0x5354554e; + + // Compare with the FINGERPRINT value in the packet. + if (fingerprint != computedFingerprint) + { + MS_WARN_TAG( + ice, + "computed FINGERPRINT value does not match the value in the packet, " + "packet discarded"); + + delete packet; + return nullptr; + } + } + + return packet; + } + + /* Instance methods. */ + + StunPacket::StunPacket( + Class klass, Method method, const uint8_t* transactionId, const uint8_t* data, size_t size) + : klass(klass), method(method), transactionId(transactionId), data(const_cast(data)), + size(size) + { + MS_TRACE(); + } + + StunPacket::~StunPacket() + { + MS_TRACE(); + } + +#if 0 + void StunPacket::Dump() const + { + MS_TRACE(); + + MS_DUMP(""); + + std::string klass; + switch (this->klass) + { + case Class::REQUEST: + klass = "Request"; + break; + case Class::INDICATION: + klass = "Indication"; + break; + case Class::SUCCESS_RESPONSE: + klass = "SuccessResponse"; + break; + case Class::ERROR_RESPONSE: + klass = "ErrorResponse"; + break; + } + if (this->method == Method::BINDING) + { + MS_DUMP(" Binding %s", klass.c_str()); + } + else + { + // This prints the unknown method number. Example: TURN Allocate => 0x003. + MS_DUMP(" %s with unknown method %#.3x", klass.c_str(), static_cast(this->method)); + } + MS_DUMP(" size: %zu bytes", this->size); + + static char transactionId[25]; + + for (int i{ 0 }; i < 12; ++i) + { + // NOTE: n must be 3 because snprintf adds a \0 after printed chars. + std::snprintf(transactionId + (i * 2), 3, "%.2x", this->transactionId[i]); + } + MS_DUMP(" transactionId: %s", transactionId); + if (this->errorCode != 0u) + MS_DUMP(" errorCode: %" PRIu16, this->errorCode); + if (!this->username.empty()) + MS_DUMP(" username: %s", this->username.c_str()); + if (this->priority != 0u) + MS_DUMP(" priority: %" PRIu32, this->priority); + if (this->iceControlling != 0u) + MS_DUMP(" iceControlling: %" PRIu64, this->iceControlling); + if (this->iceControlled != 0u) + MS_DUMP(" iceControlled: %" PRIu64, this->iceControlled); + if (this->hasUseCandidate) + MS_DUMP(" useCandidate"); + if (this->xorMappedAddress != nullptr) + { + int family; + uint16_t port; + std::string ip; + + Utils::IP::GetAddressInfo(this->xorMappedAddress, family, ip, port); + + MS_DUMP(" xorMappedAddress: %s : %" PRIu16, ip.c_str(), port); + } + if (this->messageIntegrity != nullptr) + { + static char messageIntegrity[41]; + + for (int i{ 0 }; i < 20; ++i) + { + std::snprintf(messageIntegrity + (i * 2), 3, "%.2x", this->messageIntegrity[i]); + } + + MS_DUMP(" messageIntegrity: %s", messageIntegrity); + } + if (this->hasFingerprint) + MS_DUMP(" has fingerprint"); + + MS_DUMP(""); + } +#endif + + StunPacket::Authentication StunPacket::CheckAuthentication( + const std::string& localUsername, const std::string& localPassword) + { + MS_TRACE(); + + switch (this->klass) + { + case Class::REQUEST: + case Class::INDICATION: + { + // Both USERNAME and MESSAGE-INTEGRITY must be present. + if (!this->messageIntegrity || this->username.empty()) + return Authentication::BAD_REQUEST; + + // Check that USERNAME attribute begins with our local username plus ":". + size_t localUsernameLen = localUsername.length(); + + if ( + this->username.length() <= localUsernameLen || this->username.at(localUsernameLen) != ':' || + (this->username.compare(0, localUsernameLen, localUsername) != 0)) + { + return Authentication::UNAUTHORIZED; + } + + break; + } + // This method cannot check authentication in received responses (as we + // are ICE-Lite and don't generate requests). + case Class::SUCCESS_RESPONSE: + case Class::ERROR_RESPONSE: + { + MS_ERROR("cannot check authentication for a STUN response"); + + return Authentication::BAD_REQUEST; + } + } + + // If there is FINGERPRINT it must be discarded for MESSAGE-INTEGRITY calculation, + // so the header length field must be modified (and later restored). + if (this->hasFingerprint) + // Set the header length field: full size - header length (20) - FINGERPRINT length (8). + Utils::Byte::Set2Bytes(this->data, 2, static_cast(this->size - 20 - 8)); + + // Calculate the HMAC-SHA1 of the message according to MESSAGE-INTEGRITY rules. + auto computedMessageIntegrity = openssl_HMACsha1( + localPassword.data(),localPassword.size(), this->data, (this->messageIntegrity - 4) - this->data); + + Authentication result; + + // Compare the computed HMAC-SHA1 with the MESSAGE-INTEGRITY in the packet. + if (std::memcmp(this->messageIntegrity, computedMessageIntegrity.data(), computedMessageIntegrity.size()) == 0) + result = Authentication::OK; + else + result = Authentication::UNAUTHORIZED; + + // Restore the header length field. + if (this->hasFingerprint) + Utils::Byte::Set2Bytes(this->data, 2, static_cast(this->size - 20)); + + return result; + } + + StunPacket* StunPacket::CreateSuccessResponse() + { + MS_TRACE(); + + MS_ASSERT( + this->klass == Class::REQUEST, + "attempt to create a success response for a non Request STUN packet"); + + return new StunPacket(Class::SUCCESS_RESPONSE, this->method, this->transactionId, nullptr, 0); + } + + StunPacket* StunPacket::CreateErrorResponse(uint16_t errorCode) + { + MS_TRACE(); + + MS_ASSERT( + this->klass == Class::REQUEST, + "attempt to create an error response for a non Request STUN packet"); + + auto* response = + new StunPacket(Class::ERROR_RESPONSE, this->method, this->transactionId, nullptr, 0); + + response->SetErrorCode(errorCode); + + return response; + } + + void StunPacket::Authenticate(const std::string& password) + { + // Just for Request, Indication and SuccessResponse messages. + if (this->klass == Class::ERROR_RESPONSE) + { + MS_ERROR("cannot set password for ErrorResponse messages"); + + return; + } + + this->password = password; + } + + void StunPacket::Serialize(uint8_t* buffer) + { + MS_TRACE(); + + // Some useful variables. + uint16_t usernamePaddedLen{ 0 }; + uint16_t xorMappedAddressPaddedLen{ 0 }; + bool addXorMappedAddress = + ((this->xorMappedAddress != nullptr) && this->method == StunPacket::Method::BINDING && + this->klass == Class::SUCCESS_RESPONSE); + bool addErrorCode = ((this->errorCode != 0u) && this->klass == Class::ERROR_RESPONSE); + bool addMessageIntegrity = (this->klass != Class::ERROR_RESPONSE && !this->password.empty()); + bool addFingerprint{ true }; // Do always. + + // Update data pointer. + this->data = buffer; + + // First calculate the total required size for the entire packet. + this->size = 20; // Header. + + if (!this->username.empty()) + { + usernamePaddedLen = Utils::Byte::PadTo4Bytes(static_cast(this->username.length())); + this->size += 4 + usernamePaddedLen; + } + + if (this->priority != 0u) + this->size += 4 + 4; + + if (this->iceControlling != 0u) + this->size += 4 + 8; + + if (this->iceControlled != 0u) + this->size += 4 + 8; + + if (this->hasUseCandidate) + this->size += 4; + + if (addXorMappedAddress) + { + switch (this->xorMappedAddress->sa_family) + { + case AF_INET: + { + xorMappedAddressPaddedLen = 8; + this->size += 4 + 8; + + break; + } + + case AF_INET6: + { + xorMappedAddressPaddedLen = 20; + this->size += 4 + 20; + + break; + } + + default: + { + MS_ERROR("invalid inet family in XOR-MAPPED-ADDRESS attribute"); + + addXorMappedAddress = false; + } + } + } + + if (addErrorCode) + this->size += 4 + 4; + + if (addMessageIntegrity) + this->size += 4 + 20; + + if (addFingerprint) + this->size += 4 + 4; + + // Merge class and method fields into type. + uint16_t typeField = (static_cast(this->method) & 0x0f80) << 2; + + typeField |= (static_cast(this->method) & 0x0070) << 1; + typeField |= (static_cast(this->method) & 0x000f); + typeField |= (static_cast(this->klass) & 0x02) << 7; + typeField |= (static_cast(this->klass) & 0x01) << 4; + + // Set type field. + Utils::Byte::Set2Bytes(buffer, 0, typeField); + // Set length field. + Utils::Byte::Set2Bytes(buffer, 2, static_cast(this->size) - 20); + // Set magic cookie. + std::memcpy(buffer + 4, StunPacket::magicCookie, 4); + // Set TransactionId field. + std::memcpy(buffer + 8, this->transactionId, 12); + // Update the transaction ID pointer. + this->transactionId = buffer + 8; + // Add atributes. + size_t pos{ 20 }; + + // Add USERNAME. + if (usernamePaddedLen != 0u) + { + Utils::Byte::Set2Bytes(buffer, pos, static_cast(Attribute::USERNAME)); + Utils::Byte::Set2Bytes(buffer, pos + 2, static_cast(this->username.length())); + std::memcpy(buffer + pos + 4, this->username.c_str(), this->username.length()); + pos += 4 + usernamePaddedLen; + } + + // Add PRIORITY. + if (this->priority != 0u) + { + Utils::Byte::Set2Bytes(buffer, pos, static_cast(Attribute::PRIORITY)); + Utils::Byte::Set2Bytes(buffer, pos + 2, 4); + Utils::Byte::Set4Bytes(buffer, pos + 4, this->priority); + pos += 4 + 4; + } + + // Add ICE-CONTROLLING. + if (this->iceControlling != 0u) + { + Utils::Byte::Set2Bytes(buffer, pos, static_cast(Attribute::ICE_CONTROLLING)); + Utils::Byte::Set2Bytes(buffer, pos + 2, 8); + Utils::Byte::Set8Bytes(buffer, pos + 4, this->iceControlling); + pos += 4 + 8; + } + + // Add ICE-CONTROLLED. + if (this->iceControlled != 0u) + { + Utils::Byte::Set2Bytes(buffer, pos, static_cast(Attribute::ICE_CONTROLLED)); + Utils::Byte::Set2Bytes(buffer, pos + 2, 8); + Utils::Byte::Set8Bytes(buffer, pos + 4, this->iceControlled); + pos += 4 + 8; + } + + // Add USE-CANDIDATE. + if (this->hasUseCandidate) + { + Utils::Byte::Set2Bytes(buffer, pos, static_cast(Attribute::USE_CANDIDATE)); + Utils::Byte::Set2Bytes(buffer, pos + 2, 0); + pos += 4; + } + + // Add XOR-MAPPED-ADDRESS + if (addXorMappedAddress) + { + Utils::Byte::Set2Bytes(buffer, pos, static_cast(Attribute::XOR_MAPPED_ADDRESS)); + Utils::Byte::Set2Bytes(buffer, pos + 2, xorMappedAddressPaddedLen); + + uint8_t* attrValue = buffer + pos + 4; + + switch (this->xorMappedAddress->sa_family) + { + case AF_INET: + { + // Set first byte to 0. + attrValue[0] = 0; + // Set inet family. + attrValue[1] = 0x01; + // Set port and XOR it. + std::memcpy( + attrValue + 2, + &(reinterpret_cast(this->xorMappedAddress))->sin_port, + 2); + attrValue[2] ^= StunPacket::magicCookie[0]; + attrValue[3] ^= StunPacket::magicCookie[1]; + // Set address and XOR it. + std::memcpy( + attrValue + 4, + &(reinterpret_cast(this->xorMappedAddress))->sin_addr.s_addr, + 4); + attrValue[4] ^= StunPacket::magicCookie[0]; + attrValue[5] ^= StunPacket::magicCookie[1]; + attrValue[6] ^= StunPacket::magicCookie[2]; + attrValue[7] ^= StunPacket::magicCookie[3]; + + pos += 4 + 8; + + break; + } + + case AF_INET6: + { + // Set first byte to 0. + attrValue[0] = 0; + // Set inet family. + attrValue[1] = 0x02; + // Set port and XOR it. + std::memcpy( + attrValue + 2, + &(reinterpret_cast(this->xorMappedAddress))->sin6_port, + 2); + attrValue[2] ^= StunPacket::magicCookie[0]; + attrValue[3] ^= StunPacket::magicCookie[1]; + // Set address and XOR it. + std::memcpy( + attrValue + 4, + &(reinterpret_cast(this->xorMappedAddress))->sin6_addr.s6_addr, + 16); + attrValue[4] ^= StunPacket::magicCookie[0]; + attrValue[5] ^= StunPacket::magicCookie[1]; + attrValue[6] ^= StunPacket::magicCookie[2]; + attrValue[7] ^= StunPacket::magicCookie[3]; + attrValue[8] ^= this->transactionId[0]; + attrValue[9] ^= this->transactionId[1]; + attrValue[10] ^= this->transactionId[2]; + attrValue[11] ^= this->transactionId[3]; + attrValue[12] ^= this->transactionId[4]; + attrValue[13] ^= this->transactionId[5]; + attrValue[14] ^= this->transactionId[6]; + attrValue[15] ^= this->transactionId[7]; + attrValue[16] ^= this->transactionId[8]; + attrValue[17] ^= this->transactionId[9]; + attrValue[18] ^= this->transactionId[10]; + attrValue[19] ^= this->transactionId[11]; + + pos += 4 + 20; + + break; + } + } + } + + // Add ERROR-CODE. + if (addErrorCode) + { + Utils::Byte::Set2Bytes(buffer, pos, static_cast(Attribute::ERROR_CODE)); + Utils::Byte::Set2Bytes(buffer, pos + 2, 4); + + auto codeClass = static_cast(this->errorCode / 100); + uint8_t codeNumber = static_cast(this->errorCode) - (codeClass * 100); + + Utils::Byte::Set2Bytes(buffer, pos + 4, 0); + Utils::Byte::Set1Byte(buffer, pos + 6, codeClass); + Utils::Byte::Set1Byte(buffer, pos + 7, codeNumber); + pos += 4 + 4; + } + + // Add MESSAGE-INTEGRITY. + if (addMessageIntegrity) + { + // Ignore FINGERPRINT. + if (addFingerprint) + Utils::Byte::Set2Bytes(buffer, 2, static_cast(this->size - 20 - 8)); + + // Calculate the HMAC-SHA1 of the packet according to MESSAGE-INTEGRITY rules. + auto computedMessageIntegrity = openssl_HMACsha1(this->password.data(), this->password.size(), buffer, pos); + + Utils::Byte::Set2Bytes(buffer, pos, static_cast(Attribute::MESSAGE_INTEGRITY)); + Utils::Byte::Set2Bytes(buffer, pos + 2, 20); + std::memcpy(buffer + pos + 4, computedMessageIntegrity.data(), computedMessageIntegrity.size()); + + // Update the pointer. + this->messageIntegrity = buffer + pos + 4; + pos += 4 + 20; + + // Restore length field. + if (addFingerprint) + Utils::Byte::Set2Bytes(buffer, 2, static_cast(this->size - 20)); + } + else + { + // Unset the pointer (if it was set). + this->messageIntegrity = nullptr; + } + + // Add FINGERPRINT. + if (addFingerprint) + { + // Compute the CRC32 of the packet up to (but excluding) the FINGERPRINT + // attribute and XOR it with 0x5354554e. + uint32_t computedFingerprint = GetCRC32(buffer, pos) ^ 0x5354554e; + + Utils::Byte::Set2Bytes(buffer, pos, static_cast(Attribute::FINGERPRINT)); + Utils::Byte::Set2Bytes(buffer, pos + 2, 4); + Utils::Byte::Set4Bytes(buffer, pos + 4, computedFingerprint); + pos += 4 + 4; + + // Set flag. + this->hasFingerprint = true; + } + else + { + this->hasFingerprint = false; + } + + MS_ASSERT(pos == this->size, "pos != this->size"); + } +} // namespace RTC diff --git a/webrtc/StunPacket.hpp b/webrtc/StunPacket.hpp new file mode 100644 index 00000000..a6b2c940 --- /dev/null +++ b/webrtc/StunPacket.hpp @@ -0,0 +1,213 @@ +/** +ISC License + +Copyright © 2015, Iñaki Baz Castillo + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MS_RTC_STUN_PACKET_HPP +#define MS_RTC_STUN_PACKET_HPP + + +#include "logger.h" +#include "Utils.hpp" +#include + +namespace RTC +{ + class StunPacket + { + public: + // STUN message class. + enum class Class : uint16_t + { + REQUEST = 0, + INDICATION = 1, + SUCCESS_RESPONSE = 2, + ERROR_RESPONSE = 3 + }; + + // STUN message method. + enum class Method : uint16_t + { + BINDING = 1 + }; + + // Attribute type. + enum class Attribute : uint16_t + { + MAPPED_ADDRESS = 0x0001, + USERNAME = 0x0006, + MESSAGE_INTEGRITY = 0x0008, + ERROR_CODE = 0x0009, + UNKNOWN_ATTRIBUTES = 0x000A, + REALM = 0x0014, + NONCE = 0x0015, + XOR_MAPPED_ADDRESS = 0x0020, + PRIORITY = 0x0024, + USE_CANDIDATE = 0x0025, + SOFTWARE = 0x8022, + ALTERNATE_SERVER = 0x8023, + FINGERPRINT = 0x8028, + ICE_CONTROLLED = 0x8029, + ICE_CONTROLLING = 0x802A + }; + + // Authentication result. + enum class Authentication + { + OK = 0, + UNAUTHORIZED = 1, + BAD_REQUEST = 2 + }; + + public: + static bool IsStun(const uint8_t* data, size_t len) + { + // clang-format off + return ( + // STUN headers are 20 bytes. + (len >= 20) && + // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes + (data[0] < 3) && + // Magic cookie must match. + (data[4] == StunPacket::magicCookie[0]) && (data[5] == StunPacket::magicCookie[1]) && + (data[6] == StunPacket::magicCookie[2]) && (data[7] == StunPacket::magicCookie[3]) + ); + // clang-format on + } + static StunPacket* Parse(const uint8_t* data, size_t len); + + private: + static const uint8_t magicCookie[]; + + public: + StunPacket( + Class klass, Method method, const uint8_t* transactionId, const uint8_t* data, size_t size); + ~StunPacket(); + + void Dump() const; + Class GetClass() const + { + return this->klass; + } + Method GetMethod() const + { + return this->method; + } + const uint8_t* GetData() const + { + return this->data; + } + size_t GetSize() const + { + return this->size; + } + void SetUsername(const char* username, size_t len) + { + this->username.assign(username, len); + } + void SetPriority(uint32_t priority) + { + this->priority = priority; + } + void SetIceControlling(uint64_t iceControlling) + { + this->iceControlling = iceControlling; + } + void SetIceControlled(uint64_t iceControlled) + { + this->iceControlled = iceControlled; + } + void SetUseCandidate() + { + this->hasUseCandidate = true; + } + void SetXorMappedAddress(const struct sockaddr* xorMappedAddress) + { + this->xorMappedAddress = xorMappedAddress; + } + void SetErrorCode(uint16_t errorCode) + { + this->errorCode = errorCode; + } + void SetMessageIntegrity(const uint8_t* messageIntegrity) + { + this->messageIntegrity = messageIntegrity; + } + void SetFingerprint() + { + this->hasFingerprint = true; + } + const std::string& GetUsername() const + { + return this->username; + } + uint32_t GetPriority() const + { + return this->priority; + } + uint64_t GetIceControlling() const + { + return this->iceControlling; + } + uint64_t GetIceControlled() const + { + return this->iceControlled; + } + bool HasUseCandidate() const + { + return this->hasUseCandidate; + } + uint16_t GetErrorCode() const + { + return this->errorCode; + } + bool HasMessageIntegrity() const + { + return (this->messageIntegrity ? true : false); + } + bool HasFingerprint() const + { + return this->hasFingerprint; + } + Authentication CheckAuthentication( + const std::string& localUsername, const std::string& localPassword); + StunPacket* CreateSuccessResponse(); + StunPacket* CreateErrorResponse(uint16_t errorCode); + void Authenticate(const std::string& password); + void Serialize(uint8_t* buffer); + + private: + // Passed by argument. + Class klass; // 2 bytes. + Method method; // 2 bytes. + const uint8_t* transactionId{ nullptr }; // 12 bytes. + uint8_t* data{ nullptr }; // Pointer to binary data. + size_t size{ 0u }; // The full message size (including header). + // STUN attributes. + std::string username; // Less than 513 bytes. + uint32_t priority{ 0u }; // 4 bytes unsigned integer. + uint64_t iceControlling{ 0u }; // 8 bytes unsigned integer. + uint64_t iceControlled{ 0u }; // 8 bytes unsigned integer. + bool hasUseCandidate{ false }; // 0 bytes. + const uint8_t* messageIntegrity{ nullptr }; // 20 bytes. + bool hasFingerprint{ false }; // 4 bytes. + const struct sockaddr* xorMappedAddress{ nullptr }; // 8 or 20 bytes. + uint16_t errorCode{ 0u }; // 4 bytes (no reason phrase). + std::string password; + }; +} // namespace RTC + +#endif diff --git a/webrtc/Utils.hpp b/webrtc/Utils.hpp new file mode 100644 index 00000000..1692ff50 --- /dev/null +++ b/webrtc/Utils.hpp @@ -0,0 +1,134 @@ +/** +ISC License + +Copyright © 2015, Iñaki Baz Castillo + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MS_UTILS_HPP +#define MS_UTILS_HPP + +#if defined(_WIN32) +#include +#include +#include +#pragma comment (lib, "Ws2_32.lib") +#pragma comment(lib,"Iphlpapi.lib") +#else +#include +#include +#include +#include +#include +#include +#include +#endif // defined(_WIN32) + +#include // std::transform(), std::find(), std::min(), std::max() +#include // PRIu64, etc +#include +#include // size_t +#include // uint8_t, etc +#include // std::memcmp(), std::memcpy() +#include +#include +#include +#include +#include + +namespace Utils { + +class Byte { +public: + /** + * Getters below get value in Host Byte Order. + * Setters below set value in Network Byte Order. + */ + static uint8_t Get1Byte(const uint8_t *data, size_t i); + static uint16_t Get2Bytes(const uint8_t *data, size_t i); + static uint32_t Get3Bytes(const uint8_t *data, size_t i); + static uint32_t Get4Bytes(const uint8_t *data, size_t i); + static uint64_t Get8Bytes(const uint8_t *data, size_t i); + static void Set1Byte(uint8_t *data, size_t i, uint8_t value); + static void Set2Bytes(uint8_t *data, size_t i, uint16_t value); + static void Set3Bytes(uint8_t *data, size_t i, uint32_t value); + static void Set4Bytes(uint8_t *data, size_t i, uint32_t value); + static void Set8Bytes(uint8_t *data, size_t i, uint64_t value); + static uint16_t PadTo4Bytes(uint16_t size); + static uint32_t PadTo4Bytes(uint32_t size); +}; + +/* Inline static methods. */ + +inline uint8_t Byte::Get1Byte(const uint8_t *data, size_t i) { return data[i]; } + +inline uint16_t Byte::Get2Bytes(const uint8_t *data, size_t i) { + return uint16_t{data[i + 1]} | uint16_t{data[i]} << 8; +} + +inline uint32_t Byte::Get3Bytes(const uint8_t *data, size_t i) { + return uint32_t{data[i + 2]} | uint32_t{data[i + 1]} << 8 | uint32_t{data[i]} << 16; +} + +inline uint32_t Byte::Get4Bytes(const uint8_t *data, size_t i) { + return uint32_t{data[i + 3]} | uint32_t{data[i + 2]} << 8 | uint32_t{data[i + 1]} << 16 | + uint32_t{data[i]} << 24; +} + +inline uint64_t Byte::Get8Bytes(const uint8_t *data, size_t i) { + return uint64_t{Byte::Get4Bytes(data, i)} << 32 | Byte::Get4Bytes(data, i + 4); +} + +inline void Byte::Set1Byte(uint8_t *data, size_t i, uint8_t value) { data[i] = value; } + +inline void Byte::Set2Bytes(uint8_t *data, size_t i, uint16_t value) { + data[i + 1] = static_cast(value); + data[i] = static_cast(value >> 8); +} + +inline void Byte::Set3Bytes(uint8_t *data, size_t i, uint32_t value) { + data[i + 2] = static_cast(value); + data[i + 1] = static_cast(value >> 8); + data[i] = static_cast(value >> 16); +} + +inline void Byte::Set4Bytes(uint8_t *data, size_t i, uint32_t value) { + data[i + 3] = static_cast(value); + data[i + 2] = static_cast(value >> 8); + data[i + 1] = static_cast(value >> 16); + data[i] = static_cast(value >> 24); +} + +inline void Byte::Set8Bytes(uint8_t *data, size_t i, uint64_t value) { + data[i + 7] = static_cast(value); + data[i + 6] = static_cast(value >> 8); + data[i + 5] = static_cast(value >> 16); + data[i + 4] = static_cast(value >> 24); + data[i + 3] = static_cast(value >> 32); + data[i + 2] = static_cast(value >> 40); + data[i + 1] = static_cast(value >> 48); + data[i] = static_cast(value >> 56); +} + +inline uint16_t Byte::PadTo4Bytes(uint16_t size) { + // If size is not multiple of 32 bits then pad it. + if (size & 0x03) + return (size & 0xFFFC) + 4; + else + return size; +} + +}// namespace Utils + +#endif diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp new file mode 100644 index 00000000..15ffe15e --- /dev/null +++ b/webrtc/WebRtcTransport.cpp @@ -0,0 +1,913 @@ +/* + * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#include "WebRtcTransport.h" +#include +#include "RtpExt.h" +#include "Rtcp/Rtcp.h" +#include "Rtcp/RtcpFCI.h" +#include "Rtsp/RtpReceiver.h" + +#define RTX_SSRC_OFFSET 2 +#define RTP_CNAME "zlmediakit-rtp" +#define RTP_LABEL "zlmediakit-label" +#define RTP_MSLABEL "zlmediakit-mslabel" +#define RTP_MSID RTP_MSLABEL " " RTP_LABEL + +//RTC配置项目 +namespace RTC { +#define RTC_FIELD "rtc." +//rtp和rtcp接受超时时间 +const string kTimeOutSec = RTC_FIELD"timeoutSec"; +//服务器外网ip +const string kExternIP = RTC_FIELD"externIP"; +//设置remb比特率,非0时关闭twcc并开启remb。该设置在rtc推流时有效,可以控制推流画质 +const string kRembBitRate = RTC_FIELD"rembBitRate"; + +static onceToken token([]() { + mINI::Instance()[kTimeOutSec] = 15; + mINI::Instance()[kExternIP] = ""; + mINI::Instance()[kRembBitRate] = 0; +}); + +}//namespace RTC + +WebRtcTransport::WebRtcTransport(const EventPoller::Ptr &poller) { + _poller = poller; + _dtls_transport = std::make_shared(poller, this); + _ice_server = std::make_shared(this, makeRandStr(4), makeRandStr(28).substr(4)); +} + +void WebRtcTransport::onCreate(){ + +} + +void WebRtcTransport::onDestory(){ + _dtls_transport = nullptr; + _ice_server = nullptr; +} + +const EventPoller::Ptr& WebRtcTransport::getPoller() const{ + return _poller; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void WebRtcTransport::OnIceServerSendStunPacket(const RTC::IceServer *iceServer, const RTC::StunPacket *packet, RTC::TransportTuple *tuple) { + onSendSockData((char *) packet->GetData(), packet->GetSize(), (struct sockaddr_in *) tuple); +} + +void WebRtcTransport::OnIceServerSelectedTuple(const RTC::IceServer *iceServer, RTC::TransportTuple *tuple) { + InfoL; +} + +void WebRtcTransport::OnIceServerConnected(const RTC::IceServer *iceServer) { + InfoL; +} + +void WebRtcTransport::OnIceServerCompleted(const RTC::IceServer *iceServer) { + InfoL; + if (_answer_sdp->media[0].role == DtlsRole::passive) { + _dtls_transport->Run(RTC::DtlsTransport::Role::SERVER); + } else { + _dtls_transport->Run(RTC::DtlsTransport::Role::CLIENT); + } +} + +void WebRtcTransport::OnIceServerDisconnected(const RTC::IceServer *iceServer) { + InfoL; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void WebRtcTransport::OnDtlsTransportConnected( + const RTC::DtlsTransport *dtlsTransport, + RTC::SrtpSession::CryptoSuite srtpCryptoSuite, + uint8_t *srtpLocalKey, + size_t srtpLocalKeyLen, + uint8_t *srtpRemoteKey, + size_t srtpRemoteKeyLen, + std::string &remoteCert) { + InfoL; + _srtp_session_send = std::make_shared(RTC::SrtpSession::Type::OUTBOUND, srtpCryptoSuite, srtpLocalKey, srtpLocalKeyLen); + _srtp_session_recv = std::make_shared(RTC::SrtpSession::Type::INBOUND, srtpCryptoSuite, srtpRemoteKey, srtpRemoteKeyLen); + onStartWebRTC(); +} + +void WebRtcTransport::OnDtlsTransportSendData(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) { + onSendSockData((char *)data, len); +} + +void WebRtcTransport::OnDtlsTransportConnecting(const RTC::DtlsTransport *dtlsTransport) { + InfoL; +} + +void WebRtcTransport::OnDtlsTransportFailed(const RTC::DtlsTransport *dtlsTransport) { + InfoL; + onShutdown(SockException(Err_shutdown, "dtls transport failed")); +} + +void WebRtcTransport::OnDtlsTransportClosed(const RTC::DtlsTransport *dtlsTransport) { + InfoL; + onShutdown(SockException(Err_shutdown, "dtls close notify received")); +} + +void WebRtcTransport::OnDtlsTransportApplicationDataReceived(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) { + InfoL << hexdump(data, len); +} +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void WebRtcTransport::onSendSockData(const char *buf, size_t len, bool flush){ + auto tuple = _ice_server->GetSelectedTuple(); + assert(tuple); + onSendSockData(buf, len, (struct sockaddr_in *) tuple, flush); +} + +const RtcSession& WebRtcTransport::getSdp(SdpType type) const{ + switch (type) { + case SdpType::offer: return *_offer_sdp; + case SdpType::answer: return *_answer_sdp; + default: throw std::invalid_argument("不识别的sdp类型"); + } +} + +RTC::TransportTuple* WebRtcTransport::getSelectedTuple() const{ + return _ice_server->GetSelectedTuple(); +} + +void WebRtcTransport::sendRtcpRemb(uint32_t ssrc, size_t bit_rate) { + auto remb = FCI_REMB::create({ssrc}, (uint32_t)bit_rate); + auto fb = RtcpFB::create(PSFBType::RTCP_PSFB_REMB, remb.data(), remb.size()); + fb->ssrc = htonl(0); + fb->ssrc_media = htonl(ssrc); + sendRtcpPacket((char *) fb.get(), fb->getSize(), true); + TraceL << ssrc << " " << bit_rate; +} + +void WebRtcTransport::sendRtcpPli(uint32_t ssrc) { + auto pli = RtcpFB::create(PSFBType::RTCP_PSFB_PLI); + pli->ssrc = htonl(0); + pli->ssrc_media = htonl(ssrc); + sendRtcpPacket((char *) pli.get(), pli->getSize(), true); +} + +string getFingerprint(const string &algorithm_str, const std::shared_ptr &transport){ + auto algorithm = RTC::DtlsTransport::GetFingerprintAlgorithm(algorithm_str); + for (auto &finger_prints : transport->GetLocalFingerprints()) { + if (finger_prints.algorithm == algorithm) { + return finger_prints.value; + } + } + throw std::invalid_argument(StrPrinter << "不支持的加密算法:" << algorithm_str); +} + +void WebRtcTransport::setRemoteDtlsFingerprint(const RtcSession &remote){ + //设置远端dtls签名 + RTC::DtlsTransport::Fingerprint remote_fingerprint; + remote_fingerprint.algorithm = RTC::DtlsTransport::GetFingerprintAlgorithm(_offer_sdp->media[0].fingerprint.algorithm); + remote_fingerprint.value = _offer_sdp->media[0].fingerprint.hash; + _dtls_transport->SetRemoteFingerprint(remote_fingerprint); +} + +void WebRtcTransport::onCheckSdp(SdpType type, RtcSession &sdp){ + for (auto &m : sdp.media) { + if (m.type != TrackApplication && !m.rtcp_mux) { + throw std::invalid_argument("只支持rtcp-mux模式"); + } + } + if (sdp.group.mids.empty()) { + throw std::invalid_argument("只支持group BUNDLE模式"); + } + if (type == SdpType::offer) { + sdp.checkValidSSRC(); + } +} + +void WebRtcTransport::onRtcConfigure(RtcConfigure &configure) const { + //开启remb后关闭twcc,因为开启twcc后remb无效 + GET_CONFIG(size_t, remb_bit_rate, RTC::kRembBitRate); + configure.enableTWCC(!remb_bit_rate); +} + +std::string WebRtcTransport::getAnswerSdp(const string &offer){ + try { + //// 解析offer sdp //// + _offer_sdp = std::make_shared(); + _offer_sdp->loadFrom(offer); + onCheckSdp(SdpType::offer, *_offer_sdp); + setRemoteDtlsFingerprint(*_offer_sdp); + + //// sdp 配置 //// + SdpAttrFingerprint fingerprint; + fingerprint.algorithm = _offer_sdp->media[0].fingerprint.algorithm; + fingerprint.hash = getFingerprint(fingerprint.algorithm, _dtls_transport); + RtcConfigure configure; + configure.setDefaultSetting(_ice_server->GetUsernameFragment(), _ice_server->GetPassword(), + RtpDirection::sendrecv, fingerprint); + onRtcConfigure(configure); + + //// 生成answer sdp //// + _answer_sdp = configure.createAnswer(*_offer_sdp); + onCheckSdp(SdpType::answer, *_answer_sdp); + return _answer_sdp->toString(); + } catch (exception &ex) { + onShutdown(SockException(Err_shutdown, ex.what())); + throw; + } +} + +bool is_dtls(char *buf) { + return ((*buf > 19) && (*buf < 64)); +} + +bool is_rtp(char *buf) { + RtpHeader *header = (RtpHeader *) buf; + return ((header->pt < 64) || (header->pt >= 96)); +} + +bool is_rtcp(char *buf) { + RtpHeader *header = (RtpHeader *) buf; + return ((header->pt >= 64) && (header->pt < 96)); +} + +void WebRtcTransport::inputSockData(char *buf, size_t len, RTC::TransportTuple *tuple) { + if (RTC::StunPacket::IsStun((const uint8_t *) buf, len)) { + RTC::StunPacket *packet = RTC::StunPacket::Parse((const uint8_t *) buf, len); + if (packet == nullptr) { + WarnL << "parse stun error" << std::endl; + return; + } + _ice_server->ProcessStunPacket(packet, tuple); + return; + } + if (is_dtls(buf)) { + _dtls_transport->ProcessDtlsData((uint8_t *) buf, len); + return; + } + if (is_rtp(buf)) { + if (_srtp_session_recv->DecryptSrtp((uint8_t *) buf, &len)) { + onRtp(buf, len); + } else { + WarnL; + } + return; + } + if (is_rtcp(buf)) { + if (_srtp_session_recv->DecryptSrtcp((uint8_t *) buf, &len)) { + onRtcp(buf, len); + } else { + WarnL; + } + return; + } +} + +void WebRtcTransport::sendRtpPacket(const char *buf, size_t len, bool flush, void *ctx) { + if (_srtp_session_send) { + //预留rtx加入的两个字节 + CHECK(len + SRTP_MAX_TRAILER_LEN + 2 <= sizeof(_srtp_buf)); + memcpy(_srtp_buf, buf, len); + onBeforeEncryptRtp((char *) _srtp_buf, len, ctx); + if (_srtp_session_send->EncryptRtp(_srtp_buf, &len)) { + onSendSockData((char *) _srtp_buf, len, flush); + } + } +} + +void WebRtcTransport::sendRtcpPacket(const char *buf, size_t len, bool flush, void *ctx){ + if (_srtp_session_send) { + CHECK(len + SRTP_MAX_TRAILER_LEN <= sizeof(_srtp_buf)); + memcpy(_srtp_buf, buf, len); + onBeforeEncryptRtcp((char *) _srtp_buf, len, ctx); + if (_srtp_session_send->EncryptRtcp(_srtp_buf, &len)) { + onSendSockData((char *) _srtp_buf, len, flush); + } + } +} + +/////////////////////////////////////////////////////////////////////////////////// +WebRtcTransportImp::Ptr WebRtcTransportImp::create(const EventPoller::Ptr &poller){ + WebRtcTransportImp::Ptr ret(new WebRtcTransportImp(poller), [](WebRtcTransportImp *ptr){ + ptr->onDestory(); + delete ptr; + }); + ret->onCreate(); + return ret; +} + +void WebRtcTransportImp::onCreate(){ + WebRtcTransport::onCreate(); + _socket = Socket::createSocket(getPoller(), false); + //随机端口,绑定全部网卡 + _socket->bindUdpSock(0); + weak_ptr weak_self = shared_from_this(); + _socket->setOnRead([weak_self](const Buffer::Ptr &buf, struct sockaddr *addr, int addr_len) mutable { + auto strong_self = weak_self.lock(); + if (strong_self) { + strong_self->inputSockData(buf->data(), buf->size(), addr); + } + }); + _self = shared_from_this(); + + GET_CONFIG(float, timeoutSec, RTC::kTimeOutSec); + _timer = std::make_shared(timeoutSec / 2, [weak_self]() { + auto strong_self = weak_self.lock(); + if (!strong_self) { + return false; + } + if (strong_self->_alive_ticker.elapsedTime() > timeoutSec * 1000) { + strong_self->onShutdown(SockException(Err_timeout, "接受rtp和rtcp超时")); + } + return true; + }, getPoller()); +} + +WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller) : WebRtcTransport(poller) { + InfoL << this; +} + +WebRtcTransportImp::~WebRtcTransportImp() { + InfoL << this; +} + +void WebRtcTransportImp::onDestory() { + WebRtcTransport::onDestory(); + uint64_t duration = _alive_ticker.createdTime() / 1000; + + //流量统计事件广播 + GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold); + + if (_reader) { + WarnL << "RTC播放器(" + << _media_info._vhost << "/" + << _media_info._app << "/" + << _media_info._streamid + << ")结束播放,耗时(s):" << duration; + if (_bytes_usage >= iFlowThreshold * 1024) { + NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _media_info, _bytes_usage, duration, true, static_cast(*_socket)); + } + } + + if (_push_src) { + WarnL << "RTC推流器(" + << _media_info._vhost << "/" + << _media_info._app << "/" + << _media_info._streamid + << ")结束推流,耗时(s):" << duration; + if (_bytes_usage >= iFlowThreshold * 1024) { + NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _media_info, _bytes_usage, duration, false, static_cast(*_socket)); + } + } +} + +void WebRtcTransportImp::attach(const RtspMediaSource::Ptr &src, const MediaInfo &info, bool is_play) { + assert(src); + _media_info = info; + if (is_play) { + _play_src = src; + } else { + _push_src = src; + } +} + +void WebRtcTransportImp::onSendSockData(const char *buf, size_t len, struct sockaddr_in *dst, bool flush) { + auto ptr = BufferRaw::create(); + ptr->assign(buf, len); + _socket->send(ptr, (struct sockaddr *)(dst), sizeof(struct sockaddr), flush); +} + +/////////////////////////////////////////////////////////////////// + +bool WebRtcTransportImp::canSendRtp() const{ + auto &sdp = getSdp(SdpType::answer); + return _play_src && (sdp.media[0].direction == RtpDirection::sendrecv || sdp.media[0].direction == RtpDirection::sendonly); +} + +bool WebRtcTransportImp::canRecvRtp() const{ + auto &sdp = getSdp(SdpType::answer); + return _push_src && (sdp.media[0].direction == RtpDirection::sendrecv || sdp.media[0].direction == RtpDirection::recvonly); +} + +void WebRtcTransportImp::onStartWebRTC() { + //获取ssrc和pt相关信息,届时收到rtp和rtcp时分别可以根据pt和ssrc找到相关的信息 + for (auto &m_answer : getSdp(SdpType::answer).media) { + auto m_offer = getSdp(SdpType::offer).getMedia(m_answer.type); + auto info = std::make_shared(); + + info->media = &m_answer; + info->answer_ssrc_rtp = m_answer.getRtpSSRC(); + info->answer_ssrc_rtx = m_answer.getRtxSSRC(); + info->offer_ssrc_rtp = m_offer->getRtpSSRC(); + info->offer_ssrc_rtx = m_offer->getRtxSSRC(); + info->plan_rtp = &m_answer.plan[0];; + info->plan_rtx = m_answer.getRelatedRtxPlan(info->plan_rtp->pt); + info->rtcp_context_recv = std::make_shared(info->plan_rtp->sample_rate, true); + info->rtcp_context_send = std::make_shared(info->plan_rtp->sample_rate, false); + info->receiver = std::make_shared([info, this](RtpPacket::Ptr rtp) mutable { + onSortedRtp(*info, std::move(rtp)); + }); + info->nack_ctx.setOnNack([info, this](const FCI_NACK &nack) mutable { + onSendNack(*info, nack); + }); + + //send ssrc --> RtpPayloadInfo + _rtp_info_ssrc[info->answer_ssrc_rtp] = std::make_pair(false, info); + _rtp_info_ssrc[info->answer_ssrc_rtx] = std::make_pair(true, info); + + //recv ssrc --> RtpPayloadInfo + _rtp_info_ssrc[info->offer_ssrc_rtp] = std::make_pair(false, info);; + _rtp_info_ssrc[info->offer_ssrc_rtx] = std::make_pair(true, info);; + + //rtp pt --> RtpPayloadInfo + _rtp_info_pt.emplace(info->plan_rtp->pt, std::make_pair(false, info)); + if (info->plan_rtx) { + //rtx pt --> RtpPayloadInfo + _rtp_info_pt.emplace(info->plan_rtx->pt, std::make_pair(true, info)); + } + if (m_offer->type != TrackApplication) { + //记录rtp ext类型与id的关系,方便接收或发送rtp时修改rtp ext id + for (auto &ext : m_offer->extmap) { + auto ext_type = RtpExt::getExtType(ext.ext); + _rtp_ext_id_to_type.emplace(ext.id, ext_type); + _rtp_ext_type_to_id.emplace(ext_type, ext.id); + } + } + } + + if (canRecvRtp()) { + _push_src->setSdp(getSdp(SdpType::answer).toRtspSdp()); + } + if (canSendRtp()) { + _reader = _play_src->getRing()->attach(getPoller(), true); + weak_ptr weak_self = shared_from_this(); + _reader->setReadCB([weak_self](const RtspMediaSource::RingDataType &pkt) { + auto strongSelf = weak_self.lock(); + if (!strongSelf) { + return; + } + size_t i = 0; + pkt->for_each([&](const RtpPacket::Ptr &rtp) { + strongSelf->onSendRtp(rtp, ++i == pkt->size()); + }); + }); + _reader->setDetachCB([weak_self](){ + auto strongSelf = weak_self.lock(); + if (!strongSelf) { + return; + } + strongSelf->onShutdown(SockException(Err_eof, "rtsp ring buffer detached")); + }); + + RtcSession rtsp_send_sdp; + rtsp_send_sdp.loadFrom(_play_src->getSdp(), false); + for (auto &m : getSdp(SdpType::answer).media) { + if (m.type == TrackApplication) { + continue; + } + auto rtsp_media = rtsp_send_sdp.getMedia(m.type); + if (rtsp_media && getCodecId(rtsp_media->plan[0].codec) == getCodecId(m.plan[0].codec)) { + auto it = _rtp_info_pt.find(m.plan[0].pt); + CHECK(it != _rtp_info_pt.end()); + //记录发送rtp时约定的信息,届时发送rtp时需要修改pt和ssrc + _send_rtp_info[m.type] = it->second.second; + } + } + } + //使用完毕后,释放强引用,这样确保推流器断开后能及时注销媒体 + _play_src = nullptr; +} + +void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp){ + WebRtcTransport::onCheckSdp(type, sdp); + if (type != SdpType::answer) { + //我们只修改answer sdp + return; + } + + //修改answer sdp的ip、端口信息 + GET_CONFIG(string, extern_ip, RTC::kExternIP); + for (auto &m : sdp.media) { + m.addr.reset(); + m.addr.address = extern_ip.empty() ? SockUtil::get_local_ip() : extern_ip; + m.rtcp_addr.reset(); + m.rtcp_addr.address = m.addr.address; + m.rtcp_addr.port = _socket->get_local_port(); + m.port = m.rtcp_addr.port; + sdp.origin.address = m.addr.address; + } + + if (!canSendRtp()) { + //设置我们发送的rtp的ssrc + return; + } + + for (auto &m : sdp.media) { + if (m.type == TrackApplication) { + continue; + } + //添加answer sdp的ssrc信息 + m.rtp_rtx_ssrc.emplace_back(); + m.rtp_rtx_ssrc[0].ssrc = _play_src->getSsrc(m.type); + m.rtp_rtx_ssrc[0].cname = RTP_CNAME; + m.rtp_rtx_ssrc[0].label = RTP_LABEL; + m.rtp_rtx_ssrc[0].mslabel = RTP_MSLABEL; + m.rtp_rtx_ssrc[0].msid = RTP_MSID; + + if (m.getRelatedRtxPlan(m.plan[0].pt)) { + m.rtp_rtx_ssrc.emplace_back(); + m.rtp_rtx_ssrc[1] = m.rtp_rtx_ssrc[0]; + m.rtp_rtx_ssrc[1].ssrc += RTX_SSRC_OFFSET; + } + } +} + +void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const { + WebRtcTransport::onRtcConfigure(configure); + + if (_play_src) { + //这是播放,同时也可能有推流 + configure.video.direction = _push_src ? RtpDirection::sendrecv : RtpDirection::sendonly; + configure.audio.direction = configure.video.direction; + configure.setPlayRtspInfo(_play_src->getSdp()); + } else if (_push_src) { + //这只是推流 + configure.video.direction = RtpDirection::recvonly; + configure.audio.direction = RtpDirection::recvonly; + } else { + throw std::invalid_argument("未设置播放或推流的媒体源"); + } + + //添加接收端口candidate信息 + configure.addCandidate(*getIceCandidate()); +} + +SdpAttrCandidate::Ptr WebRtcTransportImp::getIceCandidate() const{ + auto candidate = std::make_shared(); + candidate->foundation = "udpcandidate"; + //rtp端口 + candidate->component = 1; + candidate->transport = "udp"; + //优先级,单candidate时随便 + candidate->priority = 100; + GET_CONFIG(string, extern_ip, RTC::kExternIP); + candidate->address = extern_ip.empty() ? SockUtil::get_local_ip() : extern_ip; + candidate->port = _socket->get_local_port(); + candidate->type = "host"; + return candidate; +} + +/////////////////////////////////////////////////////////////////// + +class RtpReceiverImp : public RtpReceiver { +public: + RtpReceiverImp( function cb){ + _on_sort = std::move(cb); + } + + ~RtpReceiverImp() override = default; + + bool inputRtp(TrackType type, int samplerate, uint8_t *ptr, size_t len){ + return handleOneRtp((int) type, type, samplerate, ptr, len); + } + +protected: + void onRtpSorted(RtpPacket::Ptr rtp, int track_index) override { + _on_sort(std::move(rtp)); + } + +private: + function _on_sort; +}; + +void WebRtcTransportImp::onRtcp(const char *buf, size_t len) { + _bytes_usage += len; + auto rtcps = RtcpHeader::loadFromBytes((char *) buf, len); + for (auto rtcp : rtcps) { + switch ((RtcpType) rtcp->pt) { + case RtcpType::RTCP_SR : { + //对方汇报rtp发送情况 + RtcpSR *sr = (RtcpSR *) rtcp; + auto it = _rtp_info_ssrc.find(sr->ssrc); + if (it != _rtp_info_ssrc.end()) { + auto rtx = it->second.first; + if (!rtx) { + auto &info = it->second.second; + info->rtcp_context_recv->onRtcp(sr); + auto rr = info->rtcp_context_recv->createRtcpRR(info->answer_ssrc_rtp, info->offer_ssrc_rtp); + sendRtcpPacket(rr->data(), rr->size(), true); + } + } else { + WarnL << "未识别的sr rtcp包:" << rtcp->dumpString(); + } + break; + } + case RtcpType::RTCP_RR : { + _alive_ticker.resetTime(); + //对方汇报rtp接收情况 + RtcpRR *rr = (RtcpRR *) rtcp; + for (auto item : rr->getItemList()) { + auto it = _rtp_info_ssrc.find(item->ssrc); + if (it != _rtp_info_ssrc.end()) { + auto rtx = it->second.first; + if (!rtx) { + auto &info = it->second.second; + auto sr = info->rtcp_context_send->createRtcpSR(info->answer_ssrc_rtp); + sendRtcpPacket(sr->data(), sr->size(), true); + } + } else { + WarnL << "未识别的rr rtcp包:" << rtcp->dumpString(); + } + } + break; + } + case RtcpType::RTCP_BYE : { + //对方汇报停止发送rtp + RtcpBye *bye = (RtcpBye *) rtcp; + for (auto ssrc : bye->getSSRC()) { + auto it = _rtp_info_ssrc.find(*ssrc); + if (it == _rtp_info_ssrc.end()) { + WarnL << "未识别的bye rtcp包:" << rtcp->dumpString(); + continue; + } + _rtp_info_ssrc.erase(it); + } + onShutdown(SockException(Err_eof, "rtcp bye message received")); + break; + } + case RtcpType::RTCP_PSFB: + case RtcpType::RTCP_RTPFB: { + if ((RtcpType) rtcp->pt == RtcpType::RTCP_PSFB) { + break; + } + //RTPFB + switch ((RTPFBType) rtcp->report_count) { + case RTPFBType::RTCP_RTPFB_NACK : { + RtcpFB *fb = (RtcpFB *) rtcp; + auto it = _rtp_info_ssrc.find(fb->ssrc_media); + if (it == _rtp_info_ssrc.end()) { + WarnL << "未识别的 rtcp包:" << rtcp->dumpString(); + return; + } + auto rtx = it->second.first; + if (!rtx) { + auto &info = it->second.second; + auto &fci = fb->getFci(); + info->nack_list.for_each_nack(fci, [&](const RtpPacket::Ptr &rtp) { + //rtp重传 + onSendRtp(rtp, true, true); + }); + } + break; + } + default: break; + } + break; + } + default: break; + } + } +} + +/////////////////////////////////////////////////////////////////// + +void WebRtcTransportImp::changeRtpExtId(const RtpPayloadInfo *info, const RtpHeader *header, bool is_recv, bool is_rtx) const{ + auto ext_map = RtpExt::getExtValue(header); + for (auto &pr : ext_map) { + if (is_recv) { + auto it = _rtp_ext_id_to_type.find(pr.first); + if (it == _rtp_ext_id_to_type.end()) { + WarnL << "接收rtp时,忽略不识别的rtp ext, id=" << (int) pr.first; + pr.second.clearExt(); + continue; + } + pr.second.setType(it->second); + //重新赋值ext id为 ext type,作为后面处理ext的统一中间类型 + pr.second.setExtId((uint8_t) it->second); + } else { + pr.second.setType((RtpExtType) pr.first); + auto it = _rtp_ext_type_to_id.find((RtpExtType) pr.first); + if (it == _rtp_ext_type_to_id.end()) { + WarnL << "发送rtp时, 忽略不被客户端支持rtp ext:" << pr.second.dumpString(); + pr.second.clearExt(); + continue; + } + //重新赋值ext id为客户端sdp声明的类型 + pr.second.setExtId(it->second); + } + } +} + +void WebRtcTransportImp::onRtp(const char *buf, size_t len) { + onRtp_l(buf, len, false); +} + +void WebRtcTransportImp::onRtp_l(const char *buf, size_t len, bool rtx) { + if (!rtx) { + _bytes_usage += len; + _alive_ticker.resetTime(); + } + + RtpHeader *rtp = (RtpHeader *) buf; + //根据接收到的rtp的pt信息,找到该流的信息 + auto it = _rtp_info_pt.find(rtp->pt); + if (it == _rtp_info_pt.end()) { + WarnL; + return; + } + auto &info = it->second.second; + if (!it->second.first) { + //这是普通的rtp数据 + auto seq = ntohs(rtp->seq); +#if 0 + if (!rtx && info->media->type == TrackVideo && seq % 100 == 0) { + //此处模拟接受丢包 + DebugL << "recv dropped:" << seq; + return; + } +#endif + if (!rtx) { + //统计rtp接受情况,便于生成nack rtcp包 + info->nack_ctx.received(seq); + //时间戳转换成毫秒 + auto stamp_ms = ntohl(rtp->stamp) * uint64_t(1000) / info->plan_rtp->sample_rate; + //统计rtp收到的情况,好做rr汇报 + info->rtcp_context_recv->onRtp(seq, stamp_ms, len); + } + //修改ext id至统一 + changeRtpExtId(info.get(), rtp, true, rtx); + //解析并排序rtp + info->receiver->inputRtp(info->media->type, info->plan_rtp->sample_rate, (uint8_t *) buf, len); + return; + } + + //这里是rtx重传包 + //https://datatracker.ietf.org/doc/html/rfc4588#section-4 + auto payload = rtp->getPayloadData(); + auto size = rtp->getPayloadSize(len); + if (size < 2) { + return; + } + //前两个字节是原始的rtp的seq + auto origin_seq = payload[0] << 8 | payload[1]; + InfoL << "received rtx rtp: " << origin_seq; + rtp->seq = htons(origin_seq); + rtp->ssrc = htonl(info->offer_ssrc_rtp); + rtp->pt = info->plan_rtp->pt; + memmove((uint8_t *) buf + 2, buf, payload - (uint8_t *) buf); + buf += 2; + len -= 2; + onRtp_l(buf, len, true); +} + +void WebRtcTransportImp::onSendNack(RtpPayloadInfo &info, const FCI_NACK &nack) { + auto rtcp = RtcpFB::create(RTPFBType::RTCP_RTPFB_NACK, &nack, FCI_NACK::kSize); + rtcp->ssrc = htons(info.answer_ssrc_rtp); + rtcp->ssrc_media = htonl(info.offer_ssrc_rtp); + sendRtcpPacket((char *) rtcp.get(), rtcp->getSize(), true); +} + +/////////////////////////////////////////////////////////////////// + +void WebRtcTransportImp::onSortedRtp(RtpPayloadInfo &info, RtpPacket::Ptr rtp) { + if (info.media->type == TrackVideo && _pli_ticker.elapsedTime() > 2000) { + //定期发送pli请求关键帧,方便非rtc等协议 + _pli_ticker.resetTime(); + sendRtcpPli(rtp->getSSRC()); + + //开启remb,则发送remb包调节比特率 + GET_CONFIG(size_t, remb_bit_rate, RTC::kRembBitRate); + if (remb_bit_rate && getSdp(SdpType::answer).supportRtcpFb(SdpConst::kRembRtcpFb)) { + sendRtcpRemb(rtp->getSSRC(), remb_bit_rate); + } + } + + if (_push_src) { + _push_src->onWrite(std::move(rtp), false); + } +} + +/////////////////////////////////////////////////////////////////// + +void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool rtx){ + auto &info = _send_rtp_info[rtp->type]; + if (!info) { + //忽略,对方不支持该编码类型 + return; + } + if (!rtx) { + //统计rtp发送情况,好做sr汇报 + info->rtcp_context_send->onRtp(rtp->getSeq(), rtp->getStampMS(), rtp->size() - RtpPacket::kRtpTcpHeaderSize); + info->nack_list.push_back(rtp); +#if 0 + //此处模拟发送丢包 + if (rtp->type == TrackVideo && rtp->getSeq() % 100 == 0) { + DebugL << "send dropped:" << rtp->getSeq(); + return; + } +#endif + } else { + WarnL << "send rtx rtp:" << rtp->getSeq(); + } + pair ctx{rtx, info.get()}; + sendRtpPacket(rtp->data() + RtpPacket::kRtpTcpHeaderSize, rtp->size() - RtpPacket::kRtpTcpHeaderSize, flush, &ctx); + _bytes_usage += rtp->size() - RtpPacket::kRtpTcpHeaderSize; +} + +void WebRtcTransportImp::onBeforeEncryptRtp(const char *buf, size_t &len, void *ctx) { + auto pr = (pair *) ctx; + auto header = (RtpHeader *) buf; + + if (!pr->first || !pr->second->plan_rtx) { + //普通的rtp,或者不支持rtx, 修改目标pt和ssrc + changeRtpExtId(pr->second, header, false, false); + header->pt = pr->second->plan_rtp->pt; + header->ssrc = htonl(pr->second->answer_ssrc_rtp); + } else { + //重传的rtp, rtx + changeRtpExtId(pr->second, header, false, true); + header->pt = pr->second->plan_rtx->pt; + if (pr->second->answer_ssrc_rtx) { + //有rtx单独的ssrc,有些情况下,浏览器支持rtx,但是未指定rtx单独的ssrc + header->ssrc = htonl(pr->second->answer_ssrc_rtx); + } else { + //未单独指定rtx的ssrc,那么使用rtp的ssrc + header->ssrc = htonl(pr->second->answer_ssrc_rtp); + } + + auto origin_seq = ntohs(header->seq); + //seq跟原来的不一样 + header->seq = htons(_rtx_seq[pr->second->media->type]++); + auto payload = header->getPayloadData(); + auto payload_size = header->getPayloadSize(len); + if (payload_size) { + //rtp负载后移两个字节,这两个字节用于存放osn + //https://datatracker.ietf.org/doc/html/rfc4588#section-4 + memmove(payload + 2, payload, payload_size); + } + payload[0] = origin_seq >> 8; + payload[1] = origin_seq & 0xFF; + len += 2; + } +} + +void WebRtcTransportImp::onShutdown(const SockException &ex){ + WarnL << ex.what(); + _self = nullptr; +} + +///////////////////////////////////////////////////////////////////////////////////////////// + +bool WebRtcTransportImp::close(MediaSource &sender, bool force) { + //此回调在其他线程触发 + if(!_push_src || (!force && _push_src->totalReaderCount())){ + return false; + } + string err = StrPrinter << "close media:" << sender.getSchema() << "/" << sender.getVhost() << "/" << sender.getApp() << "/" << sender.getId() << " " << force; + onShutdown(SockException(Err_shutdown,err)); + return true; +} + +int WebRtcTransportImp::totalReaderCount(MediaSource &sender) { + return _push_src ? _push_src->totalReaderCount() : sender.readerCount(); +} + +MediaOriginType WebRtcTransportImp::getOriginType(MediaSource &sender) const { + return MediaOriginType::rtc_push; +} + +string WebRtcTransportImp::getOriginUrl(MediaSource &sender) const { + return ""; +} + +std::shared_ptr WebRtcTransportImp::getOriginSock(MediaSource &sender) const { + return const_cast(this)->shared_from_this(); +} + +///////////////////////////////////////////////////////////////////////////////////////////// + +string WebRtcTransportImp::get_local_ip() { + return getSdp(SdpType::answer).media[0].candidate[0].address; +} + +uint16_t WebRtcTransportImp::get_local_port() { + return _socket->get_local_port(); +} + +string WebRtcTransportImp::get_peer_ip() { + return SockUtil::inet_ntoa(((struct sockaddr_in *) getSelectedTuple())->sin_addr); +} + +uint16_t WebRtcTransportImp::get_peer_port() { + return ntohs(((struct sockaddr_in *) getSelectedTuple())->sin_port); +} + +string WebRtcTransportImp::getIdentifier() const { + return StrPrinter << this; +} \ No newline at end of file diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h new file mode 100644 index 00000000..7f0dbb6b --- /dev/null +++ b/webrtc/WebRtcTransport.h @@ -0,0 +1,395 @@ +/* + * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#pragma once + +#include +#include +#include "DtlsTransport.hpp" +#include "IceServer.hpp" +#include "SrtpSession.hpp" +#include "StunPacket.hpp" +#include "Sdp.h" +#include "Poller/EventPoller.h" +#include "Network/Socket.h" +#include "Rtsp/RtspMediaSourceImp.h" +#include "Rtcp/RtcpContext.h" +#include "Rtcp/RtcpFCI.h" +using namespace toolkit; +using namespace mediakit; + +class WebRtcTransport : public RTC::DtlsTransport::Listener, public RTC::IceServer::Listener { +public: + using Ptr = std::shared_ptr; + WebRtcTransport(const EventPoller::Ptr &poller); + ~WebRtcTransport() override = default; + + /** + * 创建对象 + */ + virtual void onCreate(); + + /** + * 销毁对象 + */ + virtual void onDestory(); + + /** + * 创建webrtc answer sdp + * @param offer offer sdp + * @return answer sdp + */ + std::string getAnswerSdp(const string &offer); + + /** + * socket收到udp数据 + * @param buf 数据指针 + * @param len 数据长度 + * @param tuple 数据来源 + */ + void inputSockData(char *buf, size_t len, RTC::TransportTuple *tuple); + + /** + * 发送rtp + * @param buf rtcp内容 + * @param len rtcp长度 + * @param flush 是否flush socket + * @param ctx 用户指针 + */ + void sendRtpPacket(const char *buf, size_t len, bool flush, void *ctx = nullptr); + void sendRtcpPacket(const char *buf, size_t len, bool flush, void *ctx = nullptr); + + const EventPoller::Ptr& getPoller() const; + +protected: + //// dtls相关的回调 //// + void OnDtlsTransportConnecting(const RTC::DtlsTransport *dtlsTransport) override; + void OnDtlsTransportConnected(const RTC::DtlsTransport *dtlsTransport, + RTC::SrtpSession::CryptoSuite srtpCryptoSuite, + uint8_t *srtpLocalKey, + size_t srtpLocalKeyLen, + uint8_t *srtpRemoteKey, + size_t srtpRemoteKeyLen, + std::string &remoteCert) override; + + void OnDtlsTransportFailed(const RTC::DtlsTransport *dtlsTransport) override; + void OnDtlsTransportClosed(const RTC::DtlsTransport *dtlsTransport) override; + void OnDtlsTransportSendData(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) override; + void OnDtlsTransportApplicationDataReceived(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) override; + +protected: + //// ice相关的回调 /// + void OnIceServerSendStunPacket(const RTC::IceServer *iceServer, const RTC::StunPacket *packet, RTC::TransportTuple *tuple) override; + void OnIceServerSelectedTuple(const RTC::IceServer *iceServer, RTC::TransportTuple *tuple) override; + void OnIceServerConnected(const RTC::IceServer *iceServer) override; + void OnIceServerCompleted(const RTC::IceServer *iceServer) override; + void OnIceServerDisconnected(const RTC::IceServer *iceServer) override; + +protected: + virtual void onStartWebRTC() = 0; + virtual void onRtcConfigure(RtcConfigure &configure) const; + virtual void onCheckSdp(SdpType type, RtcSession &sdp); + virtual void onSendSockData(const char *buf, size_t len, struct sockaddr_in *dst, bool flush = true) = 0; + + virtual void onRtp(const char *buf, size_t len) = 0; + virtual void onRtcp(const char *buf, size_t len) = 0; + virtual void onShutdown(const SockException &ex) = 0; + virtual void onBeforeEncryptRtp(const char *buf, size_t &len, void *ctx) = 0; + virtual void onBeforeEncryptRtcp(const char *buf, size_t &len, void *ctx) = 0; + +protected: + const RtcSession& getSdp(SdpType type) const; + RTC::TransportTuple* getSelectedTuple() const; + void sendRtcpRemb(uint32_t ssrc, size_t bit_rate); + void sendRtcpPli(uint32_t ssrc); + +private: + void onSendSockData(const char *buf, size_t len, bool flush = true); + void setRemoteDtlsFingerprint(const RtcSession &remote); + +private: + uint8_t _srtp_buf[2000]; + EventPoller::Ptr _poller; + std::shared_ptr _ice_server; + std::shared_ptr _dtls_transport; + std::shared_ptr _srtp_session_send; + std::shared_ptr _srtp_session_recv; + RtcSession::Ptr _offer_sdp; + RtcSession::Ptr _answer_sdp; +}; + +class RtpReceiverImp; + +class NackList { +public: + void push_back(RtpPacket::Ptr rtp) { + auto seq = rtp->getSeq(); + _nack_cache_seq.emplace_back(seq); + _nack_cache_pkt.emplace(seq, std::move(rtp)); + while (get_cache_ms() > kMaxNackMS) { + //需要清除部分nack缓存 + pop_front(); + } + } + + template + void for_each_nack(const FCI_NACK &nack, const FUNC &func) { + auto seq = nack.getPid(); + for (auto bit : nack.getBitArray()) { + if (bit) { + //丢包 + RtpPacket::Ptr *ptr = get_rtp(seq); + if (ptr) { + func(*ptr); + } + } + ++seq; + } + } + +private: + void pop_front() { + if (_nack_cache_seq.empty()) { + return; + } + _nack_cache_pkt.erase(_nack_cache_seq.front()); + _nack_cache_seq.pop_front(); + } + + RtpPacket::Ptr *get_rtp(uint16_t seq) { + auto it = _nack_cache_pkt.find(seq); + if (it == _nack_cache_pkt.end()) { + return nullptr; + } + return &it->second; + } + + uint32_t get_cache_ms() { + if (_nack_cache_seq.size() < 2) { + return 0; + } + uint32_t back = _nack_cache_pkt[_nack_cache_seq.back()]->getStampMS(); + uint32_t front = _nack_cache_pkt[_nack_cache_seq.front()]->getStampMS(); + if (back > front) { + return back - front; + } + //很有可能回环了 + return back + (UINT32_MAX - front); + } + +private: + static constexpr uint32_t kMaxNackMS = 10 * 1000; + deque _nack_cache_seq; + unordered_map _nack_cache_pkt; +}; + +class NackContext { +public: + using onNack = function; + + void received(uint16_t seq) { + if (!_last_max_seq && _seq.empty()) { + _last_max_seq = seq - 1; + } + _seq.emplace(seq); + auto max_seq = *_seq.rbegin(); + auto min_seq = *_seq.begin(); + auto diff = max_seq - min_seq; + if (!diff) { + return; + } + + if (diff > UINT32_MAX / 2) { + //回环 + _seq.clear(); + _last_max_seq = min_seq; + return; + } + + if (_seq.size() == diff + 1 && _last_max_seq + 1 == min_seq) { + //都是连续的seq,未丢包 + _seq.clear(); + _last_max_seq = max_seq; + } else { + //seq不连续,有丢包 + if (min_seq == _last_max_seq + 1) { + //前面部分seq是连续的,未丢包,移除之 + eraseFrontSeq(); + } + + //有丢包,丢包从_last_max_seq开始 + if (max_seq - _last_max_seq > FCI_NACK::kBitSize) { + vector vec; + vec.resize(FCI_NACK::kBitSize); + for (auto i = 0; i < FCI_NACK::kBitSize; ++i) { + vec[i] = _seq.find(_last_max_seq + i + 2) == _seq.end(); + } + doNack(FCI_NACK(_last_max_seq + 1, vec)); + _last_max_seq += FCI_NACK::kBitSize + 1; + if (_last_max_seq >= max_seq) { + _seq.clear(); + } else { + auto it = _seq.emplace_hint(_seq.begin(), _last_max_seq); + _seq.erase(_seq.begin(), it); + } + } + } + } + + void setOnNack(onNack cb) { + _cb = std::move(cb); + } + +private: + void doNack(const FCI_NACK &nack) { + if (_cb) { + _cb(nack); + } + } + + void eraseFrontSeq(){ + //前面部分seq是连续的,未丢包,移除之 + for (auto it = _seq.begin(); it != _seq.end();) { + if (*it != _last_max_seq + 1) { + //seq不连续,丢包了 + break; + } + _last_max_seq = *it; + it = _seq.erase(it); + } + } + +private: + onNack _cb; + set _seq; + uint16_t _last_max_seq = 0; +}; + +class WebRtcTransportImp : public WebRtcTransport, public MediaSourceEvent, public SockInfo, public std::enable_shared_from_this{ +public: + using Ptr = std::shared_ptr; + ~WebRtcTransportImp() override; + + /** + * 创建WebRTC对象 + * @param poller 改对象需要绑定的线程 + * @return 对象 + */ + static Ptr create(const EventPoller::Ptr &poller); + + /** + * 绑定rtsp媒体源 + * @param src 媒体源 + * @param is_play 是播放还是推流 + */ + void attach(const RtspMediaSource::Ptr &src, const MediaInfo &info, bool is_play = true); + +protected: + void onStartWebRTC() override; + void onSendSockData(const char *buf, size_t len, struct sockaddr_in *dst, bool flush = true) override; + void onCheckSdp(SdpType type, RtcSession &sdp) override; + void onRtcConfigure(RtcConfigure &configure) const override; + + void onRtp(const char *buf, size_t len) override; + void onRtp_l(const char *buf, size_t len, bool rtx); + + void onRtcp(const char *buf, size_t len) override; + void onBeforeEncryptRtp(const char *buf, size_t &len, void *ctx) override; + void onBeforeEncryptRtcp(const char *buf, size_t &len, void *ctx) override {}; + + void onShutdown(const SockException &ex) override; + + ///////MediaSourceEvent override/////// + // 关闭 + bool close(MediaSource &sender, bool force) override; + // 播放总人数 + int totalReaderCount(MediaSource &sender) override; + // 获取媒体源类型 + MediaOriginType getOriginType(MediaSource &sender) const override; + // 获取媒体源url或者文件路径 + string getOriginUrl(MediaSource &sender) const override; + // 获取媒体源客户端相关信息 + std::shared_ptr getOriginSock(MediaSource &sender) const override; + + ///////SockInfo override/////// + //获取本机ip + string get_local_ip() override; + //获取本机端口号 + uint16_t get_local_port() override; + //获取对方ip + string get_peer_ip() override; + //获取对方端口号 + uint16_t get_peer_port() override; + //获取标识符 + string getIdentifier() const override; + +private: + WebRtcTransportImp(const EventPoller::Ptr &poller); + void onCreate() override; + void onDestory() override; + void onSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool rtx = false); + SdpAttrCandidate::Ptr getIceCandidate() const; + bool canSendRtp() const; + bool canRecvRtp() const; + + class RtpPayloadInfo { + public: + using Ptr = std::shared_ptr; + const RtcCodecPlan *plan_rtp; + const RtcCodecPlan *plan_rtx; + uint32_t offer_ssrc_rtp = 0; + uint32_t offer_ssrc_rtx = 0; + uint32_t answer_ssrc_rtp = 0; + uint32_t answer_ssrc_rtx = 0; + const RtcMedia *media; + NackList nack_list; + NackContext nack_ctx; + RtcpContext::Ptr rtcp_context_recv; + RtcpContext::Ptr rtcp_context_send; + std::shared_ptr receiver; + }; + + void onSortedRtp(RtpPayloadInfo &info, RtpPacket::Ptr rtp); + void onSendNack(RtpPayloadInfo &info, const FCI_NACK &nack); + void changeRtpExtId(const RtpPayloadInfo *info, const RtpHeader *header, bool is_recv, bool is_rtx = false) const; + +private: + uint16_t _rtx_seq[2] = {0, 0}; + //用掉的总流量 + uint64_t _bytes_usage = 0; + //媒体相关元数据 + MediaInfo _media_info; + //保持自我强引用 + Ptr _self; + //检测超时的定时器 + Timer::Ptr _timer; + //刷新计时器 + Ticker _alive_ticker; + //pli rtcp计时器 + Ticker _pli_ticker; + //复合udp端口,接收一切rtp与rtcp + Socket::Ptr _socket; + //推流的rtsp源 + RtspMediaSource::Ptr _push_src; + //播放的rtsp源 + RtspMediaSource::Ptr _play_src; + //播放rtsp源的reader对象 + RtspMediaSource::RingType::RingReader::Ptr _reader; + //根据发送rtp的track类型获取相关信息 + RtpPayloadInfo::Ptr _send_rtp_info[2]; + //根据接收rtp的pt获取相关信息 + unordered_map > _rtp_info_pt; + //根据rtcp的ssrc获取相关信息 + unordered_map > _rtp_info_ssrc; + //发送rtp时需要修改rtp ext id + map _rtp_ext_type_to_id; + //接收rtp时需要修改rtp ext id + unordered_map _rtp_ext_id_to_type; +}; \ No newline at end of file diff --git a/webrtc/answer.sdp b/webrtc/answer.sdp new file mode 100644 index 00000000..32045375 --- /dev/null +++ b/webrtc/answer.sdp @@ -0,0 +1,50 @@ +v=0 +o=- 2712902958023202213 2 IN IP4 127.0.0.1 +s=- +t=0 0 +a=group:BUNDLE 0 1 +a=msid-semantic: WMS +m=audio 9 UDP/TLS/RTP/SAVPF 111 +c=IN IP4 0.0.0.0 +a=rtcp:9 IN IP4 0.0.0.0 +a=ice-ufrag:68ws +a=ice-pwd:68wscAOadU4rdMwZ4Ow14M5u +a=ice-options:trickle +a=fingerprint:sha-256 BF:F8:C2:35:19:2E:C3:17:44:5A:BA:DF:08:C4:65:87:AB:0C:85:B9:91:69:80:8E:55:D9:2F:EF:5C:D6:F3:A2 +a=setup:active +a=mid:0 +a=ice-lite +a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level +a=recvonly +a=rtcp-mux +a=rtpmap:111 opus/48000/2 +a=rtcp-fb:111 transport-cc +a=fmtp:111 minptime=10;useinbandfec=1 +m=video 9 UDP/TLS/RTP/SAVPF 102 121 +c=IN IP4 0.0.0.0 +a=rtcp:9 IN IP4 0.0.0.0 +a=ice-ufrag:68ws +a=ice-pwd:68wscAOadU4rdMwZ4Ow14M5u +a=ice-options:trickle +a=fingerprint:sha-256 BF:F8:C2:35:19:2E:C3:17:44:5A:BA:DF:08:C4:65:87:AB:0C:85:B9:91:69:80:8E:55:D9:2F:EF:5C:D6:F3:A2 +a=setup:active +a=mid:1 +a=ice-lite +a=extmap:14 urn:ietf:params:rtp-hdrext:toffset +a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=extmap:13 urn:3gpp:video-orientation +a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 +a=extmap:12 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay +a=recvonly +a=rtcp-mux +a=rtcp-rsize +a=rtpmap:102 H264/90000 +a=rtcp-fb:102 goog-remb +a=rtcp-fb:102 transport-cc +a=rtcp-fb:102 ccm fir +a=rtcp-fb:102 nack +a=rtcp-fb:102 nack pli +a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f +a=rtpmap:121 rtx/90000 +a=fmtp:121 apt=102 + diff --git a/webrtc/janus_answer.sdp b/webrtc/janus_answer.sdp new file mode 100644 index 00000000..345c3de7 --- /dev/null +++ b/webrtc/janus_answer.sdp @@ -0,0 +1,69 @@ +v=0 +o=mozilla...THIS_IS_SDPARTA-87.0 5715694060540081921 0 IN IP4 0.0.0.0 +s=- +t=0 0 +a=fingerprint:sha-256 9C:9C:D9:4B:2B:82:84:95:C2:23:BC:3A:0B:BE:3B:8B:D5:6A:DA:A6:B2:F4:43:5E:C1:07:48:F8:AF:CE:FC:3D +a=group:BUNDLE video data +a=ice-options:trickle +a=msid-semantic:WMS * +m=video 9 UDP/TLS/RTP/SAVPF 120 122 121 123 126 127 97 98 +c=IN IP4 0.0.0.0 +a=sendrecv +a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid +a=extmap:4 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=extmap:5 urn:ietf:params:rtp-hdrext:toffset +a=extmap:7 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 +a=fmtp:126 profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1 +a=fmtp:97 profile-level-id=42e01f;level-asymmetry-allowed=1 +a=fmtp:120 max-fs=12288;max-fr=60 +a=fmtp:122 apt=120 +a=fmtp:121 max-fs=12288;max-fr=60 +a=fmtp:123 apt=121 +a=fmtp:127 apt=126 +a=fmtp:98 apt=97 +a=ice-pwd:518cb4fc626f82bef2ada4e9221dfb50 +a=ice-ufrag:d5484fed +a=mid:video +a=msid:{9cd17d8b-f96d-4663-866b-72ddd3b8b54b} {3dcd399d-4933-41d5-89fd-87070cfc3cf6} +a=rtcp-fb:120 nack +a=rtcp-fb:120 nack pli +a=rtcp-fb:120 ccm fir +a=rtcp-fb:120 goog-remb +a=rtcp-fb:120 transport-cc +a=rtcp-fb:121 nack +a=rtcp-fb:121 nack pli +a=rtcp-fb:121 ccm fir +a=rtcp-fb:121 goog-remb +a=rtcp-fb:121 transport-cc +a=rtcp-fb:126 nack +a=rtcp-fb:126 nack pli +a=rtcp-fb:126 ccm fir +a=rtcp-fb:126 goog-remb +a=rtcp-fb:126 transport-cc +a=rtcp-fb:97 nack +a=rtcp-fb:97 nack pli +a=rtcp-fb:97 ccm fir +a=rtcp-fb:97 goog-remb +a=rtcp-fb:97 transport-cc +a=rtcp-mux +a=rtpmap:120 VP8/90000 +a=rtpmap:122 rtx/90000 +a=rtpmap:121 VP9/90000 +a=rtpmap:123 rtx/90000 +a=rtpmap:126 H264/90000 +a=rtpmap:127 rtx/90000 +a=rtpmap:97 H264/90000 +a=rtpmap:98 rtx/90000 +a=setup:active +a=ssrc:697402393 cname:{f1ba68ef-ad59-4fff-a1f3-dbbb0cda3118} +a=ssrc:258662392 cname:{f1ba68ef-ad59-4fff-a1f3-dbbb0cda3118} +a=ssrc-group:FID 697402393 258662392 +m=application 9 UDP/DTLS/SCTP webrtc-datachannel +c=IN IP4 0.0.0.0 +a=sendrecv +a=ice-pwd:518cb4fc626f82bef2ada4e9221dfb50 +a=ice-ufrag:d5484fed +a=mid:data +a=setup:active +a=sctp-port:5000 +a=max-message-size:1073741823 diff --git a/webrtc/janus_offer.sdp b/webrtc/janus_offer.sdp new file mode 100644 index 00000000..f4f454ed --- /dev/null +++ b/webrtc/janus_offer.sdp @@ -0,0 +1,83 @@ +v=0 +o=mozilla...THIS_IS_SDPARTA-87.0 1617247876363377 1 IN IP4 23.101.8.213 +s=- +t=0 0 +a=group:BUNDLE video data +a=msid-semantic: WMS janus +a=ice-lite +a=sendrecv +m=video 9 UDP/TLS/RTP/SAVPF 120 121 126 97 122 123 127 98 +c=IN IP4 23.101.8.213 +a=sendrecv +a=mid:video +a=rtcp-mux +a=ice-ufrag:ePgh +a=ice-pwd:ZURiB67/xs69E76aOa7JDw +a=ice-options:trickle +a=fingerprint:sha-256 EF:7A:50:9C:05:8C:EF:84:4D:72:B2:74:30:BA:FD:82:76:D1:C3:FE:0C:A0:10:43:B8:6C:B2:ED:B3:F7:77:8B +a=setup:actpass +a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid +a=extmap:4 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=extmap:5 urn:ietf:params:rtp-hdrext:toffset +a=extmap:6/recvonly http://www.webrtc.org/experiments/rtp-hdrext/playout-delay +a=extmap:7 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 +a=fmtp:126 profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1 +a=fmtp:97 profile-level-id=42e01f;level-asymmetry-allowed=1 +a=fmtp:120 max-fs=12288;max-fr=60 +a=fmtp:121 max-fs=12288;max-fr=60 +a=rtcp-fb:120 nack +a=rtcp-fb:120 nack pli +a=rtcp-fb:120 ccm fir +a=rtcp-fb:120 goog-remb +a=rtcp-fb:120 transport-cc +a=rtcp-fb:121 nack +a=rtcp-fb:121 nack pli +a=rtcp-fb:121 ccm fir +a=rtcp-fb:121 goog-remb +a=rtcp-fb:121 transport-cc +a=rtcp-fb:126 nack +a=rtcp-fb:126 nack pli +a=rtcp-fb:126 ccm fir +a=rtcp-fb:126 goog-remb +a=rtcp-fb:126 transport-cc +a=rtcp-fb:97 nack +a=rtcp-fb:97 nack pli +a=rtcp-fb:97 ccm fir +a=rtcp-fb:97 goog-remb +a=rtcp-fb:97 transport-cc +a=rtpmap:120 VP8/90000 +a=rtpmap:121 VP9/90000 +a=rtpmap:126 H264/90000 +a=rtpmap:97 H264/90000 +a=rtpmap:122 rtx/90000 +a=fmtp:122 apt=120 +a=rtpmap:123 rtx/90000 +a=fmtp:123 apt=121 +a=rtpmap:127 rtx/90000 +a=fmtp:127 apt=126 +a=rtpmap:98 rtx/90000 +a=fmtp:98 apt=97 +a=ssrc-group:FID 3581519470 2258376012 +a=msid:janus janusv0 +a=ssrc:3581519470 cname:janus +a=ssrc:3581519470 msid:janus janusv0 +a=ssrc:3581519470 mslabel:janus +a=ssrc:3581519470 label:janusv0 +a=ssrc:2258376012 cname:janus +a=ssrc:2258376012 msid:janus janusv0 +a=ssrc:2258376012 mslabel:janus +a=ssrc:2258376012 label:janusv0 +a=candidate:1 1 udp 2013266431 23.101.8.213 41901 typ host +a=end-of-candidates +m=application 9 UDP/DTLS/SCTP webrtc-datachannel +c=IN IP4 23.101.8.213 +a=sendrecv +a=sctp-port:5000 +a=mid:data +a=ice-ufrag:ePgh +a=ice-pwd:ZURiB67/xs69E76aOa7JDw +a=ice-options:trickle +a=fingerprint:sha-256 EF:7A:50:9C:05:8C:EF:84:4D:72:B2:74:30:BA:FD:82:76:D1:C3:FE:0C:A0:10:43:B8:6C:B2:ED:B3:F7:77:8B +a=setup:actpass +a=candidate:1 1 udp 2013266431 23.101.8.213 41901 typ host +a=end-of-candidates diff --git a/webrtc/logger.h b/webrtc/logger.h new file mode 100644 index 00000000..c708d425 --- /dev/null +++ b/webrtc/logger.h @@ -0,0 +1,29 @@ +#pragma once +#include +#include + +#if 0 +#define MS_TRACE() +#define MS_ERROR(fmt, ...) printf("error:" fmt "\n", ##__VA_ARGS__) +#define MS_THROW_ERROR(fmt, ...) do{ printf("throw:" fmt "\n", ##__VA_ARGS__); throw std::runtime_error("error"); } while(false); +#define MS_DUMP(fmt, ...) printf("dump:" fmt "\n", ##__VA_ARGS__) +#define MS_DEBUG_2TAGS(tag1, tag2,fmt, ...) printf("debug:" fmt "\n", ##__VA_ARGS__) +#define MS_WARN_2TAGS(tag1, tag2,fmt, ...) printf("warn:" fmt "\n", ##__VA_ARGS__) +#define MS_DEBUG_TAG(tag,fmt, ...) printf("debug:" fmt "\n", ##__VA_ARGS__) +#define MS_ASSERT(con, fmt, ...) do{if(!(con)) { printf("assert failed:%s" fmt "\n", #con, ##__VA_ARGS__);} assert(con); } while(false); +#define MS_ABORT(fmt, ...) do{ printf("abort:" fmt "\n", ##__VA_ARGS__); abort(); } while(false); +#define MS_WARN_TAG(tag,fmt, ...) printf("warn:" fmt "\n", ##__VA_ARGS__) +#define MS_DEBUG_DEV(fmt, ...) printf("debug:" fmt "\n", ##__VA_ARGS__) +#else +#define MS_TRACE() +#define MS_ERROR(fmt, ...) +#define MS_THROW_ERROR(fmt, ...) +#define MS_DUMP(fmt, ...) +#define MS_DEBUG_2TAGS(tag1, tag2,fmt, ...) +#define MS_WARN_2TAGS(tag1, tag2,fmt, ...) +#define MS_DEBUG_TAG(tag,fmt, ...) +#define MS_ASSERT(con, fmt, ...) +#define MS_ABORT(fmt, ...) +#define MS_WARN_TAG(tag,fmt, ...) +#define MS_DEBUG_DEV(fmt, ...) +#endif \ No newline at end of file diff --git a/webrtc/offer-simulcast.sdp b/webrtc/offer-simulcast.sdp new file mode 100644 index 00000000..d6f1ff84 --- /dev/null +++ b/webrtc/offer-simulcast.sdp @@ -0,0 +1,255 @@ +# chrome的sdp +v=0 +o=- 403371946498103831 2 IN IP4 127.0.0.1 +s=- +t=0 0 +a=group:BUNDLE 0 1 +a=extmap-allow-mixed +a=msid-semantic: WMS +m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126 +c=IN IP4 0.0.0.0 +a=rtcp:9 IN IP4 0.0.0.0 +a=ice-ufrag:pW4Z +a=ice-pwd:S38S++HW3eTcPTyytsNI1XVp +a=ice-options:trickle +a=fingerprint:sha-256 04:32:7B:56:7D:F7:D4:EC:65:7C:04:6C:F8:0B:03:F0:35:A9:1A:C3:43:3E:18:95:67:E6:0D:D1:EE:C9:16:8C +a=setup:actpass +a=mid:0 +a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level +a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 +a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid +a=extmap:5 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id +a=extmap:6 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id +a=sendrecv +a=msid:- a3c6a137-1291-45cd-b985-07a9bd365452 +a=rtcp-mux +a=rtpmap:111 opus/48000/2 +a=rtcp-fb:111 transport-cc +a=fmtp:111 minptime=10;useinbandfec=1 +a=rtpmap:103 ISAC/16000 +a=rtpmap:104 ISAC/32000 +a=rtpmap:9 G722/8000 +a=rtpmap:0 PCMU/8000 +a=rtpmap:8 PCMA/8000 +a=rtpmap:106 CN/32000 +a=rtpmap:105 CN/16000 +a=rtpmap:13 CN/8000 +a=rtpmap:110 telephone-event/48000 +a=rtpmap:112 telephone-event/32000 +a=rtpmap:113 telephone-event/16000 +a=rtpmap:126 telephone-event/8000 +a=ssrc:3626257331 cname:JSFJMbaE9Pu5tevN +a=ssrc:3626257331 msid:- a3c6a137-1291-45cd-b985-07a9bd365452 +a=ssrc:3626257331 mslabel:- +a=ssrc:3626257331 label:a3c6a137-1291-45cd-b985-07a9bd365452 +m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 121 127 120 125 107 108 109 35 36 124 119 123 118 114 115 116 +c=IN IP4 0.0.0.0 +a=rtcp:9 IN IP4 0.0.0.0 +a=ice-ufrag:pW4Z +a=ice-pwd:S38S++HW3eTcPTyytsNI1XVp +a=ice-options:trickle +a=fingerprint:sha-256 04:32:7B:56:7D:F7:D4:EC:65:7C:04:6C:F8:0B:03:F0:35:A9:1A:C3:43:3E:18:95:67:E6:0D:D1:EE:C9:16:8C +a=setup:actpass +a=mid:1 +a=extmap:14 urn:ietf:params:rtp-hdrext:toffset +a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=extmap:13 urn:3gpp:video-orientation +a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 +a=extmap:12 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay +a=extmap:11 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type +a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing +a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/color-space +a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid +a=extmap:5 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id +a=extmap:6 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id +a=sendrecv +a=msid:- 261e5384-9cf6-479d-9d59-aaf924d1a2ea +a=rtcp-mux +a=rtcp-rsize +a=rtpmap:96 VP8/90000 +a=rtcp-fb:96 goog-remb +a=rtcp-fb:96 transport-cc +a=rtcp-fb:96 ccm fir +a=rtcp-fb:96 nack +a=rtcp-fb:96 nack pli +a=rtpmap:97 rtx/90000 +a=fmtp:97 apt=96 +a=rtpmap:98 VP9/90000 +a=rtcp-fb:98 goog-remb +a=rtcp-fb:98 transport-cc +a=rtcp-fb:98 ccm fir +a=rtcp-fb:98 nack +a=rtcp-fb:98 nack pli +a=fmtp:98 profile-id=0 +a=rtpmap:99 rtx/90000 +a=fmtp:99 apt=98 +a=rtpmap:100 VP9/90000 +a=rtcp-fb:100 goog-remb +a=rtcp-fb:100 transport-cc +a=rtcp-fb:100 ccm fir +a=rtcp-fb:100 nack +a=rtcp-fb:100 nack pli +a=fmtp:100 profile-id=2 +a=rtpmap:101 rtx/90000 +a=fmtp:101 apt=100 +a=rtpmap:102 H264/90000 +a=rtcp-fb:102 goog-remb +a=rtcp-fb:102 transport-cc +a=rtcp-fb:102 ccm fir +a=rtcp-fb:102 nack +a=rtcp-fb:102 nack pli +a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f +a=rtpmap:121 rtx/90000 +a=fmtp:121 apt=102 +a=rtpmap:127 H264/90000 +a=rtcp-fb:127 goog-remb +a=rtcp-fb:127 transport-cc +a=rtcp-fb:127 ccm fir +a=rtcp-fb:127 nack +a=rtcp-fb:127 nack pli +a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f +a=rtpmap:120 rtx/90000 +a=fmtp:120 apt=127 +a=rtpmap:125 H264/90000 +a=rtcp-fb:125 goog-remb +a=rtcp-fb:125 transport-cc +a=rtcp-fb:125 ccm fir +a=rtcp-fb:125 nack +a=rtcp-fb:125 nack pli +a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f +a=rtpmap:107 rtx/90000 +a=fmtp:107 apt=125 +a=rtpmap:108 H264/90000 +a=rtcp-fb:108 goog-remb +a=rtcp-fb:108 transport-cc +a=rtcp-fb:108 ccm fir +a=rtcp-fb:108 nack +a=rtcp-fb:108 nack pli +a=fmtp:108 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f +a=rtpmap:109 rtx/90000 +a=fmtp:109 apt=108 +a=rtpmap:35 AV1X/90000 +a=rtcp-fb:35 goog-remb +a=rtcp-fb:35 transport-cc +a=rtcp-fb:35 ccm fir +a=rtcp-fb:35 nack +a=rtcp-fb:35 nack pli +a=rtpmap:36 rtx/90000 +a=fmtp:36 apt=35 +a=rtpmap:124 H264/90000 +a=rtcp-fb:124 goog-remb +a=rtcp-fb:124 transport-cc +a=rtcp-fb:124 ccm fir +a=rtcp-fb:124 nack +a=rtcp-fb:124 nack pli +a=fmtp:124 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f +a=rtpmap:119 rtx/90000 +a=fmtp:119 apt=124 +a=rtpmap:123 H264/90000 +a=rtcp-fb:123 goog-remb +a=rtcp-fb:123 transport-cc +a=rtcp-fb:123 ccm fir +a=rtcp-fb:123 nack +a=rtcp-fb:123 nack pli +a=fmtp:123 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=64001f +a=rtpmap:118 rtx/90000 +a=fmtp:118 apt=123 +a=rtpmap:114 red/90000 +a=rtpmap:115 rtx/90000 +a=fmtp:115 apt=114 +a=rtpmap:116 ulpfec/90000 +a=rid:q send +a=rid:h send +a=rid:f send +a=simulcast:send q;h;f + +#firefox的sdp +v=0 +o=mozilla...THIS_IS_SDPARTA-88.0.1 3954544078885279475 0 IN IP4 0.0.0.0 +s=- +t=0 0 +a=fingerprint:sha-256 9B:4F:D1:D2:A5:ED:08:BC:E8:D7:DD:D8:59:2C:E6:3D:19:F9:4C:67:9C:D9:9B:7B:C9:47:7A:3A:1F:05:C8:96 +a=group:BUNDLE 0 1 +a=ice-options:trickle +a=msid-semantic:WMS * +m=audio 9 UDP/TLS/RTP/SAVPF 109 9 0 8 101 +c=IN IP4 0.0.0.0 +a=sendrecv +a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level +a=extmap:2/recvonly urn:ietf:params:rtp-hdrext:csrc-audio-level +a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid +a=fmtp:109 maxplaybackrate=48000;stereo=1;useinbandfec=1 +a=fmtp:101 0-15 +a=ice-pwd:92a9ced6d734f7ff2a45cde8b29572a9 +a=ice-ufrag:b986b945 +a=mid:0 +a=msid:- {ea61729a-c244-4c79-aeb7-b57765fefa26} +a=rtcp-mux +a=rtpmap:109 opus/48000/2 +a=rtpmap:9 G722/8000/1 +a=rtpmap:0 PCMU/8000 +a=rtpmap:8 PCMA/8000 +a=rtpmap:101 telephone-event/8000/1 +a=setup:actpass +a=ssrc:3000327501 cname:{12e7c547-559e-46e2-94db-f1ad474c95dc} +m=video 9 UDP/TLS/RTP/SAVPF 120 124 121 125 126 127 97 98 +c=IN IP4 0.0.0.0 +a=sendrecv +a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid +a=extmap:4 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=extmap:5 urn:ietf:params:rtp-hdrext:toffset +a=extmap:6/recvonly http://www.webrtc.org/experiments/rtp-hdrext/playout-delay +a=extmap:7 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 +a=extmap:8/sendonly urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id +a=extmap:9/sendonly urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id +a=fmtp:126 profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1 +a=fmtp:97 profile-level-id=42e01f;level-asymmetry-allowed=1 +a=fmtp:120 max-fs=12288;max-fr=60 +a=fmtp:124 apt=120 +a=fmtp:121 max-fs=12288;max-fr=60 +a=fmtp:125 apt=121 +a=fmtp:127 apt=126 +a=fmtp:98 apt=97 +a=ice-pwd:92a9ced6d734f7ff2a45cde8b29572a9 +a=ice-ufrag:b986b945 +a=mid:1 +a=msid:- {3bfe1b80-20eb-4b42-b8b7-fac45fb281bf} +a=rid:q send +a=rid:h send +a=rid:f send +a=rtcp-fb:120 nack +a=rtcp-fb:120 nack pli +a=rtcp-fb:120 ccm fir +a=rtcp-fb:120 goog-remb +a=rtcp-fb:120 transport-cc +a=rtcp-fb:121 nack +a=rtcp-fb:121 nack pli +a=rtcp-fb:121 ccm fir +a=rtcp-fb:121 goog-remb +a=rtcp-fb:121 transport-cc +a=rtcp-fb:126 nack +a=rtcp-fb:126 nack pli +a=rtcp-fb:126 ccm fir +a=rtcp-fb:126 goog-remb +a=rtcp-fb:126 transport-cc +a=rtcp-fb:97 nack +a=rtcp-fb:97 nack pli +a=rtcp-fb:97 ccm fir +a=rtcp-fb:97 goog-remb +a=rtcp-fb:97 transport-cc +a=rtcp-mux +a=rtcp-rsize +a=rtpmap:120 VP8/90000 +a=rtpmap:124 rtx/90000 +a=rtpmap:121 VP9/90000 +a=rtpmap:125 rtx/90000 +a=rtpmap:126 H264/90000 +a=rtpmap:127 rtx/90000 +a=rtpmap:97 H264/90000 +a=rtpmap:98 rtx/90000 +a=setup:actpass +a=simulcast:send q;h;f +a=ssrc:2581133096 cname:{12e7c547-559e-46e2-94db-f1ad474c95dc} +a=ssrc:773854125 cname:{12e7c547-559e-46e2-94db-f1ad474c95dc} +a=ssrc:4100728001 cname:{12e7c547-559e-46e2-94db-f1ad474c95dc} diff --git a/webrtc/offer.sdp b/webrtc/offer.sdp new file mode 100644 index 00000000..c3b09302 --- /dev/null +++ b/webrtc/offer.sdp @@ -0,0 +1,169 @@ +v=0 +o=- 8056465047193717905 2 IN IP4 127.0.0.1 +s=- +t=0 0 +a=group:BUNDLE 0 1 +a=extmap-allow-mixed +a=msid-semantic: WMS +m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126 +c=IN IP4 0.0.0.0 +a=rtcp:9 IN IP4 0.0.0.0 +a=ice-ufrag:LtFR +a=ice-pwd:sUVVlvhNoL2g/GL36TyfZGwP +a=ice-options:trickle +a=fingerprint:sha-256 21:21:07:E8:3C:D0:3B:45:87:9A:31:86:DE:4F:C1:BA:E1:0E:96:BA:41:36:6E:3A:3F:C6:C8:92:95:5B:71:5F +a=setup:actpass +a=mid:0 +a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level +a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 +a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid +a=extmap:5 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id +a=extmap:6 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id +a=sendrecv +a=msid:- 2ebeb64c-2eb3-4c4f-b5d5-d578245b969e +a=rtcp-mux +a=rtpmap:111 opus/48000/2 +a=rtcp-fb:111 transport-cc +a=fmtp:111 minptime=10;useinbandfec=1 +a=rtpmap:103 ISAC/16000 +a=rtpmap:104 ISAC/32000 +a=rtpmap:9 G722/8000 +a=rtpmap:0 PCMU/8000 +a=rtpmap:8 PCMA/8000 +a=rtpmap:106 CN/32000 +a=rtpmap:105 CN/16000 +a=rtpmap:13 CN/8000 +a=rtpmap:110 telephone-event/48000 +a=rtpmap:112 telephone-event/32000 +a=rtpmap:113 telephone-event/16000 +a=rtpmap:126 telephone-event/8000 +a=ssrc:905965261 cname:7iEkMV0/MMfqSEce +a=ssrc:905965261 msid:- 2ebeb64c-2eb3-4c4f-b5d5-d578245b969e +a=ssrc:905965261 mslabel:- +a=ssrc:905965261 label:2ebeb64c-2eb3-4c4f-b5d5-d578245b969e +m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 121 127 120 125 107 108 109 35 36 124 119 123 118 114 115 116 +c=IN IP4 0.0.0.0 +a=rtcp:9 IN IP4 0.0.0.0 +a=ice-ufrag:LtFR +a=ice-pwd:sUVVlvhNoL2g/GL36TyfZGwP +a=ice-options:trickle +a=fingerprint:sha-256 21:21:07:E8:3C:D0:3B:45:87:9A:31:86:DE:4F:C1:BA:E1:0E:96:BA:41:36:6E:3A:3F:C6:C8:92:95:5B:71:5F +a=setup:actpass +a=mid:1 +a=extmap:14 urn:ietf:params:rtp-hdrext:toffset +a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time +a=extmap:13 urn:3gpp:video-orientation +a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 +a=extmap:12 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay +a=extmap:11 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type +a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing +a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/color-space +a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid +a=extmap:5 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id +a=extmap:6 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id +a=sendrecv +a=msid:- f36bb41d-d05d-4310-b05b-7913d0029b18 +a=rtcp-mux +a=rtcp-rsize +a=rtpmap:96 VP8/90000 +a=rtcp-fb:96 goog-remb +a=rtcp-fb:96 transport-cc +a=rtcp-fb:96 ccm fir +a=rtcp-fb:96 nack +a=rtcp-fb:96 nack pli +a=rtpmap:97 rtx/90000 +a=fmtp:97 apt=96 +a=rtpmap:98 VP9/90000 +a=rtcp-fb:98 goog-remb +a=rtcp-fb:98 transport-cc +a=rtcp-fb:98 ccm fir +a=rtcp-fb:98 nack +a=rtcp-fb:98 nack pli +a=fmtp:98 profile-id=0 +a=rtpmap:99 rtx/90000 +a=fmtp:99 apt=98 +a=rtpmap:100 VP9/90000 +a=rtcp-fb:100 goog-remb +a=rtcp-fb:100 transport-cc +a=rtcp-fb:100 ccm fir +a=rtcp-fb:100 nack +a=rtcp-fb:100 nack pli +a=fmtp:100 profile-id=2 +a=rtpmap:101 rtx/90000 +a=fmtp:101 apt=100 +a=rtpmap:102 H264/90000 +a=rtcp-fb:102 goog-remb +a=rtcp-fb:102 transport-cc +a=rtcp-fb:102 ccm fir +a=rtcp-fb:102 nack +a=rtcp-fb:102 nack pli +a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f +a=rtpmap:121 rtx/90000 +a=fmtp:121 apt=102 +a=rtpmap:127 H264/90000 +a=rtcp-fb:127 goog-remb +a=rtcp-fb:127 transport-cc +a=rtcp-fb:127 ccm fir +a=rtcp-fb:127 nack +a=rtcp-fb:127 nack pli +a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f +a=rtpmap:120 rtx/90000 +a=fmtp:120 apt=127 +a=rtpmap:125 H264/90000 +a=rtcp-fb:125 goog-remb +a=rtcp-fb:125 transport-cc +a=rtcp-fb:125 ccm fir +a=rtcp-fb:125 nack +a=rtcp-fb:125 nack pli +a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f +a=rtpmap:107 rtx/90000 +a=fmtp:107 apt=125 +a=rtpmap:108 H264/90000 +a=rtcp-fb:108 goog-remb +a=rtcp-fb:108 transport-cc +a=rtcp-fb:108 ccm fir +a=rtcp-fb:108 nack +a=rtcp-fb:108 nack pli +a=fmtp:108 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f +a=rtpmap:109 rtx/90000 +a=fmtp:109 apt=108 +a=rtpmap:35 AV1X/90000 +a=rtcp-fb:35 goog-remb +a=rtcp-fb:35 transport-cc +a=rtcp-fb:35 ccm fir +a=rtcp-fb:35 nack +a=rtcp-fb:35 nack pli +a=rtpmap:36 rtx/90000 +a=fmtp:36 apt=35 +a=rtpmap:124 H264/90000 +a=rtcp-fb:124 goog-remb +a=rtcp-fb:124 transport-cc +a=rtcp-fb:124 ccm fir +a=rtcp-fb:124 nack +a=rtcp-fb:124 nack pli +a=fmtp:124 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d0032 +a=rtpmap:119 rtx/90000 +a=fmtp:119 apt=124 +a=rtpmap:123 H264/90000 +a=rtcp-fb:123 goog-remb +a=rtcp-fb:123 transport-cc +a=rtcp-fb:123 ccm fir +a=rtcp-fb:123 nack +a=rtcp-fb:123 nack pli +a=fmtp:123 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640032 +a=rtpmap:118 rtx/90000 +a=fmtp:118 apt=123 +a=rtpmap:114 red/90000 +a=rtpmap:115 rtx/90000 +a=fmtp:115 apt=114 +a=rtpmap:116 ulpfec/90000 +a=ssrc-group:FID 2678501654 361960375 +a=ssrc:2678501654 cname:7iEkMV0/MMfqSEce +a=ssrc:2678501654 msid:- f36bb41d-d05d-4310-b05b-7913d0029b18 +a=ssrc:2678501654 mslabel:- +a=ssrc:2678501654 label:f36bb41d-d05d-4310-b05b-7913d0029b18 +a=ssrc:361960375 cname:7iEkMV0/MMfqSEce +a=ssrc:361960375 msid:- f36bb41d-d05d-4310-b05b-7913d0029b18 +a=ssrc:361960375 mslabel:- +a=ssrc:361960375 label:f36bb41d-d05d-4310-b05b-7913d0029b18 \ No newline at end of file diff --git a/webrtc/readme.md b/webrtc/readme.md new file mode 100644 index 00000000..87d21b85 --- /dev/null +++ b/webrtc/readme.md @@ -0,0 +1,37 @@ +# 致谢与声明 +本文件夹下部分文件提取自[MediaSoup](https://github.com/versatica/mediasoup) ,分别为: + +- ice相关功能: + - IceServer.cpp + - IceServer.hpp + - StunPacket.cpp + - StunPacket.hpp + - Utils.hpp + +- dtls相关功能: + - DtlsTransport.cpp + - DtlsTransport.hpp + +- srtp相关功能: + - SrtpSession.cpp + - SrtpSession.hpp + + +以上源码有一定的修改和裁剪,感谢MediaSoup开源项目及作者, +用户在使用本项目的同时,应该同时遵循MediaSoup的开源协议。 + +同时,在此也感谢开源项目[easy_webrtc_server](https://github.com/Mihawk086/easy_webrtc_server) 及作者, +在集成MediaSoup相关代码前期,主要参考这个项目。 + +另外,感谢[big panda](<2381267071@qq.com>) 开发并贡献的webrtc js测试客户端(www/webrtc目录下文件), +其开源项目地址为:https://gitee.com/xiongguangjie/zlmrtcclient.js + +# 现状与规划 +ZLMediaKit的WebRTC相关功能目前仅供测试与开发,现在还不成熟,后续主要工作有: + +- 1、完善webrtc rtcp相关功能,包括丢包重传、带宽检测等功能。 +- 2、实现rtp重传等相关功能。 +- 3、实现simulcast相关功能。 +- 4、fec、rtp扩展等其他功能。 +- 5、如果精力允许,逐步替换MediaSoup相关代码,改用自有版权代码。 + diff --git a/www/webrtc/ZLMRTCClient.js b/www/webrtc/ZLMRTCClient.js new file mode 100644 index 00000000..a92ed4a4 --- /dev/null +++ b/www/webrtc/ZLMRTCClient.js @@ -0,0 +1,7648 @@ +var ZLMRTCClient = (function (exports) { + 'use strict'; + + const Events$1 = { + WEBRTC_NOT_SUPPORT: 'WEBRTC_NOT_SUPPORT', + WEBRTC_ICE_CANDIDATE_ERROR: 'WEBRTC_ICE_CANDIDATE_ERROR', + WEBRTC_OFFER_ANSWER_EXCHANGE_FAILED: 'WEBRTC_OFFER_ANSWER_EXCHANGE_FAILED', + WEBRTC_ON_REMOTE_STREAMS: 'WEBRTC_ON_REMOTE_STREAMS', + WEBRTC_ON_LOCAL_STREAM: 'WEBRTC_ON_LOCAL_STREAM', + CAPTURE_STREAM_FAILED: 'CAPTURE_STREAM_FAILED' + }; + + const VERSION = '1.0.1'; + const BUILD_DATE = 'Mon Jun 07 2021 18:09:53 GMT+0800 (China Standard Time)'; + + // Copyright (C) <2018> Intel Corporation + // + // SPDX-License-Identifier: Apache-2.0 + // eslint-disable-next-line require-jsdoc + function isFirefox() { + return window.navigator.userAgent.match('Firefox') !== null; + } // eslint-disable-next-line require-jsdoc + + function isChrome() { + return window.navigator.userAgent.match('Chrome') !== null; + } // eslint-disable-next-line require-jsdoc + + function isEdge() { + return window.navigator.userAgent.match(/Edge\/(\d+).(\d+)$/) !== null; + } // eslint-disable-next-line require-jsdoc + + // Copyright (C) <2018> Intel Corporation + /** + * @class AudioSourceInfo + * @classDesc Source info about an audio track. Values: 'mic', 'screen-cast', 'file', 'mixed'. + * @memberOf Owt.Base + * @readonly + * @enum {string} + */ + + const AudioSourceInfo = { + MIC: 'mic', + SCREENCAST: 'screen-cast', + FILE: 'file', + MIXED: 'mixed' + }; + /** + * @class VideoSourceInfo + * @classDesc Source info about a video track. Values: 'camera', 'screen-cast', 'file', 'mixed'. + * @memberOf Owt.Base + * @readonly + * @enum {string} + */ + + const VideoSourceInfo = { + CAMERA: 'camera', + SCREENCAST: 'screen-cast', + FILE: 'file', + MIXED: 'mixed' + }; + /** + * @class TrackKind + * @classDesc Kind of a track. Values: 'audio' for audio track, 'video' for video track, 'av' for both audio and video tracks. + * @memberOf Owt.Base + * @readonly + * @enum {string} + */ + + const TrackKind = { + /** + * Audio tracks. + * @type string + */ + AUDIO: 'audio', + + /** + * Video tracks. + * @type string + */ + VIDEO: 'video', + + /** + * Both audio and video tracks. + * @type string + */ + AUDIO_AND_VIDEO: 'av' + }; + /** + * @class Resolution + * @memberOf Owt.Base + * @classDesc The Resolution defines the size of a rectangle. + * @constructor + * @param {number} width + * @param {number} height + */ + + class Resolution { + // eslint-disable-next-line require-jsdoc + constructor(width, height) { + /** + * @member {number} width + * @instance + * @memberof Owt.Base.Resolution + */ + this.width = width; + /** + * @member {number} height + * @instance + * @memberof Owt.Base.Resolution + */ + + this.height = height; + } + + } + + /* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + let logDisabled_ = true; + let deprecationWarnings_ = true; + + /** + * Extract browser version out of the provided user agent string. + * + * @param {!string} uastring userAgent string. + * @param {!string} expr Regular expression used as match criteria. + * @param {!number} pos position in the version string to be returned. + * @return {!number} browser version. + */ + function extractVersion(uastring, expr, pos) { + const match = uastring.match(expr); + return match && match.length >= pos && parseInt(match[pos], 10); + } + + // Wraps the peerconnection event eventNameToWrap in a function + // which returns the modified event object (or false to prevent + // the event). + function wrapPeerConnectionEvent(window, eventNameToWrap, wrapper) { + if (!window.RTCPeerConnection) { + return; + } + const proto = window.RTCPeerConnection.prototype; + const nativeAddEventListener = proto.addEventListener; + proto.addEventListener = function(nativeEventName, cb) { + if (nativeEventName !== eventNameToWrap) { + return nativeAddEventListener.apply(this, arguments); + } + const wrappedCallback = (e) => { + const modifiedEvent = wrapper(e); + if (modifiedEvent) { + if (cb.handleEvent) { + cb.handleEvent(modifiedEvent); + } else { + cb(modifiedEvent); + } + } + }; + this._eventMap = this._eventMap || {}; + if (!this._eventMap[eventNameToWrap]) { + this._eventMap[eventNameToWrap] = new Map(); + } + this._eventMap[eventNameToWrap].set(cb, wrappedCallback); + return nativeAddEventListener.apply(this, [nativeEventName, + wrappedCallback]); + }; + + const nativeRemoveEventListener = proto.removeEventListener; + proto.removeEventListener = function(nativeEventName, cb) { + if (nativeEventName !== eventNameToWrap || !this._eventMap + || !this._eventMap[eventNameToWrap]) { + return nativeRemoveEventListener.apply(this, arguments); + } + if (!this._eventMap[eventNameToWrap].has(cb)) { + return nativeRemoveEventListener.apply(this, arguments); + } + const unwrappedCb = this._eventMap[eventNameToWrap].get(cb); + this._eventMap[eventNameToWrap].delete(cb); + if (this._eventMap[eventNameToWrap].size === 0) { + delete this._eventMap[eventNameToWrap]; + } + if (Object.keys(this._eventMap).length === 0) { + delete this._eventMap; + } + return nativeRemoveEventListener.apply(this, [nativeEventName, + unwrappedCb]); + }; + + Object.defineProperty(proto, 'on' + eventNameToWrap, { + get() { + return this['_on' + eventNameToWrap]; + }, + set(cb) { + if (this['_on' + eventNameToWrap]) { + this.removeEventListener(eventNameToWrap, + this['_on' + eventNameToWrap]); + delete this['_on' + eventNameToWrap]; + } + if (cb) { + this.addEventListener(eventNameToWrap, + this['_on' + eventNameToWrap] = cb); + } + }, + enumerable: true, + configurable: true + }); + } + + function disableLog(bool) { + if (typeof bool !== 'boolean') { + return new Error('Argument type: ' + typeof bool + + '. Please use a boolean.'); + } + logDisabled_ = bool; + return (bool) ? 'adapter.js logging disabled' : + 'adapter.js logging enabled'; + } + + /** + * Disable or enable deprecation warnings + * @param {!boolean} bool set to true to disable warnings. + */ + function disableWarnings(bool) { + if (typeof bool !== 'boolean') { + return new Error('Argument type: ' + typeof bool + + '. Please use a boolean.'); + } + deprecationWarnings_ = !bool; + return 'adapter.js deprecation warnings ' + (bool ? 'disabled' : 'enabled'); + } + + function log$1() { + if (typeof window === 'object') { + if (logDisabled_) { + return; + } + if (typeof console !== 'undefined' && typeof console.log === 'function') { + console.log.apply(console, arguments); + } + } + } + + /** + * Shows a deprecation warning suggesting the modern and spec-compatible API. + */ + function deprecated(oldMethod, newMethod) { + if (!deprecationWarnings_) { + return; + } + console.warn(oldMethod + ' is deprecated, please use ' + newMethod + + ' instead.'); + } + + /** + * Browser detector. + * + * @return {object} result containing browser and version + * properties. + */ + function detectBrowser(window) { + // Returned result object. + const result = {browser: null, version: null}; + + // Fail early if it's not a browser + if (typeof window === 'undefined' || !window.navigator) { + result.browser = 'Not a browser.'; + return result; + } + + const {navigator} = window; + + if (navigator.mozGetUserMedia) { // Firefox. + result.browser = 'firefox'; + result.version = extractVersion(navigator.userAgent, + /Firefox\/(\d+)\./, 1); + } else if (navigator.webkitGetUserMedia || + (window.isSecureContext === false && window.webkitRTCPeerConnection && + !window.RTCIceGatherer)) { + // Chrome, Chromium, Webview, Opera. + // Version matches Chrome/WebRTC version. + // Chrome 74 removed webkitGetUserMedia on http as well so we need the + // more complicated fallback to webkitRTCPeerConnection. + result.browser = 'chrome'; + result.version = extractVersion(navigator.userAgent, + /Chrom(e|ium)\/(\d+)\./, 2); + } else if (navigator.mediaDevices && + navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)) { // Edge. + result.browser = 'edge'; + result.version = extractVersion(navigator.userAgent, + /Edge\/(\d+).(\d+)$/, 2); + } else if (window.RTCPeerConnection && + navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) { // Safari. + result.browser = 'safari'; + result.version = extractVersion(navigator.userAgent, + /AppleWebKit\/(\d+)\./, 1); + result.supportsUnifiedPlan = window.RTCRtpTransceiver && + 'currentDirection' in window.RTCRtpTransceiver.prototype; + } else { // Default fallthrough: not supported. + result.browser = 'Not a supported browser.'; + return result; + } + + return result; + } + + /** + * Checks if something is an object. + * + * @param {*} val The something you want to check. + * @return true if val is an object, false otherwise. + */ + function isObject$1(val) { + return Object.prototype.toString.call(val) === '[object Object]'; + } + + /** + * Remove all empty objects and undefined values + * from a nested object -- an enhanced and vanilla version + * of Lodash's `compact`. + */ + function compactObject(data) { + if (!isObject$1(data)) { + return data; + } + + return Object.keys(data).reduce(function(accumulator, key) { + const isObj = isObject$1(data[key]); + const value = isObj ? compactObject(data[key]) : data[key]; + const isEmptyObject = isObj && !Object.keys(value).length; + if (value === undefined || isEmptyObject) { + return accumulator; + } + return Object.assign(accumulator, {[key]: value}); + }, {}); + } + + /* iterates the stats graph recursively. */ + function walkStats(stats, base, resultSet) { + if (!base || resultSet.has(base.id)) { + return; + } + resultSet.set(base.id, base); + Object.keys(base).forEach(name => { + if (name.endsWith('Id')) { + walkStats(stats, stats.get(base[name]), resultSet); + } else if (name.endsWith('Ids')) { + base[name].forEach(id => { + walkStats(stats, stats.get(id), resultSet); + }); + } + }); + } + + /* filter getStats for a sender/receiver track. */ + function filterStats(result, track, outbound) { + const streamStatsType = outbound ? 'outbound-rtp' : 'inbound-rtp'; + const filteredResult = new Map(); + if (track === null) { + return filteredResult; + } + const trackStats = []; + result.forEach(value => { + if (value.type === 'track' && + value.trackIdentifier === track.id) { + trackStats.push(value); + } + }); + trackStats.forEach(trackStat => { + result.forEach(stats => { + if (stats.type === streamStatsType && stats.trackId === trackStat.id) { + walkStats(result, stats, filteredResult); + } + }); + }); + return filteredResult; + } + + /* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + const logging = log$1; + + function shimGetUserMedia$3(window, browserDetails) { + const navigator = window && window.navigator; + + if (!navigator.mediaDevices) { + return; + } + + const constraintsToChrome_ = function(c) { + if (typeof c !== 'object' || c.mandatory || c.optional) { + return c; + } + const cc = {}; + Object.keys(c).forEach(key => { + if (key === 'require' || key === 'advanced' || key === 'mediaSource') { + return; + } + const r = (typeof c[key] === 'object') ? c[key] : {ideal: c[key]}; + if (r.exact !== undefined && typeof r.exact === 'number') { + r.min = r.max = r.exact; + } + const oldname_ = function(prefix, name) { + if (prefix) { + return prefix + name.charAt(0).toUpperCase() + name.slice(1); + } + return (name === 'deviceId') ? 'sourceId' : name; + }; + if (r.ideal !== undefined) { + cc.optional = cc.optional || []; + let oc = {}; + if (typeof r.ideal === 'number') { + oc[oldname_('min', key)] = r.ideal; + cc.optional.push(oc); + oc = {}; + oc[oldname_('max', key)] = r.ideal; + cc.optional.push(oc); + } else { + oc[oldname_('', key)] = r.ideal; + cc.optional.push(oc); + } + } + if (r.exact !== undefined && typeof r.exact !== 'number') { + cc.mandatory = cc.mandatory || {}; + cc.mandatory[oldname_('', key)] = r.exact; + } else { + ['min', 'max'].forEach(mix => { + if (r[mix] !== undefined) { + cc.mandatory = cc.mandatory || {}; + cc.mandatory[oldname_(mix, key)] = r[mix]; + } + }); + } + }); + if (c.advanced) { + cc.optional = (cc.optional || []).concat(c.advanced); + } + return cc; + }; + + const shimConstraints_ = function(constraints, func) { + if (browserDetails.version >= 61) { + return func(constraints); + } + constraints = JSON.parse(JSON.stringify(constraints)); + if (constraints && typeof constraints.audio === 'object') { + const remap = function(obj, a, b) { + if (a in obj && !(b in obj)) { + obj[b] = obj[a]; + delete obj[a]; + } + }; + constraints = JSON.parse(JSON.stringify(constraints)); + remap(constraints.audio, 'autoGainControl', 'googAutoGainControl'); + remap(constraints.audio, 'noiseSuppression', 'googNoiseSuppression'); + constraints.audio = constraintsToChrome_(constraints.audio); + } + if (constraints && typeof constraints.video === 'object') { + // Shim facingMode for mobile & surface pro. + let face = constraints.video.facingMode; + face = face && ((typeof face === 'object') ? face : {ideal: face}); + const getSupportedFacingModeLies = browserDetails.version < 66; + + if ((face && (face.exact === 'user' || face.exact === 'environment' || + face.ideal === 'user' || face.ideal === 'environment')) && + !(navigator.mediaDevices.getSupportedConstraints && + navigator.mediaDevices.getSupportedConstraints().facingMode && + !getSupportedFacingModeLies)) { + delete constraints.video.facingMode; + let matches; + if (face.exact === 'environment' || face.ideal === 'environment') { + matches = ['back', 'rear']; + } else if (face.exact === 'user' || face.ideal === 'user') { + matches = ['front']; + } + if (matches) { + // Look for matches in label, or use last cam for back (typical). + return navigator.mediaDevices.enumerateDevices() + .then(devices => { + devices = devices.filter(d => d.kind === 'videoinput'); + let dev = devices.find(d => matches.some(match => + d.label.toLowerCase().includes(match))); + if (!dev && devices.length && matches.includes('back')) { + dev = devices[devices.length - 1]; // more likely the back cam + } + if (dev) { + constraints.video.deviceId = face.exact ? {exact: dev.deviceId} : + {ideal: dev.deviceId}; + } + constraints.video = constraintsToChrome_(constraints.video); + logging('chrome: ' + JSON.stringify(constraints)); + return func(constraints); + }); + } + } + constraints.video = constraintsToChrome_(constraints.video); + } + logging('chrome: ' + JSON.stringify(constraints)); + return func(constraints); + }; + + const shimError_ = function(e) { + if (browserDetails.version >= 64) { + return e; + } + return { + name: { + PermissionDeniedError: 'NotAllowedError', + PermissionDismissedError: 'NotAllowedError', + InvalidStateError: 'NotAllowedError', + DevicesNotFoundError: 'NotFoundError', + ConstraintNotSatisfiedError: 'OverconstrainedError', + TrackStartError: 'NotReadableError', + MediaDeviceFailedDueToShutdown: 'NotAllowedError', + MediaDeviceKillSwitchOn: 'NotAllowedError', + TabCaptureError: 'AbortError', + ScreenCaptureError: 'AbortError', + DeviceCaptureError: 'AbortError' + }[e.name] || e.name, + message: e.message, + constraint: e.constraint || e.constraintName, + toString() { + return this.name + (this.message && ': ') + this.message; + } + }; + }; + + const getUserMedia_ = function(constraints, onSuccess, onError) { + shimConstraints_(constraints, c => { + navigator.webkitGetUserMedia(c, onSuccess, e => { + if (onError) { + onError(shimError_(e)); + } + }); + }); + }; + navigator.getUserMedia = getUserMedia_.bind(navigator); + + // Even though Chrome 45 has navigator.mediaDevices and a getUserMedia + // function which returns a Promise, it does not accept spec-style + // constraints. + if (navigator.mediaDevices.getUserMedia) { + const origGetUserMedia = navigator.mediaDevices.getUserMedia. + bind(navigator.mediaDevices); + navigator.mediaDevices.getUserMedia = function(cs) { + return shimConstraints_(cs, c => origGetUserMedia(c).then(stream => { + if (c.audio && !stream.getAudioTracks().length || + c.video && !stream.getVideoTracks().length) { + stream.getTracks().forEach(track => { + track.stop(); + }); + throw new DOMException('', 'NotFoundError'); + } + return stream; + }, e => Promise.reject(shimError_(e)))); + }; + } + } + + /* + * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + function shimGetDisplayMedia$2(window, getSourceId) { + if (window.navigator.mediaDevices && + 'getDisplayMedia' in window.navigator.mediaDevices) { + return; + } + if (!(window.navigator.mediaDevices)) { + return; + } + // getSourceId is a function that returns a promise resolving with + // the sourceId of the screen/window/tab to be shared. + if (typeof getSourceId !== 'function') { + console.error('shimGetDisplayMedia: getSourceId argument is not ' + + 'a function'); + return; + } + window.navigator.mediaDevices.getDisplayMedia = + function getDisplayMedia(constraints) { + return getSourceId(constraints) + .then(sourceId => { + const widthSpecified = constraints.video && constraints.video.width; + const heightSpecified = constraints.video && + constraints.video.height; + const frameRateSpecified = constraints.video && + constraints.video.frameRate; + constraints.video = { + mandatory: { + chromeMediaSource: 'desktop', + chromeMediaSourceId: sourceId, + maxFrameRate: frameRateSpecified || 3 + } + }; + if (widthSpecified) { + constraints.video.mandatory.maxWidth = widthSpecified; + } + if (heightSpecified) { + constraints.video.mandatory.maxHeight = heightSpecified; + } + return window.navigator.mediaDevices.getUserMedia(constraints); + }); + }; + } + + /* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + function shimMediaStream(window) { + window.MediaStream = window.MediaStream || window.webkitMediaStream; + } + + function shimOnTrack$1(window) { + if (typeof window === 'object' && window.RTCPeerConnection && !('ontrack' in + window.RTCPeerConnection.prototype)) { + Object.defineProperty(window.RTCPeerConnection.prototype, 'ontrack', { + get() { + return this._ontrack; + }, + set(f) { + if (this._ontrack) { + this.removeEventListener('track', this._ontrack); + } + this.addEventListener('track', this._ontrack = f); + }, + enumerable: true, + configurable: true + }); + const origSetRemoteDescription = + window.RTCPeerConnection.prototype.setRemoteDescription; + window.RTCPeerConnection.prototype.setRemoteDescription = + function setRemoteDescription() { + if (!this._ontrackpoly) { + this._ontrackpoly = (e) => { + // onaddstream does not fire when a track is added to an existing + // stream. But stream.onaddtrack is implemented so we use that. + e.stream.addEventListener('addtrack', te => { + let receiver; + if (window.RTCPeerConnection.prototype.getReceivers) { + receiver = this.getReceivers() + .find(r => r.track && r.track.id === te.track.id); + } else { + receiver = {track: te.track}; + } + + const event = new Event('track'); + event.track = te.track; + event.receiver = receiver; + event.transceiver = {receiver}; + event.streams = [e.stream]; + this.dispatchEvent(event); + }); + e.stream.getTracks().forEach(track => { + let receiver; + if (window.RTCPeerConnection.prototype.getReceivers) { + receiver = this.getReceivers() + .find(r => r.track && r.track.id === track.id); + } else { + receiver = {track}; + } + const event = new Event('track'); + event.track = track; + event.receiver = receiver; + event.transceiver = {receiver}; + event.streams = [e.stream]; + this.dispatchEvent(event); + }); + }; + this.addEventListener('addstream', this._ontrackpoly); + } + return origSetRemoteDescription.apply(this, arguments); + }; + } else { + // even if RTCRtpTransceiver is in window, it is only used and + // emitted in unified-plan. Unfortunately this means we need + // to unconditionally wrap the event. + wrapPeerConnectionEvent(window, 'track', e => { + if (!e.transceiver) { + Object.defineProperty(e, 'transceiver', + {value: {receiver: e.receiver}}); + } + return e; + }); + } + } + + function shimGetSendersWithDtmf(window) { + // Overrides addTrack/removeTrack, depends on shimAddTrackRemoveTrack. + if (typeof window === 'object' && window.RTCPeerConnection && + !('getSenders' in window.RTCPeerConnection.prototype) && + 'createDTMFSender' in window.RTCPeerConnection.prototype) { + const shimSenderWithDtmf = function(pc, track) { + return { + track, + get dtmf() { + if (this._dtmf === undefined) { + if (track.kind === 'audio') { + this._dtmf = pc.createDTMFSender(track); + } else { + this._dtmf = null; + } + } + return this._dtmf; + }, + _pc: pc + }; + }; + + // augment addTrack when getSenders is not available. + if (!window.RTCPeerConnection.prototype.getSenders) { + window.RTCPeerConnection.prototype.getSenders = function getSenders() { + this._senders = this._senders || []; + return this._senders.slice(); // return a copy of the internal state. + }; + const origAddTrack = window.RTCPeerConnection.prototype.addTrack; + window.RTCPeerConnection.prototype.addTrack = + function addTrack(track, stream) { + let sender = origAddTrack.apply(this, arguments); + if (!sender) { + sender = shimSenderWithDtmf(this, track); + this._senders.push(sender); + } + return sender; + }; + + const origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack; + window.RTCPeerConnection.prototype.removeTrack = + function removeTrack(sender) { + origRemoveTrack.apply(this, arguments); + const idx = this._senders.indexOf(sender); + if (idx !== -1) { + this._senders.splice(idx, 1); + } + }; + } + const origAddStream = window.RTCPeerConnection.prototype.addStream; + window.RTCPeerConnection.prototype.addStream = function addStream(stream) { + this._senders = this._senders || []; + origAddStream.apply(this, [stream]); + stream.getTracks().forEach(track => { + this._senders.push(shimSenderWithDtmf(this, track)); + }); + }; + + const origRemoveStream = window.RTCPeerConnection.prototype.removeStream; + window.RTCPeerConnection.prototype.removeStream = + function removeStream(stream) { + this._senders = this._senders || []; + origRemoveStream.apply(this, [stream]); + + stream.getTracks().forEach(track => { + const sender = this._senders.find(s => s.track === track); + if (sender) { // remove sender + this._senders.splice(this._senders.indexOf(sender), 1); + } + }); + }; + } else if (typeof window === 'object' && window.RTCPeerConnection && + 'getSenders' in window.RTCPeerConnection.prototype && + 'createDTMFSender' in window.RTCPeerConnection.prototype && + window.RTCRtpSender && + !('dtmf' in window.RTCRtpSender.prototype)) { + const origGetSenders = window.RTCPeerConnection.prototype.getSenders; + window.RTCPeerConnection.prototype.getSenders = function getSenders() { + const senders = origGetSenders.apply(this, []); + senders.forEach(sender => sender._pc = this); + return senders; + }; + + Object.defineProperty(window.RTCRtpSender.prototype, 'dtmf', { + get() { + if (this._dtmf === undefined) { + if (this.track.kind === 'audio') { + this._dtmf = this._pc.createDTMFSender(this.track); + } else { + this._dtmf = null; + } + } + return this._dtmf; + } + }); + } + } + + function shimGetStats(window) { + if (!window.RTCPeerConnection) { + return; + } + + const origGetStats = window.RTCPeerConnection.prototype.getStats; + window.RTCPeerConnection.prototype.getStats = function getStats() { + const [selector, onSucc, onErr] = arguments; + + // If selector is a function then we are in the old style stats so just + // pass back the original getStats format to avoid breaking old users. + if (arguments.length > 0 && typeof selector === 'function') { + return origGetStats.apply(this, arguments); + } + + // When spec-style getStats is supported, return those when called with + // either no arguments or the selector argument is null. + if (origGetStats.length === 0 && (arguments.length === 0 || + typeof selector !== 'function')) { + return origGetStats.apply(this, []); + } + + const fixChromeStats_ = function(response) { + const standardReport = {}; + const reports = response.result(); + reports.forEach(report => { + const standardStats = { + id: report.id, + timestamp: report.timestamp, + type: { + localcandidate: 'local-candidate', + remotecandidate: 'remote-candidate' + }[report.type] || report.type + }; + report.names().forEach(name => { + standardStats[name] = report.stat(name); + }); + standardReport[standardStats.id] = standardStats; + }); + + return standardReport; + }; + + // shim getStats with maplike support + const makeMapStats = function(stats) { + return new Map(Object.keys(stats).map(key => [key, stats[key]])); + }; + + if (arguments.length >= 2) { + const successCallbackWrapper_ = function(response) { + onSucc(makeMapStats(fixChromeStats_(response))); + }; + + return origGetStats.apply(this, [successCallbackWrapper_, + selector]); + } + + // promise-support + return new Promise((resolve, reject) => { + origGetStats.apply(this, [ + function(response) { + resolve(makeMapStats(fixChromeStats_(response))); + }, reject]); + }).then(onSucc, onErr); + }; + } + + function shimSenderReceiverGetStats(window) { + if (!(typeof window === 'object' && window.RTCPeerConnection && + window.RTCRtpSender && window.RTCRtpReceiver)) { + return; + } + + // shim sender stats. + if (!('getStats' in window.RTCRtpSender.prototype)) { + const origGetSenders = window.RTCPeerConnection.prototype.getSenders; + if (origGetSenders) { + window.RTCPeerConnection.prototype.getSenders = function getSenders() { + const senders = origGetSenders.apply(this, []); + senders.forEach(sender => sender._pc = this); + return senders; + }; + } + + const origAddTrack = window.RTCPeerConnection.prototype.addTrack; + if (origAddTrack) { + window.RTCPeerConnection.prototype.addTrack = function addTrack() { + const sender = origAddTrack.apply(this, arguments); + sender._pc = this; + return sender; + }; + } + window.RTCRtpSender.prototype.getStats = function getStats() { + const sender = this; + return this._pc.getStats().then(result => + /* Note: this will include stats of all senders that + * send a track with the same id as sender.track as + * it is not possible to identify the RTCRtpSender. + */ + filterStats(result, sender.track, true)); + }; + } + + // shim receiver stats. + if (!('getStats' in window.RTCRtpReceiver.prototype)) { + const origGetReceivers = window.RTCPeerConnection.prototype.getReceivers; + if (origGetReceivers) { + window.RTCPeerConnection.prototype.getReceivers = + function getReceivers() { + const receivers = origGetReceivers.apply(this, []); + receivers.forEach(receiver => receiver._pc = this); + return receivers; + }; + } + wrapPeerConnectionEvent(window, 'track', e => { + e.receiver._pc = e.srcElement; + return e; + }); + window.RTCRtpReceiver.prototype.getStats = function getStats() { + const receiver = this; + return this._pc.getStats().then(result => + filterStats(result, receiver.track, false)); + }; + } + + if (!('getStats' in window.RTCRtpSender.prototype && + 'getStats' in window.RTCRtpReceiver.prototype)) { + return; + } + + // shim RTCPeerConnection.getStats(track). + const origGetStats = window.RTCPeerConnection.prototype.getStats; + window.RTCPeerConnection.prototype.getStats = function getStats() { + if (arguments.length > 0 && + arguments[0] instanceof window.MediaStreamTrack) { + const track = arguments[0]; + let sender; + let receiver; + let err; + this.getSenders().forEach(s => { + if (s.track === track) { + if (sender) { + err = true; + } else { + sender = s; + } + } + }); + this.getReceivers().forEach(r => { + if (r.track === track) { + if (receiver) { + err = true; + } else { + receiver = r; + } + } + return r.track === track; + }); + if (err || (sender && receiver)) { + return Promise.reject(new DOMException( + 'There are more than one sender or receiver for the track.', + 'InvalidAccessError')); + } else if (sender) { + return sender.getStats(); + } else if (receiver) { + return receiver.getStats(); + } + return Promise.reject(new DOMException( + 'There is no sender or receiver for the track.', + 'InvalidAccessError')); + } + return origGetStats.apply(this, arguments); + }; + } + + function shimAddTrackRemoveTrackWithNative(window) { + // shim addTrack/removeTrack with native variants in order to make + // the interactions with legacy getLocalStreams behave as in other browsers. + // Keeps a mapping stream.id => [stream, rtpsenders...] + window.RTCPeerConnection.prototype.getLocalStreams = + function getLocalStreams() { + this._shimmedLocalStreams = this._shimmedLocalStreams || {}; + return Object.keys(this._shimmedLocalStreams) + .map(streamId => this._shimmedLocalStreams[streamId][0]); + }; + + const origAddTrack = window.RTCPeerConnection.prototype.addTrack; + window.RTCPeerConnection.prototype.addTrack = + function addTrack(track, stream) { + if (!stream) { + return origAddTrack.apply(this, arguments); + } + this._shimmedLocalStreams = this._shimmedLocalStreams || {}; + + const sender = origAddTrack.apply(this, arguments); + if (!this._shimmedLocalStreams[stream.id]) { + this._shimmedLocalStreams[stream.id] = [stream, sender]; + } else if (this._shimmedLocalStreams[stream.id].indexOf(sender) === -1) { + this._shimmedLocalStreams[stream.id].push(sender); + } + return sender; + }; + + const origAddStream = window.RTCPeerConnection.prototype.addStream; + window.RTCPeerConnection.prototype.addStream = function addStream(stream) { + this._shimmedLocalStreams = this._shimmedLocalStreams || {}; + + stream.getTracks().forEach(track => { + const alreadyExists = this.getSenders().find(s => s.track === track); + if (alreadyExists) { + throw new DOMException('Track already exists.', + 'InvalidAccessError'); + } + }); + const existingSenders = this.getSenders(); + origAddStream.apply(this, arguments); + const newSenders = this.getSenders() + .filter(newSender => existingSenders.indexOf(newSender) === -1); + this._shimmedLocalStreams[stream.id] = [stream].concat(newSenders); + }; + + const origRemoveStream = window.RTCPeerConnection.prototype.removeStream; + window.RTCPeerConnection.prototype.removeStream = + function removeStream(stream) { + this._shimmedLocalStreams = this._shimmedLocalStreams || {}; + delete this._shimmedLocalStreams[stream.id]; + return origRemoveStream.apply(this, arguments); + }; + + const origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack; + window.RTCPeerConnection.prototype.removeTrack = + function removeTrack(sender) { + this._shimmedLocalStreams = this._shimmedLocalStreams || {}; + if (sender) { + Object.keys(this._shimmedLocalStreams).forEach(streamId => { + const idx = this._shimmedLocalStreams[streamId].indexOf(sender); + if (idx !== -1) { + this._shimmedLocalStreams[streamId].splice(idx, 1); + } + if (this._shimmedLocalStreams[streamId].length === 1) { + delete this._shimmedLocalStreams[streamId]; + } + }); + } + return origRemoveTrack.apply(this, arguments); + }; + } + + function shimAddTrackRemoveTrack(window, browserDetails) { + if (!window.RTCPeerConnection) { + return; + } + // shim addTrack and removeTrack. + if (window.RTCPeerConnection.prototype.addTrack && + browserDetails.version >= 65) { + return shimAddTrackRemoveTrackWithNative(window); + } + + // also shim pc.getLocalStreams when addTrack is shimmed + // to return the original streams. + const origGetLocalStreams = window.RTCPeerConnection.prototype + .getLocalStreams; + window.RTCPeerConnection.prototype.getLocalStreams = + function getLocalStreams() { + const nativeStreams = origGetLocalStreams.apply(this); + this._reverseStreams = this._reverseStreams || {}; + return nativeStreams.map(stream => this._reverseStreams[stream.id]); + }; + + const origAddStream = window.RTCPeerConnection.prototype.addStream; + window.RTCPeerConnection.prototype.addStream = function addStream(stream) { + this._streams = this._streams || {}; + this._reverseStreams = this._reverseStreams || {}; + + stream.getTracks().forEach(track => { + const alreadyExists = this.getSenders().find(s => s.track === track); + if (alreadyExists) { + throw new DOMException('Track already exists.', + 'InvalidAccessError'); + } + }); + // Add identity mapping for consistency with addTrack. + // Unless this is being used with a stream from addTrack. + if (!this._reverseStreams[stream.id]) { + const newStream = new window.MediaStream(stream.getTracks()); + this._streams[stream.id] = newStream; + this._reverseStreams[newStream.id] = stream; + stream = newStream; + } + origAddStream.apply(this, [stream]); + }; + + const origRemoveStream = window.RTCPeerConnection.prototype.removeStream; + window.RTCPeerConnection.prototype.removeStream = + function removeStream(stream) { + this._streams = this._streams || {}; + this._reverseStreams = this._reverseStreams || {}; + + origRemoveStream.apply(this, [(this._streams[stream.id] || stream)]); + delete this._reverseStreams[(this._streams[stream.id] ? + this._streams[stream.id].id : stream.id)]; + delete this._streams[stream.id]; + }; + + window.RTCPeerConnection.prototype.addTrack = + function addTrack(track, stream) { + if (this.signalingState === 'closed') { + throw new DOMException( + 'The RTCPeerConnection\'s signalingState is \'closed\'.', + 'InvalidStateError'); + } + const streams = [].slice.call(arguments, 1); + if (streams.length !== 1 || + !streams[0].getTracks().find(t => t === track)) { + // this is not fully correct but all we can manage without + // [[associated MediaStreams]] internal slot. + throw new DOMException( + 'The adapter.js addTrack polyfill only supports a single ' + + ' stream which is associated with the specified track.', + 'NotSupportedError'); + } + + const alreadyExists = this.getSenders().find(s => s.track === track); + if (alreadyExists) { + throw new DOMException('Track already exists.', + 'InvalidAccessError'); + } + + this._streams = this._streams || {}; + this._reverseStreams = this._reverseStreams || {}; + const oldStream = this._streams[stream.id]; + if (oldStream) { + // this is using odd Chrome behaviour, use with caution: + // https://bugs.chromium.org/p/webrtc/issues/detail?id=7815 + // Note: we rely on the high-level addTrack/dtmf shim to + // create the sender with a dtmf sender. + oldStream.addTrack(track); + + // Trigger ONN async. + Promise.resolve().then(() => { + this.dispatchEvent(new Event('negotiationneeded')); + }); + } else { + const newStream = new window.MediaStream([track]); + this._streams[stream.id] = newStream; + this._reverseStreams[newStream.id] = stream; + this.addStream(newStream); + } + return this.getSenders().find(s => s.track === track); + }; + + // replace the internal stream id with the external one and + // vice versa. + function replaceInternalStreamId(pc, description) { + let sdp = description.sdp; + Object.keys(pc._reverseStreams || []).forEach(internalId => { + const externalStream = pc._reverseStreams[internalId]; + const internalStream = pc._streams[externalStream.id]; + sdp = sdp.replace(new RegExp(internalStream.id, 'g'), + externalStream.id); + }); + return new RTCSessionDescription({ + type: description.type, + sdp + }); + } + function replaceExternalStreamId(pc, description) { + let sdp = description.sdp; + Object.keys(pc._reverseStreams || []).forEach(internalId => { + const externalStream = pc._reverseStreams[internalId]; + const internalStream = pc._streams[externalStream.id]; + sdp = sdp.replace(new RegExp(externalStream.id, 'g'), + internalStream.id); + }); + return new RTCSessionDescription({ + type: description.type, + sdp + }); + } + ['createOffer', 'createAnswer'].forEach(function(method) { + const nativeMethod = window.RTCPeerConnection.prototype[method]; + const methodObj = {[method]() { + const args = arguments; + const isLegacyCall = arguments.length && + typeof arguments[0] === 'function'; + if (isLegacyCall) { + return nativeMethod.apply(this, [ + (description) => { + const desc = replaceInternalStreamId(this, description); + args[0].apply(null, [desc]); + }, + (err) => { + if (args[1]) { + args[1].apply(null, err); + } + }, arguments[2] + ]); + } + return nativeMethod.apply(this, arguments) + .then(description => replaceInternalStreamId(this, description)); + }}; + window.RTCPeerConnection.prototype[method] = methodObj[method]; + }); + + const origSetLocalDescription = + window.RTCPeerConnection.prototype.setLocalDescription; + window.RTCPeerConnection.prototype.setLocalDescription = + function setLocalDescription() { + if (!arguments.length || !arguments[0].type) { + return origSetLocalDescription.apply(this, arguments); + } + arguments[0] = replaceExternalStreamId(this, arguments[0]); + return origSetLocalDescription.apply(this, arguments); + }; + + // TODO: mangle getStats: https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamstats-streamidentifier + + const origLocalDescription = Object.getOwnPropertyDescriptor( + window.RTCPeerConnection.prototype, 'localDescription'); + Object.defineProperty(window.RTCPeerConnection.prototype, + 'localDescription', { + get() { + const description = origLocalDescription.get.apply(this); + if (description.type === '') { + return description; + } + return replaceInternalStreamId(this, description); + } + }); + + window.RTCPeerConnection.prototype.removeTrack = + function removeTrack(sender) { + if (this.signalingState === 'closed') { + throw new DOMException( + 'The RTCPeerConnection\'s signalingState is \'closed\'.', + 'InvalidStateError'); + } + // We can not yet check for sender instanceof RTCRtpSender + // since we shim RTPSender. So we check if sender._pc is set. + if (!sender._pc) { + throw new DOMException('Argument 1 of RTCPeerConnection.removeTrack ' + + 'does not implement interface RTCRtpSender.', 'TypeError'); + } + const isLocal = sender._pc === this; + if (!isLocal) { + throw new DOMException('Sender was not created by this connection.', + 'InvalidAccessError'); + } + + // Search for the native stream the senders track belongs to. + this._streams = this._streams || {}; + let stream; + Object.keys(this._streams).forEach(streamid => { + const hasTrack = this._streams[streamid].getTracks() + .find(track => sender.track === track); + if (hasTrack) { + stream = this._streams[streamid]; + } + }); + + if (stream) { + if (stream.getTracks().length === 1) { + // if this is the last track of the stream, remove the stream. This + // takes care of any shimmed _senders. + this.removeStream(this._reverseStreams[stream.id]); + } else { + // relying on the same odd chrome behaviour as above. + stream.removeTrack(sender.track); + } + this.dispatchEvent(new Event('negotiationneeded')); + } + }; + } + + function shimPeerConnection$2(window, browserDetails) { + if (!window.RTCPeerConnection && window.webkitRTCPeerConnection) { + // very basic support for old versions. + window.RTCPeerConnection = window.webkitRTCPeerConnection; + } + if (!window.RTCPeerConnection) { + return; + } + + // shim implicit creation of RTCSessionDescription/RTCIceCandidate + if (browserDetails.version < 53) { + ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'] + .forEach(function(method) { + const nativeMethod = window.RTCPeerConnection.prototype[method]; + const methodObj = {[method]() { + arguments[0] = new ((method === 'addIceCandidate') ? + window.RTCIceCandidate : + window.RTCSessionDescription)(arguments[0]); + return nativeMethod.apply(this, arguments); + }}; + window.RTCPeerConnection.prototype[method] = methodObj[method]; + }); + } + } + + // Attempt to fix ONN in plan-b mode. + function fixNegotiationNeeded(window, browserDetails) { + wrapPeerConnectionEvent(window, 'negotiationneeded', e => { + const pc = e.target; + if (browserDetails.version < 72 || (pc.getConfiguration && + pc.getConfiguration().sdpSemantics === 'plan-b')) { + if (pc.signalingState !== 'stable') { + return; + } + } + return e; + }); + } + + var chromeShim = /*#__PURE__*/Object.freeze({ + __proto__: null, + shimMediaStream: shimMediaStream, + shimOnTrack: shimOnTrack$1, + shimGetSendersWithDtmf: shimGetSendersWithDtmf, + shimGetStats: shimGetStats, + shimSenderReceiverGetStats: shimSenderReceiverGetStats, + shimAddTrackRemoveTrackWithNative: shimAddTrackRemoveTrackWithNative, + shimAddTrackRemoveTrack: shimAddTrackRemoveTrack, + shimPeerConnection: shimPeerConnection$2, + fixNegotiationNeeded: fixNegotiationNeeded, + shimGetUserMedia: shimGetUserMedia$3, + shimGetDisplayMedia: shimGetDisplayMedia$2 + }); + + /* + * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + // Edge does not like + // 1) stun: filtered after 14393 unless ?transport=udp is present + // 2) turn: that does not have all of turn:host:port?transport=udp + // 3) turn: with ipv6 addresses + // 4) turn: occurring muliple times + function filterIceServers$1(iceServers, edgeVersion) { + let hasTurn = false; + iceServers = JSON.parse(JSON.stringify(iceServers)); + return iceServers.filter(server => { + if (server && (server.urls || server.url)) { + let urls = server.urls || server.url; + if (server.url && !server.urls) { + deprecated('RTCIceServer.url', 'RTCIceServer.urls'); + } + const isString = typeof urls === 'string'; + if (isString) { + urls = [urls]; + } + urls = urls.filter(url => { + // filter STUN unconditionally. + if (url.indexOf('stun:') === 0) { + return false; + } + + const validTurn = url.startsWith('turn') && + !url.startsWith('turn:[') && + url.includes('transport=udp'); + if (validTurn && !hasTurn) { + hasTurn = true; + return true; + } + return validTurn && !hasTurn; + }); + + delete server.url; + server.urls = isString ? urls[0] : urls; + return !!urls.length; + } + }); + } + + function createCommonjsModule(fn) { + var module = { exports: {} }; + return fn(module, module.exports), module.exports; + } + + /* eslint-env node */ + + var sdp = createCommonjsModule(function (module) { + + // SDP helpers. + var SDPUtils = {}; + + // Generate an alphanumeric identifier for cname or mids. + // TODO: use UUIDs instead? https://gist.github.com/jed/982883 + SDPUtils.generateIdentifier = function() { + return Math.random().toString(36).substr(2, 10); + }; + + // The RTCP CNAME used by all peerconnections from the same JS. + SDPUtils.localCName = SDPUtils.generateIdentifier(); + + // Splits SDP into lines, dealing with both CRLF and LF. + SDPUtils.splitLines = function(blob) { + return blob.trim().split('\n').map(function(line) { + return line.trim(); + }); + }; + // Splits SDP into sessionpart and mediasections. Ensures CRLF. + SDPUtils.splitSections = function(blob) { + var parts = blob.split('\nm='); + return parts.map(function(part, index) { + return (index > 0 ? 'm=' + part : part).trim() + '\r\n'; + }); + }; + + // returns the session description. + SDPUtils.getDescription = function(blob) { + var sections = SDPUtils.splitSections(blob); + return sections && sections[0]; + }; + + // returns the individual media sections. + SDPUtils.getMediaSections = function(blob) { + var sections = SDPUtils.splitSections(blob); + sections.shift(); + return sections; + }; + + // Returns lines that start with a certain prefix. + SDPUtils.matchPrefix = function(blob, prefix) { + return SDPUtils.splitLines(blob).filter(function(line) { + return line.indexOf(prefix) === 0; + }); + }; + + // Parses an ICE candidate line. Sample input: + // candidate:702786350 2 udp 41819902 8.8.8.8 60769 typ relay raddr 8.8.8.8 + // rport 55996" + SDPUtils.parseCandidate = function(line) { + var parts; + // Parse both variants. + if (line.indexOf('a=candidate:') === 0) { + parts = line.substring(12).split(' '); + } else { + parts = line.substring(10).split(' '); + } + + var candidate = { + foundation: parts[0], + component: parseInt(parts[1], 10), + protocol: parts[2].toLowerCase(), + priority: parseInt(parts[3], 10), + ip: parts[4], + address: parts[4], // address is an alias for ip. + port: parseInt(parts[5], 10), + // skip parts[6] == 'typ' + type: parts[7] + }; + + for (var i = 8; i < parts.length; i += 2) { + switch (parts[i]) { + case 'raddr': + candidate.relatedAddress = parts[i + 1]; + break; + case 'rport': + candidate.relatedPort = parseInt(parts[i + 1], 10); + break; + case 'tcptype': + candidate.tcpType = parts[i + 1]; + break; + case 'ufrag': + candidate.ufrag = parts[i + 1]; // for backward compability. + candidate.usernameFragment = parts[i + 1]; + break; + default: // extension handling, in particular ufrag + candidate[parts[i]] = parts[i + 1]; + break; + } + } + return candidate; + }; + + // Translates a candidate object into SDP candidate attribute. + SDPUtils.writeCandidate = function(candidate) { + var sdp = []; + sdp.push(candidate.foundation); + sdp.push(candidate.component); + sdp.push(candidate.protocol.toUpperCase()); + sdp.push(candidate.priority); + sdp.push(candidate.address || candidate.ip); + sdp.push(candidate.port); + + var type = candidate.type; + sdp.push('typ'); + sdp.push(type); + if (type !== 'host' && candidate.relatedAddress && + candidate.relatedPort) { + sdp.push('raddr'); + sdp.push(candidate.relatedAddress); + sdp.push('rport'); + sdp.push(candidate.relatedPort); + } + if (candidate.tcpType && candidate.protocol.toLowerCase() === 'tcp') { + sdp.push('tcptype'); + sdp.push(candidate.tcpType); + } + if (candidate.usernameFragment || candidate.ufrag) { + sdp.push('ufrag'); + sdp.push(candidate.usernameFragment || candidate.ufrag); + } + return 'candidate:' + sdp.join(' '); + }; + + // Parses an ice-options line, returns an array of option tags. + // a=ice-options:foo bar + SDPUtils.parseIceOptions = function(line) { + return line.substr(14).split(' '); + }; + + // Parses an rtpmap line, returns RTCRtpCoddecParameters. Sample input: + // a=rtpmap:111 opus/48000/2 + SDPUtils.parseRtpMap = function(line) { + var parts = line.substr(9).split(' '); + var parsed = { + payloadType: parseInt(parts.shift(), 10) // was: id + }; + + parts = parts[0].split('/'); + + parsed.name = parts[0]; + parsed.clockRate = parseInt(parts[1], 10); // was: clockrate + parsed.channels = parts.length === 3 ? parseInt(parts[2], 10) : 1; + // legacy alias, got renamed back to channels in ORTC. + parsed.numChannels = parsed.channels; + return parsed; + }; + + // Generate an a=rtpmap line from RTCRtpCodecCapability or + // RTCRtpCodecParameters. + SDPUtils.writeRtpMap = function(codec) { + var pt = codec.payloadType; + if (codec.preferredPayloadType !== undefined) { + pt = codec.preferredPayloadType; + } + var channels = codec.channels || codec.numChannels || 1; + return 'a=rtpmap:' + pt + ' ' + codec.name + '/' + codec.clockRate + + (channels !== 1 ? '/' + channels : '') + '\r\n'; + }; + + // Parses an a=extmap line (headerextension from RFC 5285). Sample input: + // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset + // a=extmap:2/sendonly urn:ietf:params:rtp-hdrext:toffset + SDPUtils.parseExtmap = function(line) { + var parts = line.substr(9).split(' '); + return { + id: parseInt(parts[0], 10), + direction: parts[0].indexOf('/') > 0 ? parts[0].split('/')[1] : 'sendrecv', + uri: parts[1] + }; + }; + + // Generates a=extmap line from RTCRtpHeaderExtensionParameters or + // RTCRtpHeaderExtension. + SDPUtils.writeExtmap = function(headerExtension) { + return 'a=extmap:' + (headerExtension.id || headerExtension.preferredId) + + (headerExtension.direction && headerExtension.direction !== 'sendrecv' + ? '/' + headerExtension.direction + : '') + + ' ' + headerExtension.uri + '\r\n'; + }; + + // Parses an ftmp line, returns dictionary. Sample input: + // a=fmtp:96 vbr=on;cng=on + // Also deals with vbr=on; cng=on + SDPUtils.parseFmtp = function(line) { + var parsed = {}; + var kv; + var parts = line.substr(line.indexOf(' ') + 1).split(';'); + for (var j = 0; j < parts.length; j++) { + kv = parts[j].trim().split('='); + parsed[kv[0].trim()] = kv[1]; + } + return parsed; + }; + + // Generates an a=ftmp line from RTCRtpCodecCapability or RTCRtpCodecParameters. + SDPUtils.writeFmtp = function(codec) { + var line = ''; + var pt = codec.payloadType; + if (codec.preferredPayloadType !== undefined) { + pt = codec.preferredPayloadType; + } + if (codec.parameters && Object.keys(codec.parameters).length) { + var params = []; + Object.keys(codec.parameters).forEach(function(param) { + if (codec.parameters[param]) { + params.push(param + '=' + codec.parameters[param]); + } else { + params.push(param); + } + }); + line += 'a=fmtp:' + pt + ' ' + params.join(';') + '\r\n'; + } + return line; + }; + + // Parses an rtcp-fb line, returns RTCPRtcpFeedback object. Sample input: + // a=rtcp-fb:98 nack rpsi + SDPUtils.parseRtcpFb = function(line) { + var parts = line.substr(line.indexOf(' ') + 1).split(' '); + return { + type: parts.shift(), + parameter: parts.join(' ') + }; + }; + // Generate a=rtcp-fb lines from RTCRtpCodecCapability or RTCRtpCodecParameters. + SDPUtils.writeRtcpFb = function(codec) { + var lines = ''; + var pt = codec.payloadType; + if (codec.preferredPayloadType !== undefined) { + pt = codec.preferredPayloadType; + } + if (codec.rtcpFeedback && codec.rtcpFeedback.length) { + // FIXME: special handling for trr-int? + codec.rtcpFeedback.forEach(function(fb) { + lines += 'a=rtcp-fb:' + pt + ' ' + fb.type + + (fb.parameter && fb.parameter.length ? ' ' + fb.parameter : '') + + '\r\n'; + }); + } + return lines; + }; + + // Parses an RFC 5576 ssrc media attribute. Sample input: + // a=ssrc:3735928559 cname:something + SDPUtils.parseSsrcMedia = function(line) { + var sp = line.indexOf(' '); + var parts = { + ssrc: parseInt(line.substr(7, sp - 7), 10) + }; + var colon = line.indexOf(':', sp); + if (colon > -1) { + parts.attribute = line.substr(sp + 1, colon - sp - 1); + parts.value = line.substr(colon + 1); + } else { + parts.attribute = line.substr(sp + 1); + } + return parts; + }; + + SDPUtils.parseSsrcGroup = function(line) { + var parts = line.substr(13).split(' '); + return { + semantics: parts.shift(), + ssrcs: parts.map(function(ssrc) { + return parseInt(ssrc, 10); + }) + }; + }; + + // Extracts the MID (RFC 5888) from a media section. + // returns the MID or undefined if no mid line was found. + SDPUtils.getMid = function(mediaSection) { + var mid = SDPUtils.matchPrefix(mediaSection, 'a=mid:')[0]; + if (mid) { + return mid.substr(6); + } + }; + + SDPUtils.parseFingerprint = function(line) { + var parts = line.substr(14).split(' '); + return { + algorithm: parts[0].toLowerCase(), // algorithm is case-sensitive in Edge. + value: parts[1] + }; + }; + + // Extracts DTLS parameters from SDP media section or sessionpart. + // FIXME: for consistency with other functions this should only + // get the fingerprint line as input. See also getIceParameters. + SDPUtils.getDtlsParameters = function(mediaSection, sessionpart) { + var lines = SDPUtils.matchPrefix(mediaSection + sessionpart, + 'a=fingerprint:'); + // Note: a=setup line is ignored since we use the 'auto' role. + // Note2: 'algorithm' is not case sensitive except in Edge. + return { + role: 'auto', + fingerprints: lines.map(SDPUtils.parseFingerprint) + }; + }; + + // Serializes DTLS parameters to SDP. + SDPUtils.writeDtlsParameters = function(params, setupType) { + var sdp = 'a=setup:' + setupType + '\r\n'; + params.fingerprints.forEach(function(fp) { + sdp += 'a=fingerprint:' + fp.algorithm + ' ' + fp.value + '\r\n'; + }); + return sdp; + }; + + // Parses a=crypto lines into + // https://rawgit.com/aboba/edgertc/master/msortc-rs4.html#dictionary-rtcsrtpsdesparameters-members + SDPUtils.parseCryptoLine = function(line) { + var parts = line.substr(9).split(' '); + return { + tag: parseInt(parts[0], 10), + cryptoSuite: parts[1], + keyParams: parts[2], + sessionParams: parts.slice(3), + }; + }; + + SDPUtils.writeCryptoLine = function(parameters) { + return 'a=crypto:' + parameters.tag + ' ' + + parameters.cryptoSuite + ' ' + + (typeof parameters.keyParams === 'object' + ? SDPUtils.writeCryptoKeyParams(parameters.keyParams) + : parameters.keyParams) + + (parameters.sessionParams ? ' ' + parameters.sessionParams.join(' ') : '') + + '\r\n'; + }; + + // Parses the crypto key parameters into + // https://rawgit.com/aboba/edgertc/master/msortc-rs4.html#rtcsrtpkeyparam* + SDPUtils.parseCryptoKeyParams = function(keyParams) { + if (keyParams.indexOf('inline:') !== 0) { + return null; + } + var parts = keyParams.substr(7).split('|'); + return { + keyMethod: 'inline', + keySalt: parts[0], + lifeTime: parts[1], + mkiValue: parts[2] ? parts[2].split(':')[0] : undefined, + mkiLength: parts[2] ? parts[2].split(':')[1] : undefined, + }; + }; + + SDPUtils.writeCryptoKeyParams = function(keyParams) { + return keyParams.keyMethod + ':' + + keyParams.keySalt + + (keyParams.lifeTime ? '|' + keyParams.lifeTime : '') + + (keyParams.mkiValue && keyParams.mkiLength + ? '|' + keyParams.mkiValue + ':' + keyParams.mkiLength + : ''); + }; + + // Extracts all SDES paramters. + SDPUtils.getCryptoParameters = function(mediaSection, sessionpart) { + var lines = SDPUtils.matchPrefix(mediaSection + sessionpart, + 'a=crypto:'); + return lines.map(SDPUtils.parseCryptoLine); + }; + + // Parses ICE information from SDP media section or sessionpart. + // FIXME: for consistency with other functions this should only + // get the ice-ufrag and ice-pwd lines as input. + SDPUtils.getIceParameters = function(mediaSection, sessionpart) { + var ufrag = SDPUtils.matchPrefix(mediaSection + sessionpart, + 'a=ice-ufrag:')[0]; + var pwd = SDPUtils.matchPrefix(mediaSection + sessionpart, + 'a=ice-pwd:')[0]; + if (!(ufrag && pwd)) { + return null; + } + return { + usernameFragment: ufrag.substr(12), + password: pwd.substr(10), + }; + }; + + // Serializes ICE parameters to SDP. + SDPUtils.writeIceParameters = function(params) { + return 'a=ice-ufrag:' + params.usernameFragment + '\r\n' + + 'a=ice-pwd:' + params.password + '\r\n'; + }; + + // Parses the SDP media section and returns RTCRtpParameters. + SDPUtils.parseRtpParameters = function(mediaSection) { + var description = { + codecs: [], + headerExtensions: [], + fecMechanisms: [], + rtcp: [] + }; + var lines = SDPUtils.splitLines(mediaSection); + var mline = lines[0].split(' '); + for (var i = 3; i < mline.length; i++) { // find all codecs from mline[3..] + var pt = mline[i]; + var rtpmapline = SDPUtils.matchPrefix( + mediaSection, 'a=rtpmap:' + pt + ' ')[0]; + if (rtpmapline) { + var codec = SDPUtils.parseRtpMap(rtpmapline); + var fmtps = SDPUtils.matchPrefix( + mediaSection, 'a=fmtp:' + pt + ' '); + // Only the first a=fmtp: is considered. + codec.parameters = fmtps.length ? SDPUtils.parseFmtp(fmtps[0]) : {}; + codec.rtcpFeedback = SDPUtils.matchPrefix( + mediaSection, 'a=rtcp-fb:' + pt + ' ') + .map(SDPUtils.parseRtcpFb); + description.codecs.push(codec); + // parse FEC mechanisms from rtpmap lines. + switch (codec.name.toUpperCase()) { + case 'RED': + case 'ULPFEC': + description.fecMechanisms.push(codec.name.toUpperCase()); + break; + } + } + } + SDPUtils.matchPrefix(mediaSection, 'a=extmap:').forEach(function(line) { + description.headerExtensions.push(SDPUtils.parseExtmap(line)); + }); + // FIXME: parse rtcp. + return description; + }; + + // Generates parts of the SDP media section describing the capabilities / + // parameters. + SDPUtils.writeRtpDescription = function(kind, caps) { + var sdp = ''; + + // Build the mline. + sdp += 'm=' + kind + ' '; + sdp += caps.codecs.length > 0 ? '9' : '0'; // reject if no codecs. + sdp += ' UDP/TLS/RTP/SAVPF '; + sdp += caps.codecs.map(function(codec) { + if (codec.preferredPayloadType !== undefined) { + return codec.preferredPayloadType; + } + return codec.payloadType; + }).join(' ') + '\r\n'; + + sdp += 'c=IN IP4 0.0.0.0\r\n'; + sdp += 'a=rtcp:9 IN IP4 0.0.0.0\r\n'; + + // Add a=rtpmap lines for each codec. Also fmtp and rtcp-fb. + caps.codecs.forEach(function(codec) { + sdp += SDPUtils.writeRtpMap(codec); + sdp += SDPUtils.writeFmtp(codec); + sdp += SDPUtils.writeRtcpFb(codec); + }); + var maxptime = 0; + caps.codecs.forEach(function(codec) { + if (codec.maxptime > maxptime) { + maxptime = codec.maxptime; + } + }); + if (maxptime > 0) { + sdp += 'a=maxptime:' + maxptime + '\r\n'; + } + sdp += 'a=rtcp-mux\r\n'; + + if (caps.headerExtensions) { + caps.headerExtensions.forEach(function(extension) { + sdp += SDPUtils.writeExtmap(extension); + }); + } + // FIXME: write fecMechanisms. + return sdp; + }; + + // Parses the SDP media section and returns an array of + // RTCRtpEncodingParameters. + SDPUtils.parseRtpEncodingParameters = function(mediaSection) { + var encodingParameters = []; + var description = SDPUtils.parseRtpParameters(mediaSection); + var hasRed = description.fecMechanisms.indexOf('RED') !== -1; + var hasUlpfec = description.fecMechanisms.indexOf('ULPFEC') !== -1; + + // filter a=ssrc:... cname:, ignore PlanB-msid + var ssrcs = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:') + .map(function(line) { + return SDPUtils.parseSsrcMedia(line); + }) + .filter(function(parts) { + return parts.attribute === 'cname'; + }); + var primarySsrc = ssrcs.length > 0 && ssrcs[0].ssrc; + var secondarySsrc; + + var flows = SDPUtils.matchPrefix(mediaSection, 'a=ssrc-group:FID') + .map(function(line) { + var parts = line.substr(17).split(' '); + return parts.map(function(part) { + return parseInt(part, 10); + }); + }); + if (flows.length > 0 && flows[0].length > 1 && flows[0][0] === primarySsrc) { + secondarySsrc = flows[0][1]; + } + + description.codecs.forEach(function(codec) { + if (codec.name.toUpperCase() === 'RTX' && codec.parameters.apt) { + var encParam = { + ssrc: primarySsrc, + codecPayloadType: parseInt(codec.parameters.apt, 10) + }; + if (primarySsrc && secondarySsrc) { + encParam.rtx = {ssrc: secondarySsrc}; + } + encodingParameters.push(encParam); + if (hasRed) { + encParam = JSON.parse(JSON.stringify(encParam)); + encParam.fec = { + ssrc: primarySsrc, + mechanism: hasUlpfec ? 'red+ulpfec' : 'red' + }; + encodingParameters.push(encParam); + } + } + }); + if (encodingParameters.length === 0 && primarySsrc) { + encodingParameters.push({ + ssrc: primarySsrc + }); + } + + // we support both b=AS and b=TIAS but interpret AS as TIAS. + var bandwidth = SDPUtils.matchPrefix(mediaSection, 'b='); + if (bandwidth.length) { + if (bandwidth[0].indexOf('b=TIAS:') === 0) { + bandwidth = parseInt(bandwidth[0].substr(7), 10); + } else if (bandwidth[0].indexOf('b=AS:') === 0) { + // use formula from JSEP to convert b=AS to TIAS value. + bandwidth = parseInt(bandwidth[0].substr(5), 10) * 1000 * 0.95 + - (50 * 40 * 8); + } else { + bandwidth = undefined; + } + encodingParameters.forEach(function(params) { + params.maxBitrate = bandwidth; + }); + } + return encodingParameters; + }; + + // parses http://draft.ortc.org/#rtcrtcpparameters* + SDPUtils.parseRtcpParameters = function(mediaSection) { + var rtcpParameters = {}; + + // Gets the first SSRC. Note tha with RTX there might be multiple + // SSRCs. + var remoteSsrc = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:') + .map(function(line) { + return SDPUtils.parseSsrcMedia(line); + }) + .filter(function(obj) { + return obj.attribute === 'cname'; + })[0]; + if (remoteSsrc) { + rtcpParameters.cname = remoteSsrc.value; + rtcpParameters.ssrc = remoteSsrc.ssrc; + } + + // Edge uses the compound attribute instead of reducedSize + // compound is !reducedSize + var rsize = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-rsize'); + rtcpParameters.reducedSize = rsize.length > 0; + rtcpParameters.compound = rsize.length === 0; + + // parses the rtcp-mux attrіbute. + // Note that Edge does not support unmuxed RTCP. + var mux = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-mux'); + rtcpParameters.mux = mux.length > 0; + + return rtcpParameters; + }; + + // parses either a=msid: or a=ssrc:... msid lines and returns + // the id of the MediaStream and MediaStreamTrack. + SDPUtils.parseMsid = function(mediaSection) { + var parts; + var spec = SDPUtils.matchPrefix(mediaSection, 'a=msid:'); + if (spec.length === 1) { + parts = spec[0].substr(7).split(' '); + return {stream: parts[0], track: parts[1]}; + } + var planB = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:') + .map(function(line) { + return SDPUtils.parseSsrcMedia(line); + }) + .filter(function(msidParts) { + return msidParts.attribute === 'msid'; + }); + if (planB.length > 0) { + parts = planB[0].value.split(' '); + return {stream: parts[0], track: parts[1]}; + } + }; + + // SCTP + // parses draft-ietf-mmusic-sctp-sdp-26 first and falls back + // to draft-ietf-mmusic-sctp-sdp-05 + SDPUtils.parseSctpDescription = function(mediaSection) { + var mline = SDPUtils.parseMLine(mediaSection); + var maxSizeLine = SDPUtils.matchPrefix(mediaSection, 'a=max-message-size:'); + var maxMessageSize; + if (maxSizeLine.length > 0) { + maxMessageSize = parseInt(maxSizeLine[0].substr(19), 10); + } + if (isNaN(maxMessageSize)) { + maxMessageSize = 65536; + } + var sctpPort = SDPUtils.matchPrefix(mediaSection, 'a=sctp-port:'); + if (sctpPort.length > 0) { + return { + port: parseInt(sctpPort[0].substr(12), 10), + protocol: mline.fmt, + maxMessageSize: maxMessageSize + }; + } + var sctpMapLines = SDPUtils.matchPrefix(mediaSection, 'a=sctpmap:'); + if (sctpMapLines.length > 0) { + var parts = SDPUtils.matchPrefix(mediaSection, 'a=sctpmap:')[0] + .substr(10) + .split(' '); + return { + port: parseInt(parts[0], 10), + protocol: parts[1], + maxMessageSize: maxMessageSize + }; + } + }; + + // SCTP + // outputs the draft-ietf-mmusic-sctp-sdp-26 version that all browsers + // support by now receiving in this format, unless we originally parsed + // as the draft-ietf-mmusic-sctp-sdp-05 format (indicated by the m-line + // protocol of DTLS/SCTP -- without UDP/ or TCP/) + SDPUtils.writeSctpDescription = function(media, sctp) { + var output = []; + if (media.protocol !== 'DTLS/SCTP') { + output = [ + 'm=' + media.kind + ' 9 ' + media.protocol + ' ' + sctp.protocol + '\r\n', + 'c=IN IP4 0.0.0.0\r\n', + 'a=sctp-port:' + sctp.port + '\r\n' + ]; + } else { + output = [ + 'm=' + media.kind + ' 9 ' + media.protocol + ' ' + sctp.port + '\r\n', + 'c=IN IP4 0.0.0.0\r\n', + 'a=sctpmap:' + sctp.port + ' ' + sctp.protocol + ' 65535\r\n' + ]; + } + if (sctp.maxMessageSize !== undefined) { + output.push('a=max-message-size:' + sctp.maxMessageSize + '\r\n'); + } + return output.join(''); + }; + + // Generate a session ID for SDP. + // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-20#section-5.2.1 + // recommends using a cryptographically random +ve 64-bit value + // but right now this should be acceptable and within the right range + SDPUtils.generateSessionId = function() { + return Math.random().toString().substr(2, 21); + }; + + // Write boilder plate for start of SDP + // sessId argument is optional - if not supplied it will + // be generated randomly + // sessVersion is optional and defaults to 2 + // sessUser is optional and defaults to 'thisisadapterortc' + SDPUtils.writeSessionBoilerplate = function(sessId, sessVer, sessUser) { + var sessionId; + var version = sessVer !== undefined ? sessVer : 2; + if (sessId) { + sessionId = sessId; + } else { + sessionId = SDPUtils.generateSessionId(); + } + var user = sessUser || 'thisisadapterortc'; + // FIXME: sess-id should be an NTP timestamp. + return 'v=0\r\n' + + 'o=' + user + ' ' + sessionId + ' ' + version + + ' IN IP4 127.0.0.1\r\n' + + 's=-\r\n' + + 't=0 0\r\n'; + }; + + SDPUtils.writeMediaSection = function(transceiver, caps, type, stream) { + var sdp = SDPUtils.writeRtpDescription(transceiver.kind, caps); + + // Map ICE parameters (ufrag, pwd) to SDP. + sdp += SDPUtils.writeIceParameters( + transceiver.iceGatherer.getLocalParameters()); + + // Map DTLS parameters to SDP. + sdp += SDPUtils.writeDtlsParameters( + transceiver.dtlsTransport.getLocalParameters(), + type === 'offer' ? 'actpass' : 'active'); + + sdp += 'a=mid:' + transceiver.mid + '\r\n'; + + if (transceiver.direction) { + sdp += 'a=' + transceiver.direction + '\r\n'; + } else if (transceiver.rtpSender && transceiver.rtpReceiver) { + sdp += 'a=sendrecv\r\n'; + } else if (transceiver.rtpSender) { + sdp += 'a=sendonly\r\n'; + } else if (transceiver.rtpReceiver) { + sdp += 'a=recvonly\r\n'; + } else { + sdp += 'a=inactive\r\n'; + } + + if (transceiver.rtpSender) { + // spec. + var msid = 'msid:' + stream.id + ' ' + + transceiver.rtpSender.track.id + '\r\n'; + sdp += 'a=' + msid; + + // for Chrome. + sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc + + ' ' + msid; + if (transceiver.sendEncodingParameters[0].rtx) { + sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc + + ' ' + msid; + sdp += 'a=ssrc-group:FID ' + + transceiver.sendEncodingParameters[0].ssrc + ' ' + + transceiver.sendEncodingParameters[0].rtx.ssrc + + '\r\n'; + } + } + // FIXME: this should be written by writeRtpDescription. + sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc + + ' cname:' + SDPUtils.localCName + '\r\n'; + if (transceiver.rtpSender && transceiver.sendEncodingParameters[0].rtx) { + sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc + + ' cname:' + SDPUtils.localCName + '\r\n'; + } + return sdp; + }; + + // Gets the direction from the mediaSection or the sessionpart. + SDPUtils.getDirection = function(mediaSection, sessionpart) { + // Look for sendrecv, sendonly, recvonly, inactive, default to sendrecv. + var lines = SDPUtils.splitLines(mediaSection); + for (var i = 0; i < lines.length; i++) { + switch (lines[i]) { + case 'a=sendrecv': + case 'a=sendonly': + case 'a=recvonly': + case 'a=inactive': + return lines[i].substr(2); + // FIXME: What should happen here? + } + } + if (sessionpart) { + return SDPUtils.getDirection(sessionpart); + } + return 'sendrecv'; + }; + + SDPUtils.getKind = function(mediaSection) { + var lines = SDPUtils.splitLines(mediaSection); + var mline = lines[0].split(' '); + return mline[0].substr(2); + }; + + SDPUtils.isRejected = function(mediaSection) { + return mediaSection.split(' ', 2)[1] === '0'; + }; + + SDPUtils.parseMLine = function(mediaSection) { + var lines = SDPUtils.splitLines(mediaSection); + var parts = lines[0].substr(2).split(' '); + return { + kind: parts[0], + port: parseInt(parts[1], 10), + protocol: parts[2], + fmt: parts.slice(3).join(' ') + }; + }; + + SDPUtils.parseOLine = function(mediaSection) { + var line = SDPUtils.matchPrefix(mediaSection, 'o=')[0]; + var parts = line.substr(2).split(' '); + return { + username: parts[0], + sessionId: parts[1], + sessionVersion: parseInt(parts[2], 10), + netType: parts[3], + addressType: parts[4], + address: parts[5] + }; + }; + + // a very naive interpretation of a valid SDP. + SDPUtils.isValidSDP = function(blob) { + if (typeof blob !== 'string' || blob.length === 0) { + return false; + } + var lines = SDPUtils.splitLines(blob); + for (var i = 0; i < lines.length; i++) { + if (lines[i].length < 2 || lines[i].charAt(1) !== '=') { + return false; + } + // TODO: check the modifier a bit more. + } + return true; + }; + + // Expose public methods. + { + module.exports = SDPUtils; + } + }); + + /* + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + + + function fixStatsType(stat) { + return { + inboundrtp: 'inbound-rtp', + outboundrtp: 'outbound-rtp', + candidatepair: 'candidate-pair', + localcandidate: 'local-candidate', + remotecandidate: 'remote-candidate' + }[stat.type] || stat.type; + } + + function writeMediaSection(transceiver, caps, type, stream, dtlsRole) { + var sdp$1 = sdp.writeRtpDescription(transceiver.kind, caps); + + // Map ICE parameters (ufrag, pwd) to SDP. + sdp$1 += sdp.writeIceParameters( + transceiver.iceGatherer.getLocalParameters()); + + // Map DTLS parameters to SDP. + sdp$1 += sdp.writeDtlsParameters( + transceiver.dtlsTransport.getLocalParameters(), + type === 'offer' ? 'actpass' : dtlsRole || 'active'); + + sdp$1 += 'a=mid:' + transceiver.mid + '\r\n'; + + if (transceiver.rtpSender && transceiver.rtpReceiver) { + sdp$1 += 'a=sendrecv\r\n'; + } else if (transceiver.rtpSender) { + sdp$1 += 'a=sendonly\r\n'; + } else if (transceiver.rtpReceiver) { + sdp$1 += 'a=recvonly\r\n'; + } else { + sdp$1 += 'a=inactive\r\n'; + } + + if (transceiver.rtpSender) { + var trackId = transceiver.rtpSender._initialTrackId || + transceiver.rtpSender.track.id; + transceiver.rtpSender._initialTrackId = trackId; + // spec. + var msid = 'msid:' + (stream ? stream.id : '-') + ' ' + + trackId + '\r\n'; + sdp$1 += 'a=' + msid; + // for Chrome. Legacy should no longer be required. + sdp$1 += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc + + ' ' + msid; + + // RTX + if (transceiver.sendEncodingParameters[0].rtx) { + sdp$1 += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc + + ' ' + msid; + sdp$1 += 'a=ssrc-group:FID ' + + transceiver.sendEncodingParameters[0].ssrc + ' ' + + transceiver.sendEncodingParameters[0].rtx.ssrc + + '\r\n'; + } + } + // FIXME: this should be written by writeRtpDescription. + sdp$1 += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc + + ' cname:' + sdp.localCName + '\r\n'; + if (transceiver.rtpSender && transceiver.sendEncodingParameters[0].rtx) { + sdp$1 += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc + + ' cname:' + sdp.localCName + '\r\n'; + } + return sdp$1; + } + + // Edge does not like + // 1) stun: filtered after 14393 unless ?transport=udp is present + // 2) turn: that does not have all of turn:host:port?transport=udp + // 3) turn: with ipv6 addresses + // 4) turn: occurring muliple times + function filterIceServers(iceServers, edgeVersion) { + var hasTurn = false; + iceServers = JSON.parse(JSON.stringify(iceServers)); + return iceServers.filter(function(server) { + if (server && (server.urls || server.url)) { + var urls = server.urls || server.url; + if (server.url && !server.urls) { + console.warn('RTCIceServer.url is deprecated! Use urls instead.'); + } + var isString = typeof urls === 'string'; + if (isString) { + urls = [urls]; + } + urls = urls.filter(function(url) { + var validTurn = url.indexOf('turn:') === 0 && + url.indexOf('transport=udp') !== -1 && + url.indexOf('turn:[') === -1 && + !hasTurn; + + if (validTurn) { + hasTurn = true; + return true; + } + return url.indexOf('stun:') === 0 && edgeVersion >= 14393 && + url.indexOf('?transport=udp') === -1; + }); + + delete server.url; + server.urls = isString ? urls[0] : urls; + return !!urls.length; + } + }); + } + + // Determines the intersection of local and remote capabilities. + function getCommonCapabilities(localCapabilities, remoteCapabilities) { + var commonCapabilities = { + codecs: [], + headerExtensions: [], + fecMechanisms: [] + }; + + var findCodecByPayloadType = function(pt, codecs) { + pt = parseInt(pt, 10); + for (var i = 0; i < codecs.length; i++) { + if (codecs[i].payloadType === pt || + codecs[i].preferredPayloadType === pt) { + return codecs[i]; + } + } + }; + + var rtxCapabilityMatches = function(lRtx, rRtx, lCodecs, rCodecs) { + var lCodec = findCodecByPayloadType(lRtx.parameters.apt, lCodecs); + var rCodec = findCodecByPayloadType(rRtx.parameters.apt, rCodecs); + return lCodec && rCodec && + lCodec.name.toLowerCase() === rCodec.name.toLowerCase(); + }; + + localCapabilities.codecs.forEach(function(lCodec) { + for (var i = 0; i < remoteCapabilities.codecs.length; i++) { + var rCodec = remoteCapabilities.codecs[i]; + if (lCodec.name.toLowerCase() === rCodec.name.toLowerCase() && + lCodec.clockRate === rCodec.clockRate) { + if (lCodec.name.toLowerCase() === 'rtx' && + lCodec.parameters && rCodec.parameters.apt) { + // for RTX we need to find the local rtx that has a apt + // which points to the same local codec as the remote one. + if (!rtxCapabilityMatches(lCodec, rCodec, + localCapabilities.codecs, remoteCapabilities.codecs)) { + continue; + } + } + rCodec = JSON.parse(JSON.stringify(rCodec)); // deepcopy + // number of channels is the highest common number of channels + rCodec.numChannels = Math.min(lCodec.numChannels, + rCodec.numChannels); + // push rCodec so we reply with offerer payload type + commonCapabilities.codecs.push(rCodec); + + // determine common feedback mechanisms + rCodec.rtcpFeedback = rCodec.rtcpFeedback.filter(function(fb) { + for (var j = 0; j < lCodec.rtcpFeedback.length; j++) { + if (lCodec.rtcpFeedback[j].type === fb.type && + lCodec.rtcpFeedback[j].parameter === fb.parameter) { + return true; + } + } + return false; + }); + // FIXME: also need to determine .parameters + // see https://github.com/openpeer/ortc/issues/569 + break; + } + } + }); + + localCapabilities.headerExtensions.forEach(function(lHeaderExtension) { + for (var i = 0; i < remoteCapabilities.headerExtensions.length; + i++) { + var rHeaderExtension = remoteCapabilities.headerExtensions[i]; + if (lHeaderExtension.uri === rHeaderExtension.uri) { + commonCapabilities.headerExtensions.push(rHeaderExtension); + break; + } + } + }); + + // FIXME: fecMechanisms + return commonCapabilities; + } + + // is action=setLocalDescription with type allowed in signalingState + function isActionAllowedInSignalingState(action, type, signalingState) { + return { + offer: { + setLocalDescription: ['stable', 'have-local-offer'], + setRemoteDescription: ['stable', 'have-remote-offer'] + }, + answer: { + setLocalDescription: ['have-remote-offer', 'have-local-pranswer'], + setRemoteDescription: ['have-local-offer', 'have-remote-pranswer'] + } + }[type][action].indexOf(signalingState) !== -1; + } + + function maybeAddCandidate(iceTransport, candidate) { + // Edge's internal representation adds some fields therefore + // not all fieldѕ are taken into account. + var alreadyAdded = iceTransport.getRemoteCandidates() + .find(function(remoteCandidate) { + return candidate.foundation === remoteCandidate.foundation && + candidate.ip === remoteCandidate.ip && + candidate.port === remoteCandidate.port && + candidate.priority === remoteCandidate.priority && + candidate.protocol === remoteCandidate.protocol && + candidate.type === remoteCandidate.type; + }); + if (!alreadyAdded) { + iceTransport.addRemoteCandidate(candidate); + } + return !alreadyAdded; + } + + + function makeError(name, description) { + var e = new Error(description); + e.name = name; + // legacy error codes from https://heycam.github.io/webidl/#idl-DOMException-error-names + e.code = { + NotSupportedError: 9, + InvalidStateError: 11, + InvalidAccessError: 15, + TypeError: undefined, + OperationError: undefined + }[name]; + return e; + } + + var rtcpeerconnection = function(window, edgeVersion) { + // https://w3c.github.io/mediacapture-main/#mediastream + // Helper function to add the track to the stream and + // dispatch the event ourselves. + function addTrackToStreamAndFireEvent(track, stream) { + stream.addTrack(track); + stream.dispatchEvent(new window.MediaStreamTrackEvent('addtrack', + {track: track})); + } + + function removeTrackFromStreamAndFireEvent(track, stream) { + stream.removeTrack(track); + stream.dispatchEvent(new window.MediaStreamTrackEvent('removetrack', + {track: track})); + } + + function fireAddTrack(pc, track, receiver, streams) { + var trackEvent = new Event('track'); + trackEvent.track = track; + trackEvent.receiver = receiver; + trackEvent.transceiver = {receiver: receiver}; + trackEvent.streams = streams; + window.setTimeout(function() { + pc._dispatchEvent('track', trackEvent); + }); + } + + var RTCPeerConnection = function(config) { + var pc = this; + + var _eventTarget = document.createDocumentFragment(); + ['addEventListener', 'removeEventListener', 'dispatchEvent'] + .forEach(function(method) { + pc[method] = _eventTarget[method].bind(_eventTarget); + }); + + this.canTrickleIceCandidates = null; + + this.needNegotiation = false; + + this.localStreams = []; + this.remoteStreams = []; + + this._localDescription = null; + this._remoteDescription = null; + + this.signalingState = 'stable'; + this.iceConnectionState = 'new'; + this.connectionState = 'new'; + this.iceGatheringState = 'new'; + + config = JSON.parse(JSON.stringify(config || {})); + + this.usingBundle = config.bundlePolicy === 'max-bundle'; + if (config.rtcpMuxPolicy === 'negotiate') { + throw(makeError('NotSupportedError', + 'rtcpMuxPolicy \'negotiate\' is not supported')); + } else if (!config.rtcpMuxPolicy) { + config.rtcpMuxPolicy = 'require'; + } + + switch (config.iceTransportPolicy) { + case 'all': + case 'relay': + break; + default: + config.iceTransportPolicy = 'all'; + break; + } + + switch (config.bundlePolicy) { + case 'balanced': + case 'max-compat': + case 'max-bundle': + break; + default: + config.bundlePolicy = 'balanced'; + break; + } + + config.iceServers = filterIceServers(config.iceServers || [], edgeVersion); + + this._iceGatherers = []; + if (config.iceCandidatePoolSize) { + for (var i = config.iceCandidatePoolSize; i > 0; i--) { + this._iceGatherers.push(new window.RTCIceGatherer({ + iceServers: config.iceServers, + gatherPolicy: config.iceTransportPolicy + })); + } + } else { + config.iceCandidatePoolSize = 0; + } + + this._config = config; + + // per-track iceGathers, iceTransports, dtlsTransports, rtpSenders, ... + // everything that is needed to describe a SDP m-line. + this.transceivers = []; + + this._sdpSessionId = sdp.generateSessionId(); + this._sdpSessionVersion = 0; + + this._dtlsRole = undefined; // role for a=setup to use in answers. + + this._isClosed = false; + }; + + Object.defineProperty(RTCPeerConnection.prototype, 'localDescription', { + configurable: true, + get: function() { + return this._localDescription; + } + }); + Object.defineProperty(RTCPeerConnection.prototype, 'remoteDescription', { + configurable: true, + get: function() { + return this._remoteDescription; + } + }); + + // set up event handlers on prototype + RTCPeerConnection.prototype.onicecandidate = null; + RTCPeerConnection.prototype.onaddstream = null; + RTCPeerConnection.prototype.ontrack = null; + RTCPeerConnection.prototype.onremovestream = null; + RTCPeerConnection.prototype.onsignalingstatechange = null; + RTCPeerConnection.prototype.oniceconnectionstatechange = null; + RTCPeerConnection.prototype.onconnectionstatechange = null; + RTCPeerConnection.prototype.onicegatheringstatechange = null; + RTCPeerConnection.prototype.onnegotiationneeded = null; + RTCPeerConnection.prototype.ondatachannel = null; + + RTCPeerConnection.prototype._dispatchEvent = function(name, event) { + if (this._isClosed) { + return; + } + this.dispatchEvent(event); + if (typeof this['on' + name] === 'function') { + this['on' + name](event); + } + }; + + RTCPeerConnection.prototype._emitGatheringStateChange = function() { + var event = new Event('icegatheringstatechange'); + this._dispatchEvent('icegatheringstatechange', event); + }; + + RTCPeerConnection.prototype.getConfiguration = function() { + return this._config; + }; + + RTCPeerConnection.prototype.getLocalStreams = function() { + return this.localStreams; + }; + + RTCPeerConnection.prototype.getRemoteStreams = function() { + return this.remoteStreams; + }; + + // internal helper to create a transceiver object. + // (which is not yet the same as the WebRTC 1.0 transceiver) + RTCPeerConnection.prototype._createTransceiver = function(kind, doNotAdd) { + var hasBundleTransport = this.transceivers.length > 0; + var transceiver = { + track: null, + iceGatherer: null, + iceTransport: null, + dtlsTransport: null, + localCapabilities: null, + remoteCapabilities: null, + rtpSender: null, + rtpReceiver: null, + kind: kind, + mid: null, + sendEncodingParameters: null, + recvEncodingParameters: null, + stream: null, + associatedRemoteMediaStreams: [], + wantReceive: true + }; + if (this.usingBundle && hasBundleTransport) { + transceiver.iceTransport = this.transceivers[0].iceTransport; + transceiver.dtlsTransport = this.transceivers[0].dtlsTransport; + } else { + var transports = this._createIceAndDtlsTransports(); + transceiver.iceTransport = transports.iceTransport; + transceiver.dtlsTransport = transports.dtlsTransport; + } + if (!doNotAdd) { + this.transceivers.push(transceiver); + } + return transceiver; + }; + + RTCPeerConnection.prototype.addTrack = function(track, stream) { + if (this._isClosed) { + throw makeError('InvalidStateError', + 'Attempted to call addTrack on a closed peerconnection.'); + } + + var alreadyExists = this.transceivers.find(function(s) { + return s.track === track; + }); + + if (alreadyExists) { + throw makeError('InvalidAccessError', 'Track already exists.'); + } + + var transceiver; + for (var i = 0; i < this.transceivers.length; i++) { + if (!this.transceivers[i].track && + this.transceivers[i].kind === track.kind) { + transceiver = this.transceivers[i]; + } + } + if (!transceiver) { + transceiver = this._createTransceiver(track.kind); + } + + this._maybeFireNegotiationNeeded(); + + if (this.localStreams.indexOf(stream) === -1) { + this.localStreams.push(stream); + } + + transceiver.track = track; + transceiver.stream = stream; + transceiver.rtpSender = new window.RTCRtpSender(track, + transceiver.dtlsTransport); + return transceiver.rtpSender; + }; + + RTCPeerConnection.prototype.addStream = function(stream) { + var pc = this; + if (edgeVersion >= 15025) { + stream.getTracks().forEach(function(track) { + pc.addTrack(track, stream); + }); + } else { + // Clone is necessary for local demos mostly, attaching directly + // to two different senders does not work (build 10547). + // Fixed in 15025 (or earlier) + var clonedStream = stream.clone(); + stream.getTracks().forEach(function(track, idx) { + var clonedTrack = clonedStream.getTracks()[idx]; + track.addEventListener('enabled', function(event) { + clonedTrack.enabled = event.enabled; + }); + }); + clonedStream.getTracks().forEach(function(track) { + pc.addTrack(track, clonedStream); + }); + } + }; + + RTCPeerConnection.prototype.removeTrack = function(sender) { + if (this._isClosed) { + throw makeError('InvalidStateError', + 'Attempted to call removeTrack on a closed peerconnection.'); + } + + if (!(sender instanceof window.RTCRtpSender)) { + throw new TypeError('Argument 1 of RTCPeerConnection.removeTrack ' + + 'does not implement interface RTCRtpSender.'); + } + + var transceiver = this.transceivers.find(function(t) { + return t.rtpSender === sender; + }); + + if (!transceiver) { + throw makeError('InvalidAccessError', + 'Sender was not created by this connection.'); + } + var stream = transceiver.stream; + + transceiver.rtpSender.stop(); + transceiver.rtpSender = null; + transceiver.track = null; + transceiver.stream = null; + + // remove the stream from the set of local streams + var localStreams = this.transceivers.map(function(t) { + return t.stream; + }); + if (localStreams.indexOf(stream) === -1 && + this.localStreams.indexOf(stream) > -1) { + this.localStreams.splice(this.localStreams.indexOf(stream), 1); + } + + this._maybeFireNegotiationNeeded(); + }; + + RTCPeerConnection.prototype.removeStream = function(stream) { + var pc = this; + stream.getTracks().forEach(function(track) { + var sender = pc.getSenders().find(function(s) { + return s.track === track; + }); + if (sender) { + pc.removeTrack(sender); + } + }); + }; + + RTCPeerConnection.prototype.getSenders = function() { + return this.transceivers.filter(function(transceiver) { + return !!transceiver.rtpSender; + }) + .map(function(transceiver) { + return transceiver.rtpSender; + }); + }; + + RTCPeerConnection.prototype.getReceivers = function() { + return this.transceivers.filter(function(transceiver) { + return !!transceiver.rtpReceiver; + }) + .map(function(transceiver) { + return transceiver.rtpReceiver; + }); + }; + + + RTCPeerConnection.prototype._createIceGatherer = function(sdpMLineIndex, + usingBundle) { + var pc = this; + if (usingBundle && sdpMLineIndex > 0) { + return this.transceivers[0].iceGatherer; + } else if (this._iceGatherers.length) { + return this._iceGatherers.shift(); + } + var iceGatherer = new window.RTCIceGatherer({ + iceServers: this._config.iceServers, + gatherPolicy: this._config.iceTransportPolicy + }); + Object.defineProperty(iceGatherer, 'state', + {value: 'new', writable: true} + ); + + this.transceivers[sdpMLineIndex].bufferedCandidateEvents = []; + this.transceivers[sdpMLineIndex].bufferCandidates = function(event) { + var end = !event.candidate || Object.keys(event.candidate).length === 0; + // polyfill since RTCIceGatherer.state is not implemented in + // Edge 10547 yet. + iceGatherer.state = end ? 'completed' : 'gathering'; + if (pc.transceivers[sdpMLineIndex].bufferedCandidateEvents !== null) { + pc.transceivers[sdpMLineIndex].bufferedCandidateEvents.push(event); + } + }; + iceGatherer.addEventListener('localcandidate', + this.transceivers[sdpMLineIndex].bufferCandidates); + return iceGatherer; + }; + + // start gathering from an RTCIceGatherer. + RTCPeerConnection.prototype._gather = function(mid, sdpMLineIndex) { + var pc = this; + var iceGatherer = this.transceivers[sdpMLineIndex].iceGatherer; + if (iceGatherer.onlocalcandidate) { + return; + } + var bufferedCandidateEvents = + this.transceivers[sdpMLineIndex].bufferedCandidateEvents; + this.transceivers[sdpMLineIndex].bufferedCandidateEvents = null; + iceGatherer.removeEventListener('localcandidate', + this.transceivers[sdpMLineIndex].bufferCandidates); + iceGatherer.onlocalcandidate = function(evt) { + if (pc.usingBundle && sdpMLineIndex > 0) { + // if we know that we use bundle we can drop candidates with + // ѕdpMLineIndex > 0. If we don't do this then our state gets + // confused since we dispose the extra ice gatherer. + return; + } + var event = new Event('icecandidate'); + event.candidate = {sdpMid: mid, sdpMLineIndex: sdpMLineIndex}; + + var cand = evt.candidate; + // Edge emits an empty object for RTCIceCandidateComplete‥ + var end = !cand || Object.keys(cand).length === 0; + if (end) { + // polyfill since RTCIceGatherer.state is not implemented in + // Edge 10547 yet. + if (iceGatherer.state === 'new' || iceGatherer.state === 'gathering') { + iceGatherer.state = 'completed'; + } + } else { + if (iceGatherer.state === 'new') { + iceGatherer.state = 'gathering'; + } + // RTCIceCandidate doesn't have a component, needs to be added + cand.component = 1; + // also the usernameFragment. TODO: update SDP to take both variants. + cand.ufrag = iceGatherer.getLocalParameters().usernameFragment; + + var serializedCandidate = sdp.writeCandidate(cand); + event.candidate = Object.assign(event.candidate, + sdp.parseCandidate(serializedCandidate)); + + event.candidate.candidate = serializedCandidate; + event.candidate.toJSON = function() { + return { + candidate: event.candidate.candidate, + sdpMid: event.candidate.sdpMid, + sdpMLineIndex: event.candidate.sdpMLineIndex, + usernameFragment: event.candidate.usernameFragment + }; + }; + } + + // update local description. + var sections = sdp.getMediaSections(pc._localDescription.sdp); + if (!end) { + sections[event.candidate.sdpMLineIndex] += + 'a=' + event.candidate.candidate + '\r\n'; + } else { + sections[event.candidate.sdpMLineIndex] += + 'a=end-of-candidates\r\n'; + } + pc._localDescription.sdp = + sdp.getDescription(pc._localDescription.sdp) + + sections.join(''); + var complete = pc.transceivers.every(function(transceiver) { + return transceiver.iceGatherer && + transceiver.iceGatherer.state === 'completed'; + }); + + if (pc.iceGatheringState !== 'gathering') { + pc.iceGatheringState = 'gathering'; + pc._emitGatheringStateChange(); + } + + // Emit candidate. Also emit null candidate when all gatherers are + // complete. + if (!end) { + pc._dispatchEvent('icecandidate', event); + } + if (complete) { + pc._dispatchEvent('icecandidate', new Event('icecandidate')); + pc.iceGatheringState = 'complete'; + pc._emitGatheringStateChange(); + } + }; + + // emit already gathered candidates. + window.setTimeout(function() { + bufferedCandidateEvents.forEach(function(e) { + iceGatherer.onlocalcandidate(e); + }); + }, 0); + }; + + // Create ICE transport and DTLS transport. + RTCPeerConnection.prototype._createIceAndDtlsTransports = function() { + var pc = this; + var iceTransport = new window.RTCIceTransport(null); + iceTransport.onicestatechange = function() { + pc._updateIceConnectionState(); + pc._updateConnectionState(); + }; + + var dtlsTransport = new window.RTCDtlsTransport(iceTransport); + dtlsTransport.ondtlsstatechange = function() { + pc._updateConnectionState(); + }; + dtlsTransport.onerror = function() { + // onerror does not set state to failed by itself. + Object.defineProperty(dtlsTransport, 'state', + {value: 'failed', writable: true}); + pc._updateConnectionState(); + }; + + return { + iceTransport: iceTransport, + dtlsTransport: dtlsTransport + }; + }; + + // Destroy ICE gatherer, ICE transport and DTLS transport. + // Without triggering the callbacks. + RTCPeerConnection.prototype._disposeIceAndDtlsTransports = function( + sdpMLineIndex) { + var iceGatherer = this.transceivers[sdpMLineIndex].iceGatherer; + if (iceGatherer) { + delete iceGatherer.onlocalcandidate; + delete this.transceivers[sdpMLineIndex].iceGatherer; + } + var iceTransport = this.transceivers[sdpMLineIndex].iceTransport; + if (iceTransport) { + delete iceTransport.onicestatechange; + delete this.transceivers[sdpMLineIndex].iceTransport; + } + var dtlsTransport = this.transceivers[sdpMLineIndex].dtlsTransport; + if (dtlsTransport) { + delete dtlsTransport.ondtlsstatechange; + delete dtlsTransport.onerror; + delete this.transceivers[sdpMLineIndex].dtlsTransport; + } + }; + + // Start the RTP Sender and Receiver for a transceiver. + RTCPeerConnection.prototype._transceive = function(transceiver, + send, recv) { + var params = getCommonCapabilities(transceiver.localCapabilities, + transceiver.remoteCapabilities); + if (send && transceiver.rtpSender) { + params.encodings = transceiver.sendEncodingParameters; + params.rtcp = { + cname: sdp.localCName, + compound: transceiver.rtcpParameters.compound + }; + if (transceiver.recvEncodingParameters.length) { + params.rtcp.ssrc = transceiver.recvEncodingParameters[0].ssrc; + } + transceiver.rtpSender.send(params); + } + if (recv && transceiver.rtpReceiver && params.codecs.length > 0) { + // remove RTX field in Edge 14942 + if (transceiver.kind === 'video' + && transceiver.recvEncodingParameters + && edgeVersion < 15019) { + transceiver.recvEncodingParameters.forEach(function(p) { + delete p.rtx; + }); + } + if (transceiver.recvEncodingParameters.length) { + params.encodings = transceiver.recvEncodingParameters; + } else { + params.encodings = [{}]; + } + params.rtcp = { + compound: transceiver.rtcpParameters.compound + }; + if (transceiver.rtcpParameters.cname) { + params.rtcp.cname = transceiver.rtcpParameters.cname; + } + if (transceiver.sendEncodingParameters.length) { + params.rtcp.ssrc = transceiver.sendEncodingParameters[0].ssrc; + } + transceiver.rtpReceiver.receive(params); + } + }; + + RTCPeerConnection.prototype.setLocalDescription = function(description) { + var pc = this; + + // Note: pranswer is not supported. + if (['offer', 'answer'].indexOf(description.type) === -1) { + return Promise.reject(makeError('TypeError', + 'Unsupported type "' + description.type + '"')); + } + + if (!isActionAllowedInSignalingState('setLocalDescription', + description.type, pc.signalingState) || pc._isClosed) { + return Promise.reject(makeError('InvalidStateError', + 'Can not set local ' + description.type + + ' in state ' + pc.signalingState)); + } + + var sections; + var sessionpart; + if (description.type === 'offer') { + // VERY limited support for SDP munging. Limited to: + // * changing the order of codecs + sections = sdp.splitSections(description.sdp); + sessionpart = sections.shift(); + sections.forEach(function(mediaSection, sdpMLineIndex) { + var caps = sdp.parseRtpParameters(mediaSection); + pc.transceivers[sdpMLineIndex].localCapabilities = caps; + }); + + pc.transceivers.forEach(function(transceiver, sdpMLineIndex) { + pc._gather(transceiver.mid, sdpMLineIndex); + }); + } else if (description.type === 'answer') { + sections = sdp.splitSections(pc._remoteDescription.sdp); + sessionpart = sections.shift(); + var isIceLite = sdp.matchPrefix(sessionpart, + 'a=ice-lite').length > 0; + sections.forEach(function(mediaSection, sdpMLineIndex) { + var transceiver = pc.transceivers[sdpMLineIndex]; + var iceGatherer = transceiver.iceGatherer; + var iceTransport = transceiver.iceTransport; + var dtlsTransport = transceiver.dtlsTransport; + var localCapabilities = transceiver.localCapabilities; + var remoteCapabilities = transceiver.remoteCapabilities; + + // treat bundle-only as not-rejected. + var rejected = sdp.isRejected(mediaSection) && + sdp.matchPrefix(mediaSection, 'a=bundle-only').length === 0; + + if (!rejected && !transceiver.rejected) { + var remoteIceParameters = sdp.getIceParameters( + mediaSection, sessionpart); + var remoteDtlsParameters = sdp.getDtlsParameters( + mediaSection, sessionpart); + if (isIceLite) { + remoteDtlsParameters.role = 'server'; + } + + if (!pc.usingBundle || sdpMLineIndex === 0) { + pc._gather(transceiver.mid, sdpMLineIndex); + if (iceTransport.state === 'new') { + iceTransport.start(iceGatherer, remoteIceParameters, + isIceLite ? 'controlling' : 'controlled'); + } + if (dtlsTransport.state === 'new') { + dtlsTransport.start(remoteDtlsParameters); + } + } + + // Calculate intersection of capabilities. + var params = getCommonCapabilities(localCapabilities, + remoteCapabilities); + + // Start the RTCRtpSender. The RTCRtpReceiver for this + // transceiver has already been started in setRemoteDescription. + pc._transceive(transceiver, + params.codecs.length > 0, + false); + } + }); + } + + pc._localDescription = { + type: description.type, + sdp: description.sdp + }; + if (description.type === 'offer') { + pc._updateSignalingState('have-local-offer'); + } else { + pc._updateSignalingState('stable'); + } + + return Promise.resolve(); + }; + + RTCPeerConnection.prototype.setRemoteDescription = function(description) { + var pc = this; + + // Note: pranswer is not supported. + if (['offer', 'answer'].indexOf(description.type) === -1) { + return Promise.reject(makeError('TypeError', + 'Unsupported type "' + description.type + '"')); + } + + if (!isActionAllowedInSignalingState('setRemoteDescription', + description.type, pc.signalingState) || pc._isClosed) { + return Promise.reject(makeError('InvalidStateError', + 'Can not set remote ' + description.type + + ' in state ' + pc.signalingState)); + } + + var streams = {}; + pc.remoteStreams.forEach(function(stream) { + streams[stream.id] = stream; + }); + var receiverList = []; + var sections = sdp.splitSections(description.sdp); + var sessionpart = sections.shift(); + var isIceLite = sdp.matchPrefix(sessionpart, + 'a=ice-lite').length > 0; + var usingBundle = sdp.matchPrefix(sessionpart, + 'a=group:BUNDLE ').length > 0; + pc.usingBundle = usingBundle; + var iceOptions = sdp.matchPrefix(sessionpart, + 'a=ice-options:')[0]; + if (iceOptions) { + pc.canTrickleIceCandidates = iceOptions.substr(14).split(' ') + .indexOf('trickle') >= 0; + } else { + pc.canTrickleIceCandidates = false; + } + + sections.forEach(function(mediaSection, sdpMLineIndex) { + var lines = sdp.splitLines(mediaSection); + var kind = sdp.getKind(mediaSection); + // treat bundle-only as not-rejected. + var rejected = sdp.isRejected(mediaSection) && + sdp.matchPrefix(mediaSection, 'a=bundle-only').length === 0; + var protocol = lines[0].substr(2).split(' ')[2]; + + var direction = sdp.getDirection(mediaSection, sessionpart); + var remoteMsid = sdp.parseMsid(mediaSection); + + var mid = sdp.getMid(mediaSection) || sdp.generateIdentifier(); + + // Reject datachannels which are not implemented yet. + if (rejected || (kind === 'application' && (protocol === 'DTLS/SCTP' || + protocol === 'UDP/DTLS/SCTP'))) { + // TODO: this is dangerous in the case where a non-rejected m-line + // becomes rejected. + pc.transceivers[sdpMLineIndex] = { + mid: mid, + kind: kind, + protocol: protocol, + rejected: true + }; + return; + } + + if (!rejected && pc.transceivers[sdpMLineIndex] && + pc.transceivers[sdpMLineIndex].rejected) { + // recycle a rejected transceiver. + pc.transceivers[sdpMLineIndex] = pc._createTransceiver(kind, true); + } + + var transceiver; + var iceGatherer; + var iceTransport; + var dtlsTransport; + var rtpReceiver; + var sendEncodingParameters; + var recvEncodingParameters; + var localCapabilities; + + var track; + // FIXME: ensure the mediaSection has rtcp-mux set. + var remoteCapabilities = sdp.parseRtpParameters(mediaSection); + var remoteIceParameters; + var remoteDtlsParameters; + if (!rejected) { + remoteIceParameters = sdp.getIceParameters(mediaSection, + sessionpart); + remoteDtlsParameters = sdp.getDtlsParameters(mediaSection, + sessionpart); + remoteDtlsParameters.role = 'client'; + } + recvEncodingParameters = + sdp.parseRtpEncodingParameters(mediaSection); + + var rtcpParameters = sdp.parseRtcpParameters(mediaSection); + + var isComplete = sdp.matchPrefix(mediaSection, + 'a=end-of-candidates', sessionpart).length > 0; + var cands = sdp.matchPrefix(mediaSection, 'a=candidate:') + .map(function(cand) { + return sdp.parseCandidate(cand); + }) + .filter(function(cand) { + return cand.component === 1; + }); + + // Check if we can use BUNDLE and dispose transports. + if ((description.type === 'offer' || description.type === 'answer') && + !rejected && usingBundle && sdpMLineIndex > 0 && + pc.transceivers[sdpMLineIndex]) { + pc._disposeIceAndDtlsTransports(sdpMLineIndex); + pc.transceivers[sdpMLineIndex].iceGatherer = + pc.transceivers[0].iceGatherer; + pc.transceivers[sdpMLineIndex].iceTransport = + pc.transceivers[0].iceTransport; + pc.transceivers[sdpMLineIndex].dtlsTransport = + pc.transceivers[0].dtlsTransport; + if (pc.transceivers[sdpMLineIndex].rtpSender) { + pc.transceivers[sdpMLineIndex].rtpSender.setTransport( + pc.transceivers[0].dtlsTransport); + } + if (pc.transceivers[sdpMLineIndex].rtpReceiver) { + pc.transceivers[sdpMLineIndex].rtpReceiver.setTransport( + pc.transceivers[0].dtlsTransport); + } + } + if (description.type === 'offer' && !rejected) { + transceiver = pc.transceivers[sdpMLineIndex] || + pc._createTransceiver(kind); + transceiver.mid = mid; + + if (!transceiver.iceGatherer) { + transceiver.iceGatherer = pc._createIceGatherer(sdpMLineIndex, + usingBundle); + } + + if (cands.length && transceiver.iceTransport.state === 'new') { + if (isComplete && (!usingBundle || sdpMLineIndex === 0)) { + transceiver.iceTransport.setRemoteCandidates(cands); + } else { + cands.forEach(function(candidate) { + maybeAddCandidate(transceiver.iceTransport, candidate); + }); + } + } + + localCapabilities = window.RTCRtpReceiver.getCapabilities(kind); + + // filter RTX until additional stuff needed for RTX is implemented + // in adapter.js + if (edgeVersion < 15019) { + localCapabilities.codecs = localCapabilities.codecs.filter( + function(codec) { + return codec.name !== 'rtx'; + }); + } + + sendEncodingParameters = transceiver.sendEncodingParameters || [{ + ssrc: (2 * sdpMLineIndex + 2) * 1001 + }]; + + // TODO: rewrite to use http://w3c.github.io/webrtc-pc/#set-associated-remote-streams + var isNewTrack = false; + if (direction === 'sendrecv' || direction === 'sendonly') { + isNewTrack = !transceiver.rtpReceiver; + rtpReceiver = transceiver.rtpReceiver || + new window.RTCRtpReceiver(transceiver.dtlsTransport, kind); + + if (isNewTrack) { + var stream; + track = rtpReceiver.track; + // FIXME: does not work with Plan B. + if (remoteMsid && remoteMsid.stream === '-') ; else if (remoteMsid) { + if (!streams[remoteMsid.stream]) { + streams[remoteMsid.stream] = new window.MediaStream(); + Object.defineProperty(streams[remoteMsid.stream], 'id', { + get: function() { + return remoteMsid.stream; + } + }); + } + Object.defineProperty(track, 'id', { + get: function() { + return remoteMsid.track; + } + }); + stream = streams[remoteMsid.stream]; + } else { + if (!streams.default) { + streams.default = new window.MediaStream(); + } + stream = streams.default; + } + if (stream) { + addTrackToStreamAndFireEvent(track, stream); + transceiver.associatedRemoteMediaStreams.push(stream); + } + receiverList.push([track, rtpReceiver, stream]); + } + } else if (transceiver.rtpReceiver && transceiver.rtpReceiver.track) { + transceiver.associatedRemoteMediaStreams.forEach(function(s) { + var nativeTrack = s.getTracks().find(function(t) { + return t.id === transceiver.rtpReceiver.track.id; + }); + if (nativeTrack) { + removeTrackFromStreamAndFireEvent(nativeTrack, s); + } + }); + transceiver.associatedRemoteMediaStreams = []; + } + + transceiver.localCapabilities = localCapabilities; + transceiver.remoteCapabilities = remoteCapabilities; + transceiver.rtpReceiver = rtpReceiver; + transceiver.rtcpParameters = rtcpParameters; + transceiver.sendEncodingParameters = sendEncodingParameters; + transceiver.recvEncodingParameters = recvEncodingParameters; + + // Start the RTCRtpReceiver now. The RTPSender is started in + // setLocalDescription. + pc._transceive(pc.transceivers[sdpMLineIndex], + false, + isNewTrack); + } else if (description.type === 'answer' && !rejected) { + transceiver = pc.transceivers[sdpMLineIndex]; + iceGatherer = transceiver.iceGatherer; + iceTransport = transceiver.iceTransport; + dtlsTransport = transceiver.dtlsTransport; + rtpReceiver = transceiver.rtpReceiver; + sendEncodingParameters = transceiver.sendEncodingParameters; + localCapabilities = transceiver.localCapabilities; + + pc.transceivers[sdpMLineIndex].recvEncodingParameters = + recvEncodingParameters; + pc.transceivers[sdpMLineIndex].remoteCapabilities = + remoteCapabilities; + pc.transceivers[sdpMLineIndex].rtcpParameters = rtcpParameters; + + if (cands.length && iceTransport.state === 'new') { + if ((isIceLite || isComplete) && + (!usingBundle || sdpMLineIndex === 0)) { + iceTransport.setRemoteCandidates(cands); + } else { + cands.forEach(function(candidate) { + maybeAddCandidate(transceiver.iceTransport, candidate); + }); + } + } + + if (!usingBundle || sdpMLineIndex === 0) { + if (iceTransport.state === 'new') { + iceTransport.start(iceGatherer, remoteIceParameters, + 'controlling'); + } + if (dtlsTransport.state === 'new') { + dtlsTransport.start(remoteDtlsParameters); + } + } + + // If the offer contained RTX but the answer did not, + // remove RTX from sendEncodingParameters. + var commonCapabilities = getCommonCapabilities( + transceiver.localCapabilities, + transceiver.remoteCapabilities); + + var hasRtx = commonCapabilities.codecs.filter(function(c) { + return c.name.toLowerCase() === 'rtx'; + }).length; + if (!hasRtx && transceiver.sendEncodingParameters[0].rtx) { + delete transceiver.sendEncodingParameters[0].rtx; + } + + pc._transceive(transceiver, + direction === 'sendrecv' || direction === 'recvonly', + direction === 'sendrecv' || direction === 'sendonly'); + + // TODO: rewrite to use http://w3c.github.io/webrtc-pc/#set-associated-remote-streams + if (rtpReceiver && + (direction === 'sendrecv' || direction === 'sendonly')) { + track = rtpReceiver.track; + if (remoteMsid) { + if (!streams[remoteMsid.stream]) { + streams[remoteMsid.stream] = new window.MediaStream(); + } + addTrackToStreamAndFireEvent(track, streams[remoteMsid.stream]); + receiverList.push([track, rtpReceiver, streams[remoteMsid.stream]]); + } else { + if (!streams.default) { + streams.default = new window.MediaStream(); + } + addTrackToStreamAndFireEvent(track, streams.default); + receiverList.push([track, rtpReceiver, streams.default]); + } + } else { + // FIXME: actually the receiver should be created later. + delete transceiver.rtpReceiver; + } + } + }); + + if (pc._dtlsRole === undefined) { + pc._dtlsRole = description.type === 'offer' ? 'active' : 'passive'; + } + + pc._remoteDescription = { + type: description.type, + sdp: description.sdp + }; + if (description.type === 'offer') { + pc._updateSignalingState('have-remote-offer'); + } else { + pc._updateSignalingState('stable'); + } + Object.keys(streams).forEach(function(sid) { + var stream = streams[sid]; + if (stream.getTracks().length) { + if (pc.remoteStreams.indexOf(stream) === -1) { + pc.remoteStreams.push(stream); + var event = new Event('addstream'); + event.stream = stream; + window.setTimeout(function() { + pc._dispatchEvent('addstream', event); + }); + } + + receiverList.forEach(function(item) { + var track = item[0]; + var receiver = item[1]; + if (stream.id !== item[2].id) { + return; + } + fireAddTrack(pc, track, receiver, [stream]); + }); + } + }); + receiverList.forEach(function(item) { + if (item[2]) { + return; + } + fireAddTrack(pc, item[0], item[1], []); + }); + + // check whether addIceCandidate({}) was called within four seconds after + // setRemoteDescription. + window.setTimeout(function() { + if (!(pc && pc.transceivers)) { + return; + } + pc.transceivers.forEach(function(transceiver) { + if (transceiver.iceTransport && + transceiver.iceTransport.state === 'new' && + transceiver.iceTransport.getRemoteCandidates().length > 0) { + console.warn('Timeout for addRemoteCandidate. Consider sending ' + + 'an end-of-candidates notification'); + transceiver.iceTransport.addRemoteCandidate({}); + } + }); + }, 4000); + + return Promise.resolve(); + }; + + RTCPeerConnection.prototype.close = function() { + this.transceivers.forEach(function(transceiver) { + /* not yet + if (transceiver.iceGatherer) { + transceiver.iceGatherer.close(); + } + */ + if (transceiver.iceTransport) { + transceiver.iceTransport.stop(); + } + if (transceiver.dtlsTransport) { + transceiver.dtlsTransport.stop(); + } + if (transceiver.rtpSender) { + transceiver.rtpSender.stop(); + } + if (transceiver.rtpReceiver) { + transceiver.rtpReceiver.stop(); + } + }); + // FIXME: clean up tracks, local streams, remote streams, etc + this._isClosed = true; + this._updateSignalingState('closed'); + }; + + // Update the signaling state. + RTCPeerConnection.prototype._updateSignalingState = function(newState) { + this.signalingState = newState; + var event = new Event('signalingstatechange'); + this._dispatchEvent('signalingstatechange', event); + }; + + // Determine whether to fire the negotiationneeded event. + RTCPeerConnection.prototype._maybeFireNegotiationNeeded = function() { + var pc = this; + if (this.signalingState !== 'stable' || this.needNegotiation === true) { + return; + } + this.needNegotiation = true; + window.setTimeout(function() { + if (pc.needNegotiation) { + pc.needNegotiation = false; + var event = new Event('negotiationneeded'); + pc._dispatchEvent('negotiationneeded', event); + } + }, 0); + }; + + // Update the ice connection state. + RTCPeerConnection.prototype._updateIceConnectionState = function() { + var newState; + var states = { + 'new': 0, + closed: 0, + checking: 0, + connected: 0, + completed: 0, + disconnected: 0, + failed: 0 + }; + this.transceivers.forEach(function(transceiver) { + if (transceiver.iceTransport && !transceiver.rejected) { + states[transceiver.iceTransport.state]++; + } + }); + + newState = 'new'; + if (states.failed > 0) { + newState = 'failed'; + } else if (states.checking > 0) { + newState = 'checking'; + } else if (states.disconnected > 0) { + newState = 'disconnected'; + } else if (states.new > 0) { + newState = 'new'; + } else if (states.connected > 0) { + newState = 'connected'; + } else if (states.completed > 0) { + newState = 'completed'; + } + + if (newState !== this.iceConnectionState) { + this.iceConnectionState = newState; + var event = new Event('iceconnectionstatechange'); + this._dispatchEvent('iceconnectionstatechange', event); + } + }; + + // Update the connection state. + RTCPeerConnection.prototype._updateConnectionState = function() { + var newState; + var states = { + 'new': 0, + closed: 0, + connecting: 0, + connected: 0, + completed: 0, + disconnected: 0, + failed: 0 + }; + this.transceivers.forEach(function(transceiver) { + if (transceiver.iceTransport && transceiver.dtlsTransport && + !transceiver.rejected) { + states[transceiver.iceTransport.state]++; + states[transceiver.dtlsTransport.state]++; + } + }); + // ICETransport.completed and connected are the same for this purpose. + states.connected += states.completed; + + newState = 'new'; + if (states.failed > 0) { + newState = 'failed'; + } else if (states.connecting > 0) { + newState = 'connecting'; + } else if (states.disconnected > 0) { + newState = 'disconnected'; + } else if (states.new > 0) { + newState = 'new'; + } else if (states.connected > 0) { + newState = 'connected'; + } + + if (newState !== this.connectionState) { + this.connectionState = newState; + var event = new Event('connectionstatechange'); + this._dispatchEvent('connectionstatechange', event); + } + }; + + RTCPeerConnection.prototype.createOffer = function() { + var pc = this; + + if (pc._isClosed) { + return Promise.reject(makeError('InvalidStateError', + 'Can not call createOffer after close')); + } + + var numAudioTracks = pc.transceivers.filter(function(t) { + return t.kind === 'audio'; + }).length; + var numVideoTracks = pc.transceivers.filter(function(t) { + return t.kind === 'video'; + }).length; + + // Determine number of audio and video tracks we need to send/recv. + var offerOptions = arguments[0]; + if (offerOptions) { + // Reject Chrome legacy constraints. + if (offerOptions.mandatory || offerOptions.optional) { + throw new TypeError( + 'Legacy mandatory/optional constraints not supported.'); + } + if (offerOptions.offerToReceiveAudio !== undefined) { + if (offerOptions.offerToReceiveAudio === true) { + numAudioTracks = 1; + } else if (offerOptions.offerToReceiveAudio === false) { + numAudioTracks = 0; + } else { + numAudioTracks = offerOptions.offerToReceiveAudio; + } + } + if (offerOptions.offerToReceiveVideo !== undefined) { + if (offerOptions.offerToReceiveVideo === true) { + numVideoTracks = 1; + } else if (offerOptions.offerToReceiveVideo === false) { + numVideoTracks = 0; + } else { + numVideoTracks = offerOptions.offerToReceiveVideo; + } + } + } + + pc.transceivers.forEach(function(transceiver) { + if (transceiver.kind === 'audio') { + numAudioTracks--; + if (numAudioTracks < 0) { + transceiver.wantReceive = false; + } + } else if (transceiver.kind === 'video') { + numVideoTracks--; + if (numVideoTracks < 0) { + transceiver.wantReceive = false; + } + } + }); + + // Create M-lines for recvonly streams. + while (numAudioTracks > 0 || numVideoTracks > 0) { + if (numAudioTracks > 0) { + pc._createTransceiver('audio'); + numAudioTracks--; + } + if (numVideoTracks > 0) { + pc._createTransceiver('video'); + numVideoTracks--; + } + } + + var sdp$1 = sdp.writeSessionBoilerplate(pc._sdpSessionId, + pc._sdpSessionVersion++); + pc.transceivers.forEach(function(transceiver, sdpMLineIndex) { + // For each track, create an ice gatherer, ice transport, + // dtls transport, potentially rtpsender and rtpreceiver. + var track = transceiver.track; + var kind = transceiver.kind; + var mid = transceiver.mid || sdp.generateIdentifier(); + transceiver.mid = mid; + + if (!transceiver.iceGatherer) { + transceiver.iceGatherer = pc._createIceGatherer(sdpMLineIndex, + pc.usingBundle); + } + + var localCapabilities = window.RTCRtpSender.getCapabilities(kind); + // filter RTX until additional stuff needed for RTX is implemented + // in adapter.js + if (edgeVersion < 15019) { + localCapabilities.codecs = localCapabilities.codecs.filter( + function(codec) { + return codec.name !== 'rtx'; + }); + } + localCapabilities.codecs.forEach(function(codec) { + // work around https://bugs.chromium.org/p/webrtc/issues/detail?id=6552 + // by adding level-asymmetry-allowed=1 + if (codec.name === 'H264' && + codec.parameters['level-asymmetry-allowed'] === undefined) { + codec.parameters['level-asymmetry-allowed'] = '1'; + } + + // for subsequent offers, we might have to re-use the payload + // type of the last offer. + if (transceiver.remoteCapabilities && + transceiver.remoteCapabilities.codecs) { + transceiver.remoteCapabilities.codecs.forEach(function(remoteCodec) { + if (codec.name.toLowerCase() === remoteCodec.name.toLowerCase() && + codec.clockRate === remoteCodec.clockRate) { + codec.preferredPayloadType = remoteCodec.payloadType; + } + }); + } + }); + localCapabilities.headerExtensions.forEach(function(hdrExt) { + var remoteExtensions = transceiver.remoteCapabilities && + transceiver.remoteCapabilities.headerExtensions || []; + remoteExtensions.forEach(function(rHdrExt) { + if (hdrExt.uri === rHdrExt.uri) { + hdrExt.id = rHdrExt.id; + } + }); + }); + + // generate an ssrc now, to be used later in rtpSender.send + var sendEncodingParameters = transceiver.sendEncodingParameters || [{ + ssrc: (2 * sdpMLineIndex + 1) * 1001 + }]; + if (track) { + // add RTX + if (edgeVersion >= 15019 && kind === 'video' && + !sendEncodingParameters[0].rtx) { + sendEncodingParameters[0].rtx = { + ssrc: sendEncodingParameters[0].ssrc + 1 + }; + } + } + + if (transceiver.wantReceive) { + transceiver.rtpReceiver = new window.RTCRtpReceiver( + transceiver.dtlsTransport, kind); + } + + transceiver.localCapabilities = localCapabilities; + transceiver.sendEncodingParameters = sendEncodingParameters; + }); + + // always offer BUNDLE and dispose on return if not supported. + if (pc._config.bundlePolicy !== 'max-compat') { + sdp$1 += 'a=group:BUNDLE ' + pc.transceivers.map(function(t) { + return t.mid; + }).join(' ') + '\r\n'; + } + sdp$1 += 'a=ice-options:trickle\r\n'; + + pc.transceivers.forEach(function(transceiver, sdpMLineIndex) { + sdp$1 += writeMediaSection(transceiver, transceiver.localCapabilities, + 'offer', transceiver.stream, pc._dtlsRole); + sdp$1 += 'a=rtcp-rsize\r\n'; + + if (transceiver.iceGatherer && pc.iceGatheringState !== 'new' && + (sdpMLineIndex === 0 || !pc.usingBundle)) { + transceiver.iceGatherer.getLocalCandidates().forEach(function(cand) { + cand.component = 1; + sdp$1 += 'a=' + sdp.writeCandidate(cand) + '\r\n'; + }); + + if (transceiver.iceGatherer.state === 'completed') { + sdp$1 += 'a=end-of-candidates\r\n'; + } + } + }); + + var desc = new window.RTCSessionDescription({ + type: 'offer', + sdp: sdp$1 + }); + return Promise.resolve(desc); + }; + + RTCPeerConnection.prototype.createAnswer = function() { + var pc = this; + + if (pc._isClosed) { + return Promise.reject(makeError('InvalidStateError', + 'Can not call createAnswer after close')); + } + + if (!(pc.signalingState === 'have-remote-offer' || + pc.signalingState === 'have-local-pranswer')) { + return Promise.reject(makeError('InvalidStateError', + 'Can not call createAnswer in signalingState ' + pc.signalingState)); + } + + var sdp$1 = sdp.writeSessionBoilerplate(pc._sdpSessionId, + pc._sdpSessionVersion++); + if (pc.usingBundle) { + sdp$1 += 'a=group:BUNDLE ' + pc.transceivers.map(function(t) { + return t.mid; + }).join(' ') + '\r\n'; + } + sdp$1 += 'a=ice-options:trickle\r\n'; + + var mediaSectionsInOffer = sdp.getMediaSections( + pc._remoteDescription.sdp).length; + pc.transceivers.forEach(function(transceiver, sdpMLineIndex) { + if (sdpMLineIndex + 1 > mediaSectionsInOffer) { + return; + } + if (transceiver.rejected) { + if (transceiver.kind === 'application') { + if (transceiver.protocol === 'DTLS/SCTP') { // legacy fmt + sdp$1 += 'm=application 0 DTLS/SCTP 5000\r\n'; + } else { + sdp$1 += 'm=application 0 ' + transceiver.protocol + + ' webrtc-datachannel\r\n'; + } + } else if (transceiver.kind === 'audio') { + sdp$1 += 'm=audio 0 UDP/TLS/RTP/SAVPF 0\r\n' + + 'a=rtpmap:0 PCMU/8000\r\n'; + } else if (transceiver.kind === 'video') { + sdp$1 += 'm=video 0 UDP/TLS/RTP/SAVPF 120\r\n' + + 'a=rtpmap:120 VP8/90000\r\n'; + } + sdp$1 += 'c=IN IP4 0.0.0.0\r\n' + + 'a=inactive\r\n' + + 'a=mid:' + transceiver.mid + '\r\n'; + return; + } + + // FIXME: look at direction. + if (transceiver.stream) { + var localTrack; + if (transceiver.kind === 'audio') { + localTrack = transceiver.stream.getAudioTracks()[0]; + } else if (transceiver.kind === 'video') { + localTrack = transceiver.stream.getVideoTracks()[0]; + } + if (localTrack) { + // add RTX + if (edgeVersion >= 15019 && transceiver.kind === 'video' && + !transceiver.sendEncodingParameters[0].rtx) { + transceiver.sendEncodingParameters[0].rtx = { + ssrc: transceiver.sendEncodingParameters[0].ssrc + 1 + }; + } + } + } + + // Calculate intersection of capabilities. + var commonCapabilities = getCommonCapabilities( + transceiver.localCapabilities, + transceiver.remoteCapabilities); + + var hasRtx = commonCapabilities.codecs.filter(function(c) { + return c.name.toLowerCase() === 'rtx'; + }).length; + if (!hasRtx && transceiver.sendEncodingParameters[0].rtx) { + delete transceiver.sendEncodingParameters[0].rtx; + } + + sdp$1 += writeMediaSection(transceiver, commonCapabilities, + 'answer', transceiver.stream, pc._dtlsRole); + if (transceiver.rtcpParameters && + transceiver.rtcpParameters.reducedSize) { + sdp$1 += 'a=rtcp-rsize\r\n'; + } + }); + + var desc = new window.RTCSessionDescription({ + type: 'answer', + sdp: sdp$1 + }); + return Promise.resolve(desc); + }; + + RTCPeerConnection.prototype.addIceCandidate = function(candidate) { + var pc = this; + var sections; + if (candidate && !(candidate.sdpMLineIndex !== undefined || + candidate.sdpMid)) { + return Promise.reject(new TypeError('sdpMLineIndex or sdpMid required')); + } + + // TODO: needs to go into ops queue. + return new Promise(function(resolve, reject) { + if (!pc._remoteDescription) { + return reject(makeError('InvalidStateError', + 'Can not add ICE candidate without a remote description')); + } else if (!candidate || candidate.candidate === '') { + for (var j = 0; j < pc.transceivers.length; j++) { + if (pc.transceivers[j].rejected) { + continue; + } + pc.transceivers[j].iceTransport.addRemoteCandidate({}); + sections = sdp.getMediaSections(pc._remoteDescription.sdp); + sections[j] += 'a=end-of-candidates\r\n'; + pc._remoteDescription.sdp = + sdp.getDescription(pc._remoteDescription.sdp) + + sections.join(''); + if (pc.usingBundle) { + break; + } + } + } else { + var sdpMLineIndex = candidate.sdpMLineIndex; + if (candidate.sdpMid) { + for (var i = 0; i < pc.transceivers.length; i++) { + if (pc.transceivers[i].mid === candidate.sdpMid) { + sdpMLineIndex = i; + break; + } + } + } + var transceiver = pc.transceivers[sdpMLineIndex]; + if (transceiver) { + if (transceiver.rejected) { + return resolve(); + } + var cand = Object.keys(candidate.candidate).length > 0 ? + sdp.parseCandidate(candidate.candidate) : {}; + // Ignore Chrome's invalid candidates since Edge does not like them. + if (cand.protocol === 'tcp' && (cand.port === 0 || cand.port === 9)) { + return resolve(); + } + // Ignore RTCP candidates, we assume RTCP-MUX. + if (cand.component && cand.component !== 1) { + return resolve(); + } + // when using bundle, avoid adding candidates to the wrong + // ice transport. And avoid adding candidates added in the SDP. + if (sdpMLineIndex === 0 || (sdpMLineIndex > 0 && + transceiver.iceTransport !== pc.transceivers[0].iceTransport)) { + if (!maybeAddCandidate(transceiver.iceTransport, cand)) { + return reject(makeError('OperationError', + 'Can not add ICE candidate')); + } + } + + // update the remoteDescription. + var candidateString = candidate.candidate.trim(); + if (candidateString.indexOf('a=') === 0) { + candidateString = candidateString.substr(2); + } + sections = sdp.getMediaSections(pc._remoteDescription.sdp); + sections[sdpMLineIndex] += 'a=' + + (cand.type ? candidateString : 'end-of-candidates') + + '\r\n'; + pc._remoteDescription.sdp = + sdp.getDescription(pc._remoteDescription.sdp) + + sections.join(''); + } else { + return reject(makeError('OperationError', + 'Can not add ICE candidate')); + } + } + resolve(); + }); + }; + + RTCPeerConnection.prototype.getStats = function(selector) { + if (selector && selector instanceof window.MediaStreamTrack) { + var senderOrReceiver = null; + this.transceivers.forEach(function(transceiver) { + if (transceiver.rtpSender && + transceiver.rtpSender.track === selector) { + senderOrReceiver = transceiver.rtpSender; + } else if (transceiver.rtpReceiver && + transceiver.rtpReceiver.track === selector) { + senderOrReceiver = transceiver.rtpReceiver; + } + }); + if (!senderOrReceiver) { + throw makeError('InvalidAccessError', 'Invalid selector.'); + } + return senderOrReceiver.getStats(); + } + + var promises = []; + this.transceivers.forEach(function(transceiver) { + ['rtpSender', 'rtpReceiver', 'iceGatherer', 'iceTransport', + 'dtlsTransport'].forEach(function(method) { + if (transceiver[method]) { + promises.push(transceiver[method].getStats()); + } + }); + }); + return Promise.all(promises).then(function(allStats) { + var results = new Map(); + allStats.forEach(function(stats) { + stats.forEach(function(stat) { + results.set(stat.id, stat); + }); + }); + return results; + }); + }; + + // fix low-level stat names and return Map instead of object. + var ortcObjects = ['RTCRtpSender', 'RTCRtpReceiver', 'RTCIceGatherer', + 'RTCIceTransport', 'RTCDtlsTransport']; + ortcObjects.forEach(function(ortcObjectName) { + var obj = window[ortcObjectName]; + if (obj && obj.prototype && obj.prototype.getStats) { + var nativeGetstats = obj.prototype.getStats; + obj.prototype.getStats = function() { + return nativeGetstats.apply(this) + .then(function(nativeStats) { + var mapStats = new Map(); + Object.keys(nativeStats).forEach(function(id) { + nativeStats[id].type = fixStatsType(nativeStats[id]); + mapStats.set(id, nativeStats[id]); + }); + return mapStats; + }); + }; + } + }); + + // legacy callback shims. Should be moved to adapter.js some days. + var methods = ['createOffer', 'createAnswer']; + methods.forEach(function(method) { + var nativeMethod = RTCPeerConnection.prototype[method]; + RTCPeerConnection.prototype[method] = function() { + var args = arguments; + if (typeof args[0] === 'function' || + typeof args[1] === 'function') { // legacy + return nativeMethod.apply(this, [arguments[2]]) + .then(function(description) { + if (typeof args[0] === 'function') { + args[0].apply(null, [description]); + } + }, function(error) { + if (typeof args[1] === 'function') { + args[1].apply(null, [error]); + } + }); + } + return nativeMethod.apply(this, arguments); + }; + }); + + methods = ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate']; + methods.forEach(function(method) { + var nativeMethod = RTCPeerConnection.prototype[method]; + RTCPeerConnection.prototype[method] = function() { + var args = arguments; + if (typeof args[1] === 'function' || + typeof args[2] === 'function') { // legacy + return nativeMethod.apply(this, arguments) + .then(function() { + if (typeof args[1] === 'function') { + args[1].apply(null); + } + }, function(error) { + if (typeof args[2] === 'function') { + args[2].apply(null, [error]); + } + }); + } + return nativeMethod.apply(this, arguments); + }; + }); + + // getStats is special. It doesn't have a spec legacy method yet we support + // getStats(something, cb) without error callbacks. + ['getStats'].forEach(function(method) { + var nativeMethod = RTCPeerConnection.prototype[method]; + RTCPeerConnection.prototype[method] = function() { + var args = arguments; + if (typeof args[1] === 'function') { + return nativeMethod.apply(this, arguments) + .then(function() { + if (typeof args[1] === 'function') { + args[1].apply(null); + } + }); + } + return nativeMethod.apply(this, arguments); + }; + }); + + return RTCPeerConnection; + }; + + /* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + function shimGetUserMedia$2(window) { + const navigator = window && window.navigator; + + const shimError_ = function(e) { + return { + name: {PermissionDeniedError: 'NotAllowedError'}[e.name] || e.name, + message: e.message, + constraint: e.constraint, + toString() { + return this.name; + } + }; + }; + + // getUserMedia error shim. + const origGetUserMedia = navigator.mediaDevices.getUserMedia. + bind(navigator.mediaDevices); + navigator.mediaDevices.getUserMedia = function(c) { + return origGetUserMedia(c).catch(e => Promise.reject(shimError_(e))); + }; + } + + /* + * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + function shimGetDisplayMedia$1(window) { + if (!('getDisplayMedia' in window.navigator)) { + return; + } + if (!(window.navigator.mediaDevices)) { + return; + } + if (window.navigator.mediaDevices && + 'getDisplayMedia' in window.navigator.mediaDevices) { + return; + } + window.navigator.mediaDevices.getDisplayMedia = + window.navigator.getDisplayMedia.bind(window.navigator); + } + + /* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + function shimPeerConnection$1(window, browserDetails) { + if (window.RTCIceGatherer) { + if (!window.RTCIceCandidate) { + window.RTCIceCandidate = function RTCIceCandidate(args) { + return args; + }; + } + if (!window.RTCSessionDescription) { + window.RTCSessionDescription = function RTCSessionDescription(args) { + return args; + }; + } + // this adds an additional event listener to MediaStrackTrack that signals + // when a tracks enabled property was changed. Workaround for a bug in + // addStream, see below. No longer required in 15025+ + if (browserDetails.version < 15025) { + const origMSTEnabled = Object.getOwnPropertyDescriptor( + window.MediaStreamTrack.prototype, 'enabled'); + Object.defineProperty(window.MediaStreamTrack.prototype, 'enabled', { + set(value) { + origMSTEnabled.set.call(this, value); + const ev = new Event('enabled'); + ev.enabled = value; + this.dispatchEvent(ev); + } + }); + } + } + + // ORTC defines the DTMF sender a bit different. + // https://github.com/w3c/ortc/issues/714 + if (window.RTCRtpSender && !('dtmf' in window.RTCRtpSender.prototype)) { + Object.defineProperty(window.RTCRtpSender.prototype, 'dtmf', { + get() { + if (this._dtmf === undefined) { + if (this.track.kind === 'audio') { + this._dtmf = new window.RTCDtmfSender(this); + } else if (this.track.kind === 'video') { + this._dtmf = null; + } + } + return this._dtmf; + } + }); + } + // Edge currently only implements the RTCDtmfSender, not the + // RTCDTMFSender alias. See http://draft.ortc.org/#rtcdtmfsender2* + if (window.RTCDtmfSender && !window.RTCDTMFSender) { + window.RTCDTMFSender = window.RTCDtmfSender; + } + + const RTCPeerConnectionShim = rtcpeerconnection(window, + browserDetails.version); + window.RTCPeerConnection = function RTCPeerConnection(config) { + if (config && config.iceServers) { + config.iceServers = filterIceServers$1(config.iceServers, + browserDetails.version); + log$1('ICE servers after filtering:', config.iceServers); + } + return new RTCPeerConnectionShim(config); + }; + window.RTCPeerConnection.prototype = RTCPeerConnectionShim.prototype; + } + + function shimReplaceTrack(window) { + // ORTC has replaceTrack -- https://github.com/w3c/ortc/issues/614 + if (window.RTCRtpSender && + !('replaceTrack' in window.RTCRtpSender.prototype)) { + window.RTCRtpSender.prototype.replaceTrack = + window.RTCRtpSender.prototype.setTrack; + } + } + + var edgeShim = /*#__PURE__*/Object.freeze({ + __proto__: null, + shimPeerConnection: shimPeerConnection$1, + shimReplaceTrack: shimReplaceTrack, + shimGetUserMedia: shimGetUserMedia$2, + shimGetDisplayMedia: shimGetDisplayMedia$1 + }); + + /* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + function shimGetUserMedia$1(window, browserDetails) { + const navigator = window && window.navigator; + const MediaStreamTrack = window && window.MediaStreamTrack; + + navigator.getUserMedia = function(constraints, onSuccess, onError) { + // Replace Firefox 44+'s deprecation warning with unprefixed version. + deprecated('navigator.getUserMedia', + 'navigator.mediaDevices.getUserMedia'); + navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError); + }; + + if (!(browserDetails.version > 55 && + 'autoGainControl' in navigator.mediaDevices.getSupportedConstraints())) { + const remap = function(obj, a, b) { + if (a in obj && !(b in obj)) { + obj[b] = obj[a]; + delete obj[a]; + } + }; + + const nativeGetUserMedia = navigator.mediaDevices.getUserMedia. + bind(navigator.mediaDevices); + navigator.mediaDevices.getUserMedia = function(c) { + if (typeof c === 'object' && typeof c.audio === 'object') { + c = JSON.parse(JSON.stringify(c)); + remap(c.audio, 'autoGainControl', 'mozAutoGainControl'); + remap(c.audio, 'noiseSuppression', 'mozNoiseSuppression'); + } + return nativeGetUserMedia(c); + }; + + if (MediaStreamTrack && MediaStreamTrack.prototype.getSettings) { + const nativeGetSettings = MediaStreamTrack.prototype.getSettings; + MediaStreamTrack.prototype.getSettings = function() { + const obj = nativeGetSettings.apply(this, arguments); + remap(obj, 'mozAutoGainControl', 'autoGainControl'); + remap(obj, 'mozNoiseSuppression', 'noiseSuppression'); + return obj; + }; + } + + if (MediaStreamTrack && MediaStreamTrack.prototype.applyConstraints) { + const nativeApplyConstraints = + MediaStreamTrack.prototype.applyConstraints; + MediaStreamTrack.prototype.applyConstraints = function(c) { + if (this.kind === 'audio' && typeof c === 'object') { + c = JSON.parse(JSON.stringify(c)); + remap(c, 'autoGainControl', 'mozAutoGainControl'); + remap(c, 'noiseSuppression', 'mozNoiseSuppression'); + } + return nativeApplyConstraints.apply(this, [c]); + }; + } + } + } + + /* + * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + function shimGetDisplayMedia(window, preferredMediaSource) { + if (window.navigator.mediaDevices && + 'getDisplayMedia' in window.navigator.mediaDevices) { + return; + } + if (!(window.navigator.mediaDevices)) { + return; + } + window.navigator.mediaDevices.getDisplayMedia = + function getDisplayMedia(constraints) { + if (!(constraints && constraints.video)) { + const err = new DOMException('getDisplayMedia without video ' + + 'constraints is undefined'); + err.name = 'NotFoundError'; + // from https://heycam.github.io/webidl/#idl-DOMException-error-names + err.code = 8; + return Promise.reject(err); + } + if (constraints.video === true) { + constraints.video = {mediaSource: preferredMediaSource}; + } else { + constraints.video.mediaSource = preferredMediaSource; + } + return window.navigator.mediaDevices.getUserMedia(constraints); + }; + } + + /* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + function shimOnTrack(window) { + if (typeof window === 'object' && window.RTCTrackEvent && + ('receiver' in window.RTCTrackEvent.prototype) && + !('transceiver' in window.RTCTrackEvent.prototype)) { + Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', { + get() { + return {receiver: this.receiver}; + } + }); + } + } + + function shimPeerConnection(window, browserDetails) { + if (typeof window !== 'object' || + !(window.RTCPeerConnection || window.mozRTCPeerConnection)) { + return; // probably media.peerconnection.enabled=false in about:config + } + if (!window.RTCPeerConnection && window.mozRTCPeerConnection) { + // very basic support for old versions. + window.RTCPeerConnection = window.mozRTCPeerConnection; + } + + if (browserDetails.version < 53) { + // shim away need for obsolete RTCIceCandidate/RTCSessionDescription. + ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'] + .forEach(function(method) { + const nativeMethod = window.RTCPeerConnection.prototype[method]; + const methodObj = {[method]() { + arguments[0] = new ((method === 'addIceCandidate') ? + window.RTCIceCandidate : + window.RTCSessionDescription)(arguments[0]); + return nativeMethod.apply(this, arguments); + }}; + window.RTCPeerConnection.prototype[method] = methodObj[method]; + }); + } + + const modernStatsTypes = { + inboundrtp: 'inbound-rtp', + outboundrtp: 'outbound-rtp', + candidatepair: 'candidate-pair', + localcandidate: 'local-candidate', + remotecandidate: 'remote-candidate' + }; + + const nativeGetStats = window.RTCPeerConnection.prototype.getStats; + window.RTCPeerConnection.prototype.getStats = function getStats() { + const [selector, onSucc, onErr] = arguments; + return nativeGetStats.apply(this, [selector || null]) + .then(stats => { + if (browserDetails.version < 53 && !onSucc) { + // Shim only promise getStats with spec-hyphens in type names + // Leave callback version alone; misc old uses of forEach before Map + try { + stats.forEach(stat => { + stat.type = modernStatsTypes[stat.type] || stat.type; + }); + } catch (e) { + if (e.name !== 'TypeError') { + throw e; + } + // Avoid TypeError: "type" is read-only, in old versions. 34-43ish + stats.forEach((stat, i) => { + stats.set(i, Object.assign({}, stat, { + type: modernStatsTypes[stat.type] || stat.type + })); + }); + } + } + return stats; + }) + .then(onSucc, onErr); + }; + } + + function shimSenderGetStats(window) { + if (!(typeof window === 'object' && window.RTCPeerConnection && + window.RTCRtpSender)) { + return; + } + if (window.RTCRtpSender && 'getStats' in window.RTCRtpSender.prototype) { + return; + } + const origGetSenders = window.RTCPeerConnection.prototype.getSenders; + if (origGetSenders) { + window.RTCPeerConnection.prototype.getSenders = function getSenders() { + const senders = origGetSenders.apply(this, []); + senders.forEach(sender => sender._pc = this); + return senders; + }; + } + + const origAddTrack = window.RTCPeerConnection.prototype.addTrack; + if (origAddTrack) { + window.RTCPeerConnection.prototype.addTrack = function addTrack() { + const sender = origAddTrack.apply(this, arguments); + sender._pc = this; + return sender; + }; + } + window.RTCRtpSender.prototype.getStats = function getStats() { + return this.track ? this._pc.getStats(this.track) : + Promise.resolve(new Map()); + }; + } + + function shimReceiverGetStats(window) { + if (!(typeof window === 'object' && window.RTCPeerConnection && + window.RTCRtpSender)) { + return; + } + if (window.RTCRtpSender && 'getStats' in window.RTCRtpReceiver.prototype) { + return; + } + const origGetReceivers = window.RTCPeerConnection.prototype.getReceivers; + if (origGetReceivers) { + window.RTCPeerConnection.prototype.getReceivers = function getReceivers() { + const receivers = origGetReceivers.apply(this, []); + receivers.forEach(receiver => receiver._pc = this); + return receivers; + }; + } + wrapPeerConnectionEvent(window, 'track', e => { + e.receiver._pc = e.srcElement; + return e; + }); + window.RTCRtpReceiver.prototype.getStats = function getStats() { + return this._pc.getStats(this.track); + }; + } + + function shimRemoveStream(window) { + if (!window.RTCPeerConnection || + 'removeStream' in window.RTCPeerConnection.prototype) { + return; + } + window.RTCPeerConnection.prototype.removeStream = + function removeStream(stream) { + deprecated('removeStream', 'removeTrack'); + this.getSenders().forEach(sender => { + if (sender.track && stream.getTracks().includes(sender.track)) { + this.removeTrack(sender); + } + }); + }; + } + + function shimRTCDataChannel(window) { + // rename DataChannel to RTCDataChannel (native fix in FF60): + // https://bugzilla.mozilla.org/show_bug.cgi?id=1173851 + if (window.DataChannel && !window.RTCDataChannel) { + window.RTCDataChannel = window.DataChannel; + } + } + + function shimAddTransceiver(window) { + // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647 + // Firefox ignores the init sendEncodings options passed to addTransceiver + // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918 + if (!(typeof window === 'object' && window.RTCPeerConnection)) { + return; + } + const origAddTransceiver = window.RTCPeerConnection.prototype.addTransceiver; + if (origAddTransceiver) { + window.RTCPeerConnection.prototype.addTransceiver = + function addTransceiver() { + this.setParametersPromises = []; + const initParameters = arguments[1]; + const shouldPerformCheck = initParameters && + 'sendEncodings' in initParameters; + if (shouldPerformCheck) { + // If sendEncodings params are provided, validate grammar + initParameters.sendEncodings.forEach((encodingParam) => { + if ('rid' in encodingParam) { + const ridRegex = /^[a-z0-9]{0,16}$/i; + if (!ridRegex.test(encodingParam.rid)) { + throw new TypeError('Invalid RID value provided.'); + } + } + if ('scaleResolutionDownBy' in encodingParam) { + if (!(parseFloat(encodingParam.scaleResolutionDownBy) >= 1.0)) { + throw new RangeError('scale_resolution_down_by must be >= 1.0'); + } + } + if ('maxFramerate' in encodingParam) { + if (!(parseFloat(encodingParam.maxFramerate) >= 0)) { + throw new RangeError('max_framerate must be >= 0.0'); + } + } + }); + } + const transceiver = origAddTransceiver.apply(this, arguments); + if (shouldPerformCheck) { + // Check if the init options were applied. If not we do this in an + // asynchronous way and save the promise reference in a global object. + // This is an ugly hack, but at the same time is way more robust than + // checking the sender parameters before and after the createOffer + // Also note that after the createoffer we are not 100% sure that + // the params were asynchronously applied so we might miss the + // opportunity to recreate offer. + const {sender} = transceiver; + const params = sender.getParameters(); + if (!('encodings' in params) || + // Avoid being fooled by patched getParameters() below. + (params.encodings.length === 1 && + Object.keys(params.encodings[0]).length === 0)) { + params.encodings = initParameters.sendEncodings; + sender.sendEncodings = initParameters.sendEncodings; + this.setParametersPromises.push(sender.setParameters(params) + .then(() => { + delete sender.sendEncodings; + }).catch(() => { + delete sender.sendEncodings; + }) + ); + } + } + return transceiver; + }; + } + } + + function shimGetParameters(window) { + if (!(typeof window === 'object' && window.RTCRtpSender)) { + return; + } + const origGetParameters = window.RTCRtpSender.prototype.getParameters; + if (origGetParameters) { + window.RTCRtpSender.prototype.getParameters = + function getParameters() { + const params = origGetParameters.apply(this, arguments); + if (!('encodings' in params)) { + params.encodings = [].concat(this.sendEncodings || [{}]); + } + return params; + }; + } + } + + function shimCreateOffer(window) { + // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647 + // Firefox ignores the init sendEncodings options passed to addTransceiver + // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918 + if (!(typeof window === 'object' && window.RTCPeerConnection)) { + return; + } + const origCreateOffer = window.RTCPeerConnection.prototype.createOffer; + window.RTCPeerConnection.prototype.createOffer = function createOffer() { + if (this.setParametersPromises && this.setParametersPromises.length) { + return Promise.all(this.setParametersPromises) + .then(() => { + return origCreateOffer.apply(this, arguments); + }) + .finally(() => { + this.setParametersPromises = []; + }); + } + return origCreateOffer.apply(this, arguments); + }; + } + + function shimCreateAnswer(window) { + // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647 + // Firefox ignores the init sendEncodings options passed to addTransceiver + // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918 + if (!(typeof window === 'object' && window.RTCPeerConnection)) { + return; + } + const origCreateAnswer = window.RTCPeerConnection.prototype.createAnswer; + window.RTCPeerConnection.prototype.createAnswer = function createAnswer() { + if (this.setParametersPromises && this.setParametersPromises.length) { + return Promise.all(this.setParametersPromises) + .then(() => { + return origCreateAnswer.apply(this, arguments); + }) + .finally(() => { + this.setParametersPromises = []; + }); + } + return origCreateAnswer.apply(this, arguments); + }; + } + + var firefoxShim = /*#__PURE__*/Object.freeze({ + __proto__: null, + shimOnTrack: shimOnTrack, + shimPeerConnection: shimPeerConnection, + shimSenderGetStats: shimSenderGetStats, + shimReceiverGetStats: shimReceiverGetStats, + shimRemoveStream: shimRemoveStream, + shimRTCDataChannel: shimRTCDataChannel, + shimAddTransceiver: shimAddTransceiver, + shimGetParameters: shimGetParameters, + shimCreateOffer: shimCreateOffer, + shimCreateAnswer: shimCreateAnswer, + shimGetUserMedia: shimGetUserMedia$1, + shimGetDisplayMedia: shimGetDisplayMedia + }); + + /* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + function shimLocalStreamsAPI(window) { + if (typeof window !== 'object' || !window.RTCPeerConnection) { + return; + } + if (!('getLocalStreams' in window.RTCPeerConnection.prototype)) { + window.RTCPeerConnection.prototype.getLocalStreams = + function getLocalStreams() { + if (!this._localStreams) { + this._localStreams = []; + } + return this._localStreams; + }; + } + if (!('addStream' in window.RTCPeerConnection.prototype)) { + const _addTrack = window.RTCPeerConnection.prototype.addTrack; + window.RTCPeerConnection.prototype.addStream = function addStream(stream) { + if (!this._localStreams) { + this._localStreams = []; + } + if (!this._localStreams.includes(stream)) { + this._localStreams.push(stream); + } + // Try to emulate Chrome's behaviour of adding in audio-video order. + // Safari orders by track id. + stream.getAudioTracks().forEach(track => _addTrack.call(this, track, + stream)); + stream.getVideoTracks().forEach(track => _addTrack.call(this, track, + stream)); + }; + + window.RTCPeerConnection.prototype.addTrack = + function addTrack(track, ...streams) { + if (streams) { + streams.forEach((stream) => { + if (!this._localStreams) { + this._localStreams = [stream]; + } else if (!this._localStreams.includes(stream)) { + this._localStreams.push(stream); + } + }); + } + return _addTrack.apply(this, arguments); + }; + } + if (!('removeStream' in window.RTCPeerConnection.prototype)) { + window.RTCPeerConnection.prototype.removeStream = + function removeStream(stream) { + if (!this._localStreams) { + this._localStreams = []; + } + const index = this._localStreams.indexOf(stream); + if (index === -1) { + return; + } + this._localStreams.splice(index, 1); + const tracks = stream.getTracks(); + this.getSenders().forEach(sender => { + if (tracks.includes(sender.track)) { + this.removeTrack(sender); + } + }); + }; + } + } + + function shimRemoteStreamsAPI(window) { + if (typeof window !== 'object' || !window.RTCPeerConnection) { + return; + } + if (!('getRemoteStreams' in window.RTCPeerConnection.prototype)) { + window.RTCPeerConnection.prototype.getRemoteStreams = + function getRemoteStreams() { + return this._remoteStreams ? this._remoteStreams : []; + }; + } + if (!('onaddstream' in window.RTCPeerConnection.prototype)) { + Object.defineProperty(window.RTCPeerConnection.prototype, 'onaddstream', { + get() { + return this._onaddstream; + }, + set(f) { + if (this._onaddstream) { + this.removeEventListener('addstream', this._onaddstream); + this.removeEventListener('track', this._onaddstreampoly); + } + this.addEventListener('addstream', this._onaddstream = f); + this.addEventListener('track', this._onaddstreampoly = (e) => { + e.streams.forEach(stream => { + if (!this._remoteStreams) { + this._remoteStreams = []; + } + if (this._remoteStreams.includes(stream)) { + return; + } + this._remoteStreams.push(stream); + const event = new Event('addstream'); + event.stream = stream; + this.dispatchEvent(event); + }); + }); + } + }); + const origSetRemoteDescription = + window.RTCPeerConnection.prototype.setRemoteDescription; + window.RTCPeerConnection.prototype.setRemoteDescription = + function setRemoteDescription() { + const pc = this; + if (!this._onaddstreampoly) { + this.addEventListener('track', this._onaddstreampoly = function(e) { + e.streams.forEach(stream => { + if (!pc._remoteStreams) { + pc._remoteStreams = []; + } + if (pc._remoteStreams.indexOf(stream) >= 0) { + return; + } + pc._remoteStreams.push(stream); + const event = new Event('addstream'); + event.stream = stream; + pc.dispatchEvent(event); + }); + }); + } + return origSetRemoteDescription.apply(pc, arguments); + }; + } + } + + function shimCallbacksAPI(window) { + if (typeof window !== 'object' || !window.RTCPeerConnection) { + return; + } + const prototype = window.RTCPeerConnection.prototype; + const origCreateOffer = prototype.createOffer; + const origCreateAnswer = prototype.createAnswer; + const setLocalDescription = prototype.setLocalDescription; + const setRemoteDescription = prototype.setRemoteDescription; + const addIceCandidate = prototype.addIceCandidate; + + prototype.createOffer = + function createOffer(successCallback, failureCallback) { + const options = (arguments.length >= 2) ? arguments[2] : arguments[0]; + const promise = origCreateOffer.apply(this, [options]); + if (!failureCallback) { + return promise; + } + promise.then(successCallback, failureCallback); + return Promise.resolve(); + }; + + prototype.createAnswer = + function createAnswer(successCallback, failureCallback) { + const options = (arguments.length >= 2) ? arguments[2] : arguments[0]; + const promise = origCreateAnswer.apply(this, [options]); + if (!failureCallback) { + return promise; + } + promise.then(successCallback, failureCallback); + return Promise.resolve(); + }; + + let withCallback = function(description, successCallback, failureCallback) { + const promise = setLocalDescription.apply(this, [description]); + if (!failureCallback) { + return promise; + } + promise.then(successCallback, failureCallback); + return Promise.resolve(); + }; + prototype.setLocalDescription = withCallback; + + withCallback = function(description, successCallback, failureCallback) { + const promise = setRemoteDescription.apply(this, [description]); + if (!failureCallback) { + return promise; + } + promise.then(successCallback, failureCallback); + return Promise.resolve(); + }; + prototype.setRemoteDescription = withCallback; + + withCallback = function(candidate, successCallback, failureCallback) { + const promise = addIceCandidate.apply(this, [candidate]); + if (!failureCallback) { + return promise; + } + promise.then(successCallback, failureCallback); + return Promise.resolve(); + }; + prototype.addIceCandidate = withCallback; + } + + function shimGetUserMedia(window) { + const navigator = window && window.navigator; + + if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { + // shim not needed in Safari 12.1 + const mediaDevices = navigator.mediaDevices; + const _getUserMedia = mediaDevices.getUserMedia.bind(mediaDevices); + navigator.mediaDevices.getUserMedia = (constraints) => { + return _getUserMedia(shimConstraints(constraints)); + }; + } + + if (!navigator.getUserMedia && navigator.mediaDevices && + navigator.mediaDevices.getUserMedia) { + navigator.getUserMedia = function getUserMedia(constraints, cb, errcb) { + navigator.mediaDevices.getUserMedia(constraints) + .then(cb, errcb); + }.bind(navigator); + } + } + + function shimConstraints(constraints) { + if (constraints && constraints.video !== undefined) { + return Object.assign({}, + constraints, + {video: compactObject(constraints.video)} + ); + } + + return constraints; + } + + function shimRTCIceServerUrls(window) { + if (!window.RTCPeerConnection) { + return; + } + // migrate from non-spec RTCIceServer.url to RTCIceServer.urls + const OrigPeerConnection = window.RTCPeerConnection; + window.RTCPeerConnection = + function RTCPeerConnection(pcConfig, pcConstraints) { + if (pcConfig && pcConfig.iceServers) { + const newIceServers = []; + for (let i = 0; i < pcConfig.iceServers.length; i++) { + let server = pcConfig.iceServers[i]; + if (!server.hasOwnProperty('urls') && + server.hasOwnProperty('url')) { + deprecated('RTCIceServer.url', 'RTCIceServer.urls'); + server = JSON.parse(JSON.stringify(server)); + server.urls = server.url; + delete server.url; + newIceServers.push(server); + } else { + newIceServers.push(pcConfig.iceServers[i]); + } + } + pcConfig.iceServers = newIceServers; + } + return new OrigPeerConnection(pcConfig, pcConstraints); + }; + window.RTCPeerConnection.prototype = OrigPeerConnection.prototype; + // wrap static methods. Currently just generateCertificate. + if ('generateCertificate' in OrigPeerConnection) { + Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', { + get() { + return OrigPeerConnection.generateCertificate; + } + }); + } + } + + function shimTrackEventTransceiver(window) { + // Add event.transceiver member over deprecated event.receiver + if (typeof window === 'object' && window.RTCTrackEvent && + 'receiver' in window.RTCTrackEvent.prototype && + !('transceiver' in window.RTCTrackEvent.prototype)) { + Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', { + get() { + return {receiver: this.receiver}; + } + }); + } + } + + function shimCreateOfferLegacy(window) { + const origCreateOffer = window.RTCPeerConnection.prototype.createOffer; + window.RTCPeerConnection.prototype.createOffer = + function createOffer(offerOptions) { + if (offerOptions) { + if (typeof offerOptions.offerToReceiveAudio !== 'undefined') { + // support bit values + offerOptions.offerToReceiveAudio = + !!offerOptions.offerToReceiveAudio; + } + const audioTransceiver = this.getTransceivers().find(transceiver => + transceiver.receiver.track.kind === 'audio'); + if (offerOptions.offerToReceiveAudio === false && audioTransceiver) { + if (audioTransceiver.direction === 'sendrecv') { + if (audioTransceiver.setDirection) { + audioTransceiver.setDirection('sendonly'); + } else { + audioTransceiver.direction = 'sendonly'; + } + } else if (audioTransceiver.direction === 'recvonly') { + if (audioTransceiver.setDirection) { + audioTransceiver.setDirection('inactive'); + } else { + audioTransceiver.direction = 'inactive'; + } + } + } else if (offerOptions.offerToReceiveAudio === true && + !audioTransceiver) { + this.addTransceiver('audio'); + } + + if (typeof offerOptions.offerToReceiveVideo !== 'undefined') { + // support bit values + offerOptions.offerToReceiveVideo = + !!offerOptions.offerToReceiveVideo; + } + const videoTransceiver = this.getTransceivers().find(transceiver => + transceiver.receiver.track.kind === 'video'); + if (offerOptions.offerToReceiveVideo === false && videoTransceiver) { + if (videoTransceiver.direction === 'sendrecv') { + if (videoTransceiver.setDirection) { + videoTransceiver.setDirection('sendonly'); + } else { + videoTransceiver.direction = 'sendonly'; + } + } else if (videoTransceiver.direction === 'recvonly') { + if (videoTransceiver.setDirection) { + videoTransceiver.setDirection('inactive'); + } else { + videoTransceiver.direction = 'inactive'; + } + } + } else if (offerOptions.offerToReceiveVideo === true && + !videoTransceiver) { + this.addTransceiver('video'); + } + } + return origCreateOffer.apply(this, arguments); + }; + } + + function shimAudioContext(window) { + if (typeof window !== 'object' || window.AudioContext) { + return; + } + window.AudioContext = window.webkitAudioContext; + } + + var safariShim = /*#__PURE__*/Object.freeze({ + __proto__: null, + shimLocalStreamsAPI: shimLocalStreamsAPI, + shimRemoteStreamsAPI: shimRemoteStreamsAPI, + shimCallbacksAPI: shimCallbacksAPI, + shimGetUserMedia: shimGetUserMedia, + shimConstraints: shimConstraints, + shimRTCIceServerUrls: shimRTCIceServerUrls, + shimTrackEventTransceiver: shimTrackEventTransceiver, + shimCreateOfferLegacy: shimCreateOfferLegacy, + shimAudioContext: shimAudioContext + }); + + /* + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + function shimRTCIceCandidate(window) { + // foundation is arbitrarily chosen as an indicator for full support for + // https://w3c.github.io/webrtc-pc/#rtcicecandidate-interface + if (!window.RTCIceCandidate || (window.RTCIceCandidate && 'foundation' in + window.RTCIceCandidate.prototype)) { + return; + } + + const NativeRTCIceCandidate = window.RTCIceCandidate; + window.RTCIceCandidate = function RTCIceCandidate(args) { + // Remove the a= which shouldn't be part of the candidate string. + if (typeof args === 'object' && args.candidate && + args.candidate.indexOf('a=') === 0) { + args = JSON.parse(JSON.stringify(args)); + args.candidate = args.candidate.substr(2); + } + + if (args.candidate && args.candidate.length) { + // Augment the native candidate with the parsed fields. + const nativeCandidate = new NativeRTCIceCandidate(args); + const parsedCandidate = sdp.parseCandidate(args.candidate); + const augmentedCandidate = Object.assign(nativeCandidate, + parsedCandidate); + + // Add a serializer that does not serialize the extra attributes. + augmentedCandidate.toJSON = function toJSON() { + return { + candidate: augmentedCandidate.candidate, + sdpMid: augmentedCandidate.sdpMid, + sdpMLineIndex: augmentedCandidate.sdpMLineIndex, + usernameFragment: augmentedCandidate.usernameFragment, + }; + }; + return augmentedCandidate; + } + return new NativeRTCIceCandidate(args); + }; + window.RTCIceCandidate.prototype = NativeRTCIceCandidate.prototype; + + // Hook up the augmented candidate in onicecandidate and + // addEventListener('icecandidate', ...) + wrapPeerConnectionEvent(window, 'icecandidate', e => { + if (e.candidate) { + Object.defineProperty(e, 'candidate', { + value: new window.RTCIceCandidate(e.candidate), + writable: 'false' + }); + } + return e; + }); + } + + function shimMaxMessageSize(window, browserDetails) { + if (!window.RTCPeerConnection) { + return; + } + + if (!('sctp' in window.RTCPeerConnection.prototype)) { + Object.defineProperty(window.RTCPeerConnection.prototype, 'sctp', { + get() { + return typeof this._sctp === 'undefined' ? null : this._sctp; + } + }); + } + + const sctpInDescription = function(description) { + if (!description || !description.sdp) { + return false; + } + const sections = sdp.splitSections(description.sdp); + sections.shift(); + return sections.some(mediaSection => { + const mLine = sdp.parseMLine(mediaSection); + return mLine && mLine.kind === 'application' + && mLine.protocol.indexOf('SCTP') !== -1; + }); + }; + + const getRemoteFirefoxVersion = function(description) { + // TODO: Is there a better solution for detecting Firefox? + const match = description.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/); + if (match === null || match.length < 2) { + return -1; + } + const version = parseInt(match[1], 10); + // Test for NaN (yes, this is ugly) + return version !== version ? -1 : version; + }; + + const getCanSendMaxMessageSize = function(remoteIsFirefox) { + // Every implementation we know can send at least 64 KiB. + // Note: Although Chrome is technically able to send up to 256 KiB, the + // data does not reach the other peer reliably. + // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=8419 + let canSendMaxMessageSize = 65536; + if (browserDetails.browser === 'firefox') { + if (browserDetails.version < 57) { + if (remoteIsFirefox === -1) { + // FF < 57 will send in 16 KiB chunks using the deprecated PPID + // fragmentation. + canSendMaxMessageSize = 16384; + } else { + // However, other FF (and RAWRTC) can reassemble PPID-fragmented + // messages. Thus, supporting ~2 GiB when sending. + canSendMaxMessageSize = 2147483637; + } + } else if (browserDetails.version < 60) { + // Currently, all FF >= 57 will reset the remote maximum message size + // to the default value when a data channel is created at a later + // stage. :( + // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1426831 + canSendMaxMessageSize = + browserDetails.version === 57 ? 65535 : 65536; + } else { + // FF >= 60 supports sending ~2 GiB + canSendMaxMessageSize = 2147483637; + } + } + return canSendMaxMessageSize; + }; + + const getMaxMessageSize = function(description, remoteIsFirefox) { + // Note: 65536 bytes is the default value from the SDP spec. Also, + // every implementation we know supports receiving 65536 bytes. + let maxMessageSize = 65536; + + // FF 57 has a slightly incorrect default remote max message size, so + // we need to adjust it here to avoid a failure when sending. + // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1425697 + if (browserDetails.browser === 'firefox' + && browserDetails.version === 57) { + maxMessageSize = 65535; + } + + const match = sdp.matchPrefix(description.sdp, + 'a=max-message-size:'); + if (match.length > 0) { + maxMessageSize = parseInt(match[0].substr(19), 10); + } else if (browserDetails.browser === 'firefox' && + remoteIsFirefox !== -1) { + // If the maximum message size is not present in the remote SDP and + // both local and remote are Firefox, the remote peer can receive + // ~2 GiB. + maxMessageSize = 2147483637; + } + return maxMessageSize; + }; + + const origSetRemoteDescription = + window.RTCPeerConnection.prototype.setRemoteDescription; + window.RTCPeerConnection.prototype.setRemoteDescription = + function setRemoteDescription() { + this._sctp = null; + // Chrome decided to not expose .sctp in plan-b mode. + // As usual, adapter.js has to do an 'ugly worakaround' + // to cover up the mess. + if (browserDetails.browser === 'chrome' && browserDetails.version >= 76) { + const {sdpSemantics} = this.getConfiguration(); + if (sdpSemantics === 'plan-b') { + Object.defineProperty(this, 'sctp', { + get() { + return typeof this._sctp === 'undefined' ? null : this._sctp; + }, + enumerable: true, + configurable: true, + }); + } + } + + if (sctpInDescription(arguments[0])) { + // Check if the remote is FF. + const isFirefox = getRemoteFirefoxVersion(arguments[0]); + + // Get the maximum message size the local peer is capable of sending + const canSendMMS = getCanSendMaxMessageSize(isFirefox); + + // Get the maximum message size of the remote peer. + const remoteMMS = getMaxMessageSize(arguments[0], isFirefox); + + // Determine final maximum message size + let maxMessageSize; + if (canSendMMS === 0 && remoteMMS === 0) { + maxMessageSize = Number.POSITIVE_INFINITY; + } else if (canSendMMS === 0 || remoteMMS === 0) { + maxMessageSize = Math.max(canSendMMS, remoteMMS); + } else { + maxMessageSize = Math.min(canSendMMS, remoteMMS); + } + + // Create a dummy RTCSctpTransport object and the 'maxMessageSize' + // attribute. + const sctp = {}; + Object.defineProperty(sctp, 'maxMessageSize', { + get() { + return maxMessageSize; + } + }); + this._sctp = sctp; + } + + return origSetRemoteDescription.apply(this, arguments); + }; + } + + function shimSendThrowTypeError(window) { + if (!(window.RTCPeerConnection && + 'createDataChannel' in window.RTCPeerConnection.prototype)) { + return; + } + + // Note: Although Firefox >= 57 has a native implementation, the maximum + // message size can be reset for all data channels at a later stage. + // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1426831 + + function wrapDcSend(dc, pc) { + const origDataChannelSend = dc.send; + dc.send = function send() { + const data = arguments[0]; + const length = data.length || data.size || data.byteLength; + if (dc.readyState === 'open' && + pc.sctp && length > pc.sctp.maxMessageSize) { + throw new TypeError('Message too large (can send a maximum of ' + + pc.sctp.maxMessageSize + ' bytes)'); + } + return origDataChannelSend.apply(dc, arguments); + }; + } + const origCreateDataChannel = + window.RTCPeerConnection.prototype.createDataChannel; + window.RTCPeerConnection.prototype.createDataChannel = + function createDataChannel() { + const dataChannel = origCreateDataChannel.apply(this, arguments); + wrapDcSend(dataChannel, this); + return dataChannel; + }; + wrapPeerConnectionEvent(window, 'datachannel', e => { + wrapDcSend(e.channel, e.target); + return e; + }); + } + + + /* shims RTCConnectionState by pretending it is the same as iceConnectionState. + * See https://bugs.chromium.org/p/webrtc/issues/detail?id=6145#c12 + * for why this is a valid hack in Chrome. In Firefox it is slightly incorrect + * since DTLS failures would be hidden. See + * https://bugzilla.mozilla.org/show_bug.cgi?id=1265827 + * for the Firefox tracking bug. + */ + function shimConnectionState(window) { + if (!window.RTCPeerConnection || + 'connectionState' in window.RTCPeerConnection.prototype) { + return; + } + const proto = window.RTCPeerConnection.prototype; + Object.defineProperty(proto, 'connectionState', { + get() { + return { + completed: 'connected', + checking: 'connecting' + }[this.iceConnectionState] || this.iceConnectionState; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(proto, 'onconnectionstatechange', { + get() { + return this._onconnectionstatechange || null; + }, + set(cb) { + if (this._onconnectionstatechange) { + this.removeEventListener('connectionstatechange', + this._onconnectionstatechange); + delete this._onconnectionstatechange; + } + if (cb) { + this.addEventListener('connectionstatechange', + this._onconnectionstatechange = cb); + } + }, + enumerable: true, + configurable: true + }); + + ['setLocalDescription', 'setRemoteDescription'].forEach((method) => { + const origMethod = proto[method]; + proto[method] = function() { + if (!this._connectionstatechangepoly) { + this._connectionstatechangepoly = e => { + const pc = e.target; + if (pc._lastConnectionState !== pc.connectionState) { + pc._lastConnectionState = pc.connectionState; + const newEvent = new Event('connectionstatechange', e); + pc.dispatchEvent(newEvent); + } + return e; + }; + this.addEventListener('iceconnectionstatechange', + this._connectionstatechangepoly); + } + return origMethod.apply(this, arguments); + }; + }); + } + + function removeExtmapAllowMixed(window, browserDetails) { + /* remove a=extmap-allow-mixed for webrtc.org < M71 */ + if (!window.RTCPeerConnection) { + return; + } + if (browserDetails.browser === 'chrome' && browserDetails.version >= 71) { + return; + } + if (browserDetails.browser === 'safari' && browserDetails.version >= 605) { + return; + } + const nativeSRD = window.RTCPeerConnection.prototype.setRemoteDescription; + window.RTCPeerConnection.prototype.setRemoteDescription = + function setRemoteDescription(desc) { + if (desc && desc.sdp && desc.sdp.indexOf('\na=extmap-allow-mixed') !== -1) { + const sdp = desc.sdp.split('\n').filter((line) => { + return line.trim() !== 'a=extmap-allow-mixed'; + }).join('\n'); + // Safari enforces read-only-ness of RTCSessionDescription fields. + if (window.RTCSessionDescription && + desc instanceof window.RTCSessionDescription) { + arguments[0] = new window.RTCSessionDescription({ + type: desc.type, + sdp, + }); + } else { + desc.sdp = sdp; + } + } + return nativeSRD.apply(this, arguments); + }; + } + + function shimAddIceCandidateNullOrEmpty(window, browserDetails) { + // Support for addIceCandidate(null or undefined) + // as well as addIceCandidate({candidate: "", ...}) + // https://bugs.chromium.org/p/chromium/issues/detail?id=978582 + // Note: must be called before other polyfills which change the signature. + if (!(window.RTCPeerConnection && window.RTCPeerConnection.prototype)) { + return; + } + const nativeAddIceCandidate = + window.RTCPeerConnection.prototype.addIceCandidate; + if (!nativeAddIceCandidate || nativeAddIceCandidate.length === 0) { + return; + } + window.RTCPeerConnection.prototype.addIceCandidate = + function addIceCandidate() { + if (!arguments[0]) { + if (arguments[1]) { + arguments[1].apply(null); + } + return Promise.resolve(); + } + // Firefox 68+ emits and processes {candidate: "", ...}, ignore + // in older versions. + // Native support for ignoring exists for Chrome M77+. + // Safari ignores as well, exact version unknown but works in the same + // version that also ignores addIceCandidate(null). + if (((browserDetails.browser === 'chrome' && browserDetails.version < 78) + || (browserDetails.browser === 'firefox' + && browserDetails.version < 68) + || (browserDetails.browser === 'safari')) + && arguments[0] && arguments[0].candidate === '') { + return Promise.resolve(); + } + return nativeAddIceCandidate.apply(this, arguments); + }; + } + + var commonShim = /*#__PURE__*/Object.freeze({ + __proto__: null, + shimRTCIceCandidate: shimRTCIceCandidate, + shimMaxMessageSize: shimMaxMessageSize, + shimSendThrowTypeError: shimSendThrowTypeError, + shimConnectionState: shimConnectionState, + removeExtmapAllowMixed: removeExtmapAllowMixed, + shimAddIceCandidateNullOrEmpty: shimAddIceCandidateNullOrEmpty + }); + + /* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + // Shimming starts here. + function adapterFactory({window} = {}, options = { + shimChrome: true, + shimFirefox: true, + shimEdge: true, + shimSafari: true, + }) { + // Utils. + const logging = log$1; + const browserDetails = detectBrowser(window); + + const adapter = { + browserDetails, + commonShim, + extractVersion: extractVersion, + disableLog: disableLog, + disableWarnings: disableWarnings + }; + + // Shim browser if found. + switch (browserDetails.browser) { + case 'chrome': + if (!chromeShim || !shimPeerConnection$2 || + !options.shimChrome) { + logging('Chrome shim is not included in this adapter release.'); + return adapter; + } + if (browserDetails.version === null) { + logging('Chrome shim can not determine version, not shimming.'); + return adapter; + } + logging('adapter.js shimming chrome.'); + // Export to the adapter global object visible in the browser. + adapter.browserShim = chromeShim; + + // Must be called before shimPeerConnection. + shimAddIceCandidateNullOrEmpty(window, browserDetails); + + shimGetUserMedia$3(window, browserDetails); + shimMediaStream(window); + shimPeerConnection$2(window, browserDetails); + shimOnTrack$1(window); + shimAddTrackRemoveTrack(window, browserDetails); + shimGetSendersWithDtmf(window); + shimGetStats(window); + shimSenderReceiverGetStats(window); + fixNegotiationNeeded(window, browserDetails); + + shimRTCIceCandidate(window); + shimConnectionState(window); + shimMaxMessageSize(window, browserDetails); + shimSendThrowTypeError(window); + removeExtmapAllowMixed(window, browserDetails); + break; + case 'firefox': + if (!firefoxShim || !shimPeerConnection || + !options.shimFirefox) { + logging('Firefox shim is not included in this adapter release.'); + return adapter; + } + logging('adapter.js shimming firefox.'); + // Export to the adapter global object visible in the browser. + adapter.browserShim = firefoxShim; + + // Must be called before shimPeerConnection. + shimAddIceCandidateNullOrEmpty(window, browserDetails); + + shimGetUserMedia$1(window, browserDetails); + shimPeerConnection(window, browserDetails); + shimOnTrack(window); + shimRemoveStream(window); + shimSenderGetStats(window); + shimReceiverGetStats(window); + shimRTCDataChannel(window); + shimAddTransceiver(window); + shimGetParameters(window); + shimCreateOffer(window); + shimCreateAnswer(window); + + shimRTCIceCandidate(window); + shimConnectionState(window); + shimMaxMessageSize(window, browserDetails); + shimSendThrowTypeError(window); + break; + case 'edge': + if (!edgeShim || !shimPeerConnection$1 || !options.shimEdge) { + logging('MS edge shim is not included in this adapter release.'); + return adapter; + } + logging('adapter.js shimming edge.'); + // Export to the adapter global object visible in the browser. + adapter.browserShim = edgeShim; + + shimGetUserMedia$2(window); + shimGetDisplayMedia$1(window); + shimPeerConnection$1(window, browserDetails); + shimReplaceTrack(window); + + // the edge shim implements the full RTCIceCandidate object. + + shimMaxMessageSize(window, browserDetails); + shimSendThrowTypeError(window); + break; + case 'safari': + if (!safariShim || !options.shimSafari) { + logging('Safari shim is not included in this adapter release.'); + return adapter; + } + logging('adapter.js shimming safari.'); + // Export to the adapter global object visible in the browser. + adapter.browserShim = safariShim; + + // Must be called before shimCallbackAPI. + shimAddIceCandidateNullOrEmpty(window, browserDetails); + + shimRTCIceServerUrls(window); + shimCreateOfferLegacy(window); + shimCallbacksAPI(window); + shimLocalStreamsAPI(window); + shimRemoteStreamsAPI(window); + shimTrackEventTransceiver(window); + shimGetUserMedia(window); + shimAudioContext(window); + + shimRTCIceCandidate(window); + shimMaxMessageSize(window, browserDetails); + shimSendThrowTypeError(window); + removeExtmapAllowMixed(window, browserDetails); + break; + default: + logging('Unsupported browser!'); + break; + } + + return adapter; + } + + /* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. + */ + + adapterFactory({window: typeof window === 'undefined' ? undefined : window}); + + /** + * @class AudioTrackConstraints + * @classDesc Constraints for creating an audio MediaStreamTrack. + * @memberof Owt.Base + * @constructor + * @param {Owt.Base.AudioSourceInfo} source Source info of this audio track. + */ + + class AudioTrackConstraints { + // eslint-disable-next-line require-jsdoc + constructor(source) { + if (!Object.values(AudioSourceInfo).some(v => v === source)) { + throw new TypeError('Invalid source.'); + } + /** + * @member {string} source + * @memberof Owt.Base.AudioTrackConstraints + * @desc Values could be "mic", "screen-cast", "file" or "mixed". + * @instance + */ + + + this.source = source; + /** + * @member {string} deviceId + * @memberof Owt.Base.AudioTrackConstraints + * @desc Do not provide deviceId if source is not "mic". + * @instance + * @see https://w3c.github.io/mediacapture-main/#def-constraint-deviceId + */ + + this.deviceId = undefined; + } + + } + /** + * @class VideoTrackConstraints + * @classDesc Constraints for creating a video MediaStreamTrack. + * @memberof Owt.Base + * @constructor + * @param {Owt.Base.VideoSourceInfo} source Source info of this video track. + */ + + class VideoTrackConstraints { + // eslint-disable-next-line require-jsdoc + constructor(source) { + if (!Object.values(VideoSourceInfo).some(v => v === source)) { + throw new TypeError('Invalid source.'); + } + /** + * @member {string} source + * @memberof Owt.Base.VideoTrackConstraints + * @desc Values could be "camera", "screen-cast", "file" or "mixed". + * @instance + */ + + + this.source = source; + /** + * @member {string} deviceId + * @memberof Owt.Base.VideoTrackConstraints + * @desc Do not provide deviceId if source is not "camera". + * @instance + * @see https://w3c.github.io/mediacapture-main/#def-constraint-deviceId + */ + + this.deviceId = undefined; + /** + * @member {Owt.Base.Resolution} resolution + * @memberof Owt.Base.VideoTrackConstraints + * @instance + */ + + this.resolution = undefined; + /** + * @member {number} frameRate + * @memberof Owt.Base.VideoTrackConstraints + * @instance + */ + + this.frameRate = undefined; + } + + } + /** + * @class StreamConstraints + * @classDesc Constraints for creating a MediaStream from screen mic and camera. + * @memberof Owt.Base + * @constructor + * @param {?Owt.Base.AudioTrackConstraints} audioConstraints + * @param {?Owt.Base.VideoTrackConstraints} videoConstraints + */ + + class StreamConstraints { + // eslint-disable-next-line require-jsdoc + constructor(audioConstraints = false, videoConstraints = false) { + /** + * @member {Owt.Base.MediaStreamTrackDeviceConstraintsForAudio} audio + * @memberof Owt.Base.MediaStreamDeviceConstraints + * @instance + */ + this.audio = audioConstraints; + /** + * @member {Owt.Base.MediaStreamTrackDeviceConstraintsForVideo} Video + * @memberof Owt.Base.MediaStreamDeviceConstraints + * @instance + */ + + this.video = videoConstraints; + } + + } // eslint-disable-next-line require-jsdoc + + function isVideoConstrainsForScreenCast(constraints) { + return typeof constraints.video === 'object' && constraints.video.source === VideoSourceInfo.SCREENCAST; + } + /** + * @class MediaStreamFactory + * @classDesc A factory to create MediaStream. You can also create MediaStream by yourself. + * @memberof Owt.Base + */ + + + class MediaStreamFactory { + /** + * @function createMediaStream + * @static + * @desc Create a MediaStream with given constraints. If you want to create a MediaStream for screen cast, please make sure both audio and video's source are "screen-cast". + * @memberof Owt.Base.MediaStreamFactory + * @return {Promise} Return a promise that is resolved when stream is successfully created, or rejected if one of the following error happened: + * - One or more parameters cannot be satisfied. + * - Specified device is busy. + * - Cannot obtain necessary permission or operation is canceled by user. + * - Video source is screen cast, while audio source is not. + * - Audio source is screen cast, while video source is disabled. + * @param {Owt.Base.StreamConstraints} constraints + */ + static createMediaStream(constraints) { + if (typeof constraints !== 'object' || !constraints.audio && !constraints.video) { + return Promise.reject(new TypeError('Invalid constrains')); + } + + if (!isVideoConstrainsForScreenCast(constraints) && typeof constraints.audio === 'object' && constraints.audio.source === AudioSourceInfo.SCREENCAST) { + return Promise.reject(new TypeError('Cannot share screen without video.')); + } + + if (isVideoConstrainsForScreenCast(constraints) && !isChrome() && !isFirefox()) { + return Promise.reject(new TypeError('Screen sharing only supports Chrome and Firefox.')); + } + + if (isVideoConstrainsForScreenCast(constraints) && typeof constraints.audio === 'object' && constraints.audio.source !== AudioSourceInfo.SCREENCAST) { + return Promise.reject(new TypeError('Cannot capture video from screen cast while capture audio from' + ' other source.')); + } // Check and convert constraints. + + + if (!constraints.audio && !constraints.video) { + return Promise.reject(new TypeError('At least one of audio and video must be requested.')); + } + + const mediaConstraints = Object.create({}); + + if (typeof constraints.audio === 'object' && constraints.audio.source === AudioSourceInfo.MIC) { + mediaConstraints.audio = Object.create({}); + + if (isEdge()) { + mediaConstraints.audio.deviceId = constraints.audio.deviceId; + } else { + mediaConstraints.audio.deviceId = { + exact: constraints.audio.deviceId + }; + } + } else { + if (constraints.audio.source === AudioSourceInfo.SCREENCAST) { + mediaConstraints.audio = true; + } else { + mediaConstraints.audio = constraints.audio; + } + } + + if (typeof constraints.video === 'object') { + mediaConstraints.video = Object.create({}); + + if (typeof constraints.video.frameRate === 'number') { + mediaConstraints.video.frameRate = constraints.video.frameRate; + } + + if (constraints.video.resolution && constraints.video.resolution.width && constraints.video.resolution.height) { + if (constraints.video.source === VideoSourceInfo.SCREENCAST) { + mediaConstraints.video.width = constraints.video.resolution.width; + mediaConstraints.video.height = constraints.video.resolution.height; + } else { + mediaConstraints.video.width = Object.create({}); + mediaConstraints.video.width.exact = constraints.video.resolution.width; + mediaConstraints.video.height = Object.create({}); + mediaConstraints.video.height.exact = constraints.video.resolution.height; + } + } + + if (typeof constraints.video.deviceId === 'string') { + mediaConstraints.video.deviceId = { + exact: constraints.video.deviceId + }; + } + + if (isFirefox() && constraints.video.source === VideoSourceInfo.SCREENCAST) { + mediaConstraints.video.mediaSource = 'screen'; + } + } else { + mediaConstraints.video = constraints.video; + } + + if (isVideoConstrainsForScreenCast(constraints)) { + return navigator.mediaDevices.getDisplayMedia(mediaConstraints); + } else { + return navigator.mediaDevices.getUserMedia(mediaConstraints); + } + } + + } + + // Copyright (C) <2018> Intel Corporation + + var media = /*#__PURE__*/Object.freeze({ + __proto__: null, + AudioTrackConstraints: AudioTrackConstraints, + VideoTrackConstraints: VideoTrackConstraints, + StreamConstraints: StreamConstraints, + MediaStreamFactory: MediaStreamFactory, + AudioSourceInfo: AudioSourceInfo, + VideoSourceInfo: VideoSourceInfo, + TrackKind: TrackKind, + Resolution: Resolution + }); + + let logger; + let errorLogger; + function setLogger() { + /*eslint-disable */ + logger = console.log; + errorLogger = console.error; + /*eslint-enable */ + } + function log(message, ...optionalParams) { + if (logger) { + logger(message, ...optionalParams); + } + } + function error(message, ...optionalParams) { + if (errorLogger) { + errorLogger(message, ...optionalParams); + } + } + + class Event$1 { + constructor(type) { + this.listener = {}; + this.type = type | ''; + } + + on(event, fn) { + if (!this.listener[event]) { + this.listener[event] = []; + } + + this.listener[event].push(fn); + return true; + } + + off(event, fn) { + if (this.listener[event]) { + var index = this.listener[event].indexOf(fn); + + if (index > -1) { + this.listener[event].splice(index, 1); + } + + return true; + } + + return false; + } + + offAll() { + this.listener = {}; + } + + dispatch(event, data) { + if (this.listener[event]) { + this.listener[event].map(each => { + each.apply(null, [data]); + }); + return true; + } + + return false; + } + + } + + var bind = function bind(fn, thisArg) { + return function wrap() { + var args = new Array(arguments.length); + for (var i = 0; i < args.length; i++) { + args[i] = arguments[i]; + } + return fn.apply(thisArg, args); + }; + }; + + /*global toString:true*/ + + // utils is a library of generic helper functions non-specific to axios + + var toString = Object.prototype.toString; + + /** + * Determine if a value is an Array + * + * @param {Object} val The value to test + * @returns {boolean} True if value is an Array, otherwise false + */ + function isArray(val) { + return toString.call(val) === '[object Array]'; + } + + /** + * Determine if a value is undefined + * + * @param {Object} val The value to test + * @returns {boolean} True if the value is undefined, otherwise false + */ + function isUndefined(val) { + return typeof val === 'undefined'; + } + + /** + * Determine if a value is a Buffer + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a Buffer, otherwise false + */ + function isBuffer(val) { + return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor) + && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val); + } + + /** + * Determine if a value is an ArrayBuffer + * + * @param {Object} val The value to test + * @returns {boolean} True if value is an ArrayBuffer, otherwise false + */ + function isArrayBuffer(val) { + return toString.call(val) === '[object ArrayBuffer]'; + } + + /** + * Determine if a value is a FormData + * + * @param {Object} val The value to test + * @returns {boolean} True if value is an FormData, otherwise false + */ + function isFormData(val) { + return (typeof FormData !== 'undefined') && (val instanceof FormData); + } + + /** + * Determine if a value is a view on an ArrayBuffer + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false + */ + function isArrayBufferView(val) { + var result; + if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) { + result = ArrayBuffer.isView(val); + } else { + result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer); + } + return result; + } + + /** + * Determine if a value is a String + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a String, otherwise false + */ + function isString(val) { + return typeof val === 'string'; + } + + /** + * Determine if a value is a Number + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a Number, otherwise false + */ + function isNumber(val) { + return typeof val === 'number'; + } + + /** + * Determine if a value is an Object + * + * @param {Object} val The value to test + * @returns {boolean} True if value is an Object, otherwise false + */ + function isObject(val) { + return val !== null && typeof val === 'object'; + } + + /** + * Determine if a value is a plain Object + * + * @param {Object} val The value to test + * @return {boolean} True if value is a plain Object, otherwise false + */ + function isPlainObject(val) { + if (toString.call(val) !== '[object Object]') { + return false; + } + + var prototype = Object.getPrototypeOf(val); + return prototype === null || prototype === Object.prototype; + } + + /** + * Determine if a value is a Date + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a Date, otherwise false + */ + function isDate(val) { + return toString.call(val) === '[object Date]'; + } + + /** + * Determine if a value is a File + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a File, otherwise false + */ + function isFile(val) { + return toString.call(val) === '[object File]'; + } + + /** + * Determine if a value is a Blob + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a Blob, otherwise false + */ + function isBlob(val) { + return toString.call(val) === '[object Blob]'; + } + + /** + * Determine if a value is a Function + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a Function, otherwise false + */ + function isFunction(val) { + return toString.call(val) === '[object Function]'; + } + + /** + * Determine if a value is a Stream + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a Stream, otherwise false + */ + function isStream(val) { + return isObject(val) && isFunction(val.pipe); + } + + /** + * Determine if a value is a URLSearchParams object + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a URLSearchParams object, otherwise false + */ + function isURLSearchParams(val) { + return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams; + } + + /** + * Trim excess whitespace off the beginning and end of a string + * + * @param {String} str The String to trim + * @returns {String} The String freed of excess whitespace + */ + function trim(str) { + return str.replace(/^\s*/, '').replace(/\s*$/, ''); + } + + /** + * Determine if we're running in a standard browser environment + * + * This allows axios to run in a web worker, and react-native. + * Both environments support XMLHttpRequest, but not fully standard globals. + * + * web workers: + * typeof window -> undefined + * typeof document -> undefined + * + * react-native: + * navigator.product -> 'ReactNative' + * nativescript + * navigator.product -> 'NativeScript' or 'NS' + */ + function isStandardBrowserEnv() { + if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' || + navigator.product === 'NativeScript' || + navigator.product === 'NS')) { + return false; + } + return ( + typeof window !== 'undefined' && + typeof document !== 'undefined' + ); + } + + /** + * Iterate over an Array or an Object invoking a function for each item. + * + * If `obj` is an Array callback will be called passing + * the value, index, and complete array for each item. + * + * If 'obj' is an Object callback will be called passing + * the value, key, and complete object for each property. + * + * @param {Object|Array} obj The object to iterate + * @param {Function} fn The callback to invoke for each item + */ + function forEach(obj, fn) { + // Don't bother if no value provided + if (obj === null || typeof obj === 'undefined') { + return; + } + + // Force an array if not already something iterable + if (typeof obj !== 'object') { + /*eslint no-param-reassign:0*/ + obj = [obj]; + } + + if (isArray(obj)) { + // Iterate over array values + for (var i = 0, l = obj.length; i < l; i++) { + fn.call(null, obj[i], i, obj); + } + } else { + // Iterate over object keys + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) { + fn.call(null, obj[key], key, obj); + } + } + } + } + + /** + * Accepts varargs expecting each argument to be an object, then + * immutably merges the properties of each object and returns result. + * + * When multiple objects contain the same key the later object in + * the arguments list will take precedence. + * + * Example: + * + * ```js + * var result = merge({foo: 123}, {foo: 456}); + * console.log(result.foo); // outputs 456 + * ``` + * + * @param {Object} obj1 Object to merge + * @returns {Object} Result of all merge properties + */ + function merge(/* obj1, obj2, obj3, ... */) { + var result = {}; + function assignValue(val, key) { + if (isPlainObject(result[key]) && isPlainObject(val)) { + result[key] = merge(result[key], val); + } else if (isPlainObject(val)) { + result[key] = merge({}, val); + } else if (isArray(val)) { + result[key] = val.slice(); + } else { + result[key] = val; + } + } + + for (var i = 0, l = arguments.length; i < l; i++) { + forEach(arguments[i], assignValue); + } + return result; + } + + /** + * Extends object a by mutably adding to it the properties of object b. + * + * @param {Object} a The object to be extended + * @param {Object} b The object to copy properties from + * @param {Object} thisArg The object to bind function to + * @return {Object} The resulting value of object a + */ + function extend(a, b, thisArg) { + forEach(b, function assignValue(val, key) { + if (thisArg && typeof val === 'function') { + a[key] = bind(val, thisArg); + } else { + a[key] = val; + } + }); + return a; + } + + /** + * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM) + * + * @param {string} content with BOM + * @return {string} content value without BOM + */ + function stripBOM(content) { + if (content.charCodeAt(0) === 0xFEFF) { + content = content.slice(1); + } + return content; + } + + var utils = { + isArray: isArray, + isArrayBuffer: isArrayBuffer, + isBuffer: isBuffer, + isFormData: isFormData, + isArrayBufferView: isArrayBufferView, + isString: isString, + isNumber: isNumber, + isObject: isObject, + isPlainObject: isPlainObject, + isUndefined: isUndefined, + isDate: isDate, + isFile: isFile, + isBlob: isBlob, + isFunction: isFunction, + isStream: isStream, + isURLSearchParams: isURLSearchParams, + isStandardBrowserEnv: isStandardBrowserEnv, + forEach: forEach, + merge: merge, + extend: extend, + trim: trim, + stripBOM: stripBOM + }; + + function encode(val) { + return encodeURIComponent(val). + replace(/%3A/gi, ':'). + replace(/%24/g, '$'). + replace(/%2C/gi, ','). + replace(/%20/g, '+'). + replace(/%5B/gi, '['). + replace(/%5D/gi, ']'); + } + + /** + * Build a URL by appending params to the end + * + * @param {string} url The base of the url (e.g., http://www.google.com) + * @param {object} [params] The params to be appended + * @returns {string} The formatted url + */ + var buildURL = function buildURL(url, params, paramsSerializer) { + /*eslint no-param-reassign:0*/ + if (!params) { + return url; + } + + var serializedParams; + if (paramsSerializer) { + serializedParams = paramsSerializer(params); + } else if (utils.isURLSearchParams(params)) { + serializedParams = params.toString(); + } else { + var parts = []; + + utils.forEach(params, function serialize(val, key) { + if (val === null || typeof val === 'undefined') { + return; + } + + if (utils.isArray(val)) { + key = key + '[]'; + } else { + val = [val]; + } + + utils.forEach(val, function parseValue(v) { + if (utils.isDate(v)) { + v = v.toISOString(); + } else if (utils.isObject(v)) { + v = JSON.stringify(v); + } + parts.push(encode(key) + '=' + encode(v)); + }); + }); + + serializedParams = parts.join('&'); + } + + if (serializedParams) { + var hashmarkIndex = url.indexOf('#'); + if (hashmarkIndex !== -1) { + url = url.slice(0, hashmarkIndex); + } + + url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams; + } + + return url; + }; + + function InterceptorManager() { + this.handlers = []; + } + + /** + * Add a new interceptor to the stack + * + * @param {Function} fulfilled The function to handle `then` for a `Promise` + * @param {Function} rejected The function to handle `reject` for a `Promise` + * + * @return {Number} An ID used to remove interceptor later + */ + InterceptorManager.prototype.use = function use(fulfilled, rejected) { + this.handlers.push({ + fulfilled: fulfilled, + rejected: rejected + }); + return this.handlers.length - 1; + }; + + /** + * Remove an interceptor from the stack + * + * @param {Number} id The ID that was returned by `use` + */ + InterceptorManager.prototype.eject = function eject(id) { + if (this.handlers[id]) { + this.handlers[id] = null; + } + }; + + /** + * Iterate over all the registered interceptors + * + * This method is particularly useful for skipping over any + * interceptors that may have become `null` calling `eject`. + * + * @param {Function} fn The function to call for each interceptor + */ + InterceptorManager.prototype.forEach = function forEach(fn) { + utils.forEach(this.handlers, function forEachHandler(h) { + if (h !== null) { + fn(h); + } + }); + }; + + var InterceptorManager_1 = InterceptorManager; + + /** + * Transform the data for a request or a response + * + * @param {Object|String} data The data to be transformed + * @param {Array} headers The headers for the request or response + * @param {Array|Function} fns A single function or Array of functions + * @returns {*} The resulting transformed data + */ + var transformData = function transformData(data, headers, fns) { + /*eslint no-param-reassign:0*/ + utils.forEach(fns, function transform(fn) { + data = fn(data, headers); + }); + + return data; + }; + + var isCancel = function isCancel(value) { + return !!(value && value.__CANCEL__); + }; + + var normalizeHeaderName = function normalizeHeaderName(headers, normalizedName) { + utils.forEach(headers, function processHeader(value, name) { + if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) { + headers[normalizedName] = value; + delete headers[name]; + } + }); + }; + + /** + * Update an Error with the specified config, error code, and response. + * + * @param {Error} error The error to update. + * @param {Object} config The config. + * @param {string} [code] The error code (for example, 'ECONNABORTED'). + * @param {Object} [request] The request. + * @param {Object} [response] The response. + * @returns {Error} The error. + */ + var enhanceError = function enhanceError(error, config, code, request, response) { + error.config = config; + if (code) { + error.code = code; + } + + error.request = request; + error.response = response; + error.isAxiosError = true; + + error.toJSON = function toJSON() { + return { + // Standard + message: this.message, + name: this.name, + // Microsoft + description: this.description, + number: this.number, + // Mozilla + fileName: this.fileName, + lineNumber: this.lineNumber, + columnNumber: this.columnNumber, + stack: this.stack, + // Axios + config: this.config, + code: this.code + }; + }; + return error; + }; + + /** + * Create an Error with the specified message, config, error code, request and response. + * + * @param {string} message The error message. + * @param {Object} config The config. + * @param {string} [code] The error code (for example, 'ECONNABORTED'). + * @param {Object} [request] The request. + * @param {Object} [response] The response. + * @returns {Error} The created error. + */ + var createError = function createError(message, config, code, request, response) { + var error = new Error(message); + return enhanceError(error, config, code, request, response); + }; + + /** + * Resolve or reject a Promise based on response status. + * + * @param {Function} resolve A function that resolves the promise. + * @param {Function} reject A function that rejects the promise. + * @param {object} response The response. + */ + var settle = function settle(resolve, reject, response) { + var validateStatus = response.config.validateStatus; + if (!response.status || !validateStatus || validateStatus(response.status)) { + resolve(response); + } else { + reject(createError( + 'Request failed with status code ' + response.status, + response.config, + null, + response.request, + response + )); + } + }; + + var cookies = ( + utils.isStandardBrowserEnv() ? + + // Standard browser envs support document.cookie + (function standardBrowserEnv() { + return { + write: function write(name, value, expires, path, domain, secure) { + var cookie = []; + cookie.push(name + '=' + encodeURIComponent(value)); + + if (utils.isNumber(expires)) { + cookie.push('expires=' + new Date(expires).toGMTString()); + } + + if (utils.isString(path)) { + cookie.push('path=' + path); + } + + if (utils.isString(domain)) { + cookie.push('domain=' + domain); + } + + if (secure === true) { + cookie.push('secure'); + } + + document.cookie = cookie.join('; '); + }, + + read: function read(name) { + var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)')); + return (match ? decodeURIComponent(match[3]) : null); + }, + + remove: function remove(name) { + this.write(name, '', Date.now() - 86400000); + } + }; + })() : + + // Non standard browser env (web workers, react-native) lack needed support. + (function nonStandardBrowserEnv() { + return { + write: function write() {}, + read: function read() { return null; }, + remove: function remove() {} + }; + })() + ); + + /** + * Determines whether the specified URL is absolute + * + * @param {string} url The URL to test + * @returns {boolean} True if the specified URL is absolute, otherwise false + */ + var isAbsoluteURL = function isAbsoluteURL(url) { + // A URL is considered absolute if it begins with "://" or "//" (protocol-relative URL). + // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed + // by any combination of letters, digits, plus, period, or hyphen. + return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url); + }; + + /** + * Creates a new URL by combining the specified URLs + * + * @param {string} baseURL The base URL + * @param {string} relativeURL The relative URL + * @returns {string} The combined URL + */ + var combineURLs = function combineURLs(baseURL, relativeURL) { + return relativeURL + ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') + : baseURL; + }; + + /** + * Creates a new URL by combining the baseURL with the requestedURL, + * only when the requestedURL is not already an absolute URL. + * If the requestURL is absolute, this function returns the requestedURL untouched. + * + * @param {string} baseURL The base URL + * @param {string} requestedURL Absolute or relative URL to combine + * @returns {string} The combined full path + */ + var buildFullPath = function buildFullPath(baseURL, requestedURL) { + if (baseURL && !isAbsoluteURL(requestedURL)) { + return combineURLs(baseURL, requestedURL); + } + return requestedURL; + }; + + // Headers whose duplicates are ignored by node + // c.f. https://nodejs.org/api/http.html#http_message_headers + var ignoreDuplicateOf = [ + 'age', 'authorization', 'content-length', 'content-type', 'etag', + 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', + 'last-modified', 'location', 'max-forwards', 'proxy-authorization', + 'referer', 'retry-after', 'user-agent' + ]; + + /** + * Parse headers into an object + * + * ``` + * Date: Wed, 27 Aug 2014 08:58:49 GMT + * Content-Type: application/json + * Connection: keep-alive + * Transfer-Encoding: chunked + * ``` + * + * @param {String} headers Headers needing to be parsed + * @returns {Object} Headers parsed into an object + */ + var parseHeaders = function parseHeaders(headers) { + var parsed = {}; + var key; + var val; + var i; + + if (!headers) { return parsed; } + + utils.forEach(headers.split('\n'), function parser(line) { + i = line.indexOf(':'); + key = utils.trim(line.substr(0, i)).toLowerCase(); + val = utils.trim(line.substr(i + 1)); + + if (key) { + if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) { + return; + } + if (key === 'set-cookie') { + parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]); + } else { + parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val; + } + } + }); + + return parsed; + }; + + var isURLSameOrigin = ( + utils.isStandardBrowserEnv() ? + + // Standard browser envs have full support of the APIs needed to test + // whether the request URL is of the same origin as current location. + (function standardBrowserEnv() { + var msie = /(msie|trident)/i.test(navigator.userAgent); + var urlParsingNode = document.createElement('a'); + var originURL; + + /** + * Parse a URL to discover it's components + * + * @param {String} url The URL to be parsed + * @returns {Object} + */ + function resolveURL(url) { + var href = url; + + if (msie) { + // IE needs attribute set twice to normalize properties + urlParsingNode.setAttribute('href', href); + href = urlParsingNode.href; + } + + urlParsingNode.setAttribute('href', href); + + // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils + return { + href: urlParsingNode.href, + protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '', + host: urlParsingNode.host, + search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '', + hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '', + hostname: urlParsingNode.hostname, + port: urlParsingNode.port, + pathname: (urlParsingNode.pathname.charAt(0) === '/') ? + urlParsingNode.pathname : + '/' + urlParsingNode.pathname + }; + } + + originURL = resolveURL(window.location.href); + + /** + * Determine if a URL shares the same origin as the current location + * + * @param {String} requestURL The URL to test + * @returns {boolean} True if URL shares the same origin, otherwise false + */ + return function isURLSameOrigin(requestURL) { + var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL; + return (parsed.protocol === originURL.protocol && + parsed.host === originURL.host); + }; + })() : + + // Non standard browser envs (web workers, react-native) lack needed support. + (function nonStandardBrowserEnv() { + return function isURLSameOrigin() { + return true; + }; + })() + ); + + var xhr = function xhrAdapter(config) { + return new Promise(function dispatchXhrRequest(resolve, reject) { + var requestData = config.data; + var requestHeaders = config.headers; + + if (utils.isFormData(requestData)) { + delete requestHeaders['Content-Type']; // Let the browser set it + } + + var request = new XMLHttpRequest(); + + // HTTP basic authentication + if (config.auth) { + var username = config.auth.username || ''; + var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : ''; + requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password); + } + + var fullPath = buildFullPath(config.baseURL, config.url); + request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true); + + // Set the request timeout in MS + request.timeout = config.timeout; + + // Listen for ready state + request.onreadystatechange = function handleLoad() { + if (!request || request.readyState !== 4) { + return; + } + + // The request errored out and we didn't get a response, this will be + // handled by onerror instead + // With one exception: request that using file: protocol, most browsers + // will return status as 0 even though it's a successful request + if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) { + return; + } + + // Prepare the response + var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null; + var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response; + var response = { + data: responseData, + status: request.status, + statusText: request.statusText, + headers: responseHeaders, + config: config, + request: request + }; + + settle(resolve, reject, response); + + // Clean up request + request = null; + }; + + // Handle browser request cancellation (as opposed to a manual cancellation) + request.onabort = function handleAbort() { + if (!request) { + return; + } + + reject(createError('Request aborted', config, 'ECONNABORTED', request)); + + // Clean up request + request = null; + }; + + // Handle low level network errors + request.onerror = function handleError() { + // Real errors are hidden from us by the browser + // onerror should only fire if it's a network error + reject(createError('Network Error', config, null, request)); + + // Clean up request + request = null; + }; + + // Handle timeout + request.ontimeout = function handleTimeout() { + var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded'; + if (config.timeoutErrorMessage) { + timeoutErrorMessage = config.timeoutErrorMessage; + } + reject(createError(timeoutErrorMessage, config, 'ECONNABORTED', + request)); + + // Clean up request + request = null; + }; + + // Add xsrf header + // This is only done if running in a standard browser environment. + // Specifically not if we're in a web worker, or react-native. + if (utils.isStandardBrowserEnv()) { + // Add xsrf header + var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ? + cookies.read(config.xsrfCookieName) : + undefined; + + if (xsrfValue) { + requestHeaders[config.xsrfHeaderName] = xsrfValue; + } + } + + // Add headers to the request + if ('setRequestHeader' in request) { + utils.forEach(requestHeaders, function setRequestHeader(val, key) { + if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') { + // Remove Content-Type if data is undefined + delete requestHeaders[key]; + } else { + // Otherwise add header to the request + request.setRequestHeader(key, val); + } + }); + } + + // Add withCredentials to request if needed + if (!utils.isUndefined(config.withCredentials)) { + request.withCredentials = !!config.withCredentials; + } + + // Add responseType to request if needed + if (config.responseType) { + try { + request.responseType = config.responseType; + } catch (e) { + // Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2. + // But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function. + if (config.responseType !== 'json') { + throw e; + } + } + } + + // Handle progress if needed + if (typeof config.onDownloadProgress === 'function') { + request.addEventListener('progress', config.onDownloadProgress); + } + + // Not all browsers support upload events + if (typeof config.onUploadProgress === 'function' && request.upload) { + request.upload.addEventListener('progress', config.onUploadProgress); + } + + if (config.cancelToken) { + // Handle cancellation + config.cancelToken.promise.then(function onCanceled(cancel) { + if (!request) { + return; + } + + request.abort(); + reject(cancel); + // Clean up request + request = null; + }); + } + + if (!requestData) { + requestData = null; + } + + // Send the request + request.send(requestData); + }); + }; + + var DEFAULT_CONTENT_TYPE = { + 'Content-Type': 'application/x-www-form-urlencoded' + }; + + function setContentTypeIfUnset(headers, value) { + if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) { + headers['Content-Type'] = value; + } + } + + function getDefaultAdapter() { + var adapter; + if (typeof XMLHttpRequest !== 'undefined') { + // For browsers use XHR adapter + adapter = xhr; + } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') { + // For node use HTTP adapter + adapter = xhr; + } + return adapter; + } + + var defaults = { + adapter: getDefaultAdapter(), + + transformRequest: [function transformRequest(data, headers) { + normalizeHeaderName(headers, 'Accept'); + normalizeHeaderName(headers, 'Content-Type'); + if (utils.isFormData(data) || + utils.isArrayBuffer(data) || + utils.isBuffer(data) || + utils.isStream(data) || + utils.isFile(data) || + utils.isBlob(data) + ) { + return data; + } + if (utils.isArrayBufferView(data)) { + return data.buffer; + } + if (utils.isURLSearchParams(data)) { + setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8'); + return data.toString(); + } + if (utils.isObject(data)) { + setContentTypeIfUnset(headers, 'application/json;charset=utf-8'); + return JSON.stringify(data); + } + return data; + }], + + transformResponse: [function transformResponse(data) { + /*eslint no-param-reassign:0*/ + if (typeof data === 'string') { + try { + data = JSON.parse(data); + } catch (e) { /* Ignore */ } + } + return data; + }], + + /** + * A timeout in milliseconds to abort a request. If set to 0 (default) a + * timeout is not created. + */ + timeout: 0, + + xsrfCookieName: 'XSRF-TOKEN', + xsrfHeaderName: 'X-XSRF-TOKEN', + + maxContentLength: -1, + maxBodyLength: -1, + + validateStatus: function validateStatus(status) { + return status >= 200 && status < 300; + } + }; + + defaults.headers = { + common: { + 'Accept': 'application/json, text/plain, */*' + } + }; + + utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) { + defaults.headers[method] = {}; + }); + + utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) { + defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE); + }); + + var defaults_1 = defaults; + + /** + * Throws a `Cancel` if cancellation has been requested. + */ + function throwIfCancellationRequested(config) { + if (config.cancelToken) { + config.cancelToken.throwIfRequested(); + } + } + + /** + * Dispatch a request to the server using the configured adapter. + * + * @param {object} config The config that is to be used for the request + * @returns {Promise} The Promise to be fulfilled + */ + var dispatchRequest = function dispatchRequest(config) { + throwIfCancellationRequested(config); + + // Ensure headers exist + config.headers = config.headers || {}; + + // Transform request data + config.data = transformData( + config.data, + config.headers, + config.transformRequest + ); + + // Flatten headers + config.headers = utils.merge( + config.headers.common || {}, + config.headers[config.method] || {}, + config.headers + ); + + utils.forEach( + ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'], + function cleanHeaderConfig(method) { + delete config.headers[method]; + } + ); + + var adapter = config.adapter || defaults_1.adapter; + + return adapter(config).then(function onAdapterResolution(response) { + throwIfCancellationRequested(config); + + // Transform response data + response.data = transformData( + response.data, + response.headers, + config.transformResponse + ); + + return response; + }, function onAdapterRejection(reason) { + if (!isCancel(reason)) { + throwIfCancellationRequested(config); + + // Transform response data + if (reason && reason.response) { + reason.response.data = transformData( + reason.response.data, + reason.response.headers, + config.transformResponse + ); + } + } + + return Promise.reject(reason); + }); + }; + + /** + * Config-specific merge-function which creates a new config-object + * by merging two configuration objects together. + * + * @param {Object} config1 + * @param {Object} config2 + * @returns {Object} New object resulting from merging config2 to config1 + */ + var mergeConfig = function mergeConfig(config1, config2) { + // eslint-disable-next-line no-param-reassign + config2 = config2 || {}; + var config = {}; + + var valueFromConfig2Keys = ['url', 'method', 'data']; + var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy', 'params']; + var defaultToConfig2Keys = [ + 'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer', + 'timeout', 'timeoutMessage', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName', + 'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'decompress', + 'maxContentLength', 'maxBodyLength', 'maxRedirects', 'transport', 'httpAgent', + 'httpsAgent', 'cancelToken', 'socketPath', 'responseEncoding' + ]; + var directMergeKeys = ['validateStatus']; + + function getMergedValue(target, source) { + if (utils.isPlainObject(target) && utils.isPlainObject(source)) { + return utils.merge(target, source); + } else if (utils.isPlainObject(source)) { + return utils.merge({}, source); + } else if (utils.isArray(source)) { + return source.slice(); + } + return source; + } + + function mergeDeepProperties(prop) { + if (!utils.isUndefined(config2[prop])) { + config[prop] = getMergedValue(config1[prop], config2[prop]); + } else if (!utils.isUndefined(config1[prop])) { + config[prop] = getMergedValue(undefined, config1[prop]); + } + } + + utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) { + if (!utils.isUndefined(config2[prop])) { + config[prop] = getMergedValue(undefined, config2[prop]); + } + }); + + utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties); + + utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) { + if (!utils.isUndefined(config2[prop])) { + config[prop] = getMergedValue(undefined, config2[prop]); + } else if (!utils.isUndefined(config1[prop])) { + config[prop] = getMergedValue(undefined, config1[prop]); + } + }); + + utils.forEach(directMergeKeys, function merge(prop) { + if (prop in config2) { + config[prop] = getMergedValue(config1[prop], config2[prop]); + } else if (prop in config1) { + config[prop] = getMergedValue(undefined, config1[prop]); + } + }); + + var axiosKeys = valueFromConfig2Keys + .concat(mergeDeepPropertiesKeys) + .concat(defaultToConfig2Keys) + .concat(directMergeKeys); + + var otherKeys = Object + .keys(config1) + .concat(Object.keys(config2)) + .filter(function filterAxiosKeys(key) { + return axiosKeys.indexOf(key) === -1; + }); + + utils.forEach(otherKeys, mergeDeepProperties); + + return config; + }; + + /** + * Create a new instance of Axios + * + * @param {Object} instanceConfig The default config for the instance + */ + function Axios(instanceConfig) { + this.defaults = instanceConfig; + this.interceptors = { + request: new InterceptorManager_1(), + response: new InterceptorManager_1() + }; + } + + /** + * Dispatch a request + * + * @param {Object} config The config specific for this request (merged with this.defaults) + */ + Axios.prototype.request = function request(config) { + /*eslint no-param-reassign:0*/ + // Allow for axios('example/url'[, config]) a la fetch API + if (typeof config === 'string') { + config = arguments[1] || {}; + config.url = arguments[0]; + } else { + config = config || {}; + } + + config = mergeConfig(this.defaults, config); + + // Set config.method + if (config.method) { + config.method = config.method.toLowerCase(); + } else if (this.defaults.method) { + config.method = this.defaults.method.toLowerCase(); + } else { + config.method = 'get'; + } + + // Hook up interceptors middleware + var chain = [dispatchRequest, undefined]; + var promise = Promise.resolve(config); + + this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) { + chain.unshift(interceptor.fulfilled, interceptor.rejected); + }); + + this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) { + chain.push(interceptor.fulfilled, interceptor.rejected); + }); + + while (chain.length) { + promise = promise.then(chain.shift(), chain.shift()); + } + + return promise; + }; + + Axios.prototype.getUri = function getUri(config) { + config = mergeConfig(this.defaults, config); + return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, ''); + }; + + // Provide aliases for supported request methods + utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) { + /*eslint func-names:0*/ + Axios.prototype[method] = function(url, config) { + return this.request(mergeConfig(config || {}, { + method: method, + url: url, + data: (config || {}).data + })); + }; + }); + + utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) { + /*eslint func-names:0*/ + Axios.prototype[method] = function(url, data, config) { + return this.request(mergeConfig(config || {}, { + method: method, + url: url, + data: data + })); + }; + }); + + var Axios_1 = Axios; + + /** + * A `Cancel` is an object that is thrown when an operation is canceled. + * + * @class + * @param {string=} message The message. + */ + function Cancel(message) { + this.message = message; + } + + Cancel.prototype.toString = function toString() { + return 'Cancel' + (this.message ? ': ' + this.message : ''); + }; + + Cancel.prototype.__CANCEL__ = true; + + var Cancel_1 = Cancel; + + /** + * A `CancelToken` is an object that can be used to request cancellation of an operation. + * + * @class + * @param {Function} executor The executor function. + */ + function CancelToken(executor) { + if (typeof executor !== 'function') { + throw new TypeError('executor must be a function.'); + } + + var resolvePromise; + this.promise = new Promise(function promiseExecutor(resolve) { + resolvePromise = resolve; + }); + + var token = this; + executor(function cancel(message) { + if (token.reason) { + // Cancellation has already been requested + return; + } + + token.reason = new Cancel_1(message); + resolvePromise(token.reason); + }); + } + + /** + * Throws a `Cancel` if cancellation has been requested. + */ + CancelToken.prototype.throwIfRequested = function throwIfRequested() { + if (this.reason) { + throw this.reason; + } + }; + + /** + * Returns an object that contains a new `CancelToken` and a function that, when called, + * cancels the `CancelToken`. + */ + CancelToken.source = function source() { + var cancel; + var token = new CancelToken(function executor(c) { + cancel = c; + }); + return { + token: token, + cancel: cancel + }; + }; + + var CancelToken_1 = CancelToken; + + /** + * Syntactic sugar for invoking a function and expanding an array for arguments. + * + * Common use case would be to use `Function.prototype.apply`. + * + * ```js + * function f(x, y, z) {} + * var args = [1, 2, 3]; + * f.apply(null, args); + * ``` + * + * With `spread` this example can be re-written. + * + * ```js + * spread(function(x, y, z) {})([1, 2, 3]); + * ``` + * + * @param {Function} callback + * @returns {Function} + */ + var spread = function spread(callback) { + return function wrap(arr) { + return callback.apply(null, arr); + }; + }; + + /** + * Determines whether the payload is an error thrown by Axios + * + * @param {*} payload The value to test + * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false + */ + var isAxiosError = function isAxiosError(payload) { + return (typeof payload === 'object') && (payload.isAxiosError === true); + }; + + /** + * Create an instance of Axios + * + * @param {Object} defaultConfig The default config for the instance + * @return {Axios} A new instance of Axios + */ + function createInstance(defaultConfig) { + var context = new Axios_1(defaultConfig); + var instance = bind(Axios_1.prototype.request, context); + + // Copy axios.prototype to instance + utils.extend(instance, Axios_1.prototype, context); + + // Copy context to instance + utils.extend(instance, context); + + return instance; + } + + // Create the default instance to be exported + var axios$1 = createInstance(defaults_1); + + // Expose Axios class to allow class inheritance + axios$1.Axios = Axios_1; + + // Factory for creating new instances + axios$1.create = function create(instanceConfig) { + return createInstance(mergeConfig(axios$1.defaults, instanceConfig)); + }; + + // Expose Cancel & CancelToken + axios$1.Cancel = Cancel_1; + axios$1.CancelToken = CancelToken_1; + axios$1.isCancel = isCancel; + + // Expose all/spread + axios$1.all = function all(promises) { + return Promise.all(promises); + }; + axios$1.spread = spread; + + // Expose isAxiosError + axios$1.isAxiosError = isAxiosError; + + var axios_1 = axios$1; + + // Allow use of default import syntax in TypeScript + var _default = axios$1; + axios_1.default = _default; + + var axios = axios_1; + + class RTCEndpoint extends Event$1 { + constructor(options) { + super('RTCPusherPlayer'); + this.TAG = '[RTCPusherPlayer]'; + let defaults = { + element: '', + // html video element + debug: false, + // if output debug log + zlmsdpUrl: '', + simulcast: false, + useCamera: true, + audioEnable: true, + videoEnable: true, + recvOnly: false, + resolution: { + w: 0, + h: 0 + } + }; + this.options = Object.assign({}, defaults, options); + + if (this.options.debug) { + setLogger(); + } + + this.e = { + onicecandidate: this._onIceCandidate.bind(this), + ontrack: this._onTrack.bind(this), + onicecandidateerror: this._onIceCandidateError.bind(this) + }; + this._remoteStream = null; + this._localStream = null; + this.pc = new RTCPeerConnection(null); + this.pc.onicecandidate = this.e.onicecandidate; + this.pc.onicecandidateerror = this.e.onicecandidateerror; + this.pc.ontrack = this.e.ontrack; + if (!this.options.recvOnly && (this.options.audioEnable || this.options.videoEnable)) this.start();else this.receive(); + } + + receive() { + + const AudioTransceiverInit = { + direction: 'recvonly', + sendEncodings: [] + }; + const VideoTransceiverInit = { + direction: 'recvonly', + sendEncodings: [] + }; + this.pc.addTransceiver('audio', AudioTransceiverInit); + this.pc.addTransceiver('video', VideoTransceiverInit); + this.pc.createOffer().then(desc => { + log(this.TAG, 'offer:', desc.sdp); + this.pc.setLocalDescription(desc).then(() => { + axios({ + method: 'post', + url: this.options.zlmsdpUrl, + responseType: 'json', + data: desc.sdp, + headers: { + 'Content-Type': 'text/plain;charset=utf-8' + } + }).then(response => { + let ret = response.data; //JSON.parse(response.data); + + if (ret.code != 0) { + // mean failed for offer/answer exchange + this.dispatch(Events$1.WEBRTC_OFFER_ANSWER_EXCHANGE_FAILED, ret); + return; + } + + let answer = {}; + answer.sdp = ret.sdp; + answer.type = 'answer'; + log(this.TAG, 'answer:', ret.sdp); + this.pc.setRemoteDescription(answer).then(() => { + log(this.TAG, 'set remote sucess'); + }).catch(e => { + error(this.TAG, e); + }); + }); + }); + }).catch(e => { + error(this.TAG, e); + }); + } + + start() { + let videoConstraints = false; + let audioConstraints = false; + + if (this.options.useCamera) { + if (this.options.videoEnable) videoConstraints = new VideoTrackConstraints(VideoSourceInfo.CAMERA); + if (this.options.audioEnable) audioConstraints = new AudioTrackConstraints(AudioSourceInfo.MIC); + } else { + if (this.options.videoEnable) { + videoConstraints = new VideoTrackConstraints(VideoSourceInfo.SCREENCAST); + if (this.options.audioEnable) audioConstraints = new AudioTrackConstraints(AudioSourceInfo.SCREENCAST); + } else { + if (this.options.audioEnable) audioConstraints = new AudioTrackConstraints(AudioSourceInfo.MIC);else { + // error shared display media not only audio + error(this.TAG, 'error paramter'); + } + } + } + + if (this.options.resolution.w != 0 && this.options.resolution.h != 0 && typeof videoConstraints == 'object') { + videoConstraints.resolution = new Resolution(this.options.resolution.w, this.options.resolution.h); + } + + MediaStreamFactory.createMediaStream(new StreamConstraints(audioConstraints, videoConstraints)).then(stream => { + this._localStream = stream; + this.dispatch(Events$1.WEBRTC_ON_LOCAL_STREAM, stream); + const AudioTransceiverInit = { + direction: 'sendrecv', + sendEncodings: [] + }; + const VideoTransceiverInit = { + direction: 'sendrecv', + sendEncodings: [] + }; + + if (this.options.simulcast && stream.getVideoTracks().length > 0) { + VideoTransceiverInit.sendEncodings = [{ + rid: 'q', + active: true, + scaleResolutionDownBy: 4.0 + }, { + rid: 'h', + active: true, + scaleResolutionDownBy: 2.0 + }, { + rid: 'f', + active: true + }]; + } + + if (stream.getAudioTracks().length > 0) { + this.pc.addTransceiver(stream.getAudioTracks()[0], AudioTransceiverInit); + } else { + AudioTransceiverInit.direction = 'recvonly'; + this.pc.addTransceiver('audio', AudioTransceiverInit); + } + + if (stream.getVideoTracks().length > 0) { + this.pc.addTransceiver(stream.getVideoTracks()[0], VideoTransceiverInit); + } else { + VideoTransceiverInit.direction = 'recvonly'; + this.pc.addTransceiver('video', VideoTransceiverInit); + } + /* + stream.getTracks().forEach((track,idx)=>{ + debug.log(this.TAG,track); + this.pc.addTrack(track); + }); + */ + + + this.pc.createOffer().then(desc => { + log(this.TAG, 'offer:', desc.sdp); + this.pc.setLocalDescription(desc).then(() => { + axios({ + method: 'post', + url: this.options.zlmsdpUrl, + responseType: 'json', + data: desc.sdp, + headers: { + 'Content-Type': 'text/plain;charset=utf-8' + } + }).then(response => { + let ret = response.data; //JSON.parse(response.data); + + if (ret.code != 0) { + // mean failed for offer/answer exchange + this.dispatch(Events$1.WEBRTC_OFFER_ANSWER_EXCHANGE_FAILED, ret); + return; + } + + let answer = {}; + answer.sdp = ret.sdp; + answer.type = 'answer'; + log(this.TAG, 'answer:', ret.sdp); + this.pc.setRemoteDescription(answer).then(() => { + log(this.TAG, 'set remote sucess'); + }).catch(e => { + error(this.TAG, e); + }); + }); + }); + }).catch(e => { + error(this.TAG, e); + }); + }).catch(e => { + this.dispatch(Events$1.CAPTURE_STREAM_FAILED); //debug.error(this.TAG,e); + }); //const offerOptions = {}; + + /* + if (typeof this.pc.addTransceiver === 'function') { + // |direction| seems not working on Safari. + this.pc.addTransceiver('audio', { direction: 'recvonly' }); + this.pc.addTransceiver('video', { direction: 'recvonly' }); + } else { + offerOptions.offerToReceiveAudio = true; + offerOptions.offerToReceiveVideo = true; + } + */ + } + + _onIceCandidate(event) { + if (event.candidate) { + log('Remote ICE candidate: \n ' + event.candidate.candidate); // Send the candidate to the remote peer + } + } + + _onTrack(event) { + if (this.options.element && event.streams && event.streams.length > 0) { + this.options.element.srcObject = event.streams[0]; + this._remoteStream = event.streams[0]; + this.dispatch(Events$1.WEBRTC_ON_REMOTE_STREAMS, event); + } else { + error('element pararm is failed'); + } + } + + _onIceCandidateError(event) { + this.dispatch(Events$1.WEBRTC_ICE_CANDIDATE_ERROR, event); + } + + close() { + if (this.pc) { + this.pc.close(); + this.pc = null; + } + + if (this.options) { + this.options = null; + } + + if (this._localStream) { + this._localStream.getTracks().forEach((track, idx) => { + track.stop(); + }); + } + + if (this._remoteStream) { + this._remoteStream.getTracks().forEach((track, idx) => { + track.stop(); + }); + } + } + + get remoteStream() { + return this._remoteStream; + } + + get localStream() { + return this._localStream; + } + + } + + const quickScan = [{ + 'label': '4K(UHD)', + 'width': 3840, + 'height': 2160 + }, { + 'label': '1080p(FHD)', + 'width': 1920, + 'height': 1080 + }, { + 'label': 'UXGA', + 'width': 1600, + 'height': 1200, + 'ratio': '4:3' + }, { + 'label': '720p(HD)', + 'width': 1280, + 'height': 720 + }, { + 'label': 'SVGA', + 'width': 800, + 'height': 600 + }, { + 'label': 'VGA', + 'width': 640, + 'height': 480 + }, { + 'label': '360p(nHD)', + 'width': 640, + 'height': 360 + }, { + 'label': 'CIF', + 'width': 352, + 'height': 288 + }, { + 'label': 'QVGA', + 'width': 320, + 'height': 240 + }, { + 'label': 'QCIF', + 'width': 176, + 'height': 144 + }, { + 'label': 'QQVGA', + 'width': 160, + 'height': 120 + }]; + function GetSupportCameraResolutions$1() { + return new Promise(function (resolve, reject) { + let resolutions = []; + let ok = 0; + let err = 0; + + for (let i = 0; i < quickScan.length; ++i) { + let videoConstraints = new VideoTrackConstraints(VideoSourceInfo.CAMERA); + videoConstraints.resolution = new Resolution(quickScan[i].width, quickScan[i].height); + MediaStreamFactory.createMediaStream(new StreamConstraints(false, videoConstraints)).then(stream => { + resolutions.push(quickScan[i]); + ok++; + + if (ok + err == quickScan.length) { + resolve(resolutions); + } + }).catch(e => { + err++; + + if (ok + err == quickScan.length) { + resolve(resolutions); + } + }); + } + }); + } + function GetAllScanResolution$1() { + return quickScan; + } + function isSupportResolution$1(w, h) { + return new Promise(function (resolve, reject) { + let videoConstraints = new VideoTrackConstraints(VideoSourceInfo.CAMERA); + videoConstraints.resolution = new Resolution(w, h); + MediaStreamFactory.createMediaStream(new StreamConstraints(false, videoConstraints)).then(stream => { + resolve(); + }).catch(e => { + reject(e); + }); + }); + } + + console.log('build date:', BUILD_DATE); + console.log('version:', VERSION); + const Events = Events$1; + const Media = media; + const Endpoint = RTCEndpoint; + const GetSupportCameraResolutions = GetSupportCameraResolutions$1; + const GetAllScanResolution = GetAllScanResolution$1; + const isSupportResolution = isSupportResolution$1; + + exports.Endpoint = Endpoint; + exports.Events = Events; + exports.GetAllScanResolution = GetAllScanResolution; + exports.GetSupportCameraResolutions = GetSupportCameraResolutions; + exports.Media = Media; + exports.isSupportResolution = isSupportResolution; + + Object.defineProperty(exports, '__esModule', { value: true }); + + return exports; + +}({})); +//# sourceMappingURL=ZLMRTCClient.js.map diff --git a/www/webrtc/ZLMRTCClient.js.map b/www/webrtc/ZLMRTCClient.js.map new file mode 100644 index 00000000..fa9114c4 --- /dev/null +++ b/www/webrtc/ZLMRTCClient.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ZLMRTCClient.js","sources":["../src/base/event.js","../src/ulity/version.js","../src/base/utils.js","../src/base/mediaformat.js","../node_modules/webrtc-adapter/src/js/utils.js","../node_modules/webrtc-adapter/src/js/chrome/getusermedia.js","../node_modules/webrtc-adapter/src/js/chrome/getdisplaymedia.js","../node_modules/webrtc-adapter/src/js/chrome/chrome_shim.js","../node_modules/webrtc-adapter/src/js/edge/filtericeservers.js","../node_modules/sdp/sdp.js","../node_modules/rtcpeerconnection-shim/rtcpeerconnection.js","../node_modules/webrtc-adapter/src/js/edge/getusermedia.js","../node_modules/webrtc-adapter/src/js/edge/getdisplaymedia.js","../node_modules/webrtc-adapter/src/js/edge/edge_shim.js","../node_modules/webrtc-adapter/src/js/firefox/getusermedia.js","../node_modules/webrtc-adapter/src/js/firefox/getdisplaymedia.js","../node_modules/webrtc-adapter/src/js/firefox/firefox_shim.js","../node_modules/webrtc-adapter/src/js/safari/safari_shim.js","../node_modules/webrtc-adapter/src/js/common_shim.js","../node_modules/webrtc-adapter/src/js/adapter_factory.js","../node_modules/webrtc-adapter/src/js/adapter_core.js","../src/base/mediastream-factory.js","../src/base/export.js","../src/ulity/debug.js","../src/ulity/event.js","../node_modules/axios/lib/helpers/bind.js","../node_modules/axios/lib/utils.js","../node_modules/axios/lib/helpers/buildURL.js","../node_modules/axios/lib/core/InterceptorManager.js","../node_modules/axios/lib/core/transformData.js","../node_modules/axios/lib/cancel/isCancel.js","../node_modules/axios/lib/helpers/normalizeHeaderName.js","../node_modules/axios/lib/core/enhanceError.js","../node_modules/axios/lib/core/createError.js","../node_modules/axios/lib/core/settle.js","../node_modules/axios/lib/helpers/cookies.js","../node_modules/axios/lib/helpers/isAbsoluteURL.js","../node_modules/axios/lib/helpers/combineURLs.js","../node_modules/axios/lib/core/buildFullPath.js","../node_modules/axios/lib/helpers/parseHeaders.js","../node_modules/axios/lib/helpers/isURLSameOrigin.js","../node_modules/axios/lib/adapters/xhr.js","../node_modules/axios/lib/defaults.js","../node_modules/axios/lib/core/dispatchRequest.js","../node_modules/axios/lib/core/mergeConfig.js","../node_modules/axios/lib/core/Axios.js","../node_modules/axios/lib/cancel/Cancel.js","../node_modules/axios/lib/cancel/CancelToken.js","../node_modules/axios/lib/helpers/spread.js","../node_modules/axios/lib/helpers/isAxiosError.js","../node_modules/axios/lib/axios.js","../node_modules/axios/index.js","../src/endpoint/endpoint.js","../src/base/resolutionfind.js","../src/export.js"],"sourcesContent":["const Events = {\n\tWEBRTC_NOT_SUPPORT : 'WEBRTC_NOT_SUPPORT',\n\tWEBRTC_ICE_CANDIDATE_ERROR : 'WEBRTC_ICE_CANDIDATE_ERROR',\n\tWEBRTC_OFFER_ANSWER_EXCHANGE_FAILED:'WEBRTC_OFFER_ANSWER_EXCHANGE_FAILED',\n\tWEBRTC_ON_REMOTE_STREAMS:'WEBRTC_ON_REMOTE_STREAMS',\n\tWEBRTC_ON_LOCAL_STREAM:'WEBRTC_ON_LOCAL_STREAM',\n\tCAPTURE_STREAM_FAILED:'CAPTURE_STREAM_FAILED'\n};\n\nexport default Events;","export const VERSION = '__VERSION__';\nexport const BUILD_DATE = '__BUILD_DATE__';","// Copyright (C) <2018> Intel Corporation\n//\n// SPDX-License-Identifier: Apache-2.0\n\n\n// eslint-disable-next-line require-jsdoc\nexport function isFirefox() {\n return window.navigator.userAgent.match('Firefox') !== null;\n}\n// eslint-disable-next-line require-jsdoc\nexport function isChrome() {\n return window.navigator.userAgent.match('Chrome') !== null;\n}\n// eslint-disable-next-line require-jsdoc\nexport function isSafari() {\n return /^((?!chrome|android).)*safari/i.test(window.navigator.userAgent);\n}\n// eslint-disable-next-line require-jsdoc\nexport function isEdge() {\n return window.navigator.userAgent.match(/Edge\\/(\\d+).(\\d+)$/) !== null;\n}\n// eslint-disable-next-line require-jsdoc\nexport function createUuid() {\n return 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {\n const r = Math.random() * 16 | 0;\n const v = c === 'x' ? r : (r & 0x3 | 0x8);\n return v.toString(16);\n });\n}","// Copyright (C) <2018> Intel Corporation\n//\n// SPDX-License-Identifier: Apache-2.0\n\n'use strict';\n/**\n * @class AudioSourceInfo\n * @classDesc Source info about an audio track. Values: 'mic', 'screen-cast', 'file', 'mixed'.\n * @memberOf Owt.Base\n * @readonly\n * @enum {string}\n */\nexport const AudioSourceInfo = {\n MIC: 'mic',\n SCREENCAST: 'screen-cast',\n FILE: 'file',\n MIXED: 'mixed',\n};\n\n/**\n * @class VideoSourceInfo\n * @classDesc Source info about a video track. Values: 'camera', 'screen-cast', 'file', 'mixed'.\n * @memberOf Owt.Base\n * @readonly\n * @enum {string}\n */\nexport const VideoSourceInfo = {\n CAMERA: 'camera',\n SCREENCAST: 'screen-cast',\n FILE: 'file',\n MIXED: 'mixed',\n};\n\n/**\n * @class TrackKind\n * @classDesc Kind of a track. Values: 'audio' for audio track, 'video' for video track, 'av' for both audio and video tracks.\n * @memberOf Owt.Base\n * @readonly\n * @enum {string}\n */\nexport const TrackKind = {\n /**\n * Audio tracks.\n * @type string\n */\n AUDIO: 'audio',\n /**\n * Video tracks.\n * @type string\n */\n VIDEO: 'video',\n /**\n * Both audio and video tracks.\n * @type string\n */\n AUDIO_AND_VIDEO: 'av',\n};\n/**\n * @class Resolution\n * @memberOf Owt.Base\n * @classDesc The Resolution defines the size of a rectangle.\n * @constructor\n * @param {number} width\n * @param {number} height\n */\nexport class Resolution {\n // eslint-disable-next-line require-jsdoc\n constructor(width, height) {\n /**\n * @member {number} width\n * @instance\n * @memberof Owt.Base.Resolution\n */\n this.width = width;\n /**\n * @member {number} height\n * @instance\n * @memberof Owt.Base.Resolution\n */\n this.height = height;\n }\n}\n","/*\n * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n /* eslint-env node */\n'use strict';\n\nlet logDisabled_ = true;\nlet deprecationWarnings_ = true;\n\n/**\n * Extract browser version out of the provided user agent string.\n *\n * @param {!string} uastring userAgent string.\n * @param {!string} expr Regular expression used as match criteria.\n * @param {!number} pos position in the version string to be returned.\n * @return {!number} browser version.\n */\nexport function extractVersion(uastring, expr, pos) {\n const match = uastring.match(expr);\n return match && match.length >= pos && parseInt(match[pos], 10);\n}\n\n// Wraps the peerconnection event eventNameToWrap in a function\n// which returns the modified event object (or false to prevent\n// the event).\nexport function wrapPeerConnectionEvent(window, eventNameToWrap, wrapper) {\n if (!window.RTCPeerConnection) {\n return;\n }\n const proto = window.RTCPeerConnection.prototype;\n const nativeAddEventListener = proto.addEventListener;\n proto.addEventListener = function(nativeEventName, cb) {\n if (nativeEventName !== eventNameToWrap) {\n return nativeAddEventListener.apply(this, arguments);\n }\n const wrappedCallback = (e) => {\n const modifiedEvent = wrapper(e);\n if (modifiedEvent) {\n if (cb.handleEvent) {\n cb.handleEvent(modifiedEvent);\n } else {\n cb(modifiedEvent);\n }\n }\n };\n this._eventMap = this._eventMap || {};\n if (!this._eventMap[eventNameToWrap]) {\n this._eventMap[eventNameToWrap] = new Map();\n }\n this._eventMap[eventNameToWrap].set(cb, wrappedCallback);\n return nativeAddEventListener.apply(this, [nativeEventName,\n wrappedCallback]);\n };\n\n const nativeRemoveEventListener = proto.removeEventListener;\n proto.removeEventListener = function(nativeEventName, cb) {\n if (nativeEventName !== eventNameToWrap || !this._eventMap\n || !this._eventMap[eventNameToWrap]) {\n return nativeRemoveEventListener.apply(this, arguments);\n }\n if (!this._eventMap[eventNameToWrap].has(cb)) {\n return nativeRemoveEventListener.apply(this, arguments);\n }\n const unwrappedCb = this._eventMap[eventNameToWrap].get(cb);\n this._eventMap[eventNameToWrap].delete(cb);\n if (this._eventMap[eventNameToWrap].size === 0) {\n delete this._eventMap[eventNameToWrap];\n }\n if (Object.keys(this._eventMap).length === 0) {\n delete this._eventMap;\n }\n return nativeRemoveEventListener.apply(this, [nativeEventName,\n unwrappedCb]);\n };\n\n Object.defineProperty(proto, 'on' + eventNameToWrap, {\n get() {\n return this['_on' + eventNameToWrap];\n },\n set(cb) {\n if (this['_on' + eventNameToWrap]) {\n this.removeEventListener(eventNameToWrap,\n this['_on' + eventNameToWrap]);\n delete this['_on' + eventNameToWrap];\n }\n if (cb) {\n this.addEventListener(eventNameToWrap,\n this['_on' + eventNameToWrap] = cb);\n }\n },\n enumerable: true,\n configurable: true\n });\n}\n\nexport function disableLog(bool) {\n if (typeof bool !== 'boolean') {\n return new Error('Argument type: ' + typeof bool +\n '. Please use a boolean.');\n }\n logDisabled_ = bool;\n return (bool) ? 'adapter.js logging disabled' :\n 'adapter.js logging enabled';\n}\n\n/**\n * Disable or enable deprecation warnings\n * @param {!boolean} bool set to true to disable warnings.\n */\nexport function disableWarnings(bool) {\n if (typeof bool !== 'boolean') {\n return new Error('Argument type: ' + typeof bool +\n '. Please use a boolean.');\n }\n deprecationWarnings_ = !bool;\n return 'adapter.js deprecation warnings ' + (bool ? 'disabled' : 'enabled');\n}\n\nexport function log() {\n if (typeof window === 'object') {\n if (logDisabled_) {\n return;\n }\n if (typeof console !== 'undefined' && typeof console.log === 'function') {\n console.log.apply(console, arguments);\n }\n }\n}\n\n/**\n * Shows a deprecation warning suggesting the modern and spec-compatible API.\n */\nexport function deprecated(oldMethod, newMethod) {\n if (!deprecationWarnings_) {\n return;\n }\n console.warn(oldMethod + ' is deprecated, please use ' + newMethod +\n ' instead.');\n}\n\n/**\n * Browser detector.\n *\n * @return {object} result containing browser and version\n * properties.\n */\nexport function detectBrowser(window) {\n // Returned result object.\n const result = {browser: null, version: null};\n\n // Fail early if it's not a browser\n if (typeof window === 'undefined' || !window.navigator) {\n result.browser = 'Not a browser.';\n return result;\n }\n\n const {navigator} = window;\n\n if (navigator.mozGetUserMedia) { // Firefox.\n result.browser = 'firefox';\n result.version = extractVersion(navigator.userAgent,\n /Firefox\\/(\\d+)\\./, 1);\n } else if (navigator.webkitGetUserMedia ||\n (window.isSecureContext === false && window.webkitRTCPeerConnection &&\n !window.RTCIceGatherer)) {\n // Chrome, Chromium, Webview, Opera.\n // Version matches Chrome/WebRTC version.\n // Chrome 74 removed webkitGetUserMedia on http as well so we need the\n // more complicated fallback to webkitRTCPeerConnection.\n result.browser = 'chrome';\n result.version = extractVersion(navigator.userAgent,\n /Chrom(e|ium)\\/(\\d+)\\./, 2);\n } else if (navigator.mediaDevices &&\n navigator.userAgent.match(/Edge\\/(\\d+).(\\d+)$/)) { // Edge.\n result.browser = 'edge';\n result.version = extractVersion(navigator.userAgent,\n /Edge\\/(\\d+).(\\d+)$/, 2);\n } else if (window.RTCPeerConnection &&\n navigator.userAgent.match(/AppleWebKit\\/(\\d+)\\./)) { // Safari.\n result.browser = 'safari';\n result.version = extractVersion(navigator.userAgent,\n /AppleWebKit\\/(\\d+)\\./, 1);\n result.supportsUnifiedPlan = window.RTCRtpTransceiver &&\n 'currentDirection' in window.RTCRtpTransceiver.prototype;\n } else { // Default fallthrough: not supported.\n result.browser = 'Not a supported browser.';\n return result;\n }\n\n return result;\n}\n\n/**\n * Checks if something is an object.\n *\n * @param {*} val The something you want to check.\n * @return true if val is an object, false otherwise.\n */\nfunction isObject(val) {\n return Object.prototype.toString.call(val) === '[object Object]';\n}\n\n/**\n * Remove all empty objects and undefined values\n * from a nested object -- an enhanced and vanilla version\n * of Lodash's `compact`.\n */\nexport function compactObject(data) {\n if (!isObject(data)) {\n return data;\n }\n\n return Object.keys(data).reduce(function(accumulator, key) {\n const isObj = isObject(data[key]);\n const value = isObj ? compactObject(data[key]) : data[key];\n const isEmptyObject = isObj && !Object.keys(value).length;\n if (value === undefined || isEmptyObject) {\n return accumulator;\n }\n return Object.assign(accumulator, {[key]: value});\n }, {});\n}\n\n/* iterates the stats graph recursively. */\nexport function walkStats(stats, base, resultSet) {\n if (!base || resultSet.has(base.id)) {\n return;\n }\n resultSet.set(base.id, base);\n Object.keys(base).forEach(name => {\n if (name.endsWith('Id')) {\n walkStats(stats, stats.get(base[name]), resultSet);\n } else if (name.endsWith('Ids')) {\n base[name].forEach(id => {\n walkStats(stats, stats.get(id), resultSet);\n });\n }\n });\n}\n\n/* filter getStats for a sender/receiver track. */\nexport function filterStats(result, track, outbound) {\n const streamStatsType = outbound ? 'outbound-rtp' : 'inbound-rtp';\n const filteredResult = new Map();\n if (track === null) {\n return filteredResult;\n }\n const trackStats = [];\n result.forEach(value => {\n if (value.type === 'track' &&\n value.trackIdentifier === track.id) {\n trackStats.push(value);\n }\n });\n trackStats.forEach(trackStat => {\n result.forEach(stats => {\n if (stats.type === streamStatsType && stats.trackId === trackStat.id) {\n walkStats(result, stats, filteredResult);\n }\n });\n });\n return filteredResult;\n}\n\n","/*\n * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n/* eslint-env node */\n'use strict';\nimport * as utils from '../utils.js';\nconst logging = utils.log;\n\nexport function shimGetUserMedia(window, browserDetails) {\n const navigator = window && window.navigator;\n\n if (!navigator.mediaDevices) {\n return;\n }\n\n const constraintsToChrome_ = function(c) {\n if (typeof c !== 'object' || c.mandatory || c.optional) {\n return c;\n }\n const cc = {};\n Object.keys(c).forEach(key => {\n if (key === 'require' || key === 'advanced' || key === 'mediaSource') {\n return;\n }\n const r = (typeof c[key] === 'object') ? c[key] : {ideal: c[key]};\n if (r.exact !== undefined && typeof r.exact === 'number') {\n r.min = r.max = r.exact;\n }\n const oldname_ = function(prefix, name) {\n if (prefix) {\n return prefix + name.charAt(0).toUpperCase() + name.slice(1);\n }\n return (name === 'deviceId') ? 'sourceId' : name;\n };\n if (r.ideal !== undefined) {\n cc.optional = cc.optional || [];\n let oc = {};\n if (typeof r.ideal === 'number') {\n oc[oldname_('min', key)] = r.ideal;\n cc.optional.push(oc);\n oc = {};\n oc[oldname_('max', key)] = r.ideal;\n cc.optional.push(oc);\n } else {\n oc[oldname_('', key)] = r.ideal;\n cc.optional.push(oc);\n }\n }\n if (r.exact !== undefined && typeof r.exact !== 'number') {\n cc.mandatory = cc.mandatory || {};\n cc.mandatory[oldname_('', key)] = r.exact;\n } else {\n ['min', 'max'].forEach(mix => {\n if (r[mix] !== undefined) {\n cc.mandatory = cc.mandatory || {};\n cc.mandatory[oldname_(mix, key)] = r[mix];\n }\n });\n }\n });\n if (c.advanced) {\n cc.optional = (cc.optional || []).concat(c.advanced);\n }\n return cc;\n };\n\n const shimConstraints_ = function(constraints, func) {\n if (browserDetails.version >= 61) {\n return func(constraints);\n }\n constraints = JSON.parse(JSON.stringify(constraints));\n if (constraints && typeof constraints.audio === 'object') {\n const remap = function(obj, a, b) {\n if (a in obj && !(b in obj)) {\n obj[b] = obj[a];\n delete obj[a];\n }\n };\n constraints = JSON.parse(JSON.stringify(constraints));\n remap(constraints.audio, 'autoGainControl', 'googAutoGainControl');\n remap(constraints.audio, 'noiseSuppression', 'googNoiseSuppression');\n constraints.audio = constraintsToChrome_(constraints.audio);\n }\n if (constraints && typeof constraints.video === 'object') {\n // Shim facingMode for mobile & surface pro.\n let face = constraints.video.facingMode;\n face = face && ((typeof face === 'object') ? face : {ideal: face});\n const getSupportedFacingModeLies = browserDetails.version < 66;\n\n if ((face && (face.exact === 'user' || face.exact === 'environment' ||\n face.ideal === 'user' || face.ideal === 'environment')) &&\n !(navigator.mediaDevices.getSupportedConstraints &&\n navigator.mediaDevices.getSupportedConstraints().facingMode &&\n !getSupportedFacingModeLies)) {\n delete constraints.video.facingMode;\n let matches;\n if (face.exact === 'environment' || face.ideal === 'environment') {\n matches = ['back', 'rear'];\n } else if (face.exact === 'user' || face.ideal === 'user') {\n matches = ['front'];\n }\n if (matches) {\n // Look for matches in label, or use last cam for back (typical).\n return navigator.mediaDevices.enumerateDevices()\n .then(devices => {\n devices = devices.filter(d => d.kind === 'videoinput');\n let dev = devices.find(d => matches.some(match =>\n d.label.toLowerCase().includes(match)));\n if (!dev && devices.length && matches.includes('back')) {\n dev = devices[devices.length - 1]; // more likely the back cam\n }\n if (dev) {\n constraints.video.deviceId = face.exact ? {exact: dev.deviceId} :\n {ideal: dev.deviceId};\n }\n constraints.video = constraintsToChrome_(constraints.video);\n logging('chrome: ' + JSON.stringify(constraints));\n return func(constraints);\n });\n }\n }\n constraints.video = constraintsToChrome_(constraints.video);\n }\n logging('chrome: ' + JSON.stringify(constraints));\n return func(constraints);\n };\n\n const shimError_ = function(e) {\n if (browserDetails.version >= 64) {\n return e;\n }\n return {\n name: {\n PermissionDeniedError: 'NotAllowedError',\n PermissionDismissedError: 'NotAllowedError',\n InvalidStateError: 'NotAllowedError',\n DevicesNotFoundError: 'NotFoundError',\n ConstraintNotSatisfiedError: 'OverconstrainedError',\n TrackStartError: 'NotReadableError',\n MediaDeviceFailedDueToShutdown: 'NotAllowedError',\n MediaDeviceKillSwitchOn: 'NotAllowedError',\n TabCaptureError: 'AbortError',\n ScreenCaptureError: 'AbortError',\n DeviceCaptureError: 'AbortError'\n }[e.name] || e.name,\n message: e.message,\n constraint: e.constraint || e.constraintName,\n toString() {\n return this.name + (this.message && ': ') + this.message;\n }\n };\n };\n\n const getUserMedia_ = function(constraints, onSuccess, onError) {\n shimConstraints_(constraints, c => {\n navigator.webkitGetUserMedia(c, onSuccess, e => {\n if (onError) {\n onError(shimError_(e));\n }\n });\n });\n };\n navigator.getUserMedia = getUserMedia_.bind(navigator);\n\n // Even though Chrome 45 has navigator.mediaDevices and a getUserMedia\n // function which returns a Promise, it does not accept spec-style\n // constraints.\n if (navigator.mediaDevices.getUserMedia) {\n const origGetUserMedia = navigator.mediaDevices.getUserMedia.\n bind(navigator.mediaDevices);\n navigator.mediaDevices.getUserMedia = function(cs) {\n return shimConstraints_(cs, c => origGetUserMedia(c).then(stream => {\n if (c.audio && !stream.getAudioTracks().length ||\n c.video && !stream.getVideoTracks().length) {\n stream.getTracks().forEach(track => {\n track.stop();\n });\n throw new DOMException('', 'NotFoundError');\n }\n return stream;\n }, e => Promise.reject(shimError_(e))));\n };\n }\n}\n","/*\n * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n/* eslint-env node */\n'use strict';\nexport function shimGetDisplayMedia(window, getSourceId) {\n if (window.navigator.mediaDevices &&\n 'getDisplayMedia' in window.navigator.mediaDevices) {\n return;\n }\n if (!(window.navigator.mediaDevices)) {\n return;\n }\n // getSourceId is a function that returns a promise resolving with\n // the sourceId of the screen/window/tab to be shared.\n if (typeof getSourceId !== 'function') {\n console.error('shimGetDisplayMedia: getSourceId argument is not ' +\n 'a function');\n return;\n }\n window.navigator.mediaDevices.getDisplayMedia =\n function getDisplayMedia(constraints) {\n return getSourceId(constraints)\n .then(sourceId => {\n const widthSpecified = constraints.video && constraints.video.width;\n const heightSpecified = constraints.video &&\n constraints.video.height;\n const frameRateSpecified = constraints.video &&\n constraints.video.frameRate;\n constraints.video = {\n mandatory: {\n chromeMediaSource: 'desktop',\n chromeMediaSourceId: sourceId,\n maxFrameRate: frameRateSpecified || 3\n }\n };\n if (widthSpecified) {\n constraints.video.mandatory.maxWidth = widthSpecified;\n }\n if (heightSpecified) {\n constraints.video.mandatory.maxHeight = heightSpecified;\n }\n return window.navigator.mediaDevices.getUserMedia(constraints);\n });\n };\n}\n","/*\n * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n /* eslint-env node */\n'use strict';\nimport * as utils from '../utils.js';\n\nexport {shimGetUserMedia} from './getusermedia';\nexport {shimGetDisplayMedia} from './getdisplaymedia';\n\nexport function shimMediaStream(window) {\n window.MediaStream = window.MediaStream || window.webkitMediaStream;\n}\n\nexport function shimOnTrack(window) {\n if (typeof window === 'object' && window.RTCPeerConnection && !('ontrack' in\n window.RTCPeerConnection.prototype)) {\n Object.defineProperty(window.RTCPeerConnection.prototype, 'ontrack', {\n get() {\n return this._ontrack;\n },\n set(f) {\n if (this._ontrack) {\n this.removeEventListener('track', this._ontrack);\n }\n this.addEventListener('track', this._ontrack = f);\n },\n enumerable: true,\n configurable: true\n });\n const origSetRemoteDescription =\n window.RTCPeerConnection.prototype.setRemoteDescription;\n window.RTCPeerConnection.prototype.setRemoteDescription =\n function setRemoteDescription() {\n if (!this._ontrackpoly) {\n this._ontrackpoly = (e) => {\n // onaddstream does not fire when a track is added to an existing\n // stream. But stream.onaddtrack is implemented so we use that.\n e.stream.addEventListener('addtrack', te => {\n let receiver;\n if (window.RTCPeerConnection.prototype.getReceivers) {\n receiver = this.getReceivers()\n .find(r => r.track && r.track.id === te.track.id);\n } else {\n receiver = {track: te.track};\n }\n\n const event = new Event('track');\n event.track = te.track;\n event.receiver = receiver;\n event.transceiver = {receiver};\n event.streams = [e.stream];\n this.dispatchEvent(event);\n });\n e.stream.getTracks().forEach(track => {\n let receiver;\n if (window.RTCPeerConnection.prototype.getReceivers) {\n receiver = this.getReceivers()\n .find(r => r.track && r.track.id === track.id);\n } else {\n receiver = {track};\n }\n const event = new Event('track');\n event.track = track;\n event.receiver = receiver;\n event.transceiver = {receiver};\n event.streams = [e.stream];\n this.dispatchEvent(event);\n });\n };\n this.addEventListener('addstream', this._ontrackpoly);\n }\n return origSetRemoteDescription.apply(this, arguments);\n };\n } else {\n // even if RTCRtpTransceiver is in window, it is only used and\n // emitted in unified-plan. Unfortunately this means we need\n // to unconditionally wrap the event.\n utils.wrapPeerConnectionEvent(window, 'track', e => {\n if (!e.transceiver) {\n Object.defineProperty(e, 'transceiver',\n {value: {receiver: e.receiver}});\n }\n return e;\n });\n }\n}\n\nexport function shimGetSendersWithDtmf(window) {\n // Overrides addTrack/removeTrack, depends on shimAddTrackRemoveTrack.\n if (typeof window === 'object' && window.RTCPeerConnection &&\n !('getSenders' in window.RTCPeerConnection.prototype) &&\n 'createDTMFSender' in window.RTCPeerConnection.prototype) {\n const shimSenderWithDtmf = function(pc, track) {\n return {\n track,\n get dtmf() {\n if (this._dtmf === undefined) {\n if (track.kind === 'audio') {\n this._dtmf = pc.createDTMFSender(track);\n } else {\n this._dtmf = null;\n }\n }\n return this._dtmf;\n },\n _pc: pc\n };\n };\n\n // augment addTrack when getSenders is not available.\n if (!window.RTCPeerConnection.prototype.getSenders) {\n window.RTCPeerConnection.prototype.getSenders = function getSenders() {\n this._senders = this._senders || [];\n return this._senders.slice(); // return a copy of the internal state.\n };\n const origAddTrack = window.RTCPeerConnection.prototype.addTrack;\n window.RTCPeerConnection.prototype.addTrack =\n function addTrack(track, stream) {\n let sender = origAddTrack.apply(this, arguments);\n if (!sender) {\n sender = shimSenderWithDtmf(this, track);\n this._senders.push(sender);\n }\n return sender;\n };\n\n const origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;\n window.RTCPeerConnection.prototype.removeTrack =\n function removeTrack(sender) {\n origRemoveTrack.apply(this, arguments);\n const idx = this._senders.indexOf(sender);\n if (idx !== -1) {\n this._senders.splice(idx, 1);\n }\n };\n }\n const origAddStream = window.RTCPeerConnection.prototype.addStream;\n window.RTCPeerConnection.prototype.addStream = function addStream(stream) {\n this._senders = this._senders || [];\n origAddStream.apply(this, [stream]);\n stream.getTracks().forEach(track => {\n this._senders.push(shimSenderWithDtmf(this, track));\n });\n };\n\n const origRemoveStream = window.RTCPeerConnection.prototype.removeStream;\n window.RTCPeerConnection.prototype.removeStream =\n function removeStream(stream) {\n this._senders = this._senders || [];\n origRemoveStream.apply(this, [stream]);\n\n stream.getTracks().forEach(track => {\n const sender = this._senders.find(s => s.track === track);\n if (sender) { // remove sender\n this._senders.splice(this._senders.indexOf(sender), 1);\n }\n });\n };\n } else if (typeof window === 'object' && window.RTCPeerConnection &&\n 'getSenders' in window.RTCPeerConnection.prototype &&\n 'createDTMFSender' in window.RTCPeerConnection.prototype &&\n window.RTCRtpSender &&\n !('dtmf' in window.RTCRtpSender.prototype)) {\n const origGetSenders = window.RTCPeerConnection.prototype.getSenders;\n window.RTCPeerConnection.prototype.getSenders = function getSenders() {\n const senders = origGetSenders.apply(this, []);\n senders.forEach(sender => sender._pc = this);\n return senders;\n };\n\n Object.defineProperty(window.RTCRtpSender.prototype, 'dtmf', {\n get() {\n if (this._dtmf === undefined) {\n if (this.track.kind === 'audio') {\n this._dtmf = this._pc.createDTMFSender(this.track);\n } else {\n this._dtmf = null;\n }\n }\n return this._dtmf;\n }\n });\n }\n}\n\nexport function shimGetStats(window) {\n if (!window.RTCPeerConnection) {\n return;\n }\n\n const origGetStats = window.RTCPeerConnection.prototype.getStats;\n window.RTCPeerConnection.prototype.getStats = function getStats() {\n const [selector, onSucc, onErr] = arguments;\n\n // If selector is a function then we are in the old style stats so just\n // pass back the original getStats format to avoid breaking old users.\n if (arguments.length > 0 && typeof selector === 'function') {\n return origGetStats.apply(this, arguments);\n }\n\n // When spec-style getStats is supported, return those when called with\n // either no arguments or the selector argument is null.\n if (origGetStats.length === 0 && (arguments.length === 0 ||\n typeof selector !== 'function')) {\n return origGetStats.apply(this, []);\n }\n\n const fixChromeStats_ = function(response) {\n const standardReport = {};\n const reports = response.result();\n reports.forEach(report => {\n const standardStats = {\n id: report.id,\n timestamp: report.timestamp,\n type: {\n localcandidate: 'local-candidate',\n remotecandidate: 'remote-candidate'\n }[report.type] || report.type\n };\n report.names().forEach(name => {\n standardStats[name] = report.stat(name);\n });\n standardReport[standardStats.id] = standardStats;\n });\n\n return standardReport;\n };\n\n // shim getStats with maplike support\n const makeMapStats = function(stats) {\n return new Map(Object.keys(stats).map(key => [key, stats[key]]));\n };\n\n if (arguments.length >= 2) {\n const successCallbackWrapper_ = function(response) {\n onSucc(makeMapStats(fixChromeStats_(response)));\n };\n\n return origGetStats.apply(this, [successCallbackWrapper_,\n selector]);\n }\n\n // promise-support\n return new Promise((resolve, reject) => {\n origGetStats.apply(this, [\n function(response) {\n resolve(makeMapStats(fixChromeStats_(response)));\n }, reject]);\n }).then(onSucc, onErr);\n };\n}\n\nexport function shimSenderReceiverGetStats(window) {\n if (!(typeof window === 'object' && window.RTCPeerConnection &&\n window.RTCRtpSender && window.RTCRtpReceiver)) {\n return;\n }\n\n // shim sender stats.\n if (!('getStats' in window.RTCRtpSender.prototype)) {\n const origGetSenders = window.RTCPeerConnection.prototype.getSenders;\n if (origGetSenders) {\n window.RTCPeerConnection.prototype.getSenders = function getSenders() {\n const senders = origGetSenders.apply(this, []);\n senders.forEach(sender => sender._pc = this);\n return senders;\n };\n }\n\n const origAddTrack = window.RTCPeerConnection.prototype.addTrack;\n if (origAddTrack) {\n window.RTCPeerConnection.prototype.addTrack = function addTrack() {\n const sender = origAddTrack.apply(this, arguments);\n sender._pc = this;\n return sender;\n };\n }\n window.RTCRtpSender.prototype.getStats = function getStats() {\n const sender = this;\n return this._pc.getStats().then(result =>\n /* Note: this will include stats of all senders that\n * send a track with the same id as sender.track as\n * it is not possible to identify the RTCRtpSender.\n */\n utils.filterStats(result, sender.track, true));\n };\n }\n\n // shim receiver stats.\n if (!('getStats' in window.RTCRtpReceiver.prototype)) {\n const origGetReceivers = window.RTCPeerConnection.prototype.getReceivers;\n if (origGetReceivers) {\n window.RTCPeerConnection.prototype.getReceivers =\n function getReceivers() {\n const receivers = origGetReceivers.apply(this, []);\n receivers.forEach(receiver => receiver._pc = this);\n return receivers;\n };\n }\n utils.wrapPeerConnectionEvent(window, 'track', e => {\n e.receiver._pc = e.srcElement;\n return e;\n });\n window.RTCRtpReceiver.prototype.getStats = function getStats() {\n const receiver = this;\n return this._pc.getStats().then(result =>\n utils.filterStats(result, receiver.track, false));\n };\n }\n\n if (!('getStats' in window.RTCRtpSender.prototype &&\n 'getStats' in window.RTCRtpReceiver.prototype)) {\n return;\n }\n\n // shim RTCPeerConnection.getStats(track).\n const origGetStats = window.RTCPeerConnection.prototype.getStats;\n window.RTCPeerConnection.prototype.getStats = function getStats() {\n if (arguments.length > 0 &&\n arguments[0] instanceof window.MediaStreamTrack) {\n const track = arguments[0];\n let sender;\n let receiver;\n let err;\n this.getSenders().forEach(s => {\n if (s.track === track) {\n if (sender) {\n err = true;\n } else {\n sender = s;\n }\n }\n });\n this.getReceivers().forEach(r => {\n if (r.track === track) {\n if (receiver) {\n err = true;\n } else {\n receiver = r;\n }\n }\n return r.track === track;\n });\n if (err || (sender && receiver)) {\n return Promise.reject(new DOMException(\n 'There are more than one sender or receiver for the track.',\n 'InvalidAccessError'));\n } else if (sender) {\n return sender.getStats();\n } else if (receiver) {\n return receiver.getStats();\n }\n return Promise.reject(new DOMException(\n 'There is no sender or receiver for the track.',\n 'InvalidAccessError'));\n }\n return origGetStats.apply(this, arguments);\n };\n}\n\nexport function shimAddTrackRemoveTrackWithNative(window) {\n // shim addTrack/removeTrack with native variants in order to make\n // the interactions with legacy getLocalStreams behave as in other browsers.\n // Keeps a mapping stream.id => [stream, rtpsenders...]\n window.RTCPeerConnection.prototype.getLocalStreams =\n function getLocalStreams() {\n this._shimmedLocalStreams = this._shimmedLocalStreams || {};\n return Object.keys(this._shimmedLocalStreams)\n .map(streamId => this._shimmedLocalStreams[streamId][0]);\n };\n\n const origAddTrack = window.RTCPeerConnection.prototype.addTrack;\n window.RTCPeerConnection.prototype.addTrack =\n function addTrack(track, stream) {\n if (!stream) {\n return origAddTrack.apply(this, arguments);\n }\n this._shimmedLocalStreams = this._shimmedLocalStreams || {};\n\n const sender = origAddTrack.apply(this, arguments);\n if (!this._shimmedLocalStreams[stream.id]) {\n this._shimmedLocalStreams[stream.id] = [stream, sender];\n } else if (this._shimmedLocalStreams[stream.id].indexOf(sender) === -1) {\n this._shimmedLocalStreams[stream.id].push(sender);\n }\n return sender;\n };\n\n const origAddStream = window.RTCPeerConnection.prototype.addStream;\n window.RTCPeerConnection.prototype.addStream = function addStream(stream) {\n this._shimmedLocalStreams = this._shimmedLocalStreams || {};\n\n stream.getTracks().forEach(track => {\n const alreadyExists = this.getSenders().find(s => s.track === track);\n if (alreadyExists) {\n throw new DOMException('Track already exists.',\n 'InvalidAccessError');\n }\n });\n const existingSenders = this.getSenders();\n origAddStream.apply(this, arguments);\n const newSenders = this.getSenders()\n .filter(newSender => existingSenders.indexOf(newSender) === -1);\n this._shimmedLocalStreams[stream.id] = [stream].concat(newSenders);\n };\n\n const origRemoveStream = window.RTCPeerConnection.prototype.removeStream;\n window.RTCPeerConnection.prototype.removeStream =\n function removeStream(stream) {\n this._shimmedLocalStreams = this._shimmedLocalStreams || {};\n delete this._shimmedLocalStreams[stream.id];\n return origRemoveStream.apply(this, arguments);\n };\n\n const origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;\n window.RTCPeerConnection.prototype.removeTrack =\n function removeTrack(sender) {\n this._shimmedLocalStreams = this._shimmedLocalStreams || {};\n if (sender) {\n Object.keys(this._shimmedLocalStreams).forEach(streamId => {\n const idx = this._shimmedLocalStreams[streamId].indexOf(sender);\n if (idx !== -1) {\n this._shimmedLocalStreams[streamId].splice(idx, 1);\n }\n if (this._shimmedLocalStreams[streamId].length === 1) {\n delete this._shimmedLocalStreams[streamId];\n }\n });\n }\n return origRemoveTrack.apply(this, arguments);\n };\n}\n\nexport function shimAddTrackRemoveTrack(window, browserDetails) {\n if (!window.RTCPeerConnection) {\n return;\n }\n // shim addTrack and removeTrack.\n if (window.RTCPeerConnection.prototype.addTrack &&\n browserDetails.version >= 65) {\n return shimAddTrackRemoveTrackWithNative(window);\n }\n\n // also shim pc.getLocalStreams when addTrack is shimmed\n // to return the original streams.\n const origGetLocalStreams = window.RTCPeerConnection.prototype\n .getLocalStreams;\n window.RTCPeerConnection.prototype.getLocalStreams =\n function getLocalStreams() {\n const nativeStreams = origGetLocalStreams.apply(this);\n this._reverseStreams = this._reverseStreams || {};\n return nativeStreams.map(stream => this._reverseStreams[stream.id]);\n };\n\n const origAddStream = window.RTCPeerConnection.prototype.addStream;\n window.RTCPeerConnection.prototype.addStream = function addStream(stream) {\n this._streams = this._streams || {};\n this._reverseStreams = this._reverseStreams || {};\n\n stream.getTracks().forEach(track => {\n const alreadyExists = this.getSenders().find(s => s.track === track);\n if (alreadyExists) {\n throw new DOMException('Track already exists.',\n 'InvalidAccessError');\n }\n });\n // Add identity mapping for consistency with addTrack.\n // Unless this is being used with a stream from addTrack.\n if (!this._reverseStreams[stream.id]) {\n const newStream = new window.MediaStream(stream.getTracks());\n this._streams[stream.id] = newStream;\n this._reverseStreams[newStream.id] = stream;\n stream = newStream;\n }\n origAddStream.apply(this, [stream]);\n };\n\n const origRemoveStream = window.RTCPeerConnection.prototype.removeStream;\n window.RTCPeerConnection.prototype.removeStream =\n function removeStream(stream) {\n this._streams = this._streams || {};\n this._reverseStreams = this._reverseStreams || {};\n\n origRemoveStream.apply(this, [(this._streams[stream.id] || stream)]);\n delete this._reverseStreams[(this._streams[stream.id] ?\n this._streams[stream.id].id : stream.id)];\n delete this._streams[stream.id];\n };\n\n window.RTCPeerConnection.prototype.addTrack =\n function addTrack(track, stream) {\n if (this.signalingState === 'closed') {\n throw new DOMException(\n 'The RTCPeerConnection\\'s signalingState is \\'closed\\'.',\n 'InvalidStateError');\n }\n const streams = [].slice.call(arguments, 1);\n if (streams.length !== 1 ||\n !streams[0].getTracks().find(t => t === track)) {\n // this is not fully correct but all we can manage without\n // [[associated MediaStreams]] internal slot.\n throw new DOMException(\n 'The adapter.js addTrack polyfill only supports a single ' +\n ' stream which is associated with the specified track.',\n 'NotSupportedError');\n }\n\n const alreadyExists = this.getSenders().find(s => s.track === track);\n if (alreadyExists) {\n throw new DOMException('Track already exists.',\n 'InvalidAccessError');\n }\n\n this._streams = this._streams || {};\n this._reverseStreams = this._reverseStreams || {};\n const oldStream = this._streams[stream.id];\n if (oldStream) {\n // this is using odd Chrome behaviour, use with caution:\n // https://bugs.chromium.org/p/webrtc/issues/detail?id=7815\n // Note: we rely on the high-level addTrack/dtmf shim to\n // create the sender with a dtmf sender.\n oldStream.addTrack(track);\n\n // Trigger ONN async.\n Promise.resolve().then(() => {\n this.dispatchEvent(new Event('negotiationneeded'));\n });\n } else {\n const newStream = new window.MediaStream([track]);\n this._streams[stream.id] = newStream;\n this._reverseStreams[newStream.id] = stream;\n this.addStream(newStream);\n }\n return this.getSenders().find(s => s.track === track);\n };\n\n // replace the internal stream id with the external one and\n // vice versa.\n function replaceInternalStreamId(pc, description) {\n let sdp = description.sdp;\n Object.keys(pc._reverseStreams || []).forEach(internalId => {\n const externalStream = pc._reverseStreams[internalId];\n const internalStream = pc._streams[externalStream.id];\n sdp = sdp.replace(new RegExp(internalStream.id, 'g'),\n externalStream.id);\n });\n return new RTCSessionDescription({\n type: description.type,\n sdp\n });\n }\n function replaceExternalStreamId(pc, description) {\n let sdp = description.sdp;\n Object.keys(pc._reverseStreams || []).forEach(internalId => {\n const externalStream = pc._reverseStreams[internalId];\n const internalStream = pc._streams[externalStream.id];\n sdp = sdp.replace(new RegExp(externalStream.id, 'g'),\n internalStream.id);\n });\n return new RTCSessionDescription({\n type: description.type,\n sdp\n });\n }\n ['createOffer', 'createAnswer'].forEach(function(method) {\n const nativeMethod = window.RTCPeerConnection.prototype[method];\n const methodObj = {[method]() {\n const args = arguments;\n const isLegacyCall = arguments.length &&\n typeof arguments[0] === 'function';\n if (isLegacyCall) {\n return nativeMethod.apply(this, [\n (description) => {\n const desc = replaceInternalStreamId(this, description);\n args[0].apply(null, [desc]);\n },\n (err) => {\n if (args[1]) {\n args[1].apply(null, err);\n }\n }, arguments[2]\n ]);\n }\n return nativeMethod.apply(this, arguments)\n .then(description => replaceInternalStreamId(this, description));\n }};\n window.RTCPeerConnection.prototype[method] = methodObj[method];\n });\n\n const origSetLocalDescription =\n window.RTCPeerConnection.prototype.setLocalDescription;\n window.RTCPeerConnection.prototype.setLocalDescription =\n function setLocalDescription() {\n if (!arguments.length || !arguments[0].type) {\n return origSetLocalDescription.apply(this, arguments);\n }\n arguments[0] = replaceExternalStreamId(this, arguments[0]);\n return origSetLocalDescription.apply(this, arguments);\n };\n\n // TODO: mangle getStats: https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamstats-streamidentifier\n\n const origLocalDescription = Object.getOwnPropertyDescriptor(\n window.RTCPeerConnection.prototype, 'localDescription');\n Object.defineProperty(window.RTCPeerConnection.prototype,\n 'localDescription', {\n get() {\n const description = origLocalDescription.get.apply(this);\n if (description.type === '') {\n return description;\n }\n return replaceInternalStreamId(this, description);\n }\n });\n\n window.RTCPeerConnection.prototype.removeTrack =\n function removeTrack(sender) {\n if (this.signalingState === 'closed') {\n throw new DOMException(\n 'The RTCPeerConnection\\'s signalingState is \\'closed\\'.',\n 'InvalidStateError');\n }\n // We can not yet check for sender instanceof RTCRtpSender\n // since we shim RTPSender. So we check if sender._pc is set.\n if (!sender._pc) {\n throw new DOMException('Argument 1 of RTCPeerConnection.removeTrack ' +\n 'does not implement interface RTCRtpSender.', 'TypeError');\n }\n const isLocal = sender._pc === this;\n if (!isLocal) {\n throw new DOMException('Sender was not created by this connection.',\n 'InvalidAccessError');\n }\n\n // Search for the native stream the senders track belongs to.\n this._streams = this._streams || {};\n let stream;\n Object.keys(this._streams).forEach(streamid => {\n const hasTrack = this._streams[streamid].getTracks()\n .find(track => sender.track === track);\n if (hasTrack) {\n stream = this._streams[streamid];\n }\n });\n\n if (stream) {\n if (stream.getTracks().length === 1) {\n // if this is the last track of the stream, remove the stream. This\n // takes care of any shimmed _senders.\n this.removeStream(this._reverseStreams[stream.id]);\n } else {\n // relying on the same odd chrome behaviour as above.\n stream.removeTrack(sender.track);\n }\n this.dispatchEvent(new Event('negotiationneeded'));\n }\n };\n}\n\nexport function shimPeerConnection(window, browserDetails) {\n if (!window.RTCPeerConnection && window.webkitRTCPeerConnection) {\n // very basic support for old versions.\n window.RTCPeerConnection = window.webkitRTCPeerConnection;\n }\n if (!window.RTCPeerConnection) {\n return;\n }\n\n // shim implicit creation of RTCSessionDescription/RTCIceCandidate\n if (browserDetails.version < 53) {\n ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate']\n .forEach(function(method) {\n const nativeMethod = window.RTCPeerConnection.prototype[method];\n const methodObj = {[method]() {\n arguments[0] = new ((method === 'addIceCandidate') ?\n window.RTCIceCandidate :\n window.RTCSessionDescription)(arguments[0]);\n return nativeMethod.apply(this, arguments);\n }};\n window.RTCPeerConnection.prototype[method] = methodObj[method];\n });\n }\n}\n\n// Attempt to fix ONN in plan-b mode.\nexport function fixNegotiationNeeded(window, browserDetails) {\n utils.wrapPeerConnectionEvent(window, 'negotiationneeded', e => {\n const pc = e.target;\n if (browserDetails.version < 72 || (pc.getConfiguration &&\n pc.getConfiguration().sdpSemantics === 'plan-b')) {\n if (pc.signalingState !== 'stable') {\n return;\n }\n }\n return e;\n });\n}\n","/*\n * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n/* eslint-env node */\n'use strict';\n\nimport * as utils from '../utils';\n// Edge does not like\n// 1) stun: filtered after 14393 unless ?transport=udp is present\n// 2) turn: that does not have all of turn:host:port?transport=udp\n// 3) turn: with ipv6 addresses\n// 4) turn: occurring muliple times\nexport function filterIceServers(iceServers, edgeVersion) {\n let hasTurn = false;\n iceServers = JSON.parse(JSON.stringify(iceServers));\n return iceServers.filter(server => {\n if (server && (server.urls || server.url)) {\n let urls = server.urls || server.url;\n if (server.url && !server.urls) {\n utils.deprecated('RTCIceServer.url', 'RTCIceServer.urls');\n }\n const isString = typeof urls === 'string';\n if (isString) {\n urls = [urls];\n }\n urls = urls.filter(url => {\n // filter STUN unconditionally.\n if (url.indexOf('stun:') === 0) {\n return false;\n }\n\n const validTurn = url.startsWith('turn') &&\n !url.startsWith('turn:[') &&\n url.includes('transport=udp');\n if (validTurn && !hasTurn) {\n hasTurn = true;\n return true;\n }\n return validTurn && !hasTurn;\n });\n\n delete server.url;\n server.urls = isString ? urls[0] : urls;\n return !!urls.length;\n }\n });\n}\n","/* eslint-env node */\n'use strict';\n\n// SDP helpers.\nvar SDPUtils = {};\n\n// Generate an alphanumeric identifier for cname or mids.\n// TODO: use UUIDs instead? https://gist.github.com/jed/982883\nSDPUtils.generateIdentifier = function() {\n return Math.random().toString(36).substr(2, 10);\n};\n\n// The RTCP CNAME used by all peerconnections from the same JS.\nSDPUtils.localCName = SDPUtils.generateIdentifier();\n\n// Splits SDP into lines, dealing with both CRLF and LF.\nSDPUtils.splitLines = function(blob) {\n return blob.trim().split('\\n').map(function(line) {\n return line.trim();\n });\n};\n// Splits SDP into sessionpart and mediasections. Ensures CRLF.\nSDPUtils.splitSections = function(blob) {\n var parts = blob.split('\\nm=');\n return parts.map(function(part, index) {\n return (index > 0 ? 'm=' + part : part).trim() + '\\r\\n';\n });\n};\n\n// returns the session description.\nSDPUtils.getDescription = function(blob) {\n var sections = SDPUtils.splitSections(blob);\n return sections && sections[0];\n};\n\n// returns the individual media sections.\nSDPUtils.getMediaSections = function(blob) {\n var sections = SDPUtils.splitSections(blob);\n sections.shift();\n return sections;\n};\n\n// Returns lines that start with a certain prefix.\nSDPUtils.matchPrefix = function(blob, prefix) {\n return SDPUtils.splitLines(blob).filter(function(line) {\n return line.indexOf(prefix) === 0;\n });\n};\n\n// Parses an ICE candidate line. Sample input:\n// candidate:702786350 2 udp 41819902 8.8.8.8 60769 typ relay raddr 8.8.8.8\n// rport 55996\"\nSDPUtils.parseCandidate = function(line) {\n var parts;\n // Parse both variants.\n if (line.indexOf('a=candidate:') === 0) {\n parts = line.substring(12).split(' ');\n } else {\n parts = line.substring(10).split(' ');\n }\n\n var candidate = {\n foundation: parts[0],\n component: parseInt(parts[1], 10),\n protocol: parts[2].toLowerCase(),\n priority: parseInt(parts[3], 10),\n ip: parts[4],\n address: parts[4], // address is an alias for ip.\n port: parseInt(parts[5], 10),\n // skip parts[6] == 'typ'\n type: parts[7]\n };\n\n for (var i = 8; i < parts.length; i += 2) {\n switch (parts[i]) {\n case 'raddr':\n candidate.relatedAddress = parts[i + 1];\n break;\n case 'rport':\n candidate.relatedPort = parseInt(parts[i + 1], 10);\n break;\n case 'tcptype':\n candidate.tcpType = parts[i + 1];\n break;\n case 'ufrag':\n candidate.ufrag = parts[i + 1]; // for backward compability.\n candidate.usernameFragment = parts[i + 1];\n break;\n default: // extension handling, in particular ufrag\n candidate[parts[i]] = parts[i + 1];\n break;\n }\n }\n return candidate;\n};\n\n// Translates a candidate object into SDP candidate attribute.\nSDPUtils.writeCandidate = function(candidate) {\n var sdp = [];\n sdp.push(candidate.foundation);\n sdp.push(candidate.component);\n sdp.push(candidate.protocol.toUpperCase());\n sdp.push(candidate.priority);\n sdp.push(candidate.address || candidate.ip);\n sdp.push(candidate.port);\n\n var type = candidate.type;\n sdp.push('typ');\n sdp.push(type);\n if (type !== 'host' && candidate.relatedAddress &&\n candidate.relatedPort) {\n sdp.push('raddr');\n sdp.push(candidate.relatedAddress);\n sdp.push('rport');\n sdp.push(candidate.relatedPort);\n }\n if (candidate.tcpType && candidate.protocol.toLowerCase() === 'tcp') {\n sdp.push('tcptype');\n sdp.push(candidate.tcpType);\n }\n if (candidate.usernameFragment || candidate.ufrag) {\n sdp.push('ufrag');\n sdp.push(candidate.usernameFragment || candidate.ufrag);\n }\n return 'candidate:' + sdp.join(' ');\n};\n\n// Parses an ice-options line, returns an array of option tags.\n// a=ice-options:foo bar\nSDPUtils.parseIceOptions = function(line) {\n return line.substr(14).split(' ');\n};\n\n// Parses an rtpmap line, returns RTCRtpCoddecParameters. Sample input:\n// a=rtpmap:111 opus/48000/2\nSDPUtils.parseRtpMap = function(line) {\n var parts = line.substr(9).split(' ');\n var parsed = {\n payloadType: parseInt(parts.shift(), 10) // was: id\n };\n\n parts = parts[0].split('/');\n\n parsed.name = parts[0];\n parsed.clockRate = parseInt(parts[1], 10); // was: clockrate\n parsed.channels = parts.length === 3 ? parseInt(parts[2], 10) : 1;\n // legacy alias, got renamed back to channels in ORTC.\n parsed.numChannels = parsed.channels;\n return parsed;\n};\n\n// Generate an a=rtpmap line from RTCRtpCodecCapability or\n// RTCRtpCodecParameters.\nSDPUtils.writeRtpMap = function(codec) {\n var pt = codec.payloadType;\n if (codec.preferredPayloadType !== undefined) {\n pt = codec.preferredPayloadType;\n }\n var channels = codec.channels || codec.numChannels || 1;\n return 'a=rtpmap:' + pt + ' ' + codec.name + '/' + codec.clockRate +\n (channels !== 1 ? '/' + channels : '') + '\\r\\n';\n};\n\n// Parses an a=extmap line (headerextension from RFC 5285). Sample input:\n// a=extmap:2 urn:ietf:params:rtp-hdrext:toffset\n// a=extmap:2/sendonly urn:ietf:params:rtp-hdrext:toffset\nSDPUtils.parseExtmap = function(line) {\n var parts = line.substr(9).split(' ');\n return {\n id: parseInt(parts[0], 10),\n direction: parts[0].indexOf('/') > 0 ? parts[0].split('/')[1] : 'sendrecv',\n uri: parts[1]\n };\n};\n\n// Generates a=extmap line from RTCRtpHeaderExtensionParameters or\n// RTCRtpHeaderExtension.\nSDPUtils.writeExtmap = function(headerExtension) {\n return 'a=extmap:' + (headerExtension.id || headerExtension.preferredId) +\n (headerExtension.direction && headerExtension.direction !== 'sendrecv'\n ? '/' + headerExtension.direction\n : '') +\n ' ' + headerExtension.uri + '\\r\\n';\n};\n\n// Parses an ftmp line, returns dictionary. Sample input:\n// a=fmtp:96 vbr=on;cng=on\n// Also deals with vbr=on; cng=on\nSDPUtils.parseFmtp = function(line) {\n var parsed = {};\n var kv;\n var parts = line.substr(line.indexOf(' ') + 1).split(';');\n for (var j = 0; j < parts.length; j++) {\n kv = parts[j].trim().split('=');\n parsed[kv[0].trim()] = kv[1];\n }\n return parsed;\n};\n\n// Generates an a=ftmp line from RTCRtpCodecCapability or RTCRtpCodecParameters.\nSDPUtils.writeFmtp = function(codec) {\n var line = '';\n var pt = codec.payloadType;\n if (codec.preferredPayloadType !== undefined) {\n pt = codec.preferredPayloadType;\n }\n if (codec.parameters && Object.keys(codec.parameters).length) {\n var params = [];\n Object.keys(codec.parameters).forEach(function(param) {\n if (codec.parameters[param]) {\n params.push(param + '=' + codec.parameters[param]);\n } else {\n params.push(param);\n }\n });\n line += 'a=fmtp:' + pt + ' ' + params.join(';') + '\\r\\n';\n }\n return line;\n};\n\n// Parses an rtcp-fb line, returns RTCPRtcpFeedback object. Sample input:\n// a=rtcp-fb:98 nack rpsi\nSDPUtils.parseRtcpFb = function(line) {\n var parts = line.substr(line.indexOf(' ') + 1).split(' ');\n return {\n type: parts.shift(),\n parameter: parts.join(' ')\n };\n};\n// Generate a=rtcp-fb lines from RTCRtpCodecCapability or RTCRtpCodecParameters.\nSDPUtils.writeRtcpFb = function(codec) {\n var lines = '';\n var pt = codec.payloadType;\n if (codec.preferredPayloadType !== undefined) {\n pt = codec.preferredPayloadType;\n }\n if (codec.rtcpFeedback && codec.rtcpFeedback.length) {\n // FIXME: special handling for trr-int?\n codec.rtcpFeedback.forEach(function(fb) {\n lines += 'a=rtcp-fb:' + pt + ' ' + fb.type +\n (fb.parameter && fb.parameter.length ? ' ' + fb.parameter : '') +\n '\\r\\n';\n });\n }\n return lines;\n};\n\n// Parses an RFC 5576 ssrc media attribute. Sample input:\n// a=ssrc:3735928559 cname:something\nSDPUtils.parseSsrcMedia = function(line) {\n var sp = line.indexOf(' ');\n var parts = {\n ssrc: parseInt(line.substr(7, sp - 7), 10)\n };\n var colon = line.indexOf(':', sp);\n if (colon > -1) {\n parts.attribute = line.substr(sp + 1, colon - sp - 1);\n parts.value = line.substr(colon + 1);\n } else {\n parts.attribute = line.substr(sp + 1);\n }\n return parts;\n};\n\nSDPUtils.parseSsrcGroup = function(line) {\n var parts = line.substr(13).split(' ');\n return {\n semantics: parts.shift(),\n ssrcs: parts.map(function(ssrc) {\n return parseInt(ssrc, 10);\n })\n };\n};\n\n// Extracts the MID (RFC 5888) from a media section.\n// returns the MID or undefined if no mid line was found.\nSDPUtils.getMid = function(mediaSection) {\n var mid = SDPUtils.matchPrefix(mediaSection, 'a=mid:')[0];\n if (mid) {\n return mid.substr(6);\n }\n};\n\nSDPUtils.parseFingerprint = function(line) {\n var parts = line.substr(14).split(' ');\n return {\n algorithm: parts[0].toLowerCase(), // algorithm is case-sensitive in Edge.\n value: parts[1]\n };\n};\n\n// Extracts DTLS parameters from SDP media section or sessionpart.\n// FIXME: for consistency with other functions this should only\n// get the fingerprint line as input. See also getIceParameters.\nSDPUtils.getDtlsParameters = function(mediaSection, sessionpart) {\n var lines = SDPUtils.matchPrefix(mediaSection + sessionpart,\n 'a=fingerprint:');\n // Note: a=setup line is ignored since we use the 'auto' role.\n // Note2: 'algorithm' is not case sensitive except in Edge.\n return {\n role: 'auto',\n fingerprints: lines.map(SDPUtils.parseFingerprint)\n };\n};\n\n// Serializes DTLS parameters to SDP.\nSDPUtils.writeDtlsParameters = function(params, setupType) {\n var sdp = 'a=setup:' + setupType + '\\r\\n';\n params.fingerprints.forEach(function(fp) {\n sdp += 'a=fingerprint:' + fp.algorithm + ' ' + fp.value + '\\r\\n';\n });\n return sdp;\n};\n\n// Parses a=crypto lines into\n// https://rawgit.com/aboba/edgertc/master/msortc-rs4.html#dictionary-rtcsrtpsdesparameters-members\nSDPUtils.parseCryptoLine = function(line) {\n var parts = line.substr(9).split(' ');\n return {\n tag: parseInt(parts[0], 10),\n cryptoSuite: parts[1],\n keyParams: parts[2],\n sessionParams: parts.slice(3),\n };\n};\n\nSDPUtils.writeCryptoLine = function(parameters) {\n return 'a=crypto:' + parameters.tag + ' ' +\n parameters.cryptoSuite + ' ' +\n (typeof parameters.keyParams === 'object'\n ? SDPUtils.writeCryptoKeyParams(parameters.keyParams)\n : parameters.keyParams) +\n (parameters.sessionParams ? ' ' + parameters.sessionParams.join(' ') : '') +\n '\\r\\n';\n};\n\n// Parses the crypto key parameters into\n// https://rawgit.com/aboba/edgertc/master/msortc-rs4.html#rtcsrtpkeyparam*\nSDPUtils.parseCryptoKeyParams = function(keyParams) {\n if (keyParams.indexOf('inline:') !== 0) {\n return null;\n }\n var parts = keyParams.substr(7).split('|');\n return {\n keyMethod: 'inline',\n keySalt: parts[0],\n lifeTime: parts[1],\n mkiValue: parts[2] ? parts[2].split(':')[0] : undefined,\n mkiLength: parts[2] ? parts[2].split(':')[1] : undefined,\n };\n};\n\nSDPUtils.writeCryptoKeyParams = function(keyParams) {\n return keyParams.keyMethod + ':'\n + keyParams.keySalt +\n (keyParams.lifeTime ? '|' + keyParams.lifeTime : '') +\n (keyParams.mkiValue && keyParams.mkiLength\n ? '|' + keyParams.mkiValue + ':' + keyParams.mkiLength\n : '');\n};\n\n// Extracts all SDES paramters.\nSDPUtils.getCryptoParameters = function(mediaSection, sessionpart) {\n var lines = SDPUtils.matchPrefix(mediaSection + sessionpart,\n 'a=crypto:');\n return lines.map(SDPUtils.parseCryptoLine);\n};\n\n// Parses ICE information from SDP media section or sessionpart.\n// FIXME: for consistency with other functions this should only\n// get the ice-ufrag and ice-pwd lines as input.\nSDPUtils.getIceParameters = function(mediaSection, sessionpart) {\n var ufrag = SDPUtils.matchPrefix(mediaSection + sessionpart,\n 'a=ice-ufrag:')[0];\n var pwd = SDPUtils.matchPrefix(mediaSection + sessionpart,\n 'a=ice-pwd:')[0];\n if (!(ufrag && pwd)) {\n return null;\n }\n return {\n usernameFragment: ufrag.substr(12),\n password: pwd.substr(10),\n };\n};\n\n// Serializes ICE parameters to SDP.\nSDPUtils.writeIceParameters = function(params) {\n return 'a=ice-ufrag:' + params.usernameFragment + '\\r\\n' +\n 'a=ice-pwd:' + params.password + '\\r\\n';\n};\n\n// Parses the SDP media section and returns RTCRtpParameters.\nSDPUtils.parseRtpParameters = function(mediaSection) {\n var description = {\n codecs: [],\n headerExtensions: [],\n fecMechanisms: [],\n rtcp: []\n };\n var lines = SDPUtils.splitLines(mediaSection);\n var mline = lines[0].split(' ');\n for (var i = 3; i < mline.length; i++) { // find all codecs from mline[3..]\n var pt = mline[i];\n var rtpmapline = SDPUtils.matchPrefix(\n mediaSection, 'a=rtpmap:' + pt + ' ')[0];\n if (rtpmapline) {\n var codec = SDPUtils.parseRtpMap(rtpmapline);\n var fmtps = SDPUtils.matchPrefix(\n mediaSection, 'a=fmtp:' + pt + ' ');\n // Only the first a=fmtp: is considered.\n codec.parameters = fmtps.length ? SDPUtils.parseFmtp(fmtps[0]) : {};\n codec.rtcpFeedback = SDPUtils.matchPrefix(\n mediaSection, 'a=rtcp-fb:' + pt + ' ')\n .map(SDPUtils.parseRtcpFb);\n description.codecs.push(codec);\n // parse FEC mechanisms from rtpmap lines.\n switch (codec.name.toUpperCase()) {\n case 'RED':\n case 'ULPFEC':\n description.fecMechanisms.push(codec.name.toUpperCase());\n break;\n default: // only RED and ULPFEC are recognized as FEC mechanisms.\n break;\n }\n }\n }\n SDPUtils.matchPrefix(mediaSection, 'a=extmap:').forEach(function(line) {\n description.headerExtensions.push(SDPUtils.parseExtmap(line));\n });\n // FIXME: parse rtcp.\n return description;\n};\n\n// Generates parts of the SDP media section describing the capabilities /\n// parameters.\nSDPUtils.writeRtpDescription = function(kind, caps) {\n var sdp = '';\n\n // Build the mline.\n sdp += 'm=' + kind + ' ';\n sdp += caps.codecs.length > 0 ? '9' : '0'; // reject if no codecs.\n sdp += ' UDP/TLS/RTP/SAVPF ';\n sdp += caps.codecs.map(function(codec) {\n if (codec.preferredPayloadType !== undefined) {\n return codec.preferredPayloadType;\n }\n return codec.payloadType;\n }).join(' ') + '\\r\\n';\n\n sdp += 'c=IN IP4 0.0.0.0\\r\\n';\n sdp += 'a=rtcp:9 IN IP4 0.0.0.0\\r\\n';\n\n // Add a=rtpmap lines for each codec. Also fmtp and rtcp-fb.\n caps.codecs.forEach(function(codec) {\n sdp += SDPUtils.writeRtpMap(codec);\n sdp += SDPUtils.writeFmtp(codec);\n sdp += SDPUtils.writeRtcpFb(codec);\n });\n var maxptime = 0;\n caps.codecs.forEach(function(codec) {\n if (codec.maxptime > maxptime) {\n maxptime = codec.maxptime;\n }\n });\n if (maxptime > 0) {\n sdp += 'a=maxptime:' + maxptime + '\\r\\n';\n }\n sdp += 'a=rtcp-mux\\r\\n';\n\n if (caps.headerExtensions) {\n caps.headerExtensions.forEach(function(extension) {\n sdp += SDPUtils.writeExtmap(extension);\n });\n }\n // FIXME: write fecMechanisms.\n return sdp;\n};\n\n// Parses the SDP media section and returns an array of\n// RTCRtpEncodingParameters.\nSDPUtils.parseRtpEncodingParameters = function(mediaSection) {\n var encodingParameters = [];\n var description = SDPUtils.parseRtpParameters(mediaSection);\n var hasRed = description.fecMechanisms.indexOf('RED') !== -1;\n var hasUlpfec = description.fecMechanisms.indexOf('ULPFEC') !== -1;\n\n // filter a=ssrc:... cname:, ignore PlanB-msid\n var ssrcs = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:')\n .map(function(line) {\n return SDPUtils.parseSsrcMedia(line);\n })\n .filter(function(parts) {\n return parts.attribute === 'cname';\n });\n var primarySsrc = ssrcs.length > 0 && ssrcs[0].ssrc;\n var secondarySsrc;\n\n var flows = SDPUtils.matchPrefix(mediaSection, 'a=ssrc-group:FID')\n .map(function(line) {\n var parts = line.substr(17).split(' ');\n return parts.map(function(part) {\n return parseInt(part, 10);\n });\n });\n if (flows.length > 0 && flows[0].length > 1 && flows[0][0] === primarySsrc) {\n secondarySsrc = flows[0][1];\n }\n\n description.codecs.forEach(function(codec) {\n if (codec.name.toUpperCase() === 'RTX' && codec.parameters.apt) {\n var encParam = {\n ssrc: primarySsrc,\n codecPayloadType: parseInt(codec.parameters.apt, 10)\n };\n if (primarySsrc && secondarySsrc) {\n encParam.rtx = {ssrc: secondarySsrc};\n }\n encodingParameters.push(encParam);\n if (hasRed) {\n encParam = JSON.parse(JSON.stringify(encParam));\n encParam.fec = {\n ssrc: primarySsrc,\n mechanism: hasUlpfec ? 'red+ulpfec' : 'red'\n };\n encodingParameters.push(encParam);\n }\n }\n });\n if (encodingParameters.length === 0 && primarySsrc) {\n encodingParameters.push({\n ssrc: primarySsrc\n });\n }\n\n // we support both b=AS and b=TIAS but interpret AS as TIAS.\n var bandwidth = SDPUtils.matchPrefix(mediaSection, 'b=');\n if (bandwidth.length) {\n if (bandwidth[0].indexOf('b=TIAS:') === 0) {\n bandwidth = parseInt(bandwidth[0].substr(7), 10);\n } else if (bandwidth[0].indexOf('b=AS:') === 0) {\n // use formula from JSEP to convert b=AS to TIAS value.\n bandwidth = parseInt(bandwidth[0].substr(5), 10) * 1000 * 0.95\n - (50 * 40 * 8);\n } else {\n bandwidth = undefined;\n }\n encodingParameters.forEach(function(params) {\n params.maxBitrate = bandwidth;\n });\n }\n return encodingParameters;\n};\n\n// parses http://draft.ortc.org/#rtcrtcpparameters*\nSDPUtils.parseRtcpParameters = function(mediaSection) {\n var rtcpParameters = {};\n\n // Gets the first SSRC. Note tha with RTX there might be multiple\n // SSRCs.\n var remoteSsrc = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:')\n .map(function(line) {\n return SDPUtils.parseSsrcMedia(line);\n })\n .filter(function(obj) {\n return obj.attribute === 'cname';\n })[0];\n if (remoteSsrc) {\n rtcpParameters.cname = remoteSsrc.value;\n rtcpParameters.ssrc = remoteSsrc.ssrc;\n }\n\n // Edge uses the compound attribute instead of reducedSize\n // compound is !reducedSize\n var rsize = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-rsize');\n rtcpParameters.reducedSize = rsize.length > 0;\n rtcpParameters.compound = rsize.length === 0;\n\n // parses the rtcp-mux attrіbute.\n // Note that Edge does not support unmuxed RTCP.\n var mux = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-mux');\n rtcpParameters.mux = mux.length > 0;\n\n return rtcpParameters;\n};\n\n// parses either a=msid: or a=ssrc:... msid lines and returns\n// the id of the MediaStream and MediaStreamTrack.\nSDPUtils.parseMsid = function(mediaSection) {\n var parts;\n var spec = SDPUtils.matchPrefix(mediaSection, 'a=msid:');\n if (spec.length === 1) {\n parts = spec[0].substr(7).split(' ');\n return {stream: parts[0], track: parts[1]};\n }\n var planB = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:')\n .map(function(line) {\n return SDPUtils.parseSsrcMedia(line);\n })\n .filter(function(msidParts) {\n return msidParts.attribute === 'msid';\n });\n if (planB.length > 0) {\n parts = planB[0].value.split(' ');\n return {stream: parts[0], track: parts[1]};\n }\n};\n\n// SCTP\n// parses draft-ietf-mmusic-sctp-sdp-26 first and falls back\n// to draft-ietf-mmusic-sctp-sdp-05\nSDPUtils.parseSctpDescription = function(mediaSection) {\n var mline = SDPUtils.parseMLine(mediaSection);\n var maxSizeLine = SDPUtils.matchPrefix(mediaSection, 'a=max-message-size:');\n var maxMessageSize;\n if (maxSizeLine.length > 0) {\n maxMessageSize = parseInt(maxSizeLine[0].substr(19), 10);\n }\n if (isNaN(maxMessageSize)) {\n maxMessageSize = 65536;\n }\n var sctpPort = SDPUtils.matchPrefix(mediaSection, 'a=sctp-port:');\n if (sctpPort.length > 0) {\n return {\n port: parseInt(sctpPort[0].substr(12), 10),\n protocol: mline.fmt,\n maxMessageSize: maxMessageSize\n };\n }\n var sctpMapLines = SDPUtils.matchPrefix(mediaSection, 'a=sctpmap:');\n if (sctpMapLines.length > 0) {\n var parts = SDPUtils.matchPrefix(mediaSection, 'a=sctpmap:')[0]\n .substr(10)\n .split(' ');\n return {\n port: parseInt(parts[0], 10),\n protocol: parts[1],\n maxMessageSize: maxMessageSize\n };\n }\n};\n\n// SCTP\n// outputs the draft-ietf-mmusic-sctp-sdp-26 version that all browsers\n// support by now receiving in this format, unless we originally parsed\n// as the draft-ietf-mmusic-sctp-sdp-05 format (indicated by the m-line\n// protocol of DTLS/SCTP -- without UDP/ or TCP/)\nSDPUtils.writeSctpDescription = function(media, sctp) {\n var output = [];\n if (media.protocol !== 'DTLS/SCTP') {\n output = [\n 'm=' + media.kind + ' 9 ' + media.protocol + ' ' + sctp.protocol + '\\r\\n',\n 'c=IN IP4 0.0.0.0\\r\\n',\n 'a=sctp-port:' + sctp.port + '\\r\\n'\n ];\n } else {\n output = [\n 'm=' + media.kind + ' 9 ' + media.protocol + ' ' + sctp.port + '\\r\\n',\n 'c=IN IP4 0.0.0.0\\r\\n',\n 'a=sctpmap:' + sctp.port + ' ' + sctp.protocol + ' 65535\\r\\n'\n ];\n }\n if (sctp.maxMessageSize !== undefined) {\n output.push('a=max-message-size:' + sctp.maxMessageSize + '\\r\\n');\n }\n return output.join('');\n};\n\n// Generate a session ID for SDP.\n// https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-20#section-5.2.1\n// recommends using a cryptographically random +ve 64-bit value\n// but right now this should be acceptable and within the right range\nSDPUtils.generateSessionId = function() {\n return Math.random().toString().substr(2, 21);\n};\n\n// Write boilder plate for start of SDP\n// sessId argument is optional - if not supplied it will\n// be generated randomly\n// sessVersion is optional and defaults to 2\n// sessUser is optional and defaults to 'thisisadapterortc'\nSDPUtils.writeSessionBoilerplate = function(sessId, sessVer, sessUser) {\n var sessionId;\n var version = sessVer !== undefined ? sessVer : 2;\n if (sessId) {\n sessionId = sessId;\n } else {\n sessionId = SDPUtils.generateSessionId();\n }\n var user = sessUser || 'thisisadapterortc';\n // FIXME: sess-id should be an NTP timestamp.\n return 'v=0\\r\\n' +\n 'o=' + user + ' ' + sessionId + ' ' + version +\n ' IN IP4 127.0.0.1\\r\\n' +\n 's=-\\r\\n' +\n 't=0 0\\r\\n';\n};\n\nSDPUtils.writeMediaSection = function(transceiver, caps, type, stream) {\n var sdp = SDPUtils.writeRtpDescription(transceiver.kind, caps);\n\n // Map ICE parameters (ufrag, pwd) to SDP.\n sdp += SDPUtils.writeIceParameters(\n transceiver.iceGatherer.getLocalParameters());\n\n // Map DTLS parameters to SDP.\n sdp += SDPUtils.writeDtlsParameters(\n transceiver.dtlsTransport.getLocalParameters(),\n type === 'offer' ? 'actpass' : 'active');\n\n sdp += 'a=mid:' + transceiver.mid + '\\r\\n';\n\n if (transceiver.direction) {\n sdp += 'a=' + transceiver.direction + '\\r\\n';\n } else if (transceiver.rtpSender && transceiver.rtpReceiver) {\n sdp += 'a=sendrecv\\r\\n';\n } else if (transceiver.rtpSender) {\n sdp += 'a=sendonly\\r\\n';\n } else if (transceiver.rtpReceiver) {\n sdp += 'a=recvonly\\r\\n';\n } else {\n sdp += 'a=inactive\\r\\n';\n }\n\n if (transceiver.rtpSender) {\n // spec.\n var msid = 'msid:' + stream.id + ' ' +\n transceiver.rtpSender.track.id + '\\r\\n';\n sdp += 'a=' + msid;\n\n // for Chrome.\n sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc +\n ' ' + msid;\n if (transceiver.sendEncodingParameters[0].rtx) {\n sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc +\n ' ' + msid;\n sdp += 'a=ssrc-group:FID ' +\n transceiver.sendEncodingParameters[0].ssrc + ' ' +\n transceiver.sendEncodingParameters[0].rtx.ssrc +\n '\\r\\n';\n }\n }\n // FIXME: this should be written by writeRtpDescription.\n sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc +\n ' cname:' + SDPUtils.localCName + '\\r\\n';\n if (transceiver.rtpSender && transceiver.sendEncodingParameters[0].rtx) {\n sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc +\n ' cname:' + SDPUtils.localCName + '\\r\\n';\n }\n return sdp;\n};\n\n// Gets the direction from the mediaSection or the sessionpart.\nSDPUtils.getDirection = function(mediaSection, sessionpart) {\n // Look for sendrecv, sendonly, recvonly, inactive, default to sendrecv.\n var lines = SDPUtils.splitLines(mediaSection);\n for (var i = 0; i < lines.length; i++) {\n switch (lines[i]) {\n case 'a=sendrecv':\n case 'a=sendonly':\n case 'a=recvonly':\n case 'a=inactive':\n return lines[i].substr(2);\n default:\n // FIXME: What should happen here?\n }\n }\n if (sessionpart) {\n return SDPUtils.getDirection(sessionpart);\n }\n return 'sendrecv';\n};\n\nSDPUtils.getKind = function(mediaSection) {\n var lines = SDPUtils.splitLines(mediaSection);\n var mline = lines[0].split(' ');\n return mline[0].substr(2);\n};\n\nSDPUtils.isRejected = function(mediaSection) {\n return mediaSection.split(' ', 2)[1] === '0';\n};\n\nSDPUtils.parseMLine = function(mediaSection) {\n var lines = SDPUtils.splitLines(mediaSection);\n var parts = lines[0].substr(2).split(' ');\n return {\n kind: parts[0],\n port: parseInt(parts[1], 10),\n protocol: parts[2],\n fmt: parts.slice(3).join(' ')\n };\n};\n\nSDPUtils.parseOLine = function(mediaSection) {\n var line = SDPUtils.matchPrefix(mediaSection, 'o=')[0];\n var parts = line.substr(2).split(' ');\n return {\n username: parts[0],\n sessionId: parts[1],\n sessionVersion: parseInt(parts[2], 10),\n netType: parts[3],\n addressType: parts[4],\n address: parts[5]\n };\n};\n\n// a very naive interpretation of a valid SDP.\nSDPUtils.isValidSDP = function(blob) {\n if (typeof blob !== 'string' || blob.length === 0) {\n return false;\n }\n var lines = SDPUtils.splitLines(blob);\n for (var i = 0; i < lines.length; i++) {\n if (lines[i].length < 2 || lines[i].charAt(1) !== '=') {\n return false;\n }\n // TODO: check the modifier a bit more.\n }\n return true;\n};\n\n// Expose public methods.\nif (typeof module === 'object') {\n module.exports = SDPUtils;\n}\n","/*\n * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n /* eslint-env node */\n'use strict';\n\nvar SDPUtils = require('sdp');\n\nfunction fixStatsType(stat) {\n return {\n inboundrtp: 'inbound-rtp',\n outboundrtp: 'outbound-rtp',\n candidatepair: 'candidate-pair',\n localcandidate: 'local-candidate',\n remotecandidate: 'remote-candidate'\n }[stat.type] || stat.type;\n}\n\nfunction writeMediaSection(transceiver, caps, type, stream, dtlsRole) {\n var sdp = SDPUtils.writeRtpDescription(transceiver.kind, caps);\n\n // Map ICE parameters (ufrag, pwd) to SDP.\n sdp += SDPUtils.writeIceParameters(\n transceiver.iceGatherer.getLocalParameters());\n\n // Map DTLS parameters to SDP.\n sdp += SDPUtils.writeDtlsParameters(\n transceiver.dtlsTransport.getLocalParameters(),\n type === 'offer' ? 'actpass' : dtlsRole || 'active');\n\n sdp += 'a=mid:' + transceiver.mid + '\\r\\n';\n\n if (transceiver.rtpSender && transceiver.rtpReceiver) {\n sdp += 'a=sendrecv\\r\\n';\n } else if (transceiver.rtpSender) {\n sdp += 'a=sendonly\\r\\n';\n } else if (transceiver.rtpReceiver) {\n sdp += 'a=recvonly\\r\\n';\n } else {\n sdp += 'a=inactive\\r\\n';\n }\n\n if (transceiver.rtpSender) {\n var trackId = transceiver.rtpSender._initialTrackId ||\n transceiver.rtpSender.track.id;\n transceiver.rtpSender._initialTrackId = trackId;\n // spec.\n var msid = 'msid:' + (stream ? stream.id : '-') + ' ' +\n trackId + '\\r\\n';\n sdp += 'a=' + msid;\n // for Chrome. Legacy should no longer be required.\n sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc +\n ' ' + msid;\n\n // RTX\n if (transceiver.sendEncodingParameters[0].rtx) {\n sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc +\n ' ' + msid;\n sdp += 'a=ssrc-group:FID ' +\n transceiver.sendEncodingParameters[0].ssrc + ' ' +\n transceiver.sendEncodingParameters[0].rtx.ssrc +\n '\\r\\n';\n }\n }\n // FIXME: this should be written by writeRtpDescription.\n sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc +\n ' cname:' + SDPUtils.localCName + '\\r\\n';\n if (transceiver.rtpSender && transceiver.sendEncodingParameters[0].rtx) {\n sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc +\n ' cname:' + SDPUtils.localCName + '\\r\\n';\n }\n return sdp;\n}\n\n// Edge does not like\n// 1) stun: filtered after 14393 unless ?transport=udp is present\n// 2) turn: that does not have all of turn:host:port?transport=udp\n// 3) turn: with ipv6 addresses\n// 4) turn: occurring muliple times\nfunction filterIceServers(iceServers, edgeVersion) {\n var hasTurn = false;\n iceServers = JSON.parse(JSON.stringify(iceServers));\n return iceServers.filter(function(server) {\n if (server && (server.urls || server.url)) {\n var urls = server.urls || server.url;\n if (server.url && !server.urls) {\n console.warn('RTCIceServer.url is deprecated! Use urls instead.');\n }\n var isString = typeof urls === 'string';\n if (isString) {\n urls = [urls];\n }\n urls = urls.filter(function(url) {\n var validTurn = url.indexOf('turn:') === 0 &&\n url.indexOf('transport=udp') !== -1 &&\n url.indexOf('turn:[') === -1 &&\n !hasTurn;\n\n if (validTurn) {\n hasTurn = true;\n return true;\n }\n return url.indexOf('stun:') === 0 && edgeVersion >= 14393 &&\n url.indexOf('?transport=udp') === -1;\n });\n\n delete server.url;\n server.urls = isString ? urls[0] : urls;\n return !!urls.length;\n }\n });\n}\n\n// Determines the intersection of local and remote capabilities.\nfunction getCommonCapabilities(localCapabilities, remoteCapabilities) {\n var commonCapabilities = {\n codecs: [],\n headerExtensions: [],\n fecMechanisms: []\n };\n\n var findCodecByPayloadType = function(pt, codecs) {\n pt = parseInt(pt, 10);\n for (var i = 0; i < codecs.length; i++) {\n if (codecs[i].payloadType === pt ||\n codecs[i].preferredPayloadType === pt) {\n return codecs[i];\n }\n }\n };\n\n var rtxCapabilityMatches = function(lRtx, rRtx, lCodecs, rCodecs) {\n var lCodec = findCodecByPayloadType(lRtx.parameters.apt, lCodecs);\n var rCodec = findCodecByPayloadType(rRtx.parameters.apt, rCodecs);\n return lCodec && rCodec &&\n lCodec.name.toLowerCase() === rCodec.name.toLowerCase();\n };\n\n localCapabilities.codecs.forEach(function(lCodec) {\n for (var i = 0; i < remoteCapabilities.codecs.length; i++) {\n var rCodec = remoteCapabilities.codecs[i];\n if (lCodec.name.toLowerCase() === rCodec.name.toLowerCase() &&\n lCodec.clockRate === rCodec.clockRate) {\n if (lCodec.name.toLowerCase() === 'rtx' &&\n lCodec.parameters && rCodec.parameters.apt) {\n // for RTX we need to find the local rtx that has a apt\n // which points to the same local codec as the remote one.\n if (!rtxCapabilityMatches(lCodec, rCodec,\n localCapabilities.codecs, remoteCapabilities.codecs)) {\n continue;\n }\n }\n rCodec = JSON.parse(JSON.stringify(rCodec)); // deepcopy\n // number of channels is the highest common number of channels\n rCodec.numChannels = Math.min(lCodec.numChannels,\n rCodec.numChannels);\n // push rCodec so we reply with offerer payload type\n commonCapabilities.codecs.push(rCodec);\n\n // determine common feedback mechanisms\n rCodec.rtcpFeedback = rCodec.rtcpFeedback.filter(function(fb) {\n for (var j = 0; j < lCodec.rtcpFeedback.length; j++) {\n if (lCodec.rtcpFeedback[j].type === fb.type &&\n lCodec.rtcpFeedback[j].parameter === fb.parameter) {\n return true;\n }\n }\n return false;\n });\n // FIXME: also need to determine .parameters\n // see https://github.com/openpeer/ortc/issues/569\n break;\n }\n }\n });\n\n localCapabilities.headerExtensions.forEach(function(lHeaderExtension) {\n for (var i = 0; i < remoteCapabilities.headerExtensions.length;\n i++) {\n var rHeaderExtension = remoteCapabilities.headerExtensions[i];\n if (lHeaderExtension.uri === rHeaderExtension.uri) {\n commonCapabilities.headerExtensions.push(rHeaderExtension);\n break;\n }\n }\n });\n\n // FIXME: fecMechanisms\n return commonCapabilities;\n}\n\n// is action=setLocalDescription with type allowed in signalingState\nfunction isActionAllowedInSignalingState(action, type, signalingState) {\n return {\n offer: {\n setLocalDescription: ['stable', 'have-local-offer'],\n setRemoteDescription: ['stable', 'have-remote-offer']\n },\n answer: {\n setLocalDescription: ['have-remote-offer', 'have-local-pranswer'],\n setRemoteDescription: ['have-local-offer', 'have-remote-pranswer']\n }\n }[type][action].indexOf(signalingState) !== -1;\n}\n\nfunction maybeAddCandidate(iceTransport, candidate) {\n // Edge's internal representation adds some fields therefore\n // not all fieldѕ are taken into account.\n var alreadyAdded = iceTransport.getRemoteCandidates()\n .find(function(remoteCandidate) {\n return candidate.foundation === remoteCandidate.foundation &&\n candidate.ip === remoteCandidate.ip &&\n candidate.port === remoteCandidate.port &&\n candidate.priority === remoteCandidate.priority &&\n candidate.protocol === remoteCandidate.protocol &&\n candidate.type === remoteCandidate.type;\n });\n if (!alreadyAdded) {\n iceTransport.addRemoteCandidate(candidate);\n }\n return !alreadyAdded;\n}\n\n\nfunction makeError(name, description) {\n var e = new Error(description);\n e.name = name;\n // legacy error codes from https://heycam.github.io/webidl/#idl-DOMException-error-names\n e.code = {\n NotSupportedError: 9,\n InvalidStateError: 11,\n InvalidAccessError: 15,\n TypeError: undefined,\n OperationError: undefined\n }[name];\n return e;\n}\n\nmodule.exports = function(window, edgeVersion) {\n // https://w3c.github.io/mediacapture-main/#mediastream\n // Helper function to add the track to the stream and\n // dispatch the event ourselves.\n function addTrackToStreamAndFireEvent(track, stream) {\n stream.addTrack(track);\n stream.dispatchEvent(new window.MediaStreamTrackEvent('addtrack',\n {track: track}));\n }\n\n function removeTrackFromStreamAndFireEvent(track, stream) {\n stream.removeTrack(track);\n stream.dispatchEvent(new window.MediaStreamTrackEvent('removetrack',\n {track: track}));\n }\n\n function fireAddTrack(pc, track, receiver, streams) {\n var trackEvent = new Event('track');\n trackEvent.track = track;\n trackEvent.receiver = receiver;\n trackEvent.transceiver = {receiver: receiver};\n trackEvent.streams = streams;\n window.setTimeout(function() {\n pc._dispatchEvent('track', trackEvent);\n });\n }\n\n var RTCPeerConnection = function(config) {\n var pc = this;\n\n var _eventTarget = document.createDocumentFragment();\n ['addEventListener', 'removeEventListener', 'dispatchEvent']\n .forEach(function(method) {\n pc[method] = _eventTarget[method].bind(_eventTarget);\n });\n\n this.canTrickleIceCandidates = null;\n\n this.needNegotiation = false;\n\n this.localStreams = [];\n this.remoteStreams = [];\n\n this._localDescription = null;\n this._remoteDescription = null;\n\n this.signalingState = 'stable';\n this.iceConnectionState = 'new';\n this.connectionState = 'new';\n this.iceGatheringState = 'new';\n\n config = JSON.parse(JSON.stringify(config || {}));\n\n this.usingBundle = config.bundlePolicy === 'max-bundle';\n if (config.rtcpMuxPolicy === 'negotiate') {\n throw(makeError('NotSupportedError',\n 'rtcpMuxPolicy \\'negotiate\\' is not supported'));\n } else if (!config.rtcpMuxPolicy) {\n config.rtcpMuxPolicy = 'require';\n }\n\n switch (config.iceTransportPolicy) {\n case 'all':\n case 'relay':\n break;\n default:\n config.iceTransportPolicy = 'all';\n break;\n }\n\n switch (config.bundlePolicy) {\n case 'balanced':\n case 'max-compat':\n case 'max-bundle':\n break;\n default:\n config.bundlePolicy = 'balanced';\n break;\n }\n\n config.iceServers = filterIceServers(config.iceServers || [], edgeVersion);\n\n this._iceGatherers = [];\n if (config.iceCandidatePoolSize) {\n for (var i = config.iceCandidatePoolSize; i > 0; i--) {\n this._iceGatherers.push(new window.RTCIceGatherer({\n iceServers: config.iceServers,\n gatherPolicy: config.iceTransportPolicy\n }));\n }\n } else {\n config.iceCandidatePoolSize = 0;\n }\n\n this._config = config;\n\n // per-track iceGathers, iceTransports, dtlsTransports, rtpSenders, ...\n // everything that is needed to describe a SDP m-line.\n this.transceivers = [];\n\n this._sdpSessionId = SDPUtils.generateSessionId();\n this._sdpSessionVersion = 0;\n\n this._dtlsRole = undefined; // role for a=setup to use in answers.\n\n this._isClosed = false;\n };\n\n Object.defineProperty(RTCPeerConnection.prototype, 'localDescription', {\n configurable: true,\n get: function() {\n return this._localDescription;\n }\n });\n Object.defineProperty(RTCPeerConnection.prototype, 'remoteDescription', {\n configurable: true,\n get: function() {\n return this._remoteDescription;\n }\n });\n\n // set up event handlers on prototype\n RTCPeerConnection.prototype.onicecandidate = null;\n RTCPeerConnection.prototype.onaddstream = null;\n RTCPeerConnection.prototype.ontrack = null;\n RTCPeerConnection.prototype.onremovestream = null;\n RTCPeerConnection.prototype.onsignalingstatechange = null;\n RTCPeerConnection.prototype.oniceconnectionstatechange = null;\n RTCPeerConnection.prototype.onconnectionstatechange = null;\n RTCPeerConnection.prototype.onicegatheringstatechange = null;\n RTCPeerConnection.prototype.onnegotiationneeded = null;\n RTCPeerConnection.prototype.ondatachannel = null;\n\n RTCPeerConnection.prototype._dispatchEvent = function(name, event) {\n if (this._isClosed) {\n return;\n }\n this.dispatchEvent(event);\n if (typeof this['on' + name] === 'function') {\n this['on' + name](event);\n }\n };\n\n RTCPeerConnection.prototype._emitGatheringStateChange = function() {\n var event = new Event('icegatheringstatechange');\n this._dispatchEvent('icegatheringstatechange', event);\n };\n\n RTCPeerConnection.prototype.getConfiguration = function() {\n return this._config;\n };\n\n RTCPeerConnection.prototype.getLocalStreams = function() {\n return this.localStreams;\n };\n\n RTCPeerConnection.prototype.getRemoteStreams = function() {\n return this.remoteStreams;\n };\n\n // internal helper to create a transceiver object.\n // (which is not yet the same as the WebRTC 1.0 transceiver)\n RTCPeerConnection.prototype._createTransceiver = function(kind, doNotAdd) {\n var hasBundleTransport = this.transceivers.length > 0;\n var transceiver = {\n track: null,\n iceGatherer: null,\n iceTransport: null,\n dtlsTransport: null,\n localCapabilities: null,\n remoteCapabilities: null,\n rtpSender: null,\n rtpReceiver: null,\n kind: kind,\n mid: null,\n sendEncodingParameters: null,\n recvEncodingParameters: null,\n stream: null,\n associatedRemoteMediaStreams: [],\n wantReceive: true\n };\n if (this.usingBundle && hasBundleTransport) {\n transceiver.iceTransport = this.transceivers[0].iceTransport;\n transceiver.dtlsTransport = this.transceivers[0].dtlsTransport;\n } else {\n var transports = this._createIceAndDtlsTransports();\n transceiver.iceTransport = transports.iceTransport;\n transceiver.dtlsTransport = transports.dtlsTransport;\n }\n if (!doNotAdd) {\n this.transceivers.push(transceiver);\n }\n return transceiver;\n };\n\n RTCPeerConnection.prototype.addTrack = function(track, stream) {\n if (this._isClosed) {\n throw makeError('InvalidStateError',\n 'Attempted to call addTrack on a closed peerconnection.');\n }\n\n var alreadyExists = this.transceivers.find(function(s) {\n return s.track === track;\n });\n\n if (alreadyExists) {\n throw makeError('InvalidAccessError', 'Track already exists.');\n }\n\n var transceiver;\n for (var i = 0; i < this.transceivers.length; i++) {\n if (!this.transceivers[i].track &&\n this.transceivers[i].kind === track.kind) {\n transceiver = this.transceivers[i];\n }\n }\n if (!transceiver) {\n transceiver = this._createTransceiver(track.kind);\n }\n\n this._maybeFireNegotiationNeeded();\n\n if (this.localStreams.indexOf(stream) === -1) {\n this.localStreams.push(stream);\n }\n\n transceiver.track = track;\n transceiver.stream = stream;\n transceiver.rtpSender = new window.RTCRtpSender(track,\n transceiver.dtlsTransport);\n return transceiver.rtpSender;\n };\n\n RTCPeerConnection.prototype.addStream = function(stream) {\n var pc = this;\n if (edgeVersion >= 15025) {\n stream.getTracks().forEach(function(track) {\n pc.addTrack(track, stream);\n });\n } else {\n // Clone is necessary for local demos mostly, attaching directly\n // to two different senders does not work (build 10547).\n // Fixed in 15025 (or earlier)\n var clonedStream = stream.clone();\n stream.getTracks().forEach(function(track, idx) {\n var clonedTrack = clonedStream.getTracks()[idx];\n track.addEventListener('enabled', function(event) {\n clonedTrack.enabled = event.enabled;\n });\n });\n clonedStream.getTracks().forEach(function(track) {\n pc.addTrack(track, clonedStream);\n });\n }\n };\n\n RTCPeerConnection.prototype.removeTrack = function(sender) {\n if (this._isClosed) {\n throw makeError('InvalidStateError',\n 'Attempted to call removeTrack on a closed peerconnection.');\n }\n\n if (!(sender instanceof window.RTCRtpSender)) {\n throw new TypeError('Argument 1 of RTCPeerConnection.removeTrack ' +\n 'does not implement interface RTCRtpSender.');\n }\n\n var transceiver = this.transceivers.find(function(t) {\n return t.rtpSender === sender;\n });\n\n if (!transceiver) {\n throw makeError('InvalidAccessError',\n 'Sender was not created by this connection.');\n }\n var stream = transceiver.stream;\n\n transceiver.rtpSender.stop();\n transceiver.rtpSender = null;\n transceiver.track = null;\n transceiver.stream = null;\n\n // remove the stream from the set of local streams\n var localStreams = this.transceivers.map(function(t) {\n return t.stream;\n });\n if (localStreams.indexOf(stream) === -1 &&\n this.localStreams.indexOf(stream) > -1) {\n this.localStreams.splice(this.localStreams.indexOf(stream), 1);\n }\n\n this._maybeFireNegotiationNeeded();\n };\n\n RTCPeerConnection.prototype.removeStream = function(stream) {\n var pc = this;\n stream.getTracks().forEach(function(track) {\n var sender = pc.getSenders().find(function(s) {\n return s.track === track;\n });\n if (sender) {\n pc.removeTrack(sender);\n }\n });\n };\n\n RTCPeerConnection.prototype.getSenders = function() {\n return this.transceivers.filter(function(transceiver) {\n return !!transceiver.rtpSender;\n })\n .map(function(transceiver) {\n return transceiver.rtpSender;\n });\n };\n\n RTCPeerConnection.prototype.getReceivers = function() {\n return this.transceivers.filter(function(transceiver) {\n return !!transceiver.rtpReceiver;\n })\n .map(function(transceiver) {\n return transceiver.rtpReceiver;\n });\n };\n\n\n RTCPeerConnection.prototype._createIceGatherer = function(sdpMLineIndex,\n usingBundle) {\n var pc = this;\n if (usingBundle && sdpMLineIndex > 0) {\n return this.transceivers[0].iceGatherer;\n } else if (this._iceGatherers.length) {\n return this._iceGatherers.shift();\n }\n var iceGatherer = new window.RTCIceGatherer({\n iceServers: this._config.iceServers,\n gatherPolicy: this._config.iceTransportPolicy\n });\n Object.defineProperty(iceGatherer, 'state',\n {value: 'new', writable: true}\n );\n\n this.transceivers[sdpMLineIndex].bufferedCandidateEvents = [];\n this.transceivers[sdpMLineIndex].bufferCandidates = function(event) {\n var end = !event.candidate || Object.keys(event.candidate).length === 0;\n // polyfill since RTCIceGatherer.state is not implemented in\n // Edge 10547 yet.\n iceGatherer.state = end ? 'completed' : 'gathering';\n if (pc.transceivers[sdpMLineIndex].bufferedCandidateEvents !== null) {\n pc.transceivers[sdpMLineIndex].bufferedCandidateEvents.push(event);\n }\n };\n iceGatherer.addEventListener('localcandidate',\n this.transceivers[sdpMLineIndex].bufferCandidates);\n return iceGatherer;\n };\n\n // start gathering from an RTCIceGatherer.\n RTCPeerConnection.prototype._gather = function(mid, sdpMLineIndex) {\n var pc = this;\n var iceGatherer = this.transceivers[sdpMLineIndex].iceGatherer;\n if (iceGatherer.onlocalcandidate) {\n return;\n }\n var bufferedCandidateEvents =\n this.transceivers[sdpMLineIndex].bufferedCandidateEvents;\n this.transceivers[sdpMLineIndex].bufferedCandidateEvents = null;\n iceGatherer.removeEventListener('localcandidate',\n this.transceivers[sdpMLineIndex].bufferCandidates);\n iceGatherer.onlocalcandidate = function(evt) {\n if (pc.usingBundle && sdpMLineIndex > 0) {\n // if we know that we use bundle we can drop candidates with\n // ѕdpMLineIndex > 0. If we don't do this then our state gets\n // confused since we dispose the extra ice gatherer.\n return;\n }\n var event = new Event('icecandidate');\n event.candidate = {sdpMid: mid, sdpMLineIndex: sdpMLineIndex};\n\n var cand = evt.candidate;\n // Edge emits an empty object for RTCIceCandidateComplete‥\n var end = !cand || Object.keys(cand).length === 0;\n if (end) {\n // polyfill since RTCIceGatherer.state is not implemented in\n // Edge 10547 yet.\n if (iceGatherer.state === 'new' || iceGatherer.state === 'gathering') {\n iceGatherer.state = 'completed';\n }\n } else {\n if (iceGatherer.state === 'new') {\n iceGatherer.state = 'gathering';\n }\n // RTCIceCandidate doesn't have a component, needs to be added\n cand.component = 1;\n // also the usernameFragment. TODO: update SDP to take both variants.\n cand.ufrag = iceGatherer.getLocalParameters().usernameFragment;\n\n var serializedCandidate = SDPUtils.writeCandidate(cand);\n event.candidate = Object.assign(event.candidate,\n SDPUtils.parseCandidate(serializedCandidate));\n\n event.candidate.candidate = serializedCandidate;\n event.candidate.toJSON = function() {\n return {\n candidate: event.candidate.candidate,\n sdpMid: event.candidate.sdpMid,\n sdpMLineIndex: event.candidate.sdpMLineIndex,\n usernameFragment: event.candidate.usernameFragment\n };\n };\n }\n\n // update local description.\n var sections = SDPUtils.getMediaSections(pc._localDescription.sdp);\n if (!end) {\n sections[event.candidate.sdpMLineIndex] +=\n 'a=' + event.candidate.candidate + '\\r\\n';\n } else {\n sections[event.candidate.sdpMLineIndex] +=\n 'a=end-of-candidates\\r\\n';\n }\n pc._localDescription.sdp =\n SDPUtils.getDescription(pc._localDescription.sdp) +\n sections.join('');\n var complete = pc.transceivers.every(function(transceiver) {\n return transceiver.iceGatherer &&\n transceiver.iceGatherer.state === 'completed';\n });\n\n if (pc.iceGatheringState !== 'gathering') {\n pc.iceGatheringState = 'gathering';\n pc._emitGatheringStateChange();\n }\n\n // Emit candidate. Also emit null candidate when all gatherers are\n // complete.\n if (!end) {\n pc._dispatchEvent('icecandidate', event);\n }\n if (complete) {\n pc._dispatchEvent('icecandidate', new Event('icecandidate'));\n pc.iceGatheringState = 'complete';\n pc._emitGatheringStateChange();\n }\n };\n\n // emit already gathered candidates.\n window.setTimeout(function() {\n bufferedCandidateEvents.forEach(function(e) {\n iceGatherer.onlocalcandidate(e);\n });\n }, 0);\n };\n\n // Create ICE transport and DTLS transport.\n RTCPeerConnection.prototype._createIceAndDtlsTransports = function() {\n var pc = this;\n var iceTransport = new window.RTCIceTransport(null);\n iceTransport.onicestatechange = function() {\n pc._updateIceConnectionState();\n pc._updateConnectionState();\n };\n\n var dtlsTransport = new window.RTCDtlsTransport(iceTransport);\n dtlsTransport.ondtlsstatechange = function() {\n pc._updateConnectionState();\n };\n dtlsTransport.onerror = function() {\n // onerror does not set state to failed by itself.\n Object.defineProperty(dtlsTransport, 'state',\n {value: 'failed', writable: true});\n pc._updateConnectionState();\n };\n\n return {\n iceTransport: iceTransport,\n dtlsTransport: dtlsTransport\n };\n };\n\n // Destroy ICE gatherer, ICE transport and DTLS transport.\n // Without triggering the callbacks.\n RTCPeerConnection.prototype._disposeIceAndDtlsTransports = function(\n sdpMLineIndex) {\n var iceGatherer = this.transceivers[sdpMLineIndex].iceGatherer;\n if (iceGatherer) {\n delete iceGatherer.onlocalcandidate;\n delete this.transceivers[sdpMLineIndex].iceGatherer;\n }\n var iceTransport = this.transceivers[sdpMLineIndex].iceTransport;\n if (iceTransport) {\n delete iceTransport.onicestatechange;\n delete this.transceivers[sdpMLineIndex].iceTransport;\n }\n var dtlsTransport = this.transceivers[sdpMLineIndex].dtlsTransport;\n if (dtlsTransport) {\n delete dtlsTransport.ondtlsstatechange;\n delete dtlsTransport.onerror;\n delete this.transceivers[sdpMLineIndex].dtlsTransport;\n }\n };\n\n // Start the RTP Sender and Receiver for a transceiver.\n RTCPeerConnection.prototype._transceive = function(transceiver,\n send, recv) {\n var params = getCommonCapabilities(transceiver.localCapabilities,\n transceiver.remoteCapabilities);\n if (send && transceiver.rtpSender) {\n params.encodings = transceiver.sendEncodingParameters;\n params.rtcp = {\n cname: SDPUtils.localCName,\n compound: transceiver.rtcpParameters.compound\n };\n if (transceiver.recvEncodingParameters.length) {\n params.rtcp.ssrc = transceiver.recvEncodingParameters[0].ssrc;\n }\n transceiver.rtpSender.send(params);\n }\n if (recv && transceiver.rtpReceiver && params.codecs.length > 0) {\n // remove RTX field in Edge 14942\n if (transceiver.kind === 'video'\n && transceiver.recvEncodingParameters\n && edgeVersion < 15019) {\n transceiver.recvEncodingParameters.forEach(function(p) {\n delete p.rtx;\n });\n }\n if (transceiver.recvEncodingParameters.length) {\n params.encodings = transceiver.recvEncodingParameters;\n } else {\n params.encodings = [{}];\n }\n params.rtcp = {\n compound: transceiver.rtcpParameters.compound\n };\n if (transceiver.rtcpParameters.cname) {\n params.rtcp.cname = transceiver.rtcpParameters.cname;\n }\n if (transceiver.sendEncodingParameters.length) {\n params.rtcp.ssrc = transceiver.sendEncodingParameters[0].ssrc;\n }\n transceiver.rtpReceiver.receive(params);\n }\n };\n\n RTCPeerConnection.prototype.setLocalDescription = function(description) {\n var pc = this;\n\n // Note: pranswer is not supported.\n if (['offer', 'answer'].indexOf(description.type) === -1) {\n return Promise.reject(makeError('TypeError',\n 'Unsupported type \"' + description.type + '\"'));\n }\n\n if (!isActionAllowedInSignalingState('setLocalDescription',\n description.type, pc.signalingState) || pc._isClosed) {\n return Promise.reject(makeError('InvalidStateError',\n 'Can not set local ' + description.type +\n ' in state ' + pc.signalingState));\n }\n\n var sections;\n var sessionpart;\n if (description.type === 'offer') {\n // VERY limited support for SDP munging. Limited to:\n // * changing the order of codecs\n sections = SDPUtils.splitSections(description.sdp);\n sessionpart = sections.shift();\n sections.forEach(function(mediaSection, sdpMLineIndex) {\n var caps = SDPUtils.parseRtpParameters(mediaSection);\n pc.transceivers[sdpMLineIndex].localCapabilities = caps;\n });\n\n pc.transceivers.forEach(function(transceiver, sdpMLineIndex) {\n pc._gather(transceiver.mid, sdpMLineIndex);\n });\n } else if (description.type === 'answer') {\n sections = SDPUtils.splitSections(pc._remoteDescription.sdp);\n sessionpart = sections.shift();\n var isIceLite = SDPUtils.matchPrefix(sessionpart,\n 'a=ice-lite').length > 0;\n sections.forEach(function(mediaSection, sdpMLineIndex) {\n var transceiver = pc.transceivers[sdpMLineIndex];\n var iceGatherer = transceiver.iceGatherer;\n var iceTransport = transceiver.iceTransport;\n var dtlsTransport = transceiver.dtlsTransport;\n var localCapabilities = transceiver.localCapabilities;\n var remoteCapabilities = transceiver.remoteCapabilities;\n\n // treat bundle-only as not-rejected.\n var rejected = SDPUtils.isRejected(mediaSection) &&\n SDPUtils.matchPrefix(mediaSection, 'a=bundle-only').length === 0;\n\n if (!rejected && !transceiver.rejected) {\n var remoteIceParameters = SDPUtils.getIceParameters(\n mediaSection, sessionpart);\n var remoteDtlsParameters = SDPUtils.getDtlsParameters(\n mediaSection, sessionpart);\n if (isIceLite) {\n remoteDtlsParameters.role = 'server';\n }\n\n if (!pc.usingBundle || sdpMLineIndex === 0) {\n pc._gather(transceiver.mid, sdpMLineIndex);\n if (iceTransport.state === 'new') {\n iceTransport.start(iceGatherer, remoteIceParameters,\n isIceLite ? 'controlling' : 'controlled');\n }\n if (dtlsTransport.state === 'new') {\n dtlsTransport.start(remoteDtlsParameters);\n }\n }\n\n // Calculate intersection of capabilities.\n var params = getCommonCapabilities(localCapabilities,\n remoteCapabilities);\n\n // Start the RTCRtpSender. The RTCRtpReceiver for this\n // transceiver has already been started in setRemoteDescription.\n pc._transceive(transceiver,\n params.codecs.length > 0,\n false);\n }\n });\n }\n\n pc._localDescription = {\n type: description.type,\n sdp: description.sdp\n };\n if (description.type === 'offer') {\n pc._updateSignalingState('have-local-offer');\n } else {\n pc._updateSignalingState('stable');\n }\n\n return Promise.resolve();\n };\n\n RTCPeerConnection.prototype.setRemoteDescription = function(description) {\n var pc = this;\n\n // Note: pranswer is not supported.\n if (['offer', 'answer'].indexOf(description.type) === -1) {\n return Promise.reject(makeError('TypeError',\n 'Unsupported type \"' + description.type + '\"'));\n }\n\n if (!isActionAllowedInSignalingState('setRemoteDescription',\n description.type, pc.signalingState) || pc._isClosed) {\n return Promise.reject(makeError('InvalidStateError',\n 'Can not set remote ' + description.type +\n ' in state ' + pc.signalingState));\n }\n\n var streams = {};\n pc.remoteStreams.forEach(function(stream) {\n streams[stream.id] = stream;\n });\n var receiverList = [];\n var sections = SDPUtils.splitSections(description.sdp);\n var sessionpart = sections.shift();\n var isIceLite = SDPUtils.matchPrefix(sessionpart,\n 'a=ice-lite').length > 0;\n var usingBundle = SDPUtils.matchPrefix(sessionpart,\n 'a=group:BUNDLE ').length > 0;\n pc.usingBundle = usingBundle;\n var iceOptions = SDPUtils.matchPrefix(sessionpart,\n 'a=ice-options:')[0];\n if (iceOptions) {\n pc.canTrickleIceCandidates = iceOptions.substr(14).split(' ')\n .indexOf('trickle') >= 0;\n } else {\n pc.canTrickleIceCandidates = false;\n }\n\n sections.forEach(function(mediaSection, sdpMLineIndex) {\n var lines = SDPUtils.splitLines(mediaSection);\n var kind = SDPUtils.getKind(mediaSection);\n // treat bundle-only as not-rejected.\n var rejected = SDPUtils.isRejected(mediaSection) &&\n SDPUtils.matchPrefix(mediaSection, 'a=bundle-only').length === 0;\n var protocol = lines[0].substr(2).split(' ')[2];\n\n var direction = SDPUtils.getDirection(mediaSection, sessionpart);\n var remoteMsid = SDPUtils.parseMsid(mediaSection);\n\n var mid = SDPUtils.getMid(mediaSection) || SDPUtils.generateIdentifier();\n\n // Reject datachannels which are not implemented yet.\n if (rejected || (kind === 'application' && (protocol === 'DTLS/SCTP' ||\n protocol === 'UDP/DTLS/SCTP'))) {\n // TODO: this is dangerous in the case where a non-rejected m-line\n // becomes rejected.\n pc.transceivers[sdpMLineIndex] = {\n mid: mid,\n kind: kind,\n protocol: protocol,\n rejected: true\n };\n return;\n }\n\n if (!rejected && pc.transceivers[sdpMLineIndex] &&\n pc.transceivers[sdpMLineIndex].rejected) {\n // recycle a rejected transceiver.\n pc.transceivers[sdpMLineIndex] = pc._createTransceiver(kind, true);\n }\n\n var transceiver;\n var iceGatherer;\n var iceTransport;\n var dtlsTransport;\n var rtpReceiver;\n var sendEncodingParameters;\n var recvEncodingParameters;\n var localCapabilities;\n\n var track;\n // FIXME: ensure the mediaSection has rtcp-mux set.\n var remoteCapabilities = SDPUtils.parseRtpParameters(mediaSection);\n var remoteIceParameters;\n var remoteDtlsParameters;\n if (!rejected) {\n remoteIceParameters = SDPUtils.getIceParameters(mediaSection,\n sessionpart);\n remoteDtlsParameters = SDPUtils.getDtlsParameters(mediaSection,\n sessionpart);\n remoteDtlsParameters.role = 'client';\n }\n recvEncodingParameters =\n SDPUtils.parseRtpEncodingParameters(mediaSection);\n\n var rtcpParameters = SDPUtils.parseRtcpParameters(mediaSection);\n\n var isComplete = SDPUtils.matchPrefix(mediaSection,\n 'a=end-of-candidates', sessionpart).length > 0;\n var cands = SDPUtils.matchPrefix(mediaSection, 'a=candidate:')\n .map(function(cand) {\n return SDPUtils.parseCandidate(cand);\n })\n .filter(function(cand) {\n return cand.component === 1;\n });\n\n // Check if we can use BUNDLE and dispose transports.\n if ((description.type === 'offer' || description.type === 'answer') &&\n !rejected && usingBundle && sdpMLineIndex > 0 &&\n pc.transceivers[sdpMLineIndex]) {\n pc._disposeIceAndDtlsTransports(sdpMLineIndex);\n pc.transceivers[sdpMLineIndex].iceGatherer =\n pc.transceivers[0].iceGatherer;\n pc.transceivers[sdpMLineIndex].iceTransport =\n pc.transceivers[0].iceTransport;\n pc.transceivers[sdpMLineIndex].dtlsTransport =\n pc.transceivers[0].dtlsTransport;\n if (pc.transceivers[sdpMLineIndex].rtpSender) {\n pc.transceivers[sdpMLineIndex].rtpSender.setTransport(\n pc.transceivers[0].dtlsTransport);\n }\n if (pc.transceivers[sdpMLineIndex].rtpReceiver) {\n pc.transceivers[sdpMLineIndex].rtpReceiver.setTransport(\n pc.transceivers[0].dtlsTransport);\n }\n }\n if (description.type === 'offer' && !rejected) {\n transceiver = pc.transceivers[sdpMLineIndex] ||\n pc._createTransceiver(kind);\n transceiver.mid = mid;\n\n if (!transceiver.iceGatherer) {\n transceiver.iceGatherer = pc._createIceGatherer(sdpMLineIndex,\n usingBundle);\n }\n\n if (cands.length && transceiver.iceTransport.state === 'new') {\n if (isComplete && (!usingBundle || sdpMLineIndex === 0)) {\n transceiver.iceTransport.setRemoteCandidates(cands);\n } else {\n cands.forEach(function(candidate) {\n maybeAddCandidate(transceiver.iceTransport, candidate);\n });\n }\n }\n\n localCapabilities = window.RTCRtpReceiver.getCapabilities(kind);\n\n // filter RTX until additional stuff needed for RTX is implemented\n // in adapter.js\n if (edgeVersion < 15019) {\n localCapabilities.codecs = localCapabilities.codecs.filter(\n function(codec) {\n return codec.name !== 'rtx';\n });\n }\n\n sendEncodingParameters = transceiver.sendEncodingParameters || [{\n ssrc: (2 * sdpMLineIndex + 2) * 1001\n }];\n\n // TODO: rewrite to use http://w3c.github.io/webrtc-pc/#set-associated-remote-streams\n var isNewTrack = false;\n if (direction === 'sendrecv' || direction === 'sendonly') {\n isNewTrack = !transceiver.rtpReceiver;\n rtpReceiver = transceiver.rtpReceiver ||\n new window.RTCRtpReceiver(transceiver.dtlsTransport, kind);\n\n if (isNewTrack) {\n var stream;\n track = rtpReceiver.track;\n // FIXME: does not work with Plan B.\n if (remoteMsid && remoteMsid.stream === '-') {\n // no-op. a stream id of '-' means: no associated stream.\n } else if (remoteMsid) {\n if (!streams[remoteMsid.stream]) {\n streams[remoteMsid.stream] = new window.MediaStream();\n Object.defineProperty(streams[remoteMsid.stream], 'id', {\n get: function() {\n return remoteMsid.stream;\n }\n });\n }\n Object.defineProperty(track, 'id', {\n get: function() {\n return remoteMsid.track;\n }\n });\n stream = streams[remoteMsid.stream];\n } else {\n if (!streams.default) {\n streams.default = new window.MediaStream();\n }\n stream = streams.default;\n }\n if (stream) {\n addTrackToStreamAndFireEvent(track, stream);\n transceiver.associatedRemoteMediaStreams.push(stream);\n }\n receiverList.push([track, rtpReceiver, stream]);\n }\n } else if (transceiver.rtpReceiver && transceiver.rtpReceiver.track) {\n transceiver.associatedRemoteMediaStreams.forEach(function(s) {\n var nativeTrack = s.getTracks().find(function(t) {\n return t.id === transceiver.rtpReceiver.track.id;\n });\n if (nativeTrack) {\n removeTrackFromStreamAndFireEvent(nativeTrack, s);\n }\n });\n transceiver.associatedRemoteMediaStreams = [];\n }\n\n transceiver.localCapabilities = localCapabilities;\n transceiver.remoteCapabilities = remoteCapabilities;\n transceiver.rtpReceiver = rtpReceiver;\n transceiver.rtcpParameters = rtcpParameters;\n transceiver.sendEncodingParameters = sendEncodingParameters;\n transceiver.recvEncodingParameters = recvEncodingParameters;\n\n // Start the RTCRtpReceiver now. The RTPSender is started in\n // setLocalDescription.\n pc._transceive(pc.transceivers[sdpMLineIndex],\n false,\n isNewTrack);\n } else if (description.type === 'answer' && !rejected) {\n transceiver = pc.transceivers[sdpMLineIndex];\n iceGatherer = transceiver.iceGatherer;\n iceTransport = transceiver.iceTransport;\n dtlsTransport = transceiver.dtlsTransport;\n rtpReceiver = transceiver.rtpReceiver;\n sendEncodingParameters = transceiver.sendEncodingParameters;\n localCapabilities = transceiver.localCapabilities;\n\n pc.transceivers[sdpMLineIndex].recvEncodingParameters =\n recvEncodingParameters;\n pc.transceivers[sdpMLineIndex].remoteCapabilities =\n remoteCapabilities;\n pc.transceivers[sdpMLineIndex].rtcpParameters = rtcpParameters;\n\n if (cands.length && iceTransport.state === 'new') {\n if ((isIceLite || isComplete) &&\n (!usingBundle || sdpMLineIndex === 0)) {\n iceTransport.setRemoteCandidates(cands);\n } else {\n cands.forEach(function(candidate) {\n maybeAddCandidate(transceiver.iceTransport, candidate);\n });\n }\n }\n\n if (!usingBundle || sdpMLineIndex === 0) {\n if (iceTransport.state === 'new') {\n iceTransport.start(iceGatherer, remoteIceParameters,\n 'controlling');\n }\n if (dtlsTransport.state === 'new') {\n dtlsTransport.start(remoteDtlsParameters);\n }\n }\n\n // If the offer contained RTX but the answer did not,\n // remove RTX from sendEncodingParameters.\n var commonCapabilities = getCommonCapabilities(\n transceiver.localCapabilities,\n transceiver.remoteCapabilities);\n\n var hasRtx = commonCapabilities.codecs.filter(function(c) {\n return c.name.toLowerCase() === 'rtx';\n }).length;\n if (!hasRtx && transceiver.sendEncodingParameters[0].rtx) {\n delete transceiver.sendEncodingParameters[0].rtx;\n }\n\n pc._transceive(transceiver,\n direction === 'sendrecv' || direction === 'recvonly',\n direction === 'sendrecv' || direction === 'sendonly');\n\n // TODO: rewrite to use http://w3c.github.io/webrtc-pc/#set-associated-remote-streams\n if (rtpReceiver &&\n (direction === 'sendrecv' || direction === 'sendonly')) {\n track = rtpReceiver.track;\n if (remoteMsid) {\n if (!streams[remoteMsid.stream]) {\n streams[remoteMsid.stream] = new window.MediaStream();\n }\n addTrackToStreamAndFireEvent(track, streams[remoteMsid.stream]);\n receiverList.push([track, rtpReceiver, streams[remoteMsid.stream]]);\n } else {\n if (!streams.default) {\n streams.default = new window.MediaStream();\n }\n addTrackToStreamAndFireEvent(track, streams.default);\n receiverList.push([track, rtpReceiver, streams.default]);\n }\n } else {\n // FIXME: actually the receiver should be created later.\n delete transceiver.rtpReceiver;\n }\n }\n });\n\n if (pc._dtlsRole === undefined) {\n pc._dtlsRole = description.type === 'offer' ? 'active' : 'passive';\n }\n\n pc._remoteDescription = {\n type: description.type,\n sdp: description.sdp\n };\n if (description.type === 'offer') {\n pc._updateSignalingState('have-remote-offer');\n } else {\n pc._updateSignalingState('stable');\n }\n Object.keys(streams).forEach(function(sid) {\n var stream = streams[sid];\n if (stream.getTracks().length) {\n if (pc.remoteStreams.indexOf(stream) === -1) {\n pc.remoteStreams.push(stream);\n var event = new Event('addstream');\n event.stream = stream;\n window.setTimeout(function() {\n pc._dispatchEvent('addstream', event);\n });\n }\n\n receiverList.forEach(function(item) {\n var track = item[0];\n var receiver = item[1];\n if (stream.id !== item[2].id) {\n return;\n }\n fireAddTrack(pc, track, receiver, [stream]);\n });\n }\n });\n receiverList.forEach(function(item) {\n if (item[2]) {\n return;\n }\n fireAddTrack(pc, item[0], item[1], []);\n });\n\n // check whether addIceCandidate({}) was called within four seconds after\n // setRemoteDescription.\n window.setTimeout(function() {\n if (!(pc && pc.transceivers)) {\n return;\n }\n pc.transceivers.forEach(function(transceiver) {\n if (transceiver.iceTransport &&\n transceiver.iceTransport.state === 'new' &&\n transceiver.iceTransport.getRemoteCandidates().length > 0) {\n console.warn('Timeout for addRemoteCandidate. Consider sending ' +\n 'an end-of-candidates notification');\n transceiver.iceTransport.addRemoteCandidate({});\n }\n });\n }, 4000);\n\n return Promise.resolve();\n };\n\n RTCPeerConnection.prototype.close = function() {\n this.transceivers.forEach(function(transceiver) {\n /* not yet\n if (transceiver.iceGatherer) {\n transceiver.iceGatherer.close();\n }\n */\n if (transceiver.iceTransport) {\n transceiver.iceTransport.stop();\n }\n if (transceiver.dtlsTransport) {\n transceiver.dtlsTransport.stop();\n }\n if (transceiver.rtpSender) {\n transceiver.rtpSender.stop();\n }\n if (transceiver.rtpReceiver) {\n transceiver.rtpReceiver.stop();\n }\n });\n // FIXME: clean up tracks, local streams, remote streams, etc\n this._isClosed = true;\n this._updateSignalingState('closed');\n };\n\n // Update the signaling state.\n RTCPeerConnection.prototype._updateSignalingState = function(newState) {\n this.signalingState = newState;\n var event = new Event('signalingstatechange');\n this._dispatchEvent('signalingstatechange', event);\n };\n\n // Determine whether to fire the negotiationneeded event.\n RTCPeerConnection.prototype._maybeFireNegotiationNeeded = function() {\n var pc = this;\n if (this.signalingState !== 'stable' || this.needNegotiation === true) {\n return;\n }\n this.needNegotiation = true;\n window.setTimeout(function() {\n if (pc.needNegotiation) {\n pc.needNegotiation = false;\n var event = new Event('negotiationneeded');\n pc._dispatchEvent('negotiationneeded', event);\n }\n }, 0);\n };\n\n // Update the ice connection state.\n RTCPeerConnection.prototype._updateIceConnectionState = function() {\n var newState;\n var states = {\n 'new': 0,\n closed: 0,\n checking: 0,\n connected: 0,\n completed: 0,\n disconnected: 0,\n failed: 0\n };\n this.transceivers.forEach(function(transceiver) {\n if (transceiver.iceTransport && !transceiver.rejected) {\n states[transceiver.iceTransport.state]++;\n }\n });\n\n newState = 'new';\n if (states.failed > 0) {\n newState = 'failed';\n } else if (states.checking > 0) {\n newState = 'checking';\n } else if (states.disconnected > 0) {\n newState = 'disconnected';\n } else if (states.new > 0) {\n newState = 'new';\n } else if (states.connected > 0) {\n newState = 'connected';\n } else if (states.completed > 0) {\n newState = 'completed';\n }\n\n if (newState !== this.iceConnectionState) {\n this.iceConnectionState = newState;\n var event = new Event('iceconnectionstatechange');\n this._dispatchEvent('iceconnectionstatechange', event);\n }\n };\n\n // Update the connection state.\n RTCPeerConnection.prototype._updateConnectionState = function() {\n var newState;\n var states = {\n 'new': 0,\n closed: 0,\n connecting: 0,\n connected: 0,\n completed: 0,\n disconnected: 0,\n failed: 0\n };\n this.transceivers.forEach(function(transceiver) {\n if (transceiver.iceTransport && transceiver.dtlsTransport &&\n !transceiver.rejected) {\n states[transceiver.iceTransport.state]++;\n states[transceiver.dtlsTransport.state]++;\n }\n });\n // ICETransport.completed and connected are the same for this purpose.\n states.connected += states.completed;\n\n newState = 'new';\n if (states.failed > 0) {\n newState = 'failed';\n } else if (states.connecting > 0) {\n newState = 'connecting';\n } else if (states.disconnected > 0) {\n newState = 'disconnected';\n } else if (states.new > 0) {\n newState = 'new';\n } else if (states.connected > 0) {\n newState = 'connected';\n }\n\n if (newState !== this.connectionState) {\n this.connectionState = newState;\n var event = new Event('connectionstatechange');\n this._dispatchEvent('connectionstatechange', event);\n }\n };\n\n RTCPeerConnection.prototype.createOffer = function() {\n var pc = this;\n\n if (pc._isClosed) {\n return Promise.reject(makeError('InvalidStateError',\n 'Can not call createOffer after close'));\n }\n\n var numAudioTracks = pc.transceivers.filter(function(t) {\n return t.kind === 'audio';\n }).length;\n var numVideoTracks = pc.transceivers.filter(function(t) {\n return t.kind === 'video';\n }).length;\n\n // Determine number of audio and video tracks we need to send/recv.\n var offerOptions = arguments[0];\n if (offerOptions) {\n // Reject Chrome legacy constraints.\n if (offerOptions.mandatory || offerOptions.optional) {\n throw new TypeError(\n 'Legacy mandatory/optional constraints not supported.');\n }\n if (offerOptions.offerToReceiveAudio !== undefined) {\n if (offerOptions.offerToReceiveAudio === true) {\n numAudioTracks = 1;\n } else if (offerOptions.offerToReceiveAudio === false) {\n numAudioTracks = 0;\n } else {\n numAudioTracks = offerOptions.offerToReceiveAudio;\n }\n }\n if (offerOptions.offerToReceiveVideo !== undefined) {\n if (offerOptions.offerToReceiveVideo === true) {\n numVideoTracks = 1;\n } else if (offerOptions.offerToReceiveVideo === false) {\n numVideoTracks = 0;\n } else {\n numVideoTracks = offerOptions.offerToReceiveVideo;\n }\n }\n }\n\n pc.transceivers.forEach(function(transceiver) {\n if (transceiver.kind === 'audio') {\n numAudioTracks--;\n if (numAudioTracks < 0) {\n transceiver.wantReceive = false;\n }\n } else if (transceiver.kind === 'video') {\n numVideoTracks--;\n if (numVideoTracks < 0) {\n transceiver.wantReceive = false;\n }\n }\n });\n\n // Create M-lines for recvonly streams.\n while (numAudioTracks > 0 || numVideoTracks > 0) {\n if (numAudioTracks > 0) {\n pc._createTransceiver('audio');\n numAudioTracks--;\n }\n if (numVideoTracks > 0) {\n pc._createTransceiver('video');\n numVideoTracks--;\n }\n }\n\n var sdp = SDPUtils.writeSessionBoilerplate(pc._sdpSessionId,\n pc._sdpSessionVersion++);\n pc.transceivers.forEach(function(transceiver, sdpMLineIndex) {\n // For each track, create an ice gatherer, ice transport,\n // dtls transport, potentially rtpsender and rtpreceiver.\n var track = transceiver.track;\n var kind = transceiver.kind;\n var mid = transceiver.mid || SDPUtils.generateIdentifier();\n transceiver.mid = mid;\n\n if (!transceiver.iceGatherer) {\n transceiver.iceGatherer = pc._createIceGatherer(sdpMLineIndex,\n pc.usingBundle);\n }\n\n var localCapabilities = window.RTCRtpSender.getCapabilities(kind);\n // filter RTX until additional stuff needed for RTX is implemented\n // in adapter.js\n if (edgeVersion < 15019) {\n localCapabilities.codecs = localCapabilities.codecs.filter(\n function(codec) {\n return codec.name !== 'rtx';\n });\n }\n localCapabilities.codecs.forEach(function(codec) {\n // work around https://bugs.chromium.org/p/webrtc/issues/detail?id=6552\n // by adding level-asymmetry-allowed=1\n if (codec.name === 'H264' &&\n codec.parameters['level-asymmetry-allowed'] === undefined) {\n codec.parameters['level-asymmetry-allowed'] = '1';\n }\n\n // for subsequent offers, we might have to re-use the payload\n // type of the last offer.\n if (transceiver.remoteCapabilities &&\n transceiver.remoteCapabilities.codecs) {\n transceiver.remoteCapabilities.codecs.forEach(function(remoteCodec) {\n if (codec.name.toLowerCase() === remoteCodec.name.toLowerCase() &&\n codec.clockRate === remoteCodec.clockRate) {\n codec.preferredPayloadType = remoteCodec.payloadType;\n }\n });\n }\n });\n localCapabilities.headerExtensions.forEach(function(hdrExt) {\n var remoteExtensions = transceiver.remoteCapabilities &&\n transceiver.remoteCapabilities.headerExtensions || [];\n remoteExtensions.forEach(function(rHdrExt) {\n if (hdrExt.uri === rHdrExt.uri) {\n hdrExt.id = rHdrExt.id;\n }\n });\n });\n\n // generate an ssrc now, to be used later in rtpSender.send\n var sendEncodingParameters = transceiver.sendEncodingParameters || [{\n ssrc: (2 * sdpMLineIndex + 1) * 1001\n }];\n if (track) {\n // add RTX\n if (edgeVersion >= 15019 && kind === 'video' &&\n !sendEncodingParameters[0].rtx) {\n sendEncodingParameters[0].rtx = {\n ssrc: sendEncodingParameters[0].ssrc + 1\n };\n }\n }\n\n if (transceiver.wantReceive) {\n transceiver.rtpReceiver = new window.RTCRtpReceiver(\n transceiver.dtlsTransport, kind);\n }\n\n transceiver.localCapabilities = localCapabilities;\n transceiver.sendEncodingParameters = sendEncodingParameters;\n });\n\n // always offer BUNDLE and dispose on return if not supported.\n if (pc._config.bundlePolicy !== 'max-compat') {\n sdp += 'a=group:BUNDLE ' + pc.transceivers.map(function(t) {\n return t.mid;\n }).join(' ') + '\\r\\n';\n }\n sdp += 'a=ice-options:trickle\\r\\n';\n\n pc.transceivers.forEach(function(transceiver, sdpMLineIndex) {\n sdp += writeMediaSection(transceiver, transceiver.localCapabilities,\n 'offer', transceiver.stream, pc._dtlsRole);\n sdp += 'a=rtcp-rsize\\r\\n';\n\n if (transceiver.iceGatherer && pc.iceGatheringState !== 'new' &&\n (sdpMLineIndex === 0 || !pc.usingBundle)) {\n transceiver.iceGatherer.getLocalCandidates().forEach(function(cand) {\n cand.component = 1;\n sdp += 'a=' + SDPUtils.writeCandidate(cand) + '\\r\\n';\n });\n\n if (transceiver.iceGatherer.state === 'completed') {\n sdp += 'a=end-of-candidates\\r\\n';\n }\n }\n });\n\n var desc = new window.RTCSessionDescription({\n type: 'offer',\n sdp: sdp\n });\n return Promise.resolve(desc);\n };\n\n RTCPeerConnection.prototype.createAnswer = function() {\n var pc = this;\n\n if (pc._isClosed) {\n return Promise.reject(makeError('InvalidStateError',\n 'Can not call createAnswer after close'));\n }\n\n if (!(pc.signalingState === 'have-remote-offer' ||\n pc.signalingState === 'have-local-pranswer')) {\n return Promise.reject(makeError('InvalidStateError',\n 'Can not call createAnswer in signalingState ' + pc.signalingState));\n }\n\n var sdp = SDPUtils.writeSessionBoilerplate(pc._sdpSessionId,\n pc._sdpSessionVersion++);\n if (pc.usingBundle) {\n sdp += 'a=group:BUNDLE ' + pc.transceivers.map(function(t) {\n return t.mid;\n }).join(' ') + '\\r\\n';\n }\n sdp += 'a=ice-options:trickle\\r\\n';\n\n var mediaSectionsInOffer = SDPUtils.getMediaSections(\n pc._remoteDescription.sdp).length;\n pc.transceivers.forEach(function(transceiver, sdpMLineIndex) {\n if (sdpMLineIndex + 1 > mediaSectionsInOffer) {\n return;\n }\n if (transceiver.rejected) {\n if (transceiver.kind === 'application') {\n if (transceiver.protocol === 'DTLS/SCTP') { // legacy fmt\n sdp += 'm=application 0 DTLS/SCTP 5000\\r\\n';\n } else {\n sdp += 'm=application 0 ' + transceiver.protocol +\n ' webrtc-datachannel\\r\\n';\n }\n } else if (transceiver.kind === 'audio') {\n sdp += 'm=audio 0 UDP/TLS/RTP/SAVPF 0\\r\\n' +\n 'a=rtpmap:0 PCMU/8000\\r\\n';\n } else if (transceiver.kind === 'video') {\n sdp += 'm=video 0 UDP/TLS/RTP/SAVPF 120\\r\\n' +\n 'a=rtpmap:120 VP8/90000\\r\\n';\n }\n sdp += 'c=IN IP4 0.0.0.0\\r\\n' +\n 'a=inactive\\r\\n' +\n 'a=mid:' + transceiver.mid + '\\r\\n';\n return;\n }\n\n // FIXME: look at direction.\n if (transceiver.stream) {\n var localTrack;\n if (transceiver.kind === 'audio') {\n localTrack = transceiver.stream.getAudioTracks()[0];\n } else if (transceiver.kind === 'video') {\n localTrack = transceiver.stream.getVideoTracks()[0];\n }\n if (localTrack) {\n // add RTX\n if (edgeVersion >= 15019 && transceiver.kind === 'video' &&\n !transceiver.sendEncodingParameters[0].rtx) {\n transceiver.sendEncodingParameters[0].rtx = {\n ssrc: transceiver.sendEncodingParameters[0].ssrc + 1\n };\n }\n }\n }\n\n // Calculate intersection of capabilities.\n var commonCapabilities = getCommonCapabilities(\n transceiver.localCapabilities,\n transceiver.remoteCapabilities);\n\n var hasRtx = commonCapabilities.codecs.filter(function(c) {\n return c.name.toLowerCase() === 'rtx';\n }).length;\n if (!hasRtx && transceiver.sendEncodingParameters[0].rtx) {\n delete transceiver.sendEncodingParameters[0].rtx;\n }\n\n sdp += writeMediaSection(transceiver, commonCapabilities,\n 'answer', transceiver.stream, pc._dtlsRole);\n if (transceiver.rtcpParameters &&\n transceiver.rtcpParameters.reducedSize) {\n sdp += 'a=rtcp-rsize\\r\\n';\n }\n });\n\n var desc = new window.RTCSessionDescription({\n type: 'answer',\n sdp: sdp\n });\n return Promise.resolve(desc);\n };\n\n RTCPeerConnection.prototype.addIceCandidate = function(candidate) {\n var pc = this;\n var sections;\n if (candidate && !(candidate.sdpMLineIndex !== undefined ||\n candidate.sdpMid)) {\n return Promise.reject(new TypeError('sdpMLineIndex or sdpMid required'));\n }\n\n // TODO: needs to go into ops queue.\n return new Promise(function(resolve, reject) {\n if (!pc._remoteDescription) {\n return reject(makeError('InvalidStateError',\n 'Can not add ICE candidate without a remote description'));\n } else if (!candidate || candidate.candidate === '') {\n for (var j = 0; j < pc.transceivers.length; j++) {\n if (pc.transceivers[j].rejected) {\n continue;\n }\n pc.transceivers[j].iceTransport.addRemoteCandidate({});\n sections = SDPUtils.getMediaSections(pc._remoteDescription.sdp);\n sections[j] += 'a=end-of-candidates\\r\\n';\n pc._remoteDescription.sdp =\n SDPUtils.getDescription(pc._remoteDescription.sdp) +\n sections.join('');\n if (pc.usingBundle) {\n break;\n }\n }\n } else {\n var sdpMLineIndex = candidate.sdpMLineIndex;\n if (candidate.sdpMid) {\n for (var i = 0; i < pc.transceivers.length; i++) {\n if (pc.transceivers[i].mid === candidate.sdpMid) {\n sdpMLineIndex = i;\n break;\n }\n }\n }\n var transceiver = pc.transceivers[sdpMLineIndex];\n if (transceiver) {\n if (transceiver.rejected) {\n return resolve();\n }\n var cand = Object.keys(candidate.candidate).length > 0 ?\n SDPUtils.parseCandidate(candidate.candidate) : {};\n // Ignore Chrome's invalid candidates since Edge does not like them.\n if (cand.protocol === 'tcp' && (cand.port === 0 || cand.port === 9)) {\n return resolve();\n }\n // Ignore RTCP candidates, we assume RTCP-MUX.\n if (cand.component && cand.component !== 1) {\n return resolve();\n }\n // when using bundle, avoid adding candidates to the wrong\n // ice transport. And avoid adding candidates added in the SDP.\n if (sdpMLineIndex === 0 || (sdpMLineIndex > 0 &&\n transceiver.iceTransport !== pc.transceivers[0].iceTransport)) {\n if (!maybeAddCandidate(transceiver.iceTransport, cand)) {\n return reject(makeError('OperationError',\n 'Can not add ICE candidate'));\n }\n }\n\n // update the remoteDescription.\n var candidateString = candidate.candidate.trim();\n if (candidateString.indexOf('a=') === 0) {\n candidateString = candidateString.substr(2);\n }\n sections = SDPUtils.getMediaSections(pc._remoteDescription.sdp);\n sections[sdpMLineIndex] += 'a=' +\n (cand.type ? candidateString : 'end-of-candidates')\n + '\\r\\n';\n pc._remoteDescription.sdp =\n SDPUtils.getDescription(pc._remoteDescription.sdp) +\n sections.join('');\n } else {\n return reject(makeError('OperationError',\n 'Can not add ICE candidate'));\n }\n }\n resolve();\n });\n };\n\n RTCPeerConnection.prototype.getStats = function(selector) {\n if (selector && selector instanceof window.MediaStreamTrack) {\n var senderOrReceiver = null;\n this.transceivers.forEach(function(transceiver) {\n if (transceiver.rtpSender &&\n transceiver.rtpSender.track === selector) {\n senderOrReceiver = transceiver.rtpSender;\n } else if (transceiver.rtpReceiver &&\n transceiver.rtpReceiver.track === selector) {\n senderOrReceiver = transceiver.rtpReceiver;\n }\n });\n if (!senderOrReceiver) {\n throw makeError('InvalidAccessError', 'Invalid selector.');\n }\n return senderOrReceiver.getStats();\n }\n\n var promises = [];\n this.transceivers.forEach(function(transceiver) {\n ['rtpSender', 'rtpReceiver', 'iceGatherer', 'iceTransport',\n 'dtlsTransport'].forEach(function(method) {\n if (transceiver[method]) {\n promises.push(transceiver[method].getStats());\n }\n });\n });\n return Promise.all(promises).then(function(allStats) {\n var results = new Map();\n allStats.forEach(function(stats) {\n stats.forEach(function(stat) {\n results.set(stat.id, stat);\n });\n });\n return results;\n });\n };\n\n // fix low-level stat names and return Map instead of object.\n var ortcObjects = ['RTCRtpSender', 'RTCRtpReceiver', 'RTCIceGatherer',\n 'RTCIceTransport', 'RTCDtlsTransport'];\n ortcObjects.forEach(function(ortcObjectName) {\n var obj = window[ortcObjectName];\n if (obj && obj.prototype && obj.prototype.getStats) {\n var nativeGetstats = obj.prototype.getStats;\n obj.prototype.getStats = function() {\n return nativeGetstats.apply(this)\n .then(function(nativeStats) {\n var mapStats = new Map();\n Object.keys(nativeStats).forEach(function(id) {\n nativeStats[id].type = fixStatsType(nativeStats[id]);\n mapStats.set(id, nativeStats[id]);\n });\n return mapStats;\n });\n };\n }\n });\n\n // legacy callback shims. Should be moved to adapter.js some days.\n var methods = ['createOffer', 'createAnswer'];\n methods.forEach(function(method) {\n var nativeMethod = RTCPeerConnection.prototype[method];\n RTCPeerConnection.prototype[method] = function() {\n var args = arguments;\n if (typeof args[0] === 'function' ||\n typeof args[1] === 'function') { // legacy\n return nativeMethod.apply(this, [arguments[2]])\n .then(function(description) {\n if (typeof args[0] === 'function') {\n args[0].apply(null, [description]);\n }\n }, function(error) {\n if (typeof args[1] === 'function') {\n args[1].apply(null, [error]);\n }\n });\n }\n return nativeMethod.apply(this, arguments);\n };\n });\n\n methods = ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'];\n methods.forEach(function(method) {\n var nativeMethod = RTCPeerConnection.prototype[method];\n RTCPeerConnection.prototype[method] = function() {\n var args = arguments;\n if (typeof args[1] === 'function' ||\n typeof args[2] === 'function') { // legacy\n return nativeMethod.apply(this, arguments)\n .then(function() {\n if (typeof args[1] === 'function') {\n args[1].apply(null);\n }\n }, function(error) {\n if (typeof args[2] === 'function') {\n args[2].apply(null, [error]);\n }\n });\n }\n return nativeMethod.apply(this, arguments);\n };\n });\n\n // getStats is special. It doesn't have a spec legacy method yet we support\n // getStats(something, cb) without error callbacks.\n ['getStats'].forEach(function(method) {\n var nativeMethod = RTCPeerConnection.prototype[method];\n RTCPeerConnection.prototype[method] = function() {\n var args = arguments;\n if (typeof args[1] === 'function') {\n return nativeMethod.apply(this, arguments)\n .then(function() {\n if (typeof args[1] === 'function') {\n args[1].apply(null);\n }\n });\n }\n return nativeMethod.apply(this, arguments);\n };\n });\n\n return RTCPeerConnection;\n};\n","/*\n * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n /* eslint-env node */\n'use strict';\n\nexport function shimGetUserMedia(window) {\n const navigator = window && window.navigator;\n\n const shimError_ = function(e) {\n return {\n name: {PermissionDeniedError: 'NotAllowedError'}[e.name] || e.name,\n message: e.message,\n constraint: e.constraint,\n toString() {\n return this.name;\n }\n };\n };\n\n // getUserMedia error shim.\n const origGetUserMedia = navigator.mediaDevices.getUserMedia.\n bind(navigator.mediaDevices);\n navigator.mediaDevices.getUserMedia = function(c) {\n return origGetUserMedia(c).catch(e => Promise.reject(shimError_(e)));\n };\n}\n","/*\n * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n /* eslint-env node */\n'use strict';\n\nexport function shimGetDisplayMedia(window) {\n if (!('getDisplayMedia' in window.navigator)) {\n return;\n }\n if (!(window.navigator.mediaDevices)) {\n return;\n }\n if (window.navigator.mediaDevices &&\n 'getDisplayMedia' in window.navigator.mediaDevices) {\n return;\n }\n window.navigator.mediaDevices.getDisplayMedia =\n window.navigator.getDisplayMedia.bind(window.navigator);\n}\n","/*\n * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n/* eslint-env node */\n'use strict';\n\nimport * as utils from '../utils';\nimport {filterIceServers} from './filtericeservers';\nimport shimRTCPeerConnection from 'rtcpeerconnection-shim';\n\nexport {shimGetUserMedia} from './getusermedia';\nexport {shimGetDisplayMedia} from './getdisplaymedia';\n\nexport function shimPeerConnection(window, browserDetails) {\n if (window.RTCIceGatherer) {\n if (!window.RTCIceCandidate) {\n window.RTCIceCandidate = function RTCIceCandidate(args) {\n return args;\n };\n }\n if (!window.RTCSessionDescription) {\n window.RTCSessionDescription = function RTCSessionDescription(args) {\n return args;\n };\n }\n // this adds an additional event listener to MediaStrackTrack that signals\n // when a tracks enabled property was changed. Workaround for a bug in\n // addStream, see below. No longer required in 15025+\n if (browserDetails.version < 15025) {\n const origMSTEnabled = Object.getOwnPropertyDescriptor(\n window.MediaStreamTrack.prototype, 'enabled');\n Object.defineProperty(window.MediaStreamTrack.prototype, 'enabled', {\n set(value) {\n origMSTEnabled.set.call(this, value);\n const ev = new Event('enabled');\n ev.enabled = value;\n this.dispatchEvent(ev);\n }\n });\n }\n }\n\n // ORTC defines the DTMF sender a bit different.\n // https://github.com/w3c/ortc/issues/714\n if (window.RTCRtpSender && !('dtmf' in window.RTCRtpSender.prototype)) {\n Object.defineProperty(window.RTCRtpSender.prototype, 'dtmf', {\n get() {\n if (this._dtmf === undefined) {\n if (this.track.kind === 'audio') {\n this._dtmf = new window.RTCDtmfSender(this);\n } else if (this.track.kind === 'video') {\n this._dtmf = null;\n }\n }\n return this._dtmf;\n }\n });\n }\n // Edge currently only implements the RTCDtmfSender, not the\n // RTCDTMFSender alias. See http://draft.ortc.org/#rtcdtmfsender2*\n if (window.RTCDtmfSender && !window.RTCDTMFSender) {\n window.RTCDTMFSender = window.RTCDtmfSender;\n }\n\n const RTCPeerConnectionShim = shimRTCPeerConnection(window,\n browserDetails.version);\n window.RTCPeerConnection = function RTCPeerConnection(config) {\n if (config && config.iceServers) {\n config.iceServers = filterIceServers(config.iceServers,\n browserDetails.version);\n utils.log('ICE servers after filtering:', config.iceServers);\n }\n return new RTCPeerConnectionShim(config);\n };\n window.RTCPeerConnection.prototype = RTCPeerConnectionShim.prototype;\n}\n\nexport function shimReplaceTrack(window) {\n // ORTC has replaceTrack -- https://github.com/w3c/ortc/issues/614\n if (window.RTCRtpSender &&\n !('replaceTrack' in window.RTCRtpSender.prototype)) {\n window.RTCRtpSender.prototype.replaceTrack =\n window.RTCRtpSender.prototype.setTrack;\n }\n}\n","/*\n * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n/* eslint-env node */\n'use strict';\n\nimport * as utils from '../utils';\n\nexport function shimGetUserMedia(window, browserDetails) {\n const navigator = window && window.navigator;\n const MediaStreamTrack = window && window.MediaStreamTrack;\n\n navigator.getUserMedia = function(constraints, onSuccess, onError) {\n // Replace Firefox 44+'s deprecation warning with unprefixed version.\n utils.deprecated('navigator.getUserMedia',\n 'navigator.mediaDevices.getUserMedia');\n navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError);\n };\n\n if (!(browserDetails.version > 55 &&\n 'autoGainControl' in navigator.mediaDevices.getSupportedConstraints())) {\n const remap = function(obj, a, b) {\n if (a in obj && !(b in obj)) {\n obj[b] = obj[a];\n delete obj[a];\n }\n };\n\n const nativeGetUserMedia = navigator.mediaDevices.getUserMedia.\n bind(navigator.mediaDevices);\n navigator.mediaDevices.getUserMedia = function(c) {\n if (typeof c === 'object' && typeof c.audio === 'object') {\n c = JSON.parse(JSON.stringify(c));\n remap(c.audio, 'autoGainControl', 'mozAutoGainControl');\n remap(c.audio, 'noiseSuppression', 'mozNoiseSuppression');\n }\n return nativeGetUserMedia(c);\n };\n\n if (MediaStreamTrack && MediaStreamTrack.prototype.getSettings) {\n const nativeGetSettings = MediaStreamTrack.prototype.getSettings;\n MediaStreamTrack.prototype.getSettings = function() {\n const obj = nativeGetSettings.apply(this, arguments);\n remap(obj, 'mozAutoGainControl', 'autoGainControl');\n remap(obj, 'mozNoiseSuppression', 'noiseSuppression');\n return obj;\n };\n }\n\n if (MediaStreamTrack && MediaStreamTrack.prototype.applyConstraints) {\n const nativeApplyConstraints =\n MediaStreamTrack.prototype.applyConstraints;\n MediaStreamTrack.prototype.applyConstraints = function(c) {\n if (this.kind === 'audio' && typeof c === 'object') {\n c = JSON.parse(JSON.stringify(c));\n remap(c, 'autoGainControl', 'mozAutoGainControl');\n remap(c, 'noiseSuppression', 'mozNoiseSuppression');\n }\n return nativeApplyConstraints.apply(this, [c]);\n };\n }\n }\n}\n","/*\n * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n/* eslint-env node */\n'use strict';\n\nexport function shimGetDisplayMedia(window, preferredMediaSource) {\n if (window.navigator.mediaDevices &&\n 'getDisplayMedia' in window.navigator.mediaDevices) {\n return;\n }\n if (!(window.navigator.mediaDevices)) {\n return;\n }\n window.navigator.mediaDevices.getDisplayMedia =\n function getDisplayMedia(constraints) {\n if (!(constraints && constraints.video)) {\n const err = new DOMException('getDisplayMedia without video ' +\n 'constraints is undefined');\n err.name = 'NotFoundError';\n // from https://heycam.github.io/webidl/#idl-DOMException-error-names\n err.code = 8;\n return Promise.reject(err);\n }\n if (constraints.video === true) {\n constraints.video = {mediaSource: preferredMediaSource};\n } else {\n constraints.video.mediaSource = preferredMediaSource;\n }\n return window.navigator.mediaDevices.getUserMedia(constraints);\n };\n}\n","/*\n * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n/* eslint-env node */\n'use strict';\n\nimport * as utils from '../utils';\nexport {shimGetUserMedia} from './getusermedia';\nexport {shimGetDisplayMedia} from './getdisplaymedia';\n\nexport function shimOnTrack(window) {\n if (typeof window === 'object' && window.RTCTrackEvent &&\n ('receiver' in window.RTCTrackEvent.prototype) &&\n !('transceiver' in window.RTCTrackEvent.prototype)) {\n Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', {\n get() {\n return {receiver: this.receiver};\n }\n });\n }\n}\n\nexport function shimPeerConnection(window, browserDetails) {\n if (typeof window !== 'object' ||\n !(window.RTCPeerConnection || window.mozRTCPeerConnection)) {\n return; // probably media.peerconnection.enabled=false in about:config\n }\n if (!window.RTCPeerConnection && window.mozRTCPeerConnection) {\n // very basic support for old versions.\n window.RTCPeerConnection = window.mozRTCPeerConnection;\n }\n\n if (browserDetails.version < 53) {\n // shim away need for obsolete RTCIceCandidate/RTCSessionDescription.\n ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate']\n .forEach(function(method) {\n const nativeMethod = window.RTCPeerConnection.prototype[method];\n const methodObj = {[method]() {\n arguments[0] = new ((method === 'addIceCandidate') ?\n window.RTCIceCandidate :\n window.RTCSessionDescription)(arguments[0]);\n return nativeMethod.apply(this, arguments);\n }};\n window.RTCPeerConnection.prototype[method] = methodObj[method];\n });\n }\n\n const modernStatsTypes = {\n inboundrtp: 'inbound-rtp',\n outboundrtp: 'outbound-rtp',\n candidatepair: 'candidate-pair',\n localcandidate: 'local-candidate',\n remotecandidate: 'remote-candidate'\n };\n\n const nativeGetStats = window.RTCPeerConnection.prototype.getStats;\n window.RTCPeerConnection.prototype.getStats = function getStats() {\n const [selector, onSucc, onErr] = arguments;\n return nativeGetStats.apply(this, [selector || null])\n .then(stats => {\n if (browserDetails.version < 53 && !onSucc) {\n // Shim only promise getStats with spec-hyphens in type names\n // Leave callback version alone; misc old uses of forEach before Map\n try {\n stats.forEach(stat => {\n stat.type = modernStatsTypes[stat.type] || stat.type;\n });\n } catch (e) {\n if (e.name !== 'TypeError') {\n throw e;\n }\n // Avoid TypeError: \"type\" is read-only, in old versions. 34-43ish\n stats.forEach((stat, i) => {\n stats.set(i, Object.assign({}, stat, {\n type: modernStatsTypes[stat.type] || stat.type\n }));\n });\n }\n }\n return stats;\n })\n .then(onSucc, onErr);\n };\n}\n\nexport function shimSenderGetStats(window) {\n if (!(typeof window === 'object' && window.RTCPeerConnection &&\n window.RTCRtpSender)) {\n return;\n }\n if (window.RTCRtpSender && 'getStats' in window.RTCRtpSender.prototype) {\n return;\n }\n const origGetSenders = window.RTCPeerConnection.prototype.getSenders;\n if (origGetSenders) {\n window.RTCPeerConnection.prototype.getSenders = function getSenders() {\n const senders = origGetSenders.apply(this, []);\n senders.forEach(sender => sender._pc = this);\n return senders;\n };\n }\n\n const origAddTrack = window.RTCPeerConnection.prototype.addTrack;\n if (origAddTrack) {\n window.RTCPeerConnection.prototype.addTrack = function addTrack() {\n const sender = origAddTrack.apply(this, arguments);\n sender._pc = this;\n return sender;\n };\n }\n window.RTCRtpSender.prototype.getStats = function getStats() {\n return this.track ? this._pc.getStats(this.track) :\n Promise.resolve(new Map());\n };\n}\n\nexport function shimReceiverGetStats(window) {\n if (!(typeof window === 'object' && window.RTCPeerConnection &&\n window.RTCRtpSender)) {\n return;\n }\n if (window.RTCRtpSender && 'getStats' in window.RTCRtpReceiver.prototype) {\n return;\n }\n const origGetReceivers = window.RTCPeerConnection.prototype.getReceivers;\n if (origGetReceivers) {\n window.RTCPeerConnection.prototype.getReceivers = function getReceivers() {\n const receivers = origGetReceivers.apply(this, []);\n receivers.forEach(receiver => receiver._pc = this);\n return receivers;\n };\n }\n utils.wrapPeerConnectionEvent(window, 'track', e => {\n e.receiver._pc = e.srcElement;\n return e;\n });\n window.RTCRtpReceiver.prototype.getStats = function getStats() {\n return this._pc.getStats(this.track);\n };\n}\n\nexport function shimRemoveStream(window) {\n if (!window.RTCPeerConnection ||\n 'removeStream' in window.RTCPeerConnection.prototype) {\n return;\n }\n window.RTCPeerConnection.prototype.removeStream =\n function removeStream(stream) {\n utils.deprecated('removeStream', 'removeTrack');\n this.getSenders().forEach(sender => {\n if (sender.track && stream.getTracks().includes(sender.track)) {\n this.removeTrack(sender);\n }\n });\n };\n}\n\nexport function shimRTCDataChannel(window) {\n // rename DataChannel to RTCDataChannel (native fix in FF60):\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1173851\n if (window.DataChannel && !window.RTCDataChannel) {\n window.RTCDataChannel = window.DataChannel;\n }\n}\n\nexport function shimAddTransceiver(window) {\n // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647\n // Firefox ignores the init sendEncodings options passed to addTransceiver\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918\n if (!(typeof window === 'object' && window.RTCPeerConnection)) {\n return;\n }\n const origAddTransceiver = window.RTCPeerConnection.prototype.addTransceiver;\n if (origAddTransceiver) {\n window.RTCPeerConnection.prototype.addTransceiver =\n function addTransceiver() {\n this.setParametersPromises = [];\n const initParameters = arguments[1];\n const shouldPerformCheck = initParameters &&\n 'sendEncodings' in initParameters;\n if (shouldPerformCheck) {\n // If sendEncodings params are provided, validate grammar\n initParameters.sendEncodings.forEach((encodingParam) => {\n if ('rid' in encodingParam) {\n const ridRegex = /^[a-z0-9]{0,16}$/i;\n if (!ridRegex.test(encodingParam.rid)) {\n throw new TypeError('Invalid RID value provided.');\n }\n }\n if ('scaleResolutionDownBy' in encodingParam) {\n if (!(parseFloat(encodingParam.scaleResolutionDownBy) >= 1.0)) {\n throw new RangeError('scale_resolution_down_by must be >= 1.0');\n }\n }\n if ('maxFramerate' in encodingParam) {\n if (!(parseFloat(encodingParam.maxFramerate) >= 0)) {\n throw new RangeError('max_framerate must be >= 0.0');\n }\n }\n });\n }\n const transceiver = origAddTransceiver.apply(this, arguments);\n if (shouldPerformCheck) {\n // Check if the init options were applied. If not we do this in an\n // asynchronous way and save the promise reference in a global object.\n // This is an ugly hack, but at the same time is way more robust than\n // checking the sender parameters before and after the createOffer\n // Also note that after the createoffer we are not 100% sure that\n // the params were asynchronously applied so we might miss the\n // opportunity to recreate offer.\n const {sender} = transceiver;\n const params = sender.getParameters();\n if (!('encodings' in params) ||\n // Avoid being fooled by patched getParameters() below.\n (params.encodings.length === 1 &&\n Object.keys(params.encodings[0]).length === 0)) {\n params.encodings = initParameters.sendEncodings;\n sender.sendEncodings = initParameters.sendEncodings;\n this.setParametersPromises.push(sender.setParameters(params)\n .then(() => {\n delete sender.sendEncodings;\n }).catch(() => {\n delete sender.sendEncodings;\n })\n );\n }\n }\n return transceiver;\n };\n }\n}\n\nexport function shimGetParameters(window) {\n if (!(typeof window === 'object' && window.RTCRtpSender)) {\n return;\n }\n const origGetParameters = window.RTCRtpSender.prototype.getParameters;\n if (origGetParameters) {\n window.RTCRtpSender.prototype.getParameters =\n function getParameters() {\n const params = origGetParameters.apply(this, arguments);\n if (!('encodings' in params)) {\n params.encodings = [].concat(this.sendEncodings || [{}]);\n }\n return params;\n };\n }\n}\n\nexport function shimCreateOffer(window) {\n // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647\n // Firefox ignores the init sendEncodings options passed to addTransceiver\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918\n if (!(typeof window === 'object' && window.RTCPeerConnection)) {\n return;\n }\n const origCreateOffer = window.RTCPeerConnection.prototype.createOffer;\n window.RTCPeerConnection.prototype.createOffer = function createOffer() {\n if (this.setParametersPromises && this.setParametersPromises.length) {\n return Promise.all(this.setParametersPromises)\n .then(() => {\n return origCreateOffer.apply(this, arguments);\n })\n .finally(() => {\n this.setParametersPromises = [];\n });\n }\n return origCreateOffer.apply(this, arguments);\n };\n}\n\nexport function shimCreateAnswer(window) {\n // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647\n // Firefox ignores the init sendEncodings options passed to addTransceiver\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918\n if (!(typeof window === 'object' && window.RTCPeerConnection)) {\n return;\n }\n const origCreateAnswer = window.RTCPeerConnection.prototype.createAnswer;\n window.RTCPeerConnection.prototype.createAnswer = function createAnswer() {\n if (this.setParametersPromises && this.setParametersPromises.length) {\n return Promise.all(this.setParametersPromises)\n .then(() => {\n return origCreateAnswer.apply(this, arguments);\n })\n .finally(() => {\n this.setParametersPromises = [];\n });\n }\n return origCreateAnswer.apply(this, arguments);\n };\n}\n","/*\n * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n'use strict';\nimport * as utils from '../utils';\n\nexport function shimLocalStreamsAPI(window) {\n if (typeof window !== 'object' || !window.RTCPeerConnection) {\n return;\n }\n if (!('getLocalStreams' in window.RTCPeerConnection.prototype)) {\n window.RTCPeerConnection.prototype.getLocalStreams =\n function getLocalStreams() {\n if (!this._localStreams) {\n this._localStreams = [];\n }\n return this._localStreams;\n };\n }\n if (!('addStream' in window.RTCPeerConnection.prototype)) {\n const _addTrack = window.RTCPeerConnection.prototype.addTrack;\n window.RTCPeerConnection.prototype.addStream = function addStream(stream) {\n if (!this._localStreams) {\n this._localStreams = [];\n }\n if (!this._localStreams.includes(stream)) {\n this._localStreams.push(stream);\n }\n // Try to emulate Chrome's behaviour of adding in audio-video order.\n // Safari orders by track id.\n stream.getAudioTracks().forEach(track => _addTrack.call(this, track,\n stream));\n stream.getVideoTracks().forEach(track => _addTrack.call(this, track,\n stream));\n };\n\n window.RTCPeerConnection.prototype.addTrack =\n function addTrack(track, ...streams) {\n if (streams) {\n streams.forEach((stream) => {\n if (!this._localStreams) {\n this._localStreams = [stream];\n } else if (!this._localStreams.includes(stream)) {\n this._localStreams.push(stream);\n }\n });\n }\n return _addTrack.apply(this, arguments);\n };\n }\n if (!('removeStream' in window.RTCPeerConnection.prototype)) {\n window.RTCPeerConnection.prototype.removeStream =\n function removeStream(stream) {\n if (!this._localStreams) {\n this._localStreams = [];\n }\n const index = this._localStreams.indexOf(stream);\n if (index === -1) {\n return;\n }\n this._localStreams.splice(index, 1);\n const tracks = stream.getTracks();\n this.getSenders().forEach(sender => {\n if (tracks.includes(sender.track)) {\n this.removeTrack(sender);\n }\n });\n };\n }\n}\n\nexport function shimRemoteStreamsAPI(window) {\n if (typeof window !== 'object' || !window.RTCPeerConnection) {\n return;\n }\n if (!('getRemoteStreams' in window.RTCPeerConnection.prototype)) {\n window.RTCPeerConnection.prototype.getRemoteStreams =\n function getRemoteStreams() {\n return this._remoteStreams ? this._remoteStreams : [];\n };\n }\n if (!('onaddstream' in window.RTCPeerConnection.prototype)) {\n Object.defineProperty(window.RTCPeerConnection.prototype, 'onaddstream', {\n get() {\n return this._onaddstream;\n },\n set(f) {\n if (this._onaddstream) {\n this.removeEventListener('addstream', this._onaddstream);\n this.removeEventListener('track', this._onaddstreampoly);\n }\n this.addEventListener('addstream', this._onaddstream = f);\n this.addEventListener('track', this._onaddstreampoly = (e) => {\n e.streams.forEach(stream => {\n if (!this._remoteStreams) {\n this._remoteStreams = [];\n }\n if (this._remoteStreams.includes(stream)) {\n return;\n }\n this._remoteStreams.push(stream);\n const event = new Event('addstream');\n event.stream = stream;\n this.dispatchEvent(event);\n });\n });\n }\n });\n const origSetRemoteDescription =\n window.RTCPeerConnection.prototype.setRemoteDescription;\n window.RTCPeerConnection.prototype.setRemoteDescription =\n function setRemoteDescription() {\n const pc = this;\n if (!this._onaddstreampoly) {\n this.addEventListener('track', this._onaddstreampoly = function(e) {\n e.streams.forEach(stream => {\n if (!pc._remoteStreams) {\n pc._remoteStreams = [];\n }\n if (pc._remoteStreams.indexOf(stream) >= 0) {\n return;\n }\n pc._remoteStreams.push(stream);\n const event = new Event('addstream');\n event.stream = stream;\n pc.dispatchEvent(event);\n });\n });\n }\n return origSetRemoteDescription.apply(pc, arguments);\n };\n }\n}\n\nexport function shimCallbacksAPI(window) {\n if (typeof window !== 'object' || !window.RTCPeerConnection) {\n return;\n }\n const prototype = window.RTCPeerConnection.prototype;\n const origCreateOffer = prototype.createOffer;\n const origCreateAnswer = prototype.createAnswer;\n const setLocalDescription = prototype.setLocalDescription;\n const setRemoteDescription = prototype.setRemoteDescription;\n const addIceCandidate = prototype.addIceCandidate;\n\n prototype.createOffer =\n function createOffer(successCallback, failureCallback) {\n const options = (arguments.length >= 2) ? arguments[2] : arguments[0];\n const promise = origCreateOffer.apply(this, [options]);\n if (!failureCallback) {\n return promise;\n }\n promise.then(successCallback, failureCallback);\n return Promise.resolve();\n };\n\n prototype.createAnswer =\n function createAnswer(successCallback, failureCallback) {\n const options = (arguments.length >= 2) ? arguments[2] : arguments[0];\n const promise = origCreateAnswer.apply(this, [options]);\n if (!failureCallback) {\n return promise;\n }\n promise.then(successCallback, failureCallback);\n return Promise.resolve();\n };\n\n let withCallback = function(description, successCallback, failureCallback) {\n const promise = setLocalDescription.apply(this, [description]);\n if (!failureCallback) {\n return promise;\n }\n promise.then(successCallback, failureCallback);\n return Promise.resolve();\n };\n prototype.setLocalDescription = withCallback;\n\n withCallback = function(description, successCallback, failureCallback) {\n const promise = setRemoteDescription.apply(this, [description]);\n if (!failureCallback) {\n return promise;\n }\n promise.then(successCallback, failureCallback);\n return Promise.resolve();\n };\n prototype.setRemoteDescription = withCallback;\n\n withCallback = function(candidate, successCallback, failureCallback) {\n const promise = addIceCandidate.apply(this, [candidate]);\n if (!failureCallback) {\n return promise;\n }\n promise.then(successCallback, failureCallback);\n return Promise.resolve();\n };\n prototype.addIceCandidate = withCallback;\n}\n\nexport function shimGetUserMedia(window) {\n const navigator = window && window.navigator;\n\n if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {\n // shim not needed in Safari 12.1\n const mediaDevices = navigator.mediaDevices;\n const _getUserMedia = mediaDevices.getUserMedia.bind(mediaDevices);\n navigator.mediaDevices.getUserMedia = (constraints) => {\n return _getUserMedia(shimConstraints(constraints));\n };\n }\n\n if (!navigator.getUserMedia && navigator.mediaDevices &&\n navigator.mediaDevices.getUserMedia) {\n navigator.getUserMedia = function getUserMedia(constraints, cb, errcb) {\n navigator.mediaDevices.getUserMedia(constraints)\n .then(cb, errcb);\n }.bind(navigator);\n }\n}\n\nexport function shimConstraints(constraints) {\n if (constraints && constraints.video !== undefined) {\n return Object.assign({},\n constraints,\n {video: utils.compactObject(constraints.video)}\n );\n }\n\n return constraints;\n}\n\nexport function shimRTCIceServerUrls(window) {\n if (!window.RTCPeerConnection) {\n return;\n }\n // migrate from non-spec RTCIceServer.url to RTCIceServer.urls\n const OrigPeerConnection = window.RTCPeerConnection;\n window.RTCPeerConnection =\n function RTCPeerConnection(pcConfig, pcConstraints) {\n if (pcConfig && pcConfig.iceServers) {\n const newIceServers = [];\n for (let i = 0; i < pcConfig.iceServers.length; i++) {\n let server = pcConfig.iceServers[i];\n if (!server.hasOwnProperty('urls') &&\n server.hasOwnProperty('url')) {\n utils.deprecated('RTCIceServer.url', 'RTCIceServer.urls');\n server = JSON.parse(JSON.stringify(server));\n server.urls = server.url;\n delete server.url;\n newIceServers.push(server);\n } else {\n newIceServers.push(pcConfig.iceServers[i]);\n }\n }\n pcConfig.iceServers = newIceServers;\n }\n return new OrigPeerConnection(pcConfig, pcConstraints);\n };\n window.RTCPeerConnection.prototype = OrigPeerConnection.prototype;\n // wrap static methods. Currently just generateCertificate.\n if ('generateCertificate' in OrigPeerConnection) {\n Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {\n get() {\n return OrigPeerConnection.generateCertificate;\n }\n });\n }\n}\n\nexport function shimTrackEventTransceiver(window) {\n // Add event.transceiver member over deprecated event.receiver\n if (typeof window === 'object' && window.RTCTrackEvent &&\n 'receiver' in window.RTCTrackEvent.prototype &&\n !('transceiver' in window.RTCTrackEvent.prototype)) {\n Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', {\n get() {\n return {receiver: this.receiver};\n }\n });\n }\n}\n\nexport function shimCreateOfferLegacy(window) {\n const origCreateOffer = window.RTCPeerConnection.prototype.createOffer;\n window.RTCPeerConnection.prototype.createOffer =\n function createOffer(offerOptions) {\n if (offerOptions) {\n if (typeof offerOptions.offerToReceiveAudio !== 'undefined') {\n // support bit values\n offerOptions.offerToReceiveAudio =\n !!offerOptions.offerToReceiveAudio;\n }\n const audioTransceiver = this.getTransceivers().find(transceiver =>\n transceiver.receiver.track.kind === 'audio');\n if (offerOptions.offerToReceiveAudio === false && audioTransceiver) {\n if (audioTransceiver.direction === 'sendrecv') {\n if (audioTransceiver.setDirection) {\n audioTransceiver.setDirection('sendonly');\n } else {\n audioTransceiver.direction = 'sendonly';\n }\n } else if (audioTransceiver.direction === 'recvonly') {\n if (audioTransceiver.setDirection) {\n audioTransceiver.setDirection('inactive');\n } else {\n audioTransceiver.direction = 'inactive';\n }\n }\n } else if (offerOptions.offerToReceiveAudio === true &&\n !audioTransceiver) {\n this.addTransceiver('audio');\n }\n\n if (typeof offerOptions.offerToReceiveVideo !== 'undefined') {\n // support bit values\n offerOptions.offerToReceiveVideo =\n !!offerOptions.offerToReceiveVideo;\n }\n const videoTransceiver = this.getTransceivers().find(transceiver =>\n transceiver.receiver.track.kind === 'video');\n if (offerOptions.offerToReceiveVideo === false && videoTransceiver) {\n if (videoTransceiver.direction === 'sendrecv') {\n if (videoTransceiver.setDirection) {\n videoTransceiver.setDirection('sendonly');\n } else {\n videoTransceiver.direction = 'sendonly';\n }\n } else if (videoTransceiver.direction === 'recvonly') {\n if (videoTransceiver.setDirection) {\n videoTransceiver.setDirection('inactive');\n } else {\n videoTransceiver.direction = 'inactive';\n }\n }\n } else if (offerOptions.offerToReceiveVideo === true &&\n !videoTransceiver) {\n this.addTransceiver('video');\n }\n }\n return origCreateOffer.apply(this, arguments);\n };\n}\n\nexport function shimAudioContext(window) {\n if (typeof window !== 'object' || window.AudioContext) {\n return;\n }\n window.AudioContext = window.webkitAudioContext;\n}\n","/*\n * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n/* eslint-env node */\n'use strict';\n\nimport SDPUtils from 'sdp';\nimport * as utils from './utils';\n\nexport function shimRTCIceCandidate(window) {\n // foundation is arbitrarily chosen as an indicator for full support for\n // https://w3c.github.io/webrtc-pc/#rtcicecandidate-interface\n if (!window.RTCIceCandidate || (window.RTCIceCandidate && 'foundation' in\n window.RTCIceCandidate.prototype)) {\n return;\n }\n\n const NativeRTCIceCandidate = window.RTCIceCandidate;\n window.RTCIceCandidate = function RTCIceCandidate(args) {\n // Remove the a= which shouldn't be part of the candidate string.\n if (typeof args === 'object' && args.candidate &&\n args.candidate.indexOf('a=') === 0) {\n args = JSON.parse(JSON.stringify(args));\n args.candidate = args.candidate.substr(2);\n }\n\n if (args.candidate && args.candidate.length) {\n // Augment the native candidate with the parsed fields.\n const nativeCandidate = new NativeRTCIceCandidate(args);\n const parsedCandidate = SDPUtils.parseCandidate(args.candidate);\n const augmentedCandidate = Object.assign(nativeCandidate,\n parsedCandidate);\n\n // Add a serializer that does not serialize the extra attributes.\n augmentedCandidate.toJSON = function toJSON() {\n return {\n candidate: augmentedCandidate.candidate,\n sdpMid: augmentedCandidate.sdpMid,\n sdpMLineIndex: augmentedCandidate.sdpMLineIndex,\n usernameFragment: augmentedCandidate.usernameFragment,\n };\n };\n return augmentedCandidate;\n }\n return new NativeRTCIceCandidate(args);\n };\n window.RTCIceCandidate.prototype = NativeRTCIceCandidate.prototype;\n\n // Hook up the augmented candidate in onicecandidate and\n // addEventListener('icecandidate', ...)\n utils.wrapPeerConnectionEvent(window, 'icecandidate', e => {\n if (e.candidate) {\n Object.defineProperty(e, 'candidate', {\n value: new window.RTCIceCandidate(e.candidate),\n writable: 'false'\n });\n }\n return e;\n });\n}\n\nexport function shimMaxMessageSize(window, browserDetails) {\n if (!window.RTCPeerConnection) {\n return;\n }\n\n if (!('sctp' in window.RTCPeerConnection.prototype)) {\n Object.defineProperty(window.RTCPeerConnection.prototype, 'sctp', {\n get() {\n return typeof this._sctp === 'undefined' ? null : this._sctp;\n }\n });\n }\n\n const sctpInDescription = function(description) {\n if (!description || !description.sdp) {\n return false;\n }\n const sections = SDPUtils.splitSections(description.sdp);\n sections.shift();\n return sections.some(mediaSection => {\n const mLine = SDPUtils.parseMLine(mediaSection);\n return mLine && mLine.kind === 'application'\n && mLine.protocol.indexOf('SCTP') !== -1;\n });\n };\n\n const getRemoteFirefoxVersion = function(description) {\n // TODO: Is there a better solution for detecting Firefox?\n const match = description.sdp.match(/mozilla...THIS_IS_SDPARTA-(\\d+)/);\n if (match === null || match.length < 2) {\n return -1;\n }\n const version = parseInt(match[1], 10);\n // Test for NaN (yes, this is ugly)\n return version !== version ? -1 : version;\n };\n\n const getCanSendMaxMessageSize = function(remoteIsFirefox) {\n // Every implementation we know can send at least 64 KiB.\n // Note: Although Chrome is technically able to send up to 256 KiB, the\n // data does not reach the other peer reliably.\n // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=8419\n let canSendMaxMessageSize = 65536;\n if (browserDetails.browser === 'firefox') {\n if (browserDetails.version < 57) {\n if (remoteIsFirefox === -1) {\n // FF < 57 will send in 16 KiB chunks using the deprecated PPID\n // fragmentation.\n canSendMaxMessageSize = 16384;\n } else {\n // However, other FF (and RAWRTC) can reassemble PPID-fragmented\n // messages. Thus, supporting ~2 GiB when sending.\n canSendMaxMessageSize = 2147483637;\n }\n } else if (browserDetails.version < 60) {\n // Currently, all FF >= 57 will reset the remote maximum message size\n // to the default value when a data channel is created at a later\n // stage. :(\n // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1426831\n canSendMaxMessageSize =\n browserDetails.version === 57 ? 65535 : 65536;\n } else {\n // FF >= 60 supports sending ~2 GiB\n canSendMaxMessageSize = 2147483637;\n }\n }\n return canSendMaxMessageSize;\n };\n\n const getMaxMessageSize = function(description, remoteIsFirefox) {\n // Note: 65536 bytes is the default value from the SDP spec. Also,\n // every implementation we know supports receiving 65536 bytes.\n let maxMessageSize = 65536;\n\n // FF 57 has a slightly incorrect default remote max message size, so\n // we need to adjust it here to avoid a failure when sending.\n // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1425697\n if (browserDetails.browser === 'firefox'\n && browserDetails.version === 57) {\n maxMessageSize = 65535;\n }\n\n const match = SDPUtils.matchPrefix(description.sdp,\n 'a=max-message-size:');\n if (match.length > 0) {\n maxMessageSize = parseInt(match[0].substr(19), 10);\n } else if (browserDetails.browser === 'firefox' &&\n remoteIsFirefox !== -1) {\n // If the maximum message size is not present in the remote SDP and\n // both local and remote are Firefox, the remote peer can receive\n // ~2 GiB.\n maxMessageSize = 2147483637;\n }\n return maxMessageSize;\n };\n\n const origSetRemoteDescription =\n window.RTCPeerConnection.prototype.setRemoteDescription;\n window.RTCPeerConnection.prototype.setRemoteDescription =\n function setRemoteDescription() {\n this._sctp = null;\n // Chrome decided to not expose .sctp in plan-b mode.\n // As usual, adapter.js has to do an 'ugly worakaround'\n // to cover up the mess.\n if (browserDetails.browser === 'chrome' && browserDetails.version >= 76) {\n const {sdpSemantics} = this.getConfiguration();\n if (sdpSemantics === 'plan-b') {\n Object.defineProperty(this, 'sctp', {\n get() {\n return typeof this._sctp === 'undefined' ? null : this._sctp;\n },\n enumerable: true,\n configurable: true,\n });\n }\n }\n\n if (sctpInDescription(arguments[0])) {\n // Check if the remote is FF.\n const isFirefox = getRemoteFirefoxVersion(arguments[0]);\n\n // Get the maximum message size the local peer is capable of sending\n const canSendMMS = getCanSendMaxMessageSize(isFirefox);\n\n // Get the maximum message size of the remote peer.\n const remoteMMS = getMaxMessageSize(arguments[0], isFirefox);\n\n // Determine final maximum message size\n let maxMessageSize;\n if (canSendMMS === 0 && remoteMMS === 0) {\n maxMessageSize = Number.POSITIVE_INFINITY;\n } else if (canSendMMS === 0 || remoteMMS === 0) {\n maxMessageSize = Math.max(canSendMMS, remoteMMS);\n } else {\n maxMessageSize = Math.min(canSendMMS, remoteMMS);\n }\n\n // Create a dummy RTCSctpTransport object and the 'maxMessageSize'\n // attribute.\n const sctp = {};\n Object.defineProperty(sctp, 'maxMessageSize', {\n get() {\n return maxMessageSize;\n }\n });\n this._sctp = sctp;\n }\n\n return origSetRemoteDescription.apply(this, arguments);\n };\n}\n\nexport function shimSendThrowTypeError(window) {\n if (!(window.RTCPeerConnection &&\n 'createDataChannel' in window.RTCPeerConnection.prototype)) {\n return;\n }\n\n // Note: Although Firefox >= 57 has a native implementation, the maximum\n // message size can be reset for all data channels at a later stage.\n // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1426831\n\n function wrapDcSend(dc, pc) {\n const origDataChannelSend = dc.send;\n dc.send = function send() {\n const data = arguments[0];\n const length = data.length || data.size || data.byteLength;\n if (dc.readyState === 'open' &&\n pc.sctp && length > pc.sctp.maxMessageSize) {\n throw new TypeError('Message too large (can send a maximum of ' +\n pc.sctp.maxMessageSize + ' bytes)');\n }\n return origDataChannelSend.apply(dc, arguments);\n };\n }\n const origCreateDataChannel =\n window.RTCPeerConnection.prototype.createDataChannel;\n window.RTCPeerConnection.prototype.createDataChannel =\n function createDataChannel() {\n const dataChannel = origCreateDataChannel.apply(this, arguments);\n wrapDcSend(dataChannel, this);\n return dataChannel;\n };\n utils.wrapPeerConnectionEvent(window, 'datachannel', e => {\n wrapDcSend(e.channel, e.target);\n return e;\n });\n}\n\n\n/* shims RTCConnectionState by pretending it is the same as iceConnectionState.\n * See https://bugs.chromium.org/p/webrtc/issues/detail?id=6145#c12\n * for why this is a valid hack in Chrome. In Firefox it is slightly incorrect\n * since DTLS failures would be hidden. See\n * https://bugzilla.mozilla.org/show_bug.cgi?id=1265827\n * for the Firefox tracking bug.\n */\nexport function shimConnectionState(window) {\n if (!window.RTCPeerConnection ||\n 'connectionState' in window.RTCPeerConnection.prototype) {\n return;\n }\n const proto = window.RTCPeerConnection.prototype;\n Object.defineProperty(proto, 'connectionState', {\n get() {\n return {\n completed: 'connected',\n checking: 'connecting'\n }[this.iceConnectionState] || this.iceConnectionState;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(proto, 'onconnectionstatechange', {\n get() {\n return this._onconnectionstatechange || null;\n },\n set(cb) {\n if (this._onconnectionstatechange) {\n this.removeEventListener('connectionstatechange',\n this._onconnectionstatechange);\n delete this._onconnectionstatechange;\n }\n if (cb) {\n this.addEventListener('connectionstatechange',\n this._onconnectionstatechange = cb);\n }\n },\n enumerable: true,\n configurable: true\n });\n\n ['setLocalDescription', 'setRemoteDescription'].forEach((method) => {\n const origMethod = proto[method];\n proto[method] = function() {\n if (!this._connectionstatechangepoly) {\n this._connectionstatechangepoly = e => {\n const pc = e.target;\n if (pc._lastConnectionState !== pc.connectionState) {\n pc._lastConnectionState = pc.connectionState;\n const newEvent = new Event('connectionstatechange', e);\n pc.dispatchEvent(newEvent);\n }\n return e;\n };\n this.addEventListener('iceconnectionstatechange',\n this._connectionstatechangepoly);\n }\n return origMethod.apply(this, arguments);\n };\n });\n}\n\nexport function removeExtmapAllowMixed(window, browserDetails) {\n /* remove a=extmap-allow-mixed for webrtc.org < M71 */\n if (!window.RTCPeerConnection) {\n return;\n }\n if (browserDetails.browser === 'chrome' && browserDetails.version >= 71) {\n return;\n }\n if (browserDetails.browser === 'safari' && browserDetails.version >= 605) {\n return;\n }\n const nativeSRD = window.RTCPeerConnection.prototype.setRemoteDescription;\n window.RTCPeerConnection.prototype.setRemoteDescription =\n function setRemoteDescription(desc) {\n if (desc && desc.sdp && desc.sdp.indexOf('\\na=extmap-allow-mixed') !== -1) {\n const sdp = desc.sdp.split('\\n').filter((line) => {\n return line.trim() !== 'a=extmap-allow-mixed';\n }).join('\\n');\n // Safari enforces read-only-ness of RTCSessionDescription fields.\n if (window.RTCSessionDescription &&\n desc instanceof window.RTCSessionDescription) {\n arguments[0] = new window.RTCSessionDescription({\n type: desc.type,\n sdp,\n });\n } else {\n desc.sdp = sdp;\n }\n }\n return nativeSRD.apply(this, arguments);\n };\n}\n\nexport function shimAddIceCandidateNullOrEmpty(window, browserDetails) {\n // Support for addIceCandidate(null or undefined)\n // as well as addIceCandidate({candidate: \"\", ...})\n // https://bugs.chromium.org/p/chromium/issues/detail?id=978582\n // Note: must be called before other polyfills which change the signature.\n if (!(window.RTCPeerConnection && window.RTCPeerConnection.prototype)) {\n return;\n }\n const nativeAddIceCandidate =\n window.RTCPeerConnection.prototype.addIceCandidate;\n if (!nativeAddIceCandidate || nativeAddIceCandidate.length === 0) {\n return;\n }\n window.RTCPeerConnection.prototype.addIceCandidate =\n function addIceCandidate() {\n if (!arguments[0]) {\n if (arguments[1]) {\n arguments[1].apply(null);\n }\n return Promise.resolve();\n }\n // Firefox 68+ emits and processes {candidate: \"\", ...}, ignore\n // in older versions.\n // Native support for ignoring exists for Chrome M77+.\n // Safari ignores as well, exact version unknown but works in the same\n // version that also ignores addIceCandidate(null).\n if (((browserDetails.browser === 'chrome' && browserDetails.version < 78)\n || (browserDetails.browser === 'firefox'\n && browserDetails.version < 68)\n || (browserDetails.browser === 'safari'))\n && arguments[0] && arguments[0].candidate === '') {\n return Promise.resolve();\n }\n return nativeAddIceCandidate.apply(this, arguments);\n };\n}\n","/*\n * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\nimport * as utils from './utils';\n\n // Browser shims.\nimport * as chromeShim from './chrome/chrome_shim';\nimport * as edgeShim from './edge/edge_shim';\nimport * as firefoxShim from './firefox/firefox_shim';\nimport * as safariShim from './safari/safari_shim';\nimport * as commonShim from './common_shim';\n\n// Shimming starts here.\nexport function adapterFactory({window} = {}, options = {\n shimChrome: true,\n shimFirefox: true,\n shimEdge: true,\n shimSafari: true,\n}) {\n // Utils.\n const logging = utils.log;\n const browserDetails = utils.detectBrowser(window);\n\n const adapter = {\n browserDetails,\n commonShim,\n extractVersion: utils.extractVersion,\n disableLog: utils.disableLog,\n disableWarnings: utils.disableWarnings\n };\n\n // Shim browser if found.\n switch (browserDetails.browser) {\n case 'chrome':\n if (!chromeShim || !chromeShim.shimPeerConnection ||\n !options.shimChrome) {\n logging('Chrome shim is not included in this adapter release.');\n return adapter;\n }\n if (browserDetails.version === null) {\n logging('Chrome shim can not determine version, not shimming.');\n return adapter;\n }\n logging('adapter.js shimming chrome.');\n // Export to the adapter global object visible in the browser.\n adapter.browserShim = chromeShim;\n\n // Must be called before shimPeerConnection.\n commonShim.shimAddIceCandidateNullOrEmpty(window, browserDetails);\n\n chromeShim.shimGetUserMedia(window, browserDetails);\n chromeShim.shimMediaStream(window, browserDetails);\n chromeShim.shimPeerConnection(window, browserDetails);\n chromeShim.shimOnTrack(window, browserDetails);\n chromeShim.shimAddTrackRemoveTrack(window, browserDetails);\n chromeShim.shimGetSendersWithDtmf(window, browserDetails);\n chromeShim.shimGetStats(window, browserDetails);\n chromeShim.shimSenderReceiverGetStats(window, browserDetails);\n chromeShim.fixNegotiationNeeded(window, browserDetails);\n\n commonShim.shimRTCIceCandidate(window, browserDetails);\n commonShim.shimConnectionState(window, browserDetails);\n commonShim.shimMaxMessageSize(window, browserDetails);\n commonShim.shimSendThrowTypeError(window, browserDetails);\n commonShim.removeExtmapAllowMixed(window, browserDetails);\n break;\n case 'firefox':\n if (!firefoxShim || !firefoxShim.shimPeerConnection ||\n !options.shimFirefox) {\n logging('Firefox shim is not included in this adapter release.');\n return adapter;\n }\n logging('adapter.js shimming firefox.');\n // Export to the adapter global object visible in the browser.\n adapter.browserShim = firefoxShim;\n\n // Must be called before shimPeerConnection.\n commonShim.shimAddIceCandidateNullOrEmpty(window, browserDetails);\n\n firefoxShim.shimGetUserMedia(window, browserDetails);\n firefoxShim.shimPeerConnection(window, browserDetails);\n firefoxShim.shimOnTrack(window, browserDetails);\n firefoxShim.shimRemoveStream(window, browserDetails);\n firefoxShim.shimSenderGetStats(window, browserDetails);\n firefoxShim.shimReceiverGetStats(window, browserDetails);\n firefoxShim.shimRTCDataChannel(window, browserDetails);\n firefoxShim.shimAddTransceiver(window, browserDetails);\n firefoxShim.shimGetParameters(window, browserDetails);\n firefoxShim.shimCreateOffer(window, browserDetails);\n firefoxShim.shimCreateAnswer(window, browserDetails);\n\n commonShim.shimRTCIceCandidate(window, browserDetails);\n commonShim.shimConnectionState(window, browserDetails);\n commonShim.shimMaxMessageSize(window, browserDetails);\n commonShim.shimSendThrowTypeError(window, browserDetails);\n break;\n case 'edge':\n if (!edgeShim || !edgeShim.shimPeerConnection || !options.shimEdge) {\n logging('MS edge shim is not included in this adapter release.');\n return adapter;\n }\n logging('adapter.js shimming edge.');\n // Export to the adapter global object visible in the browser.\n adapter.browserShim = edgeShim;\n\n edgeShim.shimGetUserMedia(window, browserDetails);\n edgeShim.shimGetDisplayMedia(window, browserDetails);\n edgeShim.shimPeerConnection(window, browserDetails);\n edgeShim.shimReplaceTrack(window, browserDetails);\n\n // the edge shim implements the full RTCIceCandidate object.\n\n commonShim.shimMaxMessageSize(window, browserDetails);\n commonShim.shimSendThrowTypeError(window, browserDetails);\n break;\n case 'safari':\n if (!safariShim || !options.shimSafari) {\n logging('Safari shim is not included in this adapter release.');\n return adapter;\n }\n logging('adapter.js shimming safari.');\n // Export to the adapter global object visible in the browser.\n adapter.browserShim = safariShim;\n\n // Must be called before shimCallbackAPI.\n commonShim.shimAddIceCandidateNullOrEmpty(window, browserDetails);\n\n safariShim.shimRTCIceServerUrls(window, browserDetails);\n safariShim.shimCreateOfferLegacy(window, browserDetails);\n safariShim.shimCallbacksAPI(window, browserDetails);\n safariShim.shimLocalStreamsAPI(window, browserDetails);\n safariShim.shimRemoteStreamsAPI(window, browserDetails);\n safariShim.shimTrackEventTransceiver(window, browserDetails);\n safariShim.shimGetUserMedia(window, browserDetails);\n safariShim.shimAudioContext(window, browserDetails);\n\n commonShim.shimRTCIceCandidate(window, browserDetails);\n commonShim.shimMaxMessageSize(window, browserDetails);\n commonShim.shimSendThrowTypeError(window, browserDetails);\n commonShim.removeExtmapAllowMixed(window, browserDetails);\n break;\n default:\n logging('Unsupported browser!');\n break;\n }\n\n return adapter;\n}\n","/*\n * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.\n *\n * Use of this source code is governed by a BSD-style license\n * that can be found in the LICENSE file in the root of the source\n * tree.\n */\n/* eslint-env node */\n\n'use strict';\n\nimport {adapterFactory} from './adapter_factory.js';\n\nconst adapter =\n adapterFactory({window: typeof window === 'undefined' ? undefined : window});\nexport default adapter;\n","\n'use strict';\nimport * as utils from './utils.js';\nimport * as MediaFormatModule from './mediaformat.js';\nimport adapter from 'webrtc-adapter';\n\n/**\n * @class AudioTrackConstraints\n * @classDesc Constraints for creating an audio MediaStreamTrack.\n * @memberof Owt.Base\n * @constructor\n * @param {Owt.Base.AudioSourceInfo} source Source info of this audio track.\n */\nexport class AudioTrackConstraints {\n // eslint-disable-next-line require-jsdoc\n constructor(source) {\n if (!Object.values(MediaFormatModule.AudioSourceInfo)\n .some((v) => v === source)) {\n throw new TypeError('Invalid source.');\n }\n /**\n * @member {string} source\n * @memberof Owt.Base.AudioTrackConstraints\n * @desc Values could be \"mic\", \"screen-cast\", \"file\" or \"mixed\".\n * @instance\n */\n this.source = source;\n /**\n * @member {string} deviceId\n * @memberof Owt.Base.AudioTrackConstraints\n * @desc Do not provide deviceId if source is not \"mic\".\n * @instance\n * @see https://w3c.github.io/mediacapture-main/#def-constraint-deviceId\n */\n this.deviceId = undefined;\n }\n}\n\n/**\n * @class VideoTrackConstraints\n * @classDesc Constraints for creating a video MediaStreamTrack.\n * @memberof Owt.Base\n * @constructor\n * @param {Owt.Base.VideoSourceInfo} source Source info of this video track.\n */\nexport class VideoTrackConstraints {\n // eslint-disable-next-line require-jsdoc\n constructor(source) {\n if (!Object.values(MediaFormatModule.VideoSourceInfo)\n .some((v) => v === source)) {\n throw new TypeError('Invalid source.');\n }\n /**\n * @member {string} source\n * @memberof Owt.Base.VideoTrackConstraints\n * @desc Values could be \"camera\", \"screen-cast\", \"file\" or \"mixed\".\n * @instance\n */\n this.source = source;\n /**\n * @member {string} deviceId\n * @memberof Owt.Base.VideoTrackConstraints\n * @desc Do not provide deviceId if source is not \"camera\".\n * @instance\n * @see https://w3c.github.io/mediacapture-main/#def-constraint-deviceId\n */\n\n this.deviceId = undefined;\n\n /**\n * @member {Owt.Base.Resolution} resolution\n * @memberof Owt.Base.VideoTrackConstraints\n * @instance\n */\n this.resolution = undefined;\n\n /**\n * @member {number} frameRate\n * @memberof Owt.Base.VideoTrackConstraints\n * @instance\n */\n this.frameRate = undefined;\n }\n}\n/**\n * @class StreamConstraints\n * @classDesc Constraints for creating a MediaStream from screen mic and camera.\n * @memberof Owt.Base\n * @constructor\n * @param {?Owt.Base.AudioTrackConstraints} audioConstraints\n * @param {?Owt.Base.VideoTrackConstraints} videoConstraints\n */\nexport class StreamConstraints {\n // eslint-disable-next-line require-jsdoc\n constructor(audioConstraints = false, videoConstraints = false) {\n /**\n * @member {Owt.Base.MediaStreamTrackDeviceConstraintsForAudio} audio\n * @memberof Owt.Base.MediaStreamDeviceConstraints\n * @instance\n */\n this.audio = audioConstraints;\n /**\n * @member {Owt.Base.MediaStreamTrackDeviceConstraintsForVideo} Video\n * @memberof Owt.Base.MediaStreamDeviceConstraints\n * @instance\n */\n this.video = videoConstraints;\n }\n}\n\n// eslint-disable-next-line require-jsdoc\nfunction isVideoConstrainsForScreenCast(constraints) {\n return (typeof constraints.video === 'object' && constraints.video.source ===\n MediaFormatModule.VideoSourceInfo.SCREENCAST);\n}\n\n/**\n * @class MediaStreamFactory\n * @classDesc A factory to create MediaStream. You can also create MediaStream by yourself.\n * @memberof Owt.Base\n */\nexport class MediaStreamFactory {\n /**\n * @function createMediaStream\n * @static\n * @desc Create a MediaStream with given constraints. If you want to create a MediaStream for screen cast, please make sure both audio and video's source are \"screen-cast\".\n * @memberof Owt.Base.MediaStreamFactory\n * @return {Promise} Return a promise that is resolved when stream is successfully created, or rejected if one of the following error happened:\n * - One or more parameters cannot be satisfied.\n * - Specified device is busy.\n * - Cannot obtain necessary permission or operation is canceled by user.\n * - Video source is screen cast, while audio source is not.\n * - Audio source is screen cast, while video source is disabled.\n * @param {Owt.Base.StreamConstraints} constraints\n */\n static createMediaStream(constraints) {\n if (typeof constraints !== 'object' ||\n (!constraints.audio && !constraints.video)) {\n return Promise.reject(new TypeError('Invalid constrains'));\n }\n if (!isVideoConstrainsForScreenCast(constraints) &&\n (typeof constraints.audio === 'object') &&\n constraints.audio.source ===\n MediaFormatModule.AudioSourceInfo.SCREENCAST) {\n return Promise.reject(\n new TypeError('Cannot share screen without video.'));\n }\n if (isVideoConstrainsForScreenCast(constraints) && !utils.isChrome() &&\n !utils.isFirefox()) {\n return Promise.reject(\n new TypeError('Screen sharing only supports Chrome and Firefox.'));\n }\n if (isVideoConstrainsForScreenCast(constraints) &&\n typeof constraints.audio === 'object' &&\n constraints.audio.source !==\n MediaFormatModule.AudioSourceInfo.SCREENCAST) {\n return Promise.reject(new TypeError(\n 'Cannot capture video from screen cast while capture audio from'\n + ' other source.'));\n }\n\n // Check and convert constraints.\n if (!constraints.audio && !constraints.video) {\n return Promise.reject(new TypeError(\n 'At least one of audio and video must be requested.'));\n }\n const mediaConstraints = Object.create({});\n if (typeof constraints.audio === 'object' &&\n constraints.audio.source === MediaFormatModule.AudioSourceInfo.MIC) {\n mediaConstraints.audio = Object.create({});\n if (utils.isEdge()) {\n mediaConstraints.audio.deviceId = constraints.audio.deviceId;\n } else {\n mediaConstraints.audio.deviceId = {\n exact: constraints.audio.deviceId,\n };\n }\n } else {\n if (constraints.audio.source ===\n MediaFormatModule.AudioSourceInfo.SCREENCAST) {\n mediaConstraints.audio = true;\n } else {\n mediaConstraints.audio = constraints.audio;\n }\n }\n if (typeof constraints.video === 'object') {\n mediaConstraints.video = Object.create({});\n if (typeof constraints.video.frameRate === 'number') {\n mediaConstraints.video.frameRate = constraints.video.frameRate;\n }\n if (constraints.video.resolution &&\n constraints.video.resolution.width &&\n constraints.video.resolution.height) {\n if (constraints.video.source ===\n MediaFormatModule.VideoSourceInfo.SCREENCAST) {\n mediaConstraints.video.width = constraints.video.resolution.width;\n mediaConstraints.video.height = constraints.video.resolution.height;\n } else {\n mediaConstraints.video.width = Object.create({});\n mediaConstraints.video.width.exact =\n constraints.video.resolution.width;\n mediaConstraints.video.height = Object.create({});\n mediaConstraints.video.height.exact =\n constraints.video.resolution.height;\n }\n }\n if (typeof constraints.video.deviceId === 'string') {\n mediaConstraints.video.deviceId = {exact: constraints.video.deviceId};\n }\n if (utils.isFirefox() &&\n constraints.video.source ===\n MediaFormatModule.VideoSourceInfo.SCREENCAST) {\n mediaConstraints.video.mediaSource = 'screen';\n }\n } else {\n mediaConstraints.video = constraints.video;\n }\n\n if (isVideoConstrainsForScreenCast(constraints)) {\n return navigator.mediaDevices.getDisplayMedia(mediaConstraints);\n } else {\n return navigator.mediaDevices.getUserMedia(mediaConstraints);\n }\n }\n}\n","// Copyright (C) <2018> Intel Corporation\n//\n// SPDX-License-Identifier: Apache-2.0\n\n'use strict';\n\nexport * from './mediastream-factory.js';\nexport * from './mediaformat.js';","let logger;\nlet errorLogger;\n\nexport function setLogger() {\n /*eslint-disable */\n logger = console.log;\n errorLogger = console.error;\n /*eslint-enable */\n}\n\nexport function isEnable() {\n return logger != null;\n}\n\nexport function log(message, ...optionalParams) {\n if (logger) {\n logger(message, ...optionalParams);\n }\n}\nexport function error(message, ...optionalParams) {\n if (errorLogger) {\n errorLogger(message, ...optionalParams);\n }\n}\n","export default class Event {\n constructor(type) {\n this.listener = {};\n this.type = type | '';\n }\n\n on(event, fn) {\n if (!this.listener[event]) {\n this.listener[event] = [];\n }\n this.listener[event].push(fn);\n return true;\n }\n\n off(event, fn) {\n if (this.listener[event]) {\n var index = this.listener[event].indexOf(fn);\n if (index > -1) {\n this.listener[event].splice(index, 1);\n }\n return true;\n }\n return false;\n }\n\n offAll() {\n this.listener = {};\n }\n\n dispatch(event, data) {\n if (this.listener[event]) {\n this.listener[event].map((each) => {\n each.apply(null, [data]);\n });\n return true;\n }\n return false;\n }\n}\n","'use strict';\n\nmodule.exports = function bind(fn, thisArg) {\n return function wrap() {\n var args = new Array(arguments.length);\n for (var i = 0; i < args.length; i++) {\n args[i] = arguments[i];\n }\n return fn.apply(thisArg, args);\n };\n};\n","'use strict';\n\nvar bind = require('./helpers/bind');\n\n/*global toString:true*/\n\n// utils is a library of generic helper functions non-specific to axios\n\nvar toString = Object.prototype.toString;\n\n/**\n * Determine if a value is an Array\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is an Array, otherwise false\n */\nfunction isArray(val) {\n return toString.call(val) === '[object Array]';\n}\n\n/**\n * Determine if a value is undefined\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if the value is undefined, otherwise false\n */\nfunction isUndefined(val) {\n return typeof val === 'undefined';\n}\n\n/**\n * Determine if a value is a Buffer\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Buffer, otherwise false\n */\nfunction isBuffer(val) {\n return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)\n && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);\n}\n\n/**\n * Determine if a value is an ArrayBuffer\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is an ArrayBuffer, otherwise false\n */\nfunction isArrayBuffer(val) {\n return toString.call(val) === '[object ArrayBuffer]';\n}\n\n/**\n * Determine if a value is a FormData\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is an FormData, otherwise false\n */\nfunction isFormData(val) {\n return (typeof FormData !== 'undefined') && (val instanceof FormData);\n}\n\n/**\n * Determine if a value is a view on an ArrayBuffer\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false\n */\nfunction isArrayBufferView(val) {\n var result;\n if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {\n result = ArrayBuffer.isView(val);\n } else {\n result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);\n }\n return result;\n}\n\n/**\n * Determine if a value is a String\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a String, otherwise false\n */\nfunction isString(val) {\n return typeof val === 'string';\n}\n\n/**\n * Determine if a value is a Number\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Number, otherwise false\n */\nfunction isNumber(val) {\n return typeof val === 'number';\n}\n\n/**\n * Determine if a value is an Object\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is an Object, otherwise false\n */\nfunction isObject(val) {\n return val !== null && typeof val === 'object';\n}\n\n/**\n * Determine if a value is a plain Object\n *\n * @param {Object} val The value to test\n * @return {boolean} True if value is a plain Object, otherwise false\n */\nfunction isPlainObject(val) {\n if (toString.call(val) !== '[object Object]') {\n return false;\n }\n\n var prototype = Object.getPrototypeOf(val);\n return prototype === null || prototype === Object.prototype;\n}\n\n/**\n * Determine if a value is a Date\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Date, otherwise false\n */\nfunction isDate(val) {\n return toString.call(val) === '[object Date]';\n}\n\n/**\n * Determine if a value is a File\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a File, otherwise false\n */\nfunction isFile(val) {\n return toString.call(val) === '[object File]';\n}\n\n/**\n * Determine if a value is a Blob\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Blob, otherwise false\n */\nfunction isBlob(val) {\n return toString.call(val) === '[object Blob]';\n}\n\n/**\n * Determine if a value is a Function\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Function, otherwise false\n */\nfunction isFunction(val) {\n return toString.call(val) === '[object Function]';\n}\n\n/**\n * Determine if a value is a Stream\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Stream, otherwise false\n */\nfunction isStream(val) {\n return isObject(val) && isFunction(val.pipe);\n}\n\n/**\n * Determine if a value is a URLSearchParams object\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a URLSearchParams object, otherwise false\n */\nfunction isURLSearchParams(val) {\n return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;\n}\n\n/**\n * Trim excess whitespace off the beginning and end of a string\n *\n * @param {String} str The String to trim\n * @returns {String} The String freed of excess whitespace\n */\nfunction trim(str) {\n return str.replace(/^\\s*/, '').replace(/\\s*$/, '');\n}\n\n/**\n * Determine if we're running in a standard browser environment\n *\n * This allows axios to run in a web worker, and react-native.\n * Both environments support XMLHttpRequest, but not fully standard globals.\n *\n * web workers:\n * typeof window -> undefined\n * typeof document -> undefined\n *\n * react-native:\n * navigator.product -> 'ReactNative'\n * nativescript\n * navigator.product -> 'NativeScript' or 'NS'\n */\nfunction isStandardBrowserEnv() {\n if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||\n navigator.product === 'NativeScript' ||\n navigator.product === 'NS')) {\n return false;\n }\n return (\n typeof window !== 'undefined' &&\n typeof document !== 'undefined'\n );\n}\n\n/**\n * Iterate over an Array or an Object invoking a function for each item.\n *\n * If `obj` is an Array callback will be called passing\n * the value, index, and complete array for each item.\n *\n * If 'obj' is an Object callback will be called passing\n * the value, key, and complete object for each property.\n *\n * @param {Object|Array} obj The object to iterate\n * @param {Function} fn The callback to invoke for each item\n */\nfunction forEach(obj, fn) {\n // Don't bother if no value provided\n if (obj === null || typeof obj === 'undefined') {\n return;\n }\n\n // Force an array if not already something iterable\n if (typeof obj !== 'object') {\n /*eslint no-param-reassign:0*/\n obj = [obj];\n }\n\n if (isArray(obj)) {\n // Iterate over array values\n for (var i = 0, l = obj.length; i < l; i++) {\n fn.call(null, obj[i], i, obj);\n }\n } else {\n // Iterate over object keys\n for (var key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n fn.call(null, obj[key], key, obj);\n }\n }\n }\n}\n\n/**\n * Accepts varargs expecting each argument to be an object, then\n * immutably merges the properties of each object and returns result.\n *\n * When multiple objects contain the same key the later object in\n * the arguments list will take precedence.\n *\n * Example:\n *\n * ```js\n * var result = merge({foo: 123}, {foo: 456});\n * console.log(result.foo); // outputs 456\n * ```\n *\n * @param {Object} obj1 Object to merge\n * @returns {Object} Result of all merge properties\n */\nfunction merge(/* obj1, obj2, obj3, ... */) {\n var result = {};\n function assignValue(val, key) {\n if (isPlainObject(result[key]) && isPlainObject(val)) {\n result[key] = merge(result[key], val);\n } else if (isPlainObject(val)) {\n result[key] = merge({}, val);\n } else if (isArray(val)) {\n result[key] = val.slice();\n } else {\n result[key] = val;\n }\n }\n\n for (var i = 0, l = arguments.length; i < l; i++) {\n forEach(arguments[i], assignValue);\n }\n return result;\n}\n\n/**\n * Extends object a by mutably adding to it the properties of object b.\n *\n * @param {Object} a The object to be extended\n * @param {Object} b The object to copy properties from\n * @param {Object} thisArg The object to bind function to\n * @return {Object} The resulting value of object a\n */\nfunction extend(a, b, thisArg) {\n forEach(b, function assignValue(val, key) {\n if (thisArg && typeof val === 'function') {\n a[key] = bind(val, thisArg);\n } else {\n a[key] = val;\n }\n });\n return a;\n}\n\n/**\n * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)\n *\n * @param {string} content with BOM\n * @return {string} content value without BOM\n */\nfunction stripBOM(content) {\n if (content.charCodeAt(0) === 0xFEFF) {\n content = content.slice(1);\n }\n return content;\n}\n\nmodule.exports = {\n isArray: isArray,\n isArrayBuffer: isArrayBuffer,\n isBuffer: isBuffer,\n isFormData: isFormData,\n isArrayBufferView: isArrayBufferView,\n isString: isString,\n isNumber: isNumber,\n isObject: isObject,\n isPlainObject: isPlainObject,\n isUndefined: isUndefined,\n isDate: isDate,\n isFile: isFile,\n isBlob: isBlob,\n isFunction: isFunction,\n isStream: isStream,\n isURLSearchParams: isURLSearchParams,\n isStandardBrowserEnv: isStandardBrowserEnv,\n forEach: forEach,\n merge: merge,\n extend: extend,\n trim: trim,\n stripBOM: stripBOM\n};\n","'use strict';\n\nvar utils = require('./../utils');\n\nfunction encode(val) {\n return encodeURIComponent(val).\n replace(/%3A/gi, ':').\n replace(/%24/g, '$').\n replace(/%2C/gi, ',').\n replace(/%20/g, '+').\n replace(/%5B/gi, '[').\n replace(/%5D/gi, ']');\n}\n\n/**\n * Build a URL by appending params to the end\n *\n * @param {string} url The base of the url (e.g., http://www.google.com)\n * @param {object} [params] The params to be appended\n * @returns {string} The formatted url\n */\nmodule.exports = function buildURL(url, params, paramsSerializer) {\n /*eslint no-param-reassign:0*/\n if (!params) {\n return url;\n }\n\n var serializedParams;\n if (paramsSerializer) {\n serializedParams = paramsSerializer(params);\n } else if (utils.isURLSearchParams(params)) {\n serializedParams = params.toString();\n } else {\n var parts = [];\n\n utils.forEach(params, function serialize(val, key) {\n if (val === null || typeof val === 'undefined') {\n return;\n }\n\n if (utils.isArray(val)) {\n key = key + '[]';\n } else {\n val = [val];\n }\n\n utils.forEach(val, function parseValue(v) {\n if (utils.isDate(v)) {\n v = v.toISOString();\n } else if (utils.isObject(v)) {\n v = JSON.stringify(v);\n }\n parts.push(encode(key) + '=' + encode(v));\n });\n });\n\n serializedParams = parts.join('&');\n }\n\n if (serializedParams) {\n var hashmarkIndex = url.indexOf('#');\n if (hashmarkIndex !== -1) {\n url = url.slice(0, hashmarkIndex);\n }\n\n url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;\n }\n\n return url;\n};\n","'use strict';\n\nvar utils = require('./../utils');\n\nfunction InterceptorManager() {\n this.handlers = [];\n}\n\n/**\n * Add a new interceptor to the stack\n *\n * @param {Function} fulfilled The function to handle `then` for a `Promise`\n * @param {Function} rejected The function to handle `reject` for a `Promise`\n *\n * @return {Number} An ID used to remove interceptor later\n */\nInterceptorManager.prototype.use = function use(fulfilled, rejected) {\n this.handlers.push({\n fulfilled: fulfilled,\n rejected: rejected\n });\n return this.handlers.length - 1;\n};\n\n/**\n * Remove an interceptor from the stack\n *\n * @param {Number} id The ID that was returned by `use`\n */\nInterceptorManager.prototype.eject = function eject(id) {\n if (this.handlers[id]) {\n this.handlers[id] = null;\n }\n};\n\n/**\n * Iterate over all the registered interceptors\n *\n * This method is particularly useful for skipping over any\n * interceptors that may have become `null` calling `eject`.\n *\n * @param {Function} fn The function to call for each interceptor\n */\nInterceptorManager.prototype.forEach = function forEach(fn) {\n utils.forEach(this.handlers, function forEachHandler(h) {\n if (h !== null) {\n fn(h);\n }\n });\n};\n\nmodule.exports = InterceptorManager;\n","'use strict';\n\nvar utils = require('./../utils');\n\n/**\n * Transform the data for a request or a response\n *\n * @param {Object|String} data The data to be transformed\n * @param {Array} headers The headers for the request or response\n * @param {Array|Function} fns A single function or Array of functions\n * @returns {*} The resulting transformed data\n */\nmodule.exports = function transformData(data, headers, fns) {\n /*eslint no-param-reassign:0*/\n utils.forEach(fns, function transform(fn) {\n data = fn(data, headers);\n });\n\n return data;\n};\n","'use strict';\n\nmodule.exports = function isCancel(value) {\n return !!(value && value.__CANCEL__);\n};\n","'use strict';\n\nvar utils = require('../utils');\n\nmodule.exports = function normalizeHeaderName(headers, normalizedName) {\n utils.forEach(headers, function processHeader(value, name) {\n if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {\n headers[normalizedName] = value;\n delete headers[name];\n }\n });\n};\n","'use strict';\n\n/**\n * Update an Error with the specified config, error code, and response.\n *\n * @param {Error} error The error to update.\n * @param {Object} config The config.\n * @param {string} [code] The error code (for example, 'ECONNABORTED').\n * @param {Object} [request] The request.\n * @param {Object} [response] The response.\n * @returns {Error} The error.\n */\nmodule.exports = function enhanceError(error, config, code, request, response) {\n error.config = config;\n if (code) {\n error.code = code;\n }\n\n error.request = request;\n error.response = response;\n error.isAxiosError = true;\n\n error.toJSON = function toJSON() {\n return {\n // Standard\n message: this.message,\n name: this.name,\n // Microsoft\n description: this.description,\n number: this.number,\n // Mozilla\n fileName: this.fileName,\n lineNumber: this.lineNumber,\n columnNumber: this.columnNumber,\n stack: this.stack,\n // Axios\n config: this.config,\n code: this.code\n };\n };\n return error;\n};\n","'use strict';\n\nvar enhanceError = require('./enhanceError');\n\n/**\n * Create an Error with the specified message, config, error code, request and response.\n *\n * @param {string} message The error message.\n * @param {Object} config The config.\n * @param {string} [code] The error code (for example, 'ECONNABORTED').\n * @param {Object} [request] The request.\n * @param {Object} [response] The response.\n * @returns {Error} The created error.\n */\nmodule.exports = function createError(message, config, code, request, response) {\n var error = new Error(message);\n return enhanceError(error, config, code, request, response);\n};\n","'use strict';\n\nvar createError = require('./createError');\n\n/**\n * Resolve or reject a Promise based on response status.\n *\n * @param {Function} resolve A function that resolves the promise.\n * @param {Function} reject A function that rejects the promise.\n * @param {object} response The response.\n */\nmodule.exports = function settle(resolve, reject, response) {\n var validateStatus = response.config.validateStatus;\n if (!response.status || !validateStatus || validateStatus(response.status)) {\n resolve(response);\n } else {\n reject(createError(\n 'Request failed with status code ' + response.status,\n response.config,\n null,\n response.request,\n response\n ));\n }\n};\n","'use strict';\n\nvar utils = require('./../utils');\n\nmodule.exports = (\n utils.isStandardBrowserEnv() ?\n\n // Standard browser envs support document.cookie\n (function standardBrowserEnv() {\n return {\n write: function write(name, value, expires, path, domain, secure) {\n var cookie = [];\n cookie.push(name + '=' + encodeURIComponent(value));\n\n if (utils.isNumber(expires)) {\n cookie.push('expires=' + new Date(expires).toGMTString());\n }\n\n if (utils.isString(path)) {\n cookie.push('path=' + path);\n }\n\n if (utils.isString(domain)) {\n cookie.push('domain=' + domain);\n }\n\n if (secure === true) {\n cookie.push('secure');\n }\n\n document.cookie = cookie.join('; ');\n },\n\n read: function read(name) {\n var match = document.cookie.match(new RegExp('(^|;\\\\s*)(' + name + ')=([^;]*)'));\n return (match ? decodeURIComponent(match[3]) : null);\n },\n\n remove: function remove(name) {\n this.write(name, '', Date.now() - 86400000);\n }\n };\n })() :\n\n // Non standard browser env (web workers, react-native) lack needed support.\n (function nonStandardBrowserEnv() {\n return {\n write: function write() {},\n read: function read() { return null; },\n remove: function remove() {}\n };\n })()\n);\n","'use strict';\n\n/**\n * Determines whether the specified URL is absolute\n *\n * @param {string} url The URL to test\n * @returns {boolean} True if the specified URL is absolute, otherwise false\n */\nmodule.exports = function isAbsoluteURL(url) {\n // A URL is considered absolute if it begins with \"://\" or \"//\" (protocol-relative URL).\n // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed\n // by any combination of letters, digits, plus, period, or hyphen.\n return /^([a-z][a-z\\d\\+\\-\\.]*:)?\\/\\//i.test(url);\n};\n","'use strict';\n\n/**\n * Creates a new URL by combining the specified URLs\n *\n * @param {string} baseURL The base URL\n * @param {string} relativeURL The relative URL\n * @returns {string} The combined URL\n */\nmodule.exports = function combineURLs(baseURL, relativeURL) {\n return relativeURL\n ? baseURL.replace(/\\/+$/, '') + '/' + relativeURL.replace(/^\\/+/, '')\n : baseURL;\n};\n","'use strict';\n\nvar isAbsoluteURL = require('../helpers/isAbsoluteURL');\nvar combineURLs = require('../helpers/combineURLs');\n\n/**\n * Creates a new URL by combining the baseURL with the requestedURL,\n * only when the requestedURL is not already an absolute URL.\n * If the requestURL is absolute, this function returns the requestedURL untouched.\n *\n * @param {string} baseURL The base URL\n * @param {string} requestedURL Absolute or relative URL to combine\n * @returns {string} The combined full path\n */\nmodule.exports = function buildFullPath(baseURL, requestedURL) {\n if (baseURL && !isAbsoluteURL(requestedURL)) {\n return combineURLs(baseURL, requestedURL);\n }\n return requestedURL;\n};\n","'use strict';\n\nvar utils = require('./../utils');\n\n// Headers whose duplicates are ignored by node\n// c.f. https://nodejs.org/api/http.html#http_message_headers\nvar ignoreDuplicateOf = [\n 'age', 'authorization', 'content-length', 'content-type', 'etag',\n 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',\n 'last-modified', 'location', 'max-forwards', 'proxy-authorization',\n 'referer', 'retry-after', 'user-agent'\n];\n\n/**\n * Parse headers into an object\n *\n * ```\n * Date: Wed, 27 Aug 2014 08:58:49 GMT\n * Content-Type: application/json\n * Connection: keep-alive\n * Transfer-Encoding: chunked\n * ```\n *\n * @param {String} headers Headers needing to be parsed\n * @returns {Object} Headers parsed into an object\n */\nmodule.exports = function parseHeaders(headers) {\n var parsed = {};\n var key;\n var val;\n var i;\n\n if (!headers) { return parsed; }\n\n utils.forEach(headers.split('\\n'), function parser(line) {\n i = line.indexOf(':');\n key = utils.trim(line.substr(0, i)).toLowerCase();\n val = utils.trim(line.substr(i + 1));\n\n if (key) {\n if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {\n return;\n }\n if (key === 'set-cookie') {\n parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);\n } else {\n parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;\n }\n }\n });\n\n return parsed;\n};\n","'use strict';\n\nvar utils = require('./../utils');\n\nmodule.exports = (\n utils.isStandardBrowserEnv() ?\n\n // Standard browser envs have full support of the APIs needed to test\n // whether the request URL is of the same origin as current location.\n (function standardBrowserEnv() {\n var msie = /(msie|trident)/i.test(navigator.userAgent);\n var urlParsingNode = document.createElement('a');\n var originURL;\n\n /**\n * Parse a URL to discover it's components\n *\n * @param {String} url The URL to be parsed\n * @returns {Object}\n */\n function resolveURL(url) {\n var href = url;\n\n if (msie) {\n // IE needs attribute set twice to normalize properties\n urlParsingNode.setAttribute('href', href);\n href = urlParsingNode.href;\n }\n\n urlParsingNode.setAttribute('href', href);\n\n // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils\n return {\n href: urlParsingNode.href,\n protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',\n host: urlParsingNode.host,\n search: urlParsingNode.search ? urlParsingNode.search.replace(/^\\?/, '') : '',\n hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',\n hostname: urlParsingNode.hostname,\n port: urlParsingNode.port,\n pathname: (urlParsingNode.pathname.charAt(0) === '/') ?\n urlParsingNode.pathname :\n '/' + urlParsingNode.pathname\n };\n }\n\n originURL = resolveURL(window.location.href);\n\n /**\n * Determine if a URL shares the same origin as the current location\n *\n * @param {String} requestURL The URL to test\n * @returns {boolean} True if URL shares the same origin, otherwise false\n */\n return function isURLSameOrigin(requestURL) {\n var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;\n return (parsed.protocol === originURL.protocol &&\n parsed.host === originURL.host);\n };\n })() :\n\n // Non standard browser envs (web workers, react-native) lack needed support.\n (function nonStandardBrowserEnv() {\n return function isURLSameOrigin() {\n return true;\n };\n })()\n);\n","'use strict';\n\nvar utils = require('./../utils');\nvar settle = require('./../core/settle');\nvar cookies = require('./../helpers/cookies');\nvar buildURL = require('./../helpers/buildURL');\nvar buildFullPath = require('../core/buildFullPath');\nvar parseHeaders = require('./../helpers/parseHeaders');\nvar isURLSameOrigin = require('./../helpers/isURLSameOrigin');\nvar createError = require('../core/createError');\n\nmodule.exports = function xhrAdapter(config) {\n return new Promise(function dispatchXhrRequest(resolve, reject) {\n var requestData = config.data;\n var requestHeaders = config.headers;\n\n if (utils.isFormData(requestData)) {\n delete requestHeaders['Content-Type']; // Let the browser set it\n }\n\n var request = new XMLHttpRequest();\n\n // HTTP basic authentication\n if (config.auth) {\n var username = config.auth.username || '';\n var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';\n requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);\n }\n\n var fullPath = buildFullPath(config.baseURL, config.url);\n request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);\n\n // Set the request timeout in MS\n request.timeout = config.timeout;\n\n // Listen for ready state\n request.onreadystatechange = function handleLoad() {\n if (!request || request.readyState !== 4) {\n return;\n }\n\n // The request errored out and we didn't get a response, this will be\n // handled by onerror instead\n // With one exception: request that using file: protocol, most browsers\n // will return status as 0 even though it's a successful request\n if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {\n return;\n }\n\n // Prepare the response\n var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;\n var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;\n var response = {\n data: responseData,\n status: request.status,\n statusText: request.statusText,\n headers: responseHeaders,\n config: config,\n request: request\n };\n\n settle(resolve, reject, response);\n\n // Clean up request\n request = null;\n };\n\n // Handle browser request cancellation (as opposed to a manual cancellation)\n request.onabort = function handleAbort() {\n if (!request) {\n return;\n }\n\n reject(createError('Request aborted', config, 'ECONNABORTED', request));\n\n // Clean up request\n request = null;\n };\n\n // Handle low level network errors\n request.onerror = function handleError() {\n // Real errors are hidden from us by the browser\n // onerror should only fire if it's a network error\n reject(createError('Network Error', config, null, request));\n\n // Clean up request\n request = null;\n };\n\n // Handle timeout\n request.ontimeout = function handleTimeout() {\n var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';\n if (config.timeoutErrorMessage) {\n timeoutErrorMessage = config.timeoutErrorMessage;\n }\n reject(createError(timeoutErrorMessage, config, 'ECONNABORTED',\n request));\n\n // Clean up request\n request = null;\n };\n\n // Add xsrf header\n // This is only done if running in a standard browser environment.\n // Specifically not if we're in a web worker, or react-native.\n if (utils.isStandardBrowserEnv()) {\n // Add xsrf header\n var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?\n cookies.read(config.xsrfCookieName) :\n undefined;\n\n if (xsrfValue) {\n requestHeaders[config.xsrfHeaderName] = xsrfValue;\n }\n }\n\n // Add headers to the request\n if ('setRequestHeader' in request) {\n utils.forEach(requestHeaders, function setRequestHeader(val, key) {\n if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {\n // Remove Content-Type if data is undefined\n delete requestHeaders[key];\n } else {\n // Otherwise add header to the request\n request.setRequestHeader(key, val);\n }\n });\n }\n\n // Add withCredentials to request if needed\n if (!utils.isUndefined(config.withCredentials)) {\n request.withCredentials = !!config.withCredentials;\n }\n\n // Add responseType to request if needed\n if (config.responseType) {\n try {\n request.responseType = config.responseType;\n } catch (e) {\n // Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.\n // But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.\n if (config.responseType !== 'json') {\n throw e;\n }\n }\n }\n\n // Handle progress if needed\n if (typeof config.onDownloadProgress === 'function') {\n request.addEventListener('progress', config.onDownloadProgress);\n }\n\n // Not all browsers support upload events\n if (typeof config.onUploadProgress === 'function' && request.upload) {\n request.upload.addEventListener('progress', config.onUploadProgress);\n }\n\n if (config.cancelToken) {\n // Handle cancellation\n config.cancelToken.promise.then(function onCanceled(cancel) {\n if (!request) {\n return;\n }\n\n request.abort();\n reject(cancel);\n // Clean up request\n request = null;\n });\n }\n\n if (!requestData) {\n requestData = null;\n }\n\n // Send the request\n request.send(requestData);\n });\n};\n","'use strict';\n\nvar utils = require('./utils');\nvar normalizeHeaderName = require('./helpers/normalizeHeaderName');\n\nvar DEFAULT_CONTENT_TYPE = {\n 'Content-Type': 'application/x-www-form-urlencoded'\n};\n\nfunction setContentTypeIfUnset(headers, value) {\n if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {\n headers['Content-Type'] = value;\n }\n}\n\nfunction getDefaultAdapter() {\n var adapter;\n if (typeof XMLHttpRequest !== 'undefined') {\n // For browsers use XHR adapter\n adapter = require('./adapters/xhr');\n } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {\n // For node use HTTP adapter\n adapter = require('./adapters/http');\n }\n return adapter;\n}\n\nvar defaults = {\n adapter: getDefaultAdapter(),\n\n transformRequest: [function transformRequest(data, headers) {\n normalizeHeaderName(headers, 'Accept');\n normalizeHeaderName(headers, 'Content-Type');\n if (utils.isFormData(data) ||\n utils.isArrayBuffer(data) ||\n utils.isBuffer(data) ||\n utils.isStream(data) ||\n utils.isFile(data) ||\n utils.isBlob(data)\n ) {\n return data;\n }\n if (utils.isArrayBufferView(data)) {\n return data.buffer;\n }\n if (utils.isURLSearchParams(data)) {\n setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');\n return data.toString();\n }\n if (utils.isObject(data)) {\n setContentTypeIfUnset(headers, 'application/json;charset=utf-8');\n return JSON.stringify(data);\n }\n return data;\n }],\n\n transformResponse: [function transformResponse(data) {\n /*eslint no-param-reassign:0*/\n if (typeof data === 'string') {\n try {\n data = JSON.parse(data);\n } catch (e) { /* Ignore */ }\n }\n return data;\n }],\n\n /**\n * A timeout in milliseconds to abort a request. If set to 0 (default) a\n * timeout is not created.\n */\n timeout: 0,\n\n xsrfCookieName: 'XSRF-TOKEN',\n xsrfHeaderName: 'X-XSRF-TOKEN',\n\n maxContentLength: -1,\n maxBodyLength: -1,\n\n validateStatus: function validateStatus(status) {\n return status >= 200 && status < 300;\n }\n};\n\ndefaults.headers = {\n common: {\n 'Accept': 'application/json, text/plain, */*'\n }\n};\n\nutils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {\n defaults.headers[method] = {};\n});\n\nutils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {\n defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);\n});\n\nmodule.exports = defaults;\n","'use strict';\n\nvar utils = require('./../utils');\nvar transformData = require('./transformData');\nvar isCancel = require('../cancel/isCancel');\nvar defaults = require('../defaults');\n\n/**\n * Throws a `Cancel` if cancellation has been requested.\n */\nfunction throwIfCancellationRequested(config) {\n if (config.cancelToken) {\n config.cancelToken.throwIfRequested();\n }\n}\n\n/**\n * Dispatch a request to the server using the configured adapter.\n *\n * @param {object} config The config that is to be used for the request\n * @returns {Promise} The Promise to be fulfilled\n */\nmodule.exports = function dispatchRequest(config) {\n throwIfCancellationRequested(config);\n\n // Ensure headers exist\n config.headers = config.headers || {};\n\n // Transform request data\n config.data = transformData(\n config.data,\n config.headers,\n config.transformRequest\n );\n\n // Flatten headers\n config.headers = utils.merge(\n config.headers.common || {},\n config.headers[config.method] || {},\n config.headers\n );\n\n utils.forEach(\n ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],\n function cleanHeaderConfig(method) {\n delete config.headers[method];\n }\n );\n\n var adapter = config.adapter || defaults.adapter;\n\n return adapter(config).then(function onAdapterResolution(response) {\n throwIfCancellationRequested(config);\n\n // Transform response data\n response.data = transformData(\n response.data,\n response.headers,\n config.transformResponse\n );\n\n return response;\n }, function onAdapterRejection(reason) {\n if (!isCancel(reason)) {\n throwIfCancellationRequested(config);\n\n // Transform response data\n if (reason && reason.response) {\n reason.response.data = transformData(\n reason.response.data,\n reason.response.headers,\n config.transformResponse\n );\n }\n }\n\n return Promise.reject(reason);\n });\n};\n","'use strict';\n\nvar utils = require('../utils');\n\n/**\n * Config-specific merge-function which creates a new config-object\n * by merging two configuration objects together.\n *\n * @param {Object} config1\n * @param {Object} config2\n * @returns {Object} New object resulting from merging config2 to config1\n */\nmodule.exports = function mergeConfig(config1, config2) {\n // eslint-disable-next-line no-param-reassign\n config2 = config2 || {};\n var config = {};\n\n var valueFromConfig2Keys = ['url', 'method', 'data'];\n var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy', 'params'];\n var defaultToConfig2Keys = [\n 'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer',\n 'timeout', 'timeoutMessage', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',\n 'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'decompress',\n 'maxContentLength', 'maxBodyLength', 'maxRedirects', 'transport', 'httpAgent',\n 'httpsAgent', 'cancelToken', 'socketPath', 'responseEncoding'\n ];\n var directMergeKeys = ['validateStatus'];\n\n function getMergedValue(target, source) {\n if (utils.isPlainObject(target) && utils.isPlainObject(source)) {\n return utils.merge(target, source);\n } else if (utils.isPlainObject(source)) {\n return utils.merge({}, source);\n } else if (utils.isArray(source)) {\n return source.slice();\n }\n return source;\n }\n\n function mergeDeepProperties(prop) {\n if (!utils.isUndefined(config2[prop])) {\n config[prop] = getMergedValue(config1[prop], config2[prop]);\n } else if (!utils.isUndefined(config1[prop])) {\n config[prop] = getMergedValue(undefined, config1[prop]);\n }\n }\n\n utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) {\n if (!utils.isUndefined(config2[prop])) {\n config[prop] = getMergedValue(undefined, config2[prop]);\n }\n });\n\n utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties);\n\n utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {\n if (!utils.isUndefined(config2[prop])) {\n config[prop] = getMergedValue(undefined, config2[prop]);\n } else if (!utils.isUndefined(config1[prop])) {\n config[prop] = getMergedValue(undefined, config1[prop]);\n }\n });\n\n utils.forEach(directMergeKeys, function merge(prop) {\n if (prop in config2) {\n config[prop] = getMergedValue(config1[prop], config2[prop]);\n } else if (prop in config1) {\n config[prop] = getMergedValue(undefined, config1[prop]);\n }\n });\n\n var axiosKeys = valueFromConfig2Keys\n .concat(mergeDeepPropertiesKeys)\n .concat(defaultToConfig2Keys)\n .concat(directMergeKeys);\n\n var otherKeys = Object\n .keys(config1)\n .concat(Object.keys(config2))\n .filter(function filterAxiosKeys(key) {\n return axiosKeys.indexOf(key) === -1;\n });\n\n utils.forEach(otherKeys, mergeDeepProperties);\n\n return config;\n};\n","'use strict';\n\nvar utils = require('./../utils');\nvar buildURL = require('../helpers/buildURL');\nvar InterceptorManager = require('./InterceptorManager');\nvar dispatchRequest = require('./dispatchRequest');\nvar mergeConfig = require('./mergeConfig');\n\n/**\n * Create a new instance of Axios\n *\n * @param {Object} instanceConfig The default config for the instance\n */\nfunction Axios(instanceConfig) {\n this.defaults = instanceConfig;\n this.interceptors = {\n request: new InterceptorManager(),\n response: new InterceptorManager()\n };\n}\n\n/**\n * Dispatch a request\n *\n * @param {Object} config The config specific for this request (merged with this.defaults)\n */\nAxios.prototype.request = function request(config) {\n /*eslint no-param-reassign:0*/\n // Allow for axios('example/url'[, config]) a la fetch API\n if (typeof config === 'string') {\n config = arguments[1] || {};\n config.url = arguments[0];\n } else {\n config = config || {};\n }\n\n config = mergeConfig(this.defaults, config);\n\n // Set config.method\n if (config.method) {\n config.method = config.method.toLowerCase();\n } else if (this.defaults.method) {\n config.method = this.defaults.method.toLowerCase();\n } else {\n config.method = 'get';\n }\n\n // Hook up interceptors middleware\n var chain = [dispatchRequest, undefined];\n var promise = Promise.resolve(config);\n\n this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {\n chain.unshift(interceptor.fulfilled, interceptor.rejected);\n });\n\n this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {\n chain.push(interceptor.fulfilled, interceptor.rejected);\n });\n\n while (chain.length) {\n promise = promise.then(chain.shift(), chain.shift());\n }\n\n return promise;\n};\n\nAxios.prototype.getUri = function getUri(config) {\n config = mergeConfig(this.defaults, config);\n return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\\?/, '');\n};\n\n// Provide aliases for supported request methods\nutils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {\n /*eslint func-names:0*/\n Axios.prototype[method] = function(url, config) {\n return this.request(mergeConfig(config || {}, {\n method: method,\n url: url,\n data: (config || {}).data\n }));\n };\n});\n\nutils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {\n /*eslint func-names:0*/\n Axios.prototype[method] = function(url, data, config) {\n return this.request(mergeConfig(config || {}, {\n method: method,\n url: url,\n data: data\n }));\n };\n});\n\nmodule.exports = Axios;\n","'use strict';\n\n/**\n * A `Cancel` is an object that is thrown when an operation is canceled.\n *\n * @class\n * @param {string=} message The message.\n */\nfunction Cancel(message) {\n this.message = message;\n}\n\nCancel.prototype.toString = function toString() {\n return 'Cancel' + (this.message ? ': ' + this.message : '');\n};\n\nCancel.prototype.__CANCEL__ = true;\n\nmodule.exports = Cancel;\n","'use strict';\n\nvar Cancel = require('./Cancel');\n\n/**\n * A `CancelToken` is an object that can be used to request cancellation of an operation.\n *\n * @class\n * @param {Function} executor The executor function.\n */\nfunction CancelToken(executor) {\n if (typeof executor !== 'function') {\n throw new TypeError('executor must be a function.');\n }\n\n var resolvePromise;\n this.promise = new Promise(function promiseExecutor(resolve) {\n resolvePromise = resolve;\n });\n\n var token = this;\n executor(function cancel(message) {\n if (token.reason) {\n // Cancellation has already been requested\n return;\n }\n\n token.reason = new Cancel(message);\n resolvePromise(token.reason);\n });\n}\n\n/**\n * Throws a `Cancel` if cancellation has been requested.\n */\nCancelToken.prototype.throwIfRequested = function throwIfRequested() {\n if (this.reason) {\n throw this.reason;\n }\n};\n\n/**\n * Returns an object that contains a new `CancelToken` and a function that, when called,\n * cancels the `CancelToken`.\n */\nCancelToken.source = function source() {\n var cancel;\n var token = new CancelToken(function executor(c) {\n cancel = c;\n });\n return {\n token: token,\n cancel: cancel\n };\n};\n\nmodule.exports = CancelToken;\n","'use strict';\n\n/**\n * Syntactic sugar for invoking a function and expanding an array for arguments.\n *\n * Common use case would be to use `Function.prototype.apply`.\n *\n * ```js\n * function f(x, y, z) {}\n * var args = [1, 2, 3];\n * f.apply(null, args);\n * ```\n *\n * With `spread` this example can be re-written.\n *\n * ```js\n * spread(function(x, y, z) {})([1, 2, 3]);\n * ```\n *\n * @param {Function} callback\n * @returns {Function}\n */\nmodule.exports = function spread(callback) {\n return function wrap(arr) {\n return callback.apply(null, arr);\n };\n};\n","'use strict';\n\n/**\n * Determines whether the payload is an error thrown by Axios\n *\n * @param {*} payload The value to test\n * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false\n */\nmodule.exports = function isAxiosError(payload) {\n return (typeof payload === 'object') && (payload.isAxiosError === true);\n};\n","'use strict';\n\nvar utils = require('./utils');\nvar bind = require('./helpers/bind');\nvar Axios = require('./core/Axios');\nvar mergeConfig = require('./core/mergeConfig');\nvar defaults = require('./defaults');\n\n/**\n * Create an instance of Axios\n *\n * @param {Object} defaultConfig The default config for the instance\n * @return {Axios} A new instance of Axios\n */\nfunction createInstance(defaultConfig) {\n var context = new Axios(defaultConfig);\n var instance = bind(Axios.prototype.request, context);\n\n // Copy axios.prototype to instance\n utils.extend(instance, Axios.prototype, context);\n\n // Copy context to instance\n utils.extend(instance, context);\n\n return instance;\n}\n\n// Create the default instance to be exported\nvar axios = createInstance(defaults);\n\n// Expose Axios class to allow class inheritance\naxios.Axios = Axios;\n\n// Factory for creating new instances\naxios.create = function create(instanceConfig) {\n return createInstance(mergeConfig(axios.defaults, instanceConfig));\n};\n\n// Expose Cancel & CancelToken\naxios.Cancel = require('./cancel/Cancel');\naxios.CancelToken = require('./cancel/CancelToken');\naxios.isCancel = require('./cancel/isCancel');\n\n// Expose all/spread\naxios.all = function all(promises) {\n return Promise.all(promises);\n};\naxios.spread = require('./helpers/spread');\n\n// Expose isAxiosError\naxios.isAxiosError = require('./helpers/isAxiosError');\n\nmodule.exports = axios;\n\n// Allow use of default import syntax in TypeScript\nmodule.exports.default = axios;\n","module.exports = require('./lib/axios');","\nimport { setLogger } from '../ulity/debug';\nimport * as debug from '../ulity/debug';\nimport Event from '../ulity/event';\nimport Events from '../base/event';\nimport axios from 'axios';\nimport * as Base from '../base/export';\n\nexport default class RTCEndpoint extends Event\n{\n constructor(options)\n {\n super('RTCPusherPlayer');\n this.TAG = '[RTCPusherPlayer]';\n\n let defaults = {\n element: '',// html video element\n debug: false,// if output debug log\n zlmsdpUrl:'',\n simulcast:false,\n useCamera:true,\n audioEnable:true,\n videoEnable:true,\n recvOnly:false,\n resolution:{w:0,h:0}\n };\n \n this.options = Object.assign({}, defaults, options);\n\n if(this.options.debug)\n {\n setLogger();\n }\n\n this.e = {\n onicecandidate:this._onIceCandidate.bind(this),\n ontrack:this._onTrack.bind(this),\n onicecandidateerror:this._onIceCandidateError.bind(this)\n };\n\n this._remoteStream = null;\n this._localStream = null;\n\n this.pc = new RTCPeerConnection(null);\n\n this.pc.onicecandidate = this.e.onicecandidate;\n this.pc.onicecandidateerror = this.e.onicecandidateerror;\n this.pc.ontrack = this.e.ontrack;\n\n if(!this.options.recvOnly && (this.options.audioEnable || this.options.videoEnable))\n this.start();\n else\n this.receive();\n \n }\n\n receive()\n {\n let audioTransceiver = null;\n let videoTransceiver = null;\n\n //debug.error(this.TAG,'this not implement');\n const AudioTransceiverInit = {\n direction: 'recvonly',\n sendEncodings:[]\n };\n const VideoTransceiverInit= {\n direction: 'recvonly',\n sendEncodings:[],\n };\n\n audioTransceiver = this.pc.addTransceiver('audio',AudioTransceiverInit);\n videoTransceiver = this.pc.addTransceiver('video',VideoTransceiverInit);\n \n this.pc.createOffer().then((desc)=>{\n debug.log(this.TAG,'offer:',desc.sdp);\n this.pc.setLocalDescription(desc).then(() => {\n axios({\n method: 'post',\n url:this.options.zlmsdpUrl,\n responseType:'json',\n data:desc.sdp,\n headers:{\n 'Content-Type':'text/plain;charset=utf-8'\n }\n }).then(response=>{\n let ret = response.data;//JSON.parse(response.data);\n if(ret.code != 0)\n {// mean failed for offer/answer exchange \n this.dispatch(Events.WEBRTC_OFFER_ANSWER_EXCHANGE_FAILED,ret);\n return;\n }\n let answer = {};\n answer.sdp = ret.sdp;\n answer.type = 'answer';\n debug.log(this.TAG,'answer:',ret.sdp);\n\n this.pc.setRemoteDescription(answer).then(()=>{\n debug.log(this.TAG,'set remote sucess');\n }).catch(e=>{\n debug.error(this.TAG,e);\n });\n });\n });\n }).catch(e=>{\n debug.error(this.TAG,e);\n });\n }\n\n start()\n {\n let videoConstraints = false;\n let audioConstraints = false;\n\n if(this.options.useCamera)\n {\n if(this.options.videoEnable)\n videoConstraints = new Base.VideoTrackConstraints(Base.VideoSourceInfo.CAMERA);\n if(this.options.audioEnable)\n audioConstraints = new Base.AudioTrackConstraints(Base.AudioSourceInfo.MIC);\n }\n else\n {\n if(this.options.videoEnable)\n {\n videoConstraints = new Base.VideoTrackConstraints(Base.VideoSourceInfo.SCREENCAST);\n if(this.options.audioEnable)\n audioConstraints = new Base.AudioTrackConstraints(Base.AudioSourceInfo.SCREENCAST);\n }\n else\n {\n if(this.options.audioEnable)\n audioConstraints = new Base.AudioTrackConstraints(Base.AudioSourceInfo.MIC);\n else\n {// error shared display media not only audio\n debug.error(this.TAG,'error paramter');\n }\n }\n \n }\n\n if(this.options.resolution.w !=0 && this.options.resolution.h!=0 && typeof videoConstraints == 'object'){\n videoConstraints.resolution = new Base.Resolution(this.options.resolution.w ,this.options.resolution.h);\n }\n\n Base.MediaStreamFactory.createMediaStream(new Base.StreamConstraints(\n audioConstraints, videoConstraints)).then(stream => {\n\n this._localStream = stream;\n\n this.dispatch(Events.WEBRTC_ON_LOCAL_STREAM,stream);\n\n const AudioTransceiverInit = {\n direction: 'sendrecv',\n sendEncodings:[]\n };\n const VideoTransceiverInit= {\n direction: 'sendrecv',\n sendEncodings:[],\n };\n \n if(this.options.simulcast && stream.getVideoTracks().length>0)\n {\n VideoTransceiverInit.sendEncodings = [\n {rid: 'q', active: true, scaleResolutionDownBy: 4.0},\n {rid: 'h', active: true, scaleResolutionDownBy: 2.0},\n {rid: 'f', active: true}\n ];\n }\n let audioTransceiver = null;\n let videoTransceiver = null;\n\n if(stream.getAudioTracks().length>0)\n {\n audioTransceiver = this.pc.addTransceiver(stream.getAudioTracks()[0],\n AudioTransceiverInit);\n }\n else\n {\n AudioTransceiverInit.direction ='recvonly';\n audioTransceiver = this.pc.addTransceiver('audio',AudioTransceiverInit);\n }\n \n if(stream.getVideoTracks().length>0)\n {\n videoTransceiver = this.pc.addTransceiver(stream.getVideoTracks()[0],\n VideoTransceiverInit);\n }\n else\n {\n VideoTransceiverInit.direction = 'recvonly';\n videoTransceiver = this.pc.addTransceiver('video',\n VideoTransceiverInit);\n }\n\n /*\n stream.getTracks().forEach((track,idx)=>{\n debug.log(this.TAG,track);\n this.pc.addTrack(track);\n });\n */\n this.pc.createOffer().then((desc)=>{\n debug.log(this.TAG,'offer:',desc.sdp);\n this.pc.setLocalDescription(desc).then(() => {\n axios({\n method: 'post',\n url:this.options.zlmsdpUrl,\n responseType:'json',\n data:desc.sdp,\n headers:{\n 'Content-Type':'text/plain;charset=utf-8'\n }\n }).then(response=>{\n let ret = response.data;//JSON.parse(response.data);\n if(ret.code != 0)\n {// mean failed for offer/answer exchange \n this.dispatch(Events.WEBRTC_OFFER_ANSWER_EXCHANGE_FAILED,ret);\n return;\n }\n let answer = {};\n answer.sdp = ret.sdp;\n answer.type = 'answer';\n debug.log(this.TAG,'answer:',ret.sdp);\n \n this.pc.setRemoteDescription(answer).then(()=>{\n debug.log(this.TAG,'set remote sucess');\n }).catch(e=>{\n debug.error(this.TAG,e);\n });\n });\n });\n }).catch(e=>{\n debug.error(this.TAG,e);\n });\n\n }).catch(e=>{\n this.dispatch(Events.CAPTURE_STREAM_FAILED);\n //debug.error(this.TAG,e);\n });\n \n //const offerOptions = {};\n /*\n if (typeof this.pc.addTransceiver === 'function') {\n // |direction| seems not working on Safari.\n this.pc.addTransceiver('audio', { direction: 'recvonly' });\n this.pc.addTransceiver('video', { direction: 'recvonly' });\n } else {\n offerOptions.offerToReceiveAudio = true;\n offerOptions.offerToReceiveVideo = true;\n }\n */\n\n\n\n }\n _onIceCandidate(event) {\n if (event.candidate) { \n debug.log('Remote ICE candidate: \\n ' + event.candidate.candidate);\n // Send the candidate to the remote peer\n }\n else {\n // All ICE candidates have been sent\n }\n }\n\n _onTrack(event){\n if(this.options.element && event.streams && event.streams.length>0)\n {\n this.options.element.srcObject = event.streams[0];\n this._remoteStream = event.streams[0];\n\n this.dispatch(Events.WEBRTC_ON_REMOTE_STREAMS,event);\n }\n else\n {\n debug.error('element pararm is failed');\n }\n }\n\n _onIceCandidateError(event){\n this.dispatch(Events.WEBRTC_ICE_CANDIDATE_ERROR,event);\n }\n\n close()\n {\n if(this.pc)\n {\n this.pc.close();\n this.pc=null;\n }\n\n if(this.options)\n {\n this.options=null;\n }\n\n if(this._localStream)\n {\n this._localStream.getTracks().forEach((track,idx)=>{\n track.stop();\n });\n }\n\n if(this._remoteStream)\n {\n this._remoteStream.getTracks().forEach((track,idx)=>{\n track.stop();\n });\n }\n }\n\n get remoteStream()\n {\n return this._remoteStream;\n }\n \n get localStream()\n {\n return this._localStream;\n }\n}\n","import * as mediaformat from './mediaformat';\nimport * as MediaFactory from './mediastream-factory';\n\n\nconst quickScan=[\n {\n 'label': '4K(UHD)',\n 'width': 3840,\n 'height': 2160\n },\n {\n 'label': '1080p(FHD)',\n 'width': 1920,\n 'height': 1080\n },\n {\n 'label': 'UXGA',\n 'width': 1600,\n 'height': 1200,\n 'ratio': '4:3'\n },\n {\n 'label': '720p(HD)',\n 'width': 1280,\n 'height': 720\n },\n {\n 'label': 'SVGA',\n 'width': 800,\n 'height': 600\n },\n {\n 'label': 'VGA',\n 'width': 640,\n 'height': 480\n },\n {\n 'label': '360p(nHD)',\n 'width': 640,\n 'height': 360\n },\n {\n 'label': 'CIF',\n 'width': 352,\n 'height': 288\n },\n {\n 'label': 'QVGA',\n 'width': 320,\n 'height': 240\n },\n {\n 'label': 'QCIF',\n 'width': 176,\n 'height': 144\n },\n {\n 'label': 'QQVGA',\n 'width': 160,\n 'height': 120\n }\n];\n\n\n\n\nexport default function GetSupportCameraResolutions(){\n return new Promise(function (resolve, reject) {\n let resolutions = [];\n let ok = 0;\n let err = 0;\n for (let i = 0; i < quickScan.length; ++i) {\n let videoConstraints = new MediaFactory.VideoTrackConstraints(mediaformat.VideoSourceInfo.CAMERA);\n videoConstraints.resolution = new mediaformat.Resolution(quickScan[i].width, quickScan[i].height);\n\n MediaFactory.MediaStreamFactory.createMediaStream(new MediaFactory.StreamConstraints(\n false, videoConstraints)).then(stream => {\n resolutions.push(quickScan[i]);\n ok++;\n if(ok+err == quickScan.length)\n {\n resolve(resolutions);\n }\n }).catch(e => {\n err++;\n if(ok+err == quickScan.length)\n {\n resolve(resolutions);\n }\n });\n }\n });\n}\n\nexport function GetAllScanResolution()\n{\n return quickScan;\n}\nexport function isSupportResolution(w,h)\n{\n return new Promise(function (resolve, reject) {\n let videoConstraints = new MediaFactory.VideoTrackConstraints(mediaformat.VideoSourceInfo.CAMERA);\n videoConstraints.resolution = new mediaformat.Resolution(w,h);\n\n MediaFactory.MediaStreamFactory.createMediaStream(new MediaFactory.StreamConstraints(\n false, videoConstraints)).then(stream => {\n resolve();\n }).catch(e => {\n reject(e);\n });\n });\n}","import * as events from './base/event';\nimport * as compile from './ulity/version';\nimport * as media from './base/export';\nimport * as endpoint from './endpoint/endpoint';\nimport * as resolution from './base/resolutionfind';\n\n\n\nconsole.log('build date:',compile.BUILD_DATE);\nconsole.log('version:',compile.VERSION);\n\nexport const Events = events.default;\nexport const Media = media;\nexport const Endpoint = endpoint.default;\nexport const GetSupportCameraResolutions = resolution.default;\nexport const GetAllScanResolution = resolution.GetAllScanResolution;\nexport const isSupportResolution = resolution.isSupportResolution;"],"names":["Events","WEBRTC_NOT_SUPPORT","WEBRTC_ICE_CANDIDATE_ERROR","WEBRTC_OFFER_ANSWER_EXCHANGE_FAILED","WEBRTC_ON_REMOTE_STREAMS","WEBRTC_ON_LOCAL_STREAM","CAPTURE_STREAM_FAILED","VERSION","BUILD_DATE","isFirefox","window","navigator","userAgent","match","isChrome","isEdge","AudioSourceInfo","MIC","SCREENCAST","FILE","MIXED","VideoSourceInfo","CAMERA","TrackKind","AUDIO","VIDEO","AUDIO_AND_VIDEO","Resolution","constructor","width","height","log","isObject","utils.log","shimGetUserMedia","shimGetDisplayMedia","shimOnTrack","utils.wrapPeerConnectionEvent","utils.filterStats","shimPeerConnection","filterIceServers","utils.deprecated","sdp","SDPUtils","shimRTCPeerConnection","utils.compactObject","utils.detectBrowser","utils.extractVersion","utils.disableLog","utils.disableWarnings","chromeShim.shimPeerConnection","commonShim.shimAddIceCandidateNullOrEmpty","chromeShim.shimGetUserMedia","chromeShim.shimMediaStream","chromeShim.shimOnTrack","chromeShim.shimAddTrackRemoveTrack","chromeShim.shimGetSendersWithDtmf","chromeShim.shimGetStats","chromeShim.shimSenderReceiverGetStats","chromeShim.fixNegotiationNeeded","commonShim.shimRTCIceCandidate","commonShim.shimConnectionState","commonShim.shimMaxMessageSize","commonShim.shimSendThrowTypeError","commonShim.removeExtmapAllowMixed","firefoxShim.shimPeerConnection","firefoxShim.shimGetUserMedia","firefoxShim.shimOnTrack","firefoxShim.shimRemoveStream","firefoxShim.shimSenderGetStats","firefoxShim.shimReceiverGetStats","firefoxShim.shimRTCDataChannel","firefoxShim.shimAddTransceiver","firefoxShim.shimGetParameters","firefoxShim.shimCreateOffer","firefoxShim.shimCreateAnswer","edgeShim.shimPeerConnection","edgeShim.shimGetUserMedia","edgeShim.shimGetDisplayMedia","edgeShim.shimReplaceTrack","safariShim.shimRTCIceServerUrls","safariShim.shimCreateOfferLegacy","safariShim.shimCallbacksAPI","safariShim.shimLocalStreamsAPI","safariShim.shimRemoteStreamsAPI","safariShim.shimTrackEventTransceiver","safariShim.shimGetUserMedia","safariShim.shimAudioContext","AudioTrackConstraints","source","Object","values","MediaFormatModule","some","v","TypeError","deviceId","undefined","VideoTrackConstraints","resolution","frameRate","StreamConstraints","audioConstraints","videoConstraints","audio","video","isVideoConstrainsForScreenCast","constraints","MediaStreamFactory","createMediaStream","Promise","reject","utils","mediaConstraints","create","exact","mediaSource","mediaDevices","getDisplayMedia","getUserMedia","logger","errorLogger","setLogger","console","error","message","optionalParams","Event","type","listener","on","event","fn","push","off","index","indexOf","splice","offAll","dispatch","data","map","each","apply","require$$0","require$$1","defaults","InterceptorManager","Cancel","Axios","axios","require$$2","require$$3","require$$4","RTCEndpoint","options","TAG","element","debug","zlmsdpUrl","simulcast","useCamera","audioEnable","videoEnable","recvOnly","w","h","assign","e","onicecandidate","_onIceCandidate","bind","ontrack","_onTrack","onicecandidateerror","_onIceCandidateError","_remoteStream","_localStream","pc","RTCPeerConnection","start","receive","AudioTransceiverInit","direction","sendEncodings","VideoTransceiverInit","audioTransceiver","addTransceiver","videoTransceiver","createOffer","then","desc","setLocalDescription","method","url","responseType","headers","response","ret","code","answer","setRemoteDescription","catch","Base","stream","getVideoTracks","length","rid","active","scaleResolutionDownBy","getAudioTracks","candidate","streams","srcObject","close","getTracks","forEach","track","idx","stop","remoteStream","localStream","quickScan","GetSupportCameraResolutions","resolve","resolutions","ok","err","i","MediaFactory","mediaformat","GetAllScanResolution","isSupportResolution","compile","events","Media","media","Endpoint","endpoint"],"mappings":";;;CAAA,MAAMA,QAAM,GAAG;CACdC,EAAAA,kBAAkB,EAAG,oBADP;CAEdC,EAAAA,0BAA0B,EAAG,4BAFf;CAGdC,EAAAA,mCAAmC,EAAC,qCAHtB;CAIdC,EAAAA,wBAAwB,EAAC,0BAJX;CAKdC,EAAAA,sBAAsB,EAAC,wBALT;CAMdC,EAAAA,qBAAqB,EAAC;CANR,CAAf;;CCAO,MAAMC,OAAO,GAAG,OAAhB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AT,CAA6BnE,CAA7B,EAA+BC,CAA/B,EACP;CACI,SAAO,IAAIxD,OAAJ,CAAY,UAAUkH,OAAV,EAAmBjH,MAAnB,EAA2B;CAC1C,QAAIR,gBAAgB,GAAG,IAAI8H,qBAAJ,CAAuCC,eAAA,CAA4BhN,MAAnE,CAAvB;CACAiF,IAAAA,gBAAgB,CAACJ,UAAjB,GAA8B,IAAImI,UAAJ,CAA2BjE,CAA3B,EAA6BC,CAA7B,CAA9B;CAEA+D,IAAAA,kBAAA,CAAgCxH,iBAAhC,CAAkD,IAAIwH,iBAAJ,CAC9C,KAD8C,EACvC9H,gBADuC,CAAlD,EAC8BuF,IAD9B,CACmCc,MAAM,IAAI;CACjCoB,MAAAA,OAAO;CACd,KAHL,EAGOtB,KAHP,CAGalC,CAAC,IAAI;CACVzD,MAAAA,MAAM,CAACyD,CAAD,CAAN;CACH,KALL;CAMH,GAVM,CAAP;CAWH;;CCvGD7C,OAAO,CAAC5F,GAAR,CAAY,aAAZ,EAA0B0M,UAA1B;CACA9G,OAAO,CAAC5F,GAAR,CAAY,UAAZ,EAAuB0M,OAAvB;OAEazO,MAAM,GAAG0O;OACTC,KAAK,GAAGC;OACRC,QAAQ,GAAGC;OACXf,2BAA2B,GAAG5H;OAC9BoI,oBAAoB,GAAGpI;OACvBqI,mBAAmB,GAAGrI;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/www/webrtc/index.html b/www/webrtc/index.html new file mode 100644 index 00000000..9007d34b --- /dev/null +++ b/www/webrtc/index.html @@ -0,0 +1,192 @@ + + + + ZLM RTC demo + + + + + +
+
+ + + +
+ +
+ +

+ + +

+ +

+ + +

+

+ + +

+ + +

+ + +

+ +

+ + +

+ +

+ + push + play +

+ +

+ + +

+ + + + +
+
+ + + + + + + + \ No newline at end of file diff --git a/www/webrtc/readme.txt b/www/webrtc/readme.txt new file mode 100644 index 00000000..ba651b40 --- /dev/null +++ b/www/webrtc/readme.txt @@ -0,0 +1,2 @@ +感谢[big panda](<2381267071@qq.com>) 开发并贡献此webrtc js测试客户端, +其开源项目地址为:https://gitee.com/xiongguangjie/zlmrtcclient.js \ No newline at end of file