@rongcloud/plugin-rtc 5.6.8 → 5.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import{EventEmitter as e,isNumber as t,validate as i,isObject as r,ErrorCode as n,HttpMethod as o,isArray as s,ConnectionStatus as a,notEmptyObject as c,notEmptyArray as d,notEmptyString as _,isString as l,RTCMode as u,assert as h,ConversationType as g,isHttpUrl as v,isBoolean as p,isUndefined as R,forEach as m,VersionManage as I,LogL as E}from"@rongcloud/engine";
1
+ import{EventEmitter as e,isNumber as t,validate as i,isObject as r,ErrorCode as n,HttpMethod as o,isArray as s,RCConnectionStatus as a,notEmptyObject as c,notEmptyArray as d,notEmptyString as _,isString as l,RTCMode as u,assert as h,ConversationType as g,isHttpUrl as v,isBoolean as p,isUndefined as R,forEach as m,VersionManage as I,LogL as E}from"@rongcloud/engine";
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
@@ -12,5 +12,5 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */function S(e,t,i,r){return new(i||(i=Promise))((function(n,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}var T,f,C;!function(e){e[e.SUCCESS=1e4]="SUCCESS",e[e.PB_ERROR=40001]="PB_ERROR",e[e.SIGNAL_DISCONNECTED=5e4]="SIGNAL_DISCONNECTED",e[e.PARAMS_ERROR=50001]="PARAMS_ERROR",e[e.REPERT_JOIN_ROOM=50002]="REPERT_JOIN_ROOM",e[e.NOT_IN_ROOM=50003]="NOT_IN_ROOM",e[e.SERVICE_INVALID=50004]="SERVICE_INVALID",e[e.RTC_TOKEN_INVALID=50006]="RTC_TOKEN_INVALID",e[e.SIGNAL_ERROR=53001]="SIGNAL_ERROR",e[e.CREATE_OFFER_FAILED=53003]="CREATE_OFFER_FAILED",e[e.REQUEST_FAILED=53004]="REQUEST_FAILED",e[e.MCU_SERVER_NOT_FOUND=53005]="MCU_SERVER_NOT_FOUND",e[e.BROADCAST_SUB_LIST_NOT_EMPTY=53007]="BROADCAST_SUB_LIST_NOT_EMPTY",e[e.ROOM_HAS_BEEN_DESTROYED=53008]="ROOM_HAS_BEEN_DESTROYED",e[e.NOT_OPEN_VIDEO_AUDIO_SERVER=53009]="NOT_OPEN_VIDEO_AUDIO_SERVER",e[e.GET_USER_MEDIA_FAILED=53010]="GET_USER_MEDIA_FAILED",e[e.GET_DISPLAY_MEDIA_FAILED=53011]="GET_DISPLAY_MEDIA_FAILED",e[e.BROWSER_PERMISSION_DENIED=53012]="BROWSER_PERMISSION_DENIED",e[e.CREATE_CUSTOM_TRACK_FAILED=53013]="CREATE_CUSTOM_TRACK_FAILED",e[e.INVALID_TAGS=53014]="INVALID_TAGS",e[e.INVALID_USER_ID=53015]="INVALID_USER_ID",e[e.CREATE_FILE_TRACK_FAILED=53016]="CREATE_FILE_TRACK_FAILED",e[e.INVALID_FILE_INSTANCE=53017]="INVALID_FILE_INSTANCE",e[e.SET_REMOTE_DESCRIPTION_FAILED=53018]="SET_REMOTE_DESCRIPTION_FAILED",e[e.BROWSER_NOT_SUPPORT=53019]="BROWSER_NOT_SUPPORT",e[e.TRACK_NOT_READY=53020]="TRACK_NOT_READY",e[e.VIDEO_TRACK_MISS_MEDIA_ELEMENT=53021]="VIDEO_TRACK_MISS_MEDIA_ELEMENT",e[e.TRACK_PLAY_ERROR=53022]="TRACK_PLAY_ERROR",e[e.SIGNAL_AUDIENCE_JOIN_ROOM_FAILED=53023]="SIGNAL_AUDIENCE_JOIN_ROOM_FAILED",e[e.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED=53024]="SIGNAL_ROOM_CHANGE_IDENTITY_FAILED",e[e.PACKAGE_ENVIRONMENT_ERROR=53025]="PACKAGE_ENVIRONMENT_ERROR",e[e.PUBLISH_TRACK_LIMIT_EXCEEDED=53026]="PUBLISH_TRACK_LIMIT_EXCEEDED",e[e.CDN_RESOURCE_IS_EMPTY=53027]="CDN_RESOURCE_IS_EMPTY",e[e.SIGNAL_JOIN_RTC_ROOM_REFUSED=53028]="SIGNAL_JOIN_RTC_ROOM_REFUSED",e[e.NO_PERMISSION_TO_USE_REQUESTED_DEVICE=53029]="NO_PERMISSION_TO_USE_REQUESTED_DEVICE",e[e.THE_FUNCTION_IS_DISABLED_IN_PKROOM=53030]="THE_FUNCTION_IS_DISABLED_IN_PKROOM",e[e.SOME_TRACKS_PUBLISH_FAILED=53031]="SOME_TRACKS_PUBLISH_FAILED",e[e.MAC_IN_ELECTRON_NOT_SUPPORT_SCREEN_SHARE_WITH_AUDIO=53032]="MAC_IN_ELECTRON_NOT_SUPPORT_SCREEN_SHARE_WITH_AUDIO",e[e.JWT_TIME_OUT=1004]="JWT_TIME_OUT",e[e.SYSTEM_PERMISSION_DENIED=53033]="SYSTEM_PERMISSION_DENIED",e[e.PUBLISH_TRACKS_IS_INVALID=53034]="PUBLISH_TRACKS_IS_INVALID"}(T||(T={})),function(e){e.L_INDEX_INSTALL_RTC_PLUGIN_O="L-index_install_rtc_plugin-O",e.L_RTC_CLIENT_IM_CONNECTION_STATE_S="L-rtc_client_im_connection_state-S",e.L_RTC_CLIENT_IM_DISCONNECT_S="L-rtc_client_im_disconnect-S",e.L_RTC_CLIENT_MESSAGE_O="L-rtc_client_message-O",e.L_RTC_CLIENT_DESTROY_S="L-rtc_client_destroy-S",e.L_RTC_CLIENT_JOIN_RTC_ROOM_T="L-rtc_client_join_rtc_room-T",e.L_RTC_CLIENT_JOIN_RTC_ROOM_R="L-rtc_client_join_rtc_room-R",e.L_RTC_CLIENT_JOIN_LIVING_ROOM_T="L-rtc_client_join_living_room-T",e.L_RTC_CLIENT_JOIN_LIVING_ROOM_R="L-rtc_client_join_living_room-R",e.L_RTC_CLIENT_GET_AUDIENCE_CLIENT_O="L-rtc_client_get_audience_client-O",e.L_RTC_CLIENT_LEAVE_ROOM_T="L-rtc_client_leave_room-T",e.L_RTC_CLIENT_LEAVE_ROOM_R="L-rtc_client_leave_room-R",e.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O="L-rtc_client_create_microphone_audio_track-O",e.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O="L-rtc_client_create_camera_video_track-O",e.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O="L-rtc_client_create_microphone_and_camera_tracks-O",e.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_TRACK_O="L-rtc_client_create_screen_video_track-O",e.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_AND_AUDIO_TRACKS_O="L-rtc_client_create_screen_video_and_audio_tracks-O",e.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O="L-rtc_client_create_local_audio_track-O",e.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O="L-rtc_client_create_local_video_track-O",e.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O="L-rtc_client_create_local_file_tracks-O",e.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O="L-rtc_client_create_local_tracks-O",e.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_T="L-rtc_client_join_living_room_as_audience-T",e.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R="L-rtc_client_join_living_room_as_audience_R",e.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_T="L-rtc_client_leave_living_room_as_audience-T",e.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R="L-rtc_client_leave_living_room_as_audience-R",e.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_T="L-rtc_client_upgrade_to_anchor_room-T",e.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R="L-rtc_client_upgrade_to_anchor_room-R",e.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_T="L-rtc_client_downgrade_to_audience_room-T",e.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R="L-rtc_client_downgrade_to_audience_room-R",e.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_T="L-rtc_client_get_joined_room_info-T",e.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_R="L-rtc_client_get_joined_room_info-R",e.L_AUDIENCE_CLIENT_CALL_ONTRACKREADY_O="L-audinence_client_call_onTrackReady-O",e.L_AUDIENCE_CLIENT_SUBSCRIBE_T="L-audinence_client_subscribe-T",e.L_AUDIENCE_CLIENT_SUBSCRIBE_R="L-audinence_client_subscribe-R",e.L_AUDIENCE_CLIENT_UNSUBSCRIBE_T="L-audinence_client_unsubscribe-T",e.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R="L-audinence_client_unsubscribe-R",e.L_PINGER_START_O="L-pinger_start-O",e.L_PINGER_STOP_O="L-pinger_stop-O",e.L_PINGER_SEND_RTCPING_T="L-pinger_send_rtcping-T",e.L_PINGER_SEND_RTCPING_R="L-pinger_send_rtcping-R",e.L_ABSTRACT_ROOM_SEND_MESSAGE_T="L-abstract_room_send_message-T",e.L_ABSTRACT_ROOM_SEND_MESSAGE_R="L-abstract_room_send_message-R",e.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_T="L-abstract_room_set_room_attribute-T",e.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_R="L-abstract_room_set_room_attribute_R",e.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_T="L-abstract_room_delete_room_attribute_T",e.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R="L-abstract_room_delete_room_attribute_R",e.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_T="L-abstract_room_get_room_attribute_T",e.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_R="L-abstract_room_get_room_attribute_R",e.L_ABSTRACT_ROOM_PUBLISH_T="L-abstract_room_publish-T",e.L_ABSTRACT_ROOM_PUBLISH_R="L-abstract_room_publish-R",e.L_ABSTRACT_ROOM_PUBLISH_P="L-abstract_room_publish-P",e.L_ABSTRACT_ROOM_UNPUBLISH_T="L-abstract_room_unpublish-T",e.L_ABSTRACT_ROOM_UNPUBLISH_R="L-abstract_room_unpublish-R",e.L_ABSTRACT_ROOM_UNPUBLISH_P="L-abstract_room_unpublish-P",e.L_ABSTRACT_ROOM_SUBSCRIBE_T="L-abstract_room_subscribe-T",e.L_ABSTRACT_ROOM_SUBSCRIBE_R="L-abstract_room_subscribe-R",e.L_ABSTRACT_ROOM_UNSUBSCRIBE_T="L-abstract_room_unsubscribe-T",e.L_ABSTRACT_ROOM_UNSUBSCRIBE_R="L-abstract_room_unsubscribe-R",e.L_APP_CALL_UNSUBSCRIBE_O="L-app_call_unsubscribe-O",e.L_USER_LEFT_UNSUBSCRIBE_O="L-user_left_unsubscribe-O",e.L_RES_UNPUB_UNSUBSCRIBE_O="L-res_unpub_unsubscribe-O",e.L_ABSTRACT_ROOM_REGISTER_ROOM_EVENT_LISTENER_O="L-abstract_room_register_room_event_listener-O",e.L_ABSTRACT_ROOM_REGISTER_REPORT_LISTENER_O="L-abstract_room_register_report_listener-O",e.L_ABSTRACT_ROOM_AUDIO_LEVEL_O="L-abstract_room_audio_level-O",e.L_ABSTRACT_ROOM_IM_RECONNECTED_T="L-abstract_room_im_reconnected-T",e.L_ABSTRACT_ROOM_IM_RECONNECTED_R="L-abstract_room_im_reconnected-R",e.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O="L-abstract_room_call_app_listener-O",e.L_ABSTRACT_ROOM_SETBITRATE_O="L-abstract_room_setBitrate-O",e.L_ABSTRACT_ROOM_ONTRACKREADY_O="L-abstract_room_onTrackReady-O",e.L_ABSTRACT_ROOM_RECEIVE_MESSAGE_O="L-abstract_room_receive_message-O",e.L_ABSTRACT_ROOM_ONKICKOFF_O="L-abstract_room_onKickoff-O",e.L_LIVING_ROOM_RECONNECTED_T="L-living_room_reconnected-T",e.L_LIVING_ROOM_RECONNECTED_R="L-living_room_reconnected-R",e.L_LIVING_ROOM_ENABLE_INNER_CDN_T="L-living_room_enable_inner_cdn-T",e.L_LIVING_ROOM_ENABLE_INNER_CDN_R="L-living_room_enable_inner_cdn-R",e.L_LIVING_ROOM_SPREAD_CDN_INFO_T="L-living_room_spread_cdn_info-T",e.L_LIVING_ROOM_SPREAD_CDN_INFO_R="L-living_room_spread_cdn_info-R",e.L_LIVING_ROOM_SET_ROOM_CDN_INFO_T="L-living_room_set_room_cdn_info-T",e.L_LIVING_ROOM_SET_ROOM_CDN_INFO_R="L-living_room_set_room_cdn_info-R",e.L_LIVING_ROOM_JOINED_PK_ROOM_T="L-living_room_joined_pk_room-T",e.L_LIVING_ROOM_JOINED_PK_ROOM_R="L-living_room_joined_pk_room-R",e.L_LIVING_ROOM_LEAVE_PK_ROOM_T="L-living_room_leave_pk_room-T",e.L_LIVING_ROOM_LEAVE_PK_ROOM_R="L-living_room_leave_pk_room-R",e.L_APP_CALL_LEAVE_PK_ROOM_O="L-app_call_leave_pk_room-O",e.L_QUIT_PK_LEAVE_PK_ROOM_O="L-quit_pk_leave_pk_room-O",e.L_LIVING_ROOM_GET_ROOM_PK_HANDLER_O="L-living_room_get_room_pk_handler-O",e.L_LIVING_ROOM_GET_MCU_CONFIG_BUILDER_O="L-living_room_get_mcu_config_builder-O",e.L_LIVING_ROOM_QUIT_ALL_PK_ROOM_O="L-living_room_quit_all_pk_room-O",e.L_LIVING_PK_HANDLER_REGISTER_ROOM_PK_EVENT_LISTENER_O="L-living_pk_handler_register_room_pk_event_listener-O",e.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O="L-living_pk_handler_call_app_listener-O",e.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_T="L-living_pk_handler_request_join_other_room-T",e.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R="L-living_pk_handler_request_join_other_room-R",e.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_T="L-living_pk_handler_cancel_request_join_other_room-T",e.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R="L-living_pk_handler_cancel_request_join_other_room-R",e.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_T="L-living_pk_handler_response_join_other_room-T",e.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R="L-living_pk_handler_response_join_other_room-R",e.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_T="L-living_pk_handler_join_other_room-T",e.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R="L-living_pk_handler_join_other_room-R",e.L_LIVING_PK_HANDLER_LEAVE_OTHER_ROOM_T="L-living_pk_handler_leave_other_room-T",e.L_LIVING_PK_HANDLER_LEAVE_OTHER_ROOM_R="L-living_pk_handler_leave_other_room-R",e.L_QUIT_PK_T="L-quit_pk-T",e.L_QUIT_PK_R="L-quit_pk-R",e.L_EXCHANGE_WITH_PUSHOTHERROOM_T="L-exchange_with_pushotherroom-T",e.L_EXCHANGE_WITH_PUSHOTHERROOM_R="L-exchange_with_pushotherroom-R",e.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O="L-audience_living_room_call_app_listener-O",e.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_O="L-audience_living_room_pull_kvEntries-O",e.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_T="L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_T",e.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R="L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R",e.L_AUDIENCE_LIVING_ROOM_SINGAL_DATA_CHANGE_P="L-audience_living_room_singal_data_change-P",e.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_T="L-audience_living_room_get_cdn_play_url-T",e.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R="L-audience_living_room_get_cdn_play_url-R",e.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_T="L-audience_living_room_subscribe-T",e.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R="L-audience_living_room_subscribe-R",e.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_T="L-audience_living_room_unsubscribe-T",e.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_R="L-audience_living_room_unsubscribe-R",e.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_T="L-audience_living_room_update_subscribeList-T",e.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R="L-audience_living_room_update_subscribeList-R",e.L_AUDIENCE_LIVING_ROOM_ONTRACKREADY_O="L-audience_living_room_onTrackReady-O",e.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_R="L-audience_living_room_im_reconnected-R",e.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_T="L-audience_living_room_im_reconnected-T",e.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O="L-mcu_config_builder_set_host_video_track-O",e.L_MCU_CONFIG_BUILDER_SET_MIX_LAYOUT_MODE_O="L-mcu_config_builder_set_mix_layout_mode-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RESOLUTION_O="L-mcu_config_builder_set_output_video_resolution-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_FPS_O="L-mcu_config_builder_set_output_video_fps-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_BITRATE_O="L-mcu_config_builder_set_output_video_bitrate-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_RESOLUTION_O="L-mcu_config_builder_set_output_tiny_video_resolution-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_FPS_O="L-mcu_config_builder_set_output_tiny_video_fps-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_BITRATE_O="L-mcu_config_builder_set_output_tiny_video_bitrate-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RENDER_MODE_O="L-mcu_config_builder_set_output_video_render_mode-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_AUDIO_BITRATE_O="L-mcu_config_builder_set_output_audio_bitrate-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_COLOR_O="L-mcu_config_builder_set_output_background_color-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O="L-mcu_config_builder_add_output_background_picture-O",e.L_MCU_CONFIG_BUILDER_REMOVE_OUTPUT_BACKGROUND_PICTURE_O="L-mcu_config_builder_remove_output_background_picture-O",e.L_MCU_CONFIG_BUILDER_CLEAR_OUTPUT_BACKGROUND_PICTURE_O="L-mcu_config_builder_clear_output_background_picture-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O="L-mcu_config_builder_set_output_background_picture-fill-mode-O",e.L_MCU_CONFIG_BUILDER_ADD_PUBLISH_STREAM_URLS_O="L-mcu_config_builder_add_publish_stream_urls-O",e.L_MCU_CONFIG_BUILDER_REMOVE_PUBLISH_STREAM_URLS_O="L-mcu_config_builder_remove_publish_stream_urls-O",e.L_MCU_CONFIG_BUILDER_CLEAR_PUBLISH_STREAM_URLS_O="L-mcu_config_builder_clear_publish_stream_urls-O",e.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O="L-mcu_config_builder_add_customize_layout_video-O",e.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O="L-mcu_config_builder_remove_customize_layout_video-O",e.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_LAYOUT_VIDEO_O="L-mcu_config_builder_clear_customize_layout_video-O",e.L_MCU_CONFIG_BUILDER_SET_CUSTOMIZE_INPUT_AUDIO_O="L-mcu_config_builder_set_customize_input_audio-O",e.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O="L-mcu_config_builder_add_customize_input_audio-O",e.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O="L-mcu_config_builder_remove_customize_input_audio-O",e.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_INPUT_AUDIO_O="L-mcu_config_builder_clear_customize_input_audio-O",e.L_MCU_CONFIG_BUILDER_RESET_O="L-mcu_config_builder_reset-O",e.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O="L-mcu_config_builder_add_single_water_mark-O",e.L_MCU_CONFIG_BUILDER_REMOVE_SINGLE_WATER_MARK_O="L-mcu_config_builder_remove_single_water_mark-O",e.L_MCU_CONFIG_BUILDER_CLEAR_SINGLE_WATER_MARK_O="L-mcu_config_builder_clear_single_water_mark-O",e.L_MEDIA_SERVICE_SET_MCU_CONFIG_T="L-media_service_set_mcu_config-T",e.L_MEDIA_SERVICE_SET_MCU_CONFIG_R="L-media_service_set_mcu_config-R",e.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_T="L-media_service_get_cnd_resource_info-T",e.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_R="L-media_service_get_cnd_resource_info-R",e.L_MEDIA_SERVICE_MSLIST_CHANGE_O="L-media_service_msList_change-O",e.L_MEDIA_SERVICE_PARSE_NAVI_CALLVOIP_INFO_O="L-media_service_parse_navi_callvoip_info-O",e.L_MEDIA_SERVICE_REQUEST_T="L-media_service_request-T",e.L_MEDIA_SERVICE_REQUEST_R="L-media_service_request-R",e.L_LOCAL_TRACK_DESTROY_O="L-loacl_track_destroy-O",e.L_LOCAL_TRACK_SET_BITRATE_O="L-loacl_track_set_bitrate-O",e.L_LOCAL_TRACK_SET_LOCAL_MUTED_O="L-loacl_track_set_local_muted-O",e.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_T="L-loacl_track_set_local_muted_spread-T",e.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_R="L-loacl_track_set_local_muted_spread-R",e.L_TRACK_PLAY_O="L-track_play-O",e.L_TRACK_PLAY_E="L-track_play-E",e.L_TRACK_LOAD_START_O="L-track_load_start-O",e.L_TRACK_DURATION_CHANGE_O="L-track_duration_change-O",e.L_TRACK_LOADED_META_DATA_O="L-track_loaded_meta_data-O",e.L_TRACK_LOADED_DATA_O="L-track_loaded_data-O",e.L_TRACK_ABORT_O="L-track_abort-O",e.L_TRACK_VOLUME_CHANGE_O="L-track_volume_change-O",e.L_TRACK_CANPLAY_O="L-track_canplay-O",e.L_ABSTRACT_STAT_PARSER_FORMAT_RTC_STATE_REPORT_O="L-abstract_stat_parser_format_rtc_state_report-O",e.L_A_SDP_STRATEGY_SET_SDP_SEMANTICS_O="L-a_sdp_strategy_set_sdp_semantics-O",e.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O="L-a_sdp_strategy_set_remote_answer-O",e.L_RTC_PEER_CONNECTION_ADD_LOCAL_TRACK_O="L-rtc_peer_connection_add_local_track-O",e.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_S="L-rtc_peer_connection_ice_connection_state-S",e.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_REPORT_R="L-rtc_peer_connection_ice_connection_state_report-R",e.L_RTC_PEER_CONNECTION_CONNECTION_STATE_S="L-rtc_peer_connection_connection_state-S",e.L_RTC_PEER_CONNECTION_SET_BITRATE_O="L-rtc_peer_connection_set_bitrate-O",e.L_RTC_PEER_CONNECTION_CREATE_OFFER_O="L-rtc_peer_connection_create_offer-O",e.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_BY_ID_O="L-rtc_peer_connection_remove_local_track_by_id-O",e.L_RTC_PEER_CONNECTION_REMOVE_ALL_LOCAL_TRACK_O="L-rtc_peer_connection_remove_all_local_track-O",e.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_O="L-rtc_peer_connection_remove_local_track-O",e.L_RTC_PEER_CONNECTION_DESTROY_O="L-rtc_peer_connection_destroy-O",e.L_RTC_SET_RECOMMEND_BITRATE_O="L_rtc_set_recommend_bitrate_O",e.L_RTC_3ANOISE_NODE_O="L_RTC_AAAnoiseNode_O",e.L_RTC_3ANOISE_NODE_E="L_RTC_AAAnoiseNode_E",e.L_RTC_3ANOISE_NODE_STOP_O="L_RTC_AAAnoiseNode_Stop_O",e.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_T="L_rtc_client_join_cross_rtc_room_T",e.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_R="L_rtc_client_join_cross_rtc_room_R",e.L_QS_JOIN_ROOM_S="RTC-joinRoomRtc-S",e.L_QS_SUBSCRIBE_S="RTC-subscribe-S",e.L_QS_UNSUBSCRIBE_S="RTC-unsubscribe-S",e.L_QS_PUBLISH_S="RTC-publishRtc-S",e.L_QS_UNPUBLISH_S="RTC-unpublishRtc-S",e.L_QS_ICE_STATUS_S="RTC-iceStatus-S",e.L_QS_KICKED_S="RTC-forcedOffline-S",e.L_QS_PUB_ICE_STATUS_S="RTC-pubIceConnected-S",e.L_QS_SUB_ICE_STATUS_S="RTC-subIceConnected-S",e.L_QS_RECV_PUB_MSG_S="RTC-recvPubMsg-S",e.L_SET_ENCODER_PREFERENCES_S="RTC-set_Encoder_Preferences-S",e.L_RTCNTF_PULL_ROOM_STATUS_O="L-rtcntf_pull_room_status-O",e.L_RTCPING_PULL_ROOM_STATUS_O="L-rtcping_pull_room_status-O",e.L_PULL_ROOM_STATUS_T="L-pull_room_status-T",e.L_PULL_ROOM_STATUS_R="L-pull_room_status-R",e.L_OLD_DAILY_RECORD_O="L-old_daily_record-O",e.L_REMOTE_USER_JOINED_RESOURCES_O="L-remote_user_joined_resources-O",e.L_REMOTE_USER_STATE_HANDLE_O="L-remote_user_state_handle-O",e.L_HTTP_POLARIS_REPORT_FAIL_O="L-http_polaris_report_fail-O",e.L_UPDATE_SUBSCRIBELIST_COMMAND_T="L-update_subscribeList_command-T",e.L_UPDATE_SUBSCRIBELIST_COMMAND_P="L-update_subscribeList_command-P",e.L_UPDATE_SUBSCRIBELIST_COMMAND_R="L-update_subscribeList_command-R",e.L_RTC_CLIENT_NAVI_CHANGE_O="L-rtc_client_navi_change-O",e.L_UNPUBLISH_PREV_COMMAND_T="L-unpublish_prev_command-T",e.L_UNPUBLISH_PREV_COMMAND_R="L-unpublish_prev_command-R",e.L_RETRY_EXCHANGE_COMMAND_T="L-retry_exchange_command-T",e.L_RETRY_EXCHANGE_SPREAD_T="L-retry_exchange_spread-T",e.L_RETRY_EXCHANGE_SPREAD_R="L-retry_exchange_spread-R",e.L_PARSE_USERSTATE_COMMAND_R="L-parse_userstate_command-R",e.L_RESUB_REPUB_RES_R="L-resub_repub_res-R",e.L_PARSE_ROOMDATA_URIS_R="L-parse_roomdata_uris-R",e.L_SET_AUDIO_CONSTRAINTS_O="L-set_audio_constraints-O",e.L_FUNCTION_IS_UNAVAILABLE="L-function_is_unavailable",e.L_CLEAR_UNSUBSCRIBE_LIST_O="L-clear_unsubscribe_list-O",e.L_INVOKER_PUSH_O="L-invoker_push-O",e.L_INVOKER_EXECUTE_T="L-invoker_execute-T",e.L_INVOKER_EXECUTE_R="L-invoker_execute-R",e.L_INVOKER_DESTROY_O="L-invoker_destroy-R"}(f||(f={})),function(e){e.FAILED="fail",e.SUCCESSED="success",e.TIMEOUT="timeout",e.INFO="info"}(C||(C={}));let O=!0,L=!0;function N(e,t,i){const r=e.match(t);return r&&r.length>=i&&parseInt(r[i],10)}function A(e,t,i){if(!e.RTCPeerConnection)return;const r=e.RTCPeerConnection.prototype,n=r.addEventListener;r.addEventListener=function(e,r){if(e!==t)return n.apply(this,arguments);const o=e=>{const t=i(e);t&&(r.handleEvent?r.handleEvent(t):r(t))};return this._eventMap=this._eventMap||{},this._eventMap[t]||(this._eventMap[t]=new Map),this._eventMap[t].set(r,o),n.apply(this,[e,o])};const o=r.removeEventListener;r.removeEventListener=function(e,i){if(e!==t||!this._eventMap||!this._eventMap[t])return o.apply(this,arguments);if(!this._eventMap[t].has(i))return o.apply(this,arguments);const r=this._eventMap[t].get(i);return this._eventMap[t].delete(i),0===this._eventMap[t].size&&delete this._eventMap[t],0===Object.keys(this._eventMap).length&&delete this._eventMap,o.apply(this,[e,r])},Object.defineProperty(r,"on"+t,{get(){return this["_on"+t]},set(e){this["_on"+t]&&(this.removeEventListener(t,this["_on"+t]),delete this["_on"+t]),e&&this.addEventListener(t,this["_on"+t]=e)},enumerable:!0,configurable:!0})}function y(e){return"boolean"!=typeof e?new Error("Argument type: "+typeof e+". Please use a boolean."):(O=e,e?"adapter.js logging disabled":"adapter.js logging enabled")}function k(e){return"boolean"!=typeof e?new Error("Argument type: "+typeof e+". Please use a boolean."):(L=!e,"adapter.js deprecation warnings "+(e?"disabled":"enabled"))}function D(){if("object"==typeof window){if(O)return;"undefined"!=typeof console&&"function"==typeof console.log&&console.log.apply(console,arguments)}}function b(e,t){L&&console.warn(e+" is deprecated, please use "+t+" instead.")}function U(e){return"[object Object]"===Object.prototype.toString.call(e)}function P(e){return U(e)?Object.keys(e).reduce((function(t,i){const r=U(e[i]),n=r?P(e[i]):e[i],o=r&&!Object.keys(n).length;return void 0===n||o?t:Object.assign(t,{[i]:n})}),{}):e}function M(e,t,i){t&&!i.has(t.id)&&(i.set(t.id,t),Object.keys(t).forEach((r=>{r.endsWith("Id")?M(e,e.get(t[r]),i):r.endsWith("Ids")&&t[r].forEach((t=>{M(e,e.get(t),i)}))})))}function x(e,t,i){const r=i?"outbound-rtp":"inbound-rtp",n=new Map;if(null===t)return n;const o=[];return e.forEach((e=>{"track"===e.type&&e.trackIdentifier===t.id&&o.push(e)})),o.forEach((t=>{e.forEach((i=>{i.type===r&&i.trackId===t.id&&M(e,i,n)}))})),n}const w=D;function B(e,t){const i=e&&e.navigator;if(!i.mediaDevices)return;const r=function(e){if("object"!=typeof e||e.mandatory||e.optional)return e;const t={};return Object.keys(e).forEach((i=>{if("require"===i||"advanced"===i||"mediaSource"===i)return;const r="object"==typeof e[i]?e[i]:{ideal:e[i]};void 0!==r.exact&&"number"==typeof r.exact&&(r.min=r.max=r.exact);const n=function(e,t){return e?e+t.charAt(0).toUpperCase()+t.slice(1):"deviceId"===t?"sourceId":t};if(void 0!==r.ideal){t.optional=t.optional||[];let e={};"number"==typeof r.ideal?(e[n("min",i)]=r.ideal,t.optional.push(e),e={},e[n("max",i)]=r.ideal,t.optional.push(e)):(e[n("",i)]=r.ideal,t.optional.push(e))}void 0!==r.exact&&"number"!=typeof r.exact?(t.mandatory=t.mandatory||{},t.mandatory[n("",i)]=r.exact):["min","max"].forEach((e=>{void 0!==r[e]&&(t.mandatory=t.mandatory||{},t.mandatory[n(e,i)]=r[e])}))})),e.advanced&&(t.optional=(t.optional||[]).concat(e.advanced)),t},n=function(e,n){if(t.version>=61)return n(e);if((e=JSON.parse(JSON.stringify(e)))&&"object"==typeof e.audio){const t=function(e,t,i){t in e&&!(i in e)&&(e[i]=e[t],delete e[t])};t((e=JSON.parse(JSON.stringify(e))).audio,"autoGainControl","googAutoGainControl"),t(e.audio,"noiseSuppression","googNoiseSuppression"),e.audio=r(e.audio)}if(e&&"object"==typeof e.video){let o=e.video.facingMode;o=o&&("object"==typeof o?o:{ideal:o});const s=t.version<66;if(o&&("user"===o.exact||"environment"===o.exact||"user"===o.ideal||"environment"===o.ideal)&&(!i.mediaDevices.getSupportedConstraints||!i.mediaDevices.getSupportedConstraints().facingMode||s)){let t;if(delete e.video.facingMode,"environment"===o.exact||"environment"===o.ideal?t=["back","rear"]:"user"!==o.exact&&"user"!==o.ideal||(t=["front"]),t)return i.mediaDevices.enumerateDevices().then((i=>{let s=(i=i.filter((e=>"videoinput"===e.kind))).find((e=>t.some((t=>e.label.toLowerCase().includes(t)))));return!s&&i.length&&t.includes("back")&&(s=i[i.length-1]),s&&(e.video.deviceId=o.exact?{exact:s.deviceId}:{ideal:s.deviceId}),e.video=r(e.video),w("chrome: "+JSON.stringify(e)),n(e)}))}e.video=r(e.video)}return w("chrome: "+JSON.stringify(e)),n(e)},o=function(e){return t.version>=64?e:{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}}};if(i.getUserMedia=function(e,t,r){n(e,(e=>{i.webkitGetUserMedia(e,t,(e=>{r&&r(o(e))}))}))}.bind(i),i.mediaDevices.getUserMedia){const e=i.mediaDevices.getUserMedia.bind(i.mediaDevices);i.mediaDevices.getUserMedia=function(t){return n(t,(t=>e(t).then((e=>{if(t.audio&&!e.getAudioTracks().length||t.video&&!e.getVideoTracks().length)throw e.getTracks().forEach((e=>{e.stop()})),new DOMException("","NotFoundError");return e}),(e=>Promise.reject(o(e))))))}}}function V(e){e.MediaStream=e.MediaStream||e.webkitMediaStream}function F(e){if("object"==typeof e&&e.RTCPeerConnection&&!("ontrack"in e.RTCPeerConnection.prototype)){Object.defineProperty(e.RTCPeerConnection.prototype,"ontrack",{get(){return this._ontrack},set(e){this._ontrack&&this.removeEventListener("track",this._ontrack),this.addEventListener("track",this._ontrack=e)},enumerable:!0,configurable:!0});const t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=t=>{t.stream.addEventListener("addtrack",(i=>{let r;r=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find((e=>e.track&&e.track.id===i.track.id)):{track:i.track};const n=new Event("track");n.track=i.track,n.receiver=r,n.transceiver={receiver:r},n.streams=[t.stream],this.dispatchEvent(n)})),t.stream.getTracks().forEach((i=>{let r;r=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find((e=>e.track&&e.track.id===i.id)):{track:i};const n=new Event("track");n.track=i,n.receiver=r,n.transceiver={receiver:r},n.streams=[t.stream],this.dispatchEvent(n)}))},this.addEventListener("addstream",this._ontrackpoly)),t.apply(this,arguments)}}else A(e,"track",(e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e)))}function J(e){if("object"==typeof e&&e.RTCPeerConnection&&!("getSenders"in e.RTCPeerConnection.prototype)&&"createDTMFSender"in e.RTCPeerConnection.prototype){const t=function(e,t){return{track:t,get dtmf(){return void 0===this._dtmf&&("audio"===t.kind?this._dtmf=e.createDTMFSender(t):this._dtmf=null),this._dtmf},_pc:e}};if(!e.RTCPeerConnection.prototype.getSenders){e.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};const i=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,r){let n=i.apply(this,arguments);return n||(n=t(this,e),this._senders.push(n)),n};const r=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){r.apply(this,arguments);const t=this._senders.indexOf(e);-1!==t&&this._senders.splice(t,1)}}const i=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){this._senders=this._senders||[],i.apply(this,[e]),e.getTracks().forEach((e=>{this._senders.push(t(this,e))}))};const r=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){this._senders=this._senders||[],r.apply(this,[e]),e.getTracks().forEach((e=>{const t=this._senders.find((t=>t.track===e));t&&this._senders.splice(this._senders.indexOf(t),1)}))}}else if("object"==typeof e&&e.RTCPeerConnection&&"getSenders"in e.RTCPeerConnection.prototype&&"createDTMFSender"in e.RTCPeerConnection.prototype&&e.RTCRtpSender&&!("dtmf"in e.RTCRtpSender.prototype)){const t=e.RTCPeerConnection.prototype.getSenders;e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e},Object.defineProperty(e.RTCRtpSender.prototype,"dtmf",{get(){return void 0===this._dtmf&&("audio"===this.track.kind?this._dtmf=this._pc.createDTMFSender(this.track):this._dtmf=null),this._dtmf}})}}function G(e){if(!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){const[e,i,r]=arguments;if(arguments.length>0&&"function"==typeof e)return t.apply(this,arguments);if(0===t.length&&(0===arguments.length||"function"!=typeof e))return t.apply(this,[]);const n=function(e){const t={};return e.result().forEach((e=>{const i={id:e.id,timestamp:e.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[e.type]||e.type};e.names().forEach((t=>{i[t]=e.stat(t)})),t[i.id]=i})),t},o=function(e){return new Map(Object.keys(e).map((t=>[t,e[t]])))};if(arguments.length>=2){const r=function(e){i(o(n(e)))};return t.apply(this,[r,e])}return new Promise(((e,i)=>{t.apply(this,[function(t){e(o(n(t)))},i])})).then(i,r)}}function H(e){if(!("object"==typeof e&&e.RTCPeerConnection&&e.RTCRtpSender&&e.RTCRtpReceiver))return;if(!("getStats"in e.RTCRtpSender.prototype)){const t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e});const i=e.RTCPeerConnection.prototype.addTrack;i&&(e.RTCPeerConnection.prototype.addTrack=function(){const e=i.apply(this,arguments);return e._pc=this,e}),e.RTCRtpSender.prototype.getStats=function(){const e=this;return this._pc.getStats().then((t=>x(t,e.track,!0)))}}if(!("getStats"in e.RTCRtpReceiver.prototype)){const t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e}),A(e,"track",(e=>(e.receiver._pc=e.srcElement,e))),e.RTCRtpReceiver.prototype.getStats=function(){const e=this;return this._pc.getStats().then((t=>x(t,e.track,!1)))}}if(!("getStats"in e.RTCRtpSender.prototype)||!("getStats"in e.RTCRtpReceiver.prototype))return;const t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof e.MediaStreamTrack){const e=arguments[0];let t,i,r;return this.getSenders().forEach((i=>{i.track===e&&(t?r=!0:t=i)})),this.getReceivers().forEach((t=>(t.track===e&&(i?r=!0:i=t),t.track===e))),r||t&&i?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):t?t.getStats():i?i.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return t.apply(this,arguments)}}function K(e){e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map((e=>this._shimmedLocalStreams[e][0]))};const t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,i){if(!i)return t.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};const r=t.apply(this,arguments);return this._shimmedLocalStreams[i.id]?-1===this._shimmedLocalStreams[i.id].indexOf(r)&&this._shimmedLocalStreams[i.id].push(r):this._shimmedLocalStreams[i.id]=[i,r],r};const i=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){this._shimmedLocalStreams=this._shimmedLocalStreams||{},e.getTracks().forEach((e=>{if(this.getSenders().find((t=>t.track===e)))throw new DOMException("Track already exists.","InvalidAccessError")}));const t=this.getSenders();i.apply(this,arguments);const r=this.getSenders().filter((e=>-1===t.indexOf(e)));this._shimmedLocalStreams[e.id]=[e].concat(r)};const r=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[e.id],r.apply(this,arguments)};const n=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},e&&Object.keys(this._shimmedLocalStreams).forEach((t=>{const i=this._shimmedLocalStreams[t].indexOf(e);-1!==i&&this._shimmedLocalStreams[t].splice(i,1),1===this._shimmedLocalStreams[t].length&&delete this._shimmedLocalStreams[t]})),n.apply(this,arguments)}}function j(e,t){if(!e.RTCPeerConnection)return;if(e.RTCPeerConnection.prototype.addTrack&&t.version>=65)return K(e);const i=e.RTCPeerConnection.prototype.getLocalStreams;e.RTCPeerConnection.prototype.getLocalStreams=function(){const e=i.apply(this);return this._reverseStreams=this._reverseStreams||{},e.map((e=>this._reverseStreams[e.id]))};const r=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(t){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},t.getTracks().forEach((e=>{if(this.getSenders().find((t=>t.track===e)))throw new DOMException("Track already exists.","InvalidAccessError")})),!this._reverseStreams[t.id]){const i=new e.MediaStream(t.getTracks());this._streams[t.id]=i,this._reverseStreams[i.id]=t,t=i}r.apply(this,[t])};const n=e.RTCPeerConnection.prototype.removeStream;function o(e,t){let i=t.sdp;return Object.keys(e._reverseStreams||[]).forEach((t=>{const r=e._reverseStreams[t],n=e._streams[r.id];i=i.replace(new RegExp(n.id,"g"),r.id)})),new RTCSessionDescription({type:t.type,sdp:i})}function s(e,t){let i=t.sdp;return Object.keys(e._reverseStreams||[]).forEach((t=>{const r=e._reverseStreams[t],n=e._streams[r.id];i=i.replace(new RegExp(r.id,"g"),n.id)})),new RTCSessionDescription({type:t.type,sdp:i})}e.RTCPeerConnection.prototype.removeStream=function(e){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},n.apply(this,[this._streams[e.id]||e]),delete this._reverseStreams[this._streams[e.id]?this._streams[e.id].id:e.id],delete this._streams[e.id]},e.RTCPeerConnection.prototype.addTrack=function(t,i){if("closed"===this.signalingState)throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");const r=[].slice.call(arguments,1);if(1!==r.length||!r[0].getTracks().find((e=>e===t)))throw new DOMException("The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.","NotSupportedError");const n=this.getSenders().find((e=>e.track===t));if(n)throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};const o=this._streams[i.id];if(o)o.addTrack(t),Promise.resolve().then((()=>{this.dispatchEvent(new Event("negotiationneeded"))}));else{const r=new e.MediaStream([t]);this._streams[i.id]=r,this._reverseStreams[r.id]=i,this.addStream(r)}return this.getSenders().find((e=>e.track===t))},["createOffer","createAnswer"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],r={[t](){const e=arguments;return arguments.length&&"function"==typeof arguments[0]?i.apply(this,[t=>{const i=o(this,t);e[0].apply(null,[i])},t=>{e[1]&&e[1].apply(null,t)},arguments[2]]):i.apply(this,arguments).then((e=>o(this,e)))}};e.RTCPeerConnection.prototype[t]=r[t]}));const a=e.RTCPeerConnection.prototype.setLocalDescription;e.RTCPeerConnection.prototype.setLocalDescription=function(){return arguments.length&&arguments[0].type?(arguments[0]=s(this,arguments[0]),a.apply(this,arguments)):a.apply(this,arguments)};const c=Object.getOwnPropertyDescriptor(e.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(e.RTCPeerConnection.prototype,"localDescription",{get(){const e=c.get.apply(this);return""===e.type?e:o(this,e)}}),e.RTCPeerConnection.prototype.removeTrack=function(e){if("closed"===this.signalingState)throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");if(!e._pc)throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.","TypeError");if(!(e._pc===this))throw new DOMException("Sender was not created by this connection.","InvalidAccessError");let t;this._streams=this._streams||{},Object.keys(this._streams).forEach((i=>{this._streams[i].getTracks().find((t=>e.track===t))&&(t=this._streams[i])})),t&&(1===t.getTracks().length?this.removeStream(this._reverseStreams[t.id]):t.removeTrack(e.track),this.dispatchEvent(new Event("negotiationneeded")))}}function $(e,t){!e.RTCPeerConnection&&e.webkitRTCPeerConnection&&(e.RTCPeerConnection=e.webkitRTCPeerConnection),e.RTCPeerConnection&&t.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],r={[t](){return arguments[0]=new("addIceCandidate"===t?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),i.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=r[t]}))}function W(e,t){A(e,"negotiationneeded",(e=>{const i=e.target;if(!(t.version<72||i.getConfiguration&&"plan-b"===i.getConfiguration().sdpSemantics)||"stable"===i.signalingState)return e}))}var Y=Object.freeze({__proto__:null,shimMediaStream:V,shimOnTrack:F,shimGetSendersWithDtmf:J,shimGetStats:G,shimSenderReceiverGetStats:H,shimAddTrackRemoveTrackWithNative:K,shimAddTrackRemoveTrack:j,shimPeerConnection:$,fixNegotiationNeeded:W,shimGetUserMedia:B,shimGetDisplayMedia:function(e,t){e.navigator.mediaDevices&&"getDisplayMedia"in e.navigator.mediaDevices||e.navigator.mediaDevices&&("function"==typeof t?e.navigator.mediaDevices.getDisplayMedia=function(i){return t(i).then((t=>{const r=i.video&&i.video.width,n=i.video&&i.video.height,o=i.video&&i.video.frameRate;return i.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:t,maxFrameRate:o||3}},r&&(i.video.mandatory.maxWidth=r),n&&(i.video.mandatory.maxHeight=n),e.navigator.mediaDevices.getUserMedia(i)}))}:console.error("shimGetDisplayMedia: getSourceId argument is not a function"))}});var q,z,Q=(q=function(e){var t={generateIdentifier:function(){return Math.random().toString(36).substr(2,10)}};t.localCName=t.generateIdentifier(),t.splitLines=function(e){return e.trim().split("\n").map((function(e){return e.trim()}))},t.splitSections=function(e){return e.split("\nm=").map((function(e,t){return(t>0?"m="+e:e).trim()+"\r\n"}))},t.getDescription=function(e){var i=t.splitSections(e);return i&&i[0]},t.getMediaSections=function(e){var i=t.splitSections(e);return i.shift(),i},t.matchPrefix=function(e,i){return t.splitLines(e).filter((function(e){return 0===e.indexOf(i)}))},t.parseCandidate=function(e){for(var t,i={foundation:(t=0===e.indexOf("a=candidate:")?e.substring(12).split(" "):e.substring(10).split(" "))[0],component:parseInt(t[1],10),protocol:t[2].toLowerCase(),priority:parseInt(t[3],10),ip:t[4],address:t[4],port:parseInt(t[5],10),type:t[7]},r=8;r<t.length;r+=2)switch(t[r]){case"raddr":i.relatedAddress=t[r+1];break;case"rport":i.relatedPort=parseInt(t[r+1],10);break;case"tcptype":i.tcpType=t[r+1];break;case"ufrag":i.ufrag=t[r+1],i.usernameFragment=t[r+1];break;default:i[t[r]]=t[r+1]}return i},t.writeCandidate=function(e){var t=[];t.push(e.foundation),t.push(e.component),t.push(e.protocol.toUpperCase()),t.push(e.priority),t.push(e.address||e.ip),t.push(e.port);var i=e.type;return t.push("typ"),t.push(i),"host"!==i&&e.relatedAddress&&e.relatedPort&&(t.push("raddr"),t.push(e.relatedAddress),t.push("rport"),t.push(e.relatedPort)),e.tcpType&&"tcp"===e.protocol.toLowerCase()&&(t.push("tcptype"),t.push(e.tcpType)),(e.usernameFragment||e.ufrag)&&(t.push("ufrag"),t.push(e.usernameFragment||e.ufrag)),"candidate:"+t.join(" ")},t.parseIceOptions=function(e){return e.substr(14).split(" ")},t.parseRtpMap=function(e){var t=e.substr(9).split(" "),i={payloadType:parseInt(t.shift(),10)};return t=t[0].split("/"),i.name=t[0],i.clockRate=parseInt(t[1],10),i.channels=3===t.length?parseInt(t[2],10):1,i.numChannels=i.channels,i},t.writeRtpMap=function(e){var t=e.payloadType;void 0!==e.preferredPayloadType&&(t=e.preferredPayloadType);var i=e.channels||e.numChannels||1;return"a=rtpmap:"+t+" "+e.name+"/"+e.clockRate+(1!==i?"/"+i:"")+"\r\n"},t.parseExtmap=function(e){var t=e.substr(9).split(" ");return{id:parseInt(t[0],10),direction:t[0].indexOf("/")>0?t[0].split("/")[1]:"sendrecv",uri:t[1]}},t.writeExtmap=function(e){return"a=extmap:"+(e.id||e.preferredId)+(e.direction&&"sendrecv"!==e.direction?"/"+e.direction:"")+" "+e.uri+"\r\n"},t.parseFmtp=function(e){for(var t,i={},r=e.substr(e.indexOf(" ")+1).split(";"),n=0;n<r.length;n++)i[(t=r[n].trim().split("="))[0].trim()]=t[1];return i},t.writeFmtp=function(e){var t="",i=e.payloadType;if(void 0!==e.preferredPayloadType&&(i=e.preferredPayloadType),e.parameters&&Object.keys(e.parameters).length){var r=[];Object.keys(e.parameters).forEach((function(t){e.parameters[t]?r.push(t+"="+e.parameters[t]):r.push(t)})),t+="a=fmtp:"+i+" "+r.join(";")+"\r\n"}return t},t.parseRtcpFb=function(e){var t=e.substr(e.indexOf(" ")+1).split(" ");return{type:t.shift(),parameter:t.join(" ")}},t.writeRtcpFb=function(e){var t="",i=e.payloadType;return void 0!==e.preferredPayloadType&&(i=e.preferredPayloadType),e.rtcpFeedback&&e.rtcpFeedback.length&&e.rtcpFeedback.forEach((function(e){t+="a=rtcp-fb:"+i+" "+e.type+(e.parameter&&e.parameter.length?" "+e.parameter:"")+"\r\n"})),t},t.parseSsrcMedia=function(e){var t=e.indexOf(" "),i={ssrc:parseInt(e.substr(7,t-7),10)},r=e.indexOf(":",t);return r>-1?(i.attribute=e.substr(t+1,r-t-1),i.value=e.substr(r+1)):i.attribute=e.substr(t+1),i},t.parseSsrcGroup=function(e){var t=e.substr(13).split(" ");return{semantics:t.shift(),ssrcs:t.map((function(e){return parseInt(e,10)}))}},t.getMid=function(e){var i=t.matchPrefix(e,"a=mid:")[0];if(i)return i.substr(6)},t.parseFingerprint=function(e){var t=e.substr(14).split(" ");return{algorithm:t[0].toLowerCase(),value:t[1]}},t.getDtlsParameters=function(e,i){return{role:"auto",fingerprints:t.matchPrefix(e+i,"a=fingerprint:").map(t.parseFingerprint)}},t.writeDtlsParameters=function(e,t){var i="a=setup:"+t+"\r\n";return e.fingerprints.forEach((function(e){i+="a=fingerprint:"+e.algorithm+" "+e.value+"\r\n"})),i},t.parseCryptoLine=function(e){var t=e.substr(9).split(" ");return{tag:parseInt(t[0],10),cryptoSuite:t[1],keyParams:t[2],sessionParams:t.slice(3)}},t.writeCryptoLine=function(e){return"a=crypto:"+e.tag+" "+e.cryptoSuite+" "+("object"==typeof e.keyParams?t.writeCryptoKeyParams(e.keyParams):e.keyParams)+(e.sessionParams?" "+e.sessionParams.join(" "):"")+"\r\n"},t.parseCryptoKeyParams=function(e){if(0!==e.indexOf("inline:"))return null;var t=e.substr(7).split("|");return{keyMethod:"inline",keySalt:t[0],lifeTime:t[1],mkiValue:t[2]?t[2].split(":")[0]:void 0,mkiLength:t[2]?t[2].split(":")[1]:void 0}},t.writeCryptoKeyParams=function(e){return e.keyMethod+":"+e.keySalt+(e.lifeTime?"|"+e.lifeTime:"")+(e.mkiValue&&e.mkiLength?"|"+e.mkiValue+":"+e.mkiLength:"")},t.getCryptoParameters=function(e,i){return t.matchPrefix(e+i,"a=crypto:").map(t.parseCryptoLine)},t.getIceParameters=function(e,i){var r=t.matchPrefix(e+i,"a=ice-ufrag:")[0],n=t.matchPrefix(e+i,"a=ice-pwd:")[0];return r&&n?{usernameFragment:r.substr(12),password:n.substr(10)}:null},t.writeIceParameters=function(e){return"a=ice-ufrag:"+e.usernameFragment+"\r\na=ice-pwd:"+e.password+"\r\n"},t.parseRtpParameters=function(e){for(var i={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},r=t.splitLines(e)[0].split(" "),n=3;n<r.length;n++){var o=r[n],s=t.matchPrefix(e,"a=rtpmap:"+o+" ")[0];if(s){var a=t.parseRtpMap(s),c=t.matchPrefix(e,"a=fmtp:"+o+" ");switch(a.parameters=c.length?t.parseFmtp(c[0]):{},a.rtcpFeedback=t.matchPrefix(e,"a=rtcp-fb:"+o+" ").map(t.parseRtcpFb),i.codecs.push(a),a.name.toUpperCase()){case"RED":case"ULPFEC":i.fecMechanisms.push(a.name.toUpperCase())}}}return t.matchPrefix(e,"a=extmap:").forEach((function(e){i.headerExtensions.push(t.parseExtmap(e))})),i},t.writeRtpDescription=function(e,i){var r="";r+="m="+e+" ",r+=i.codecs.length>0?"9":"0",r+=" UDP/TLS/RTP/SAVPF ",r+=i.codecs.map((function(e){return void 0!==e.preferredPayloadType?e.preferredPayloadType:e.payloadType})).join(" ")+"\r\n",r+="c=IN IP4 0.0.0.0\r\n",r+="a=rtcp:9 IN IP4 0.0.0.0\r\n",i.codecs.forEach((function(e){r+=t.writeRtpMap(e),r+=t.writeFmtp(e),r+=t.writeRtcpFb(e)}));var n=0;return i.codecs.forEach((function(e){e.maxptime>n&&(n=e.maxptime)})),n>0&&(r+="a=maxptime:"+n+"\r\n"),r+="a=rtcp-mux\r\n",i.headerExtensions&&i.headerExtensions.forEach((function(e){r+=t.writeExtmap(e)})),r},t.parseRtpEncodingParameters=function(e){var i,r=[],n=t.parseRtpParameters(e),o=-1!==n.fecMechanisms.indexOf("RED"),s=-1!==n.fecMechanisms.indexOf("ULPFEC"),a=t.matchPrefix(e,"a=ssrc:").map((function(e){return t.parseSsrcMedia(e)})).filter((function(e){return"cname"===e.attribute})),c=a.length>0&&a[0].ssrc,d=t.matchPrefix(e,"a=ssrc-group:FID").map((function(e){return e.substr(17).split(" ").map((function(e){return parseInt(e,10)}))}));d.length>0&&d[0].length>1&&d[0][0]===c&&(i=d[0][1]),n.codecs.forEach((function(e){if("RTX"===e.name.toUpperCase()&&e.parameters.apt){var t={ssrc:c,codecPayloadType:parseInt(e.parameters.apt,10)};c&&i&&(t.rtx={ssrc:i}),r.push(t),o&&((t=JSON.parse(JSON.stringify(t))).fec={ssrc:c,mechanism:s?"red+ulpfec":"red"},r.push(t))}})),0===r.length&&c&&r.push({ssrc:c});var _=t.matchPrefix(e,"b=");return _.length&&(_=0===_[0].indexOf("b=TIAS:")?parseInt(_[0].substr(7),10):0===_[0].indexOf("b=AS:")?1e3*parseInt(_[0].substr(5),10)*.95-16e3:void 0,r.forEach((function(e){e.maxBitrate=_}))),r},t.parseRtcpParameters=function(e){var i={},r=t.matchPrefix(e,"a=ssrc:").map((function(e){return t.parseSsrcMedia(e)})).filter((function(e){return"cname"===e.attribute}))[0];r&&(i.cname=r.value,i.ssrc=r.ssrc);var n=t.matchPrefix(e,"a=rtcp-rsize");i.reducedSize=n.length>0,i.compound=0===n.length;var o=t.matchPrefix(e,"a=rtcp-mux");return i.mux=o.length>0,i},t.parseMsid=function(e){var i,r=t.matchPrefix(e,"a=msid:");if(1===r.length)return{stream:(i=r[0].substr(7).split(" "))[0],track:i[1]};var n=t.matchPrefix(e,"a=ssrc:").map((function(e){return t.parseSsrcMedia(e)})).filter((function(e){return"msid"===e.attribute}));return n.length>0?{stream:(i=n[0].value.split(" "))[0],track:i[1]}:void 0},t.parseSctpDescription=function(e){var i,r=t.parseMLine(e),n=t.matchPrefix(e,"a=max-message-size:");n.length>0&&(i=parseInt(n[0].substr(19),10)),isNaN(i)&&(i=65536);var o=t.matchPrefix(e,"a=sctp-port:");if(o.length>0)return{port:parseInt(o[0].substr(12),10),protocol:r.fmt,maxMessageSize:i};if(t.matchPrefix(e,"a=sctpmap:").length>0){var s=t.matchPrefix(e,"a=sctpmap:")[0].substr(10).split(" ");return{port:parseInt(s[0],10),protocol:s[1],maxMessageSize:i}}},t.writeSctpDescription=function(e,t){var i=[];return i="DTLS/SCTP"!==e.protocol?["m="+e.kind+" 9 "+e.protocol+" "+t.protocol+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctp-port:"+t.port+"\r\n"]:["m="+e.kind+" 9 "+e.protocol+" "+t.port+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctpmap:"+t.port+" "+t.protocol+" 65535\r\n"],void 0!==t.maxMessageSize&&i.push("a=max-message-size:"+t.maxMessageSize+"\r\n"),i.join("")},t.generateSessionId=function(){return Math.random().toString().substr(2,21)},t.writeSessionBoilerplate=function(e,i,r){var n=void 0!==i?i:2;return"v=0\r\no="+(r||"thisisadapterortc")+" "+(e||t.generateSessionId())+" "+n+" IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"},t.writeMediaSection=function(e,i,r,n){var o=t.writeRtpDescription(e.kind,i);if(o+=t.writeIceParameters(e.iceGatherer.getLocalParameters()),o+=t.writeDtlsParameters(e.dtlsTransport.getLocalParameters(),"offer"===r?"actpass":"active"),o+="a=mid:"+e.mid+"\r\n",e.direction?o+="a="+e.direction+"\r\n":e.rtpSender&&e.rtpReceiver?o+="a=sendrecv\r\n":e.rtpSender?o+="a=sendonly\r\n":e.rtpReceiver?o+="a=recvonly\r\n":o+="a=inactive\r\n",e.rtpSender){var s="msid:"+n.id+" "+e.rtpSender.track.id+"\r\n";o+="a="+s,o+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" "+s,e.sendEncodingParameters[0].rtx&&(o+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" "+s,o+="a=ssrc-group:FID "+e.sendEncodingParameters[0].ssrc+" "+e.sendEncodingParameters[0].rtx.ssrc+"\r\n")}return o+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" cname:"+t.localCName+"\r\n",e.rtpSender&&e.sendEncodingParameters[0].rtx&&(o+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" cname:"+t.localCName+"\r\n"),o},t.getDirection=function(e,i){for(var r=t.splitLines(e),n=0;n<r.length;n++)switch(r[n]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return r[n].substr(2)}return i?t.getDirection(i):"sendrecv"},t.getKind=function(e){return t.splitLines(e)[0].split(" ")[0].substr(2)},t.isRejected=function(e){return"0"===e.split(" ",2)[1]},t.parseMLine=function(e){var i=t.splitLines(e)[0].substr(2).split(" ");return{kind:i[0],port:parseInt(i[1],10),protocol:i[2],fmt:i.slice(3).join(" ")}},t.parseOLine=function(e){var i=t.matchPrefix(e,"o=")[0].substr(2).split(" ");return{username:i[0],sessionId:i[1],sessionVersion:parseInt(i[2],10),netType:i[3],addressType:i[4],address:i[5]}},t.isValidSDP=function(e){if("string"!=typeof e||0===e.length)return!1;for(var i=t.splitLines(e),r=0;r<i.length;r++)if(i[r].length<2||"="!==i[r].charAt(1))return!1;return!0},e.exports=t},q(z={exports:{}},z.exports),z.exports);function Z(e,t,i,r,n){var o=Q.writeRtpDescription(e.kind,t);if(o+=Q.writeIceParameters(e.iceGatherer.getLocalParameters()),o+=Q.writeDtlsParameters(e.dtlsTransport.getLocalParameters(),"offer"===i?"actpass":n||"active"),o+="a=mid:"+e.mid+"\r\n",e.rtpSender&&e.rtpReceiver?o+="a=sendrecv\r\n":e.rtpSender?o+="a=sendonly\r\n":e.rtpReceiver?o+="a=recvonly\r\n":o+="a=inactive\r\n",e.rtpSender){var s=e.rtpSender._initialTrackId||e.rtpSender.track.id;e.rtpSender._initialTrackId=s;var a="msid:"+(r?r.id:"-")+" "+s+"\r\n";o+="a="+a,o+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" "+a,e.sendEncodingParameters[0].rtx&&(o+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" "+a,o+="a=ssrc-group:FID "+e.sendEncodingParameters[0].ssrc+" "+e.sendEncodingParameters[0].rtx.ssrc+"\r\n")}return o+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" cname:"+Q.localCName+"\r\n",e.rtpSender&&e.sendEncodingParameters[0].rtx&&(o+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" cname:"+Q.localCName+"\r\n"),o}function X(e,t){var i={codecs:[],headerExtensions:[],fecMechanisms:[]},r=function(e,t){e=parseInt(e,10);for(var i=0;i<t.length;i++)if(t[i].payloadType===e||t[i].preferredPayloadType===e)return t[i]},n=function(e,t,i,n){var o=r(e.parameters.apt,i),s=r(t.parameters.apt,n);return o&&s&&o.name.toLowerCase()===s.name.toLowerCase()};return e.codecs.forEach((function(r){for(var o=0;o<t.codecs.length;o++){var s=t.codecs[o];if(r.name.toLowerCase()===s.name.toLowerCase()&&r.clockRate===s.clockRate){if("rtx"===r.name.toLowerCase()&&r.parameters&&s.parameters.apt&&!n(r,s,e.codecs,t.codecs))continue;(s=JSON.parse(JSON.stringify(s))).numChannels=Math.min(r.numChannels,s.numChannels),i.codecs.push(s),s.rtcpFeedback=s.rtcpFeedback.filter((function(e){for(var t=0;t<r.rtcpFeedback.length;t++)if(r.rtcpFeedback[t].type===e.type&&r.rtcpFeedback[t].parameter===e.parameter)return!0;return!1}));break}}})),e.headerExtensions.forEach((function(e){for(var r=0;r<t.headerExtensions.length;r++){var n=t.headerExtensions[r];if(e.uri===n.uri){i.headerExtensions.push(n);break}}})),i}function ee(e,t,i){return-1!=={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"]}}[t][e].indexOf(i)}function te(e,t){var i=e.getRemoteCandidates().find((function(e){return t.foundation===e.foundation&&t.ip===e.ip&&t.port===e.port&&t.priority===e.priority&&t.protocol===e.protocol&&t.type===e.type}));return i||e.addRemoteCandidate(t),!i}function ie(e,t){var i=new Error(t);return i.name=e,i.code={NotSupportedError:9,InvalidStateError:11,InvalidAccessError:15,TypeError:void 0,OperationError:void 0}[e],i}var re=function(e,t){function i(t,i){i.addTrack(t),i.dispatchEvent(new e.MediaStreamTrackEvent("addtrack",{track:t}))}function r(t,i,r,n){var o=new Event("track");o.track=i,o.receiver=r,o.transceiver={receiver:r},o.streams=n,e.setTimeout((function(){t._dispatchEvent("track",o)}))}var n=function(i){var r=this,n=document.createDocumentFragment();if(["addEventListener","removeEventListener","dispatchEvent"].forEach((function(e){r[e]=n[e].bind(n)})),this.canTrickleIceCandidates=null,this.needNegotiation=!1,this.localStreams=[],this.remoteStreams=[],this._localDescription=null,this._remoteDescription=null,this.signalingState="stable",this.iceConnectionState="new",this.connectionState="new",this.iceGatheringState="new",i=JSON.parse(JSON.stringify(i||{})),this.usingBundle="max-bundle"===i.bundlePolicy,"negotiate"===i.rtcpMuxPolicy)throw ie("NotSupportedError","rtcpMuxPolicy 'negotiate' is not supported");switch(i.rtcpMuxPolicy||(i.rtcpMuxPolicy="require"),i.iceTransportPolicy){case"all":case"relay":break;default:i.iceTransportPolicy="all"}switch(i.bundlePolicy){case"balanced":case"max-compat":case"max-bundle":break;default:i.bundlePolicy="balanced"}if(i.iceServers=function(e,t){var i=!1;return(e=JSON.parse(JSON.stringify(e))).filter((function(e){if(e&&(e.urls||e.url)){var r=e.urls||e.url;e.url&&!e.urls&&console.warn("RTCIceServer.url is deprecated! Use urls instead.");var n="string"==typeof r;return n&&(r=[r]),r=r.filter((function(e){return 0!==e.indexOf("turn:")||-1===e.indexOf("transport=udp")||-1!==e.indexOf("turn:[")||i?0===e.indexOf("stun:")&&t>=14393&&-1===e.indexOf("?transport=udp"):(i=!0,!0)})),delete e.url,e.urls=n?r[0]:r,!!r.length}}))}(i.iceServers||[],t),this._iceGatherers=[],i.iceCandidatePoolSize)for(var o=i.iceCandidatePoolSize;o>0;o--)this._iceGatherers.push(new e.RTCIceGatherer({iceServers:i.iceServers,gatherPolicy:i.iceTransportPolicy}));else i.iceCandidatePoolSize=0;this._config=i,this.transceivers=[],this._sdpSessionId=Q.generateSessionId(),this._sdpSessionVersion=0,this._dtlsRole=void 0,this._isClosed=!1};Object.defineProperty(n.prototype,"localDescription",{configurable:!0,get:function(){return this._localDescription}}),Object.defineProperty(n.prototype,"remoteDescription",{configurable:!0,get:function(){return this._remoteDescription}}),n.prototype.onicecandidate=null,n.prototype.onaddstream=null,n.prototype.ontrack=null,n.prototype.onremovestream=null,n.prototype.onsignalingstatechange=null,n.prototype.oniceconnectionstatechange=null,n.prototype.onconnectionstatechange=null,n.prototype.onicegatheringstatechange=null,n.prototype.onnegotiationneeded=null,n.prototype.ondatachannel=null,n.prototype._dispatchEvent=function(e,t){this._isClosed||(this.dispatchEvent(t),"function"==typeof this["on"+e]&&this["on"+e](t))},n.prototype._emitGatheringStateChange=function(){var e=new Event("icegatheringstatechange");this._dispatchEvent("icegatheringstatechange",e)},n.prototype.getConfiguration=function(){return this._config},n.prototype.getLocalStreams=function(){return this.localStreams},n.prototype.getRemoteStreams=function(){return this.remoteStreams},n.prototype._createTransceiver=function(e,t){var i=this.transceivers.length>0,r={track:null,iceGatherer:null,iceTransport:null,dtlsTransport:null,localCapabilities:null,remoteCapabilities:null,rtpSender:null,rtpReceiver:null,kind:e,mid:null,sendEncodingParameters:null,recvEncodingParameters:null,stream:null,associatedRemoteMediaStreams:[],wantReceive:!0};if(this.usingBundle&&i)r.iceTransport=this.transceivers[0].iceTransport,r.dtlsTransport=this.transceivers[0].dtlsTransport;else{var n=this._createIceAndDtlsTransports();r.iceTransport=n.iceTransport,r.dtlsTransport=n.dtlsTransport}return t||this.transceivers.push(r),r},n.prototype.addTrack=function(t,i){if(this._isClosed)throw ie("InvalidStateError","Attempted to call addTrack on a closed peerconnection.");var r;if(this.transceivers.find((function(e){return e.track===t})))throw ie("InvalidAccessError","Track already exists.");for(var n=0;n<this.transceivers.length;n++)this.transceivers[n].track||this.transceivers[n].kind!==t.kind||(r=this.transceivers[n]);return r||(r=this._createTransceiver(t.kind)),this._maybeFireNegotiationNeeded(),-1===this.localStreams.indexOf(i)&&this.localStreams.push(i),r.track=t,r.stream=i,r.rtpSender=new e.RTCRtpSender(t,r.dtlsTransport),r.rtpSender},n.prototype.addStream=function(e){var i=this;if(t>=15025)e.getTracks().forEach((function(t){i.addTrack(t,e)}));else{var r=e.clone();e.getTracks().forEach((function(e,t){var i=r.getTracks()[t];e.addEventListener("enabled",(function(e){i.enabled=e.enabled}))})),r.getTracks().forEach((function(e){i.addTrack(e,r)}))}},n.prototype.removeTrack=function(t){if(this._isClosed)throw ie("InvalidStateError","Attempted to call removeTrack on a closed peerconnection.");if(!(t instanceof e.RTCRtpSender))throw new TypeError("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.");var i=this.transceivers.find((function(e){return e.rtpSender===t}));if(!i)throw ie("InvalidAccessError","Sender was not created by this connection.");var r=i.stream;i.rtpSender.stop(),i.rtpSender=null,i.track=null,i.stream=null,-1===this.transceivers.map((function(e){return e.stream})).indexOf(r)&&this.localStreams.indexOf(r)>-1&&this.localStreams.splice(this.localStreams.indexOf(r),1),this._maybeFireNegotiationNeeded()},n.prototype.removeStream=function(e){var t=this;e.getTracks().forEach((function(e){var i=t.getSenders().find((function(t){return t.track===e}));i&&t.removeTrack(i)}))},n.prototype.getSenders=function(){return this.transceivers.filter((function(e){return!!e.rtpSender})).map((function(e){return e.rtpSender}))},n.prototype.getReceivers=function(){return this.transceivers.filter((function(e){return!!e.rtpReceiver})).map((function(e){return e.rtpReceiver}))},n.prototype._createIceGatherer=function(t,i){var r=this;if(i&&t>0)return this.transceivers[0].iceGatherer;if(this._iceGatherers.length)return this._iceGatherers.shift();var n=new e.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(n,"state",{value:"new",writable:!0}),this.transceivers[t].bufferedCandidateEvents=[],this.transceivers[t].bufferCandidates=function(e){var i=!e.candidate||0===Object.keys(e.candidate).length;n.state=i?"completed":"gathering",null!==r.transceivers[t].bufferedCandidateEvents&&r.transceivers[t].bufferedCandidateEvents.push(e)},n.addEventListener("localcandidate",this.transceivers[t].bufferCandidates),n},n.prototype._gather=function(t,i){var r=this,n=this.transceivers[i].iceGatherer;if(!n.onlocalcandidate){var o=this.transceivers[i].bufferedCandidateEvents;this.transceivers[i].bufferedCandidateEvents=null,n.removeEventListener("localcandidate",this.transceivers[i].bufferCandidates),n.onlocalcandidate=function(e){if(!(r.usingBundle&&i>0)){var o=new Event("icecandidate");o.candidate={sdpMid:t,sdpMLineIndex:i};var s=e.candidate,a=!s||0===Object.keys(s).length;if(a)"new"!==n.state&&"gathering"!==n.state||(n.state="completed");else{"new"===n.state&&(n.state="gathering"),s.component=1,s.ufrag=n.getLocalParameters().usernameFragment;var c=Q.writeCandidate(s);o.candidate=Object.assign(o.candidate,Q.parseCandidate(c)),o.candidate.candidate=c,o.candidate.toJSON=function(){return{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex,usernameFragment:o.candidate.usernameFragment}}}var d=Q.getMediaSections(r._localDescription.sdp);d[o.candidate.sdpMLineIndex]+=a?"a=end-of-candidates\r\n":"a="+o.candidate.candidate+"\r\n",r._localDescription.sdp=Q.getDescription(r._localDescription.sdp)+d.join("");var _=r.transceivers.every((function(e){return e.iceGatherer&&"completed"===e.iceGatherer.state}));"gathering"!==r.iceGatheringState&&(r.iceGatheringState="gathering",r._emitGatheringStateChange()),a||r._dispatchEvent("icecandidate",o),_&&(r._dispatchEvent("icecandidate",new Event("icecandidate")),r.iceGatheringState="complete",r._emitGatheringStateChange())}},e.setTimeout((function(){o.forEach((function(e){n.onlocalcandidate(e)}))}),0)}},n.prototype._createIceAndDtlsTransports=function(){var t=this,i=new e.RTCIceTransport(null);i.onicestatechange=function(){t._updateIceConnectionState(),t._updateConnectionState()};var r=new e.RTCDtlsTransport(i);return r.ondtlsstatechange=function(){t._updateConnectionState()},r.onerror=function(){Object.defineProperty(r,"state",{value:"failed",writable:!0}),t._updateConnectionState()},{iceTransport:i,dtlsTransport:r}},n.prototype._disposeIceAndDtlsTransports=function(e){var t=this.transceivers[e].iceGatherer;t&&(delete t.onlocalcandidate,delete this.transceivers[e].iceGatherer);var i=this.transceivers[e].iceTransport;i&&(delete i.onicestatechange,delete this.transceivers[e].iceTransport);var r=this.transceivers[e].dtlsTransport;r&&(delete r.ondtlsstatechange,delete r.onerror,delete this.transceivers[e].dtlsTransport)},n.prototype._transceive=function(e,i,r){var n=X(e.localCapabilities,e.remoteCapabilities);i&&e.rtpSender&&(n.encodings=e.sendEncodingParameters,n.rtcp={cname:Q.localCName,compound:e.rtcpParameters.compound},e.recvEncodingParameters.length&&(n.rtcp.ssrc=e.recvEncodingParameters[0].ssrc),e.rtpSender.send(n)),r&&e.rtpReceiver&&n.codecs.length>0&&("video"===e.kind&&e.recvEncodingParameters&&t<15019&&e.recvEncodingParameters.forEach((function(e){delete e.rtx})),e.recvEncodingParameters.length?n.encodings=e.recvEncodingParameters:n.encodings=[{}],n.rtcp={compound:e.rtcpParameters.compound},e.rtcpParameters.cname&&(n.rtcp.cname=e.rtcpParameters.cname),e.sendEncodingParameters.length&&(n.rtcp.ssrc=e.sendEncodingParameters[0].ssrc),e.rtpReceiver.receive(n))},n.prototype.setLocalDescription=function(e){var t,i,r=this;if(-1===["offer","answer"].indexOf(e.type))return Promise.reject(ie("TypeError",'Unsupported type "'+e.type+'"'));if(!ee("setLocalDescription",e.type,r.signalingState)||r._isClosed)return Promise.reject(ie("InvalidStateError","Can not set local "+e.type+" in state "+r.signalingState));if("offer"===e.type)t=Q.splitSections(e.sdp),i=t.shift(),t.forEach((function(e,t){var i=Q.parseRtpParameters(e);r.transceivers[t].localCapabilities=i})),r.transceivers.forEach((function(e,t){r._gather(e.mid,t)}));else if("answer"===e.type){t=Q.splitSections(r._remoteDescription.sdp),i=t.shift();var n=Q.matchPrefix(i,"a=ice-lite").length>0;t.forEach((function(e,t){var o=r.transceivers[t],s=o.iceGatherer,a=o.iceTransport,c=o.dtlsTransport,d=o.localCapabilities,_=o.remoteCapabilities;if(!(Q.isRejected(e)&&0===Q.matchPrefix(e,"a=bundle-only").length)&&!o.rejected){var l=Q.getIceParameters(e,i),u=Q.getDtlsParameters(e,i);n&&(u.role="server"),r.usingBundle&&0!==t||(r._gather(o.mid,t),"new"===a.state&&a.start(s,l,n?"controlling":"controlled"),"new"===c.state&&c.start(u));var h=X(d,_);r._transceive(o,h.codecs.length>0,!1)}}))}return r._localDescription={type:e.type,sdp:e.sdp},"offer"===e.type?r._updateSignalingState("have-local-offer"):r._updateSignalingState("stable"),Promise.resolve()},n.prototype.setRemoteDescription=function(n){var o=this;if(-1===["offer","answer"].indexOf(n.type))return Promise.reject(ie("TypeError",'Unsupported type "'+n.type+'"'));if(!ee("setRemoteDescription",n.type,o.signalingState)||o._isClosed)return Promise.reject(ie("InvalidStateError","Can not set remote "+n.type+" in state "+o.signalingState));var s={};o.remoteStreams.forEach((function(e){s[e.id]=e}));var a=[],c=Q.splitSections(n.sdp),d=c.shift(),_=Q.matchPrefix(d,"a=ice-lite").length>0,l=Q.matchPrefix(d,"a=group:BUNDLE ").length>0;o.usingBundle=l;var u=Q.matchPrefix(d,"a=ice-options:")[0];return o.canTrickleIceCandidates=!!u&&u.substr(14).split(" ").indexOf("trickle")>=0,c.forEach((function(r,c){var u=Q.splitLines(r),h=Q.getKind(r),g=Q.isRejected(r)&&0===Q.matchPrefix(r,"a=bundle-only").length,v=u[0].substr(2).split(" ")[2],p=Q.getDirection(r,d),R=Q.parseMsid(r),m=Q.getMid(r)||Q.generateIdentifier();if(g||"application"===h&&("DTLS/SCTP"===v||"UDP/DTLS/SCTP"===v))o.transceivers[c]={mid:m,kind:h,protocol:v,rejected:!0};else{var I,E,S,T,f,C,O,L,N;!g&&o.transceivers[c]&&o.transceivers[c].rejected&&(o.transceivers[c]=o._createTransceiver(h,!0));var A,y,k=Q.parseRtpParameters(r);g||(A=Q.getIceParameters(r,d),(y=Q.getDtlsParameters(r,d)).role="client"),O=Q.parseRtpEncodingParameters(r);var D=Q.parseRtcpParameters(r),b=Q.matchPrefix(r,"a=end-of-candidates",d).length>0,U=Q.matchPrefix(r,"a=candidate:").map((function(e){return Q.parseCandidate(e)})).filter((function(e){return 1===e.component}));if(("offer"===n.type||"answer"===n.type)&&!g&&l&&c>0&&o.transceivers[c]&&(o._disposeIceAndDtlsTransports(c),o.transceivers[c].iceGatherer=o.transceivers[0].iceGatherer,o.transceivers[c].iceTransport=o.transceivers[0].iceTransport,o.transceivers[c].dtlsTransport=o.transceivers[0].dtlsTransport,o.transceivers[c].rtpSender&&o.transceivers[c].rtpSender.setTransport(o.transceivers[0].dtlsTransport),o.transceivers[c].rtpReceiver&&o.transceivers[c].rtpReceiver.setTransport(o.transceivers[0].dtlsTransport)),"offer"!==n.type||g){if("answer"===n.type&&!g){E=(I=o.transceivers[c]).iceGatherer,S=I.iceTransport,T=I.dtlsTransport,f=I.rtpReceiver,C=I.sendEncodingParameters,L=I.localCapabilities,o.transceivers[c].recvEncodingParameters=O,o.transceivers[c].remoteCapabilities=k,o.transceivers[c].rtcpParameters=D,U.length&&"new"===S.state&&(!_&&!b||l&&0!==c?U.forEach((function(e){te(I.iceTransport,e)})):S.setRemoteCandidates(U)),l&&0!==c||("new"===S.state&&S.start(E,A,"controlling"),"new"===T.state&&T.start(y)),!X(I.localCapabilities,I.remoteCapabilities).codecs.filter((function(e){return"rtx"===e.name.toLowerCase()})).length&&I.sendEncodingParameters[0].rtx&&delete I.sendEncodingParameters[0].rtx,o._transceive(I,"sendrecv"===p||"recvonly"===p,"sendrecv"===p||"sendonly"===p),!f||"sendrecv"!==p&&"sendonly"!==p?delete I.rtpReceiver:(N=f.track,R?(s[R.stream]||(s[R.stream]=new e.MediaStream),i(N,s[R.stream]),a.push([N,f,s[R.stream]])):(s.default||(s.default=new e.MediaStream),i(N,s.default),a.push([N,f,s.default])))}}else{(I=o.transceivers[c]||o._createTransceiver(h)).mid=m,I.iceGatherer||(I.iceGatherer=o._createIceGatherer(c,l)),U.length&&"new"===I.iceTransport.state&&(!b||l&&0!==c?U.forEach((function(e){te(I.iceTransport,e)})):I.iceTransport.setRemoteCandidates(U)),L=e.RTCRtpReceiver.getCapabilities(h),t<15019&&(L.codecs=L.codecs.filter((function(e){return"rtx"!==e.name}))),C=I.sendEncodingParameters||[{ssrc:1001*(2*c+2)}];var P,M=!1;if("sendrecv"===p||"sendonly"===p){if(M=!I.rtpReceiver,f=I.rtpReceiver||new e.RTCRtpReceiver(I.dtlsTransport,h),M)N=f.track,R&&"-"===R.stream||(R?(s[R.stream]||(s[R.stream]=new e.MediaStream,Object.defineProperty(s[R.stream],"id",{get:function(){return R.stream}})),Object.defineProperty(N,"id",{get:function(){return R.track}}),P=s[R.stream]):(s.default||(s.default=new e.MediaStream),P=s.default)),P&&(i(N,P),I.associatedRemoteMediaStreams.push(P)),a.push([N,f,P])}else I.rtpReceiver&&I.rtpReceiver.track&&(I.associatedRemoteMediaStreams.forEach((function(t){var i=t.getTracks().find((function(e){return e.id===I.rtpReceiver.track.id}));i&&function(t,i){i.removeTrack(t),i.dispatchEvent(new e.MediaStreamTrackEvent("removetrack",{track:t}))}(i,t)})),I.associatedRemoteMediaStreams=[]);I.localCapabilities=L,I.remoteCapabilities=k,I.rtpReceiver=f,I.rtcpParameters=D,I.sendEncodingParameters=C,I.recvEncodingParameters=O,o._transceive(o.transceivers[c],!1,M)}}})),void 0===o._dtlsRole&&(o._dtlsRole="offer"===n.type?"active":"passive"),o._remoteDescription={type:n.type,sdp:n.sdp},"offer"===n.type?o._updateSignalingState("have-remote-offer"):o._updateSignalingState("stable"),Object.keys(s).forEach((function(t){var i=s[t];if(i.getTracks().length){if(-1===o.remoteStreams.indexOf(i)){o.remoteStreams.push(i);var n=new Event("addstream");n.stream=i,e.setTimeout((function(){o._dispatchEvent("addstream",n)}))}a.forEach((function(e){var t=e[0],n=e[1];i.id===e[2].id&&r(o,t,n,[i])}))}})),a.forEach((function(e){e[2]||r(o,e[0],e[1],[])})),e.setTimeout((function(){o&&o.transceivers&&o.transceivers.forEach((function(e){e.iceTransport&&"new"===e.iceTransport.state&&e.iceTransport.getRemoteCandidates().length>0&&(console.warn("Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification"),e.iceTransport.addRemoteCandidate({}))}))}),4e3),Promise.resolve()},n.prototype.close=function(){this.transceivers.forEach((function(e){e.iceTransport&&e.iceTransport.stop(),e.dtlsTransport&&e.dtlsTransport.stop(),e.rtpSender&&e.rtpSender.stop(),e.rtpReceiver&&e.rtpReceiver.stop()})),this._isClosed=!0,this._updateSignalingState("closed")},n.prototype._updateSignalingState=function(e){this.signalingState=e;var t=new Event("signalingstatechange");this._dispatchEvent("signalingstatechange",t)},n.prototype._maybeFireNegotiationNeeded=function(){var t=this;"stable"===this.signalingState&&!0!==this.needNegotiation&&(this.needNegotiation=!0,e.setTimeout((function(){if(t.needNegotiation){t.needNegotiation=!1;var e=new Event("negotiationneeded");t._dispatchEvent("negotiationneeded",e)}}),0))},n.prototype._updateIceConnectionState=function(){var e,t={new:0,closed:0,checking:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach((function(e){e.iceTransport&&!e.rejected&&t[e.iceTransport.state]++})),e="new",t.failed>0?e="failed":t.checking>0?e="checking":t.disconnected>0?e="disconnected":t.new>0?e="new":t.connected>0?e="connected":t.completed>0&&(e="completed"),e!==this.iceConnectionState){this.iceConnectionState=e;var i=new Event("iceconnectionstatechange");this._dispatchEvent("iceconnectionstatechange",i)}},n.prototype._updateConnectionState=function(){var e,t={new:0,closed:0,connecting:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach((function(e){e.iceTransport&&e.dtlsTransport&&!e.rejected&&(t[e.iceTransport.state]++,t[e.dtlsTransport.state]++)})),t.connected+=t.completed,e="new",t.failed>0?e="failed":t.connecting>0?e="connecting":t.disconnected>0?e="disconnected":t.new>0?e="new":t.connected>0&&(e="connected"),e!==this.connectionState){this.connectionState=e;var i=new Event("connectionstatechange");this._dispatchEvent("connectionstatechange",i)}},n.prototype.createOffer=function(){var i=this;if(i._isClosed)return Promise.reject(ie("InvalidStateError","Can not call createOffer after close"));var r=i.transceivers.filter((function(e){return"audio"===e.kind})).length,n=i.transceivers.filter((function(e){return"video"===e.kind})).length,o=arguments[0];if(o){if(o.mandatory||o.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");void 0!==o.offerToReceiveAudio&&(r=!0===o.offerToReceiveAudio?1:!1===o.offerToReceiveAudio?0:o.offerToReceiveAudio),void 0!==o.offerToReceiveVideo&&(n=!0===o.offerToReceiveVideo?1:!1===o.offerToReceiveVideo?0:o.offerToReceiveVideo)}for(i.transceivers.forEach((function(e){"audio"===e.kind?--r<0&&(e.wantReceive=!1):"video"===e.kind&&--n<0&&(e.wantReceive=!1)}));r>0||n>0;)r>0&&(i._createTransceiver("audio"),r--),n>0&&(i._createTransceiver("video"),n--);var s=Q.writeSessionBoilerplate(i._sdpSessionId,i._sdpSessionVersion++);i.transceivers.forEach((function(r,n){var o=r.track,s=r.kind,a=r.mid||Q.generateIdentifier();r.mid=a,r.iceGatherer||(r.iceGatherer=i._createIceGatherer(n,i.usingBundle));var c=e.RTCRtpSender.getCapabilities(s);t<15019&&(c.codecs=c.codecs.filter((function(e){return"rtx"!==e.name}))),c.codecs.forEach((function(e){"H264"===e.name&&void 0===e.parameters["level-asymmetry-allowed"]&&(e.parameters["level-asymmetry-allowed"]="1"),r.remoteCapabilities&&r.remoteCapabilities.codecs&&r.remoteCapabilities.codecs.forEach((function(t){e.name.toLowerCase()===t.name.toLowerCase()&&e.clockRate===t.clockRate&&(e.preferredPayloadType=t.payloadType)}))})),c.headerExtensions.forEach((function(e){(r.remoteCapabilities&&r.remoteCapabilities.headerExtensions||[]).forEach((function(t){e.uri===t.uri&&(e.id=t.id)}))}));var d=r.sendEncodingParameters||[{ssrc:1001*(2*n+1)}];o&&t>=15019&&"video"===s&&!d[0].rtx&&(d[0].rtx={ssrc:d[0].ssrc+1}),r.wantReceive&&(r.rtpReceiver=new e.RTCRtpReceiver(r.dtlsTransport,s)),r.localCapabilities=c,r.sendEncodingParameters=d})),"max-compat"!==i._config.bundlePolicy&&(s+="a=group:BUNDLE "+i.transceivers.map((function(e){return e.mid})).join(" ")+"\r\n"),s+="a=ice-options:trickle\r\n",i.transceivers.forEach((function(e,t){s+=Z(e,e.localCapabilities,"offer",e.stream,i._dtlsRole),s+="a=rtcp-rsize\r\n",!e.iceGatherer||"new"===i.iceGatheringState||0!==t&&i.usingBundle||(e.iceGatherer.getLocalCandidates().forEach((function(e){e.component=1,s+="a="+Q.writeCandidate(e)+"\r\n"})),"completed"===e.iceGatherer.state&&(s+="a=end-of-candidates\r\n"))}));var a=new e.RTCSessionDescription({type:"offer",sdp:s});return Promise.resolve(a)},n.prototype.createAnswer=function(){var i=this;if(i._isClosed)return Promise.reject(ie("InvalidStateError","Can not call createAnswer after close"));if("have-remote-offer"!==i.signalingState&&"have-local-pranswer"!==i.signalingState)return Promise.reject(ie("InvalidStateError","Can not call createAnswer in signalingState "+i.signalingState));var r=Q.writeSessionBoilerplate(i._sdpSessionId,i._sdpSessionVersion++);i.usingBundle&&(r+="a=group:BUNDLE "+i.transceivers.map((function(e){return e.mid})).join(" ")+"\r\n"),r+="a=ice-options:trickle\r\n";var n=Q.getMediaSections(i._remoteDescription.sdp).length;i.transceivers.forEach((function(e,o){if(!(o+1>n)){if(e.rejected)return"application"===e.kind?"DTLS/SCTP"===e.protocol?r+="m=application 0 DTLS/SCTP 5000\r\n":r+="m=application 0 "+e.protocol+" webrtc-datachannel\r\n":"audio"===e.kind?r+="m=audio 0 UDP/TLS/RTP/SAVPF 0\r\na=rtpmap:0 PCMU/8000\r\n":"video"===e.kind&&(r+="m=video 0 UDP/TLS/RTP/SAVPF 120\r\na=rtpmap:120 VP8/90000\r\n"),void(r+="c=IN IP4 0.0.0.0\r\na=inactive\r\na=mid:"+e.mid+"\r\n");var s;if(e.stream)"audio"===e.kind?s=e.stream.getAudioTracks()[0]:"video"===e.kind&&(s=e.stream.getVideoTracks()[0]),s&&t>=15019&&"video"===e.kind&&!e.sendEncodingParameters[0].rtx&&(e.sendEncodingParameters[0].rtx={ssrc:e.sendEncodingParameters[0].ssrc+1});var a=X(e.localCapabilities,e.remoteCapabilities);!a.codecs.filter((function(e){return"rtx"===e.name.toLowerCase()})).length&&e.sendEncodingParameters[0].rtx&&delete e.sendEncodingParameters[0].rtx,r+=Z(e,a,"answer",e.stream,i._dtlsRole),e.rtcpParameters&&e.rtcpParameters.reducedSize&&(r+="a=rtcp-rsize\r\n")}}));var o=new e.RTCSessionDescription({type:"answer",sdp:r});return Promise.resolve(o)},n.prototype.addIceCandidate=function(e){var t,i=this;return e&&void 0===e.sdpMLineIndex&&!e.sdpMid?Promise.reject(new TypeError("sdpMLineIndex or sdpMid required")):new Promise((function(r,n){if(!i._remoteDescription)return n(ie("InvalidStateError","Can not add ICE candidate without a remote description"));if(e&&""!==e.candidate){var o=e.sdpMLineIndex;if(e.sdpMid)for(var s=0;s<i.transceivers.length;s++)if(i.transceivers[s].mid===e.sdpMid){o=s;break}var a=i.transceivers[o];if(!a)return n(ie("OperationError","Can not add ICE candidate"));if(a.rejected)return r();var c=Object.keys(e.candidate).length>0?Q.parseCandidate(e.candidate):{};if("tcp"===c.protocol&&(0===c.port||9===c.port))return r();if(c.component&&1!==c.component)return r();if((0===o||o>0&&a.iceTransport!==i.transceivers[0].iceTransport)&&!te(a.iceTransport,c))return n(ie("OperationError","Can not add ICE candidate"));var d=e.candidate.trim();0===d.indexOf("a=")&&(d=d.substr(2)),(t=Q.getMediaSections(i._remoteDescription.sdp))[o]+="a="+(c.type?d:"end-of-candidates")+"\r\n",i._remoteDescription.sdp=Q.getDescription(i._remoteDescription.sdp)+t.join("")}else for(var _=0;_<i.transceivers.length&&(i.transceivers[_].rejected||(i.transceivers[_].iceTransport.addRemoteCandidate({}),(t=Q.getMediaSections(i._remoteDescription.sdp))[_]+="a=end-of-candidates\r\n",i._remoteDescription.sdp=Q.getDescription(i._remoteDescription.sdp)+t.join(""),!i.usingBundle));_++);r()}))},n.prototype.getStats=function(t){if(t&&t instanceof e.MediaStreamTrack){var i=null;if(this.transceivers.forEach((function(e){e.rtpSender&&e.rtpSender.track===t?i=e.rtpSender:e.rtpReceiver&&e.rtpReceiver.track===t&&(i=e.rtpReceiver)})),!i)throw ie("InvalidAccessError","Invalid selector.");return i.getStats()}var r=[];return this.transceivers.forEach((function(e){["rtpSender","rtpReceiver","iceGatherer","iceTransport","dtlsTransport"].forEach((function(t){e[t]&&r.push(e[t].getStats())}))})),Promise.all(r).then((function(e){var t=new Map;return e.forEach((function(e){e.forEach((function(e){t.set(e.id,e)}))})),t}))};["RTCRtpSender","RTCRtpReceiver","RTCIceGatherer","RTCIceTransport","RTCDtlsTransport"].forEach((function(t){var i=e[t];if(i&&i.prototype&&i.prototype.getStats){var r=i.prototype.getStats;i.prototype.getStats=function(){return r.apply(this).then((function(e){var t=new Map;return Object.keys(e).forEach((function(i){var r;e[i].type={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[(r=e[i]).type]||r.type,t.set(i,e[i])})),t}))}}}));var o=["createOffer","createAnswer"];return o.forEach((function(e){var t=n.prototype[e];n.prototype[e]=function(){var e=arguments;return"function"==typeof e[0]||"function"==typeof e[1]?t.apply(this,[arguments[2]]).then((function(t){"function"==typeof e[0]&&e[0].apply(null,[t])}),(function(t){"function"==typeof e[1]&&e[1].apply(null,[t])})):t.apply(this,arguments)}})),(o=["setLocalDescription","setRemoteDescription","addIceCandidate"]).forEach((function(e){var t=n.prototype[e];n.prototype[e]=function(){var e=arguments;return"function"==typeof e[1]||"function"==typeof e[2]?t.apply(this,arguments).then((function(){"function"==typeof e[1]&&e[1].apply(null)}),(function(t){"function"==typeof e[2]&&e[2].apply(null,[t])})):t.apply(this,arguments)}})),["getStats"].forEach((function(e){var t=n.prototype[e];n.prototype[e]=function(){var e=arguments;return"function"==typeof e[1]?t.apply(this,arguments).then((function(){"function"==typeof e[1]&&e[1].apply(null)})):t.apply(this,arguments)}})),n};function ne(e){const t=e&&e.navigator,i=t.mediaDevices.getUserMedia.bind(t.mediaDevices);t.mediaDevices.getUserMedia=function(e){return i(e).catch((e=>Promise.reject(function(e){return{name:{PermissionDeniedError:"NotAllowedError"}[e.name]||e.name,message:e.message,constraint:e.constraint,toString(){return this.name}}}(e))))}}function oe(e){"getDisplayMedia"in e.navigator&&e.navigator.mediaDevices&&(e.navigator.mediaDevices&&"getDisplayMedia"in e.navigator.mediaDevices||(e.navigator.mediaDevices.getDisplayMedia=e.navigator.getDisplayMedia.bind(e.navigator)))}function se(e,t){if(e.RTCIceGatherer&&(e.RTCIceCandidate||(e.RTCIceCandidate=function(e){return e}),e.RTCSessionDescription||(e.RTCSessionDescription=function(e){return e}),t.version<15025)){const t=Object.getOwnPropertyDescriptor(e.MediaStreamTrack.prototype,"enabled");Object.defineProperty(e.MediaStreamTrack.prototype,"enabled",{set(e){t.set.call(this,e);const i=new Event("enabled");i.enabled=e,this.dispatchEvent(i)}})}e.RTCRtpSender&&!("dtmf"in e.RTCRtpSender.prototype)&&Object.defineProperty(e.RTCRtpSender.prototype,"dtmf",{get(){return void 0===this._dtmf&&("audio"===this.track.kind?this._dtmf=new e.RTCDtmfSender(this):"video"===this.track.kind&&(this._dtmf=null)),this._dtmf}}),e.RTCDtmfSender&&!e.RTCDTMFSender&&(e.RTCDTMFSender=e.RTCDtmfSender);const i=re(e,t.version);e.RTCPeerConnection=function(e){return e&&e.iceServers&&(e.iceServers=function(e,t){let i=!1;return(e=JSON.parse(JSON.stringify(e))).filter((e=>{if(e&&(e.urls||e.url)){let t=e.urls||e.url;e.url&&!e.urls&&b("RTCIceServer.url","RTCIceServer.urls");const r="string"==typeof t;return r&&(t=[t]),t=t.filter((e=>{if(0===e.indexOf("stun:"))return!1;const t=e.startsWith("turn")&&!e.startsWith("turn:[")&&e.includes("transport=udp");return t&&!i?(i=!0,!0):t&&!i})),delete e.url,e.urls=r?t[0]:t,!!t.length}}))}(e.iceServers,t.version),D("ICE servers after filtering:",e.iceServers)),new i(e)},e.RTCPeerConnection.prototype=i.prototype}function ae(e){e.RTCRtpSender&&!("replaceTrack"in e.RTCRtpSender.prototype)&&(e.RTCRtpSender.prototype.replaceTrack=e.RTCRtpSender.prototype.setTrack)}var ce=Object.freeze({__proto__:null,shimPeerConnection:se,shimReplaceTrack:ae,shimGetUserMedia:ne,shimGetDisplayMedia:oe});function de(e,t){const i=e&&e.navigator,r=e&&e.MediaStreamTrack;if(i.getUserMedia=function(e,t,r){b("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),i.mediaDevices.getUserMedia(e).then(t,r)},!(t.version>55&&"autoGainControl"in i.mediaDevices.getSupportedConstraints())){const e=function(e,t,i){t in e&&!(i in e)&&(e[i]=e[t],delete e[t])},t=i.mediaDevices.getUserMedia.bind(i.mediaDevices);if(i.mediaDevices.getUserMedia=function(i){return"object"==typeof i&&"object"==typeof i.audio&&(i=JSON.parse(JSON.stringify(i)),e(i.audio,"autoGainControl","mozAutoGainControl"),e(i.audio,"noiseSuppression","mozNoiseSuppression")),t(i)},r&&r.prototype.getSettings){const t=r.prototype.getSettings;r.prototype.getSettings=function(){const i=t.apply(this,arguments);return e(i,"mozAutoGainControl","autoGainControl"),e(i,"mozNoiseSuppression","noiseSuppression"),i}}if(r&&r.prototype.applyConstraints){const t=r.prototype.applyConstraints;r.prototype.applyConstraints=function(i){return"audio"===this.kind&&"object"==typeof i&&(i=JSON.parse(JSON.stringify(i)),e(i,"autoGainControl","mozAutoGainControl"),e(i,"noiseSuppression","mozNoiseSuppression")),t.apply(this,[i])}}}}function _e(e){"object"==typeof e&&e.RTCTrackEvent&&"receiver"in e.RTCTrackEvent.prototype&&!("transceiver"in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function le(e,t){if("object"!=typeof e||!e.RTCPeerConnection&&!e.mozRTCPeerConnection)return;!e.RTCPeerConnection&&e.mozRTCPeerConnection&&(e.RTCPeerConnection=e.mozRTCPeerConnection),t.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],r={[t](){return arguments[0]=new("addIceCandidate"===t?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),i.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=r[t]}));const i={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},r=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){const[e,n,o]=arguments;return r.apply(this,[e||null]).then((e=>{if(t.version<53&&!n)try{e.forEach((e=>{e.type=i[e.type]||e.type}))}catch(t){if("TypeError"!==t.name)throw t;e.forEach(((t,r)=>{e.set(r,Object.assign({},t,{type:i[t.type]||t.type}))}))}return e})).then(n,o)}}function ue(e){if("object"!=typeof e||!e.RTCPeerConnection||!e.RTCRtpSender)return;if(e.RTCRtpSender&&"getStats"in e.RTCRtpSender.prototype)return;const t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e});const i=e.RTCPeerConnection.prototype.addTrack;i&&(e.RTCPeerConnection.prototype.addTrack=function(){const e=i.apply(this,arguments);return e._pc=this,e}),e.RTCRtpSender.prototype.getStats=function(){return this.track?this._pc.getStats(this.track):Promise.resolve(new Map)}}function he(e){if("object"!=typeof e||!e.RTCPeerConnection||!e.RTCRtpSender)return;if(e.RTCRtpSender&&"getStats"in e.RTCRtpReceiver.prototype)return;const t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e}),A(e,"track",(e=>(e.receiver._pc=e.srcElement,e))),e.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function ge(e){e.RTCPeerConnection&&!("removeStream"in e.RTCPeerConnection.prototype)&&(e.RTCPeerConnection.prototype.removeStream=function(e){b("removeStream","removeTrack"),this.getSenders().forEach((t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)}))})}function ve(e){e.DataChannel&&!e.RTCDataChannel&&(e.RTCDataChannel=e.DataChannel)}function pe(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.addTransceiver;t&&(e.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];const e=arguments[1],i=e&&"sendEncodings"in e;i&&e.sendEncodings.forEach((e=>{if("rid"in e){if(!/^[a-z0-9]{0,16}$/i.test(e.rid))throw new TypeError("Invalid RID value provided.")}if("scaleResolutionDownBy"in e&&!(parseFloat(e.scaleResolutionDownBy)>=1))throw new RangeError("scale_resolution_down_by must be >= 1.0");if("maxFramerate"in e&&!(parseFloat(e.maxFramerate)>=0))throw new RangeError("max_framerate must be >= 0.0")}));const r=t.apply(this,arguments);if(i){const{sender:t}=r,i=t.getParameters();(!("encodings"in i)||1===i.encodings.length&&0===Object.keys(i.encodings[0]).length)&&(i.encodings=e.sendEncodings,t.sendEncodings=e.sendEncodings,this.setParametersPromises.push(t.setParameters(i).then((()=>{delete t.sendEncodings})).catch((()=>{delete t.sendEncodings}))))}return r})}function Re(e){if("object"!=typeof e||!e.RTCRtpSender)return;const t=e.RTCRtpSender.prototype.getParameters;t&&(e.RTCRtpSender.prototype.getParameters=function(){const e=t.apply(this,arguments);return"encodings"in e||(e.encodings=[].concat(this.sendEncodings||[{}])),e})}function me(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then((()=>t.apply(this,arguments))).finally((()=>{this.setParametersPromises=[]})):t.apply(this,arguments)}}function Ie(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.createAnswer;e.RTCPeerConnection.prototype.createAnswer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then((()=>t.apply(this,arguments))).finally((()=>{this.setParametersPromises=[]})):t.apply(this,arguments)}}var Ee=Object.freeze({__proto__:null,shimOnTrack:_e,shimPeerConnection:le,shimSenderGetStats:ue,shimReceiverGetStats:he,shimRemoveStream:ge,shimRTCDataChannel:ve,shimAddTransceiver:pe,shimGetParameters:Re,shimCreateOffer:me,shimCreateAnswer:Ie,shimGetUserMedia:de,shimGetDisplayMedia:function(e,t){e.navigator.mediaDevices&&"getDisplayMedia"in e.navigator.mediaDevices||e.navigator.mediaDevices&&(e.navigator.mediaDevices.getDisplayMedia=function(i){if(!i||!i.video){const e=new DOMException("getDisplayMedia without video constraints is undefined");return e.name="NotFoundError",e.code=8,Promise.reject(e)}return!0===i.video?i.video={mediaSource:t}:i.video.mediaSource=t,e.navigator.mediaDevices.getUserMedia(i)})}});function Se(e){if("object"==typeof e&&e.RTCPeerConnection){if("getLocalStreams"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),!("addStream"in e.RTCPeerConnection.prototype)){const t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addStream=function(e){this._localStreams||(this._localStreams=[]),this._localStreams.includes(e)||this._localStreams.push(e),e.getAudioTracks().forEach((i=>t.call(this,i,e))),e.getVideoTracks().forEach((i=>t.call(this,i,e)))},e.RTCPeerConnection.prototype.addTrack=function(e,...i){return i&&i.forEach((e=>{this._localStreams?this._localStreams.includes(e)||this._localStreams.push(e):this._localStreams=[e]})),t.apply(this,arguments)}}"removeStream"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.removeStream=function(e){this._localStreams||(this._localStreams=[]);const t=this._localStreams.indexOf(e);if(-1===t)return;this._localStreams.splice(t,1);const i=e.getTracks();this.getSenders().forEach((e=>{i.includes(e.track)&&this.removeTrack(e)}))})}}function Te(e){if("object"==typeof e&&e.RTCPeerConnection&&("getRemoteStreams"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),!("onaddstream"in e.RTCPeerConnection.prototype))){Object.defineProperty(e.RTCPeerConnection.prototype,"onaddstream",{get(){return this._onaddstream},set(e){this._onaddstream&&(this.removeEventListener("addstream",this._onaddstream),this.removeEventListener("track",this._onaddstreampoly)),this.addEventListener("addstream",this._onaddstream=e),this.addEventListener("track",this._onaddstreampoly=e=>{e.streams.forEach((e=>{if(this._remoteStreams||(this._remoteStreams=[]),this._remoteStreams.includes(e))return;this._remoteStreams.push(e);const t=new Event("addstream");t.stream=e,this.dispatchEvent(t)}))})}});const t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){const e=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(t){t.streams.forEach((t=>{if(e._remoteStreams||(e._remoteStreams=[]),e._remoteStreams.indexOf(t)>=0)return;e._remoteStreams.push(t);const i=new Event("addstream");i.stream=t,e.dispatchEvent(i)}))}),t.apply(e,arguments)}}}function fe(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype,i=t.createOffer,r=t.createAnswer,n=t.setLocalDescription,o=t.setRemoteDescription,s=t.addIceCandidate;t.createOffer=function(e,t){const r=arguments.length>=2?arguments[2]:arguments[0],n=i.apply(this,[r]);return t?(n.then(e,t),Promise.resolve()):n},t.createAnswer=function(e,t){const i=arguments.length>=2?arguments[2]:arguments[0],n=r.apply(this,[i]);return t?(n.then(e,t),Promise.resolve()):n};let a=function(e,t,i){const r=n.apply(this,[e]);return i?(r.then(t,i),Promise.resolve()):r};t.setLocalDescription=a,a=function(e,t,i){const r=o.apply(this,[e]);return i?(r.then(t,i),Promise.resolve()):r},t.setRemoteDescription=a,a=function(e,t,i){const r=s.apply(this,[e]);return i?(r.then(t,i),Promise.resolve()):r},t.addIceCandidate=a}function Ce(e){const t=e&&e.navigator;if(t.mediaDevices&&t.mediaDevices.getUserMedia){const e=t.mediaDevices,i=e.getUserMedia.bind(e);t.mediaDevices.getUserMedia=e=>i(Oe(e))}!t.getUserMedia&&t.mediaDevices&&t.mediaDevices.getUserMedia&&(t.getUserMedia=function(e,i,r){t.mediaDevices.getUserMedia(e).then(i,r)}.bind(t))}function Oe(e){return e&&void 0!==e.video?Object.assign({},e,{video:P(e.video)}):e}function Le(e){if(!e.RTCPeerConnection)return;const t=e.RTCPeerConnection;e.RTCPeerConnection=function(e,i){if(e&&e.iceServers){const t=[];for(let i=0;i<e.iceServers.length;i++){let r=e.iceServers[i];!r.hasOwnProperty("urls")&&r.hasOwnProperty("url")?(b("RTCIceServer.url","RTCIceServer.urls"),r=JSON.parse(JSON.stringify(r)),r.urls=r.url,delete r.url,t.push(r)):t.push(e.iceServers[i])}e.iceServers=t}return new t(e,i)},e.RTCPeerConnection.prototype=t.prototype,"generateCertificate"in t&&Object.defineProperty(e.RTCPeerConnection,"generateCertificate",{get:()=>t.generateCertificate})}function Ne(e){"object"==typeof e&&e.RTCTrackEvent&&"receiver"in e.RTCTrackEvent.prototype&&!("transceiver"in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function Ae(e){const t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(e){if(e){void 0!==e.offerToReceiveAudio&&(e.offerToReceiveAudio=!!e.offerToReceiveAudio);const t=this.getTransceivers().find((e=>"audio"===e.receiver.track.kind));!1===e.offerToReceiveAudio&&t?"sendrecv"===t.direction?t.setDirection?t.setDirection("sendonly"):t.direction="sendonly":"recvonly"===t.direction&&(t.setDirection?t.setDirection("inactive"):t.direction="inactive"):!0!==e.offerToReceiveAudio||t||this.addTransceiver("audio"),void 0!==e.offerToReceiveVideo&&(e.offerToReceiveVideo=!!e.offerToReceiveVideo);const i=this.getTransceivers().find((e=>"video"===e.receiver.track.kind));!1===e.offerToReceiveVideo&&i?"sendrecv"===i.direction?i.setDirection?i.setDirection("sendonly"):i.direction="sendonly":"recvonly"===i.direction&&(i.setDirection?i.setDirection("inactive"):i.direction="inactive"):!0!==e.offerToReceiveVideo||i||this.addTransceiver("video")}return t.apply(this,arguments)}}function ye(e){"object"!=typeof e||e.AudioContext||(e.AudioContext=e.webkitAudioContext)}var ke=Object.freeze({__proto__:null,shimLocalStreamsAPI:Se,shimRemoteStreamsAPI:Te,shimCallbacksAPI:fe,shimGetUserMedia:Ce,shimConstraints:Oe,shimRTCIceServerUrls:Le,shimTrackEventTransceiver:Ne,shimCreateOfferLegacy:Ae,shimAudioContext:ye});function De(e){if(!e.RTCIceCandidate||e.RTCIceCandidate&&"foundation"in e.RTCIceCandidate.prototype)return;const t=e.RTCIceCandidate;e.RTCIceCandidate=function(e){if("object"==typeof e&&e.candidate&&0===e.candidate.indexOf("a=")&&((e=JSON.parse(JSON.stringify(e))).candidate=e.candidate.substr(2)),e.candidate&&e.candidate.length){const i=new t(e),r=Q.parseCandidate(e.candidate),n=Object.assign(i,r);return n.toJSON=function(){return{candidate:n.candidate,sdpMid:n.sdpMid,sdpMLineIndex:n.sdpMLineIndex,usernameFragment:n.usernameFragment}},n}return new t(e)},e.RTCIceCandidate.prototype=t.prototype,A(e,"icecandidate",(t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new e.RTCIceCandidate(t.candidate),writable:"false"}),t)))}function be(e,t){if(!e.RTCPeerConnection)return;"sctp"in e.RTCPeerConnection.prototype||Object.defineProperty(e.RTCPeerConnection.prototype,"sctp",{get(){return void 0===this._sctp?null:this._sctp}});const i=function(e){if(!e||!e.sdp)return!1;const t=Q.splitSections(e.sdp);return t.shift(),t.some((e=>{const t=Q.parseMLine(e);return t&&"application"===t.kind&&-1!==t.protocol.indexOf("SCTP")}))},r=function(e){const t=e.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(null===t||t.length<2)return-1;const i=parseInt(t[1],10);return i!=i?-1:i},n=function(e){let i=65536;return"firefox"===t.browser&&(i=t.version<57?-1===e?16384:2147483637:t.version<60?57===t.version?65535:65536:2147483637),i},o=function(e,i){let r=65536;"firefox"===t.browser&&57===t.version&&(r=65535);const n=Q.matchPrefix(e.sdp,"a=max-message-size:");return n.length>0?r=parseInt(n[0].substr(19),10):"firefox"===t.browser&&-1!==i&&(r=2147483637),r},s=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,"chrome"===t.browser&&t.version>=76){const{sdpSemantics:e}=this.getConfiguration();"plan-b"===e&&Object.defineProperty(this,"sctp",{get(){return void 0===this._sctp?null:this._sctp},enumerable:!0,configurable:!0})}if(i(arguments[0])){const e=r(arguments[0]),t=n(e),i=o(arguments[0],e);let s;s=0===t&&0===i?Number.POSITIVE_INFINITY:0===t||0===i?Math.max(t,i):Math.min(t,i);const a={};Object.defineProperty(a,"maxMessageSize",{get:()=>s}),this._sctp=a}return s.apply(this,arguments)}}function Ue(e){if(!e.RTCPeerConnection||!("createDataChannel"in e.RTCPeerConnection.prototype))return;function t(e,t){const i=e.send;e.send=function(){const r=arguments[0],n=r.length||r.size||r.byteLength;if("open"===e.readyState&&t.sctp&&n>t.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+t.sctp.maxMessageSize+" bytes)");return i.apply(e,arguments)}}const i=e.RTCPeerConnection.prototype.createDataChannel;e.RTCPeerConnection.prototype.createDataChannel=function(){const e=i.apply(this,arguments);return t(e,this),e},A(e,"datachannel",(e=>(t(e.channel,e.target),e)))}function Pe(e){if(!e.RTCPeerConnection||"connectionState"in e.RTCPeerConnection.prototype)return;const t=e.RTCPeerConnection.prototype;Object.defineProperty(t,"connectionState",{get(){return{completed:"connected",checking:"connecting"}[this.iceConnectionState]||this.iceConnectionState},enumerable:!0,configurable:!0}),Object.defineProperty(t,"onconnectionstatechange",{get(){return this._onconnectionstatechange||null},set(e){this._onconnectionstatechange&&(this.removeEventListener("connectionstatechange",this._onconnectionstatechange),delete this._onconnectionstatechange),e&&this.addEventListener("connectionstatechange",this._onconnectionstatechange=e)},enumerable:!0,configurable:!0}),["setLocalDescription","setRemoteDescription"].forEach((e=>{const i=t[e];t[e]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=e=>{const t=e.target;if(t._lastConnectionState!==t.connectionState){t._lastConnectionState=t.connectionState;const i=new Event("connectionstatechange",e);t.dispatchEvent(i)}return e},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),i.apply(this,arguments)}}))}function Me(e,t){if(!e.RTCPeerConnection)return;if("chrome"===t.browser&&t.version>=71)return;if("safari"===t.browser&&t.version>=605)return;const i=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(t){if(t&&t.sdp&&-1!==t.sdp.indexOf("\na=extmap-allow-mixed")){const i=t.sdp.split("\n").filter((e=>"a=extmap-allow-mixed"!==e.trim())).join("\n");e.RTCSessionDescription&&t instanceof e.RTCSessionDescription?arguments[0]=new e.RTCSessionDescription({type:t.type,sdp:i}):t.sdp=i}return i.apply(this,arguments)}}function xe(e,t){if(!e.RTCPeerConnection||!e.RTCPeerConnection.prototype)return;const i=e.RTCPeerConnection.prototype.addIceCandidate;i&&0!==i.length&&(e.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?("chrome"===t.browser&&t.version<78||"firefox"===t.browser&&t.version<68||"safari"===t.browser)&&arguments[0]&&""===arguments[0].candidate?Promise.resolve():i.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}var we=Object.freeze({__proto__:null,shimRTCIceCandidate:De,shimMaxMessageSize:be,shimSendThrowTypeError:Ue,shimConnectionState:Pe,removeExtmapAllowMixed:Me,shimAddIceCandidateNullOrEmpty:xe});const Be=function({window:e}={},t={shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0}){const i=D,r=function(e){const t={browser:null,version:null};if(void 0===e||!e.navigator)return t.browser="Not a browser.",t;const{navigator:i}=e;if(i.mozGetUserMedia)t.browser="firefox",t.version=N(i.userAgent,/Firefox\/(\d+)\./,1);else if(i.webkitGetUserMedia||!1===e.isSecureContext&&e.webkitRTCPeerConnection&&!e.RTCIceGatherer)t.browser="chrome",t.version=N(i.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(i.mediaDevices&&i.userAgent.match(/Edge\/(\d+).(\d+)$/))t.browser="edge",t.version=N(i.userAgent,/Edge\/(\d+).(\d+)$/,2);else{if(!e.RTCPeerConnection||!i.userAgent.match(/AppleWebKit\/(\d+)\./))return t.browser="Not a supported browser.",t;t.browser="safari",t.version=N(i.userAgent,/AppleWebKit\/(\d+)\./,1),t.supportsUnifiedPlan=e.RTCRtpTransceiver&&"currentDirection"in e.RTCRtpTransceiver.prototype}return t}(e),n={browserDetails:r,commonShim:we,extractVersion:N,disableLog:y,disableWarnings:k};switch(r.browser){case"chrome":if(!Y||!$||!t.shimChrome)return i("Chrome shim is not included in this adapter release."),n;if(null===r.version)return i("Chrome shim can not determine version, not shimming."),n;i("adapter.js shimming chrome."),n.browserShim=Y,xe(e,r),B(e,r),V(e),$(e,r),F(e),j(e,r),J(e),G(e),H(e),W(e,r),De(e),Pe(e),be(e,r),Ue(e),Me(e,r);break;case"firefox":if(!Ee||!le||!t.shimFirefox)return i("Firefox shim is not included in this adapter release."),n;i("adapter.js shimming firefox."),n.browserShim=Ee,xe(e,r),de(e,r),le(e,r),_e(e),ge(e),ue(e),he(e),ve(e),pe(e),Re(e),me(e),Ie(e),De(e),Pe(e),be(e,r),Ue(e);break;case"edge":if(!ce||!se||!t.shimEdge)return i("MS edge shim is not included in this adapter release."),n;i("adapter.js shimming edge."),n.browserShim=ce,ne(e),oe(e),se(e,r),ae(e),be(e,r),Ue(e);break;case"safari":if(!ke||!t.shimSafari)return i("Safari shim is not included in this adapter release."),n;i("adapter.js shimming safari."),n.browserShim=ke,xe(e,r),Le(e),Ae(e),fe(e),Se(e),Te(e),Ne(e),Ce(e),ye(e),De(e),be(e,r),Ue(e),Me(e,r);break;default:i("Unsupported browser!")}return n}({window:"undefined"==typeof window?void 0:window});var Ve,Fe,Je;!function(e){e.FPS_10="FPS_10",e.FPS_15="FPS_15",e.FPS_24="FPS_24",e.FPS_30="FPS_30"}(Ve||(Ve={})),function(e){e.W176_H132="W176_H132",e.W176_H144="W176_H144",e.W180_H180="W180_H180",e.W240_H180="W240_H180",e.W240_H240="W240_H240",e.W256_H144="W256_H144",e.W320_H180="W320_H180",e.W320_H240="W320_H240",e.W360_H360="W360_H360",e.W480_H360="W480_H360",e.W480_H480="W480_H480",e.W640_H360="W640_H360",e.W640_H480="W640_H480",e.W720_H480="W720_H480",e.W848_H480="W848_H480",e.W960_H720="W960_H720",e.W1280_H720="W1280_H720",e.W1920_H1080="W1920_H1080",e.W144_H176="W144_H176",e.W144_H256="W144_H256",e.W180_H240="W180_H240",e.W180_H320="W180_H320",e.W240_H320="W240_H320",e.W360_H480="W360_H480",e.W360_H640="W360_H640",e.W480_H640="W480_H640",e.W480_H720="W480_H720",e.W480_H848="W480_H848",e.W720_H1280="W720_H1280",e.W720_H960="W720_H960",e.W1080_H1920="W1080_H1920"}(Fe||(Fe={})),function(e){e[e.AUDIO_ONLY=0]="AUDIO_ONLY",e[e.VIDEO_ONLY=1]="VIDEO_ONLY",e[e.AUDIO_VIDEO=2]="AUDIO_VIDEO"}(Je||(Je={}));const Ge={[Fe.W176_H132]:{width:176,height:132,maxBitrate:150,minBitrate:80},[Fe.W176_H144]:{width:176,height:144,maxBitrate:150,minBitrate:80},[Fe.W180_H180]:{width:180,height:180,maxBitrate:200,minBitrate:100},[Fe.W240_H180]:{width:240,height:180,maxBitrate:240,minBitrate:120},[Fe.W240_H240]:{width:240,height:240,maxBitrate:280,minBitrate:120},[Fe.W256_H144]:{width:256,height:144,maxBitrate:240,minBitrate:120},[Fe.W320_H180]:{width:320,height:180,maxBitrate:280,minBitrate:120},[Fe.W320_H240]:{width:320,height:240,maxBitrate:400,minBitrate:120},[Fe.W360_H360]:{width:360,height:360,maxBitrate:520,minBitrate:140},[Fe.W480_H360]:{width:480,height:360,maxBitrate:650,minBitrate:150},[Fe.W480_H480]:{width:480,height:480,maxBitrate:800,minBitrate:180},[Fe.W640_H360]:{width:640,height:360,maxBitrate:800,minBitrate:180},[Fe.W640_H480]:{width:640,height:480,maxBitrate:900,minBitrate:200},[Fe.W720_H480]:{width:720,height:480,maxBitrate:1e3,minBitrate:200},[Fe.W848_H480]:{width:848,height:480,maxBitrate:1860,minBitrate:200},[Fe.W960_H720]:{width:960,height:720,maxBitrate:2e3,minBitrate:250},[Fe.W1280_H720]:{width:1280,height:720,maxBitrate:2200,minBitrate:250},[Fe.W1920_H1080]:{width:1920,height:1080,maxBitrate:4e3,minBitrate:400},[Fe.W144_H176]:{width:144,height:176,maxBitrate:150,minBitrate:80},[Fe.W144_H256]:{width:144,height:256,maxBitrate:240,minBitrate:120},[Fe.W180_H240]:{width:180,height:240,maxBitrate:240,minBitrate:120},[Fe.W180_H320]:{width:180,height:320,maxBitrate:280,minBitrate:120},[Fe.W240_H320]:{width:240,height:320,maxBitrate:400,minBitrate:120},[Fe.W360_H480]:{width:360,height:480,maxBitrate:650,minBitrate:150},[Fe.W360_H640]:{width:360,height:640,maxBitrate:800,minBitrate:180},[Fe.W480_H640]:{width:480,height:640,maxBitrate:900,minBitrate:200},[Fe.W480_H720]:{width:480,height:720,maxBitrate:1e3,minBitrate:200},[Fe.W480_H848]:{width:480,height:848,maxBitrate:1860,minBitrate:930},[Fe.W720_H1280]:{width:720,height:1280,maxBitrate:2200,minBitrate:250},[Fe.W720_H960]:{width:720,height:960,maxBitrate:2760,minBitrate:910},[Fe.W1080_H1920]:{width:1080,height:1920,maxBitrate:4e3,minBitrate:400}},He=e=>{const t={192:180,368:360,1088:1080};return t[e]?t[e]:e},Ke=(e,t)=>{e=He(e),t=He(t);const i=Ge[`W${e}_H${t}`];if(i)return i;const r=e*t;return Object.keys(Ge).map((e=>Ge[e])).sort(((e,t)=>e.height*e.width-t.width*t.height)).filter((e=>e.height*e.width>=r))[0]||Ge.W1920_H1080},je={10:1,15:1,24:1.5,30:1.5},$e=e=>{let t=Number.MAX_VALUE,i=1;for(const r in je){const n=Math.abs(e-parseInt(r));n<t&&(t=n,i=je[r])}return i};class We{constructor(){this._logger=null}setLogger(e){this._logger=e}getLogger(){return this._logger}createTraceId(){var e;return(null===(e=this._logger)||void 0===e?void 0:e.createTraceId())||`${Date.now()}`}debug(e,t,i){var r;null===(r=this._logger)||void 0===r||r.debug(e,t,i)}info(e,t,i){var r;null===(r=this._logger)||void 0===r||r.info(e,t,i)}warn(e,t,i){var r;null===(r=this._logger)||void 0===r||r.warn(e,t,i)}error(e,t,i){var r;null===(r=this._logger)||void 0===r||r.error(e,t,i)}__statistics(e,t,i){var r;null===(r=this._logger)||void 0===r||r.__statistics(e,t,i)}static setLogger(e){this._logger=e}static getLogger(){return this._logger}}We._logger=null;const Ye=new We,qe={getCameras:()=>S(void 0,void 0,void 0,(function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind))})),getMicrophones:()=>S(void 0,void 0,void 0,(function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"audioinput"===e.kind))})),getSpeakers:()=>S(void 0,void 0,void 0,(function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"audiooutput"===e.kind))}))};var ze,Qe;!function(e){e.AUDIO="audio",e.VIDEO="video"}(ze||(ze={}));class Ze extends e{constructor(e,t,i,r,n){super(),this._tag=e,this._userId=t,this._kind=i,this._isLocalTrack=r,this._roomId=n,this._localMuted=!1,this._remoteMuted=!1,this._logger=null,this.DataTrackId="data-track-id",this._streamId=[this._userId||this._roomId,this._tag].join("_"),this._id=[this._streamId,this.isAudioTrack()?0:1].join("_"),this._logger=We.getLogger()}getStreamId(){return this._streamId}getTrackId(){return this._id}getUserId(){return this._userId}__innerGetMediaStreamTrack(){return this._msTrack}get streamTrack(){return this._msTrack}getTag(){return this._tag}isLocalTrack(){return this._isLocalTrack}isVideoTrack(){return"video"===this._kind}isAudioTrack(){return"audio"===this._kind}isReady(){var e;return"live"===(null===(e=this._msTrack)||void 0===e?void 0:e.readyState)}__innerSetMediaStreamTrack(e){this._msTrack=e,this._setLocalMuted(this._localMuted);const t=this._msStream=this._msStream||new MediaStream,i=t.getTracks()[0];i&&t.removeTrack(i),e?t.addTrack(e):this._element&&this._element.getAttribute(this.DataTrackId)===this.getTrackId()&&(this._element.pause(),this._element.srcObject=null)}_setLocalMuted(e){this._msTrack&&(this._msTrack.enabled=!e),this._localMuted=e}mute(){return this._setLocalMuted(!0)}unmute(){return this._setLocalMuted(!1)}isLocalMuted(){return this._localMuted}isMCUTrack(){return Boolean(this._roomId)}isOwnerMuted(){return this._remoteMuted}play(e,i){var r,n,o,s,a,c,d,_,l,u,h,g,v;return S(this,void 0,void 0,(function*(){if(null===(r=this._logger)||void 0===r||r.info(f.L_TRACK_PLAY_O,JSON.stringify({element:e,options:i,kind:null!==(n=this._kind)&&void 0!==n?n:"",msg:`start play trackId: ${this._id}`})),!this._msTrack)return null===(o=this._logger)||void 0===o||o.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,code:T.TRACK_NOT_READY,kind:null!==(s=this._kind)&&void 0!==s?s:"",msg:`the track is not ready to play -> id: ${this._id}`})),{code:T.TRACK_NOT_READY};if("ended"===this._msTrack.readyState&&(null===(a=this._logger)||void 0===a||a.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,kind:null!==(c=this._kind)&&void 0!==c?c:"",msg:`the track's readyState is ended -> id: ${this._id}`}))),null==i?void 0:i.volume){if(!t(null==i?void 0:i.volume))return null===(d=this._logger)||void 0===d||d.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> options.volume not a number"})),{code:T.PARAMS_ERROR};(null==i?void 0:i.volume)<0&&(i.volume=0,null===(_=this._logger)||void 0===_||_.warn(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,msg:"params error -> options.volume < 0",tips:"the valid range of options.volume is 0-100, the value of volume has been set 0"}))),(null==i?void 0:i.volume)>100&&(i.volume=100,null===(l=this._logger)||void 0===l||l.warn(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,msg:"params error -> options.volume > 100",tips:"the valid range of options.volume is 0-100, the value of volume has been set 100"})))}if(null==i?void 0:i.audioDeviceId){if(!(yield qe.getSpeakers()).map((e=>e.deviceId)).includes(i.audioDeviceId))return null===(u=this._logger)||void 0===u||u.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> options.audioDeviceId"})),{code:T.PARAMS_ERROR}}const p=this.isVideoTrack();return!p||e&&(e instanceof HTMLVideoElement||this.__validateVideoNodeName(e))?(this._element=p?e:new Audio,this._localMuted&&this._setLocalMuted(!1),this._element.srcObject&&this._element.srcObject===this._msStream||this._element.pause(),this._element.onloadstart=e=>{var t,i,r;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_LOAD_START_O,JSON.stringify({status:C.INFO,kind:null!==(i=this._kind)&&void 0!==i?i:"",msg:`HTMLMediaElement onloadstart -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, trackId: ${this._id}`}))},this._element.ondurationchange=e=>{var t,i,r;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_DURATION_CHANGE_O,JSON.stringify({status:C.INFO,kind:null!==(i=this._kind)&&void 0!==i?i:"",msg:`HTMLMediaElement ondurationchange -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, trackId: ${this._id}`}))},this._element.onloadedmetadata=e=>{var t,i,r;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_LOADED_META_DATA_O,JSON.stringify({status:C.INFO,kind:null!==(i=this._kind)&&void 0!==i?i:"",msg:`HTMLMediaElement onloadedmetadata -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, trackId: ${this._id}`}))},this._element.onloadeddata=e=>{var t,i,r;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_LOADED_DATA_O,JSON.stringify({status:C.INFO,kind:null!==(i=this._kind)&&void 0!==i?i:"",msg:`HTMLMediaElement onloadeddata -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, trackId: ${this._id}`}))},this._element.onabort=e=>{var t,i,r;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_ABORT_O,JSON.stringify({status:C.INFO,kind:null!==(i=this._kind)&&void 0!==i?i:"",msg:`HTMLMediaElement onabort -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, trackId: ${this._id}`}))},this._element.oncanplay=e=>S(this,void 0,void 0,(function*(){var t,r,n,o,s,a,c,d;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_CANPLAY_O,JSON.stringify({status:C.INFO,kind:null!==(r=this._kind)&&void 0!==r?r:"",msg:`HTMLMediaElement oncanplay -> id: ${null===(n=e.target)||void 0===n?void 0:n.id}, trackId: ${this._id}`}));try{(null==i?void 0:i.audioDeviceId)&&!p&&(yield this._element.setSinkId(i.audioDeviceId)),yield null===(o=this._element)||void 0===o?void 0:o.play()}catch(e){if("No permission to use requested device"===e.message)return void(null===(s=this._logger)||void 0===s||s.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,kind:null!==(a=this._kind)&&void 0!==a?a:"",code:T.NO_PERMISSION_TO_USE_REQUESTED_DEVICE,msg:`setSinkId failed, error msg: ${e.message}`})));null===(c=this._logger)||void 0===c||c.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,code:T.TRACK_PLAY_ERROR,kind:null!==(d=this._kind)&&void 0!==d?d:"",msg:`play error, error msg: ${e.message}`}))}})),this._element.onvolumechange=e=>{var t,i,r;const n=Math.floor(100*(null===(t=e.target)||void 0===t?void 0:t.volume));null===(i=this._logger)||void 0===i||i.info(f.L_TRACK_VOLUME_CHANGE_O,JSON.stringify({status:C.INFO,msg:`HTMLMediaElement onvolumechange -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, volume: ${n}, trackId: ${this._id}`}))},this._element.srcObject=this._msStream,this._element.autoplay=!0,p&&(this._element.playsInline=!0,this._element.x5PlaysInline=!0,this._element.webkitPlaysInline=!0),(null==i?void 0:i.audioDeviceId)&&!p&&(yield this._element.setSinkId(i.audioDeviceId)),p||!(null==i?void 0:i.volume)&&0!==(null==i?void 0:i.volume)||(this._element.volume=(null==i?void 0:i.volume)/100),null===(v=this._element)||void 0===v||v.setAttribute(this.DataTrackId,this.getTrackId()),{code:T.SUCCESS}):(null===(h=this._logger)||void 0===h||h.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,code:T.VIDEO_TRACK_MISS_MEDIA_ELEMENT,kind:null!==(g=this._kind)&&void 0!==g?g:"",msg:"params element is not a HTMLVideoElement"})),{code:T.VIDEO_TRACK_MISS_MEDIA_ELEMENT})}))}__innerDestroy(){this.__innerSetMediaStreamTrack(void 0)}__releaseMediaElement(){this._element&&this._element.getAttribute(this.DataTrackId)===this.getTrackId()&&(this._element.remove(),this._element.srcObject=null)}__validateVideoNodeName(e){return e&&e.nodeName&&"VIDEO"===e.nodeName.toUpperCase()}}!function(e){e.Speech="Speech",e.Music="Music",e.MusicHigh="MusicHigh"}(Qe||(Qe={}));const Xe={[Qe.Music]:{max:64,min:64},[Qe.MusicHigh]:{max:128,min:128},[Qe.Speech]:{max:32,min:32}};var et;!function(e){e.LEVEL0="LEVEL0",e.LEVEL1="LEVEL1",e.LEVEL2="LEVEL2",e.LEVEL3="LEVEL3",e.LEVEL4="LEVEL4",e.LEVEL5="LEVEL5"}(et||(et={}));const tt={[et.LEVEL0]:{max:150,min:80},[et.LEVEL1]:{max:280,min:120},[et.LEVEL2]:{max:650,min:150},[et.LEVEL3]:{max:1e3,min:200},[et.LEVEL4]:{max:2200,min:250},[et.LEVEL5]:{max:4e3,min:400}};class it{static setStatus(e=!0){it.isOpen=e}static setWroklet(e,t){it.workletModule=e,it.workletModule=t}static transformStreamTrack(e){var t;return S(this,void 0,void 0,(function*(){const i=We.getLogger();if(!it.isOpen)return new Promise((t=>{t({track:null==e?void 0:e.getAudioTracks()[0],stop:()=>{}})}));let r=new AudioContext({sampleRate:44100}),n=r.createMediaStreamSource(e),o=r.createMediaStreamDestination(),s=null,a=null;if(s=yield r.audioWorklet.addModule(it.workletModule).then((()=>(null==i||i.info(f.L_RTC_3ANOISE_NODE_O,JSON.stringify({status:C.SUCCESSED,message:{msg:"addModule RC3AnoiseTrack.workletModule success"}})),fetch(it.workletWasm,{cache:"force-cache",credentials:"same-origin"}).then((e=>e.arrayBuffer())).catch((e=>{throw new Error(e.message)}))))).then((e=>(a=new AudioWorkletNode(r,"process-worklet",{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[1],processorOptions:{binary:e}}),a))).catch((e=>{null==i||i.info(f.L_RTC_3ANOISE_NODE_E,JSON.stringify({status:C.FAILED,message:{msg:e.message}}))})),!s)return new Promise((t=>{t({track:null==e?void 0:e.getAudioTracks()[0],stop:()=>{}})}));n.connect(s).connect(o);let c=null===(t=null==o?void 0:o.stream)||void 0===t?void 0:t.getAudioTracks()[0],d=()=>{null==i||i.info(f.L_RTC_3ANOISE_NODE_STOP_O,JSON.stringify({status:C.SUCCESSED,message:{msg:"call stop RC3AnoiseTrack.workletModule"}})),null==s||s.port.postMessage({type:"stop",msg:""}),setTimeout((()=>{const t=null==e?void 0:e.getAudioTracks()[0];null==t||t.stop(),null==r||r.suspend(),null==r||r.close(),null==o||o.disconnect(),null==s||s.disconnect(),null==n||n.disconnect(),r=null,s=null,o=null,n=null,a=null,e=null,null==c||c.stop(),c=null,d=null}),200)};return{track:c,stop:d}}))}}it.workletModule="https://cdn.ronghub.com/plugin-rtc/wasm/5.0.0-alpha.2/process-worklet.js",it.workletWasm="https://cdn.ronghub.com/plugin-rtc/wasm/5.0.0-alpha.2/AudioProcessing.wasm",it.isOpen=!1;class rt extends Ze{constructor(e,t,i,r){super(e,t,i,!0),this._isDestroyed=!1,this._isPublished=!1,this.__innerSetMediaStreamTrack(r),r.onended=()=>{r.onended=null,this.emit(rt.EVENT_LOCAL_TRACK_END,this),this.removeAll(rt.EVENT_LOCAL_TRACK_END)}}_setLocalMuted(e){return new Promise(((t,i)=>{var r;const n=this._localMuted!==e;super._setLocalMuted(e),this._remoteMuted=this._localMuted,n&&this.emit(rt.__INNER_EVENT_MUTED_CHANGE__,this,t),null===(r=this._logger)||void 0===r||r.info(f.L_LOCAL_TRACK_SET_LOCAL_MUTED_O,JSON.stringify({enable:e,trackId:this._id}))}))}__innerSetPublished(e){this._isPublished=e}isPublished(){return this._isPublished}destroy(){var e,t;this._isDestroyed=!0,null===(e=this._msTrack)||void 0===e||e.stop(),super.__innerDestroy(),this.isAudioTrack()&&super.__releaseMediaElement(),this.emit(rt.__INNER_EVENT_DESTROY__,this),null===(t=this._logger)||void 0===t||t.info(f.L_LOCAL_TRACK_DESTROY_O,JSON.stringify({status:C.SUCCESSED,trackId:this._id}))}isDestroyed(){return this._isDestroyed}setBitrate(e=0,i=0,r=0){var n,o;!t(e)||!t(i)||!t(r)||e<=0||i<=0||e<i?null===(n=this._logger)||void 0===n||n.error(f.L_LOCAL_TRACK_SET_BITRATE_O,JSON.stringify({status:C.FAILED,msg:`params error -> max: ${e},min: ${i}, start: ${r}`,trackId:this._id})):(null===(o=this._logger)||void 0===o||o.info(f.L_LOCAL_TRACK_SET_BITRATE_O,JSON.stringify({status:C.SUCCESSED,max:e,min:i,start:r,trackId:this._id})),this._bitrateInfo={max:e,min:i,start:r})}getBitrate(){var e,t,i,r,n,o,s;let{min:a,max:c,start:d}={min:0,max:0,start:0};return(null===(e=this._msTrack)||void 0===e?void 0:e.kind)===ze.VIDEO?({min:a,max:c}=Tt(this._msTrack)):(null===(t=this._msTrack)||void 0===t?void 0:t.kind)===ze.AUDIO&&({min:a,max:c}={min:32,max:32}),(null===(i=this._bitrateInfo)||void 0===i?void 0:i.max)&&(d=.7*(null===(r=this._bitrateInfo)||void 0===r?void 0:r.max)),{min:(null===(n=this._bitrateInfo)||void 0===n?void 0:n.min)||a,max:(null===(o=this._bitrateInfo)||void 0===o?void 0:o.max)||c,start:(null===(s=this._bitrateInfo)||void 0===s?void 0:s.start)||d}}}rt.EVENT_LOCAL_TRACK_END="local-track-end",rt.__INNER_EVENT_MUTED_CHANGE__="inner-muted-change",rt.__INNER_EVENT_DESTROY__="inner-destroy";class nt extends rt{constructor(e,t,i){super(e,t,"audio",i),this._stopProcess=()=>{}}setRecommendBitrate(e){const t=We.getLogger();if(!i("audioBitrate",e,(e=>e in Qe)))return void(null==t||t.warn(f.L_RTC_SET_RECOMMEND_BITRATE_O,JSON.stringify({status:C.FAILED,msg:"params error -> params type is RCAudioBitrate"})));const r=Xe[e];this.setBitrate(r.max,r.min,r.start||.7*r.max)}setBitrate(e,...t){const[i=1,r=.7*e||1]=t;super.setBitrate(e,i,r)}__innerSetMediaStreamTrack(e){if(e)if(it.isOpen){const t=new MediaStream([e]);it.transformStreamTrack(t).then((({track:e,stop:t})=>{super.__innerSetMediaStreamTrack(e),this._stopProcess=t}))}else super.__innerSetMediaStreamTrack(e);else super.__innerSetMediaStreamTrack(e),this._stopProcess()}}class ot extends rt{constructor(e,t,i,r=!1){super(e,t,"video",i),this._isTiny=r}__isTiny(){return this._isTiny}getStreamId(){const e=super.getStreamId();return this._isTiny?`${e}_tiny`:e}getTrackId(){const e=super.getTrackId();return this._isTiny?`${e}_tiny`:e}setRecommendBitrate(e){const t=We.getLogger();if(!i("videoBitrate",e,(e=>e in et)))return void(null==t||t.warn(f.L_RTC_SET_RECOMMEND_BITRATE_O,JSON.stringify({status:C.FAILED,msg:"params error -> params type is RCVideoBitrate"})));const r=tt[e];this.setBitrate(r.max,r.min,r.start||.7*r.max)}setBitrate(e,...t){const[i=1,r=.7*e||1]=t;super.setBitrate(e,i,r)}}class st extends rt{static __innerSetMapping(e,t){const i=this._mapping.get(t)||[];i.push(e),this._mapping.set(t,i)}static __innerRemoveMapping(e,t){var i,r;const n=null===(i=this._mapping.get(t))||void 0===i?void 0:i.filter((t=>t!==e));n&&n.length>0?this._mapping.set(t,n):(this._mapping.delete(t),t.pause(),t.src="",null===(r=t.parentNode)||void 0===r||r.removeChild(t))}constructor(e,t,i,r,n){super(e,t,i,r),this._resource=n,st.__innerSetMapping(this.getTrackId(),n)}destroy(){this.isAudioTrack()&&this.mute(),st.__innerRemoveMapping(this.getTrackId(),this._resource),super.destroy()}}st._mapping=new Map;class at extends st{constructor(e,t,i,r){super(e,t,"video",i,r)}}class ct extends st{constructor(e,t,i,r){super(e,t,"audio",i,r),this._stopProcess=()=>{}}_setLocalMuted(e){const t=Object.create(null,{_setLocalMuted:{get:()=>super._setLocalMuted}});return S(this,void 0,void 0,(function*(){return this._resource&&(this._resource.muted=e),t._setLocalMuted.call(this,e)}))}play(){return this._setLocalMuted(!1),Promise.resolve({code:T.SUCCESS})}__innerSetMediaStreamTrack(e){if(e)if(it.isOpen){const t=new MediaStream([e]);it.transformStreamTrack(t).then((({track:e,stop:t})=>{super.__innerSetMediaStreamTrack(e),this._stopProcess=t}))}else super.__innerSetMediaStreamTrack(e);else super.__innerSetMediaStreamTrack(e),this._stopProcess()}}class dt extends nt{}class _t extends ot{}class lt extends ot{}class ut extends nt{}class ht extends Ze{constructor(e,t,i,r){super(e,t,i,!1,r),this._isSubscribed=!1}__innerSetRemoteMuted(e){this._remoteMuted=e}__innerSetSubscribed(e){this._isSubscribed=e}isSubscribed(){return this._isSubscribed}}class gt extends ht{constructor(e,t,i){super(e,t,"audio",i)}}class vt extends ht{constructor(e,t,i){super(e,t,"video",i),this._isSubTiny=!1}__innerSetIsTinyTrack(e){this._isSubTiny=e}isSubTiny(){return this._isSubTiny}}const pt=(e,t)=>({name:e,content:JSON.stringify({uris:t,ignore:!0})}),Rt=e=>JSON.stringify(e),mt=e=>/^[a-zA-Z\d-=]+$/g.test(e),It="http:"!==location.protocol||["localhost","127.0.0.1"].includes(location.hostname),Et=e=>{if(void 0===e)return 0;if(t(e))return e;const i=e;return i.exact||i.ideal||i.max||0},St=e=>{const t=e.getSettings(),i=e.getConstraints();return{width:Et(i.width)||t.width||0,height:Et(i.height)||t.height||0,frameRate:t.frameRate||Et(i.frameRate)}},Tt=e=>{const{width:t,height:i,frameRate:r}=St(e),n=Ke(t||1920,i||1080),o=$e(r);return{min:n.minBitrate*o,max:n.maxBitrate*o}},ft=e=>[e.msid,e.mediaType].join("_"),Ct=e=>{const t=e.split("_");return{mediaType:parseInt(t.pop()),tag:t.pop(),userId:t.join("_")}},Ot=(e,t)=>[e,t].join("_"),Lt=e=>e.map((e=>Object.assign({},e))),Nt=(e,t,i=!1)=>{e=e.slice();const r=[],n=[],o=[];return t.forEach((t=>{const n=ft(t);let s=e.findIndex((e=>ft(e)===n));if(i&&(s=e.findIndex((e=>e.uri===t.uri))),-1===s)return void r.push(t);const a=e[s];a.uri!==t.uri?r.push(t):a.state!==t.state&&o.push(t),e.splice(s,1)})),n.push(...e),{publishedList:r,unpublishedList:n,modifiedList:o}},At=()=>{let e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}));return e=`${e.replace(/-/g,"")}0`,e=parseInt(e,16),e=(e=>{const t="0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ+/".split(""),i=t.length+1;let r=+e;const n=[];do{const e=r%i;r=(r-e)/i,n.unshift(t[e])}while(r);return n.join("")})(e),e.length>22&&(e=e.slice(0,22)),e},yt=e=>{if(Ge[e]){const{width:t,height:i}=Ge[e];return{width:t,height:i}}const[t,i]=e.split("_").map((e=>parseInt(e.replace(/[^\d]/g,""))));return{width:t,height:i}},kt=e=>!!Fe[e],Dt=e=>!!Ve[e],bt=e=>parseInt(e.replace("FPS_","")),Ut=(()=>{const{browser:e,version:t,supportsUnifiedPlan:i}=Be.browserDetails;return{browser:e,version:t,supportsUnifiedPlan:!1!==i}})();function Pt(){return"captureStream"in HTMLMediaElement.prototype||"mozCaptureStream"in HTMLMediaElement.prototype}function Mt(){return"mediaDevices"in navigator&&"getDisplayMedia"in navigator.mediaDevices}const xt=e=>"[object Null]"===Object.prototype.toString.call(e),wt=e=>1===e.type,Bt=(e,t,i)=>{const r={},n=Object.keys(e.users);return n.length&&n.forEach((n=>{const o=[],s=e.users[n];if(s.extra){const{roomId:e}=JSON.parse(s.extra);if(t!==e)return}if(s.uris)try{o.push(...JSON.parse(s.uris))}catch(e){const t=We.getLogger();null==t||t.warn(f.L_PARSE_ROOMDATA_URIS_R,`invalid user data -> userId: ${n}, userData: ${s}`,i)}r[n]=o})),r},Vt=e=>e instanceof Ze?e.getTrackId():e.track.getTrackId(),Ft=e=>{if(!r(e)||void 0===e.low||void 0===e.high)return e;let{low:t}=e;t<0&&(t+=4294967296),t=t.toString(16);return parseInt(e.high.toString(16)+"00000000".replace(new RegExp(`0{${t.length}}$`),t),16)};var Jt,Gt;!function(e){e.PUBLISH="RCRTC:PublishResource",e.UNPUBLISH="RCRTC:UnpublishResource",e.MODIFY="RCRTC:ModifyResource",e.TOTAL_CONTENT_RESOURCE="RCRTC:TotalContentResources",e.STATE="RCRTC:state",e.ROOM_NOTIFY="RCRTC:RoomNtf",e.USER_NOTIFY="RCRTC:UserNtf",e.KICK="RCRTC:kick",e.PK_INVITE="RCRTC:invite",e.PK_INVITE_TIMEOUT="RCRTC:inviteTimeout",e.PK_CANCEL_INVITE="RCRTC:cancelInvite",e.PK_INVITE_ANSWER="RCRTC:answerInvite",e.PK_END="RCRTC:endInvite",e.OTHER_ROOM_OFFLINE="RCRTC:otherRoomOffline",e.ROOM_TASK_FINISH="RCRTC:roomTaskFinish"}(Jt||(Jt={})),function(e){e.SUCCESS="Success",e.FAIL="Fail"}(Gt||(Gt={}));class Ht{constructor(e,t,i=5e3,r=6e4){this._store=e,this._context=t,this._gap=i,this._offlineKickTime=r,this._latestTimestamp=Date.now(),this._started=!1,this._timer=null,this._pullRTCRoomStatus=(e,t,i)=>{};const{roomId:n,roomMode:o}=this._store;this._roomId=n,this._roomMode=o,this._offlineKickTime<15e3&&(this._offlineKickTime=15e3)}start(e){var t,i;this._pullRTCRoomStatus=e,this._started||(null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_PINGER_START_O,JSON.stringify({interval:this._gap,offlineKickTime:this._offlineKickTime})),this._started=!0,this._checkAlive())}_sendPing(e){return new Promise((t=>{this._context.rtcPing(this._roomId,this._roomMode).then(t).catch((i=>{var r,o;null===(o=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===o||o.error(f.L_PINGER_SEND_RTCPING_R,JSON.stringify({status:C.FAILED,msg:i}),e),t({code:n.UNKNOWN})})),setTimeout(t,5e3,n.TIMEOUT)}))}_diffPullRTCRoomStatus(e){var t,i,r,n;if(e>this._store.getRoomStatusVersion()){const o=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_RTCPING_PULL_ROOM_STATUS_O,JSON.stringify({pingerVersion:e}),o),this._pullRTCRoomStatus(this._roomId,o,e)}}_checkAlive(){var e,t,i,r,o,s,a,c,d,_,l;return S(this,void 0,void 0,(function*(){const u=null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t?void 0:t.createTraceId();null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_PINGER_SEND_RTCPING_T,JSON.stringify({roomId:this._roomId}),u);const{code:h,data:g}=yield this._sendPing(u),v=Date.now();return h===n.SUCCESS?(this._diffPullRTCRoomStatus(g.version),null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_PINGER_SEND_RTCPING_R,JSON.stringify({roomId:this._roomId,status:C.SUCCESSED}),u),this._latestTimestamp=v,null===(a=this.onPingResult)||void 0===a||a.call(this,Gt.SUCCESS),void(this._timer=setTimeout((()=>this._checkAlive()),this._gap))):(null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_PINGER_SEND_RTCPING_R,JSON.stringify({roomId:this._roomId,status:C.FAILED,code:h}),u),null===(_=this.onPingResult)||void 0===_||_.call(this,Gt.FAIL),40003===h||v-this._latestTimestamp>this._offlineKickTime?(this.stop(),void(null===(l=this.onFailed)||void 0===l||l.call(this,40003===h))):void(this._timer=setTimeout((()=>this._checkAlive()),500)))}))}stop(){var e,t;this._started&&(null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_PINGER_STOP_O),this._started=!1,this._timer&&(clearTimeout(this._timer),this._timer=null))}}
16
- /*! pako 2.0.4 https://github.com/nodeca/pako @license (MIT AND Zlib) */function Kt(e){let t=e.length;for(;--t>=0;)e[t]=0}const jt=256,$t=286,Wt=30,Yt=15,qt=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),zt=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),Qt=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),Zt=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Xt=new Array(576);Kt(Xt);const ei=new Array(60);Kt(ei);const ti=new Array(512);Kt(ti);const ii=new Array(256);Kt(ii);const ri=new Array(29);Kt(ri);const ni=new Array(Wt);function oi(e,t,i,r,n){this.static_tree=e,this.extra_bits=t,this.extra_base=i,this.elems=r,this.max_length=n,this.has_stree=e&&e.length}let si,ai,ci;function di(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}Kt(ni);const _i=e=>e<256?ti[e]:ti[256+(e>>>7)],li=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},ui=(e,t,i)=>{e.bi_valid>16-i?(e.bi_buf|=t<<e.bi_valid&65535,li(e,e.bi_buf),e.bi_buf=t>>16-e.bi_valid,e.bi_valid+=i-16):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=i)},hi=(e,t,i)=>{ui(e,i[2*t],i[2*t+1])},gi=(e,t)=>{let i=0;do{i|=1&e,e>>>=1,i<<=1}while(--t>0);return i>>>1},vi=(e,t,i)=>{const r=new Array(16);let n,o,s=0;for(n=1;n<=Yt;n++)r[n]=s=s+i[n-1]<<1;for(o=0;o<=t;o++){let t=e[2*o+1];0!==t&&(e[2*o]=gi(r[t]++,t))}},pi=e=>{let t;for(t=0;t<$t;t++)e.dyn_ltree[2*t]=0;for(t=0;t<Wt;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0},Ri=e=>{e.bi_valid>8?li(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},mi=(e,t,i,r)=>{const n=2*t,o=2*i;return e[n]<e[o]||e[n]===e[o]&&r[t]<=r[i]},Ii=(e,t,i)=>{const r=e.heap[i];let n=i<<1;for(;n<=e.heap_len&&(n<e.heap_len&&mi(t,e.heap[n+1],e.heap[n],e.depth)&&n++,!mi(t,r,e.heap[n],e.depth));)e.heap[i]=e.heap[n],i=n,n<<=1;e.heap[i]=r},Ei=(e,t,i)=>{let r,n,o,s,a=0;if(0!==e.last_lit)do{r=e.pending_buf[e.d_buf+2*a]<<8|e.pending_buf[e.d_buf+2*a+1],n=e.pending_buf[e.l_buf+a],a++,0===r?hi(e,n,t):(o=ii[n],hi(e,o+jt+1,t),s=qt[o],0!==s&&(n-=ri[o],ui(e,n,s)),r--,o=_i(r),hi(e,o,i),s=zt[o],0!==s&&(r-=ni[o],ui(e,r,s)))}while(a<e.last_lit);hi(e,256,t)},Si=(e,t)=>{const i=t.dyn_tree,r=t.stat_desc.static_tree,n=t.stat_desc.has_stree,o=t.stat_desc.elems;let s,a,c,d=-1;for(e.heap_len=0,e.heap_max=573,s=0;s<o;s++)0!==i[2*s]?(e.heap[++e.heap_len]=d=s,e.depth[s]=0):i[2*s+1]=0;for(;e.heap_len<2;)c=e.heap[++e.heap_len]=d<2?++d:0,i[2*c]=1,e.depth[c]=0,e.opt_len--,n&&(e.static_len-=r[2*c+1]);for(t.max_code=d,s=e.heap_len>>1;s>=1;s--)Ii(e,i,s);c=o;do{s=e.heap[1],e.heap[1]=e.heap[e.heap_len--],Ii(e,i,1),a=e.heap[1],e.heap[--e.heap_max]=s,e.heap[--e.heap_max]=a,i[2*c]=i[2*s]+i[2*a],e.depth[c]=(e.depth[s]>=e.depth[a]?e.depth[s]:e.depth[a])+1,i[2*s+1]=i[2*a+1]=c,e.heap[1]=c++,Ii(e,i,1)}while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],((e,t)=>{const i=t.dyn_tree,r=t.max_code,n=t.stat_desc.static_tree,o=t.stat_desc.has_stree,s=t.stat_desc.extra_bits,a=t.stat_desc.extra_base,c=t.stat_desc.max_length;let d,_,l,u,h,g,v=0;for(u=0;u<=Yt;u++)e.bl_count[u]=0;for(i[2*e.heap[e.heap_max]+1]=0,d=e.heap_max+1;d<573;d++)_=e.heap[d],u=i[2*i[2*_+1]+1]+1,u>c&&(u=c,v++),i[2*_+1]=u,_>r||(e.bl_count[u]++,h=0,_>=a&&(h=s[_-a]),g=i[2*_],e.opt_len+=g*(u+h),o&&(e.static_len+=g*(n[2*_+1]+h)));if(0!==v){do{for(u=c-1;0===e.bl_count[u];)u--;e.bl_count[u]--,e.bl_count[u+1]+=2,e.bl_count[c]--,v-=2}while(v>0);for(u=c;0!==u;u--)for(_=e.bl_count[u];0!==_;)l=e.heap[--d],l>r||(i[2*l+1]!==u&&(e.opt_len+=(u-i[2*l+1])*i[2*l],i[2*l+1]=u),_--)}})(e,t),vi(i,d,e.bl_count)},Ti=(e,t,i)=>{let r,n,o=-1,s=t[1],a=0,c=7,d=4;for(0===s&&(c=138,d=3),t[2*(i+1)+1]=65535,r=0;r<=i;r++)n=s,s=t[2*(r+1)+1],++a<c&&n===s||(a<d?e.bl_tree[2*n]+=a:0!==n?(n!==o&&e.bl_tree[2*n]++,e.bl_tree[32]++):a<=10?e.bl_tree[34]++:e.bl_tree[36]++,a=0,o=n,0===s?(c=138,d=3):n===s?(c=6,d=3):(c=7,d=4))},fi=(e,t,i)=>{let r,n,o=-1,s=t[1],a=0,c=7,d=4;for(0===s&&(c=138,d=3),r=0;r<=i;r++)if(n=s,s=t[2*(r+1)+1],!(++a<c&&n===s)){if(a<d)do{hi(e,n,e.bl_tree)}while(0!=--a);else 0!==n?(n!==o&&(hi(e,n,e.bl_tree),a--),hi(e,16,e.bl_tree),ui(e,a-3,2)):a<=10?(hi(e,17,e.bl_tree),ui(e,a-3,3)):(hi(e,18,e.bl_tree),ui(e,a-11,7));a=0,o=n,0===s?(c=138,d=3):n===s?(c=6,d=3):(c=7,d=4)}};let Ci=!1;const Oi=(e,t,i,r)=>{ui(e,0+(r?1:0),3),((e,t,i,r)=>{Ri(e),r&&(li(e,i),li(e,~i)),e.pending_buf.set(e.window.subarray(t,t+i),e.pending),e.pending+=i})(e,t,i,!0)};var Li=(e,t,i,r)=>{let n,o,s=0;e.level>0?(2===e.strm.data_type&&(e.strm.data_type=(e=>{let t,i=4093624447;for(t=0;t<=31;t++,i>>>=1)if(1&i&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t<jt;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0})(e)),Si(e,e.l_desc),Si(e,e.d_desc),s=(e=>{let t;for(Ti(e,e.dyn_ltree,e.l_desc.max_code),Ti(e,e.dyn_dtree,e.d_desc.max_code),Si(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*Zt[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),n=e.opt_len+3+7>>>3,o=e.static_len+3+7>>>3,o<=n&&(n=o)):n=o=i+5,i+4<=n&&-1!==t?Oi(e,t,i,r):4===e.strategy||o===n?(ui(e,2+(r?1:0),3),Ei(e,Xt,ei)):(ui(e,4+(r?1:0),3),((e,t,i,r)=>{let n;for(ui(e,t-257,5),ui(e,i-1,5),ui(e,r-4,4),n=0;n<r;n++)ui(e,e.bl_tree[2*Zt[n]+1],3);fi(e,e.dyn_ltree,t-1),fi(e,e.dyn_dtree,i-1)})(e,e.l_desc.max_code+1,e.d_desc.max_code+1,s+1),Ei(e,e.dyn_ltree,e.dyn_dtree)),pi(e),r&&Ri(e)},Ni={_tr_init:e=>{Ci||((()=>{let e,t,i,r,n;const o=new Array(16);for(i=0,r=0;r<28;r++)for(ri[r]=i,e=0;e<1<<qt[r];e++)ii[i++]=r;for(ii[i-1]=r,n=0,r=0;r<16;r++)for(ni[r]=n,e=0;e<1<<zt[r];e++)ti[n++]=r;for(n>>=7;r<Wt;r++)for(ni[r]=n<<7,e=0;e<1<<zt[r]-7;e++)ti[256+n++]=r;for(t=0;t<=Yt;t++)o[t]=0;for(e=0;e<=143;)Xt[2*e+1]=8,e++,o[8]++;for(;e<=255;)Xt[2*e+1]=9,e++,o[9]++;for(;e<=279;)Xt[2*e+1]=7,e++,o[7]++;for(;e<=287;)Xt[2*e+1]=8,e++,o[8]++;for(vi(Xt,287,o),e=0;e<Wt;e++)ei[2*e+1]=5,ei[2*e]=gi(e,5);si=new oi(Xt,qt,257,$t,Yt),ai=new oi(ei,zt,0,Wt,Yt),ci=new oi(new Array(0),Qt,0,19,7)})(),Ci=!0),e.l_desc=new di(e.dyn_ltree,si),e.d_desc=new di(e.dyn_dtree,ai),e.bl_desc=new di(e.bl_tree,ci),e.bi_buf=0,e.bi_valid=0,pi(e)},_tr_stored_block:Oi,_tr_flush_block:Li,_tr_tally:(e,t,i)=>(e.pending_buf[e.d_buf+2*e.last_lit]=t>>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&i,e.last_lit++,0===t?e.dyn_ltree[2*i]++:(e.matches++,t--,e.dyn_ltree[2*(ii[i]+jt+1)]++,e.dyn_dtree[2*_i(t)]++),e.last_lit===e.lit_bufsize-1),_tr_align:e=>{ui(e,2,3),hi(e,256,Xt),(e=>{16===e.bi_valid?(li(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)})(e)}};var Ai=(e,t,i,r)=>{let n=65535&e|0,o=e>>>16&65535|0,s=0;for(;0!==i;){s=i>2e3?2e3:i,i-=s;do{n=n+t[r++]|0,o=o+n|0}while(--s);n%=65521,o%=65521}return n|o<<16|0};const yi=new Uint32Array((()=>{let e,t=[];for(var i=0;i<256;i++){e=i;for(var r=0;r<8;r++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t})());var ki=(e,t,i,r)=>{const n=yi,o=r+i;e^=-1;for(let i=r;i<o;i++)e=e>>>8^n[255&(e^t[i])];return-1^e},Di={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},bi={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:Ui,_tr_stored_block:Pi,_tr_flush_block:Mi,_tr_tally:xi,_tr_align:wi}=Ni,{Z_NO_FLUSH:Bi,Z_PARTIAL_FLUSH:Vi,Z_FULL_FLUSH:Fi,Z_FINISH:Ji,Z_BLOCK:Gi,Z_OK:Hi,Z_STREAM_END:Ki,Z_STREAM_ERROR:ji,Z_DATA_ERROR:$i,Z_BUF_ERROR:Wi,Z_DEFAULT_COMPRESSION:Yi,Z_FILTERED:qi,Z_HUFFMAN_ONLY:zi,Z_RLE:Qi,Z_FIXED:Zi,Z_DEFAULT_STRATEGY:Xi,Z_UNKNOWN:er,Z_DEFLATED:tr}=bi,ir=258,rr=262,nr=103,or=113,sr=666,ar=(e,t)=>(e.msg=Di[t],t),cr=e=>(e<<1)-(e>4?9:0),dr=e=>{let t=e.length;for(;--t>=0;)e[t]=0};let _r=(e,t,i)=>(t<<e.hash_shift^i)&e.hash_mask;const lr=e=>{const t=e.state;let i=t.pending;i>e.avail_out&&(i=e.avail_out),0!==i&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+i),e.next_out),e.next_out+=i,t.pending_out+=i,e.total_out+=i,e.avail_out-=i,t.pending-=i,0===t.pending&&(t.pending_out=0))},ur=(e,t)=>{Mi(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,lr(e.strm)},hr=(e,t)=>{e.pending_buf[e.pending++]=t},gr=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},vr=(e,t,i,r)=>{let n=e.avail_in;return n>r&&(n=r),0===n?0:(e.avail_in-=n,t.set(e.input.subarray(e.next_in,e.next_in+n),i),1===e.state.wrap?e.adler=Ai(e.adler,t,n,i):2===e.state.wrap&&(e.adler=ki(e.adler,t,n,i)),e.next_in+=n,e.total_in+=n,n)},pr=(e,t)=>{let i,r,n=e.max_chain_length,o=e.strstart,s=e.prev_length,a=e.nice_match;const c=e.strstart>e.w_size-rr?e.strstart-(e.w_size-rr):0,d=e.window,_=e.w_mask,l=e.prev,u=e.strstart+ir;let h=d[o+s-1],g=d[o+s];e.prev_length>=e.good_match&&(n>>=2),a>e.lookahead&&(a=e.lookahead);do{if(i=t,d[i+s]===g&&d[i+s-1]===h&&d[i]===d[o]&&d[++i]===d[o+1]){o+=2,i++;do{}while(d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&o<u);if(r=ir-(u-o),o=u-ir,r>s){if(e.match_start=t,s=r,r>=a)break;h=d[o+s-1],g=d[o+s]}}}while((t=l[t&_])>c&&0!=--n);return s<=e.lookahead?s:e.lookahead},Rr=e=>{const t=e.w_size;let i,r,n,o,s;do{if(o=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-rr)){e.window.set(e.window.subarray(t,t+t),0),e.match_start-=t,e.strstart-=t,e.block_start-=t,r=e.hash_size,i=r;do{n=e.head[--i],e.head[i]=n>=t?n-t:0}while(--r);r=t,i=r;do{n=e.prev[--i],e.prev[i]=n>=t?n-t:0}while(--r);o+=t}if(0===e.strm.avail_in)break;if(r=vr(e.strm,e.window,e.strstart+e.lookahead,o),e.lookahead+=r,e.lookahead+e.insert>=3)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=_r(e,e.ins_h,e.window[s+1]);e.insert&&(e.ins_h=_r(e,e.ins_h,e.window[s+3-1]),e.prev[s&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=s,s++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookahead<rr&&0!==e.strm.avail_in)},mr=(e,t)=>{let i,r;for(;;){if(e.lookahead<rr){if(Rr(e),e.lookahead<rr&&t===Bi)return 1;if(0===e.lookahead)break}if(i=0,e.lookahead>=3&&(e.ins_h=_r(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==i&&e.strstart-i<=e.w_size-rr&&(e.match_length=pr(e,i)),e.match_length>=3)if(r=xi(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do{e.strstart++,e.ins_h=_r(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart}while(0!=--e.match_length);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=_r(e,e.ins_h,e.window[e.strstart+1]);else r=xi(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(r&&(ur(e,!1),0===e.strm.avail_out))return 1}return e.insert=e.strstart<2?e.strstart:2,t===Ji?(ur(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(ur(e,!1),0===e.strm.avail_out)?1:2},Ir=(e,t)=>{let i,r,n;for(;;){if(e.lookahead<rr){if(Rr(e),e.lookahead<rr&&t===Bi)return 1;if(0===e.lookahead)break}if(i=0,e.lookahead>=3&&(e.ins_h=_r(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==i&&e.prev_length<e.max_lazy_match&&e.strstart-i<=e.w_size-rr&&(e.match_length=pr(e,i),e.match_length<=5&&(e.strategy===qi||3===e.match_length&&e.strstart-e.match_start>4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){n=e.strstart+e.lookahead-3,r=xi(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do{++e.strstart<=n&&(e.ins_h=_r(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart)}while(0!=--e.prev_length);if(e.match_available=0,e.match_length=2,e.strstart++,r&&(ur(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if(r=xi(e,0,e.window[e.strstart-1]),r&&ur(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(r=xi(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===Ji?(ur(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(ur(e,!1),0===e.strm.avail_out)?1:2};function Er(e,t,i,r,n){this.good_length=e,this.max_lazy=t,this.nice_length=i,this.max_chain=r,this.func=n}const Sr=[new Er(0,0,0,0,((e,t)=>{let i=65535;for(i>e.pending_buf_size-5&&(i=e.pending_buf_size-5);;){if(e.lookahead<=1){if(Rr(e),0===e.lookahead&&t===Bi)return 1;if(0===e.lookahead)break}e.strstart+=e.lookahead,e.lookahead=0;const r=e.block_start+i;if((0===e.strstart||e.strstart>=r)&&(e.lookahead=e.strstart-r,e.strstart=r,ur(e,!1),0===e.strm.avail_out))return 1;if(e.strstart-e.block_start>=e.w_size-rr&&(ur(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ji?(ur(e,!0),0===e.strm.avail_out?3:4):(e.strstart>e.block_start&&(ur(e,!1),e.strm.avail_out),1)})),new Er(4,4,8,4,mr),new Er(4,5,16,8,mr),new Er(4,6,32,32,mr),new Er(4,4,16,16,Ir),new Er(8,16,32,32,Ir),new Er(8,16,128,128,Ir),new Er(8,32,128,256,Ir),new Er(32,128,258,1024,Ir),new Er(32,258,258,4096,Ir)];function Tr(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=tr,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),dr(this.dyn_ltree),dr(this.dyn_dtree),dr(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),dr(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),dr(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const fr=e=>{if(!e||!e.state)return ar(e,ji);e.total_in=e.total_out=0,e.data_type=er;const t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?42:or,e.adler=2===t.wrap?0:1,t.last_flush=Bi,Ui(t),Hi},Cr=e=>{const t=fr(e);var i;return t===Hi&&((i=e.state).window_size=2*i.w_size,dr(i.head),i.max_lazy_match=Sr[i.level].max_lazy,i.good_match=Sr[i.level].good_length,i.nice_match=Sr[i.level].nice_length,i.max_chain_length=Sr[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),t},Or=(e,t,i,r,n,o)=>{if(!e)return ji;let s=1;if(t===Yi&&(t=6),r<0?(s=0,r=-r):r>15&&(s=2,r-=16),n<1||n>9||i!==tr||r<8||r>15||t<0||t>9||o<0||o>Zi)return ar(e,ji);8===r&&(r=9);const a=new Tr;return e.state=a,a.strm=e,a.wrap=s,a.gzhead=null,a.w_bits=r,a.w_size=1<<a.w_bits,a.w_mask=a.w_size-1,a.hash_bits=n+7,a.hash_size=1<<a.hash_bits,a.hash_mask=a.hash_size-1,a.hash_shift=~~((a.hash_bits+3-1)/3),a.window=new Uint8Array(2*a.w_size),a.head=new Uint16Array(a.hash_size),a.prev=new Uint16Array(a.w_size),a.lit_bufsize=1<<n+6,a.pending_buf_size=4*a.lit_bufsize,a.pending_buf=new Uint8Array(a.pending_buf_size),a.d_buf=1*a.lit_bufsize,a.l_buf=3*a.lit_bufsize,a.level=t,a.strategy=o,a.method=i,Cr(e)};var Lr={deflateInit:(e,t)=>Or(e,t,tr,15,8,Xi),deflateInit2:Or,deflateReset:Cr,deflateResetKeep:fr,deflateSetHeader:(e,t)=>e&&e.state?2!==e.state.wrap?ji:(e.state.gzhead=t,Hi):ji,deflate:(e,t)=>{let i,r;if(!e||!e.state||t>Gi||t<0)return e?ar(e,ji):ji;const n=e.state;if(!e.output||!e.input&&0!==e.avail_in||n.status===sr&&t!==Ji)return ar(e,0===e.avail_out?Wi:ji);n.strm=e;const o=n.last_flush;if(n.last_flush=t,42===n.status)if(2===n.wrap)e.adler=0,hr(n,31),hr(n,139),hr(n,8),n.gzhead?(hr(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),hr(n,255&n.gzhead.time),hr(n,n.gzhead.time>>8&255),hr(n,n.gzhead.time>>16&255),hr(n,n.gzhead.time>>24&255),hr(n,9===n.level?2:n.strategy>=zi||n.level<2?4:0),hr(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(hr(n,255&n.gzhead.extra.length),hr(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=ki(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(hr(n,0),hr(n,0),hr(n,0),hr(n,0),hr(n,0),hr(n,9===n.level?2:n.strategy>=zi||n.level<2?4:0),hr(n,3),n.status=or);else{let t=tr+(n.w_bits-8<<4)<<8,i=-1;i=n.strategy>=zi||n.level<2?0:n.level<6?1:6===n.level?2:3,t|=i<<6,0!==n.strstart&&(t|=32),t+=31-t%31,n.status=or,gr(n,t),0!==n.strstart&&(gr(n,e.adler>>>16),gr(n,65535&e.adler)),e.adler=1}if(69===n.status)if(n.gzhead.extra){for(i=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),lr(e),i=n.pending,n.pending!==n.pending_buf_size));)hr(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=73)}else n.status=73;if(73===n.status)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),lr(e),i=n.pending,n.pending===n.pending_buf_size)){r=1;break}r=n.gzindex<n.gzhead.name.length?255&n.gzhead.name.charCodeAt(n.gzindex++):0,hr(n,r)}while(0!==r);n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),0===r&&(n.gzindex=0,n.status=91)}else n.status=91;if(91===n.status)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),lr(e),i=n.pending,n.pending===n.pending_buf_size)){r=1;break}r=n.gzindex<n.gzhead.comment.length?255&n.gzhead.comment.charCodeAt(n.gzindex++):0,hr(n,r)}while(0!==r);n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),0===r&&(n.status=nr)}else n.status=nr;if(n.status===nr&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&lr(e),n.pending+2<=n.pending_buf_size&&(hr(n,255&e.adler),hr(n,e.adler>>8&255),e.adler=0,n.status=or)):n.status=or),0!==n.pending){if(lr(e),0===e.avail_out)return n.last_flush=-1,Hi}else if(0===e.avail_in&&cr(t)<=cr(o)&&t!==Ji)return ar(e,Wi);if(n.status===sr&&0!==e.avail_in)return ar(e,Wi);if(0!==e.avail_in||0!==n.lookahead||t!==Bi&&n.status!==sr){let i=n.strategy===zi?((e,t)=>{let i;for(;;){if(0===e.lookahead&&(Rr(e),0===e.lookahead)){if(t===Bi)return 1;break}if(e.match_length=0,i=xi(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,i&&(ur(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ji?(ur(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(ur(e,!1),0===e.strm.avail_out)?1:2})(n,t):n.strategy===Qi?((e,t)=>{let i,r,n,o;const s=e.window;for(;;){if(e.lookahead<=ir){if(Rr(e),e.lookahead<=ir&&t===Bi)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(n=e.strstart-1,r=s[n],r===s[++n]&&r===s[++n]&&r===s[++n])){o=e.strstart+ir;do{}while(r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&n<o);e.match_length=ir-(o-n),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(i=xi(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(i=xi(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),i&&(ur(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ji?(ur(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(ur(e,!1),0===e.strm.avail_out)?1:2})(n,t):Sr[n.level].func(n,t);if(3!==i&&4!==i||(n.status=sr),1===i||3===i)return 0===e.avail_out&&(n.last_flush=-1),Hi;if(2===i&&(t===Vi?wi(n):t!==Gi&&(Pi(n,0,0,!1),t===Fi&&(dr(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),lr(e),0===e.avail_out))return n.last_flush=-1,Hi}return t!==Ji?Hi:n.wrap<=0?Ki:(2===n.wrap?(hr(n,255&e.adler),hr(n,e.adler>>8&255),hr(n,e.adler>>16&255),hr(n,e.adler>>24&255),hr(n,255&e.total_in),hr(n,e.total_in>>8&255),hr(n,e.total_in>>16&255),hr(n,e.total_in>>24&255)):(gr(n,e.adler>>>16),gr(n,65535&e.adler)),lr(e),n.wrap>0&&(n.wrap=-n.wrap),0!==n.pending?Hi:Ki)},deflateEnd:e=>{if(!e||!e.state)return ji;const t=e.state.status;return 42!==t&&69!==t&&73!==t&&91!==t&&t!==nr&&t!==or&&t!==sr?ar(e,ji):(e.state=null,t===or?ar(e,$i):Hi)},deflateSetDictionary:(e,t)=>{let i=t.length;if(!e||!e.state)return ji;const r=e.state,n=r.wrap;if(2===n||1===n&&42!==r.status||r.lookahead)return ji;if(1===n&&(e.adler=Ai(e.adler,t,i,0)),r.wrap=0,i>=r.w_size){0===n&&(dr(r.head),r.strstart=0,r.block_start=0,r.insert=0);let e=new Uint8Array(r.w_size);e.set(t.subarray(i-r.w_size,i),0),t=e,i=r.w_size}const o=e.avail_in,s=e.next_in,a=e.input;for(e.avail_in=i,e.next_in=0,e.input=t,Rr(r);r.lookahead>=3;){let e=r.strstart,t=r.lookahead-2;do{r.ins_h=_r(r,r.ins_h,r.window[e+3-1]),r.prev[e&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=e,e++}while(--t);r.strstart=e,r.lookahead=2,Rr(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=2,r.match_available=0,e.next_in=s,e.input=a,e.avail_in=o,r.wrap=n,Hi},deflateInfo:"pako deflate (from Nodeca project)"};const Nr=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var Ar=function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const i=t.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const t in i)Nr(i,t)&&(e[t]=i[t])}}return e},yr=e=>{let t=0;for(let i=0,r=e.length;i<r;i++)t+=e[i].length;const i=new Uint8Array(t);for(let t=0,r=0,n=e.length;t<n;t++){let n=e[t];i.set(n,r),r+=n.length}return i};let kr=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(e){kr=!1}const Dr=new Uint8Array(256);for(let e=0;e<256;e++)Dr[e]=e>=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;Dr[254]=Dr[254]=1;var br=e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);let t,i,r,n,o,s=e.length,a=0;for(n=0;n<s;n++)i=e.charCodeAt(n),55296==(64512&i)&&n+1<s&&(r=e.charCodeAt(n+1),56320==(64512&r)&&(i=65536+(i-55296<<10)+(r-56320),n++)),a+=i<128?1:i<2048?2:i<65536?3:4;for(t=new Uint8Array(a),o=0,n=0;o<a;n++)i=e.charCodeAt(n),55296==(64512&i)&&n+1<s&&(r=e.charCodeAt(n+1),56320==(64512&r)&&(i=65536+(i-55296<<10)+(r-56320),n++)),i<128?t[o++]=i:i<2048?(t[o++]=192|i>>>6,t[o++]=128|63&i):i<65536?(t[o++]=224|i>>>12,t[o++]=128|i>>>6&63,t[o++]=128|63&i):(t[o++]=240|i>>>18,t[o++]=128|i>>>12&63,t[o++]=128|i>>>6&63,t[o++]=128|63&i);return t},Ur=(e,t)=>{const i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));let r,n;const o=new Array(2*i);for(n=0,r=0;r<i;){let t=e[r++];if(t<128){o[n++]=t;continue}let s=Dr[t];if(s>4)o[n++]=65533,r+=s-1;else{for(t&=2===s?31:3===s?15:7;s>1&&r<i;)t=t<<6|63&e[r++],s--;s>1?o[n++]=65533:t<65536?o[n++]=t:(t-=65536,o[n++]=55296|t>>10&1023,o[n++]=56320|1023&t)}}return((e,t)=>{if(t<65534&&e.subarray&&kr)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let i="";for(let r=0;r<t;r++)i+=String.fromCharCode(e[r]);return i})(o,n)},Pr=(e,t)=>{(t=t||e.length)>e.length&&(t=e.length);let i=t-1;for(;i>=0&&128==(192&e[i]);)i--;return i<0||0===i?t:i+Dr[e[i]]>t?i:t};var Mr=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const xr=Object.prototype.toString,{Z_NO_FLUSH:wr,Z_SYNC_FLUSH:Br,Z_FULL_FLUSH:Vr,Z_FINISH:Fr,Z_OK:Jr,Z_STREAM_END:Gr,Z_DEFAULT_COMPRESSION:Hr,Z_DEFAULT_STRATEGY:Kr,Z_DEFLATED:jr}=bi;function $r(e){this.options=Ar({level:Hr,method:jr,chunkSize:16384,windowBits:15,memLevel:8,strategy:Kr},e||{});let t=this.options;t.raw&&t.windowBits>0?t.windowBits=-t.windowBits:t.gzip&&t.windowBits>0&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Mr,this.strm.avail_out=0;let i=Lr.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(i!==Jr)throw new Error(Di[i]);if(t.header&&Lr.deflateSetHeader(this.strm,t.header),t.dictionary){let e;if(e="string"==typeof t.dictionary?br(t.dictionary):"[object ArrayBuffer]"===xr.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,i=Lr.deflateSetDictionary(this.strm,e),i!==Jr)throw new Error(Di[i]);this._dict_set=!0}}function Wr(e,t){const i=new $r(t);if(i.push(e,!0),i.err)throw i.msg||Di[i.err];return i.result}$r.prototype.push=function(e,t){const i=this.strm,r=this.options.chunkSize;let n,o;if(this.ended)return!1;for(o=t===~~t?t:!0===t?Fr:wr,"string"==typeof e?i.input=br(e):"[object ArrayBuffer]"===xr.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(r),i.next_out=0,i.avail_out=r),(o===Br||o===Vr)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(n=Lr.deflate(i,o),n===Gr)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),n=Lr.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===Jr;if(0!==i.avail_out){if(o>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},$r.prototype.onData=function(e){this.chunks.push(e)},$r.prototype.onEnd=function(e){e===Jr&&(this.result=yr(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var Yr={Deflate:$r,deflate:Wr,deflateRaw:function(e,t){return(t=t||{}).raw=!0,Wr(e,t)},gzip:function(e,t){return(t=t||{}).gzip=!0,Wr(e,t)},constants:bi};var qr=function(e,t){let i,r,n,o,s,a,c,d,_,l,u,h,g,v,p,R,m,I,E,S,T,f,C,O;const L=e.state;i=e.next_in,C=e.input,r=i+(e.avail_in-5),n=e.next_out,O=e.output,o=n-(t-e.avail_out),s=n+(e.avail_out-257),a=L.dmax,c=L.wsize,d=L.whave,_=L.wnext,l=L.window,u=L.hold,h=L.bits,g=L.lencode,v=L.distcode,p=(1<<L.lenbits)-1,R=(1<<L.distbits)-1;e:do{h<15&&(u+=C[i++]<<h,h+=8,u+=C[i++]<<h,h+=8),m=g[u&p];t:for(;;){if(I=m>>>24,u>>>=I,h-=I,I=m>>>16&255,0===I)O[n++]=65535&m;else{if(!(16&I)){if(0==(64&I)){m=g[(65535&m)+(u&(1<<I)-1)];continue t}if(32&I){L.mode=12;break e}e.msg="invalid literal/length code",L.mode=30;break e}E=65535&m,I&=15,I&&(h<I&&(u+=C[i++]<<h,h+=8),E+=u&(1<<I)-1,u>>>=I,h-=I),h<15&&(u+=C[i++]<<h,h+=8,u+=C[i++]<<h,h+=8),m=v[u&R];i:for(;;){if(I=m>>>24,u>>>=I,h-=I,I=m>>>16&255,!(16&I)){if(0==(64&I)){m=v[(65535&m)+(u&(1<<I)-1)];continue i}e.msg="invalid distance code",L.mode=30;break e}if(S=65535&m,I&=15,h<I&&(u+=C[i++]<<h,h+=8,h<I&&(u+=C[i++]<<h,h+=8)),S+=u&(1<<I)-1,S>a){e.msg="invalid distance too far back",L.mode=30;break e}if(u>>>=I,h-=I,I=n-o,S>I){if(I=S-I,I>d&&L.sane){e.msg="invalid distance too far back",L.mode=30;break e}if(T=0,f=l,0===_){if(T+=c-I,I<E){E-=I;do{O[n++]=l[T++]}while(--I);T=n-S,f=O}}else if(_<I){if(T+=c+_-I,I-=_,I<E){E-=I;do{O[n++]=l[T++]}while(--I);if(T=0,_<E){I=_,E-=I;do{O[n++]=l[T++]}while(--I);T=n-S,f=O}}}else if(T+=_-I,I<E){E-=I;do{O[n++]=l[T++]}while(--I);T=n-S,f=O}for(;E>2;)O[n++]=f[T++],O[n++]=f[T++],O[n++]=f[T++],E-=3;E&&(O[n++]=f[T++],E>1&&(O[n++]=f[T++]))}else{T=n-S;do{O[n++]=O[T++],O[n++]=O[T++],O[n++]=O[T++],E-=3}while(E>2);E&&(O[n++]=O[T++],E>1&&(O[n++]=O[T++]))}break}}break}}while(i<r&&n<s);E=h>>3,i-=E,h-=E<<3,u&=(1<<h)-1,e.next_in=i,e.next_out=n,e.avail_in=i<r?r-i+5:5-(i-r),e.avail_out=n<s?s-n+257:257-(n-s),L.hold=u,L.bits=h};const zr=15,Qr=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),Zr=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),Xr=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),en=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var tn=(e,t,i,r,n,o,s,a)=>{const c=a.bits;let d,_,l,u,h,g,v=0,p=0,R=0,m=0,I=0,E=0,S=0,T=0,f=0,C=0,O=null,L=0;const N=new Uint16Array(16),A=new Uint16Array(16);let y,k,D,b=null,U=0;for(v=0;v<=zr;v++)N[v]=0;for(p=0;p<r;p++)N[t[i+p]]++;for(I=c,m=zr;m>=1&&0===N[m];m--);if(I>m&&(I=m),0===m)return n[o++]=20971520,n[o++]=20971520,a.bits=1,0;for(R=1;R<m&&0===N[R];R++);for(I<R&&(I=R),T=1,v=1;v<=zr;v++)if(T<<=1,T-=N[v],T<0)return-1;if(T>0&&(0===e||1!==m))return-1;for(A[1]=0,v=1;v<zr;v++)A[v+1]=A[v]+N[v];for(p=0;p<r;p++)0!==t[i+p]&&(s[A[t[i+p]]++]=p);if(0===e?(O=b=s,g=19):1===e?(O=Qr,L-=257,b=Zr,U-=257,g=256):(O=Xr,b=en,g=-1),C=0,p=0,v=R,h=o,E=I,S=0,l=-1,f=1<<I,u=f-1,1===e&&f>852||2===e&&f>592)return 1;for(;;){y=v-S,s[p]<g?(k=0,D=s[p]):s[p]>g?(k=b[U+s[p]],D=O[L+s[p]]):(k=96,D=0),d=1<<v-S,_=1<<E,R=_;do{_-=d,n[h+(C>>S)+_]=y<<24|k<<16|D|0}while(0!==_);for(d=1<<v-1;C&d;)d>>=1;if(0!==d?(C&=d-1,C+=d):C=0,p++,0==--N[v]){if(v===m)break;v=t[i+s[p]]}if(v>I&&(C&u)!==l){for(0===S&&(S=I),h+=R,E=v-S,T=1<<E;E+S<m&&(T-=N[E+S],!(T<=0));)E++,T<<=1;if(f+=1<<E,1===e&&f>852||2===e&&f>592)return 1;l=C&u,n[l]=I<<24|E<<16|h-o|0}}return 0!==C&&(n[h+C]=v-S<<24|64<<16|0),a.bits=I,0};const{Z_FINISH:rn,Z_BLOCK:nn,Z_TREES:on,Z_OK:sn,Z_STREAM_END:an,Z_NEED_DICT:cn,Z_STREAM_ERROR:dn,Z_DATA_ERROR:_n,Z_MEM_ERROR:ln,Z_BUF_ERROR:un,Z_DEFLATED:hn}=bi,gn=12,vn=30,pn=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function Rn(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const mn=e=>{if(!e||!e.state)return dn;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,sn},In=e=>{if(!e||!e.state)return dn;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,mn(e)},En=(e,t)=>{let i;if(!e||!e.state)return dn;const r=e.state;return t<0?(i=0,t=-t):(i=1+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?dn:(null!==r.window&&r.wbits!==t&&(r.window=null),r.wrap=i,r.wbits=t,In(e))},Sn=(e,t)=>{if(!e)return dn;const i=new Rn;e.state=i,i.window=null;const r=En(e,t);return r!==sn&&(e.state=null),r};let Tn,fn,Cn=!0;const On=e=>{if(Cn){Tn=new Int32Array(512),fn=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(tn(1,e.lens,0,288,Tn,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;tn(2,e.lens,0,32,fn,0,e.work,{bits:5}),Cn=!1}e.lencode=Tn,e.lenbits=9,e.distcode=fn,e.distbits=5},Ln=(e,t,i,r)=>{let n;const o=e.state;return null===o.window&&(o.wsize=1<<o.wbits,o.wnext=0,o.whave=0,o.window=new Uint8Array(o.wsize)),r>=o.wsize?(o.window.set(t.subarray(i-o.wsize,i),0),o.wnext=0,o.whave=o.wsize):(n=o.wsize-o.wnext,n>r&&(n=r),o.window.set(t.subarray(i-r,i-r+n),o.wnext),(r-=n)?(o.window.set(t.subarray(i-r,i),0),o.wnext=r,o.whave=o.wsize):(o.wnext+=n,o.wnext===o.wsize&&(o.wnext=0),o.whave<o.wsize&&(o.whave+=n))),0};var Nn={inflateReset:In,inflateReset2:En,inflateResetKeep:mn,inflateInit:e=>Sn(e,15),inflateInit2:Sn,inflate:(e,t)=>{let i,r,n,o,s,a,c,d,_,l,u,h,g,v,p,R,m,I,E,S,T,f,C=0;const O=new Uint8Array(4);let L,N;const A=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!e||!e.state||!e.output||!e.input&&0!==e.avail_in)return dn;i=e.state,i.mode===gn&&(i.mode=13),s=e.next_out,n=e.output,c=e.avail_out,o=e.next_in,r=e.input,a=e.avail_in,d=i.hold,_=i.bits,l=a,u=c,f=sn;e:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;_<16;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(2&i.wrap&&35615===d){i.check=0,O[0]=255&d,O[1]=d>>>8&255,i.check=ki(i.check,O,2,0),d=0,_=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&d)<<8)+(d>>8))%31){e.msg="incorrect header check",i.mode=vn;break}if((15&d)!==hn){e.msg="unknown compression method",i.mode=vn;break}if(d>>>=4,_-=4,T=8+(15&d),0===i.wbits)i.wbits=T;else if(T>i.wbits){e.msg="invalid window size",i.mode=vn;break}i.dmax=1<<i.wbits,e.adler=i.check=1,i.mode=512&d?10:gn,d=0,_=0;break;case 2:for(;_<16;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(i.flags=d,(255&i.flags)!==hn){e.msg="unknown compression method",i.mode=vn;break}if(57344&i.flags){e.msg="unknown header flags set",i.mode=vn;break}i.head&&(i.head.text=d>>8&1),512&i.flags&&(O[0]=255&d,O[1]=d>>>8&255,i.check=ki(i.check,O,2,0)),d=0,_=0,i.mode=3;case 3:for(;_<32;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.head&&(i.head.time=d),512&i.flags&&(O[0]=255&d,O[1]=d>>>8&255,O[2]=d>>>16&255,O[3]=d>>>24&255,i.check=ki(i.check,O,4,0)),d=0,_=0,i.mode=4;case 4:for(;_<16;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.head&&(i.head.xflags=255&d,i.head.os=d>>8),512&i.flags&&(O[0]=255&d,O[1]=d>>>8&255,i.check=ki(i.check,O,2,0)),d=0,_=0,i.mode=5;case 5:if(1024&i.flags){for(;_<16;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.length=d,i.head&&(i.head.extra_len=d),512&i.flags&&(O[0]=255&d,O[1]=d>>>8&255,i.check=ki(i.check,O,2,0)),d=0,_=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(h=i.length,h>a&&(h=a),h&&(i.head&&(T=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(r.subarray(o,o+h),T)),512&i.flags&&(i.check=ki(i.check,r,h,o)),a-=h,o+=h,i.length-=h),i.length))break e;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===a)break e;h=0;do{T=r[o+h++],i.head&&T&&i.length<65536&&(i.head.name+=String.fromCharCode(T))}while(T&&h<a);if(512&i.flags&&(i.check=ki(i.check,r,h,o)),a-=h,o+=h,T)break e}else i.head&&(i.head.name=null);i.length=0,i.mode=8;case 8:if(4096&i.flags){if(0===a)break e;h=0;do{T=r[o+h++],i.head&&T&&i.length<65536&&(i.head.comment+=String.fromCharCode(T))}while(T&&h<a);if(512&i.flags&&(i.check=ki(i.check,r,h,o)),a-=h,o+=h,T)break e}else i.head&&(i.head.comment=null);i.mode=9;case 9:if(512&i.flags){for(;_<16;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(d!==(65535&i.check)){e.msg="header crc mismatch",i.mode=vn;break}d=0,_=0}i.head&&(i.head.hcrc=i.flags>>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=gn;break;case 10:for(;_<32;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}e.adler=i.check=pn(d),d=0,_=0,i.mode=11;case 11:if(0===i.havedict)return e.next_out=s,e.avail_out=c,e.next_in=o,e.avail_in=a,i.hold=d,i.bits=_,cn;e.adler=i.check=1,i.mode=gn;case gn:if(t===nn||t===on)break e;case 13:if(i.last){d>>>=7&_,_-=7&_,i.mode=27;break}for(;_<3;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}switch(i.last=1&d,d>>>=1,_-=1,3&d){case 0:i.mode=14;break;case 1:if(On(i),i.mode=20,t===on){d>>>=2,_-=2;break e}break;case 2:i.mode=17;break;case 3:e.msg="invalid block type",i.mode=vn}d>>>=2,_-=2;break;case 14:for(d>>>=7&_,_-=7&_;_<32;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if((65535&d)!=(d>>>16^65535)){e.msg="invalid stored block lengths",i.mode=vn;break}if(i.length=65535&d,d=0,_=0,i.mode=15,t===on)break e;case 15:i.mode=16;case 16:if(h=i.length,h){if(h>a&&(h=a),h>c&&(h=c),0===h)break e;n.set(r.subarray(o,o+h),s),a-=h,o+=h,c-=h,s+=h,i.length-=h;break}i.mode=gn;break;case 17:for(;_<14;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(i.nlen=257+(31&d),d>>>=5,_-=5,i.ndist=1+(31&d),d>>>=5,_-=5,i.ncode=4+(15&d),d>>>=4,_-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=vn;break}i.have=0,i.mode=18;case 18:for(;i.have<i.ncode;){for(;_<3;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.lens[A[i.have++]]=7&d,d>>>=3,_-=3}for(;i.have<19;)i.lens[A[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,L={bits:i.lenbits},f=tn(0,i.lens,0,19,i.lencode,0,i.work,L),i.lenbits=L.bits,f){e.msg="invalid code lengths set",i.mode=vn;break}i.have=0,i.mode=19;case 19:for(;i.have<i.nlen+i.ndist;){for(;C=i.lencode[d&(1<<i.lenbits)-1],p=C>>>24,R=C>>>16&255,m=65535&C,!(p<=_);){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(m<16)d>>>=p,_-=p,i.lens[i.have++]=m;else{if(16===m){for(N=p+2;_<N;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(d>>>=p,_-=p,0===i.have){e.msg="invalid bit length repeat",i.mode=vn;break}T=i.lens[i.have-1],h=3+(3&d),d>>>=2,_-=2}else if(17===m){for(N=p+3;_<N;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}d>>>=p,_-=p,T=0,h=3+(7&d),d>>>=3,_-=3}else{for(N=p+7;_<N;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}d>>>=p,_-=p,T=0,h=11+(127&d),d>>>=7,_-=7}if(i.have+h>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=vn;break}for(;h--;)i.lens[i.have++]=T}}if(i.mode===vn)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=vn;break}if(i.lenbits=9,L={bits:i.lenbits},f=tn(1,i.lens,0,i.nlen,i.lencode,0,i.work,L),i.lenbits=L.bits,f){e.msg="invalid literal/lengths set",i.mode=vn;break}if(i.distbits=6,i.distcode=i.distdyn,L={bits:i.distbits},f=tn(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,L),i.distbits=L.bits,f){e.msg="invalid distances set",i.mode=vn;break}if(i.mode=20,t===on)break e;case 20:i.mode=21;case 21:if(a>=6&&c>=258){e.next_out=s,e.avail_out=c,e.next_in=o,e.avail_in=a,i.hold=d,i.bits=_,qr(e,u),s=e.next_out,n=e.output,c=e.avail_out,o=e.next_in,r=e.input,a=e.avail_in,d=i.hold,_=i.bits,i.mode===gn&&(i.back=-1);break}for(i.back=0;C=i.lencode[d&(1<<i.lenbits)-1],p=C>>>24,R=C>>>16&255,m=65535&C,!(p<=_);){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(R&&0==(240&R)){for(I=p,E=R,S=m;C=i.lencode[S+((d&(1<<I+E)-1)>>I)],p=C>>>24,R=C>>>16&255,m=65535&C,!(I+p<=_);){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}d>>>=I,_-=I,i.back+=I}if(d>>>=p,_-=p,i.back+=p,i.length=m,0===R){i.mode=26;break}if(32&R){i.back=-1,i.mode=gn;break}if(64&R){e.msg="invalid literal/length code",i.mode=vn;break}i.extra=15&R,i.mode=22;case 22:if(i.extra){for(N=i.extra;_<N;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.length+=d&(1<<i.extra)-1,d>>>=i.extra,_-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;C=i.distcode[d&(1<<i.distbits)-1],p=C>>>24,R=C>>>16&255,m=65535&C,!(p<=_);){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(0==(240&R)){for(I=p,E=R,S=m;C=i.distcode[S+((d&(1<<I+E)-1)>>I)],p=C>>>24,R=C>>>16&255,m=65535&C,!(I+p<=_);){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}d>>>=I,_-=I,i.back+=I}if(d>>>=p,_-=p,i.back+=p,64&R){e.msg="invalid distance code",i.mode=vn;break}i.offset=m,i.extra=15&R,i.mode=24;case 24:if(i.extra){for(N=i.extra;_<N;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.offset+=d&(1<<i.extra)-1,d>>>=i.extra,_-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=vn;break}i.mode=25;case 25:if(0===c)break e;if(h=u-c,i.offset>h){if(h=i.offset-h,h>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=vn;break}h>i.wnext?(h-=i.wnext,g=i.wsize-h):g=i.wnext-h,h>i.length&&(h=i.length),v=i.window}else v=n,g=s-i.offset,h=i.length;h>c&&(h=c),c-=h,i.length-=h;do{n[s++]=v[g++]}while(--h);0===i.length&&(i.mode=21);break;case 26:if(0===c)break e;n[s++]=i.length,c--,i.mode=21;break;case 27:if(i.wrap){for(;_<32;){if(0===a)break e;a--,d|=r[o++]<<_,_+=8}if(u-=c,e.total_out+=u,i.total+=u,u&&(e.adler=i.check=i.flags?ki(i.check,n,u,s-u):Ai(i.check,n,u,s-u)),u=c,(i.flags?d:pn(d))!==i.check){e.msg="incorrect data check",i.mode=vn;break}d=0,_=0}i.mode=28;case 28:if(i.wrap&&i.flags){for(;_<32;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(d!==(4294967295&i.total)){e.msg="incorrect length check",i.mode=vn;break}d=0,_=0}i.mode=29;case 29:f=an;break e;case vn:f=_n;break e;case 31:return ln;default:return dn}return e.next_out=s,e.avail_out=c,e.next_in=o,e.avail_in=a,i.hold=d,i.bits=_,(i.wsize||u!==e.avail_out&&i.mode<vn&&(i.mode<27||t!==rn))&&Ln(e,e.output,e.next_out,u-e.avail_out),l-=e.avail_in,u-=e.avail_out,e.total_in+=l,e.total_out+=u,i.total+=u,i.wrap&&u&&(e.adler=i.check=i.flags?ki(i.check,n,u,e.next_out-u):Ai(i.check,n,u,e.next_out-u)),e.data_type=i.bits+(i.last?64:0)+(i.mode===gn?128:0)+(20===i.mode||15===i.mode?256:0),(0===l&&0===u||t===rn)&&f===sn&&(f=un),f},inflateEnd:e=>{if(!e||!e.state)return dn;let t=e.state;return t.window&&(t.window=null),e.state=null,sn},inflateGetHeader:(e,t)=>{if(!e||!e.state)return dn;const i=e.state;return 0==(2&i.wrap)?dn:(i.head=t,t.done=!1,sn)},inflateSetDictionary:(e,t)=>{const i=t.length;let r,n,o;return e&&e.state?(r=e.state,0!==r.wrap&&11!==r.mode?dn:11===r.mode&&(n=1,n=Ai(n,t,i,0),n!==r.check)?_n:(o=Ln(e,t,i,i),o?(r.mode=31,ln):(r.havedict=1,sn))):dn},inflateInfo:"pako inflate (from Nodeca project)"};var An=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const yn=Object.prototype.toString,{Z_NO_FLUSH:kn,Z_FINISH:Dn,Z_OK:bn,Z_STREAM_END:Un,Z_NEED_DICT:Pn,Z_STREAM_ERROR:Mn,Z_DATA_ERROR:xn,Z_MEM_ERROR:wn}=bi;function Bn(e){this.options=Ar({chunkSize:65536,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Mr,this.strm.avail_out=0;let i=Nn.inflateInit2(this.strm,t.windowBits);if(i!==bn)throw new Error(Di[i]);if(this.header=new An,Nn.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=br(t.dictionary):"[object ArrayBuffer]"===yn.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=Nn.inflateSetDictionary(this.strm,t.dictionary),i!==bn)))throw new Error(Di[i])}Bn.prototype.push=function(e,t){const i=this.strm,r=this.options.chunkSize,n=this.options.dictionary;let o,s,a;if(this.ended)return!1;for(s=t===~~t?t:!0===t?Dn:kn,"[object ArrayBuffer]"===yn.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(r),i.next_out=0,i.avail_out=r),o=Nn.inflate(i,s),o===Pn&&n&&(o=Nn.inflateSetDictionary(i,n),o===bn?o=Nn.inflate(i,s):o===xn&&(o=Pn));i.avail_in>0&&o===Un&&i.state.wrap>0&&0!==e[i.next_in];)Nn.inflateReset(i),o=Nn.inflate(i,s);switch(o){case Mn:case xn:case Pn:case wn:return this.onEnd(o),this.ended=!0,!1}if(a=i.avail_out,i.next_out&&(0===i.avail_out||o===Un))if("string"===this.options.to){let e=Pr(i.output,i.next_out),t=i.next_out-e,n=Ur(i.output,e);i.next_out=t,i.avail_out=r-t,t&&i.output.set(i.output.subarray(e,e+t),0),this.onData(n)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(o!==bn||0!==a){if(o===Un)return o=Nn.inflateEnd(this.strm),this.onEnd(o),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},Bn.prototype.onData=function(e){this.chunks.push(e)},Bn.prototype.onEnd=function(e){e===bn&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=yr(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};const{Deflate:Vn,deflate:Fn,deflateRaw:Jn,gzip:Gn}=Yr;var Hn=Gn;const Kn=-1,jn=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})),$n=(e,t,i)=>S(void 0,void 0,void 0,(function*(){const r=[];return yield Promise.any(e.map((e=>S(void 0,void 0,void 0,(function*(){const n=`${e.detectorAddr.replace(/^(https?:\/\/)?/,"https://")}/rtc/detector/ping?t=${s=1e3,a=9999,s+Math.floor(Math.random()*(a-s))}`;var s,a;const c={jwt:i};if(200!==(yield t.httpReq({url:n,body:JSON.stringify(c),timeout:5e3,method:o.POST})).status)return Promise.reject();r.push(e.clusterId)}))))),r})),Wn=e=>{if(!e)return"";return e.jwt||""},Yn=(e,t)=>S(void 0,void 0,void 0,(function*(){const i=(e=>{var t;if(!e)return"";let i;try{i=JSON.parse(e.voipCallInfo||'{ "strategy": 0 }')}catch(t){const i=We.getLogger();return null==i||i.warn(f.L_MEDIA_SERVICE_PARSE_NAVI_CALLVOIP_INFO_O,`parse \`voipCallInfo\` of navi failed: ${e.voipCallInfo}`),""}if(0===i.strategy)return"";const r=null===(t=i.callEngine)||void 0===t?void 0:t.filter((e=>4===e.engineType));if(!r||0===r.length)return"";const n=r[0];return n.detectorManager?n.detectorManager:""})(t),r=Wn(t);let n=null,a=120,c=0;const d={jwt:r};if(i&&r){const t=yield e.httpReq({url:`${i}/rtc/detector/servers`,body:JSON.stringify(d),headers:{"Content-Type":"application/json;charset=UTF-8","Cache-Control":"no-cache",ClientType:`web|${Ut.browser}|${Ut.version}`,ClientVersion:"5.6.8","Client-Session-Id":jn(),"Request-Id":Date.now().toString()},method:o.POST}),_=t.data&&JSON.parse(t.data).detectorAddrs;a=t.data&&JSON.parse(t.data).clientDetectMinute,c=t.data&&JSON.parse(t.data).resultCode,_&&s(_)&&(n=yield $n(_,e,r))}return{fastMediaUrl:n,clientDetectMinute:a,status:c}})),qn=()=>({"Content-Type":"application/json;charset=UTF-8","Cache-Control":"no-cache",ClientType:`web|${Ut.browser}|${Ut.version}`,ClientVersion:"5.6.8","Client-Session-Id":jn(),"Request-Id":Date.now().toString()});class zn{constructor(e,t,i,r=5e3){this._runtime=e,this._context=t,this._msUrl=i,this._timeout=r,this._msInNavi=[],this._failedMs=[],this._rtcFinger=void 0,this._clusterId="",this._configUrl="",this._msList=[],this._qualityMsList=[],zn.isDetector||t.getConnectionStatus()!==a.CONNECTED||this.detectorMediaSever()}detectorMediaSever(){const e=this._context.getNaviInfo();if(zn.jwtToken=(null==e?void 0:e.jwt)||"",this._msUrl)return;const t=Date.now(),i=zn.detectValidMinute+zn.detectorTime>t;zn.isDetector=i,!i&&e&&c(e)&&(this._msList=[],this._getDetectorUrls(e))}_getDetectorUrls(e){return S(this,void 0,void 0,(function*(){if(zn.isDetector)return;zn.isDetector=!0;const{fastMediaUrl:t,clientDetectMinute:i,status:r}=yield Yn(this._runtime,e);if(r===T.JWT_TIME_OUT){const e=this._context.getPluginContext();yield e.refetchNaviInfo(),this.detectorMediaSever()}zn.msInDetector=t||[],zn.detectorTime=Date.now(),zn.detectValidMinute=60*i*1e3}))}getNaviMS(){return this._msUrl?[this._msUrl]:(d(this._msList)&&!this._clusterId||(this._msList=this.setMediaServiceList()),this._msList)}setMediaServiceList(){var e,t;let i=[],r=[];return this._clusterId&&(this._clusterId=this._clusterId.replace(/^(https?:\/\/)?/,"https://"),this._msList.push(this._clusterId)),d(zn.msInDetector)&&(zn.msInDetector=zn.msInDetector.map((e=>e.replace(/^(https?:\/\/)?/,"https://"))),this._msList.push(zn.msInDetector[0]),i=zn.msInDetector.concat().splice(1,zn.msInDetector.length-1)),0===this._msInNavi.length&&(0===this._failedMs.length?this._msInNavi.push(...(e=>{var t;if(!e)return[];let i;try{i=JSON.parse(e.voipCallInfo||'{ "strategy": 0 }')}catch(t){const i=We.getLogger();return null==i||i.warn(`parse \`voipCallInfo\` of navi failed: ${e.voipCallInfo}`),[]}if(0===i.strategy)return[];const r=null===(t=i.callEngine)||void 0===t?void 0:t.filter((e=>4===e.engineType));if(!r||0===r.length)return[];const n=r[0],o=[];return n.mediaServer&&o.push(n.mediaServer.replace(/^(https?:\/\/)?/,"https://")),n.backupMediaServer&&n.backupMediaServer.forEach((e=>{o.push(e.replace(/^(https?:\/\/)?/,"https://"))})),o})(this._context.getNaviInfo())):(this._msInNavi.push(...this._failedMs),this._failedMs.length=0)),r=this._msInNavi.concat().splice(1,this._msInNavi.length-1),this._msList.push(this._msInNavi[0]),this._msList=[...this._msList,...i,...r],this._msList=[...new Set(this._msList)],null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_MEDIA_SERVICE_MSLIST_CHANGE_O,`MediaServiceList msList -> ${JSON.stringify(this._msList)}`),this._msList}_request(e,t,i,r,n){var s,a,c,d,_,l,u,h,g;return S(this,void 0,void 0,(function*(){this._qualityMsList=[];if((null===(s=this._context.getNaviInfo())||void 0===s?void 0:s.openGzip)||!1){const e=JSON.stringify(i),r=e.length,n=new Uint8Array(r);for(let t=0;t<r;t++)n[t]=e.charCodeAt(t);const o={"Content-Encoding":"gzip","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"};t=Object.assign(Object.assign({},t),o),i=Hn(n,v)}var v;const p=this.getNaviMS();if(0===p.length)return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:C.FAILED,code:T.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"have no valid service address"}),r),{code:T.NOT_OPEN_VIDEO_AUDIO_SERVER};this._rtcFinger&&(i.rtcFinger=this._rtcFinger);for(let s=0;s<p.length;s+=1){const a=Date.now(),c=`${p[s]}${e}`,v=qn(),R=Object.assign(Object.assign({},v),t),m=/x-www-form-urlencoded/.test(R["Content-Type"])?i:JSON.stringify(i),I=v["Request-Id"];null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_MEDIA_SERVICE_REQUEST_T,JSON.stringify({url:c,"Request-Id":I}),r);const{status:E,data:S}=yield this._runtime.httpReq({url:c,body:m,headers:R,method:o.POST,timeout:this._timeout});if(n&&this._qualityMsList.push({rsdur:Date.now()-a,rsid:I,rscod:200===E?T.SUCCESS:T.REQUEST_FAILED,msa:c}),200===E){const e=JSON.parse(S);return e.rtcFinger&&(this._rtcFinger=e.rtcFinger),e.clusterId&&(this._clusterId=e.clusterId),null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(f.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:C.SUCCESSED,url:c}),r),{code:T.SUCCESS,data:e,qualityMsList:this._qualityMsList}}this._failedMs.push(...this._msInNavi.splice(s,1)),null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.error(f.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:C.FAILED,msg:`request error -> Request-Id: ${I}, status: ${E}, url: ${c}`,timeout:this._timeout}),r)}return{code:T.REQUEST_FAILED,qualityMsList:this._qualityMsList}}))}exchange(e,t,i,r){var n;return S(this,void 0,void 0,(function*(){const o=yield this._request("/exchange",e,t,i,r);if(o.code===T.SUCCESS&&(null===(n=o.data)||void 0===n?void 0:n.resultCode)===T.SUCCESS){const{urls:e}=o.data;e&&(this._configUrl=e.configUrl)}return o}))}exit(e){var t,i;return S(this,void 0,void 0,(function*(){const r=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId(),{code:n}=yield this._request("/exit",e,{},r);return n}))}broadcastSubscribe(e,t){var i,r;const n=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();return this._request("/broadcast/subscribe",e,t,n,!0)}broadcastExit(e){var t,i;return S(this,void 0,void 0,(function*(){const r=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId(),{code:n}=yield this._request("/broadcast/exit",e,{},r,!0);return{code:n}}))}setMcuConfig(e,t){var i,r,n,s,a,c,d,_,l,u;return S(this,void 0,void 0,(function*(){const h=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();if(null===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.info(f.L_MEDIA_SERVICE_SET_MCU_CONFIG_T,JSON.stringify({body:t}),h),!this._configUrl)return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:C.FAILED,code:T.MCU_SERVER_NOT_FOUND,msg:"MCU server not found"}),h),{code:T.MCU_SERVER_NOT_FOUND};const g=`${this._configUrl.replace(/^(https?:\/\/)?/,"https://")}/server/mcu/config`,v=qn(),p=Object.assign(Object.assign({},v),e),R=JSON.stringify(t),m=v["Request-Id"],{status:I,data:E}=yield this._runtime.httpReq({url:g,headers:p,body:R,method:o.POST});if(200===I){const e=JSON.parse(E);return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:C.SUCCESSED,"Request-Id":m}),h),{code:e.resultCode,res:e}}return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:C.FAILED,code:T.REQUEST_FAILED,msg:`request error -> Request-Id: ${m}, status: ${I}, url: ${g}`}),h),{code:T.REQUEST_FAILED}}))}getCDNResourceInfo(e,t,i){var r,n,s,a,c,d;return S(this,void 0,void 0,(function*(){const _=qn(),l=Object.assign(Object.assign({},_),e),u=_["Request-Id"];null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_T,`Request-Id: ${u}, url: ${t}`,i);const{status:h,data:g}=yield this._runtime.httpReq({url:t,headers:l,method:o.GET});if(200===h){const e=JSON.parse(g);return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_R,JSON.stringify({status:C.SUCCESSED,cdnPlayerUrl:null==e?void 0:e.data.pull_url}),i),{code:e.resultCode,res:e}}return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_R,JSON.stringify({status:C.FAILED,code:T.REQUEST_FAILED}),i),{code:T.REQUEST_FAILED}}))}}var Qn;zn.isDetector=!1,zn.msInDetector=[],zn.detectorTime=0,zn.detectValidMinute=72e5,zn.jwtToken="",function(e){e[e.NORMAL=1]="NORMAL",e[e.TINY=2]="TINY"}(Qn||(Qn={}));const Zn=(e,t)=>Math.round(8*t/e),Xn=(e,t=2)=>{const i=10**t;return Math.round(e*i)/i},eo=(e,t=2)=>{e>1&&(e=1);const i=10**t;return Math.round(e*i)},to=(e,t,i,r)=>{if(0===t)return 0;if(!i||!r)return Xn(e/t,3);const n=t-r;if(0===n)return 0;const o=e-i;return o<0||n<0?0:Xn(o/n,3)},io=e=>{const{jitter:t,rtt:i,packetsLostRate:r}=e;return!xt(t)||!xt(i)||0!==r};class ro{constructor(){}static getInstance(){return this._instance||(this._instance=new Map([["sourceIdForPublishMap",new Map],["sourceIdForSubscribeMap",new Map]])),this._instance}static destroy(){this._instance=new Map([["sourceIdForPublishMap",new Map],["sourceIdForSubscribeMap",new Map]])}}var no,oo,so,ao,co,_o,lo,uo,ho,go,vo,po,Ro,mo,Io,Eo,So,To,fo;ro._instance=new Map([["sourceIdForPublishMap",new Map],["sourceIdForSubscribeMap",new Map]]),function(e){e.TRACK="track",e.STREAM="stream",e.MEDIASOURCE="media-source",e.INBOUNDRTP="inbound-rtp",e.OUTBOUNDRTP="outbound-rtp",e.REMOTEINBOUNDRTP="remote-inbound-rtp",e.PEERCONNECTION="peer-connection",e.TRANSPORT="transport",e.CERTIFICATE="certificate",e.CANDIDATEPAIR="candidate-pair",e.REMOTECANDIDATE="remote-candidate",e.LOCALCANDIDATE="local-candidate"}(no||(no={}));class Co{constructor(e,t,i,r){this._rtcPeerConn=e,this._sdpSemantics=t,this._currentUserId=i,this._store=r,this._logger=null,this._latestPacketsSent={},this._latestBytesSent={},this._latestBytesRecv={},this._latestPacketsRecv={},this._logger=We.getLogger()}updateBytesSent(e,t,i){let r,n;if(this._latestBytesSent[e]&&t<this._latestBytesSent[e].bytesSent&&this.clearLatestpacketsSent([e]),this._latestBytesSent[e]){const{bytesSent:o,timestamp:s}=this._latestBytesSent[e];r=t-o,n=i-s,this._latestBytesSent[e]={bytesSent:t,timestamp:i}}else r=t,n=1e3,this._latestBytesSent[e]={bytesSent:t,timestamp:i};return Zn(n,r)}updateBytesRecv(e,t,i){let r,n;if(this._latestBytesRecv[e]&&t<this._latestBytesRecv[e].bytesRecv&&this.clearLatestPacketsRecv([e]),this._latestBytesRecv[e]){const{bytesRecv:o,timestamp:s}=this._latestBytesRecv[e];r=t-o,n=i-s,this._latestBytesRecv[e]={bytesRecv:t,timestamp:i}}else r=t,n=1e3,this._latestBytesRecv[e]={bytesRecv:t,timestamp:i};return Zn(n,r)}updateSenderPacketsLost(e,t,i){let r;if(Object.prototype.hasOwnProperty.call(this._latestPacketsSent[e],"packetsSent")){const{packetsLost:n,packetsSent:o}=this._latestPacketsSent[e];r=to(t,i,n,o),this._latestPacketsSent[e].packetsLost=t,this._latestPacketsSent[e].packetsSent=n===t?o:i}else r=to(t,i),this._latestPacketsSent[e].packetsLost=t,this._latestPacketsSent[e].packetsSent=i;return r}updateReceiverPacketsLost(e,t,i){let r;if(this._latestPacketsRecv[e]){const{packetsLost:n,packetsRecv:o}=this._latestPacketsRecv[e];r=to(t,i+t,n,o+n)}else r=to(t,i);return this._latestPacketsRecv[e]={packetsLost:t,packetsRecv:i},r}clearLatestpacketsSent(e){e.forEach((e=>{if(parseInt(e.split("_").pop())===Je.VIDEO_ONLY){const t=`${e}_tiny`;delete this._latestPacketsSent[t],delete this._latestBytesSent[t]}delete this._latestPacketsSent[e],delete this._latestBytesSent[e]}))}clearLatestPacketsRecv(e){e.forEach((e=>{delete this._latestPacketsRecv[e],delete this._latestBytesRecv[e]}))}parseRTCStatsReport(e){const t={};for(const[i,r]of e.entries())/codec/gi.test(r)&&i.includes("RTCCodec_")||(t[i]=r);return t}formatRCRTCStateReport(e){var t;const i={senders:[],receivers:[]};return null===(t=this._logger)||void 0===t||t.info(f.L_ABSTRACT_STAT_PARSER_FORMAT_RTC_STATE_REPORT_O,JSON.stringify({status:C.SUCCESSED,stats:e,reports:i})),i}getAudioLevelList(e){return[]}isValidSender(e){var t;const i=null===(t=this._rtcPeerConn.currentLocalDescription)||void 0===t?void 0:t.sdp,{ssrc:r}=e;return!(null==i?void 0:i.split("\r\nm=").some((e=>e.includes(r)&&e.includes("a=inactive"))))}isValidReceiver(e){var t;const i=null===(t=this._rtcPeerConn.currentRemoteDescription)||void 0===t?void 0:t.sdp,{ssrc:r}=e;return!(null==i?void 0:i.split("\r\nm=").some((e=>e.includes(r)&&e.includes("a=inactive"))))}formatStateData(e){return Object.values(e).reduce(((e,t)=>t.type===no.REMOTEINBOUNDRTP?(e.remoteInbound.push(t),e):t.type===no.INBOUNDRTP?(e.inbound.push(t),e):t.type===no.OUTBOUNDRTP?(e.outbound.push(t),e):t.type===no.TRANSPORT?(e.transport.push(t),e):t.type===no.PEERCONNECTION?(e.connection.push(t),e):e),{outbound:[],remoteInbound:[],inbound:[],transport:[],connection:[]})}}Co.formatSourceIdMapFromSdp=(e,t)=>{const i=ro.getInstance(),r=null==e?void 0:e.match(/a=ssrc:(.*) msid:(.*?) /gi);if(r){if("publish"===t){const e=i.get("sourceIdForPublishMap");null==e||e.clear(),r.forEach((t=>{const[i,r]=t.split(" ").map((e=>e.split(":")[1]));null==e||e.set(i,r)}))}if("subscribe"===t){const e=i.get("sourceIdForSubscribeMap");null==e||e.clear(),r.forEach((t=>{const[i,r]=t.split(" ").map((e=>e.split(":")[1]));null==e||e.set(i,r)}))}}};class Oo extends Co{formatRCRTCStateReport(e){const{outbound:t,remoteInbound:i,inbound:r,transport:n,connection:o}=this.formatStateData(e),s={senders:[],receivers:[]},a=Math.floor(o[0].timestamp);s.timestamp=a;let c=0,d=0;({totalPacketsLost:c,bitrateSend:d,senders:s.senders}=this.pickOutbound(t,e,c,a,d)),i.length>0&&s.senders.length>0&&this.pickRemoteInbound(i,s.senders,e);let _=0;if(({totalPacketsLost:c,bitrateRecv:_,receivers:s.receivers}=this.pickInbound(r,e,c,a,_)),n.length>0){const t=n[0];this.pickRtcTransport(t,e,s,_,d,c)}return s}pickRtcTransport(e,t,i,r,n,o){const{selectedCandidatePairId:s}=e;if(s){const e=t[s],{availableOutgoingBitrate:a,availableIncomingBitrate:c,currentRoundTripTime:d,localCandidateId:_,remoteCandidateId:l}=e,u=t[_],{ip:h,port:g,networkType:v}=u,p=t[l],{ip:R,port:m,protocol:I}=p;i.iceCandidatePair={IP:h,port:g,networkType:v,remoteIP:R,remotePort:m,protocol:I,bitrateRecv:r,bitrateSend:n,rtt:1e3*d,availableOutgoingBitrate:a,availableIncomingBitrate:c,totalPacketsLost:o},i.receivers.forEach((e=>{e.rtt=d}))}}pickRemoteInbound(e,t,i){e.forEach((e=>{var r;const{localId:n,jitter:o,roundTripTime:s,packetsLost:a}=e,c=t.filter((e=>e.id===n))[0];if(c&&!io(c)){const e=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i[c.id].ssrc);c.jitter=Math.round(1e3*o),c.rtt=s;const t=this._latestPacketsSent[e].crtPacketsSent;c.packetsLostRate=this.updateSenderPacketsLost(e,a,t)}}))}pickOutbound(e,t,i,r,n){const o=[];return e.forEach((e=>{var s;if("unified-plan"===this._sdpSemantics&&!this.isValidSender(e))return;const{id:a,kind:c,transportId:d,mediaSourceId:_,remoteId:l,packetsSent:u,bytesSent:h,trackId:g,encoderImplementation:v,pliCount:p,nackCount:R,firCount:m}=e;if(!g)return;let{framesPerSecond:I,frameWidth:E,frameHeight:S}=e;"video"!==c||E||S||I||(E=t[g].frameWidth,S=t[g].frameHeight,I=_?t[_].framesPerSecond:null);const T=t[l];let f=null,C=null,O=0;T&&(f=T.jitter,C=T.roundTripTime,O=T.packetsLost),i+=O;const L=null===(s=this._store)||void 0===s?void 0:s.getTrackIdBySSRC(e.ssrc);if(!L)return;const N=_?t[_].audioLevel:t[g].audioLevel;let A=null;!this._latestPacketsSent[L]&&(this._latestPacketsSent[L]={}),T?A=this.updateSenderPacketsLost(L,O,u):this._latestPacketsSent[L].crtPacketsSent=u;let y=this.updateBytesSent(L,h,r);y<0&&(y=0),n+=y,o.push({id:a,trackId:L,kind:c,packetsLostRate:A,remoteResource:!1,audioLevel:N||0===N?eo(N):null,frameWidth:E,frameHeight:S,frameRate:I,bitrate:y,jitter:f?Math.round(1e3*f):f,rtt:C,encoderImplementation:v,pliCount:p,nackCount:R,googFirsSent:Kn,samplingRate:Kn,googRenderDelayMs:Kn,trackState:Kn})})),{totalPacketsLost:i,bitrateSend:n,senders:o}}pickInbound(e,t,i,r,n){let o=[];return e.forEach((e=>{var s;if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(e))return;const{trackId:a,packetsLost:c,packetsReceived:d,jitter:_,bytesReceived:l,framesPerSecond:u,kind:h,codecImplementationName:g,nackCount:v,pliCount:p}=e;if(!a)return;let{frameWidth:R,frameHeight:m,audioLevel:I}=e;"video"===h?R||m||(R=t[a].frameWidth,m=t[a].frameHeight):I||(I=t[a].audioLevel),i+=c;const E=null===(s=this._store)||void 0===s?void 0:s.getTrackIdBySSRC(e.ssrc),S=this.updateReceiverPacketsLost(E,c,d);let T=this.updateBytesRecv(E,l,r);T<0&&(T=0),n+=T,o.push({trackId:E,kind:h,packetsLostRate:S,remoteResource:!0,audioLevel:I||0===I?eo(I):null,frameWidth:R,frameHeight:m,frameRate:u,bitrate:T,jitter:_?Math.round(1e3*_):0,codecImplementationName:g,nackCount:v,pliCount:p,rtt:null,samplingRate:Kn,googFirsReceived:Kn,googRenderDelayMs:Kn,trackState:Kn})})),{totalPacketsLost:i,bitrateRecv:n,receivers:o}}getAudioLevelList(e){const t=[],{outbound:i,inbound:r}=this.formatStateData(e);i.filter((e=>"audio"===(null==e?void 0:e.kind))).forEach((i=>{var r,n;if("unified-plan"===this._sdpSemantics&&!this.isValidSender(i))return;const{mediaSourceId:o,trackId:s,kind:a}=i,c=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i.ssrc),d=o&&e[o]?e[o].audioLevel:(null===(n=e[s])||void 0===n?void 0:n.audioLevel)||null;c&&t.push({trackId:c,audioLevel:d||0===d?eo(d):null})}));return r.filter((e=>"audio"===(null==e?void 0:e.kind))).forEach((i=>{var r;if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(i))return;const{trackId:n}=i,o=i.audioLevel||e[n].audioLevel,s=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i.ssrc);s&&t.push({trackId:s,audioLevel:o||0===o?eo(o):null})})),t}}class Lo extends Co{formatRCRTCStateReport(e){var t,i,r;const n=+new Date,o={senders:[],receivers:[],timestamp:n};let s=0,a=0,c=0;for(const d in e){const _=e[d],{type:l}=_;if("outbound-rtp"===l){if("unified-plan"===this._sdpSemantics&&!this.isValidSender(_))continue;const{id:i,kind:r,bytesSent:c,packetsSent:d,bitrateMean:l,framerateMean:u,nackCount:h,pliCount:g,remoteId:v}=_,{jitter:p,roundTripTime:R,packetsLost:m}=v?e[v]:{jitter:null,roundTripTime:null,packetsLost:0},I=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(_.ssrc);s+=m;let E=null;!this._latestPacketsSent[I]&&(this._latestPacketsSent[I]={}),v?E=this.updateSenderPacketsLost(I,m,d):this._latestPacketsSent[I].crtPacketsSent=d;let S=0;"video"===r?l&&(S=Math.floor(l/1e3)):S=this.updateBytesSent(I,c,n),S<0&&(S=0),a+=S,o.senders.push({trackId:I,kind:r,packetsLostRate:E,remoteResource:!1,audioLevel:null,frameWidth:null,frameHeight:null,frameRate:Math.floor(u),bitrate:S,jitter:p?Math.round(1e3*p):null,rtt:R,encoderImplementation:null,pliCount:g,nackCount:h,googFirsSent:Kn,samplingRate:Kn,googRenderDelayMs:Kn,trackState:Kn})}if("remote-inbound-rtp"===l){const{localId:t}=_,r=null===(i=this._store)||void 0===i?void 0:i.getTrackIdBySSRC(e[t].ssrc),n=o.senders.filter((e=>e.trackId===r))[0];n&&io(n)&&(n.jitter=Math.round(1e3*_.jitter),n.rtt=_.rtt,n.packetsLostRate=this.updateSenderPacketsLost(r,_.packetsLost,this._latestPacketsSent[r].crtPacketsSent))}if("inbound-rtp"===l){if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(_))continue;const{id:e,packetsLost:t,bytesReceived:i,packetsReceived:a,jitter:d,framerateMean:l,kind:u,bitrateMean:h,nackCount:g,pliCount:v}=_,p=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(_.ssrc);s+=t;const R=this.updateReceiverPacketsLost(p,t,a);let m=0;"video"===u?h&&(m=Math.floor(h/1e3)):m=this.updateBytesRecv(p,i,n),m<0&&(m=0),c+=m,o.receivers.push({trackId:p,kind:u,packetsLostRate:R,remoteResource:!0,audioLevel:null,frameWidth:null,frameHeight:null,frameRate:Math.floor(l),bitrate:m,jitter:d?Math.round(1e3*d):null,codecImplementationName:null,nackCount:g,pliCount:v,rtt:null,samplingRate:Kn,googFirsReceived:Kn,googRenderDelayMs:Kn,trackState:Kn})}if("candidate-pair"===l&&"succeeded"===_.state){const t=e[_.localCandidateId],{address:i,port:r}=t,n=e[_.remoteCandidateId],{address:d,port:l,protocol:u}=n;o.iceCandidatePair={IP:i,port:r,networkType:null,remoteIP:d,remotePort:l,protocol:u,bitrateRecv:c,bitrateSend:a,rtt:null,availableOutgoingBitrate:null,availableIncomingBitrate:null,totalPacketsLost:s}}}return o.iceCandidatePair&&(o.iceCandidatePair.bitrateSend=a),o.iceCandidatePair&&(o.iceCandidatePair.bitrateRecv=c),o}getAudioLevelList(e){var t,i;const r=[];for(const n in e){const o=e[n],{type:s}=o;if("outbound-rtp"===s){if("unified-plan"===this._sdpSemantics&&!this.isValidSender(o))continue;const{kind:e}=o;if("video"===e)continue;const i=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(o.ssrc);r.push({trackId:i,audioLevel:null})}if("inbound-rtp"===s){if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(o))continue;const{kind:e}=o;if("video"===e)continue;const t=null===(i=this._store)||void 0===i?void 0:i.getTrackIdBySSRC(o.ssrc);r.push({trackId:t,audioLevel:null})}}return r}}class No extends Co{formatRCRTCStateReport(e){const t={senders:[],receivers:[]},i=Math.floor(e.RTCPeerConnection.timestamp);t.timestamp=i;const r=Object.keys(e);let n=0,o=0;r.filter((e=>/^RTCOutboundRTP(Video|Audio)Stream_/.test(e))).forEach((r=>{var n;const s=e[r];if("unified-plan"===this._sdpSemantics&&!this.isValidSender(s))return;const a=null===(n=this._store)||void 0===n?void 0:n.getTrackIdBySSRC(s.ssrc),{mediaType:c,transportId:d,remoteId:_,packetsSent:l,bytesSent:u,trackId:h,encoderImplementation:g,pliCount:v,nackCount:p,firCount:R}=s;if(!h)return;const{audioLevel:m,frameHeight:I,frameWidth:E}=e[h];let S=this.updateBytesSent(a,u,i);S<0&&(S=0),o+=S,t.senders.push({trackId:a,kind:c,packetsLostRate:null,remoteResource:!1,audioLevel:m||0===m?eo(m):null,frameWidth:E,frameHeight:I,frameRate:null,bitrate:S,jitter:null,rtt:null,encoderImplementation:g,pliCount:v,nackCount:p,googFirsSent:Kn,samplingRate:Kn,googRenderDelayMs:Kn,trackState:Kn})}));let s=0;r.filter((e=>/^RTCInboundRTP(Video|Audio)Stream_/.test(e))).forEach((r=>{var o;const a=e[r];if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(a))return;const{trackId:c,packetsLost:d,packetsReceived:_,jitter:l,bytesReceived:u,mediaType:h,nackCount:g,pliCount:v}=a,p=null===(o=this._store)||void 0===o?void 0:o.getTrackIdBySSRC(a.ssrc);if(!c)return;const{frameHeight:R,frameWidth:m,audioLevel:I}=e[c];n+=d;const E=this.updateReceiverPacketsLost(p,d,_);let S=this.updateBytesRecv(p,u,i);S<0&&(S=0),s+=S,t.receivers.push({trackId:p,kind:h,packetsLostRate:E,remoteResource:!0,audioLevel:I||0===I?eo(I):null,frameWidth:m,frameHeight:R,frameRate:null,bitrate:S,jitter:l,codecImplementationName:null,nackCount:g,pliCount:v,rtt:null,samplingRate:Kn,googFirsReceived:Kn,googRenderDelayMs:Kn,trackState:Kn})}));const a=r.filter((e=>/^RTCTransport_/.test(e)))[0];if(a){const i=e[a],{selectedCandidatePairId:r}=i;if(r){const i=e[r],{availableOutgoingBitrate:a,availableIncomingBitrate:c,currentRoundTripTime:d,localCandidateId:_,remoteCandidateId:l}=i,u=e[_],{address:h,port:g}=u,v=e[l],{address:p,port:R,protocol:m}=v;t.iceCandidatePair={IP:h||null,port:g,networkType:null,remoteIP:p,remotePort:R,protocol:m,bitrateRecv:s,bitrateSend:o,rtt:1e3*d,availableOutgoingBitrate:a,availableIncomingBitrate:c,totalPacketsLost:n},t.receivers.forEach((e=>{e.rtt=d}))}}return t}getAudioLevelList(e){const t=[],i=Object.keys(e);i.filter((e=>/^RTCOutboundRTP(Video|Audio)Stream_/.test(e))).forEach((i=>{var r;const n=e[i];if("unified-plan"===this._sdpSemantics&&!this.isValidSender(n))return;const{trackId:o,mediaType:s}=n;if("video"===s)return;const a=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(n.ssrc),c=e[o];t.push({trackId:a,audioLevel:c||0===c?eo(c):null})}));return i.filter((e=>/^RTCInboundRTP(Video|Audio)Stream_/.test(e))).forEach((i=>{var r;const n=e[i];if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(n))return;const{trackId:o,mediaType:s}=n;if(!o||"video"===s)return;const{audioLevel:a}=e[o],c=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(n.ssrc);t.push({trackId:c,audioLevel:a||0===a?eo(a):null})})),t}}class Ao{get videoSdps(){return this.videoStreams.slice()}get audioSdps(){return this.audioStreams.slice()}constructor(e,t){this.SDP=e,this.type=t,this.SDPHeader="",this.videoStreams=[],this.audioStreams=[],this._logger=null;const i=this.getStreamIndex();this.spliteStreams(i),this._logger=We.getLogger()}static trimBlankLine(e){return e.replace(/\n\r\s*\r\n/g,"\r\n").replace(/\s+\r\n/g,"\r\n")}getStreamIndex(){const e=new RegExp("m=(?:video|audio)","img"),t=new Set([0]);let i=e.exec(this.SDP);for(;null!==i;)t.add(null==i?void 0:i.index),i=e.exec(this.SDP);return t.add(this.SDP.length),[...t]}spliteStreams(e){this.SDPHeader=this.SDP.substring(e[0],e[1]).replace(/\r\ns=-/g,`\r\ns=${(new Date).valueOf()}`);for(let t=1;t<e.length;t++){const i=this.SDP.substring(e[t],e[t+1]);/^\bm=video\b/.test(i)?this.videoStreams.push(i):this.audioStreams.push(i)}}static clearInactiveOrRecvonly(e){return/\ba=(recvonly|inactive)\b/.test(e)?e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,""):e}setHeaderBitrate(e){this.SDPHeader=this.SDPHeader.replace(/(\r\ns=[^\r\n]+)/gi,`$1\r\nc=IN IP4 0.0.0.0\r\nb=AS:${e*Ao.KBitrate}\r\nb=TIAS:${e*Ao.KBitrate*850}`)}setAudiosBitrate(e){return this.audioStreams=this.audioStreams.map((t=>this.setAudioItemBitrate(t,e))),this}setAudioBitrateWithStreamId(e,t){return this.audioStreams=this.audioStreams.map((i=>new RegExp(`\\bmsid:${t}\\b`,"ig").test(i)?this.setAudioItemBitrate(i,e):i)),this}setAudioBitrateWithMid(e,t){return this.audioStreams=this.audioStreams.map((i=>new RegExp(`\\bmid:${t}\\b`,"ig").test(i)?this.setAudioItemBitrate(i,e):i)),this}setAudioItemBitrate(e,t){if(0===t.max&&/\ba=inactive\b/gi.test(e))return e;if(!/\bmaxaveragebitrate\b/gi.test(e)){const i=["$1","maxaveragebitrate="+t.max*Ao.KBitrate];e=e.replace(/(\buseinbandfec=[^\r\n]+)/gi,i.join(";"))}return this.addAudioBlineAS(e,t)}addAudioBlineAS(e,t){return/\bb=AS:\d+\b/gi.test(e)?e:e.replace(/(\bc=IN[^\r\n]+)/gi,`$1\r\nb=AS:${t.max*Ao.KBitrate}\r\nb=TIAS:${t.max*Ao.KBitrate*850}`)}setVideosBitrate(e){return this.videoStreams=this.videoStreams.map((t=>this.setVideoItemBitrate(t,e))),this}setVideoBitrateWithStreamId(e,t){return this.videoStreams=this.videoStreams.map((i=>new RegExp(`\\bmsid:${t}\\b`,"ig").test(i)?this.setVideoItemBitrate(i,e):i)),this}setVideoBitrateWithMid(e,t){return this.videoStreams=this.videoStreams.map((i=>new RegExp(`\\bmid:${t}\\b`,"ig").test(i)?this.setVideoItemBitrate(i,e):i)),this}setVideoItemBitrate(e,t){if(0===t.max&&/\ba=inactive\b/gi.test(e))return e;if(!/\bx-google-max-bitrate\b/.test(e)){const i=["$1","x-google-max-bitrate="+t.max*Ao.KBitrate,"x-google-min-bitrate="+t.min*Ao.KBitrate,`x-google-start-bitrate=${t.start||t.max*Ao.KBitrate*.7}`];e=e.replace(/(\bprofile-level-id=42[e0]01f\b)/gi,i.join(";"))}return this.addVideoBlineAS(e,t)}addVideoBlineAS(e,t){return/\bb=AS:\d+\b/gi.test(e)?e:e.replace(/(\bc=IN[^\r\n]+)/gi,`$1\r\nb=AS:${t.max*Ao.KBitrate}\r\nb=TIAS:${t.max*Ao.KBitrate*850}`)}clearnSsrcWithMid(e,t){return this.audioStreams=this.audioStreams.map((i=>new RegExp(`\\bmid:${e}\\b`,"ig").test(i)?this.clearSSRC(i,t):i)),this.videoStreams=this.videoStreams.map((i=>new RegExp(`\\bmid:${e}\\b`,"ig").test(i)?this.clearSSRC(i,t):i)),this}clearSSRC(e,t){if(t===so.SENDONLY){if(/\ba=sendonly\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}if(t===so.RECVONLY){if(/\ba=recvonly\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}if(t===so.INACTIVE){if(/\ba=inactive\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}return e}}Ao.KBitrate=1,function(e){e.PLANB="plan-b",e.UNIFIEDPLAN="unified-plan"}(oo||(oo={})),function(e){e.SENDONLY="sendonly",e.RECVONLY="recvonly",e.INACTIVE="inactive"}(so||(so={}));class yo{static setSdpSemantics(e){const t=We.getLogger(),{browser:i,version:r,supportsUnifiedPlan:n}=Ut;null==t||t.info(f.L_A_SDP_STRATEGY_SET_SDP_SEMANTICS_O,JSON.stringify({sdpSemantics:e,supportsUnifiedPlan:n,browser:i,version:r})),n?/chrome/i.test(i)?this._sdpSemantics=r>92?"unified-plan":r<72?"plan-b":e:/firefox/i.test(i)?this._sdpSemantics="unified-plan":/safari/i.test(i)?this._sdpSemantics=r<12?"plan-b":"unified-plan":this._sdpSemantics="unified-plan":this._sdpSemantics="plan-b"}static getSdpSemantics(){return yo._sdpSemantics}constructor(e){this._peer=e,this._outboundStreams={},this._logger=null,this._logger=We.getLogger()}getOutboundVideoInfo(){const e=[];for(const t in this._outboundStreams){const i=this._outboundStreams[t].getVideoTracks()[0];if(!i)continue;const r=/_tiny$/.test(t),{width:n,height:o}=St(i);e.push({trackId:i.id,simulcast:r?Qn.TINY:Qn.NORMAL,resolution:`${n}x${o}`})}return e}setRemoteAnswer(e){var t,i,r;return S(this,void 0,void 0,(function*(){if(e=Ao.trimBlankLine(e),"disconnected"===this._peer.connectionState||"closed"===this._peer.connectionState)return null===(t=this._logger)||void 0===t||t.info(f.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:C.FAILED,msg:`peer.connectionState is ${this._peer.connectionState}`})),T.SET_REMOTE_DESCRIPTION_FAILED;try{yield this._peer.setRemoteDescription({type:"answer",sdp:e})}catch(e){return null===(i=this._logger)||void 0===i||i.info(f.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:C.FAILED,msg:e})),T.SET_REMOTE_DESCRIPTION_FAILED}return null===(r=this._logger)||void 0===r||r.info(f.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:C.SUCCESSED,sdp:e})),T.SUCCESS}))}getStatParsr(e,t,i,r){return/chrome/i.test(Ut.browser)?new Oo(e,t,i,r):/Firefox/i.test(Ut.browser)?new Lo(e,t,i,r):/Safari/i.test(Ut.browser)?new No(e,t,i,r):null}resetSdp(e){return Ao.trimBlankLine(e)}}class ko extends Ao{constructor(e){super(e,oo.PLANB),this.SDP=e}stringify(){const e=[this.SDPHeader];[...this.audioStreams,...this.videoStreams].forEach((t=>{const i=t.match(/\ba=mid:(video|audio)\b/),r=Ao.clearInactiveOrRecvonly(t);i&&i[1]===ze.AUDIO&&(e[1]=r),i&&i[1]===ze.VIDEO&&(e[2]=r)}));const t=e.join("");return Ao.trimBlankLine(t)}setAudioBitrateWithStreamId(e,t){var i;return null===(i=this._logger)||void 0===i||i.warn(f.L_FUNCTION_IS_UNAVAILABLE,"plan-b not support set Audio Bitrate With Stream Id"),this}setVideoBitrateWithStreamId(e,t){var i;return null===(i=this._logger)||void 0===i||i.warn(f.L_FUNCTION_IS_UNAVAILABLE,"plan-b not support set Video Bitrate With Stream Id"),this}}class Do extends yo{constructor(){super(...arguments),this.senders={},this._localTracks=[]}addLocalTrack(e){this._localTracks.includes(e)||this._localTracks.push(e);const t=e.getStreamId(),i=e.__innerGetMediaStreamTrack(),r=this._outboundStreams[t]||(this._outboundStreams[t]=new MediaStream);r.getTracks().forEach((e=>{e.kind===i.kind&&r.removeTrack(e)})),r.addTrack(i);const n=e.getTrackId(),o=this.senders[n];o?o.replaceTrack(i):(this.senders[n]=this._peer.addTrack(i,r),Object.defineProperty(i,"trackId",{value:n,writable:!1,enumerable:!1,configurable:!1}))}removeLocalTrack(e){const t=this._localTracks.findIndex((t=>t===e));t>=0&&this._localTracks.splice(t,1);const i=e.getTrackId(),r=this.senders[i];r&&(r.replaceTrack(null),this._peer.removeTrack(r),delete this.senders[i])}updateSubRemoteTracks(e){}updateRecvTransceiverMap(e,t){}setBitrate(e,t,i){this._maxBitrate=e,this._minBitrate=t,this._startBitrate=i||.7*e}createOffer(e){return S(this,void 0,void 0,(function*(){const t=yield this._peer.createOffer({iceRestart:e,offerToReceiveAudio:!0,offerToReceiveVideo:!0});for(const e in this._outboundStreams){const i=this._outboundStreams[e].id;t.sdp=t.sdp.replace(new RegExp(i,"g"),e)}return t.sdp&&(t.sdp=this.resetSdp(t.sdp)),yield this._peer.setLocalDescription(t),{type:"offer",semantics:"plan-b",sdp:t.sdp}}))}setRemoteAnswer(e){return e=this.resetSdp(e),super.setRemoteAnswer(e)}resetSdp(e){const t=new ko(e),i={max:0,min:0},r={max:0,min:0};return this._localTracks.forEach((e=>{const{min:t,max:n,start:o}=e.getBitrate();e.isAudioTrack()&&(r.max=r.max<n?n:r.max,r.min=r.min>t?t:r.min,r.max===n?r.start=o:r.start=.7*r.max),e.isVideoTrack()&&(i.max=i.max<n?n:i.max,i.min=i.min>t?t:i.min,i.max===n?i.start=o:i.start=.7*i.max)})),t.setAudiosBitrate(r),t.setVideosBitrate(i),t.stringify()}}class bo extends Ao{constructor(e){super(e,oo.UNIFIEDPLAN),this.SDP=e}stringify(){const e=[this.SDPHeader];[...this.audioStreams,...this.videoStreams].forEach((t=>{const i=t.match(/\ba=mid:(\d+)\b/);i&&i[1]&&(e[+i[1]+1]=t)})),this.SDPHeader="",this.videoStreams=[],this.audioStreams=[];const t=e.join("");return Ao.trimBlankLine(t)}}class Uo{static splitSections(e){return e.split("\nm=").map(((e,t)=>`${(t>0?`m=${e}`:e).trim()}\r\n`))}static getMediaSections(e){const t=Uo.splitSections(e);return t.shift(),t}static parseExtmap(e){const t=e.substr(9).split(" ");return{id:parseInt(t[0],10),direction:t[0].indexOf("/")>0?t[0].split("/")[1]:"sendrecv",uri:t[1]}}static splitLines(e){return e.trim().split("\n").map((e=>e.trim()))}static parseMLine(e){const t=Uo.splitLines(e)[0].substr(2).split(" ");return{kind:t[0],port:parseInt(t[1],10),protocol:t[2],fmt:t.slice(3).join(" ")}}static matchPrefix(e,t){return Uo.splitLines(e).filter((e=>0===e.indexOf(t)))}static parseMsid(e){let t;const i=Uo.matchPrefix(e,"a=msid:");if(1===i.length)return t=i[0].substr(7).split(" "),{stream:t[0],track:t[1]};const r=Uo.matchPrefix(e,"a=ssrc:").map((e=>Uo.parseSsrcMedia(e))).filter((e=>"msid"===e.attribute));return r.length>0&&r[0].value?(t=r[0].value.split(" "),{stream:t[0],track:t[1]}):{stream:"",track:""}}static parseSsrcMedia(e){const t=e.indexOf(" "),i={ssrc:parseInt(e.substr(7,t-7),10)},r=e.indexOf(":",t);return r>-1?(i.attribute=e.substr(t+1,r-t-1),i.value=e.substr(r+1)):i.attribute=e.substr(t+1),i}static getMid(e){const t=Uo.matchPrefix(e,"a=mid:")[0];if(t)return t.substr(6)}}class Po{constructor(){this.__streams=new Map}static getInstance(){return Po.instance||(Po.instance=new Po),Po.instance}push(e,t){return this.__streams.set(e,t),t}pickup(e){return this.__streams.get(e)}delete(e){return this.__streams.delete(e)}get streams(){const e=new Map;for(const t of this.__streams.keys())e.set(t,this.pickup(t));return e}}class Mo extends yo{constructor(){super(...arguments),this._sendTransceiver={},this._localTracks={},this._recvAudio=[],this._recvVideo=[],this._recvTransceiver={},this._subedTracks=[],this.midMsid={}}setBitrate(e,t,i){var r;null===(r=this._logger)||void 0===r||r.warn(f.L_FUNCTION_IS_UNAVAILABLE,"the interface named `setBitrate` is invalid while sdpSemantics value is `unified-plan`")}addLocalTrack(e){var t;const i=e.getTrackId(),r=e.getStreamId(),n=e.__innerGetMediaStreamTrack();this._localTracks[i]=e;const o=this._outboundStreams[r]||(this._outboundStreams[r]=new MediaStream);o.getTracks().forEach((e=>{e.kind===n.kind&&o.removeTrack(e)})),o.addTrack(n);const s=this._sendTransceiver[i];s?(s.sender.replaceTrack(n),s.direction="sendonly"):this._sendTransceiver[i]=this._peer.addTransceiver(n,{direction:"sendonly",streams:[o]});Po.getInstance().push(i,{msid:r,id:this._outboundStreams[r].id,kind:null===(t=e.streamTrack)||void 0===t?void 0:t.kind})}removeLocalTrack(e){const t=e.getTrackId(),i=e.getStreamId();e.__innerGetMediaStreamTrack(),delete this._localTracks[t];const r=this._sendTransceiver[t];if(!r)return;"closed"!==this._peer.connectionState&&(r.direction="inactive",this._peer.removeTrack(r.sender),r.sender.replaceTrack(null));const n=this._outboundStreams[i];(e.isAudioTrack()?n.getAudioTracks():n.getVideoTracks()).forEach((e=>n.removeTrack(e)));const o=this._sendTransceiver[`${t}_tiny`];if(o&&"inactive"!==o.direction&&"closed"!==this._peer.connectionState){o.direction="inactive";const{sender:e}=o,t=e.track;this._peer.removeTrack(e),e.replaceTrack(null);this._outboundStreams[`${i}_tiny`].removeTrack(t),t.stop()}}updateRecvTransceiverMap(e,t){const{mediaType:i}=Ct(e);this._recvTransceiver[e]=t;const r=i===Je.AUDIO_ONLY?this._recvAudio:this._recvVideo,n=r.findIndex((e=>e===t));n>=0&&r.splice(n,1)}updateSubRemoteTracks(e){const t=e.slice(),i=this._subedTracks.slice();this._subedTracks=e.slice();for(let e=t.length-1;e>=0;e-=1){const r=t[e],n=i.findIndex((e=>e===r));n>=0&&(t.splice(e,1),i.splice(n,1))}i.length&&i.forEach((e=>{const t=e.getTrackId();e.__innerSetMediaStreamTrack(void 0);const i=this._recvTransceiver[t];i&&(i.direction="inactive")}));const r={audio:0,video:0};t.length&&t.forEach((e=>{const t=e.isAudioTrack()?"audio":"video",i=this._recvTransceiver[e.getTrackId()];i?i.direction="recvonly":r[t]+=1}));for(let e=this._recvAudio.length;e<r.audio;e+=1)this._recvAudio.push(this._peer.addTransceiver("audio",{direction:"recvonly"}));for(let e=this._recvVideo.length;e<r.video;e+=1)this._recvVideo.push(this._peer.addTransceiver("video",{direction:"recvonly"}))}createOffer(e){return S(this,void 0,void 0,(function*(){const t=yield this._peer.createOffer({iceRestart:e});let i=t.sdp;for(const e in this._outboundStreams){const t=this._outboundStreams[e].id;i=i.replace(new RegExp(t,"g"),e)}return i=this.resetOfferSdp(i),i=i.replace(/(a=ice-options:trickle)/g,"$1\r\na=ice-options:renomination"),t.sdp=i,yield this._peer.setLocalDescription(t),{type:"offer",semantics:"unified-plan",sdp:i}}))}setRemoteAnswer(e){e=this.resetAnswerSdp(e);const t=/[\r\n]+\r\n[\r\n]+/g;return t.test(e)&&(e=e.replace(t,"\r\n")),super.setRemoteAnswer(e)}resetOfferSdp(e){var t;const i=new bo(e);for(const r in this._sendTransceiver){const n=this._sendTransceiver[r],o=null===(t=n.sender.track)||void 0===t?void 0:t.kind;let{direction:s,mid:a}=n;if(!a){Uo.getMediaSections(e).forEach((e=>{Uo.parseExtmap(e);const{kind:t}=Uo.parseMLine(e);let{stream:i}=Uo.parseMsid(e);const n=Uo.getMid(e);"video"===o?/tiny$/.test(i)?i=i.replace(/tiny$/gi,"1_tiny"):i+="_1":i+="_0",i===r&&o===t&&n&&(a=n)}))}if(a){if(s===so.SENDONLY){const e=this._localTracks[r],t=null==e?void 0:e.getBitrate();o===ze.AUDIO&&t&&i.setAudioBitrateWithMid(t,a),o===ze.VIDEO&&t&&i.setVideoBitrateWithMid(t,a)}s===so.INACTIVE&&i.clearnSsrcWithMid(a,so.INACTIVE)}}for(const e in this._recvTransceiver){const t=this._recvTransceiver[e],{direction:r,mid:n}=t;n&&r===so.INACTIVE&&i.clearnSsrcWithMid(n,so.RECVONLY)}return i.stringify()}resetAnswerSdp(e){var t;const i=new bo(e);for(const e in this._sendTransceiver){const r=this._sendTransceiver[e],{mid:n}=r;if(n){const o=this._localTracks[e],s=null==o?void 0:o.getBitrate(),a=null===(t=r.sender.track)||void 0===t?void 0:t.kind;a===ze.AUDIO&&s&&i.setAudioBitrateWithMid(s,n),a===ze.VIDEO&&s&&i.setVideoBitrateWithMid(s,n)}}return i.stringify()}}!function(e){e.VP8="VP8",e.VP9="VP9",e.H264="H264"}(ao||(ao={}));class xo extends e{constructor(e,t,i,r,n,o,s=!1,a){super(),this._pcName=e,this._reTryExchange=t,this._currentUserId=i,this._polarisReport=r,this.onTrackTrouble=n,this._store=o,this._isRoomAudience=s,this._initOptions=a,this.senderAndReciveSize=32,this.pubLocalTracks={},this._reTryExchangeTimer=null,this._reportStatsTimer=null,this._reportR3R4ToPolarisTimer=null,this._isDestroyed=!1,this._formatStatsData=null,this._logger=null,this._reportListener=null,this.troubleTracksCollection=new Map;const c=yo.getSdpSemantics(),d=this._rtcPeerConn=new RTCPeerConnection({sdpSemantics:c});this._sdpStrategy="plan-b"===c?new Do(d):new Mo(d),this._rtcPeerConn.oniceconnectionstatechange=this._onICEConnectionStateChange.bind(this),this._rtcPeerConn.onconnectionstatechange=this._onConnectionStateChange.bind(this),this._rtcPeerConn.ontrack=this._onTrackReady.bind(this),this.reportParser=this._sdpStrategy.getStatParsr(this._rtcPeerConn,c,this._currentUserId,this._store),this._logger=We.getLogger()}getName(){return this._pcName}getLocalTracks(){return Object.values(this.pubLocalTracks)}_onConnectionStateChange(){var e;null===(e=this._logger)||void 0===e||e.info(f.L_RTC_PEER_CONNECTION_CONNECTION_STATE_S,JSON.stringify({connectionState:this._rtcPeerConn.connectionState,pcName:this._pcName}))}startAutoExecute(e){this.stopAutoExecute(),this._reportStatsTimer=setTimeout((()=>{this._reportHandle(),this.startAutoExecute(e)}),e)}stopAutoExecute(){clearTimeout(this._reportStatsTimer)}_onICEConnectionStateChange(){var e,t,i,r;return S(this,void 0,void 0,(function*(){null===(e=this._logger)||void 0===e||e.info(f.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_S,JSON.stringify({connectionState:this._rtcPeerConn.connectionState,pcName:this._pcName}));const n=yield this._getStatsData(),o=n?this._createRCRTCStateReport(n).iceCandidatePair:null,{iceConnectionState:s}=this._rtcPeerConn;this.emit(xo.__INNER_ICE_STATE_CHANGE__,{status:s,time:Date.now(),iceCandidatePair:o}),"connected"===s&&(this.emit(xo.__INNER_ICE_CONNECTED__),this.startAutoExecute(1e3)),"failed"!==s&&"disconnected"!==s||(this._reTryExchange(),this._reTryExchangeTimer=setInterval(this._reTryExchange,15e3));try{null===(i=null===(t=this._reportListener)||void 0===t?void 0:t.onICEConnectionStateChange)||void 0===i||i.call(t,s,this._pcName)}catch(e){null===(r=this._logger)||void 0===r||r.error(f.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_REPORT_R,JSON.stringify({status:C.FAILED,pcName:this._pcName,mag:e}))}}))}_onTrackReady(e){if(!e.streams.length)return;const t=e.streams[0].id,{track:i}=e.receiver,r=[t,"audio"===i.kind?Je.AUDIO_ONLY:Je.VIDEO_ONLY].join("_");Object.defineProperty(i,"trackId",{value:r,writable:!1,enumerable:!1,configurable:!1}),this._updateRecvTransceiverMap(r,e.transceiver),this.emit(xo.__INNER_EVENT_TRACK_READY__,e)}setBitrate(e,t,i){var r;return S(this,void 0,void 0,(function*(){this._sdpStrategy.setBitrate(e,t,i),null===(r=this._logger)||void 0===r||r.info(f.L_RTC_PEER_CONNECTION_SET_BITRATE_O,JSON.stringify({status:C.SUCCESSED,max:e,min:t,start:i}))}))}createOffer(e){var t;return S(this,void 0,void 0,(function*(){const i=yield this._sdpStrategy.createOffer(e);return null===(t=this._logger)||void 0===t||t.info(f.L_RTC_PEER_CONNECTION_CREATE_OFFER_O,JSON.stringify({offerSDP:i.sdp,sdpDemantics:i.semantics})),i}))}setRemoteAnswer(e){return S(this,void 0,void 0,(function*(){return this._sdpStrategy.setRemoteAnswer(e)}))}getLocalTrack(e){return this.pubLocalTracks[e]||null}addLocalTrack(e){var t;this.pubLocalTracks[e.getTrackId()]=e,this._sdpStrategy.addLocalTrack(e),e.off(rt.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(rt.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),e.on(rt.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.on(rt.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),null===(t=this._logger)||void 0===t||t.info(f.L_RTC_PEER_CONNECTION_ADD_LOCAL_TRACK_O,JSON.stringify({trackId:e.getTrackId()}))}removeLocalTrackById(e){var t,i;const r=this.getLocalTrack(e);r?(null===(i=this._logger)||void 0===i||i.info(f.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_BY_ID_O,JSON.stringify({status:C.SUCCESSED,trackId:e})),this.removeLocalTrack(r)):null===(t=this._logger)||void 0===t||t.warn(f.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_BY_ID_O,JSON.stringify({status:C.FAILED,msg:"track not found",trackId:e}))}removeAllLocalTrack(){Object.keys(this.pubLocalTracks).forEach((e=>{/_tiny$/.test(e)||this.removeLocalTrackById(e)}))}removeLocalTrack(e){var t;const i=e.getTrackId();delete this.pubLocalTracks[i],this._sdpStrategy.removeLocalTrack(e),e.__innerSetPublished(!1),e.off(rt.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(rt.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this);const r=`${i}_tiny`,n=this.getLocalTrack(r);n&&(this._sdpStrategy.removeLocalTrack(n),delete this.pubLocalTracks[r],n.destroy()),null===(t=this._logger)||void 0===t||t.info(f.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_O,JSON.stringify({trackId:i}))}_updateRecvTransceiverMap(e,t){this._sdpStrategy.updateRecvTransceiverMap(e,t)}updateSubRemoteTracks(e){this._sdpStrategy.updateSubRemoteTracks(e)}getOutboundVideoInfo(){return this._sdpStrategy.getOutboundVideoInfo()}_onLocalTrackMuted(e,t){const i=this.getLocalTrack(`${e.getTrackId()}_tiny`);i&&(i.__innerGetMediaStreamTrack().enabled=!e.isLocalMuted()),this.emit(rt.__INNER_EVENT_MUTED_CHANGE__,e,t)}_onLocalTrackDestroied(e){this.emit(rt.__INNER_EVENT_DESTROY__,e)}registerReportListener(e){this._reportListener=e}_createRCRTCStateReport(e){const{timestamp:t,iceCandidatePair:i,senders:r,receivers:n}=e;(null==i?void 0:i.totalPacketsLost)&&(null==i||delete i.totalPacketsLost);for(const e in i)xt(i[e])&&delete i[e];const o=[];r.forEach((e=>{const{trackId:t,kind:i,packetsLostRate:r,remoteResource:n,bitrate:s,jitter:a}=e,c={trackId:t,kind:i,packetsLostRate:r,remoteResource:n,bitrate:s,jitter:a};(e.audioLevel||0===e.audioLevel)&&(c.audioLevel=e.audioLevel),e.frameWidth&&(c.frameWidth=e.frameWidth),e.frameHeight&&(c.frameHeight=e.frameHeight),e.frameRate&&(c.frameRate=e.frameRate),e.trackId&&o.push(Object.assign({},c))}));const s=[];return n.forEach((e=>{const{trackId:t,kind:i,packetsLostRate:r,remoteResource:n,bitrate:o,jitter:a}=e,c={trackId:t,kind:i,packetsLostRate:r,remoteResource:n,bitrate:o,jitter:a};(e.audioLevel||0===e.audioLevel)&&(c.audioLevel=e.audioLevel),e.frameWidth&&(c.frameWidth=e.frameWidth),e.frameHeight&&(c.frameHeight=e.frameHeight),e.frameRate&&(c.frameRate=e.frameRate),e.trackId&&s.push(Object.assign({},c))})),{timestamp:t,iceCandidatePair:i,senders:o,receivers:s,pcName:this._pcName}}_getStatsData(){var e,t;return S(this,void 0,void 0,(function*(){this._formatStatsData=null;let i=null;const r=yield this._rtcPeerConn.getStats();i=null===(e=this.reportParser)||void 0===e?void 0:e.parseRTCStatsReport(r);const n=null===(t=this.reportParser)||void 0===t?void 0:t.formatRCRTCStateReport(i);return this._formatStatsData=n,n}))}_reportHandle(){var e,t,i,r;return S(this,void 0,void 0,(function*(){const n=yield this._getStatsData();if(!n)return;const o=this._createRCRTCStateReport(n);null===(t=null===(e=this._reportListener)||void 0===e?void 0:e.onStateReport)||void 0===t||t.call(e,JSON.parse(JSON.stringify(o)));const s=[...n.receivers,...n.senders].filter((e=>!("audio"!==e.kind))).map((e=>({trackId:e.trackId,audioLevel:e.audioLevel})));if(this.emit(xo.__INNER_AUDIOLEVEL_CHANGE__,s),this._isRoomAudience){const e=this._getLiveAudioState();e.length&&(null===(r=null===(i=this._reportListener)||void 0===i?void 0:i.onReportLiveAudioStates)||void 0===r||r.call(i,e))}}))}_getLiveAudioState(){const e=[];return this._rtcPeerConn.getReceivers().forEach((t=>{const i=t.getContributingSources();i.length&&e.push(...i)})),e.map((e=>{var t;const{source:i,audioLevel:r}=e,n=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(i),{userId:o}=Ct(n);return{audioLevel:eo(r),userId:o,trackId:n}})).filter((e=>!!e.userId))}_sendR3R4Data(){var e,t;return S(this,void 0,void 0,(function*(){const i=this._formatStatsData;if(!i)return!0;if((null===(e=null==this?void 0:this._initOptions)||void 0===e?void 0:e.polarisThrottle)&&i.receivers.length+i.senders.length>this.senderAndReciveSize)return!0;if(i.senders.length||i.receivers.length){const e=yield null===(t=this._polarisReport)||void 0===t?void 0:t.sendR3R4Data(i);return i.senders.length>0&&i.senders.forEach((e=>{if("video"===e.kind){const{encoderImplementation:t,frameRate:i,frameWidth:r,frameHeight:n}=e;let o=0;"unknown"!==(null==t?void 0:t.toLowerCase())&&i&&r&&n||(o=1),this.setTroubleTrack(e.trackId,o)}})),e}return!0}))}__reportR3R4ToPolaris(){return S(this,void 0,void 0,(function*(){clearTimeout(this._reportR3R4ToPolarisTimer),this._reportR3R4ToPolarisTimer=setTimeout((()=>S(this,void 0,void 0,(function*(){this._sendR3R4Data().then((()=>{this.__reportR3R4ToPolaris()}))}))),2e3)}))}getRTCPeerConn(){return this._rtcPeerConn}getCapabilitiesCodes(e=ao.H264){var t;let i=null===(t=RTCRtpSender.getCapabilities("video"))||void 0===t?void 0:t.codecs,r=null;switch(e){case ao.VP8:case ao.VP9:r=i.find((t=>t.mimeType.match(e)));break;case ao.H264:r=i.find((t=>{var i;return t.mimeType.match(e)&&(null===(i=t.sdpFmtpLine)||void 0===i?void 0:i.match("42e01f"))}))}return i=i.filter((e=>e!==r)),i=[r,...i],i}setEncoderPreferences(e){var t;return S(this,void 0,void 0,(function*(){const i=this.getRTCPeerConn(),r=this.getCapabilitiesCodes(e);null===(t=this._logger)||void 0===t||t.info(f.L_SET_ENCODER_PREFERENCES_S,JSON.stringify({status:C.SUCCESSED,codecCap:r})),i.getTransceivers().forEach((e=>{var t;"video"===(null===(t=e.sender.track)||void 0===t?void 0:t.kind)&&e.setCodecPreferences(r)}))}))}destroy(){var e;this.clear(),this.clearReTryExchangeTimer(),clearTimeout(this._reportR3R4ToPolarisTimer),this.stopAutoExecute(),this.registerReportListener(null),this._rtcPeerConn.close(),this._isDestroyed=!0,this.reportParser=null,null===(e=this._logger)||void 0===e||e.info(f.L_RTC_PEER_CONNECTION_DESTROY_O,JSON.stringify({status:C.SUCCESSED}))}clearReTryExchangeTimer(){clearInterval(this._reTryExchangeTimer),this._reTryExchangeTimer=null}isDestroyed(){return this._isDestroyed}setTroubleTrack(e,t=0){let i=this.troubleTracksCollection.get(e);if(0!==t&&i){if(this.troubleTracksCollection.set(e,i+1),i+1>5&&this.onTrackTrouble){let e=[];for(const t of this.troubleTracksCollection.keys()){const i=this.troubleTracksCollection.get(t);i&&i>5&&this.pubLocalTracks[t]&&e.push(this.pubLocalTracks[t])}e.length>0&&this.onTrackTrouble(e)}}else this.troubleTracksCollection.set(e,0)}}xo.__INNER_EVENT_TRACK_READY__="inner-track-ready",xo.__INNER_AUDIOLEVEL_CHANGE__="inner-audio-level-change",xo.__INNER_ICE_STATE_CHANGE__="inner-ice-state-change",xo.__INNER_ICE_CONNECTED__="inner-ice-connected",function(e){e[e.DISABLE=0]="DISABLE",e[e.ENABLE=1]="ENABLE"}(co||(co={})),function(e){e[e.MeetingOrAnchor=1]="MeetingOrAnchor",e[e.Audience=2]="Audience"}(_o||(_o={})),function(e){e[e.NOT_REPORT=-1]="NOT_REPORT",e[e.REPORT_SUCCESS=1e4]="REPORT_SUCCESS",e[e.REPORT_FAIL=0]="REPORT_FAIL",e[e.PB_ERROR=40001]="PB_ERROR"}(lo||(lo={})),function(e){e.R1="R1",e.R2="R2",e.R3="R3",e.R4="R4"}(uo||(uo={}));class wo{constructor(e,t,i,r,n=_o.MeetingOrAnchor){this._context=e,this._runtime=t,this._roomId=i,this._crtRTCRoom=r,this._userRole=n}_send(e){return S(this,void 0,void 0,(function*(){if(this._context.getConnectionStatus()!==a.CONNECTED)return lo.NOT_REPORT;return(yield this._context.setRTCState(this._roomId,e))===n.SUCCESS?lo.REPORT_SUCCESS:lo.REPORT_FAIL}))}_getClientID(){const e="uuid";let t=this._runtime.localStorage.getItem(e);return t||(t=At(),this._runtime.localStorage.setItem(e,t)),t}_getRealResourceId(e){let t=e;const i=e.indexOf("_tiny");return i>-1&&(t=e.slice(0,i)),t}_getPolarisTrackId(e){let t="";const i=e.split("_");if(e.includes("_tiny")){const e=i.pop(),r=parseInt(i.pop())===Je.AUDIO_ONLY?"audio":"video",n=i.pop();t=[i.join("_"),n,e,r].join("_")}else{const e=parseInt(i.pop())===Je.AUDIO_ONLY?"audio":"video",r=i.pop();t=[i.join("_"),r,e].join("_")}return t}sendR3R4Data(e){return S(this,void 0,void 0,(function*(){const{iceCandidatePair:t,senders:i,receivers:r}=e,n=(null==t?void 0:t.bitrateSend)||Kn,o=(null==t?void 0:t.bitrateRecv)||Kn,s=(null==t?void 0:t.networkType)||"unknown",a=(null==t?void 0:t.rtt)||Kn,c=`${(null==t?void 0:t.IP)||Kn}:${null==t?void 0:t.port}`,d=(null==t||t.remoteIP,null==t||t.remotePort,(null==t?void 0:t.availableIncomingBitrate)||Kn),_=(null==t?void 0:t.availableOutgoingBitrate)||Kn,l=(null==t?void 0:t.totalPacketsLost)||Kn,u=this._context.getCurrentId();let h=`R3\t${n}\t-1\t-1\t-1\t${s}\t${a}\t${c}\t${d}\t${_}\t${l}\t${u}\r`,g=`R4\t${o}\t-1\t-1\t-1\t${s}\t${a}\t${c}\t${d}\t${_}\t${l}\t${u}\r`;const v=i.map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:n,bitrate:o,packetsLostRate:s,frameRate:a,frameWidth:c,frameHeight:d,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:g,googFirsSent:v,encoderImplementation:p}=e,R=this._getPolarisTrackId(i),m=this._getRealResourceId(i);return{trackId:R,googCodecName:p||String(Kn),audioLevel:r||0===r?r:Kn,bitrate:o||0===o?o:Kn,packetsLostRate:s||0===s?s:Kn,frameRate:a||Kn,resolution:c&&d?`${c} * ${d}`:"-1",jitter:l||Kn,nackCount:u||0===u?u:Kn,pliCount:h||0===h?h:Kn,rtt:g||Kn,googFirsSent:v,samplingRate:n,googRenderDelayMs:_,encoderImplementation:p||String(Kn),trackState:(null===(t=this._crtRTCRoom.getLocalTrack(m))||void 0===t?void 0:t.isLocalMuted())?co.DISABLE:co.ENABLE}})),p=r.filter((e=>!!e.trackId)).map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:n,bitrate:o,packetsLostRate:s,frameRate:a,frameWidth:c,frameHeight:d,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:g,googFirsReceived:v,codecImplementationName:p}=e,R=this._getPolarisTrackId(i),m=this._getRealResourceId(i);return{trackId:R,googCodecName:p||String(Kn),audioLevel:r||0===r?r:Kn,bitrate:o||0===o?o:Kn,packetsLostRate:s||0===s?s:Kn,frameRate:a||Kn,resolution:c&&d?`${c} * ${d}`:"-1",jitter:l||Kn,nackCount:u||0===u?u:Kn,pliCount:h||0===h?h:Kn,rtt:g||Kn,googFirsReceived:v,samplingRate:n,googRenderDelayMs:_,codecImplementationName:p||String(Kn),trackState:(null===(t=this._crtRTCRoom.getRemoteTrack(m))||void 0===t?void 0:t.isLocalMuted())?co.DISABLE:co.ENABLE}}));let R=lo.REPORT_FAIL;h+=v.map((e=>`${e.trackId}\t${e.googCodecName}\t${e.audioLevel}\t${e.samplingRate}\t${e.bitrate}\t${e.packetsLostRate}\t${e.frameRate}\t${e.resolution}\t${e.googRenderDelayMs}\t${e.jitter}\t${e.nackCount}\t${e.pliCount}\t${e.rtt}\t${e.googFirsSent}\t${e.encoderImplementation}\t${e.trackState}`)).join("\n"),e.senders.length&&(R=yield this._send(`${h}\r${this._userRole}`));let m=lo.REPORT_FAIL;return g+=p.map((e=>`${e.trackId}\t${e.googCodecName}\t${e.audioLevel}\t${e.samplingRate}\t${e.bitrate}\t${e.packetsLostRate}\t${e.frameRate}\t${e.resolution}\t${e.googRenderDelayMs}\t${e.jitter}\t${e.nackCount}\t${e.pliCount}\t${e.rtt}\t${e.googFirsReceived}\t${e.codecImplementationName}\t${e.trackState}`)).join("\n"),e.receivers.length&&(m=yield this._send(`${g}\r${this._userRole}`)),R!==lo.REPORT_SUCCESS&&m!==lo.REPORT_SUCCESS?lo.REPORT_FAIL:lo.REPORT_SUCCESS}))}sendR1(){const e=this._context.getCoreVersion(),t=navigator.platform,i=`R1\t5.6.8\t${e}\tweb\t${t}\t-1\t${Ut.browser}\t${Ut.version}\t${this._getClientID()}\t${this._userRole}`;this._send(i)}sendR2(e,t,i){const r=`R2\t${e}\t${t}\t${this._getClientID()}\r${i.join("\t")}\r${this._userRole}`;this._send(r)}}class Bo{constructor(e,t,i,r,n=_o.MeetingOrAnchor){this._context=e,this._runtime=t,this._roomId=i,this._crtRTCRoom=r,this._userRole=n,this._useHttp=!0;const o=this._context.getNaviInfo();Bo.logServer=null==o?void 0:o.logServer,Bo.dc=null==o?void 0:o.dc,this._polarisSignalReporter=new wo(e,t,i,r,n)}_send(e,t){var i,r;return S(this,void 0,void 0,(function*(){if(this._context.getConnectionStatus()!==a.CONNECTED)return lo.NOT_REPORT;const{logServer:n}=Bo;if(!n||!this._useHttp||!zn.jwtToken)return lo.REPORT_FAIL;const o=yield this._context.setRTCStateByHttp(n,this._runtime,e,t);return o===lo.REPORT_SUCCESS?lo.REPORT_SUCCESS:o===T.JWT_TIME_OUT?(this._refetchNaviInfo(),lo.REPORT_FAIL):o===lo.REPORT_FAIL||o===lo.PB_ERROR?(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_HTTP_POLARIS_REPORT_FAIL_O,`send data fail -> code: ${o}`),this._useHttp=!1,lo.REPORT_FAIL):lo.REPORT_FAIL}))}_refetchNaviInfo(){return S(this,void 0,void 0,(function*(){const{jwt:e,naviInfo:t}=yield(i=this._context,S(void 0,void 0,void 0,(function*(){const e=i.getPluginContext();yield e.refetchNaviInfo();const t=i.getNaviInfo();return{naviInfo:t,jwt:Wn(t)}})));var i;zn.jwtToken=e,Bo.logServer=null==t?void 0:t.logServer,Bo.dc=null==t?void 0:t.dc}))}_getRealResourceId(e){let t=e;const i=e.indexOf("_tiny");return i>-1&&(t=e.slice(0,i)),t}_getPolarisTrackId(e){let t="";const i=e.split("_");if(e.includes("_tiny")){const e=i.pop(),r=parseInt(i.pop())===Je.AUDIO_ONLY?"audio":"video",n=i.pop();t=[i.join("_"),n,e,r].join("_")}else{const e=parseInt(i.pop())===Je.AUDIO_ONLY?"audio":"video",r=i.pop();t=[i.join("_"),r,e].join("_")}return t}_formatReportBaseData(e){return{type:e,appKey:this._context.getAppkey(),sessionId:this._crtRTCRoom.getSessionId(),roomId:this._roomId,roomCreateTime:this._context.roomCreateTime||0,userId:this._context.getCurrentId(),userRole:this._userRole,joinTime:this._context.userJoinTime||0,signalDataCenter:Bo.dc||""}}_formatReportData(e,t){let i=this._formatReportBaseData(e),r={};switch(e){case uo.R1:r=this._formatR1Data();break;case uo.R2:r=this._formatR2Data(t);break;case uo.R3:case uo.R4:r=this._formatR3R4Data(e,t)}return Object.assign(Object.assign({},i),{[{R1:"r1Info",R2:"r2Info",R3:"r3Info",R4:"r4Info"}[e]]:r})}_formatR1Data(){return{joinTime:this._context.userJoinTime||0,rtcVersion:"5.6.8",imVersion:this._context.getCoreVersion(),platform:"web",device:navigator.platform,os:String(Kn),browserName:Ut.browser,browserVersion:String(Ut.version),receiveTime:Date.now()}}_formatR2Data(e){const{action:t,status:i,trackIds:r}=e;return{joinTime:this._context.userJoinTime||0,sendTime:Date.now(),rtcActionType:t,rtcActionStatus:i,trackId:r,receiveTime:Date.now()}}_formatR3R4Data(e,t){const{iceCandidatePair:i,senders:r,receivers:n}=t;let o=0,s=[];return e===uo.R3?(o=(null==i?void 0:i.bitrateSend)||Kn,s=r.map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:n,bitrate:o,packetsLostRate:s,frameRate:a,frameWidth:c,frameHeight:d,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:g,googFirsSent:v,encoderImplementation:p}=e,R=this._getPolarisTrackId(i),m=this._getRealResourceId(i);return{trackId:R,codeName:p||String(Kn),volume:String(r||0===r?r:Kn),samplingRate:n||Kn,bitRate:o||0===o?o:Kn,packetLossRate:s||0===s?s:Kn,frameRate:a||Kn,resolution:c&&d?`${c} * ${d}`:"-1",blockTime:_,jitterData:l||Kn,nAckCount:String(u||0===u?u:Kn),pliCount:String(h||0===h?h:Kn),googleRTTTotalTime:g||Kn,isReceiveFirstFrameRate:v,codeType:p||String(Kn),isEnabled:(null===(t=this._crtRTCRoom.getLocalTrack(m))||void 0===t?void 0:t.isLocalMuted())?co.DISABLE:co.ENABLE}}))):e===uo.R4&&(o=(null==i?void 0:i.bitrateRecv)||Kn,s=n.filter((e=>!!e.trackId)).map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:n,bitrate:o,packetsLostRate:s,frameRate:a,frameWidth:c,frameHeight:d,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:g,googFirsReceived:v,codecImplementationName:p}=e,R=this._getPolarisTrackId(i),m=this._getRealResourceId(i);return{trackId:R,codeName:p||String(Kn),volume:String(r||0===r?r:Kn),samplingRate:n||Kn,bitRate:o||0===o?o:Kn,packetLossRate:s||0===s?s:Kn,frameRate:a||Kn,resolution:c&&d?`${c} * ${d}`:"-1",blockTime:_,jitterData:l||Kn,nAckCount:String(u||0===u?u:Kn),pliCount:String(h||0===h?h:Kn),googleRTTTotalTime:g||Kn,isReceiveFirstFrameRate:v,codeType:p||String(Kn),isEnabled:(null===(t=this._crtRTCRoom.getRemoteTrack(m))||void 0===t?void 0:t.isLocalMuted())?co.DISABLE:co.ENABLE}}))),{info:{joinTime:this._context.userJoinTime||0,receiveTime:Date.now(),totalBitRate:o,appCPUUsage:-1,systemCPUUsage:-1,systemCPUFrequency:-1,networkStatus:(null==i?void 0:i.networkType)||"unknown",googleRTTNetwork:(null==i?void 0:i.rtt)||Kn,ipAddress:`${(null==i?void 0:i.IP)||Kn}:${null==i?void 0:i.port}`,useReceiveBroadBand:String((null==i?void 0:i.availableIncomingBitrate)||Kn),useSendBroadBand:String((null==i?void 0:i.availableOutgoingBitrate)||Kn),packetLossCount:String((null==i?void 0:i.totalPacketsLost)||Kn),streams:s}}}sendR3R4Data(e){return S(this,void 0,void 0,(function*(){let t=lo.REPORT_FAIL;if(e.senders.length){const i=this._formatReportData(uo.R3,e);t=yield this._send(i,uo.R3),t===lo.REPORT_FAIL&&(t=yield this._polarisSignalReporter.sendR3R4Data(e))}let i=lo.REPORT_FAIL;if(e.receivers.length){const t=this._formatReportData(uo.R4,e);i=yield this._send(t,uo.R4),i===lo.REPORT_FAIL&&(i=yield this._polarisSignalReporter.sendR3R4Data(e))}return t!==lo.REPORT_SUCCESS&&i!==lo.REPORT_SUCCESS?lo.REPORT_FAIL:lo.REPORT_SUCCESS}))}sendR1(){var e;return S(this,void 0,void 0,(function*(){const t=this._formatReportData(uo.R1);(yield this._send(t,uo.R1))===lo.REPORT_FAIL&&(null===(e=this._polarisSignalReporter)||void 0===e||e.sendR1())}))}sendR2(e,t,i){var r;return S(this,void 0,void 0,(function*(){const n=this._formatReportData(uo.R2,{action:e,status:t,trackIds:i});(yield this._send(n,uo.R2))===lo.REPORT_FAIL&&(null===(r=this._polarisSignalReporter)||void 0===r||r.sendR2(e,t,i))}))}}class Vo{constructor(e){this._room=e,this._audioLevelChangeHandler=null}audioLevelReport(e){if(!this._audioLevelChangeHandler)return;const t=[];e.forEach((e=>{const{userId:i}=Ct(e.trackId),r=this._room.getCrtUserId()===i?this._room.getLocalTrack(e.trackId):this._room.getRemoteTrack(e.trackId);r&&t.push({track:r,audioLevel:e.audioLevel||0})})),this._audioLevelChangeHandler(t)}onAudioLevelChange(e){this._audioLevelChangeHandler=e}}!function(e){e[e.ANCHOR=1]="ANCHOR",e[e.AUDIENCE=2]="AUDIENCE"}(ho||(ho={}));class Fo{constructor(e=!1,t,i,r,n,o,s,a){this._useMutilPeerC=e,this._roomId=t,this._reTryExchange=i,this._currentUserId=r,this._polarisReport=n,this._isRoomAudience=o,this._initOptions=s,this._isAudience=a,this._mutilPeerC={}}get useMutilPeerC(){return this._useMutilPeerC}_isPub(e){if(this._isAudience)return!1;if(!this._useMutilPeerC)return!0;if(!e.length)return!1;const{track:t}=e[0]instanceof rt||e[0]instanceof ht?{track:e[0]}:e[0];return t.isLocalTrack()}_groupTracksByTag(e){const t={};return e.forEach((e=>{const{track:i}=e instanceof rt?{track:e}:e,r=i.getTag();t[r]?t[r].push(e):t[r]=[e]})),t}_genPCName(e,t){let i=null;return i=e?this._useMutilPeerC?`${this._roomId}_${t}`:`${this._roomId}_pub`:`${this._roomId}_sub`,i}_createOnePeerCItem(e,t){if(this._mutilPeerC[e]&&!this._mutilPeerC[e].pc.isDestroyed())this._mutilPeerC[e].tracks=t;else{const i=this._isPub(t),r=new xo(e,(()=>this._reTryExchange(e,i)),this._currentUserId,this._polarisReport,this.onTrackTrouble,this._store,this._isRoomAudience,this._initOptions);this._mutilPeerC[e]={pc:r,tracks:t,isPub:i}}return Object.assign(Object.assign({},this._mutilPeerC[e]),{pcName:e})}createPeerCList(e){const t=[],i=this._isPub(e);if(!this._useMutilPeerC||this._useMutilPeerC&&!i){const r=this._genPCName(i);return t.push(this._createOnePeerCItem(r,e)),t}const r=this._groupTracksByTag(e);for(const e in r){const n=this._genPCName(i,e),o=r[e];t.push(this._createOnePeerCItem(n,o))}return t}_removeAllLocalTrack(){this.getPCList().forEach((e=>e.removeAllLocalTrack()))}destroyPeerC(e){this._mutilPeerC[e].pc.destroy()}_destroyAllPeerC(){this.getPCList().forEach((e=>e.destroy()))}getPCItemByPCName(e){return this._mutilPeerC[e]}getPCByTrackId(e,t=!0){const{tag:i}=Ct(e),r=this._genPCName(t,i);return this._mutilPeerC[r].pc}getPCList(){const e=[];for(const t in this._mutilPeerC)e.push(this._mutilPeerC[t].pc);return e}getMutilPeerCData(){return this._mutilPeerC}setPeerCData(e,t,i){}clear(){this._removeAllLocalTrack(),this._destroyAllPeerC()}setStore(e){this._store=e}}!function(e){e.UNPUBLISH_PREV="UnpublishPrevCommand",e.PULL_RTCROOM_STATUS="PullRTCRoomStatusCommand",e.JOINROOM="JoinRoomCommand",e.PARSE_REMOTERES="ParseRemoteResCommand",e.PARSE_USERSTATE="ParseUserStateCommand",e.LOCAL_TRACK_MUTE="LocalTrackMuteCommand",e.PUBLISH="PublishCommand",e.RETRY_EXCHANGE="RetryExchangeCommand",e.UNPUBLISH="UnpublishCommand",e.SUBSCRIBE="SubscribeCommand",e.ASYNC_COMMAND="AsyncCommand",e.UNSUBSCRIBE="UnsubscribeCommand",e.UPDATE_SUBSCRIBE_LIST="UpdateSubscribeListCommand",e.ON_SIGNAL_RECONNECTED="OnSignalReconnectedCommand",e.LEAVE_OTHER_ROOM="LeaveOtherRoomCommand",e.RTC_IDENTITY_CHANGE="RTCIdentityChangeCommand",e.ENABLE_INNER_CDN="EnableInnerCDNCommand",e.EXCHANGE_WITH_PUSH_OTHER_ROOM="ExchangeWithPushOtherRoomCommand",e.MCUCONFIG_FLUSH="MCUConfigFlushCommand",e.UNKNOWN="Unknown"}(go||(go={})),function(e){e.NORMAL="normal",e.MIDDLE="middle",e.TAIL="tail"}(vo||(vo={})),function(e){e[e.LOW=0]="LOW",e[e.NORMAL=1]="NORMAL",e[e.HIGH=2]="HIGH"}(po||(po={})),function(e){e[e.Destroy=40400]="Destroy"}(Ro||(Ro={}));class Jo{get priority(){return po.LOW}get kind(){return go.UNKNOWN}}class Go extends Jo{constructor(e=vo.NORMAL){super(),this.state=e}get kind(){return go.ASYNC_COMMAND}setState(e){this.state=e}pickoutSubscribed(e,t){const{unsubscribe:i,subscribe:r}=this.calcSubscribeList(e,t);return Go.AsyncSubscribeTasks=[],Go.AsyncUnsubscribeTasks=[],Go.AsyncUpdateSubscribeTasks=[],{subscribe:r,unsubscribe:i}}calcSubscribeList(e,t){const i=[],r=new Set,n=[],o=new Set,s=this.formateTrack(e),a=this.formateTrack(t);return a.forEach((e=>{const t=`${e.track.getTrackId()}_SUB_${e.subTiny?"0":"1"}`;this.trackInSubscribeList(e,s)||r.has(t)||(i.push(e),r.add(t))})),s.forEach((e=>{const t=`${e.track.getTrackId()}_SUB_${e.subTiny?"0":"1"}`;this.trackInSubscribeList(e,a)||o.has(t)||(n.push(e),o.add(t))})),{unsubscribe:i,subscribe:n}}formateTrack(e){return e.map((e=>e instanceof ht?{track:e,subTiny:!1}:Object.assign({subTiny:!1},e)))}trackInSubscribeList(e,t){if(0===t.length)return!1;return t.findIndex((t=>t.track.getTrackId()===e.track.getTrackId()&&t.subTiny===e.subTiny))>-1}}Go.AsyncSubscribeTasks=[],Go.AsyncUnsubscribeTasks=[],Go.AsyncUpdateSubscribeTasks=[];class Ho{constructor(e,t,i,r,n,o,s,a,c){this.context=e,this.service=t,this.peerMgr=i,this.roomId=r,this.crtUserId=n,this.roomMode=o,this.polarisReport=s,this.isUpgrade=a,this.isMainRoom=c,this._roomResources={},this._remoteTracks={},this._subscribedList=[],this._collectSubscribeList=[],this._CDNUris=null,this._CDNEnable=!1,this._destroyed=!1,this._trackIdSSRCMap=new Map,this._roomStatusVersion=0}get useMutilPeerC(){return this.peerMgr.useMutilPeerC}getResourcesByUserId(e){return this._roomResources[e]}getRemoteTrack(e){return this._remoteTracks[e]}getRemoteTracksByUserId(e){const t=[];for(const i in this._remoteTracks){const r=this._remoteTracks[i];r.getUserId()===e&&t.push(r)}return t}getRemoteTracks(){return this._remoteTracks}getSessionId(){return this._sessionId}getAllUserIds(){return Object.keys(this._roomResources)}getRemoteUserIds(){return this.getAllUserIds().filter((e=>e!==this.crtUserId))}getSubscribedList(){return this._subscribedList}getCollectSubscribeList(){return this._collectSubscribeList}getPublishedResourceByTrackId(e){const{userId:t}=Ct(e);return this._roomResources[t].find((t=>ft(t)===e))}getToken(){return this._token}getLocalTrack(e){return this.peerMgr.getPCByTrackId(e).getLocalTrack(e)}getLocalTracks(){const e=[];return this.peerMgr.getPCList().forEach((t=>{e.push(...t.getLocalTracks())})),e}getTrackState(e){var t;return(null===(t=this.getLocalTrack(e))||void 0===t?void 0:t.isLocalMuted())?0:1}getCDNEnable(){return this._CDNEnable}getCDNUris(){return this._CDNUris}getRoomStatusVersion(){return this._roomStatusVersion}getTrackIdBySSRC(e){return this._trackIdSSRCMap.get(e)}}class Ko extends Ho{_updateTrackIdSSRCMap(){Object.values(this._roomResources).forEach((e=>{e.forEach((e=>{const{ssrc:t,resourceId:i}=JSON.parse(e.uri);this._trackIdSSRCMap.set(t,i)}))}))}setTrackIdSSRCMap(e,t){this._trackIdSSRCMap.set(e,t)}_initRemoteTracks(){for(const e in this._roomResources){const t=this._roomResources[e];e!==this.crtUserId&&0!==t.length&&t.forEach((e=>{const t=ft(e),{tag:i,userId:r,mediaType:n}=Ct(t),o=n===Je.AUDIO_ONLY?new gt(i,r):new vt(i,r);o.__innerSetRemoteMuted(0===e.state),this._remoteTracks[t]=o}))}}initWithRoomData(e,t){this._sessionId=e.sessionId,this._token=e.token,this._roomStatusVersion=Ft(e.version),this._roomResources=Bt(e,this.roomId,t),this._updateTrackIdSSRCMap(),this._initRemoteTracks(),this.setResourcesByUserId(this.crtUserId,this.getResourcesByUserId(this.crtUserId)||[]);const i=We.getLogger();null==i||i.info(f.L_PARSE_ROOMDATA_URIS_R,`room data -> ${JSON.stringify(this._roomResources)}`,t)}assignRoomData(e){Object.assign(this._roomResources,e),this._updateTrackIdSSRCMap()}setResourcesByUserId(e,t){this._roomResources[e]=t,this._updateTrackIdSSRCMap()}removeRemoteTrack(e){delete this._remoteTracks[e]}removeResourcesByUserId(e){delete this._roomResources[e],this._updateTrackIdSSRCMap()}addRemoteTrack(e){this._remoteTracks[e.getTrackId()]=e}removeRemoteTracks(){const e=Object.values(this._remoteTracks);e.length&&(e.forEach((e=>{e.isAudioTrack()&&e.__releaseMediaElement()})),this._remoteTracks={})}setCDNEnabel(e){this._CDNEnable=e}setCDNUris(e){this._CDNUris=e}resetSubscribedList(e){this._subscribedList.splice(0,this._subscribedList.length,...e),this.resetCollectSubscribeList(e)}resetCollectSubscribeList(e){this._collectSubscribeList.splice(0,this._collectSubscribeList.length,...e)}setRoomStatusVersion(e){this._roomStatusVersion=Ft(e)}}class jo{constructor(e,t,i){this.context=e,this._store=t,this.abortCode=i,this._queue=[],this._busy=!1,this._isDestroyed=!1}_next(){this._busy=!1,this._execute()}_execute(){var e,t,i,r;return S(this,void 0,void 0,(function*(){if(this._isDestroyed||this._busy||0===this._queue.length)return;this._busy=!0;const{command:n,resolve:o,reject:s}=this._queue.shift();let a;const c=this._queue.map((e=>{var t;return null===(t=null==e?void 0:e.command)||void 0===t?void 0:t.kind})),d=null===(e=this.context.logger)||void 0===e?void 0:e.createTraceId();try{null===(t=this.context.logger)||void 0===t||t.info(f.L_INVOKER_EXECUTE_T,`commandKind: ${n.kind}, kinds:${c.join(",")}, length: ${this._queue.length}`,d),a=yield n.execute(this._store,this)}catch(e){return null===(i=this.context.logger)||void 0===i||i.error(f.L_INVOKER_EXECUTE_R,JSON.stringify({error:e,status:C.FAILED,commandKind:n.kind,kinds:c.join(",")}),d),s(e),void this._next()}null===(r=this.context.logger)||void 0===r||r.info(f.L_INVOKER_EXECUTE_R,`status: ${C.SUCCESSED}, commandKind: ${n.kind}`,d),o(a),this._next()}))}push(e){return new Promise(((t,i)=>{var r;if(null===(r=this.context.logger)||void 0===r||r.info(f.L_INVOKER_PUSH_O,JSON.stringify({isDestroyed:this._isDestroyed,commandKind:e.kind,length:this._queue.length})),this._isDestroyed)return void i({code:T.NOT_IN_ROOM});const{kind:n}=e;this._queue.length>0&&n===go.ASYNC_COMMAND&&({command:e,resolve:t,reject:i}=this.commandOffset(e,t,i));const{priority:o}=e;if(o===po.LOW)this._queue.push({command:e,resolve:t,reject:i});else{const r=this._queue.findIndex((e=>e.command.priority<o)),n=-1===r?this._queue.length-1:r;this._queue.splice(n,0,{command:e,resolve:t,reject:i})}Promise.resolve().then((()=>{this._execute()}))}))}commandOffset(e,t,i){const r=this._queue.length-1;if(!(this._queue[r].command.kind===go.ASYNC_COMMAND))return{command:e,resolve:t,reject:i};const[n]=this._queue.splice(r,1);n.command instanceof Go&&(n.command.setState(vo.MIDDLE),e instanceof Go&&e.setState(vo.TAIL));const o=e.execute;return e.execute=function(t,i){return S(this,void 0,void 0,(function*(){return n.command.execute.call(n.command,t,i),o.call(e,t,i)}))},{command:e,resolve:e=>{n.resolve.call(n,e),t(e)},reject:e=>{n.reject.call(n,e),i(e)}}}isDestroyed(){var e;return null===(e=this.context.logger)||void 0===e||e.info(f.L_INVOKER_DESTROY_O,JSON.stringify({isDestroyed:this._isDestroyed})),this._isDestroyed}destroy(){var e;null===(e=this.context.logger)||void 0===e||e.info(f.L_INVOKER_DESTROY_O,JSON.stringify({isDestroyed:this._isDestroyed})),this._isDestroyed||(this._isDestroyed=!0,this._queue.forEach((e=>{e.resolve({code:this.abortCode})})),this._queue.length=0)}}class $o extends jo{constructor(e,t,i,r,n,o,s,a,c){super(e,new Ko(e,t,i,r,n,o,s,a,c),T.ROOM_HAS_BEEN_DESTROYED)}get store(){return this._store}destroy(){super.destroy(),this._store.removeRemoteTracks()}}class Wo extends Jo{get kind(){return go.UNPUBLISH_PREV}execute(e){var t,i,r,o,s,a,c,d;return S(this,void 0,void 0,(function*(){const _=e.getResourcesByUserId(e.crtUserId),l=_.slice();_.length=0;const u=null===(i=null===(t=e.context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();null===(o=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===o||o.info(f.L_UNPUBLISH_PREV_COMMAND_T,JSON.stringify({resource:l}),u);const h=yield e.context.setRTCTotalRes(e.roomId,[pt(Jt.UNPUBLISH,l)],Rt([]),Jt.TOTAL_CONTENT_RESOURCE,Rt([]));h!==n.SUCCESS?null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_UNPUBLISH_PREV_COMMAND_R,JSON.stringify({status:C.FAILED,code:h}),u):null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_UNPUBLISH_PREV_COMMAND_R,JSON.stringify({status:C.SUCCESSED}),u)}))}}!function(e){e[e.RTC=0]="RTC",e[e.LIVE=2]="LIVE",e[e.CROSS_MUTI=7]="CROSS_MUTI",e[e.CROSS_LIVE=8]="CROSS_LIVE",e[e.SIP=4]="SIP",e[e.CALL=5]="CALL",e[e.MEETING=6]="MEETING"}(mo||(mo={}));class Yo extends Jo{constructor(e,t,i,r,n,o,s,a,c){super(),this.roomId=e,this.roomType=t,this.context=i,this.joinType=r,this.livingType=n,this.innerUserDatas=o,this.outerUserDatas=s,this.traceId=a,this._reportMediaActionLogger=c}get kind(){return go.JOINROOM}execute(e,t){var o,s,c,d,u,h,g,v,p,R,m,I,E,O,L,N,A,y,k,D;return S(this,void 0,void 0,(function*(){const S=Date.now(),{context:b,service:U}=e;let P=f.L_RTC_CLIENT_JOIN_RTC_ROOM_R;if(this.roomType===mo.LIVE?P=f.L_RTC_CLIENT_JOIN_LIVING_ROOM_R:this.roomType===mo.CROSS_MUTI&&(P=f.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_R),b.getConnectionStatus()!==a.CONNECTED)return null===(s=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===s||s.error(P,JSON.stringify({status:C.FAILED,code:T.SIGNAL_DISCONNECTED,msg:"im not connected"}),this.traceId),{code:T.SIGNAL_DISCONNECTED};if(U.detectorMediaSever(),wt(b.getNaviInfo()))return null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(P,JSON.stringify({status:C.FAILED,code:T.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"}),this.traceId),{code:T.PACKAGE_ENVIRONMENT_ERROR};if(!i("roomId",this.roomId,_,!0))return null===(h=null===(u=e.context)||void 0===u?void 0:u.logger)||void 0===h||h.error(P,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> roomId"}),this.traceId),{code:T.PARAMS_ERROR};if(!i("roomType",this.roomType,(e=>void 0!==mo[e])))return null===(v=null===(g=e.context)||void 0===g?void 0:g.logger)||void 0===v||v.error(P,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> roomType"}),this.traceId),{code:T.PARAMS_ERROR};if(!i("outerUserDatas",this.outerUserDatas,r,!1))return null===(R=null===(p=e.context)||void 0===p?void 0:p.logger)||void 0===R||R.error(P,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> outerUserDatas"}),this.traceId),{code:T.PARAMS_ERROR};if(this.outerUserDatas){if(!Object.keys(this.outerUserDatas).every((e=>i(`outerUserDatas.${e}`,this.outerUserDatas[e],l,!0))))return null===(I=null===(m=e.context)||void 0===m?void 0:m.logger)||void 0===I||I.error(P,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> outerUserDatas"}),this.traceId),{code:T.PARAMS_ERROR}}if(!U.getNaviMS().length)return null===(O=null===(E=e.context)||void 0===E?void 0:E.logger)||void 0===O||O.error(P,JSON.stringify({status:C.FAILED,code:T.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"No audio / video server address available"}),this.traceId),{code:T.NOT_OPEN_VIDEO_AUDIO_SERVER};const{code:M,data:x}=yield b.joinRTCRoom(this.roomId,this.roomType,this.livingType,this.joinType,this.innerUserDatas,this.outerUserDatas);if(null===(L=this._reportMediaActionLogger)||void 0===L||L.reportQualityJoinRoomData(S,M,this.roomType,null==x?void 0:x.sessionId),M!==n.SUCCESS||!x){const t=40032===M?T.SIGNAL_JOIN_RTC_ROOM_REFUSED:M;return null===(A=null===(N=e.context)||void 0===N?void 0:N.logger)||void 0===A||A.error(P,JSON.stringify({status:C.FAILED,code:t,msg:"joinRoom failed"}),this.traceId),{code:t}}e.initWithRoomData(x,this.traceId);e.getResourcesByUserId(e.crtUserId).length>0&&t.push(new Wo);const w=null===(y=x.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===y?void 0:y.value;return w&&e.setCDNUris(JSON.parse(w)[0]),null===(D=null===(k=e.context)||void 0===k?void 0:k.logger)||void 0===D||D.info(P,JSON.stringify({status:C.SUCCESSED,userId:e.crtUserId,roomId:this.roomId}),this.traceId),{code:T.SUCCESS,data:x}}))}}!function(e){e[e.ROOM=1]="ROOM",e[e.PERSON=2]="PERSON"}(Io||(Io={})),function(e){e.PUBLISH="publish",e.SUBSCRIBE="subscribe"}(Eo||(Eo={})),function(e){e.BEGIN="begin",e.END="end"}(So||(So={})),function(e){e[e.SPREAD=0]="SPREAD",e[e.NO_SPREAD=-1]="NO_SPREAD"}(To||(To={}));class qo extends Jo{constructor(e,t,i,r){super(),this.headers=e,this.reqBody=t,this.traceId=i,this.isNeedUpdateMsas=r}execute(e,t){var i,r;return S(this,void 0,void 0,(function*(){const t=yield e.service.exchange(this.headers,this.reqBody,this.traceId,this.isNeedUpdateMsas);if(e.roomMode!==mo.LIVE)return t;const n=null===(r=null===(i=t.data)||void 0===i?void 0:i.urls)||void 0===r?void 0:r.pull_url;if(t.code!==T.SUCCESS||!n)return t;const o=JSON.parse(n);if(e.setCDNUris(o),(null==o?void 0:o.broadcast)===To.SPREAD){e.setCDNEnabel(!0);const t=Object.assign(Object.assign({},o),{enableInnerCDN:!0});ts(e.context,e.roomId,t)}return t}))}}!function(e){e.PUB="pub",e.UNPUB="unpub",e.SUB="sub",e.UNSUB="unsub"}(fo||(fo={}));class zo extends Jo{constructor(e,t,i,r,n,o=fo.SUB,s){super(),this.tracks=e,this.subhook=t,this.forceReq=i,this.traceId=r,this._reportMediaActionLogger=n,this.fromCommand=o,this.unsubTracks=s,this._actionStartTime=Date.now(),this._trackMediaMap={}}get kind(){return go.UPDATE_SUBSCRIBE_LIST}execute(e,t){var r,n,o,a,c,d,_,l,u,h,g,v,p,R,m,I,E,O;return S(this,void 0,void 0,(function*(){this._actionStartTime=Date.now();const{tracks:S,forceReq:L}=this,{roomId:N}=e;if(null===(n=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_UPDATE_SUBSCRIBELIST_COMMAND_T,`roomId: ${N}, forceReq: ${L}, trackIds: ${S.map(Vt)}`,this.traceId),!i("tracks",S,(()=>s(S)&&S.every((e=>e instanceof ht||e.track instanceof ht))),!0))return null===(a=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===a||a.warn(f.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"tracks is invalid"}),this.traceId),{code:T.PARAMS_ERROR};let A=S.map((e=>e instanceof ht?{track:e}:Object.assign({},e)));const y={};A=A.filter((t=>{var i,r;const n=t.track.getTrackId();return e.getRemoteTrack(n)?!y[n]&&(y[n]=!0,!0):(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(f.L_UPDATE_SUBSCRIBELIST_COMMAND_P,`track cannot found in room -> trackId: ${n}`,this.traceId),!1)})).map((e=>Object.assign({},e)));const k=e.getSubscribedList().map((e=>Object.assign({},e)));if(!L){let t=!1;if(A.forEach((e=>{const i=k.findIndex((t=>t.track===e.track));if(-1===i)return void(t=!0);k.splice(i,1)[0].subTiny!==e.subTiny&&(t=!0)})),k.length){t=!0;const i=k.map((e=>e.track));null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.warn(f.L_CLEAR_UNSUBSCRIBE_LIST_O,JSON.stringify({list:i.map((e=>e.getTrackId()))}),this.traceId);const r=e.getSubscribedList().filter((e=>!i.includes(e.track)));e.resetSubscribedList(r)}if(!t)return null===(l=null===(_=e.context)||void 0===_?void 0:_.logger)||void 0===l||l.warn(f.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:C.SUCCESSED,msg:"subscribe list unchanged"}),this.traceId),{code:T.SUCCESS}}const{pc:D,pushOtherRooms:b,headers:U}=this.subhook(S);D.updateSubRemoteTracks(A.map((e=>e.track)));const P=yield Xo(A,!1,D,e);b&&(P.pushOtherRooms=b);const M=yield new qo(U,P,this.traceId,!0).execute(e,t);S.forEach((e=>{const t=e instanceof ht?e.getTrackId():e.track.getTrackId();this._trackMediaMap[t]=M.qualityMsList||[]})),A.map((e=>e.track.getTrackId()));const x=this.fromCommand===fo.SUB?S:this.unsubTracks;if(M.code!==T.SUCCESS)return(null==x?void 0:x.length)&&(null===(u=this._reportMediaActionLogger)||void 0===u||u.reportPubOrSubQualityData(this.fromCommand,this._actionStartTime,x,M.code,this._trackMediaMap)),null===(g=null===(h=e.context)||void 0===h?void 0:h.logger)||void 0===g||g.error(f.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:C.FAILED,code:M.code}),this.traceId),{code:M.code};const{sdp:w,resultCode:B,message:V,subscribedList:F}=M.data;if(B!==T.SUCCESS)return(null==x?void 0:x.length)&&(null===(v=this._reportMediaActionLogger)||void 0===v||v.reportPubOrSubQualityData(this.fromCommand,this._actionStartTime,x,B,this._trackMediaMap)),null===(R=null===(p=e.context)||void 0===p?void 0:p.logger)||void 0===R||R.error(f.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:C.FAILED,code:B}),this.traceId),{code:B};null===(m=this._reportMediaActionLogger)||void 0===m||m.setPubOrSubSuccessTime(Date.now());const J=yield D.setRemoteAnswer(w.sdp);if((null==x?void 0:x.length)&&(null===(I=this._reportMediaActionLogger)||void 0===I||I.reportPubOrSubQualityData(this.fromCommand,this._actionStartTime,x,J,this._trackMediaMap)),J!==T.SUCCESS)return{code:J};Co.formatSourceIdMapFromSdp(w.sdp,"subscribe");const G=null==F?void 0:F.map((e=>`${e.msid}_${e.mediaType}`)),H=A.filter((e=>null==G?void 0:G.includes(e.track.getTrackId()))),K=A.filter((e=>!(null==G?void 0:G.includes(e.track.getTrackId()))));null===(O=null===(E=e.context)||void 0===E?void 0:E.logger)||void 0===O||O.info(f.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.SUCCESSED,subSuccessTrackIds:G,failedList:K}),this.traceId);const j=e.getRemoteTracks();for(const e in j){const t=H.some((t=>t.track.getTrackId()===e));j[e].__innerSetSubscribed(t);const i=H.some((t=>t.track.getTrackId()===e&&t.subTiny));j[e].isVideoTrack()&&j[e].__innerSetIsTinyTrack(i)}return e.resetSubscribedList(H),K.length?{code:T.SUCCESS,failedList:K}:{code:T.SUCCESS}}))}}class Qo extends Jo{constructor(e,t,i,r){super(),this.tracks=e,this.subhook=t,this.traceId=i,this._reportMediaActionLogger=r}get kind(){return go.UNSUBSCRIBE}execute(e,t){var r,n,o,a;return S(this,void 0,void 0,(function*(){const{tracks:c}=this;if(null===(n=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_ABSTRACT_ROOM_UNSUBSCRIBE_T,JSON.stringify({unSubscribeTrackIds:c.map(Vt)}),this.traceId),!i("tracks",c,(()=>s(c)&&c.length>0&&c.every((e=>e instanceof ht))),!0))return null===(a=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===a||a.warn(f.L_ABSTRACT_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:T.PARAMS_ERROR};const d=e.getSubscribedList().map((e=>Object.assign({},e))).filter((e=>!c.includes(e.track)));return e.polarisReport.sendR2(Eo.SUBSCRIBE,So.END,c.map((e=>e.getTrackId()))),new zo(d,this.subhook,!1,this.traceId,this._reportMediaActionLogger,fo.UNSUB,this.tracks).execute(e,t)}))}}class Zo extends Jo{constructor(e,t,i){super(),this.subhook=e,this.tracks=t,this.onTrackUnpublish=i}execute(e,t){var i,r;return S(this,void 0,void 0,(function*(){const{tracks:n}=this,o=null===(i=e.context.logger)||void 0===i?void 0:i.createTraceId();null===(r=e.context.logger)||void 0===r||r.info(f.L_USER_LEFT_UNSUBSCRIBE_O,void 0,o),yield new Qo(n,this.subhook,o).execute(e,t),n.forEach((t=>{t.__innerDestroy(),e.removeRemoteTrack(t.getTrackId())})),this.onTrackUnpublish(n)}))}}function Xo(e,t,i,r){return S(this,void 0,void 0,(function*(){return{sdp:yield i.createOffer(t),extend:JSON.stringify({resolutionInfo:i.getOutboundVideoInfo()}),subscribeList:e.filter((e=>{const t=e.track.getTrackId(),{userId:i}=Ct(t),n=r.getResourcesByUserId(i);if(!n)return!1;const o=n.filter((e=>t===`${e.msid}_${e.mediaType}`)).length;return o})).map((e=>({simulcast:e.subTiny?Qn.TINY:Qn.NORMAL,resolution:"",uri:r.getPublishedResourceByTrackId(e.track.getTrackId()).uri}))),switchstream:!1}}))}function es(e,t,i){var r,o,s,a;return S(this,void 0,void 0,(function*(){const c=null===(r=null==e?void 0:e.logger)||void 0===r?void 0:r.createTraceId();null===(o=null==e?void 0:e.logger)||void 0===o||o.info(f.L_LIVING_ROOM_SPREAD_CDN_INFO_T,JSON.stringify({CDNUris:i}),c);const d=yield e.setRTCCDNUris(t,Jt.TOTAL_CONTENT_RESOURCE,JSON.stringify([i]));return d!==n.SUCCESS?(null===(s=null==e?void 0:e.logger)||void 0===s||s.error(f.L_LIVING_ROOM_SPREAD_CDN_INFO_R,`status: ${C.FAILED}, code: ${d}`,c),{code:T.SIGNAL_ERROR}):(null===(a=null==e?void 0:e.logger)||void 0===a||a.info(f.L_LIVING_ROOM_SPREAD_CDN_INFO_R,`status: ${C.SUCCESSED}`,c),{code:T.SUCCESS})}))}function ts(e,t,i){var r,o,s,a;return S(this,void 0,void 0,(function*(){const c=null===(r=null==e?void 0:e.logger)||void 0===r?void 0:r.createTraceId();null===(o=null==e?void 0:e.logger)||void 0===o||o.info(f.L_LIVING_ROOM_SET_ROOM_CDN_INFO_T,`CDNUris: ${i}`,c);const d=yield e.setRTCData(t,"cdn_uris",JSON.stringify([i]),!0,Io.ROOM);return d!==n.SUCCESS?(null===(s=null==e?void 0:e.logger)||void 0===s||s.error(f.L_LIVING_ROOM_SET_ROOM_CDN_INFO_R,`status: ${C.FAILED}, code: ${d}`,c),{code:T.SIGNAL_ERROR}):(null===(a=null==e?void 0:e.logger)||void 0===a||a.info(f.L_LIVING_ROOM_SET_ROOM_CDN_INFO_R,`status: ${C.SUCCESSED}`,c),{code:T.SUCCESS})}))}function is(e){return S(this,void 0,void 0,(function*(){const{context:t}=e,{roomId:i}=e,r=Object.assign({},e.getCDNUris(),{enableInnerCDN:e.getCDNEnable()});return(yield Promise.all([es(t,i,r),ts(t,i,r)])).every((e=>e.code===T.SUCCESS))?{code:T.SUCCESS}:{code:T.SIGNAL_ERROR}}))}function rs(e,t,i,r,n,o,s){return S(this,void 0,void 0,(function*(){const{roomId:a,crtUserId:c,roomMode:d}=t,_=[],l={},h={},g={},v=Bt(e,a,s),p=Object.keys(v),R=t.getAllUserIds();for(let e=p.length-1;e>=0;e-=1){const i=p[e],r=R.indexOf(i);if(-1===r){_.push(i),l[i]=Lt(v[i]);continue}const n=t.getResourcesByUserId(i),o=v[i],{publishedList:s,modifiedList:a,unpublishedList:c}=Nt(n,o,!0);l[i]=Lt(s),h[i]=Lt(c),g[i]=Lt(a),R.splice(r,1)}R.length&&R.forEach((e=>{t.removeResourcesByUserId(e)})),t.assignRoomData(v),R.length&&(yield ns(R,t,n,r,s),i.onUserLeave(R)),_.length&&i.onUserJoin(_);for(const e in h){if(e===c)continue;const o=h[e];if(o.length){const e=o.map((e=>t.getRemoteTrack(ft(e))));yield new Zo(n,e,i.onTrackUnpublish).execute(t,r)}}Object.keys(l).forEach((e=>{const r=l[e];if(0===r.length)return;const n=r.map((e=>{const i=ft(e),{userId:r,tag:n,mediaType:o}=Ct(i),s=o===Je.AUDIO_ONLY?new gt(n,r):new vt(n,r);return t.addRemoteTrack(s),s.__innerSetRemoteMuted(0===e.state),s}));i.onTrackPublish(n)})),Object.keys(g).forEach((e=>{g[e].forEach((e=>{const r=ft(e),n=t.getRemoteTrack(r);n.__innerSetRemoteMuted(0===e.state),n.isAudioTrack()?i.onAudioMuteChange(n):i.onVideoMuteChange(n)}))})),d===u.LIVE&&function(e,t,i){var r,n,o;if(!i)return void(null===(n=null===(r=t.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_LIVING_ROOM_RECONNECTED_R,JSON.stringify({status:C.FAILED,code:"",msg:"cdn_uris not found"})));const s=JSON.parse(i),a=(null===(o=t.getCDNUris())||void 0===o?void 0:o.enableInnerCDN)!==s.enableInnerCDN;t.setCDNUris(s),a&&e.onCDNEnableChange(s.enableInnerCDN)}(i,t,o)}))}function ns(e,t,i,r,n){var o;return S(this,void 0,void 0,(function*(){const s=[],a=[];e.forEach((e=>{s.push(...t.getRemoteTracksByUserId(e)),a.push(e)})),s.length&&(null===(o=t.context.logger)||void 0===o||o.info(f.L_RES_UNPUB_UNSUBSCRIBE_O,void 0,n),yield new Qo(s,i,n).execute(t,r),s.forEach((e=>t.removeRemoteTrack(e.getTrackId())))),a.length&&a.forEach((e=>t.removeResourcesByUserId(e)))}))}function os(e){var t;const{userId:i,userData:r,event:n,switchRoleType:o}=e;return{users:[{userId:i,extra:null===(t=r.filter((e=>"extra"===e.key))[0])||void 0===t?void 0:t.value,state:n,switchRoleType:o}]}}function ss(e){var t,i;const{userId:r,userData:n}=e,o=(e=>e.some((e=>"uris"===e.key||"cdn_uris"===e.key)))(n);if(!o)return;const s=null===(t=n.filter((e=>"uris"===e.key))[0])||void 0===t?void 0:t.value,a=null===(i=n.filter((e=>"cdn_uris"===e.key))[0])||void 0===i?void 0:i.value;return{userId:r,content:{uris:s?JSON.parse(s):[],cdn_uris:a&&JSON.parse(a)}}}const as=(e,t,i)=>{const r=e.split("\r\nm"),n=i===Je.AUDIO_ONLY?"audio":"video",o=r.filter((e=>e.includes(`=${n}`)&&e.includes(t)))[0];let s=new RegExp(`a=ssrc:(.*?) msid:${t}`);const a=o.match(s);return a?a[1]:""};class cs extends Jo{constructor(e,t,i){super(),this.msgContent=e,this.subhook=t,this.traceId=i}get kind(){return go.PARSE_USERSTATE}get priority(){return po.NORMAL}execute(e,t){return S(this,void 0,void 0,(function*(){const i=[],r=[],n=[],o=[],s={joined:i,left:r,upgrade:n,downgrade:o},{users:a}=this.msgContent;if(0===a.length)return s;for(let t=0;t<a.length;t++){const i=a[t];if(i.extra&&i.extra.roomId!==e.roomId)return s;if(1===Number(i.state)&&!e.getRemoteUserIds().includes(i.userId))return s}a.forEach((t=>{var s,a,c,d;const{userId:_}=t;if(0===Number(t.state)){const r=e.getResourcesByUserId(_);r||(t.switchRoleType?n.push(_):i.push(_),null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_PARSE_USERSTATE_COMMAND_R,JSON.stringify({userId:_,msg:"user "+(t.switchRoleType?"upgrade":"joined")}),this.traceId)),e.setResourcesByUserId(_,r||[])}else null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_PARSE_USERSTATE_COMMAND_R,JSON.stringify({userId:_,msg:"user "+(t.switchRoleType?"downgrade":"left")}),this.traceId),t.switchRoleType?o.push(_):r.push(_)}));const c=[...r,...o];return c.length&&(yield ns(c,e,this.subhook,t,this.traceId)),s}))}}class ds extends Jo{constructor(e,t,i,r,n,o,s,a){super(),this.msgContent=e,this.messageType=t,this.senderId=i,this.subhook=r,this.callback=n,this.traceId=o,this.sentTime=s,this._reportMediaActionLogger=a}get kind(){return go.PARSE_REMOTERES}get priority(){return po.NORMAL}execute(e,t){var i,r,n,o,s;return S(this,void 0,void 0,(function*(){const{uris:a}=this.msgContent,c=[],d=[],_=[];let l;const u=this.senderId,{messageType:h}=this;if(!e.getRemoteUserIds().includes(u))return;const g=e.getResourcesByUserId(u)||[];switch(h){case Jt.MODIFY:_.push(...a);break;case Jt.PUBLISH:c.push(...a);break;case Jt.UNPUBLISH:d.push(...a);break;case Jt.TOTAL_CONTENT_RESOURCE:l=Nt(g,a),c.push(...l.publishedList),d.push(...l.unpublishedList),_.push(...l.modifiedList)}if(c.length>0){const o=g.map(ft),s=[],a=[];if(c.forEach((t=>{const i=ft(t),r=o.indexOf(i),{userId:n,tag:c,mediaType:d}=Ct(i);r>-1?g[r]=t:g.push(t);let _=e.getRemoteTrack(i);_?_.isSubscribed()&&s.push(_):(_=d===Je.AUDIO_ONLY?new gt(c,n):new vt(c,n),e.addRemoteTrack(_),a.push(_)),_.__innerSetRemoteMuted(0===t.state)})),s.length){const n=s.map((e=>e.getTrackId())),{code:o}=yield new zo(s,this.subhook,!0,this.traceId).execute(e,t);o!==T.SUCCESS&&(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RESUB_REPUB_RES_R,JSON.stringify({status:C.FAILED,trackIds:n,code:o}),this.traceId))}this.callback.onTrackPublish(a),null===(n=this._reportMediaActionLogger)||void 0===n||n.reportQualityRecvPubMsgData(this.sentTime,this.senderId)}if(d.length>0){const i=d.map(ft);for(let e=g.length-1;e>=0;e-=1){const t=g[e];i.includes(ft(t))&&g.splice(e,1)}const r=d.map((t=>{const i=ft(t);return e.getRemoteTrack(i)}));yield new Zo(this.subhook,r,this.callback.onTrackUnpublish).execute(e,t)}if(_.length>0){const t=g.map(ft);for(let i=0;i<_.length;i+=1){const r=_[i],n=ft(r),o=t.indexOf(n);g[o].state=r.state;const s=e.getRemoteTrack(n);s.__innerSetRemoteMuted(0===r.state),s.isAudioTrack()?this.callback.onAudioMuteChange(s):this.callback.onVideoMuteChange(s)}}if(e.setResourcesByUserId(u,g),e.roomMode!==mo.LIVE)return;const v=this.msgContent;if(!v.cdn_uris)return;const p=(null===(o=e.getCDNUris())||void 0===o?void 0:o.enableInnerCDN)!==v.cdn_uris[0].enableInnerCDN;e.setCDNUris(v.cdn_uris[0]),p&&this.callback.onCDNEnableChange(!!(null===(s=e.getCDNUris())||void 0===s?void 0:s.enableInnerCDN))}))}}class _s extends Jo{constructor(e,t,i,r,n){super(),this.tracks=e,this.subhook=t,this.forceReq=i,this.traceId=r,this._reportMediaActionLogger=n}get kind(){return go.SUBSCRIBE}execute(e,t){var r,n,o,a,c,d;return S(this,void 0,void 0,(function*(){const{tracks:_,forceReq:l}=this;if(null===(n=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_ABSTRACT_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:_.map(Vt),forceReq:l}),this.traceId),!i("tracks",_,(()=>s(_)&&_.length>0&&_.every((e=>e instanceof ht||e.track instanceof ht))),!0))return null===(a=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===a||a.error(f.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:T.PARAMS_ERROR};const u=e.getSubscribedList().map((e=>Object.assign({},e))),h=_.map((e=>e instanceof ht?{track:e}:e));let g=!1;const v=[];return h.forEach((e=>{const t=e.track.getTrackId();v.push(t);const i=u.find((e=>e.track.getTrackId()===t));i&&i.subTiny===e.subTiny||(i?i.subTiny=e.subTiny:u.push(e),g=!0)})),g||l?(e.polarisReport.sendR2(Eo.SUBSCRIBE,So.BEGIN,v),new zo(u,this.subhook,!0,this.traceId,this._reportMediaActionLogger).execute(e,t)):(null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.warn(f.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.SUCCESSED,msg:"repeat subscribe"}),this.traceId),{code:T.SUCCESS})}))}}class ls extends Jo{constructor(e,t,i=3e4,r){var n;super(),this.tracks=e,this.pubhook=t,this.signalRetryTime=i,this._reportMediaActionLogger=r,this._logger=null,this._actionStartTime=Date.now(),this._trackMediaMap={},this._logger=We.getLogger(),this._traceId=null===(n=this._logger)||void 0===n?void 0:n.createTraceId()}get kind(){return go.PUBLISH}_removePubFailedTracks(e,t){e.forEach((e=>{var i;const r=e instanceof rt?e:e.track;null===(i=this._logger)||void 0===i||i.debug(f.L_ABSTRACT_ROOM_PUBLISH_P,`remove pub failed track from peerconnection -> trackId: ${r.getTrackId()}`,this._traceId),t.removeLocalTrackById(r.getTrackId())}))}__publish(e,t,i,r,n){var o,s,a,c,d,_,l,u,h,g;return S(this,void 0,void 0,(function*(){const{pcName:v,pc:p,headers:R}=t,{roomId:m}=e,I=[];i.forEach((e=>{const{track:t}=e instanceof rt?{track:e}:e;I.push(t)})),i.sort(((e,t)=>{const{track:i}=e instanceof rt?{track:e}:e,{max:r}=i.getBitrate(),{track:n}=t instanceof rt?{track:t}:t,{max:o}=n.getBitrate();return r-o}));if(p.getLocalTracks().length+((e,t)=>{let i=0;return e.forEach((e=>{const r=e instanceof rt?e.getTrackId():e.track.getTrackId();t.getLocalTrack(r)||(e instanceof rt?i++:e.pubTiny&&e.track.isVideoTrack()&&(i+=2))})),i})(i,p)>10)return null===(o=this._logger)||void 0===o||o.error(f.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:C.FAILED,code:T.PUBLISH_TRACK_LIMIT_EXCEEDED,trackIds:i.map(Vt),msg:`pcName: ${v} publish track limit exceeded`}),this._traceId),{code:T.PUBLISH_TRACK_LIMIT_EXCEEDED,tracks:I};null===(s=this._logger)||void 0===s||s.info(f.L_ABSTRACT_ROOM_PUBLISH_P,`publish tracks -> roomId: ${m}, tracks: ${i.map(Vt)}`,this._traceId);const E=[];for(let e=0;e<i.length;e++){const t=i[e],{track:r,pubTiny:n}=t instanceof rt?{pubTiny:!1,track:t}:t;if(r.isVideoTrack()&&n){let e;try{e=r.__innerGetMediaStreamTrack().clone();const t=n.frameRate||Ve.FPS_15,i=n.resolution||Fe.W176_H144,{width:o,height:s}=yt(i),a=bt(t);yield e.applyConstraints({width:o,height:s,frameRate:a})}catch(t){null==e||e.stop(),null===(a=this._logger)||void 0===a||a.warn(f.L_ABSTRACT_ROOM_PUBLISH_P,`pubTiny failed -> id: ${r.getTrackId()}, msg: ${t.message}`,this._traceId);break}const t=new ot(r.getTag(),r.getUserId(),e,!0);E.push(t),p.addLocalTrack(t)}p.addLocalTrack(r)}p.clearReTryExchangeTimer();const S=e.useMutilPeerC?[]:e.getSubscribedList(),O=yield Xo(S,!1,p,e);r&&(O.pushOtherRooms=r),Co.formatSourceIdMapFromSdp(O.sdp.sdp,"publish");const L=yield new qo(R,O,this._traceId,!0).execute(e,n);if(I.forEach((e=>{const t=e.getTrackId();this._trackMediaMap[t]=L.qualityMsList||[]})),L.code!==T.SUCCESS)return null===(c=this._reportMediaActionLogger)||void 0===c||c.reportPubOrSubQualityData(fo.PUB,this._actionStartTime,I,L.code,this._trackMediaMap),null===(d=this._logger)||void 0===d||d.error(f.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:C.FAILED,tracks:i.map(Vt),code:L.code,msg:"exchange failed"}),this._traceId),this._removePubFailedTracks(i,p),{code:L.code,tracks:I};const{sdp:N,resultCode:A,message:y}=L.data;if(A!==T.SUCCESS)return null===(_=this._reportMediaActionLogger)||void 0===_||_.reportPubOrSubQualityData(fo.PUB,this._actionStartTime,I,A,this._trackMediaMap),null===(l=this._logger)||void 0===l||l.error(f.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:C.FAILED,trackIds:i.map(Vt),code:A,msg:`exchange inner failed: ${y}`}),this._traceId),this._removePubFailedTracks(i,p),{code:A,tracks:I};null===(u=this._reportMediaActionLogger)||void 0===u||u.setPubOrSubSuccessTime(Date.now());const k=yield p.setRemoteAnswer(N.sdp);return k!==T.SUCCESS?(null===(h=this._reportMediaActionLogger)||void 0===h||h.reportPubOrSubQualityData(fo.PUB,this._actionStartTime,I,k,this._trackMediaMap),null===(g=this._logger)||void 0===g||g.error(f.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:C.FAILED,trackIds:i.map(Vt),code:k,msg:"set remote answer error"}),this._traceId),{code:k,tracks:I}):(E.length&&this._updateTinyTrackIdSSRCMap(e,O.sdp.sdp,E),Object.assign(Object.assign({},L),{tracks:I}))}))}_updateTinyTrackIdSSRCMap(e,t,i){i.forEach((i=>{const r=as(t,i.getStreamId(),Je.VIDEO_ONLY);e.setTrackIdSSRCMap(Number(r),i.getTrackId())}))}_mergePublishRes(e,t){var i,r,o;return S(this,void 0,void 0,(function*(){const s=t.crtUserId,{roomId:a}=t;let c="";const d=[],_=[],l=t.getResourcesByUserId(s),u=[...l];let h=[];e.forEach((e=>{const{tracks:i}=e;if(e.code!==T.SUCCESS)return void d.push({code:e.code,tracks:i});_.push(...i);const{publishList:r,urls:n,mcuPublishList:o}=e.data;c=null==n?void 0:n.liveUrl;r.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:t.getTrackState(ft(e))},e))).forEach((e=>{const{isInclude:t,index:i}=((e,t)=>{let i=!1,r=0;for(let n=0;n<t.length;n++){const o=t[n];if(`${e.msid}_${e.mediaType}`==`${o.msid}_${o.mediaType}`){i=!0,r=n;break}}return{isInclude:i,index:r}})(e,u);t?u.splice(i,1,e):u.push(e)}));const s=(null==o?void 0:o.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:1},e))))||[];h=s}));const{publishedList:g}=Nt(l,u),v=Object.assign(Object.assign({},t.getCDNUris()),{enableInnerCDN:t.getCDNEnable()}),p=v&&v.broadcast===To.SPREAD?JSON.stringify([v]):"",R=Date.now(),m=yield t.context.setRTCTotalRes(a,[pt(Jt.PUBLISH,g)],Rt(u),Jt.TOTAL_CONTENT_RESOURCE,Rt(h),p);if(null===(i=this._reportMediaActionLogger)||void 0===i||i.reportPubOrSubQualityData(fo.PUB,this._actionStartTime,_,m,this._trackMediaMap,[{dur:Date.now()-R,cod:m}]),m!==n.SUCCESS)return null===(r=this._logger)||void 0===r||r.error(f.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:C.FAILED,code:m,msg:"send publish streams notification failed"}),this._traceId),{code:T.SIGNAL_ERROR};t.setResourcesByUserId(s,u);const I=g.map((e=>ft(e)));t.polarisReport&&t.polarisReport.sendR2(Eo.PUBLISH,So.BEGIN,I),g.forEach((e=>{const i=t.useMutilPeerC?`${a}_${(e=>{const t=e.split("_");return{tag:t.pop(),userId:t.join("_")}})(e.msid).tag}`:`${a}_pub`,{pc:r}=t.peerMgr.getPCItemByPCName(i);r.getLocalTrack(`${e.msid}_${e.mediaType}`).__innerSetPublished(!0)})),null===(o=this._logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:C.SUCCESSED,code:d.length?T.SOME_TRACKS_PUBLISH_FAILED:T.SUCCESS,pubSuccessTrackIds:I}),this._traceId);const E={code:T.SUCCESS};return c&&(E.liveUrl=c),d.length&&(E.failedTracks=d,E.code=T.SOME_TRACKS_PUBLISH_FAILED),E}))}execute(e,t){var r,n,o,a,c,d;return S(this,void 0,void 0,(function*(){this._actionStartTime=Date.now();let{tracks:_}=this;if(null===(n=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_ABSTRACT_ROOM_PUBLISH_T,JSON.stringify({trackIds:_.map(Vt)})),!i("tracks",_,(()=>s(_)&&_.length>0&&_.every((e=>e instanceof rt||e.track instanceof rt))),!0))return null===(a=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===a||a.error(f.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),this._traceId),{code:T.PARAMS_ERROR};if(_=_.filter((t=>{var i,r;const{track:n}=t instanceof rt?{track:t}:t,o=n.isDestroyed();return o&&(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(f.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({msg:`track -> ${n.getTrackId()} has beem destroyed`}),this._traceId)),!o})),!_.length)return null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:C.FAILED,code:T.PUBLISH_TRACKS_IS_INVALID,msg:"params tracks is invalid"}),this._traceId),{code:T.PUBLISH_TRACKS_IS_INVALID};const l=[],{plist:u,pushOtherRooms:h}=this.pubhook(_);for(let i=0;i<u.length;i++){const r=u[i];l.push(this.__publish(e,r,r.tracks,h,t))}const g=yield Promise.all(l);return yield this._mergePublishRes(g,e)}))}}class us extends Jo{constructor(e,t,i){super(),this.tracks=e,this.unpubhook=t,this._reportMediaActionLogger=i,this._actionStartTime=Date.now(),this._trackMediaMap={}}get kind(){return go.UNPUBLISH}__unpublish(e,t,i,r){var n,o,s,a;return S(this,void 0,void 0,(function*(){const{pcName:c,pc:d}=i,_=r.map((e=>e.getTrackId()));if(0===_.map(e.getPublishedResourceByTrackId.bind(e)).filter((e=>!!e)).length)return{code:T.SUCCESS,tracks:r};_.forEach((e=>d.removeLocalTrackById(e))),e.polarisReport.sendR2(Eo.PUBLISH,So.END,_),d.clearReTryExchangeTimer();const l=e.useMutilPeerC?[]:e.getSubscribedList(),u=yield Xo(l,!1,d,e),{pushOtherRooms:h,headers:g}=this.unpubhook(r,c);h&&(u.pushOtherRooms=h);const v=yield new qo(g,u,this._traceId,!0).execute(e,t);if(r.forEach((e=>{const t=e.getTrackId();this._trackMediaMap[t]=v.qualityMsList||[]})),v.code!==T.SUCCESS)return this._reportMediaActionLogger.reportPubOrSubQualityData(fo.UNPUB,this._actionStartTime,r,v.code,this._trackMediaMap),null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_ABSTRACT_ROOM_UNPUBLISH_P,JSON.stringify({status:C.FAILED,code:v.code,trackIds:r.map(Vt),msg:"exchange failed"}),this._traceId),{code:v.code,tracks:r};const{resultCode:p,message:R}=v.data;return p!==T.SUCCESS?(this._reportMediaActionLogger.reportPubOrSubQualityData(fo.UNPUB,this._actionStartTime,r,v.data.resultCode,this._trackMediaMap),null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_ABSTRACT_ROOM_UNPUBLISH_P,JSON.stringify({status:C.FAILED,code:p,trackIds:r.map(Vt),msg:`exchange inner failed: ${R}`}),this._traceId),{code:p,tracks:r}):Object.assign(Object.assign({},v),{tracks:r})}))}_mergeUnpublishRes(e,t){var i,r,o,s;return S(this,void 0,void 0,(function*(){const a=e.context.getCurrentId(),{roomId:c}=e,d=[],_=[],l=[],u=[],h=[];let g=[];for(let i=0;i<t.length;i++){const r=t[i],{tracks:n}=r;if(r.code!==T.SUCCESS){_.push({code:r.code,tracks:n});continue}l.push(...n);const{mcuPublishList:o}=r.data,s=r.tracks.map((e=>e.getTrackId()));h.push(...s);const a=s.map(e.getPublishedResourceByTrackId.bind(e)).filter((e=>!!e));u.push(...a),d.push(r);const c=o?o.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:1},e))):[];g=c}const v=e.getResourcesByUserId(a).filter((e=>!u.includes(e))),p=Date.now(),R=yield e.context.setRTCTotalRes(c,[pt(Jt.UNPUBLISH,u)],Rt(v),Jt.TOTAL_CONTENT_RESOURCE,Rt(g));if(this._reportMediaActionLogger.reportPubOrSubQualityData(fo.UNPUB,this._actionStartTime,l,R,this._trackMediaMap,[{dur:Date.now()-p,cod:R}]),R!==n.SUCCESS)return null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:C.FAILED,code:R,msg:"send unpublish notification failed"}),this._traceId),{code:T.SIGNAL_ERROR};null===(s=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:C.SUCCESSED,code:_.length?T.SOME_TRACKS_PUBLISH_FAILED:T.SUCCESS,msg:"unpublish success",unPubResourceIds:h}),this._traceId),d.forEach((t=>S(this,void 0,void 0,(function*(){const{sdp:i}=t.data,{tracks:r}=t,n=e.peerMgr.getPCByTrackId(r[0].getTrackId());yield n.setRemoteAnswer(i.sdp)})))),e.setResourcesByUserId(a,v);const m={code:T.SUCCESS};return _.length&&(m.failedTracks=_,m.code=T.SOME_TRACKS_PUBLISH_FAILED),m}))}execute(e,t){var r,n,o,s,a;return S(this,void 0,void 0,(function*(){this._actionStartTime=Date.now();const{crtUserId:c,roomId:d}=e,{tracks:_}=this;this._traceId=null===(r=e.context.logger)||void 0===r?void 0:r.createTraceId(),null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_UNPUBLISH_T,JSON.stringify({trackIds:_.map(Vt)}));if(!i("tracks",_,(()=>_.every((e=>e.getUserId()===c&&e instanceof rt))),!0))return null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"})),{code:T.PARAMS_ERROR};const l=e.peerMgr.createPeerCList(_),u=[];for(let i=0;i<l.length;i++){const{tracks:r}=l[i];u.push(this.__unpublish(e,t,l[i],r))}const h=yield Promise.all(u);let g=h.length;if(h.forEach((e=>{e.code!==T.SUCCESS||e.data||(g-=1)})),0===g)return{code:T.SUCCESS};return yield this._mergeUnpublishRes(e,h)}))}}class hs extends Jo{constructor(e,t){super(),this.localTrack=e,this._recvSignalResultFn=t}get kind(){return go.LOCAL_TRACK_MUTE}execute(e,t){var i,r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const{localTrack:t}=this,l=t.getTrackId(),{crtUserId:u,roomId:h}=e,g=!t.isLocalMuted(),v=null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_T,JSON.stringify({enabled:g,trackId:this.localTrack.getTrackId()}),v);const p=[{resourceId:l,enabled:g}],R=e.getResourcesByUserId(u),m=[];for(let e=0;e<R.length;e+=1){const t=R[e],i=ft(t),r=p.findIndex((e=>e.resourceId===i));if(r>=0){const{enabled:e}=p[r];t.state=e?1:0,m.push(t);break}}const I=yield e.context.setRTCTotalRes(h,[pt(Jt.MODIFY,m)],Rt(R),Jt.TOTAL_CONTENT_RESOURCE);this._recvSignalResultFn(I),I!==n.SUCCESS&&(null===(c=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_R,JSON.stringify({status:C.FAILED,code:I,msg:"signal error"}),v)),null===(_=null===(d=e.context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_R,JSON.stringify({status:C.SUCCESSED}),v)}))}}class gs extends Jo{constructor(e,t,i){super(),this.pcName=e,this.isPub=t,this.retryHook=i}get kind(){return go.RETRY_EXCHANGE}get priority(){return po.HIGH}execute(e,t){var i,r,n,o,s;return S(this,void 0,void 0,(function*(){const a=null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_RETRY_EXCHANGE_COMMAND_T),this._store=e,this._userId=e.context.getCurrentId();const{pcName:c,isPub:d}=this,{useMutilPeerC:_}=e,{pc:l}=e.peerMgr.getPCItemByPCName(c),u=d&&_?[]:e.getSubscribedList(),h=yield Xo(u,!0,l,e),{pushOtherRooms:g,headers:v}=this.retryHook(c);g&&(h.pushOtherRooms=g);const p=yield new qo(v,h,a).execute(e,t);if(p.code!==T.SUCCESS)return;const{sdp:R,resultCode:m}=p.data;if(m!==T.SUCCESS)return;l.clearReTryExchangeTimer();if((yield l.setRemoteAnswer(R.sdp))!==T.SUCCESS)return;if(!this.isPub)return;const I=(null===(s=p.data)||void 0===s?void 0:s.publishList)||[],{plus:E,minus:S}=this._diffPublishListChange(I);(E.length||S.length)&&(yield this._spreadPublishListUri(E,S,a))}))}_diffPublishListChange(e){const t=this._store.getResourcesByUserId(this._userId),{useMutilPeerC:i}=this._store;let r=JSON.parse(JSON.stringify(t));i?e.forEach((e=>{const{mediaType:t,msid:i}=e,n=r.findIndex((e=>{const{mediaType:r,msid:n}=e;return t===r&&i===n}));if(-1===n){const t=Object.assign({tag:i.split("_").pop(),state:this._store.getTrackState(ft(e))},e);r.push(t)}else r[n].uri=e.uri})):r=e.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:this._store.getTrackState(ft(e))},e)));const{publishedList:n,unpublishedList:o}=Nt(t,r,!0);return this._store.setResourcesByUserId(this._userId,r),{plus:n,minus:o}}_spreadPublishListUri(e,t,i){var r,o,s;return S(this,void 0,void 0,(function*(){const a=this._store.getResourcesByUserId(this._userId);null===(r=this._store.context.logger)||void 0===r||r.info(f.L_RETRY_EXCHANGE_SPREAD_T,JSON.stringify({plus:e,minus:t,allPublishList:a,pcName:this.pcName}),i);const c=[];t.length&&c.push(pt(Jt.UNPUBLISH,t)),e.length&&c.push(pt(Jt.PUBLISH,e));(yield this._store.context.setRTCTotalRes(this._store.roomId,c,Rt(a),Jt.TOTAL_CONTENT_RESOURCE))===n.SUCCESS?null===(o=this._store.context.logger)||void 0===o||o.info(f.L_RETRY_EXCHANGE_SPREAD_R,`status: ${C.SUCCESSED}`,i):null===(s=this._store.context.logger)||void 0===s||s.error(f.L_RETRY_EXCHANGE_SPREAD_R,`status: ${C.FAILED}`,i)}))}}class vs extends Jo{constructor(e,t,i,r,n=3e4,o,s){super(),this.subhook=e,this.callbacks=t,this._retryHook=i,this._pubhook=r,this._signalRetryTime=n,this._pullRTCRoomStatus=o,this.livingType=s}get kind(){return go.ON_SIGNAL_RECONNECTED}get priority(){return po.HIGH}execute(e,t){var i,r,o,s,a,c;return S(this,void 0,void 0,(function*(){const{roomId:d,roomMode:_}=e;this._roomId=d,this._roomMode=_;const l=null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_ABSTRACT_ROOM_IM_RECONNECTED_T,void 0,l);if(e.peerMgr.getPCList().some((e=>"closed"===e.getRTCPeerConn().connectionState)))return null===(c=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:C.FAILED,msg:"RTCPeerConnection closed. Please rejoin room to restore services"}),l),void(this.callbacks.onPeerClosed&&this.callbacks.onPeerClosed());const{code:u}=yield e.context.rtcPing(d,_);if(40001===u){(yield this._joinRoom(e,l,t))===n.SUCCESS&&(yield this._restoreMediaServer(e,t))}else yield this._pullRTCRoomStatus(this._roomId,l).execute(e,t)}))}_joinRoom(e,t,i){var r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const{code:l,data:u}=yield e.context.joinRTCRoom(this._roomId,this._roomMode,this.livingType);if(l!==n.SUCCESS)return void(null===(o=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===o||o.error(f.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:C.FAILED,code:l,msg:"im reconnect joinRTCRoom failed"}),t));if(!u)return void(null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:C.FAILED,msg:"im reconnect joinRTCRoom, roomData is empty"}),t));const h=null===(c=u.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===c?void 0:c.value;return yield rs(u,e,this.callbacks,i,this.subhook,h,t),null===(_=null===(d=e.context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:C.SUCCESSED,roomData:u}),t),l}))}_restoreMediaServer(e,t){return S(this,void 0,void 0,(function*(){const{useMutilPeerC:i}=e.peerMgr,r=e.getLocalTracks(),n=Object.values(e.getRemoteTracks()).filter((e=>!!e.isSubscribed()));if(i)return n.length&&(yield new _s(n,this.subhook,!0).execute(e,t)),void(r.length&&(yield new ls(r,this._pubhook,this._signalRetryTime).execute(e,t)));r.length&&(yield new ls(r,this._pubhook,this._signalRetryTime).execute(e,t)),!r.length&&n.length&&(yield new _s(n,this.subhook,!0).execute(e,t))}))}}class ps extends Go{constructor(e,t,i,r=vo.NORMAL,n){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=n,this._logger=null,this._logger=We.getLogger()}get kind(){return go.ASYNC_COMMAND}execute(e,t){var i,r,n;return S(this,void 0,void 0,(function*(){const{tracks:o}=this;if(this.state===vo.NORMAL){const r=e.getSubscribedList().slice(),{code:n,failedList:s}=yield new zo(o,this.subhook,!0,this.traceId).execute(e,t),a=e.getSubscribedList().slice(),{subscribe:c,unsubscribe:d}=this.pickoutSubscribed(a,r);return null===(i=this.callbacks)||void 0===i||i.onTaskCompleted({code:n,subscribe:c,unsubscribe:d,failedList:s}),{code:n,failedList:s}}if(this.state===vo.TAIL){const{code:i}=yield new ps(this.tracks,this.subhook,this.callbacks,vo.MIDDLE,this.traceId).execute(e,t);if(i===T.SUCCESS){const i=e.getCollectSubscribeList().slice(0),o=e.getSubscribedList().slice(),{code:s,failedList:a}=yield new zo(i,this.subhook,!0).execute(e,t);if(s!==T.SUCCESS)return null===(r=this.callbacks)||void 0===r||r.onTaskCompleted({code:s,subscribe:[],unsubscribe:[],failedList:a}),{code:s,failedList:a};const c=e.getSubscribedList().slice(0),{subscribe:d,unsubscribe:_}=this.pickoutSubscribed(c,o);return null===(n=this.callbacks)||void 0===n||n.onTaskCompleted({code:s,subscribe:d,unsubscribe:_,failedList:a}),{code:s,failedList:a}}return{code:i}}return Go.AsyncUpdateSubscribeTasks.splice(Go.AsyncUpdateSubscribeTasks.length,0,...this.tracks),new Promise((t=>{const i=this.formateTrack(o);e.resetCollectSubscribeList(i),t({code:T.SUCCESS})}))}))}}class Rs extends Go{constructor(e,t,i,r=vo.NORMAL,n){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=n}get kind(){return go.ASYNC_COMMAND}execute(e,t){var r,n,o,a,c;return S(this,void 0,void 0,(function*(){const{tracks:d}=this;if(this.state===vo.NORMAL){const i=e.getSubscribedList().slice(),{code:n,failedList:o}=yield new _s(d,this.subhook,!1,this.traceId).execute(e,t),s=e.getSubscribedList().slice(),{subscribe:a,unsubscribe:c}=this.pickoutSubscribed(s,i);return null===(r=this.callbacks)||void 0===r||r.onTaskCompleted({code:n,subscribe:a,unsubscribe:c,failedList:o}),{code:n,failedList:o}}if(null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:d.map(Vt)}),this.traceId),!i("tracks",d,(()=>s(d)&&d.length>0&&d.every((e=>e instanceof ht||e.track instanceof ht))),!0))return null===(c=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:T.PARAMS_ERROR};const _=this.getSubscribedList(e).map((e=>Object.assign({},e))),l=d.map((e=>e instanceof ht?{track:e}:e)),u=[];if(l.forEach((e=>{const t=e.track.getTrackId();u.push(t);const i=_.find((e=>e.track.getTrackId()===t));if(i){if(i.subTiny===e.subTiny)return;i.subTiny=e.subTiny}else _.push(e)})),e.polarisReport.sendR2(Eo.SUBSCRIBE,So.BEGIN,u),this.state===vo.TAIL){const{code:i}=yield new Rs(this.tracks,this.subhook,this.callbacks,vo.MIDDLE,this.traceId).execute(e,t);if(i===T.SUCCESS){const i=e.getCollectSubscribeList().slice(0);return new ps(i,this.subhook,this.callbacks,vo.NORMAL,this.traceId).execute(e,t)}return{code:i}}return Go.AsyncSubscribeTasks.splice(Go.AsyncSubscribeTasks.length,0,...this.tracks),new Promise((t=>{e.resetCollectSubscribeList(_),t({code:T.SUCCESS})}))}))}getSubscribedList(e){return this.state===vo.MIDDLE?e.getCollectSubscribeList():e.getSubscribedList()}}class ms extends Go{constructor(e,t,i,r=vo.NORMAL,n){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=n}get kind(){return go.ASYNC_COMMAND}execute(e,t){var r,n,o,a,c;return S(this,void 0,void 0,(function*(){const{tracks:d}=this;if(this.state===vo.NORMAL){const i=e.getSubscribedList().slice(),{code:n,failedList:o}=yield new Qo(d,this.subhook,this.traceId).execute(e,t),s=e.getSubscribedList().slice(),{subscribe:a,unsubscribe:c}=this.pickoutSubscribed(s,i);return null===(r=this.callbacks)||void 0===r||r.onTaskCompleted({code:n,subscribe:a,unsubscribe:c,failedList:o}),{code:n,failedList:o}}if(null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_UNSUBSCRIBE_T,JSON.stringify({trackIds:d.map(Vt)}),this.traceId),!i("tracks",d,(()=>s(d)&&d.length>0&&d.every((e=>e instanceof ht))),!0))return null===(c=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===c||c.warn(f.L_ABSTRACT_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:T.PARAMS_ERROR};const _=this.getSubscribedList(e).map((e=>Object.assign({},e))).filter((e=>!d.includes(e.track)));if(e.polarisReport.sendR2(Eo.SUBSCRIBE,So.END,d.map((e=>e.getTrackId()))),this.state===vo.TAIL){const{code:i}=yield new ms(this.tracks,this.subhook,this.callbacks,vo.MIDDLE,this.traceId).execute(e,t);if(i===T.SUCCESS){const i=e.getCollectSubscribeList().slice(0).map((e=>e.track));return new ps(i,this.subhook,this.callbacks,vo.NORMAL,this.traceId).execute(e,t)}return{code:i}}return Go.AsyncUnsubscribeTasks.splice(Go.AsyncUnsubscribeTasks.length,0,...this.tracks),new Promise((t=>{e.resetCollectSubscribeList(_),t({code:T.SUCCESS})}))}))}getSubscribedList(e){return this.state===vo.MIDDLE?e.getCollectSubscribeList():e.getSubscribedList()}}var Is;!function(e){e[e.JOIN=0]="JOIN",e[e.LEAVE=1]="LEAVE",e[e.OFFLINE=2]="OFFLINE",e[e.RESOURCECHANGE=3]="RESOURCECHANGE"}(Is||(Is={}));class Es extends Jo{constructor(e,t,i,r,n,o,s){super(),this._roomId=e,this._traceId=t,this._context=i,this._callbacks=r,this._subhook=n,this._dealUserAppListener=o,this._targetPullVersion=s}get kind(){return go.PULL_RTCROOM_STATUS}execute(e,t){var i,r,o,s;return S(this,void 0,void 0,(function*(){const a=e.getRoomStatusVersion();if(null===(i=this._context.logger)||void 0===i||i.info(f.L_PULL_ROOM_STATUS_T,JSON.stringify({roomId:this._roomId,localVersion:a}),this._traceId),this._targetPullVersion&&this._targetPullVersion<=a)return null===(r=this._context.logger)||void 0===r||r.info(f.L_PULL_ROOM_STATUS_R,JSON.stringify({status:C.SUCCESSED,msg:"the roomData has been pulled",localVersion:a,targetPullVersion:this._targetPullVersion}),this._traceId),{code:n.SUCCESS};const{code:c,data:d}=yield this._context.pullRTCRoomStatus(this._roomId,a);if(c!==n.SUCCESS)return null===(o=this._context.logger)||void 0===o||o.info(f.L_PULL_ROOM_STATUS_R,JSON.stringify({status:C.FAILED,code:c}),this._traceId),{code:c};const{bFullStatus:_,version:l,usersData:u,roomStatus:h}=d;if(null===(s=this._context.logger)||void 0===s||s.info(f.L_PULL_ROOM_STATUS_R,JSON.stringify({bFullStatus:_,version:Ft(l),usersData:u,roomStatus:h}),this._traceId),e.setRoomStatusVersion(l),_){const{urisData:i,CDNUris:r}=function(e){const t={users:{}};let i="";return e.forEach((e=>{var r,n;const{userId:o,userData:s}=e;t.users[o]={};const a=null===(r=s.filter((e=>"uris"===e.key))[0])||void 0===r?void 0:r.value,c=null===(n=s.filter((e=>"cdn_uris"===e.key))[0])||void 0===n?void 0:n.value;i=c||i,t.users[o]={uris:a}})),{urisData:t,CDNUris:i&&JSON.stringify(JSON.parse(i)[0])}}(u);return yield rs(i,e,this._callbacks,t,this._subhook,r,this._traceId),{code:c}}for(let i=0;i<h.length;i++){const r=h[i];if(r.event===Is.RESOURCECHANGE){const i=ss(r);if(!i)continue;const{content:n,userId:o}=i;if(o===e.crtUserId)continue;yield new ds(n,Jt.TOTAL_CONTENT_RESOURCE,o,this._subhook.bind(this),this._callbacks,this._traceId).execute(e,t)}else{const i=os(r),n=yield new cs(i,this._subhook.bind(this),this._traceId).execute(e,t);this._dealUserAppListener(n)}}return{code:c}}))}}class Ss{constructor(){}static getMemo(){return this._memo||(this._memo={}),window.__memo__=this._memo,this._memo}static destroy(){this._memo={}}}Ss._memo={};const Ts=1,fs=5;var Cs,Os;!function(e){e[e.new=0]="new",e[e.checking=1]="checking",e[e.connected=2]="connected",e[e.completed=3]="completed",e[e.failed=4]="failed",e[e.disconnected=5]="disconnected",e[e.closed=6]="closed"}(Cs||(Cs={})),function(e){e[e.SERVER_KICK=1]="SERVER_KICK",e[e.OTHER_KICK=2]="OTHER_KICK"}(Os||(Os={}));class Ls{constructor(e,t,i){this._roomId=e,this._clientSessionId=t,this._userId=i,this._iceCandidatePair={},this._peerCStatus={},this.reportQualityJoinRoomData=(e,t,i,r)=>{this._baseReportData=Object.assign(this._baseReportData,{snid:r});const n=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{cod:t,time:e,dur:Date.now()-e,rtp:i});Ye.__statistics(f.L_QS_JOIN_ROOM_S,JSON.stringify(n))},this._baseReportData={rid:this._roomId,csnid:this._clientSessionId,snid:"",time:Date.now(),uid:this._userId},this._networkReportData={cr:"unknown",net:"unknown"}}reportQualityKickedData(e){const t=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{time:Date.now(),cod:e===Os.OTHER_KICK?fs:Ts});Ye.__statistics(f.L_QS_KICKED_S,JSON.stringify(t))}reportPubOrSubQualityData(e,t,i,r,n,o){i.forEach((i=>{var s,a;const c=i instanceof rt||i instanceof ht?i:i.track,d=c.getTrackId(),{mediaType:_}=Ct(d);let l=!1;l=c instanceof rt?!!c.isVideoTrack()&&(null===(a=(s=c).__isTiny)||void 0===a?void 0:a.call(s)):i.subTiny||!1;const u=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{resid:d,mtp:_,smct:l?Qn.TINY:Qn.NORMAL,stp:"Rongcloud"!==c.getTag()?1:0,cod:r,msas:n?n[d]:[],sigs:o,time:Date.now(),dur:Date.now()-t});switch(e){case"pub":Ye.__statistics(f.L_QS_PUBLISH_S,JSON.stringify(u));break;case"unpub":Ye.__statistics(f.L_QS_UNPUBLISH_S,JSON.stringify(u));break;case"sub":Ye.__statistics(f.L_QS_SUBSCRIBE_S,JSON.stringify(u));break;case"unsub":Ye.__statistics(f.L_QS_UNSUBSCRIBE_S,JSON.stringify(u))}}))}reportQualityRecvPubMsgData(e,t){const i=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{puid:t,time:Date.now(),dur:Date.now()-e});Ye.__statistics(f.L_QS_RECV_PUB_MSG_S,JSON.stringify(i))}setPubOrSubSuccessTime(e){this._pubOrSubSuccessTime=e}reportIceFirstConnectData(e){const t=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{time:this._pubOrSubSuccessTime,dur:Date.now()-this._pubOrSubSuccessTime}),i="pub"===e?f.L_QS_PUB_ICE_STATUS_S:f.L_QS_SUB_ICE_STATUS_S;Ye.__statistics(i,JSON.stringify(t))}setIceCandidatePair(e,t){this._iceCandidatePair[e]=t}recordQualityIceStatusData(e,t,i){const{status:r,time:n}=this._peerCStatus[e]||{};if(!n)return void(this._peerCStatus[e]={status:t,time:i});const{IP:o,port:s,networkType:a,remoteIP:c,remotePort:d}=this._iceCandidatePair[e],_=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{dur:i-n,time:i,pices:Cs[r],ices:Cs[t],rcdts:[{ip:`${c}:${d}`}],lcdts:[{ip:`${o}:${s}`,nttp:a}],cncdts:[]});Ye.__statistics(f.L_QS_ICE_STATUS_S,JSON.stringify(_)),this._peerCStatus[e]={status:t,time:i}}}const Ns="evt-leave";class As extends e{constructor(e,t,i,r,n,o,s,a,c,d=jn(),_=3e4){super(),this._context=e,this._runtime=t,this._roomId=i,this._service=n,this._initOptions=o,this._useMutilPeerC=c,this._clientSessionId=d,this.signalRetryTime=_,this._appListener=null,this._reportListener=null,this._onRecvPKMsg=null,this._reportMediaActionLogger=new Ls(this._roomId,this._clientSessionId,this._context.getCurrentId()),this._polarisReport=new Bo(this._context,this._runtime,this._roomId,this),this._peerCManager=new Fo(this._useMutilPeerC,this._roomId,this._reTryExchange.bind(this),this._context.getCurrentId(),this._polarisReport,!1,o),this._invoker=new $o(this._context,this._service,this._peerCManager,i,this._context.getCurrentId(),r,this._polarisReport,s,a),this._store=this._invoker.store,this._peerCManager.setStore(this._store),this._context.registerRTCSignalListener((e=>S(this,void 0,void 0,(function*(){var t,i,r,n,o,s;const{time:a,type:c,roomId:d}=this._context.decodeRtcNotify(e);if(this._invoker.isDestroyed())null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_RTCNTF_PULL_ROOM_STATUS_O,JSON.stringify({isDestroyed:!0,type:c,time:a,roomId:d}));else if(2===c){if(d!==this._roomId)return;const e=null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n?void 0:n.createTraceId();null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_RTCNTF_PULL_ROOM_STATUS_O,null,e),this._startPullRTCRoomStatus(d,e,a)}}))))}_pullRTCRoomStatus(e,t,i){return new Es(e,t,this._context,{onUserJoin:this._callAppListener.bind(this,"onUserJoin"),onUserLeave:this._callAppListener.bind(this,"onUserLeave"),onAudioMuteChange:this._onAudioMuteChange.bind(this),onVideoMuteChange:this._onVideoMuteChange.bind(this),onTrackPublish:this._onTrackPublish.bind(this),onTrackUnpublish:this._onTrackUnpublish.bind(this),onCDNEnableChange:this._callAppListener.bind(this,"onCDNEnableChange")},this._subhook.bind(this),this._dealUserAppListener.bind(this),i)}_startPullRTCRoomStatus(e,t,i){return S(this,void 0,void 0,(function*(){yield this._invoker.push(this._pullRTCRoomStatus(e,t,i))}))}__innerInit(e,t,i,r,n,o){return S(this,void 0,void 0,(function*(){const{code:s,data:a}=yield this._invoker.push(new Yo(this._roomId,e,this._context,t,i,r,n,o,this._reportMediaActionLogger));return s!==T.SUCCESS?{code:s}:(this._initWithRoomData(a.offlineKickTime),{code:s,data:a})}))}_initWithRoomData(e){var t;const i=this._invoker.store;this._pinger=new Ht(i,this._context,this._initOptions.pingGap,1e3*e),this._pinger.onFailed=this._kickoff.bind(this),this._pinger.onPingResult=this._handlePingResult.bind(this),this._pinger.start(this._startPullRTCRoomStatus.bind(this)),null===(t=this._polarisReport)||void 0===t||t.sendR1()}_handlePingResult(e){this._callAppListener("onPing",e)}setBitrate(e,i,r){var n,o,s,a;if(this._useMutilPeerC)return void(null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_ABSTRACT_ROOM_SETBITRATE_O,"`RCAbstractRoom.setBitrate` is disabled, use `RCLocalTrack.setBitrate` instead."));null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.warn(f.L_ABSTRACT_ROOM_SETBITRATE_O,"`RCAbstractRoom.setBitrate` will be deprecated, use `RCLocalTrack.setBitrate` instead."),h("max",e,(e=>t(e)&&e>Math.max(i||1,200)),!0),h("min",i,(i=>t(i)&&i>=1&&(!t(e)||i<e)),!0),h("start",r,(r=>t(r)&&r>i&&r<=e));this._peerCManager.getPCList().forEach((t=>{t.setBitrate(e,i,r)}))}_onTrackReady(e){var t,i,r,n;const o=e.streams[0].id,{track:s}=e.receiver,a=[o,"audio"===s.kind?Je.AUDIO_ONLY:Je.VIDEO_ONLY].join("_"),c=this._store.getRemoteTrack(a);c?(c.__innerSetMediaStreamTrack(s),null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onTrackReady",trackId:c.getTrackId()})),this._callAppListener("onTrackReady",c)):null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.warn(f.L_ABSTRACT_ROOM_ONTRACKREADY_O,`cannot found remote track ${s.id}`)}_callAppListener(e,...t){var i,r,n;const o=null===(i=this._appListener)||void 0===i?void 0:i[e];if(o)try{o(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,null==e?void 0:e.stack)}}_onTrackUnpublish(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onTrackUnpublish",trackIds:null==e?void 0:e.map((e=>e.getTrackId()))})),this._callAppListener("onTrackUnpublish",e)}__parseInnerMessage(e,t){var i,r,n,o,s,a,c,d,_,l;const{targetId:u,conversationType:h}=e;if(u!==this._roomId)return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(f.L_ABSTRACT_ROOM_RECEIVE_MESSAGE_O,JSON.stringify({status:C.FAILED,message:`roomId is different, msg roomId-> ${u}, this._roomId-> ${this._roomId} `}),t),!0;null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_RECEIVE_MESSAGE_O,`recv inner msg -> message: ${JSON.stringify(e)} | roomid: ${this._roomId}`,t);const{content:g}=e;switch(e.messageType){case Jt.KICK:this._kickoff(!0,g);break;case Jt.STATE:this._stateHandle(g,t);break;case Jt.MODIFY:case Jt.PUBLISH:case Jt.UNPUBLISH:case Jt.TOTAL_CONTENT_RESOURCE:this._resourceHandle(g,e.messageType,e.senderUserId,e.sentTime,t);break;case Jt.ROOM_NOTIFY:null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onRoomAttributeChange",messageType:e.messageType,messageContent:e.content})),this._callAppListener("onRoomAttributeChange",e.messageType,e.content);break;case Jt.USER_NOTIFY:null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.warn(f.L_OLD_DAILY_RECORD_O,`TODO: ${Jt.USER_NOTIFY}`);break;case Jt.PK_INVITE:case Jt.PK_CANCEL_INVITE:case Jt.PK_INVITE_TIMEOUT:case Jt.PK_INVITE_ANSWER:case Jt.PK_END:this._onRecvPKMsg&&this._onRecvPKMsg(e);break;case Jt.OTHER_ROOM_OFFLINE:break;default:null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onMessageReceive",messageType:e.messageType,messageContent:e.content,senderUserId:e.senderUserId,messageUId:e.messageUId})),this._callAppListener("onMessageReceive",e.messageType,g,e.senderUserId,e.messageUId)}return!0}_kickoff(e,t){var i,r,n,o;return S(this,void 0,void 0,(function*(){if(this._invoker.isDestroyed())return;let s,a;null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(f.L_ABSTRACT_ROOM_ONKICKOFF_O,`onKickOff -> byServer: ${e}, kickContent: ${JSON.stringify(t)}`),this.emit(Ns),this._leaveHandle(!e),e&&((null==t?void 0:t.users)||[]).forEach((e=>{e.userId===this._context.getCurrentId()&&(a=e.type,s=e.kickExtra,this._reportMediaActionLogger.reportQualityKickedData(a))})),null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onKickOff",byServer:e,kickType:a,kickExtra:s})),this._callAppListener("onKickOff",e,a,s)}))}_rtcpeerClosed(){var e,t;this.emit(Ns),this._leaveHandle(!0),null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onRTCPeerConnectionCloseByException"})),this._callAppListener("onRTCPeerConnectionCloseByException")}_resourceHandle(e,t,i,r,n){return S(this,void 0,void 0,(function*(){const{uris:o,ignore:s}=e;!s&&o&&this._invoker.push(new ds(e,t,i,this._subhook.bind(this),{onAudioMuteChange:this._onAudioMuteChange.bind(this),onVideoMuteChange:this._onVideoMuteChange.bind(this),onTrackPublish:this._onTrackPublish.bind(this),onTrackUnpublish:this._onTrackUnpublish.bind(this),onCDNEnableChange:this._callAppListener.bind(this,"onCDNEnableChange")},n,r,this._reportMediaActionLogger))}))}_onTrackPublish(e,t,i){var r,n;null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onTrackPublish",trackIds:null==e?void 0:e.map((e=>e.getTrackId()))})),this._callAppListener("onTrackPublish",e)}_stateHandle(e,t){return S(this,void 0,void 0,(function*(){const i=yield this._invoker.push(new cs(e,this._subhook.bind(this),t));this._dealUserAppListener(i)}))}_dealUserAppListener(e){var t,i,r,n,o,s,a,c,d;const{left:_,joined:l,upgrade:u,downgrade:h}=e;if(null===(t=this._appListener)||void 0===t?void 0:t.onSwitchRole)return null==u||u.forEach((e=>{var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onSwitchRole",userId:e,role:ho.ANCHOR})),this._callAppListener("onSwitchRole",e,ho.ANCHOR)})),null==h||h.forEach((e=>{var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onSwitchRole",userId:e,role:ho.AUDIENCE})),this._callAppListener("onSwitchRole",e,ho.AUDIENCE)})),l.length>0&&(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onUserJoin",joined:l})),this._callAppListener("onUserJoin",l)),void(_.length>0&&(null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onUserLeave",left:_})),this._callAppListener("onUserLeave",_)));const g=[...l,...u],v=[..._,...h];g.length>0&&(null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onUserJoin",allJoined:g})),this._callAppListener("onUserJoin",g)),v.length>0&&(v.length&&(null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onUserLeave",allLeft:v}))),this._callAppListener("onUserLeave",v))}getRoomId(){return this._roomId}getCrtUserId(){return this._context.getCurrentId()}__getPC(){return this._store.peerMgr.getPCList()}getRemoteUserIds(){return this._store.getRemoteUserIds()}getRemoteTracks(){const e=[];return this.getRemoteUserIds().forEach((t=>{e.push(...this.getRemoteTracksByUserId(t))})),e}getRemoteTracksByUserId(e){return this._store.getRemoteTracksByUserId(e)}getSessionId(){return this._store.getSessionId()}sendMessage(e,t){var i,r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_ABSTRACT_ROOM_SEND_MESSAGE_T,JSON.stringify({name:e,content:t}),l);const{code:u}=yield this._context.sendMessage(g.RTC_ROOM,this._roomId,{messageType:e,content:t,isStatusMessage:!0});return u!==n.SUCCESS?(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_ABSTRACT_ROOM_SEND_MESSAGE_R,JSON.stringify({status:C.FAILED,code:u}),l),{code:T.SIGNAL_ERROR}):(null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_ABSTRACT_ROOM_SEND_MESSAGE_R,JSON.stringify({status:C.SUCCESSED,name:e,content:t}),l),{code:T.SUCCESS})}))}setRoomAttribute(e,t,i,r=!1){var o,s,a,c,d,_,l,u;return S(this,void 0,void 0,(function*(){const h=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,key:e,value:t,message:i,isInner:r}),h);const g=yield this._context.setRTCData(this._roomId,e,t,r,Io.ROOM,i);return g!==n.SUCCESS?(null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_R,JSON.stringify({status:C.FAILED,code:g}),h),{code:T.SIGNAL_ERROR}):(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(f.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_R,JSON.stringify({status:C.SUCCESSED,roomId:this._roomId,key:e,value:t,message:i,isInner:r}),h),{code:T.SUCCESS})}))}deleteRoomAttributes(e,t,i=!1){var r,o,s,a,c,d,_,l;return S(this,void 0,void 0,(function*(){const u=null===(o=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===o?void 0:o.createTraceId();null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,keys:e,message:t,isInner:i}),u);const h=yield this._context.removeRTCData(this._roomId,e,i,Io.ROOM,t);return h!==n.SUCCESS?(null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:C.FAILED,code:h}),u),{code:T.SIGNAL_ERROR}):(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(f.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:C.SUCCESSED,roomId:this._roomId,keys:e,message:t,isInner:i}),u),{code:T.SUCCESS})}))}getRoomAttributes(e=[],t=!1){var i,r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,keys:e,isInner:t}),l);const{code:u,data:h}=yield this._context.getRTCData(this._roomId,e,t,Io.ROOM);return u!==n.SUCCESS?(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_R,`GetRoomAttributes Failed: ${u}`,l),{code:T.SIGNAL_ERROR}):(null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:C.SUCCESSED,data:h}),l),{code:T.SUCCESS,data:h})}))}_setUserAttributeValue(e,t,i){return this._context.setRTCData(this._roomId,e,t,!1,Io.PERSON,i)}_deleteUserAttributes(e,t){return this._context.removeRTCData(this._roomId,e,!1,Io.PERSON,t)}_getUserAttributes(e){return this._context.getRTCData(this._roomId,e,!1,Io.PERSON)}isDestroyed(){return this._invoker.isDestroyed()}__destroy(e){return this._leaveHandle(e)}_muteRemoteTracksBeforeQuit(){const e=Object.values(this._store.getRemoteTracks());e.length&&e.forEach((e=>e.mute()))}_leaveHandle(e){return S(this,void 0,void 0,(function*(){if(this._invoker.isDestroyed())return;Ss.destroy(),this._invoker.destroy(),this._muteRemoteTracksBeforeQuit(),e&&(yield this._context.quitRTCRoom(this._roomId)),this._store.isMainRoom&&(yield this._quitAllPKRoom()),this._pinger.stop();const t=[];Object.keys(this._peerCManager.getMutilPeerCData()).forEach((e=>{t.push(this._service.exit(this._getRTCReqestHeaders(e)))})),yield Promise.all(t),this._releasePCManager(),this._polarisReport=null}))}_releasePCManager(){const e=this._peerCManager.getPCList();null==e||e.forEach((e=>{e.off(rt.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(rt.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this)})),this._peerCManager.clear(),this._peerCManager=null}_onLocalTrackDestroied(e){e instanceof ot&&e.__isTiny()||this.unpublish([e])}_onLocalTrackMuted(e,t){return S(this,void 0,void 0,(function*(){this._invoker.push(new hs(e,t))}))}publish(e){return S(this,void 0,void 0,(function*(){return this._invoker.push(new ls(e,this._pubhook.bind(this),this.signalRetryTime,this._reportMediaActionLogger))}))}_getPushOtherRoomsParams(){return[]}_reTryExchange(e,t){return S(this,void 0,void 0,(function*(){this._invoker.push(new gs(e,t,(e=>({pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(e)}))))}))}_getRTCReqestHeaders(e){const t=this._useMutilPeerC?{"Peer-Connection-Id":e}:{};return Object.assign({"App-Key":this._context.getAppkey(),RoomId:this._roomId,Token:this._store.getToken(),RoomType:this._store.roomMode,UserId:this._context.getCurrentId(),"Client-Session-Id":this._clientSessionId},t)}unpublish(e){return S(this,void 0,void 0,(function*(){return this._invoker.push(new us(e,((e,t)=>({pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(t)})),this._reportMediaActionLogger))}))}_getResourceById(e){return this._store.getPublishedResourceByTrackId(e)}_isValidResourceId(e){var t;const{userId:i}=Ct(e);return!!(null===(t=this._store.getResourcesByUserId(i))||void 0===t?void 0:t.find((t=>ft(t)===e)))}_subhook(e){const{pc:t,pcName:i}=this._peerCManager.createPeerCList(e)[0];return t.on(xo.__INNER_EVENT_TRACK_READY__,this._onTrackReady,this),this._audioLevelReport&&t.on(xo.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport),t.once(xo.__INNER_ICE_CONNECTED__,(()=>{this._reportMediaActionLogger.reportIceFirstConnectData("sub")}),this),t.on(xo.__INNER_ICE_STATE_CHANGE__,(e=>{const{status:t,time:r,iceCandidatePair:n}=e;n&&this._reportMediaActionLogger.setIceCandidatePair(i,n),this._reportMediaActionLogger.recordQualityIceStatusData(i,t,r)})),t.__reportR3R4ToPolaris(),t.registerReportListener(this._reportListener),t.clearReTryExchangeTimer(),{pc:t,pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(i)}}_pubhook(e){return{plist:this._peerCManager.createPeerCList(e).map((e=>{const{pc:t,pcName:i}=e;return t.on(rt.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),t.on(rt.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),this._audioLevelReport&&t.on(xo.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport),t.once(xo.__INNER_ICE_CONNECTED__,(()=>{this._reportMediaActionLogger.reportIceFirstConnectData("pub")}),this),t.on(xo.__INNER_ICE_STATE_CHANGE__,(e=>{const{status:t,time:r,iceCandidatePair:n}=e;n&&this._reportMediaActionLogger.setIceCandidatePair(i,n),this._reportMediaActionLogger.recordQualityIceStatusData(i,t,r)})),t.registerReportListener(this._reportListener),t.__reportR3R4ToPolaris(),Object.assign(Object.assign({},e),{headers:this._getRTCReqestHeaders(i)})})),pushOtherRooms:this._getPushOtherRoomsParams()}}subscribe(e){return S(this,void 0,void 0,(function*(){return this._invoker.push(new _s(e,this._subhook.bind(this),void 0,void 0,this._reportMediaActionLogger))}))}addSubscribeTask(e){var t;const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();this._invoker.push(new Rs(e,this._subhook.bind(this),{onTaskCompleted:this._onTaskCompleted.bind(this)},vo.NORMAL,i))}unsubscribe(e){var t,i;return S(this,void 0,void 0,(function*(){const r=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();return null===(i=this._context.logger)||void 0===i||i.info(f.L_APP_CALL_UNSUBSCRIBE_O,void 0,r),this._invoker.push(new Qo(e,this._subhook.bind(this),r,this._reportMediaActionLogger))}))}addUnsubscribeTask(e){var t;const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();this._invoker.push(new ms(e,this._subhook.bind(this),{onTaskCompleted:this._onTaskCompleted.bind(this)},vo.NORMAL,i))}updateSubList(e){var t,i;return S(this,void 0,void 0,(function*(){return this._invoker.push(new zo(e,this._subhook.bind(this),!0,null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId(),this._reportMediaActionLogger))}))}addUpdateSubscribeListTask(e){var t;const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();this._invoker.push(new ps(e,this._subhook.bind(this),{onTaskCompleted:this._onTaskCompleted.bind(this)},vo.NORMAL,i))}_onTaskCompleted(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onTaskCompleted",code:e.code,subscribe:e.subscribe,unsubscribe:e.unsubscribe,failedList:e.failedList})),this._callAppListener("onTaskCompleted",e.code,e.subscribe,e.unsubscribe,e.failedList)}getLocalTrack(e){return this._store.getLocalTrack(e)}getLocalTracks(){return this._store.getLocalTracks()}getRemoteTrack(e){return this._store.getRemoteTrack(e)||null}get subscribedTracks(){return this._store.getSubscribedList().slice()}registerRoomEventListener(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_REGISTER_ROOM_EVENT_LISTENER_O,JSON.stringify({status:C.SUCCESSED,listener:e&&Object.keys(e)})),this._appListener=e,(null==e?void 0:e.onTrackTrouble)&&this._peerCManager&&(this._peerCManager.onTrackTrouble=null==e?void 0:e.onTrackTrouble.bind(this))}registerReportListener(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_REGISTER_REPORT_LISTENER_O,JSON.stringify({status:C.SUCCESSED,listener:e&&Object.keys(e)})),this._reportListener=e}onAudioLevelChange(e,t){var i,r;null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_ABSTRACT_ROOM_AUDIO_LEVEL_O,JSON.stringify({status:C.SUCCESSED,handler:null==e?void 0:e.name,gap:t})),this._audioLevelReport=new Vo(this),this._audioLevelReport.onAudioLevelChange(e)}__onReconnected(e){return S(this,void 0,void 0,(function*(){return this._invoker.push(new vs(this._subhook.bind(this),{onPeerClosed:this._rtcpeerClosed.bind(this),onAudioMuteChange:this._onAudioMuteChange.bind(this),onVideoMuteChange:this._onVideoMuteChange.bind(this),onUserJoin:this._callAppListener.bind(this,"onUserJoin"),onUserLeave:this._callAppListener.bind(this,"onUserLeave"),onTrackPublish:this._onTrackPublish.bind(this),onTrackUnpublish:this._onTrackUnpublish.bind(this),onCDNEnableChange:this._callAppListener.bind(this,"onCDNEnableChange")},(e=>({pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(e)})),this._pubhook.bind(this),this.signalRetryTime,this._pullRTCRoomStatus.bind(this),e))}))}_onAudioMuteChange(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onAudioMuteChange",trackId:e.getTrackId()})),this._callAppListener("onAudioMuteChange",e)}_onVideoMuteChange(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onVideoMuteChange",trackId:e.getTrackId()})),this._callAppListener("onVideoMuteChange",e)}_registerPKMsgListener(e){this._onRecvPKMsg=e}_quitAllPKRoom(){}getClientSessionId(){return this._clientSessionId}}class ys extends Jo{constructor(e,t){super(),this.data=e,this.cdnValues=t}get kind(){return go.MCUCONFIG_FLUSH}execute(e,t){var i,r,n,o;return S(this,void 0,void 0,(function*(){const t={"App-Key":e.context.getAppkey(),Token:e.getToken(),RoomId:e.roomId,UserId:e.context.getCurrentId(),SessionId:e.getSessionId()},{code:s,res:a}=yield e.service.setMcuConfig(t,this.data);if(s!==T.SUCCESS)return{code:s};a.pull_url&&e.setCDNUris(JSON.parse(a.pull_url));const c=this.cdnValues;return s===T.SUCCESS&&((null===(r=null===(i=c.output)||void 0===i?void 0:i.video.normal)||void 0===r?void 0:r.width)||(null===(o=null===(n=c.output)||void 0===n?void 0:n.video.normal)||void 0===o?void 0:o.fps))&&is(e),{code:s,res:a}}))}}var ks,Ds,bs,Us;!function(e){e[e.CROP=1]="CROP",e[e.WHOLE=2]="WHOLE"}(ks||(ks={})),function(e){e[e.CUSTOMIZE=1]="CUSTOMIZE",e[e.SUSPENSION=2]="SUSPENSION",e[e.ADAPTATION=3]="ADAPTATION"}(Ds||(Ds={})),function(e){e[e.CROP=1]="CROP",e[e.WHOLE=2]="WHOLE"}(bs||(bs={})),function(e){e[e.AUDIO_VIDEO_ALL=0]="AUDIO_VIDEO_ALL",e[e.AUDIO_VIDEO_NO=1]="AUDIO_VIDEO_NO",e[e.AUDIO_ALL_VIDEO_NO=2]="AUDIO_ALL_VIDEO_NO",e[e.AUDIO_NO_VIDEO_ALL=3]="AUDIO_NO_VIDEO_ALL",e[e.AUDIO_VIDEO_INPUT=4]="AUDIO_VIDEO_INPUT",e[e.AUDIO_ALL_VIDEO_INPUT=5]="AUDIO_ALL_VIDEO_INPUT",e[e.AUDIO_NO_VIDEO_INPUT=6]="AUDIO_NO_VIDEO_INPUT",e[e.AUDIO_INPUT_VIDEO_ALL=7]="AUDIO_INPUT_VIDEO_ALL",e[e.AUDIO_INPUT_VIDEO_NO=8]="AUDIO_INPUT_VIDEO_NO",e[e.ROOM_AUDIO_VIDEO_APPEND=9]="ROOM_AUDIO_VIDEO_APPEND",e[e.ROOM_AUDIO_VIDEO_NOT_APPEND=10]="ROOM_AUDIO_VIDEO_NOT_APPEND",e[e.ROOM_AUDIO_APPEND=11]="ROOM_AUDIO_APPEND",e[e.ROOM_AUDIO_NOT_APPEND=12]="ROOM_AUDIO_NOT_APPEND",e[e.ROOM_VIDEO_APPEND=13]="ROOM_VIDEO_APPEND",e[e.ROOM_VIDEO_NOT_APPEND=14]="ROOM_VIDEO_NOT_APPEND"}(Us||(Us={}));const Ps=()=>({version:2,mode:Ds.SUSPENSION});class Ms{constructor(e,t){this._invoker=e,this._isValidTrackId=t,this._values=Ps()}setHostVideoTrack(e){var t,i,r,n,o,s,a,c,d;if(!this._isValidTrackId(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,msg:`videoTrackId: ${e} is invalid`})),this;const{mediaType:_,tag:l,userId:u}=Ct(e);return _!==Je.VIDEO_ONLY?(null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,msg:`kind of ${e} is not video`})),this):(this._values.host_stream_id=Ot(u,l),null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:C.SUCCESSED,videoTrackId:e})),this)}setMixLayoutMode(e){var t,i,r,n,o,s;return[Ds.CUSTOMIZE,Ds.SUSPENSION,Ds.ADAPTATION].includes(e)?(this._values.mode=e,null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_MIX_LAYOUT_MODE_O,JSON.stringify({status:C.SUCCESSED,mode:e})),this):(null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_MIX_LAYOUT_MODE_O,JSON.stringify({status:C.SUCCESSED,msg:`mode: ${e} is invalid`})),this)}_addOutputValue(e,t,i="normal"){const r=this._values.output||(this._values.output={video:{normal:{width:640,height:480}}});if("cdn"===e)return void(r.cdn=t);if("audio"===e)return void(r.audio={bitrate:t});const{video:n}=r;if("normal"!==i&&"tiny"!==i)if("backgroundColor"!==i)if("exparams"!==i){if("backgroundPicture"===i){const e=n.backgroundPicture||(n.backgroundPicture={fillMode:ks.CROP,picture:[]});Object.assign(e,t)}}else n.exparams={renderMode:t};else n.backgroundColor=t;else{const e=n[i]||(n[i]={});Object.assign(e,t)}}setOutputVideoResolution(e){var t,i,r,n,o,s;if(!kt(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RESOLUTION_O,JSON.stringify({status:C.FAILED,msg:`params error -> resolution: ${e}`})),this;const{width:a,height:c}=yt(e);return this._addOutputValue("video",{width:a,height:c},"normal"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RESOLUTION_O,JSON.stringify({status:C.SUCCESSED,resolution:e})),this}setOutputVideoFPS(e){var t,i,r,n,o,s;if(!Dt(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_FPS_O,JSON.stringify({status:C.FAILED,msg:`params error -> fps: ${e}`})),this;const a=bt(e);return this._addOutputValue("video",{fps:a},"normal"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_FPS_O,JSON.stringify({status:C.SUCCESSED,fps:e})),this}setOutputVideoBitrate(e){var i,r,n,o,s,a;return!t(e)||e<=0?(null===(n=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_BITRATE_O,JSON.stringify({status:C.FAILED,msg:`params error -> bitrate: ${e}`})),this):(this._addOutputValue("video",{bitrate:e},"normal"),null===(a=null===(s=null===(o=this._invoker.store)||void 0===o?void 0:o.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_BITRATE_O,JSON.stringify({status:C.SUCCESSED,bitrate:e})),this)}setOutputTinyVideoResolution(e){var t,i,r,n,o,s;if(!kt(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_RESOLUTION_O,JSON.stringify({status:C.FAILED,msg:`params error -> resolution: ${e}`})),this;const{width:a,height:c}=yt(e);return this._addOutputValue("video",{width:a,height:c},"tiny"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_RESOLUTION_O,JSON.stringify({status:C.SUCCESSED,resolution:e})),this}setOutputTinyVideoFPS(e){var t,i,r,n,o,s;if(!Dt(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_FPS_O,JSON.stringify({status:C.FAILED,msg:`params error -> fps: ${e}`})),this;const a=bt(e);return this._addOutputValue("video",{fps:a},"tiny"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_FPS_O,JSON.stringify({status:C.SUCCESSED,fps:e})),this}setOutputTinyVideoBitrate(e){var i,r,n,o,s,a;return!t(e)||e<=0?(null===(n=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_BITRATE_O,JSON.stringify({status:C.FAILED,msg:`params error -> bitrate: ${e}`})),this):(this._addOutputValue("video",{bitrate:e},"tiny"),null===(a=null===(s=null===(o=this._invoker.store)||void 0===o?void 0:o.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_BITRATE_O,JSON.stringify({status:C.SUCCESSED,bitrate:e})),this)}setOutputVideoRenderMode(e){var t,i,r,n,o,s;return[bs.CROP,bs.WHOLE].includes(e)?(this._addOutputValue("video",e,"exparams"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RENDER_MODE_O,JSON.stringify({status:C.SUCCESSED,renderMode:e})),this):(null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RENDER_MODE_O,JSON.stringify({status:C.FAILED,msg:`params error -> renderMode: ${e}`})),this)}setOutputAudioBitrate(e){var i,r,n,o,s,a;return t(e)&&e>0?(this._addOutputValue("audio",e),null===(n=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_AUDIO_BITRATE_O,JSON.stringify({status:C.SUCCESSED,bitrate:e})),this):(null===(a=null===(s=null===(o=this._invoker.store)||void 0===o?void 0:o.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_AUDIO_BITRATE_O,JSON.stringify({status:C.FAILED,msg:`params error -> bitrate: ${e}`})),this)}setOutputBackgroundColor(e){var t,i,r,n,o,s;return/^0x[a-fA-F0-9]{6}$/.test(e)?(this._addOutputValue("video",e,"backgroundColor"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_COLOR_O,JSON.stringify({status:C.SUCCESSED,color:e})),this):(null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_COLOR_O,JSON.stringify({status:C.FAILED,msg:`params error -> color: ${e}`})),this)}addOutputBackgroundPicture(e,i,r,n,o){var s,a,c,d,_,l,u,h,g,p,R,m;if(!v(e))return null===(c=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:C.FAILED,msg:`params error -> uri: ${e}`})),this;if([i,r,n,o].some((e=>!t(e)||e<0||e>1)))return null===(l=null===(_=null===(d=this._invoker.store)||void 0===d?void 0:d.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:C.FAILED,msg:`params of (x, y, w, h) error -> x: ${i}, y: ${r}, w: ${n}, h: ${o}`})),this;const I=(null===(g=null===(h=null===(u=this._values.output)||void 0===u?void 0:u.video)||void 0===h?void 0:h.backgroundPicture)||void 0===g?void 0:g.picture)||[];return I.push({uri:e,w:n,h:o,x:i,y:r}),this._addOutputValue("video",{picture:I},"backgroundPicture"),null===(m=null===(R=null===(p=this._invoker.store)||void 0===p?void 0:p.context)||void 0===R?void 0:R.logger)||void 0===m||m.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:C.SUCCESSED,uri:e,x:i,y:r,w:n,h:o})),this}removeOutputBackgroundPicture(e){var t,i,r,n,o,s,a,c,d;if(!v(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_REMOVE_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:C.FAILED,msg:`params error -> uri: ${e}`})),this;let _=null===(s=null===(o=null===(n=this._values.output)||void 0===n?void 0:n.video)||void 0===o?void 0:o.backgroundPicture)||void 0===s?void 0:s.picture;return _&&(_=_.filter((t=>t.uri!==e)),this._addOutputValue("video",{pictures:_},"backgroundPicture")),null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_REMOVE_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:C.SUCCESSED,uri:e})),this}clearOutputBackgroundPicture(){var e,t,i;return this._addOutputValue("video",{pictures:[]},"backgroundPicture"),null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_CLEAR_OUTPUT_BACKGROUND_PICTURE_O),this}setOutputBackgroundPictureFillMode(e){var t,i,r,n,o,s;return[ks.CROP,ks.WHOLE].includes(e)?(this._addOutputValue("video",{fillMode:e},"backgroundPicture"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:C.SUCCESSED,fillMode:e})),this):(null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:C.FAILED,msg:`params error -> fillMode: ${e}`})),this)}addPublishStreamUrls(e){var t,i,r,n,o,a,c,d,_,l,u;const h=/^rtmp:\/\/.+/;if(!s(e)||0===e.length||e.some((e=>!h.test(e))))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:C.FAILED,msg:`params error -> urls: ${e.join(",")}`})),this;const g=(null===(o=null===(n=this._values.output)||void 0===n?void 0:n.cdn)||void 0===o?void 0:o.concat())||[];let v=!1;return e.forEach((e=>{g.some((t=>t.pushurl===e))||(v=!0,g.push({pushurl:e}))})),g.length>5?(null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:C.FAILED,msg:`params error -> publish stream urls no more than 5, length: ${e.length}`})),this):(v&&this._addOutputValue("cdn",g),null===(u=null===(l=null===(_=this._invoker.store)||void 0===_?void 0:_.context)||void 0===l?void 0:l.logger)||void 0===u||u.info(f.L_MCU_CONFIG_BUILDER_ADD_PUBLISH_STREAM_URLS_O,JSON.stringify({status:C.SUCCESSED,urls:e})),this)}removePublishStreamUrls(e){var t,i,r,n,o,a,c,d;const _=/^rtmp:\/\/.+/;if(!s(e)||0===e.length||e.some((e=>!_.test(e))))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_REMOVE_PUBLISH_STREAM_URLS_O,JSON.stringify({status:C.FAILED,msg:`params error -> urls: ${e.join(",")}`})),this;const l=(null===(o=null===(n=this._values.output)||void 0===n?void 0:n.cdn)||void 0===o?void 0:o.concat())||[];for(let t=l.length-1;t>=0;t-=1){const{pushurl:i}=l[t],r=e.indexOf(i);r>=0&&(e.splice(r,1),l.splice(t,1))}return this._addOutputValue("cdn",l),null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_REMOVE_PUBLISH_STREAM_URLS_O,JSON.stringify({status:C.SUCCESSED,urls:e})),this}clearPublishStreamUrls(){var e,t,i;return this._addOutputValue("cdn",[]),null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_CLEAR_PUBLISH_STREAM_URLS_O),this}addCustomizeLayoutVideo(e,i,r,n,o){var s,a,c,d,l,u,h,g,v,p,R,m,I,E,S,T,O,L;if(!_(e)||!this._isValidTrackId(e))return null===(c=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;if(!t(i)||!t(r))return null===(u=null===(l=null===(d=this._invoker.store)||void 0===d?void 0:d.context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`params x or y is error -> x: ${i}, y: ${r}`})),this;if([n,o].some((e=>!t(e)||e<0)))return null===(v=null===(g=null===(h=this._invoker.store)||void 0===h?void 0:h.context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`params width or height error -> width: ${n}, height: ${o}`})),this;const{userId:N,tag:A,mediaType:y}=Ct(e);if(y!==Je.VIDEO_ONLY)return null===(m=null===(R=null===(p=this._invoker.store)||void 0===p?void 0:p.context)||void 0===R?void 0:R.logger)||void 0===m||m.error(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`type of trackId: ${e} is not video`})),this;const k=Ot(N,A),D=this._values.input||(this._values.input={}),b=D.video||(D.video=[]);return b.some((e=>e.height===o&&e.width===n&&e.stream_id===k&&e.user_id===N&&e.x===i&&e.y===r))?(null===(S=null===(E=null===(I=this._invoker.store)||void 0===I?void 0:I.context)||void 0===E?void 0:E.logger)||void 0===S||S.warn(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:"Duplicate configuration item place ignored"})),this):(b.push({user_id:N,stream_id:k,x:i,y:r,width:n,height:o}),null===(L=null===(O=null===(T=this._invoker.store)||void 0===T?void 0:T.context)||void 0===O?void 0:O.logger)||void 0===L||L.info(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.SUCCESSED,trackId:e,x:i,y:r,width:n,height:o})),this)}removeCustomizeLayoutVideo(e){var t,i,r,n,o,s,a,c,d;if(!this._isValidTrackId(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;const{userId:_,tag:l,mediaType:u}=Ct(e);if(u!==Je.VIDEO_ONLY)return null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`type of trackId: ${e} is not video`})),this;const h=Ot(_,l),{input:g}=this._values;return(null==g?void 0:g.video)&&g.video.length>0&&(g.video=g.video.filter((e=>e.stream_id===h))),null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.SUCCESSED,trackId:e})),this}clearCustomizeLayoutVideo(){var e,t,i;const{input:r}=this._values;return null==r||delete r.video,null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_LAYOUT_VIDEO_O),this}setCustomizeInputAudio(e){var t,i,r,n,o,s;if(e.some((e=>this._isValidTrackId(e))))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.FAILED,msg:`trackIds contain invalid item -> trackIds: ${e.join(",")}`})),this;return(this._values.input||(this._values.input={})).audio=e.map((e=>{const{userId:t,tag:i}=Ct(e);return{stream_id:Ot(t,i),user_id:t}})),this._values.inputFilterMode=Us.AUDIO_INPUT_VIDEO_ALL,null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.SUCCESSED,trackIds:e})),this}addCustomizeInputAudio(e){var t,i,r,n,o,s,a,c,d;if(!this._isValidTrackId(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;const _=this._values.input||(this._values.input={}),l=_.audio||(_.audio=[]),{userId:u,tag:h}=Ct(e),g=Ot(u,h);return l.some((e=>e.stream_id===g&&e.user_id===u))?(null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.warn(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.FAILED,msg:`trackId: ${e} is exist`})),this):(l.push({user_id:u,stream_id:g}),this._values.inputFilterMode=Us.AUDIO_INPUT_VIDEO_ALL,null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.SUCCESSED,trackId:e})),this)}removeCustomizeInputAudio(e){var t,i,r,n,o,s,a,c,d;if(!this._isValidTrackId(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;const{input:_}=this._values;if(!(null==_?void 0:_.audio)||0===_.audio.length)return null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.FAILED,msg:`type of trackId: ${e} is not audio`})),this;const{userId:l,tag:u}=Ct(e),h=Ot(l,u);return _.audio=_.audio.filter((e=>l!==e.user_id||h!==e.stream_id)),null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.SUCCESSED,trackId:e})),this}clearCustomizeInputAudio(){var e,t,i;const{input:r}=this._values;return(null==r?void 0:r.audio)&&delete r.audio,this._values.inputFilterMode=Us.AUDIO_VIDEO_ALL,null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_INPUT_AUDIO_O),this}addPictureWaterMark(e,i,r,n,o,s){var a,c,d,_,l,u,h,g,p,R,m,I;if(!this._isValidTrackId(e))return null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;if(!v(i))return null===(u=null===(l=null===(_=this._invoker.store)||void 0===_?void 0:_.context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:C.FAILED,msg:`params error -> uri: ${i}`})),this;if([r,n,o,s].some((e=>!t(e)||e<0||e>1)))return null===(p=null===(g=null===(h=this._invoker.store)||void 0===h?void 0:h.context)||void 0===g?void 0:g.logger)||void 0===p||p.error(f.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:C.FAILED,msg:`some attrs of (x, y, w, h) is invalid -> x: ${r}, y: ${n}, w: ${o}, h: ${s}`})),this;const{userId:E,tag:S}=Ct(e),T=Ot(E,S),O=this._values.waterMark||(this._values.waterMark={enable:"on",singleScreen:[]}),{singleScreen:L}=O,N=L.filter((e=>e.streamId===T))[0];return N?N.picture.push({uri:i,w:o,h:s,x:r,y:n}):L.push({streamId:T,picture:[{uri:i,w:o,h:s,x:r,y:n}]}),this._values.waterMark.singleScreen=L,null===(I=null===(m=null===(R=this._invoker.store)||void 0===R?void 0:R.context)||void 0===m?void 0:m.logger)||void 0===I||I.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:C.SUCCESSED,trackId:e,uri:i,x:r,y:n,w:o,h:s,singleScreen:L})),this}clearPictureWaterMark(){var e,t,i;return(this._values.waterMark||(this._values.waterMark={enable:"on",singleScreen:[]})).singleScreen=[],null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_CLEAR_OUTPUT_BACKGROUND_PICTURE_O),this}removePictureWaterMark(e,t){var i,r,n,o,s,a;if(!_(e)||!this._isValidTrackId(e))return null===(n=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_MCU_CONFIG_BUILDER_REMOVE_SINGLE_WATER_MARK_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;const{userId:c,tag:d}=Ct(e),l=Ot(c,d),u=this._values.waterMark||(this._values.waterMark={enable:"on",singleScreen:[]}),{singleScreen:h}=u;return h.forEach((e=>{e.streamId===l&&(e.picture=e.picture.filter((e=>e.uri!==t)))})),null===(a=null===(s=null===(o=this._invoker.store)||void 0===o?void 0:o.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_MCU_CONFIG_BUILDER_REMOVE_SINGLE_WATER_MARK_O,JSON.stringify({status:C.SUCCESSED,trackId:e,uri:t})),this}reset(){var e,t,i;return this._values=Ps(),null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_RESET_O),this}flush(e=!0){return S(this,void 0,void 0,(function*(){const t=JSON.parse(JSON.stringify(this._values)),{code:i}=yield this._invoker.push(new ys(t,this._values));return e&&(this._values=Ps()),{code:i}}))}__innerGetValues(){return JSON.parse(JSON.stringify(this._values))}}var xs,ws,Bs;!function(e){e[e.VIDEO=0]="VIDEO",e[e.AUDIO=1]="AUDIO"}(xs||(xs={}));class Vs extends Jo{constructor(e,t,i,r){super(),this.roomId=e,this.hooks=t,this.roomPKHandler=i,this.traceId=r}_exchangeWithPushOtherRoom(e,t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){if(!e.getLocalTracks().length)return void(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.SUCCESSED,msg:"have not published resource"}),this.traceId));const _=Object.values(e.peerMgr.getMutilPeerCData()),l=Object.keys(e.peerMgr.getMutilPeerCData());for(let i=0;i<_.length;i++){const{pc:r,isPub:u}=_[i],h=u&&e.useMutilPeerC?[]:e.getSubscribedList(),g=yield Xo(h,!1,r,e),{pushOtherRooms:v,headers:p}=this.hooks(l[i]);g.pushOtherRooms=v;const R=yield new qo(p,g,this.traceId,!0).execute(e,t);if(R.code!==T.SUCCESS)return void(null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.FAILED,code:R.code,pushOtherRooms:v}),this.traceId));const{sdp:m,resultCode:I}=R.data;if(I!==T.SUCCESS)return void(null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.FAILED,code:I,pushOtherRooms:v}),this.traceId));null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.SUCCESSED,pushOtherRooms:v}),this.traceId),r.setRemoteAnswer(m.sdp)}}))}get kind(){return go.EXCHANGE_WITH_PUSH_OTHER_ROOM}execute(e,t){var i,r,n,o,s,a;return S(this,void 0,void 0,(function*(){const{roomId:c}=this;if(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_EXCHANGE_WITH_PUSHOTHERROOM_T,JSON.stringify({roomId:c})),!this.roomPKHandler)return void(null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.FAILED,msg:"_roomPKHandler not exist"}),this.traceId));this.roomPKHandler.getPKInfo(c)?yield this._exchangeWithPushOtherRoom(e,t):null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.FAILED,msg:"PKInfo not exist"}),this.traceId)}))}}class Fs extends Jo{constructor(e,t,i,r,n,o,s){super(),this.pkHandler=e,this.room=t,this._PKInfo=i,this.hooks=r,this._joinedPKRooms=n,this.isQuitPK=o,this.traceId=s}get kind(){return go.LEAVE_OTHER_ROOM}quitRoomPK(e,t,i){var r,o,s,a,c,d,_,l;return S(this,void 0,void 0,(function*(){if(null===(o=null===(r=null==t?void 0:t.context)||void 0===r?void 0:r.logger)||void 0===o||o.info(f.L_QUIT_PK_T,`roomId: ${e}`,i),!this._PKInfo[e])return void(null===(a=null===(s=null==t?void 0:t.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_QUIT_PK_R,`status: ${C.FAILED}, msg: pkinfo is empty`,i));const{inviterRoomId:u,inviteeRoomId:h,inviterUserId:g,inviteSessionId:v}=this._PKInfo[e],p={inviteeRoomId:h,inviterRoomId:u,userId:t.crtUserId},R={roomId:t.roomId,endRoomId:e,sessionId:v,content:JSON.stringify(p),keys:[`${u}|${g}`]},m=yield t.context.endRoomPK(R);return m!==n.SUCCESS?(null===(d=null===(c=null==t?void 0:t.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_QUIT_PK_R,`status: ${C.FAILED}, code: ${m}`,i),{code:T.SIGNAL_ERROR}):(null===(l=null===(_=null==t?void 0:t.context)||void 0===_?void 0:_.logger)||void 0===l||l.info(f.L_QUIT_PK_R,`status: ${C.SUCCESSED}`,i),delete this._PKInfo[e],{code:T.SUCCESS})}))}execute(e,t){var i,r,n,o;return S(this,void 0,void 0,(function*(){const{room:s,isQuitPK:a}=this,c=s.getRoomId();return null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_LIVING_ROOM_LEAVE_PK_ROOM_T,JSON.stringify({roomId:c,isQuitPK:a}),this.traceId),yield s.__destroy(!0),delete this._joinedPKRooms[c],yield new Vs(c,this.hooks,this.pkHandler,this.traceId).execute(e,t),a&&this.quitRoomPK(c,e,this.traceId),null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_LIVING_ROOM_LEAVE_PK_ROOM_R,JSON.stringify({status:C.SUCCESSED}),this.traceId),{code:T.SUCCESS}}))}}class Js{constructor(e,t,i,r,n,o,s,a,c,d,_){this._invoker=e,this._PKInfo=t,this._hooks=i,this._context=r,this._runtime=n,this._service=o,this._initOptions=s,this._mainLivingRoom=a,this._registerPKMsgListener=c,this._onJoinedPKRoom=d,this._clientSessionId=_,this._inviteTimeout=30,this._appListener=null,this._joinedPKRooms={},this._registerPKMsgListener(this._onRecvPKMsg.bind(this)),this._mainRoomId=this._mainLivingRoom.getRoomId()}_callAppListener(e,...t){var i,r,n;const o=null===(i=this._appListener)||void 0===i?void 0:i[e];if(o)try{o(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify(e))}}_onInvite(e){var t,i;const r=e.inviteInfo||{},{inviterRoomId:n,inviterUserId:o,extra:s}=r,a={inviterRoomId:n,inviterUserId:o,extra:s};this._PKInfo[n]=r,null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onRequestJoinOtherRoom",info:a})),this._callAppListener("onRequestJoinOtherRoom",a)}_onCancelInvite(e){var t,i;const{inviterRoomId:r,inviterUserId:n,extra:o}=e.inviteInfo||{},s={inviterRoomId:r,inviterUserId:n,extra:o};delete this._PKInfo[r],null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onCancelRequestOtherRoom",cancelInfo:s})),this._callAppListener("onCancelRequestOtherRoom",s)}_onInviteTimeout(e){}_onInviteAnswer(e){var t,i;const{answerCode:r,inviteContent:n}=e,{inviteSessionId:o,inviterUserId:s,inviterRoomId:a,inviteeUserId:c,inviterUserAutoMix:d,inviteeUserAutoMix:_,inviteeRoomId:l,extra:u}=n,h={agree:1===r,inviterRoomId:a,inviterUserId:s,inviteeRoomId:l,inviteeUserId:c,extra:u};this._PKInfo[l]=this._PKInfo[l]||{inviteSessionId:o,inviterRoomId:a,inviterUserId:s,inviterUserAutoMix:d,inviteeRoomId:l},this._PKInfo[l].inviteeUserAutoMix=_,null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onResponseJoinOtherRoom",answerInfo:h})),this._callAppListener("onResponseJoinOtherRoom",h)}createLeaveOtherRoomCommand(e,t,i){return new Fs(this,e,this._PKInfo,this._hooks,this._joinedPKRooms,t,i)}_onPKEnd(e){var t,i,r,n,o,s;return S(this,void 0,void 0,(function*(){const{inviteeRoomId:a,inviterRoomId:c,userId:d}=e.inviteInfo,_=c===this._mainRoomId?a:c,l={endRoomId:_,endUserId:d},u=this._joinedPKRooms[_],h=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_QUIT_PK_LEAVE_PK_ROOM_O,void 0,h),u&&(yield this._invoker.push(this.createLeaveOtherRoomCommand(u,!0,h))),delete this._PKInfo[_],null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onFinishOtherRoom",endInfo:l})),this._callAppListener("onFinishOtherRoom",l)}))}_onRecvPKMsg(e){const{targetId:t,content:i,messageType:r}=e;switch(r){case Jt.PK_INVITE:this._onInvite(i);break;case Jt.PK_CANCEL_INVITE:this._onCancelInvite(i);break;case Jt.PK_INVITE_TIMEOUT:this._onInviteTimeout(i);break;case Jt.PK_INVITE_ANSWER:this._onInviteAnswer(i);break;case Jt.PK_END:this._onPKEnd(i)}}registerRoomPKEventListener(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_LIVING_PK_HANDLER_REGISTER_ROOM_PK_EVENT_LISTENER_O,JSON.stringify({listener:e&&Object.keys(e)})),this._appListener=e}requestJoinOtherRoom(e,t,r){var o,s,a,c,d,l,u,h,g,v;return S(this,void 0,void 0,(function*(){const R=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();if(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_T,JSON.stringify({inviteeRoomId:e,inviteeUserId:t,options:r}),R),!i("inviteeRoomId",e,_,!0)||!i("inviteeUserId",t,_,!0))return null===(l=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===l||l.error(f.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> inviteeRoomId or inviteeUserId"}),R),{code:T.PARAMS_ERROR};const m=jn(),I=!p(null==r?void 0:r.autoMix)||(null==r?void 0:r.autoMix),E={inviteSessionId:m,inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviterUserAutoMix:I,inviteeRoomId:e,inviteeUserId:t,inviteeTimeoutTime:this._inviteTimeout,extra:(null==r?void 0:r.extra)||""},S={roomId:this._mainRoomId,invitedRoomId:e,invitedUserId:t,inviteTimeout:this._inviteTimeout,inviteInfo:JSON.stringify(E),inviteSessionId:m},O=yield this._context.requestRoomPK(S);return O!==n.SUCCESS?(null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(f.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:O}),R),{code:O}):(this._PKInfo[e]={inviteSessionId:m,inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviterUserAutoMix:I,inviteeRoomId:e},null===(v=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===v||v.info(f.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.SUCCESSED}),R),{code:T.SUCCESS})}))}cancelRequestJoinOtherRoom(e,t,r){var o,s,a,c,d,l,u,h,g,v,p,R;return S(this,void 0,void 0,(function*(){const m=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();if(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_T,JSON.stringify({inviteeRoomId:e,inviteeUserId:t,extra:r}),m),!i("inviteeRoomId",e,_,!0)||!i("inviteeUserId",t,_,!0))return null===(l=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===l||l.error(f.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> inviteeRoomId or inviteeUserId"}),m),{code:T.PARAMS_ERROR};if(!this._PKInfo[e])return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(f.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:`The request to connect with ${t} user in room ${e} is not initiated`}),m),{code:T.PARAMS_ERROR};const I={inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviteeRoomId:e,inviteeUserId:t,extra:r||""},E={roomId:this._mainRoomId,invitedRoomId:e,invitedUserId:t,inviteSessionId:this._PKInfo[e].inviteSessionId,inviteInfo:JSON.stringify(I)},S=yield this._context.cancelRoomPK(E);return S!==n.SUCCESS?(null===(v=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:S}),m),{code:S}):(null===(R=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===R||R.info(f.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.SUCCESSED}),m),delete this._PKInfo[e],{code:T.SUCCESS})}))}responseJoinOtherRoom(e,t,r,o){var s,a,c,d,l,u,h,g,v,m,I,E;return S(this,void 0,void 0,(function*(){const S=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_T,JSON.stringify({inviterRoomId:e,inviterUserId:t,agree:r,options:o}),S),!i("inviterRoomId",e,_,!0)||!i("inviterUserId",t,_,!0))return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> inviterRoomId or inviterUserId"}),S),{code:T.PARAMS_ERROR};if(!this._PKInfo[e])return null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.error(f.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:`User ${t} in room ${e} did not send a request for connection`}),S),{code:T.PARAMS_ERROR};const{inviteSessionId:O,inviterUserAutoMix:L}=this._PKInfo[e],N=!p(null==o?void 0:o.autoMix)||(null==o?void 0:o.autoMix),A={inviteSessionId:O,inviterRoomId:e,inviterUserId:t,inviterUserAutoMix:L,inviteeRoomId:this._mainRoomId,inviteeUserId:this._context.getCurrentId(),inviteeUserAutoMix:N},y=Object.assign(A,{inviterUserAutoMix:L}),k=r?Object.assign(A,{MultiRoomKey:`${e}|${this._mainRoomId}`,MultiRoomValue:JSON.stringify(y)}):A;!R(null==o?void 0:o.extra)&&Object.assign(k,{extra:o.extra});const D={agree:r,roomId:this._mainRoomId,inviteSessionId:O,inviteRoomId:e,inviteUserId:t,content:JSON.stringify(k),key:`${e}|${this._mainRoomId}`,value:JSON.stringify(A)},b=yield this._context.responseRoomPK(D);return b!==n.SUCCESS?(null===(m=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===m||m.error(f.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:b}),S),{code:b}):(null===(E=null===(I=this._context)||void 0===I?void 0:I.logger)||void 0===E||E.info(f.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.SUCCESSED}),S),this._PKInfo[e].inviteeUserAutoMix=N,{code:T.SUCCESS})}))}joinOtherRoom(e){var t,r,n,o,s,c,d,l,u,h,g,v,p,R;return S(this,void 0,void 0,(function*(){const m=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId();if(null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_T,JSON.stringify({roomId:e}),m),!i("roomId",e,_,!0))return null===(c=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===c||c.error(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> roomId"}),m),{code:T.PARAMS_ERROR};if(this._context.getConnectionStatus()!==a.CONNECTED)return null===(l=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===l||l.error(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.SIGNAL_DISCONNECTED,msg:"IM disconnected"}),m),{code:T.SIGNAL_DISCONNECTED};if(this._joinedPKRooms[e])return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.warn(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),m),{code:T.REPERT_JOIN_ROOM};const I=xs.VIDEO,E={extra:`{"roomId": "${this._mainRoomId}"}`},S=new Ks(this._context,this._runtime,e,this._service,this._initOptions,I,!1,!1,!1,this._clientSessionId),{code:O,data:L}=yield S.__innerInit(mo.LIVE,void 0,I,E);return O!==T.SUCCESS?(null===(v=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:O}),m),{code:O}):(this._joinedPKRooms[e]=S,yield this._onJoinedPKRoom(e,m),null===(R=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===R||R.info(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.SUCCESSED}),m),{room:S,code:T.SUCCESS,userIds:S.getRemoteUserIds(),tracks:S.getRemoteTracks()})}))}leaveOtherRoom(e,t){var i,r,n,o;return S(this,void 0,void 0,(function*(){const s=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_APP_CALL_LEAVE_PK_ROOM_O,void 0,s),this._invoker.push(this.createLeaveOtherRoomCommand(e,t,s))}))}getPKInfo(e){return this._PKInfo[e]}getAllPKInfo(){return this._PKInfo}getJoinedPKRooms(){return this._joinedPKRooms}}!function(e){e[e.OPEN=1]="OPEN",e[e.STOP=2]="STOP"}(ws||(ws={}));class Gs extends Jo{constructor(e,t){super(),this.cdnValues=e,this.enable=t}get kind(){return go.ENABLE_INNER_CDN}execute(e,t){var i,r,n,o,s,a,c,d,_,l,u,h,g,v;return S(this,void 0,void 0,(function*(){const{enable:R}=this;if(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_LIVING_ROOM_ENABLE_INNER_CDN_T,JSON.stringify({roomId:e.roomId,enable:R})),!e.isMainRoom)return null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.FAILED,code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM};if(!p(R))return null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> enable"})),{code:T.PARAMS_ERROR};e.setCDNEnabel(R);const m={version:2,output:{inCDNModel:R?ws.OPEN:ws.STOP}},{code:I}=yield new ys(m,this.cdnValues).execute(e,t);if(I!==T.SUCCESS)return null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.FAILED,code:I,msg:"signal error"})),{code:T.SIGNAL_ERROR};const E=e.getCDNUris();if(E&&E.broadcast!==To.SPREAD)return null===(l=null===(_=e.context)||void 0===_?void 0:_.logger)||void 0===l||l.info(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.SUCCESSED,enable:R})),{code:T.SUCCESS};const{code:S}=yield is(e);return S===T.SUCCESS?(null===(h=null===(u=e.context)||void 0===u?void 0:u.logger)||void 0===h||h.info(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.SUCCESSED,enable:R})),{code:T.SUCCESS}):(null===(v=null===(g=e.context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.FAILED,code:S})),{code:S})}))}}!function(e){e[e.AnchorToViewer=1]="AnchorToViewer",e[e.ViewerToAnchor=2]="ViewerToAnchor"}(Bs||(Bs={}));class Hs extends Jo{constructor(e,t){super(),this.livingType=e,this.traceId=t}get kind(){return go.RTC_IDENTITY_CHANGE}execute(e,t){var i;return S(this,void 0,void 0,(function*(){const{code:r,data:o}=yield e.context.rtcIdentityChange(e.roomId,Bs.ViewerToAnchor,this.livingType);if(r!==n.SUCCESS||!o)return{code:r};e.initWithRoomData(o,this.traceId);e.getResourcesByUserId(e.crtUserId).length>0&&t.push(new Wo);const s=null===(i=o.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===i?void 0:i.value;return s&&e.setCDNUris(JSON.parse(s)[0]),{code:r,data:o}}))}}class Ks extends As{constructor(e,t,i,r,n,o,s,a,c,d){super(e,t,i,mo.LIVE,r,n,s,a,c,d),this._livingType=o,this._mcuConfigBuilder=new Ms(this._invoker,this._isValidResourceId.bind(this))}_initRoomPKHandler(e){if(this._store.isMainRoom){const t=((e,t)=>{const i={};return t.forEach((t=>{const r=JSON.parse(t.value),{inviterRoomId:n,inviteeRoomId:o}=r;i[e===n?o:n]=JSON.parse(t.value)})),i})(this._roomId,e.roomInfo);this._roomPKHandler=new Js(this._invoker,t,(e=>({headers:this._getRTCReqestHeaders(e),pushOtherRooms:this._getPushOtherRoomsParams()})),this._context,this._runtime,this._service,this._initOptions,this,super._registerPKMsgListener.bind(this),this._onJoinedPKRoom.bind(this),this._clientSessionId)}}__innerInit(e,t,r,n,o,s){const a=Object.create(null,{__innerInit:{get:()=>super.__innerInit}});var c,d;return S(this,void 0,void 0,(function*(){if(!i("livingType",r,(e=>e===xs.AUDIO||e===xs.VIDEO)))return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> livingType"}),s),{code:T.PARAMS_ERROR};const{code:_,data:l}=yield a.__innerInit.call(this,e,t,r,n,o,s);return _===T.SUCCESS&&l&&this._initRoomPKHandler(l),{code:_,data:l}}))}__innerInitByIdentityChange(e){var t,i,r,o;return S(this,void 0,void 0,(function*(){const{code:s,data:a}=yield this._invoker.push(new Hs(this._livingType,e));return s===n.SUCCESS&&a?(this._initRoomPKHandler(a),this._initWithRoomData(a.offlineKickTime),null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:C.SUCCESSED,roomData:a}),e)):null===(o=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===o||o.error(f.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:C.FAILED,code:s}),e),s}))}publish(e){const t=Object.create(null,{publish:{get:()=>super.publish}});var i,r;return S(this,void 0,void 0,(function*(){return this._store.isMainRoom?t.publish.call(this,e):(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:C.FAILED,code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}))}unpublish(e){const t=Object.create(null,{unpublish:{get:()=>super.unpublish}});var i,r;return S(this,void 0,void 0,(function*(){return this._store.isMainRoom?t.unpublish.call(this,e):(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:C.FAILED,code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}))}_isValidResourceId(e){var t;const{userId:i}=Ct(e),r=!!(null===(t=this._store.getResourcesByUserId(i))||void 0===t?void 0:t.find((t=>ft(t)===e)));let n=!1;const{code:o,roomPKHandler:s}=this.getRoomPKHandler();if(o!==T.SUCCESS||!s)return r;const a=s.getJoinedPKRooms(),c=[];return Object.values(a).forEach((e=>{c.push(...e.getRemoteTracks())})),n=c.some((t=>e===t.getTrackId())),r||n}getLivingType(){return this._livingType}getMCUConfigBuilder(){var e,t;return this._store.isMainRoom?this._mcuConfigBuilder:(null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.error(f.L_LIVING_ROOM_GET_MCU_CONFIG_BUILDER_O,"the `getMCUConfigBuilder` is disabled in PK room"),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}enableInnerCDN(e){return S(this,void 0,void 0,(function*(){return this._invoker.push(new Gs(this._mcuConfigBuilder.__innerGetValues(),e))}))}_resourceHandle(e,t,i,r,n){const o=Object.create(null,{_resourceHandle:{get:()=>super._resourceHandle}});return S(this,void 0,void 0,(function*(){o._resourceHandle.call(this,e,t,i,r,n)}))}__getCDNEnable(){var e;return!!(null===(e=this._store.getCDNUris())||void 0===e?void 0:e.enableInnerCDN)}__getCDNPushMode(){var e;return null===(e=this._store.getCDNUris())||void 0===e?void 0:e.push_mode}_onJoinedPKRoom(e,t){return S(this,void 0,void 0,(function*(){this._invoker.push(new Vs(e,(e=>({pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(e)})),this._roomPKHandler,t))}))}_getPushOtherRoomsParams(){const e=[];if(!this.isMainRoom()||!this._roomPKHandler)return e;const t=this._roomPKHandler.getJoinedPKRooms();for(const i in t){const r=t[i].getSessionId(),n=this._roomPKHandler.getPKInfo(i);if(!n)continue;const{inviterUserAutoMix:o,inviteeUserAutoMix:s,inviterUserId:a}=n,c=this._context.getCurrentId()===a;e.push({roomId:i,sessionId:r,autoMix:c?!!o:!!s})}return e}getRoomPKHandler(){var e,t,i,r;return this._store.isMainRoom?(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_LIVING_ROOM_GET_ROOM_PK_HANDLER_O,JSON.stringify({status:C.SUCCESSED})),{code:T.SUCCESS,roomPKHandler:this._roomPKHandler}):(null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.error(f.L_LIVING_ROOM_GET_ROOM_PK_HANDLER_O,JSON.stringify({status:C.SUCCESSED,code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}_quitAllPKRoom(){var e,t;return S(this,void 0,void 0,(function*(){const i=this._roomPKHandler.getJoinedPKRooms();for(const e in i)this._roomPKHandler.leaveOtherRoom(i[e]);null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_LIVING_ROOM_QUIT_ALL_PK_ROOM_O,JSON.stringify({status:C.SUCCESSED,roomIds:Object.keys(i)}))}))}isMainRoom(){return this._store.isMainRoom}}class js extends As{constructor(e,t,i,r,n,o,s,a,c,d=mo.RTC,_=3e4){super(e,t,i,d,r,n,o,s,a,c,_)}}const $s=new class{constructor(){this.queue=[],this.locked=!1,this.taskCount=0}checkToStart(){return S(this,void 0,void 0,(function*(){if(0===this.queue.length||this.locked)return;this.locked=!0;const{resolve:e,task:t,reject:i}=this.queue.shift();let r;try{r=yield t(),e(r)}catch(e){i(e)}this.locked=!1,this.checkToStart()}))}push(e,t=""){const i=new Promise(((t,i)=>{this.queue.push({resolve:t,task:e,reject:i})}));return this.checkToStart(),i}},Ws=(e,t="")=>$s.push(e,t);class Ys{constructor(e,t,i,r){this._context=e,this._useMutilPeerC=r,this._rtcToken="",this._liveUrl="",this._subTracks=[],this._subscribedList=[],this._clientSessionId=jn(),this._livingType=null,this._mediaType=null,this._subTiny=!1,this._fromRetry=!1,this._appListener=null,this._crtUserId=this._context.getCurrentId(),this._service=new zn(t,e,i.mediaServer),this._peerCManager=new Fo(this._useMutilPeerC,this._crtUserId,this._reTryExchange.bind(this),this._crtUserId,void 0,!1,i,!0),this._store=new Ko(this._context,this._service,this._peerCManager,this._crtUserId,this._crtUserId),this._peerCManager.setStore(this._store)}_getReqHeaders(e){return S(this,void 0,void 0,(function*(){const t=this._crtUserId;if(!this._rtcToken){const{code:i,data:r}=yield this._context.getRTCToken(t,mo.LIVE,e);if(i!==n.SUCCESS)return{code:T.SIGNAL_ERROR};this._rtcToken=r.rtcToken}const i=this._useMutilPeerC?{"Peer-Connection-Id":this._pcName}:{};return{code:T.SUCCESS,headers:Object.assign({"App-Key":this._context.getAppkey(),UserId:this._crtUserId,RoomId:t,RoomType:mo.LIVE,Token:this._rtcToken,"Client-Session-Id":this._clientSessionId},i)}}))}_clearSubscribeInfo(){var e;this._liveUrl="",this._livingType=null,this._mediaType=null,this._subTiny=!1,this._subTracks.length=0,null===(e=this._pc)||void 0===e||e.destroy(),this._pc=null}_reTryExchange(){var e;return S(this,void 0,void 0,(function*(){this._fromRetry=!0;const{code:t}=yield this.subscribe(this._liveUrl,this._livingType,this._mediaType,this._subTiny);t===T.SUCCESS&&(null===(e=this._pc)||void 0===e||e.clearReTryExchangeTimer())}))}subscribe(e,t,i,r=!1){return S(this,void 0,void 0,(function*(){return Ws((()=>this.__subscribe(e,t,i,r)),"audience-client-sub")}))}__subscribe(e,t,i,r=!1){var n,o,s,a,c,d,_,u,h,g,v,p,R,m,I,E,O,L,N,A,y,k,D;return S(this,void 0,void 0,(function*(){null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_AUDIENCE_CLIENT_SUBSCRIBE_T,JSON.stringify({liveUrl:e,livingType:t,mediaType:i,subTiny:r}));const S=[];if(wt(this._context.getNaviInfo()))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"})),{code:T.PACKAGE_ENVIRONMENT_ERROR,tracks:S};if(!this._fromRetry&&(null===(c=this._pc)||void 0===c||c.clearReTryExchangeTimer()),this._fromRetry=!1,!l(e))return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:`params error -> liveUrl: ${e}`})),{code:T.PARAMS_ERROR,tracks:S};if(![xs.AUDIO,xs.VIDEO].includes(t))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(`livingType is invalid: ${t}`),null===(v=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:`params error -> livingType: ${t}`})),{code:T.PARAMS_ERROR,tracks:S};if(![Je.AUDIO_ONLY,Je.VIDEO_ONLY,Je.AUDIO_VIDEO].includes(i))return null===(R=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===R||R.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:`params error -> -> mediaType: ${i}`})),{code:T.PARAMS_ERROR,tracks:S};if(this._liveUrl&&this._liveUrl!==e)return null===(I=null===(m=this._context)||void 0===m?void 0:m.logger)||void 0===I||I.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.BROADCAST_SUB_LIST_NOT_EMPTY,msg:"repeat subscribe"})),{code:T.BROADCAST_SUB_LIST_NOT_EMPTY,tracks:S};if(!this._pc){const{pcName:e,pc:t}=this._peerCManager.createPeerCList(S)[0];this._pc=t,this._pcName=e,this._pc.on(xo.__INNER_EVENT_TRACK_READY__,this._onTrackReady,this),this._pc.registerReportListener(this._reportListener),this._pc.__reportR3R4ToPolaris()}this._liveUrl=e;const{code:b,headers:U}=yield this._getReqHeaders(t);if(b!==T.SUCCESS)return null===(O=null===(E=this._context)||void 0===E?void 0:E.logger)||void 0===O||O.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:b,msg:"getRTCToken failed"})),{code:b,tracks:S};const P=`rc_mcu_${Date.now()}`,M="RongCloudRTC";0===this._subTracks.length&&(this._subTracks.push(new gt(M,P),new vt(M,P)),this._pc.updateSubRemoteTracks(this._subTracks.slice()));const x={sdp:yield this._pc.createOffer(!0),liveUrl:e,mediaType:i,simulcast:r?Qn.TINY:Qn.NORMAL,switchstream:!1},w=yield this._service.broadcastSubscribe(U,x);if(w.code!==T.SUCCESS)return null===(N=null===(L=this._context)||void 0===L?void 0:L.logger)||void 0===N||N.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:w.code})),{code:w.code,tracks:S};const B=w.data;if(B.resultCode!==T.SUCCESS)return null===(y=null===(A=this._context)||void 0===A?void 0:A.logger)||void 0===y||y.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:B.resultCode,msg:B.message})),{code:B.resultCode,tracks:S};this._livingType=t,this._mediaType=i,this._subTiny=r;const{sdp:V,subscribedList:F}=B;this._subscribedList=F;const J=[];return F.forEach((e=>{const{mediaType:t}=e,i=this._subTracks[t];J.push(i),i.__innerSetRemoteMuted(!0)})),this._pc.setRemoteAnswer(V.sdp),J&&this._updateTrackIdSSRCMap(V.sdp,J),null===(D=null===(k=this._context)||void 0===k?void 0:k.logger)||void 0===D||D.info(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.SUCCESSED,liveUrl:e})),{code:T.SUCCESS,tracks:J}}))}_updateTrackIdSSRCMap(e,t){t.forEach((t=>{const i=t.getTrackId(),{mediaType:r}=Ct(i),{msid:n}=this._subscribedList.filter((e=>e.mediaType===r))[0],o=as(e,n,r);this._store.setTrackIdSSRCMap(Number(o),i)}))}unsubscribe(){return S(this,void 0,void 0,(function*(){return Ws((()=>this.__unsubscribe()),"audience-client-unsub")}))}__unsubscribe(){var e,t,i,r,n,o,s,a,c;return S(this,void 0,void 0,(function*(){if(null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_AUDIENCE_CLIENT_UNSUBSCRIBE_T,JSON.stringify({liveUrl:this._liveUrl})),null===(i=this._pc)||void 0===i||i.clearReTryExchangeTimer(),!this._rtcToken||!this._liveUrl)return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.warn(f.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:"",msg:"Address does not exist, without unsubscribe"})),{code:T.SUCCESS};const{headers:d}=yield this._getReqHeaders(),{code:_}=yield this._service.broadcastExit(d);return _!==T.SUCCESS?null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:_})):(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:C.SUCCESSED,liveUrl:this._liveUrl})),this._subscribedList=[]),this._clearSubscribeInfo(),{code:_}}))}registerReportListener(e){this._reportListener=e}registerTrackEventListener(e){this._appListener=e}_onTrackReady(e){var t,i,r,n,o,s;const{track:a}=e.receiver,c="audio"===a.kind?Je.AUDIO_ONLY:Je.VIDEO_ONLY,d=this._subTracks[c];d.__innerSetMediaStreamTrack(a);try{null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_AUDIENCE_CLIENT_CALL_ONTRACKREADY_O,`trackId: ${d.getTrackId()}`),null===(n=null===(r=this._appListener)||void 0===r?void 0:r.onTrackReady)||void 0===n||n.call(r,d)}catch(e){null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_AUDIENCE_CLIENT_CALL_ONTRACKREADY_O,JSON.stringify(e))}}}var qs,zs;!function(e){e.RTMP="rtmp",e.FLV="flv",e.HLS="hls"}(qs||(qs={})),function(e){e[e.NOT_HTTPS=0]="NOT_HTTPS",e[e.HTTPS=1]="HTTPS"}(zs||(zs={}));const Qs=Object.assign(Object.assign({},yt(Fe.W176_H144)),{frameRate:bt(Ve.FPS_15)});class Zs{constructor(e,t,i,r,n,o,s,a=jn()){this._context=e,this._runtime=t,this._initOptions=i,this._roomId=r,this._joinResData=n,this.livingType=o,this._useMutilPeerC=s,this._clientSessionId=a,this._roomAnchorList=[],this._roomRes={},this._roomAnchorRes={},this._remoteTracks={},this._appListener=null,this._pc=null,this._subscribedList=[],this._sessionId="",this._destroyed=!1,this._isPulling=!1,this._pullTime=0,this._actionStartTime=Date.now(),this._trackMediaMap={},this._reportListener=null,this._crtUserId=this._context.getCurrentId(),this._reportMediaActionLogger=new Ls(this._roomId,this._clientSessionId,this._crtUserId),this._service=new zn(this._runtime,this._context,this._initOptions.mediaServer,this._initOptions.timeout),this._polarisReport=new Bo(this._context,this._runtime,this._roomId,this,_o.Audience),this._polarisReport.sendR1(),this._peerCManager=new Fo(this._useMutilPeerC,this._roomId,this._reTryExchange.bind(this),this._crtUserId,this._polarisReport,!0,this._initOptions,!0),this._context.registerRTCSignalListener((e=>S(this,void 0,void 0,(function*(){const{time:t,type:i,roomId:r}=this._context.decodeRtcNotify(e);if(1===i)this._startPull(r,t)})))),this._store=new Ko(this._context,this._service,this._peerCManager,this._roomId,this._crtUserId,mo.LIVE,this._polarisReport),this._peerCManager.setStore(this._store),this._setInitData()}_startPull(e,t){var i,r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){if(this._isPulling)return;this._isPulling=!0;if(this._pullTime>t)return void(this._isPulling=!1);const l=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_T,`pullTime: ${this._pullTime}`,l);const{code:u,data:h}=yield this._context.pullRTCRoomEntry(e);if(u===n.SUCCESS){this._isPulling=!1,this._pullTime=h.syncTime||0;const t=(null==h?void 0:h.kvEntries)||[];null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R,`status: ${C.SUCCESSED}, kvEntries: ${JSON.stringify(t)}`,l),this.singalDataChange(t,e,l)}null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R,`status: ${C.FAILED}, code: ${u}`,l)}))}_setInitData(){const{sessionId:e,remoteUserIds:t,remoteRTCUris:i,remoteMUCUris:r,remoteTracks:n,CDNUris:o}=((e,t)=>{const i=t.filter((e=>"RC_RTC_SESSIONID"===e.key))[0],r=i?i.value:"",n=t.filter((e=>"RC_ANCHOR_LIST"===e.key)).map((e=>JSON.parse(e.value||"[]")))[0],o=t.filter((e=>e.key.includes("RC_RES_"))).map((e=>JSON.parse(e.value||"{}"))),s=o.length?JSON.parse(o[0].mcu_uris||"[]"):[],a=[];s.forEach((t=>{const{mediaType:i,tag:r}=t,n=i===Je.AUDIO_ONLY?new gt(r,"",e):new vt(r,"",e);a.push(n)}));const c=[],d=[];o.forEach((e=>{const t=JSON.parse(e.uris||"[]");c.push(...t),t.forEach((e=>{const{mediaType:t,tag:i,msid:r}=e,n=r.split("_")[0],o=t===Je.AUDIO_ONLY?new gt(i,n):new vt(i,n);d.push(o)}))}));const _=t.filter((e=>"RC_CDN"===e.key)).map((e=>{const t=JSON.parse(e.value||"[]");return JSON.parse(t.cdn_uris)[0]}))[0];return{sessionId:r,remoteUserIds:n||[],remoteRTCUris:c,remoteMUCUris:s,remoteRTCTracks:d,remoteMCUTracks:a,remoteTracks:[...d,...a],CDNUris:_||{}}})(this._roomId,this._joinResData.kvEntries);this._sessionId=e,this._roomAnchorList=t,n.forEach((e=>{this._remoteTracks[e.getTrackId()]=e})),this._CDNUris=o,i.forEach((e=>{const t=e.msid.split("_")[0];this._roomAnchorRes[t]?this._roomAnchorRes[t].push(e):this._roomAnchorRes[t]=[e];const{ssrc:i,resourceId:r}=JSON.parse(e.uri);this._store.setTrackIdSSRCMap(i,r)})),r.forEach((e=>{const{mediaType:t,tag:i}=e,r=[this._roomId,i,t].join("_");this._roomRes[r]=e;const{ssrc:n}=JSON.parse(e.uri);this._store.setTrackIdSSRCMap(n,r)})),i.forEach((e=>{const t=ft(e);this._roomRes[t]=e}))}_assertRoomDestroyed(){if(this._destroyed)return T.ROOM_HAS_BEEN_DESTROYED}singalDataChange(e,t,i){var r,n,o;if(t!==this._roomId)return void(null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_AUDIENCE_LIVING_ROOM_SINGAL_DATA_CHANGE_P,JSON.stringify({status:C.FAILED,msg:`roomId inconsistency -> params roomId:${t}, current roomId:${this._roomId}`}),i));const s=[],a=null===(o=e.filter((e=>"RC_CDN"===e.key))[0])||void 0===o?void 0:o.value;a&&this._diffCDNUris(JSON.parse(JSON.parse(a).cdn_uris)[0],i),e.forEach((e=>{const{key:t,value:r,timestamp:n,uid:o}=e;if(-1!==t.indexOf("RC_RES_")){const e=JSON.parse(r||"{}"),t=JSON.parse(e.mcu_uris||"[]"),n=JSON.parse(e.uris||"[]");return s.push(...t),void this._diffAnchorResource(n,o,i)}if("RC_ANCHOR_LIST"===t){const e=JSON.parse(r||"[]"),{joinUserIds:t,leftUserIds:n}=this._diffAnchorList(e);t.length>0&&this._handleNewJoinedAnchor(t,i),n.length>0&&this._handleLeftedAnchor(n,i)}})),this._diffRoomResource(s,i)}_diffAnchorList(e){const t=e.filter((e=>this._roomAnchorList.indexOf(e)<0));return{leftUserIds:this._roomAnchorList.filter((t=>e.indexOf(t)<0)),joinUserIds:t}}_handleNewJoinedAnchor(e,t){var i,r;this._roomAnchorList.push(...e),null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorJoin",list:e}),t),this._callAppListener("onAnchorJoin",e)}_handleLeftedAnchor(e,t){var i,r;return S(this,void 0,void 0,(function*(){this._roomAnchorList=this._roomAnchorList.filter((t=>!(e.indexOf(t)>-1)));const n=[];e.forEach((e=>{n.push(...this.getRemoteTracksByUserId(e)),delete this._roomAnchorRes[e]})),n.length&&(yield this.unsubscribe(n),n.forEach((e=>delete this._remoteTracks[e.getTrackId()]))),null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorLeave",list:e}),t),this._callAppListener("onAnchorLeave",e)}))}_diffRoomResource(e,t){var i,r;return S(this,void 0,void 0,(function*(){const n=[],o=[],s=[];e.forEach((e=>{const t=ft(e),{userId:i,tag:r,mediaType:o}=Ct(t),a=[this._roomId,r,o].join("_"),{ssrc:c}=JSON.parse(e.uri);if(this._store.setTrackIdSSRCMap(c,a),!this._remoteTracks[a]){const t=o===Je.AUDIO_ONLY?new gt(r,"",this._roomId):new vt(r,"",this._roomId);n.push(t),this._remoteTracks[a]=t,this._roomRes[t.getTrackId()]=e}s.push(a)})),Object.keys(this._remoteTracks).forEach((e=>{s.indexOf(e)<0&&this._remoteTracks[e].isMCUTrack()&&o.push(this._remoteTracks[e])})),n.length>0&&(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onTrackPublish",trackIds:n.map((e=>e.getTrackId()))}),t),this._callAppListener("onTrackPublish",n)),o.length>0&&this._onUserUnpublish(o,"onTrackUnpublish",t)}))}_diffAnchorResource(e,t,i){var r,n,o,s,a,c;return S(this,void 0,void 0,(function*(){const d=this._roomAnchorRes[t]||(this._roomAnchorRes[t]=[]),{publishedList:_,unpublishedList:l,modifiedList:u}=Nt(d,e);if(_.length){const e=d.map(ft),t=[],a=[];if(_.forEach((i=>{const r=ft(i),n=e.indexOf(r),{userId:o,tag:s,mediaType:c}=Ct(r);n>-1?d[n]=i:d.push(i);let _=this._remoteTracks[r];this._roomRes[r]=i,_?_.isSubscribed()&&t.push(_):(_=c===Je.AUDIO_ONLY?new gt(s,o):new vt(s,o),this._remoteTracks[r]=_,a.push(_)),_.__innerSetRemoteMuted(0===i.state)})),t.length){const e=t.map((e=>e.getTrackId())),{code:i}=yield Ws((()=>this._subscribeHandle(t,!0)));i!==T.SUCCESS&&(null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_RESUB_REPUB_RES_R,JSON.stringify({status:C.FAILED,trackIds:e,code:i})))}null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorTrackPublish",trackIds:a.map((e=>e.getTrackId()))}),i),this._callAppListener("onAnchorTrackPublish",a)}if(l.length){const e=l.map(ft);for(let t=d.length-1;t>=0;t-=1){const i=d[t];e.includes(ft(i))&&d.splice(t,1)}const t=l.map((e=>{const t=ft(e);return this._remoteTracks[t]}));yield this._onUserUnpublish(t,"onAnchorTrackUnpublish",i)}if(u.length){const e=d.map(ft);for(let t=0;t<u.length;t++){const r=u[t],n=ft(r),o=e.indexOf(n);d[o].state=r.state;const s=this._remoteTracks[n];s.__innerSetRemoteMuted(0===r.state);const _=s.isAudioTrack()?"onAudioMuteChange":"onVideoMuteChange";null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:_,trackId:s.getTrackId()}),i),this._callAppListener(_,s)}}}))}_onUserUnpublish(e,t,i){var r,n;return S(this,void 0,void 0,(function*(){yield this.unsubscribe(e),e.forEach((e=>{this._subscribedList=this._subscribedList.filter((t=>t.track.getTrackId()!==e.getTrackId())),delete this._roomRes[e.getTrackId()],e.__innerDestroy(),delete this._remoteTracks[e.getTrackId()]})),null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:t,trackIds:e.map((e=>e.getTrackId()))}),i),this._callAppListener(t,e)}))}_callAppListener(e,...t){var i,r,n;const o=null===(i=this._appListener)||void 0===i?void 0:i[e];if(o)try{o(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify(e))}}_reTryExchange(){return S(this,void 0,void 0,(function*(){Ws((()=>S(this,void 0,void 0,(function*(){var e;const{reqBody:t}=yield this._createSubscribeParams(this._subscribedList,{},!0),i=yield this._exchangeHandle(t);if(i.code!==T.SUCCESS)return{code:i.code};const{sdp:r,resultCode:n}=i.data;if(n!==T.SUCCESS)return{code:n};this._pc.clearReTryExchangeTimer();const o=this._subscribedList.filter((e=>e.track.isMCUTrack()));if(o.length>0){const t=o[0].track.getTrackId(),i=null===(e=this._roomRes[t])||void 0===e?void 0:e.msid,n=[this._roomId,"RongCloudRTC"].join("_");r.sdp=r.sdp.replace(new RegExp(i,"g"),n)}const s=yield this._pc.setRemoteAnswer(r.sdp);return s!==T.SUCCESS?{code:s}:void 0}))),"audience-retry-exchange")}))}_createSubscribeParams(e,t,i){return S(this,void 0,void 0,(function*(){const r=yield this._pc.createOffer(i),n={resolutionInfo:[]},o={min:0,max:0};Object.keys(t).forEach((e=>{const{mediaStream:i,tinyStream:s}=t[e];[i,s].forEach(((t,i)=>{var s;const a=1===i?[e,"tiny"].join("_"):e;r.sdp=null===(s=r.sdp)||void 0===s?void 0:s.replace(new RegExp(t.id,"g"),a);const c=t.getVideoTracks()[0];if(!c)return;const d=0===i,{width:_,height:l,frameRate:u}=d?St(c):Qs;n.resolutionInfo.push({trackId:c.id,simulcast:d?Qn.NORMAL:Qn.TINY,resolution:`${_}x${l}`});const h=Ke(_,l),g=$e(u);o.min+=h.minBitrate*g,o.max+=h.maxBitrate*g}))}));return{reqBody:{sdp:r,switchstream:!1,newVersionFlag:!0,subscribeList:e.map((e=>({simulcast:e.subTiny?Qn.TINY:Qn.NORMAL,resolution:"",uri:this._roomRes[e.track.getTrackId()].uri})))},dynamicBitrate:o,offer:r}}))}_subscribeHandle(e,t=!1,r=!1){var n,o,a,c,d,_,l,u,h,g,v;return S(this,void 0,void 0,(function*(){const p=Date.now(),R=r?fo.SUB:void 0,m=null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o?void 0:o.createTraceId();null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:e.map(Vt),forceReq:t}),m);if(this._assertRoomDestroyed())return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.ROOM_HAS_BEEN_DESTROYED,msg:"room destroyed"}),m),R&&this._reportMediaActionLogger.reportPubOrSubQualityData(R,p,e,T.ROOM_HAS_BEEN_DESTROYED),{code:T.ROOM_HAS_BEEN_DESTROYED};if(!i("tracks",e,(()=>s(e)&&e.length>0&&e.every((e=>e instanceof ht||e.track instanceof ht))),!0))return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),m),R&&this._reportMediaActionLogger.reportPubOrSubQualityData(R,p,e,T.PARAMS_ERROR),{code:T.PARAMS_ERROR};const{pc:I,pcName:E}=this._peerCManager.createPeerCList(e)[0];this._pc=I,this._pc.__reportR3R4ToPolaris(),this._pcName=E,this._pc.registerReportListener(this._reportListener),this._addPeerCEvent();const S=this._subscribedList.map((e=>Object.assign({},e))),O=e.map((e=>e instanceof ht?{track:e}:e));let L=!1;const N=[];return O.forEach((e=>{const t=e.track.getTrackId();N.push(t);const i=S.find((e=>e.track.getTrackId()===t));i&&i.subTiny===e.subTiny||(i?i.subTiny=e.subTiny:S.push(e),L=!0)})),L||t?(null===(v=this._polarisReport)||void 0===v||v.sendR2(Eo.SUBSCRIBE,So.BEGIN,N),this._updateSubListHandle(S,!0,m,p,R)):(null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.warn(f.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.SUCCESSED,msg:"repeat subscribe"}),m),{code:T.SUCCESS})}))}_addPeerCEvent(){this._pc.on(xo.__INNER_EVENT_TRACK_READY__,(e=>{var t,i,r,n;const o=e.streams[0].id,{track:s}=e.receiver,a=[o,"audio"===s.kind?Je.AUDIO_ONLY:Je.VIDEO_ONLY].join("_"),c=this._remoteTracks[a];c?(c.__innerSetMediaStreamTrack(s),null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onTrackReady",trackId:c.getTrackId()})),this._callAppListener("onTrackReady",c)):null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.warn(f.L_AUDIENCE_LIVING_ROOM_ONTRACKREADY_O,`cannot found RCRemoteTrack: ${s.id}`)})),this._audioLevelReport&&this._pc.on(xo.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport),this._pc.once(xo.__INNER_ICE_CONNECTED__,(()=>{this._reportMediaActionLogger.reportIceFirstConnectData("sub")}),this),this._pc.on(xo.__INNER_ICE_STATE_CHANGE__,(e=>{const{status:t,time:i,iceCandidatePair:r}=e;r&&this._reportMediaActionLogger.setIceCandidatePair(this._pcName,r),this._reportMediaActionLogger.recordQualityIceStatusData(this._pcName,t,i)}))}_getReqHeaders(){const e=this._crtUserId,t=this._useMutilPeerC?{"Peer-Connection-Id":this._pcName}:{};return Object.assign({"App-Key":this._context.getAppkey(),RoomId:e,Token:this._joinResData.token,RoomType:mo.LIVE,UserId:e,"Session-Id":this._sessionId,"Client-Session-Id":this._clientSessionId},t)}_exchangeHandle(e){return this._service.broadcastSubscribe(this._getReqHeaders(),e)}_updateSubListHandle(e,t=!1,i,r,n){var o,s,a,c,d,_,l,u,h,g,v,p;return S(this,void 0,void 0,(function*(){null===(o=this._context.logger)||void 0===o||o.info(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_T,JSON.stringify({trackIds:e.map(Vt),forceReq:t}),i);let R=e.map((e=>e instanceof ht?{track:e}:Object.assign({},e)));const m={};R=R.filter((e=>{const t=e.track.getTrackId();return!m[t]&&(m[t]=!0,!0)})).map((e=>Object.assign({},e)));const I=this._subscribedList.map((e=>Object.assign({},e)));if(!t){let e=!1;if(R.forEach((t=>{const i=I.findIndex((e=>e.track===t.track));if(-1===i)return void(e=!0);I.splice(i,1)[0].subTiny!==t.subTiny&&(e=!0)})),I.length&&(e=!0),!e)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:C.SUCCESSED,msg:"repeat subscribe"}),i),{code:T.SUCCESS}}this._pc.clearReTryExchangeTimer(),this._pc.updateSubRemoteTracks(R.map((e=>e.track)));const{reqBody:E}=yield this._createSubscribeParams(R,{},!1),S=yield this._exchangeHandle(E);if(I.length){const e=[];I.forEach((t=>{e.push(t.track.getTrackId())})),null===(c=this._pc.reportParser)||void 0===c||c.clearLatestPacketsRecv(e)}if(e.forEach((e=>{const t=e instanceof ht?e.getTrackId():e.track.getTrackId();this._trackMediaMap[t]=S.qualityMsList||[]})),S.code!==T.SUCCESS)return n&&this._reportMediaActionLogger.reportPubOrSubQualityData(n,r,e,S.code,this._trackMediaMap),null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:C.FAILED,code:S.code}),i),{code:S.code};const{sdp:O,resultCode:L,message:N,subscribedList:A}=S.data;if(L!==T.SUCCESS)return n&&this._reportMediaActionLogger.reportPubOrSubQualityData(n,r,e,L,this._trackMediaMap),null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:C.FAILED,code:L,msg:N}),i),{code:L};R.forEach((e=>{const{track:t}=e;if(t.isMCUTrack()){const e=this._roomRes[t.getTrackId()].msid,{tag:i,userId:r}=Ct(t.getTrackId()),n=[r,i].join("_");O.sdp=O.sdp.replace(new RegExp(e,"g"),n)}}));const y=yield this._pc.setRemoteAnswer(O.sdp);if(n&&this._reportMediaActionLogger.reportPubOrSubQualityData(n,r,e,y,this._trackMediaMap),y!==T.SUCCESS)return null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.error(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:C.FAILED,code:y,msg:"set remote answer error"}),i),{code:y};const k=null==A?void 0:A.map((e=>`${e.msid}_${e.mediaType}`)),D=R.filter((e=>{if(e.track.isMCUTrack()){const t=this._roomRes[e.track.getTrackId()],i=`${t.msid}_${t.mediaType}`;return k.includes(i)}return null==k?void 0:k.includes(e.track.getTrackId())})),b=null==D?void 0:D.map((e=>`${e.track.getTrackId()}`)),U=R.filter((e=>!(null==b?void 0:b.includes(e.track.getTrackId()))));for(const e in this._remoteTracks){const t=D.some((t=>t.track.getTrackId()===e));this._remoteTracks[e].__innerSetSubscribed(t)}return this._subscribedList.splice(0,this._subscribedList.length,...D),null===(p=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===p||p.info(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:C.SUCCESSED,subSuccessTrackIds:k,failedList:U}),i),U.length?{code:T.SUCCESS,failedList:U}:{code:T.SUCCESS}}))}_diffCDNUris(e,t){var i,r,n,o,s,a;return S(this,void 0,void 0,(function*(){if(this._CDNUris.url&&!e.url)return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onCDNInfoDisable"}),t),this._callAppListener("onCDNInfoDisable"),void(this._CDNUris=e);(!this._CDNUris||!this._CDNUris.url&&e.url)&&(null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onCDNInfoEnable",resolution:`W${e.w}_H${e.h}`,fps:`FPS_${e.fps}`}),t),this._callAppListener("onCDNInfoEnable",{resolution:`W${e.w}_H${e.h}`,fps:`FPS_${e.fps}`}));const c=this._CDNUris.w&&e.w&&this._CDNUris.w!==e.w,d=this._CDNUris.h&&e.h&&this._CDNUris.h!==e.h,_=this._CDNUris.fps&&e.fps&&this._CDNUris.fps!==e.fps;(c||d||_)&&(null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onCDNInfoChange",resolution:`W${e.w}_H${e.h}`,fps:`FPS_${e.fps}`}),t),this._callAppListener("onCDNInfoChange",{resolution:`W${e.w}_H${e.h}`,fps:`FPS_${e.fps}`})),this._CDNUris=e}))}_getCDNPlayUrl(e,t){var i,r;return S(this,void 0,void 0,(function*(){const{w:n,h:o,fps:s}=e,a=this._initOptions.pullInnerCDNProtocol||qs.FLV,c=this._initOptions.pullInnerCDNUseHttps===zs.NOT_HTTPS?zs.NOT_HTTPS:zs.HTTPS;if(!this._CDNUris.url)return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:C.FAILED,code:T.CDN_RESOURCE_IS_EMPTY,msg:"cdn_uris url is empty, the anchor need to open or push CDN"}),t),{code:T.CDN_RESOURCE_IS_EMPTY};const d={"App-Key":this._context.getAppkey(),Token:this._joinResData.token,RoomId:this.getRoomId(),UserId:this._crtUserId,SessionId:this.getSessionId()},_=[],{w:l=0,h:u=1}=this._CDNUris;l/u>1?(n&&_.push(`w=${n}`),o&&_.push(`h=${o}`)):(n&&_.push(`h=${n}`),o&&_.push(`w=${o}`)),s&&_.push(`fps=${s}`),_.push(`kind=${a}`),_.push(`is_https=${c}`);const h=_.join("&");let g=`${this._CDNUris.url}?`;h&&(g+=h);const{code:v,res:p}=yield this._service.getCDNResourceInfo(d,g,t);return v!==T.SUCCESS?{code:v}:{code:v,CDNPlayUrl:null==p?void 0:p.data.pull_url}}))}getCDNPlayUrl(e,t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){const _=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();if(null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_T,JSON.stringify({resolution:e,fps:t}),_),e&&!kt(e))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> resolution"}),_),{code:T.PARAMS_ERROR};if(t&&!Dt(t))return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> fps"}),_),{code:T.PARAMS_ERROR};const{width:l,height:u}=e?yt(e):{width:null,height:null},h=t?bt(t):null,g={};return l&&(g.w=l),u&&(g.h=u),h&&(g.fps=h),this._getCDNPlayUrl(g,_)}))}subscribe(e){return S(this,void 0,void 0,(function*(){return Ws((()=>this._subscribeHandle(e,!1,!0)),"audience-sub")}))}addSubscribeTask(e){return S(this,void 0,void 0,(function*(){return Ws((()=>this._subscribeHandle(e,!1,!0)),"audience-sub")}))}__unsubscribe(e){var t,r,n,o,a,c,d,_,l;return S(this,void 0,void 0,(function*(){const u=Date.now(),h=fo.UNSUB,g=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId();null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_T,JSON.stringify({trackIds:e.map((e=>e.getTrackId()))}),g);if(this._assertRoomDestroyed())return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.ROOM_HAS_BEEN_DESTROYED,msg:"room destroyed"}),g),{code:T.ROOM_HAS_BEEN_DESTROYED};if(!i("tracks",e,(()=>s(e)&&e.length>0&&e.every((e=>e instanceof ht))),!0))return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),g),{code:T.PARAMS_ERROR};const v=this._subscribedList.map((e=>Object.assign({},e))).filter((t=>!e.includes(t.track)));return null===(l=this._polarisReport)||void 0===l||l.sendR2(Eo.SUBSCRIBE,So.END,e.map((e=>e.getTrackId()))),this._updateSubListHandle(v,!1,g,u,h)}))}unsubscribe(e){return S(this,void 0,void 0,(function*(){return Ws((()=>this.__unsubscribe(e)),"audience-unsub")}))}addUnsubscribeTask(e){return S(this,void 0,void 0,(function*(){return Ws((()=>this.__unsubscribe(e)),"audience-unsub")}))}__destroy(e){var t;return S(this,void 0,void 0,(function*(){this._destroyed||(this._destroyed=!0,e&&(yield this._context.quitLivingRoomAsAudience(this._roomId)),yield this._service.broadcastExit(this._getReqHeaders()),null===(t=this._pc)||void 0===t||t.destroy(),Ss.destroy(),this._polarisReport=null,this._context.registerRTCSignalListener(void 0))}))}getRemoteTrack(e){return this._remoteTracks[e]}__getPC(){return this._peerCManager.getPCList()}getLocalTrack(e){return{}}__onReconnected(){var e,t,i,r,o,s,a,c;return S(this,void 0,void 0,(function*(){const d=null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t?void 0:t.createTraceId();null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_T,void 0,d);const{code:_}=yield this._context.joinLivingRoomAsAudience(this._roomId,mo.LIVE);_!==n.SUCCESS&&(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_R,`status: ${C.FAILED}`,d)),null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_R,`status: ${C.SUCCESSED}`,d)}))}registerRoomEventListener(e){this._appListener=e}onAudioLevelChange(e,t){var i,r;this._audioLevelReport=new Vo(this),this._audioLevelReport.onAudioLevelChange(e),null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({handler:null==e?void 0:e.name,gap:t}))}registerReportListener(e){this._reportListener=e}getRoomId(){return this._roomId}getCrtUserId(){return this._crtUserId}getSessionId(){return this._sessionId}getRemoteUserIds(){return this._roomAnchorList}getRemoteTracksByUserId(e){const t=[];for(const i in this._remoteTracks){const r=this._remoteTracks[i];r.getUserId()===e&&t.push(r)}return t}getRemoteTracks(){const e=[],t=[];for(const e in this._remoteTracks){if(2===t.length)break;const i=this._remoteTracks[e];i.isMCUTrack()&&t.push(i)}return this._roomAnchorList.forEach((t=>{e.push(...this.getRemoteTracksByUserId(t))})),[...t,...e]}getRemoteRTCTracks(){const e=[];for(const t in this._remoteTracks){const i=this._remoteTracks[t];i.isMCUTrack()||e.push(i)}return e}getRemoteMCUTracks(){const e=[];for(const t in this._remoteTracks){const i=this._remoteTracks[t];i.isMCUTrack()&&e.push(i)}return e}getCDNInfo(){return this._CDNUris.w?{resolution:`W${this._CDNUris.w}_H${this._CDNUris.h}`,fps:`FPS_${this._CDNUris.fps}`,CDNEnable:this._CDNUris.enableInnerCDN}:{CDNEnable:!1}}getClientSessionId(){return this._clientSessionId}}var Xs,ea;!function(e){e[e.AUTOMATIC=0]="AUTOMATIC",e[e.MANUAL=1]="MANUAL"}(Xs||(Xs={}));class ta{constructor(e){this._context=e,this._isElectron=/Electron/.test(navigator.userAgent)}_getMediaStream(e,t="getUserMedia"){return S(this,void 0,void 0,(function*(){try{const i=this.setConstraintsConfig(e),r=yield navigator.mediaDevices[t](i);return{code:T.SUCCESS,stream:r}}catch(e){if("Permission denied"===e.message)return{code:T.BROWSER_PERMISSION_DENIED};if("Permission denied by system"===e.message)return{code:T.SYSTEM_PERMISSION_DENIED}}return{code:"getUserMedia"===t?T.GET_USER_MEDIA_FAILED:T.GET_DISPLAY_MEDIA_FAILED}}))}_getMediaStreamErrorReason(e){let t="";return e===T.BROWSER_PERMISSION_DENIED&&(t="Permission denied"),e===T.SYSTEM_PERMISSION_DENIED&&(t="Permission denied by system"),t}setConstraintsConfig(e){var t,i;if((null==e?void 0:e.audio)&&!this._isElectron){"boolean"==typeof e.audio&&(e.audio={});const r=navigator.mediaDevices.getSupportedConstraints();r.noiseSuppression&&(e.audio.noiseSuppression=!!r.noiseSuppression),r.autoGainControl&&(e.audio.autoGainControl=!!r.autoGainControl),r.echoCancellation&&(e.audio.echoCancellation=!!r.echoCancellation),null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_SET_AUDIO_CONSTRAINTS_O,`browser supported -> ${JSON.stringify(r)}`)}return e}createMicrophoneAudioTrack(e="RongCloudRTC",t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS};const _=this._context.getCurrentId();if(!_)return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID};const{stream:l,code:u}=yield this._getMediaStream({audio:{deviceId:null==t?void 0:t.micphoneId,sampleRate:null==t?void 0:t.sampleRate,noiseSuppression:null==t?void 0:t.noiseSuppression,echoCancellation:null==t?void 0:t.echoCancellation,autoGainControl:null==t?void 0:t.autoGainControl}});if(u!==T.SUCCESS)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:u,msg:this._getMediaStreamErrorReason(u)})),{code:u};const h=l.getAudioTracks()[0],g=new dt(e,_,h);return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:C.SUCCESSED,trackId:g.getTrackId()})),{code:u,track:g}}))}createCameraVideoTrack(e="RongCloudRTC",t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS};const _=this._context.getCurrentId();if(!_)return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID};const l=kt(null==t?void 0:t.resolution)?t.resolution:Fe.W640_H480,{width:u,height:h}=yt(l),{stream:g,code:v}=yield this._getMediaStream({video:{deviceId:null==t?void 0:t.cameraId,frameRate:bt((null==t?void 0:t.frameRate)||Ve.FPS_15),width:u,height:h,facingMode:null==t?void 0:t.faceMode}});if(v!==T.SUCCESS)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:this._getMediaStreamErrorReason(v)})),{code:v};const p=g.getVideoTracks()[0],R=new _t(e,_,p);return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:C.SUCCESSED,trackId:R.getTrackId()})),{code:v,track:R}}))}createMicrophoneAndCameraTracks(e="RongCloudRTC",t){var i,r,n,o,s,a,c,d,_,l,u,h;return S(this,void 0,void 0,(function*(){const g=[];if(!mt(e))return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS,tracks:g};const v=this._context.getCurrentId();if(!v)return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID,tracks:g};const p=kt(null===(s=null==t?void 0:t.video)||void 0===s?void 0:s.resolution)?t.video.resolution:Fe.W640_H480,{width:R,height:m}=yt(p),I=null==t?void 0:t.audio,{stream:E,code:S}=yield this._getMediaStream({video:{deviceId:null===(a=null==t?void 0:t.video)||void 0===a?void 0:a.cameraId,frameRate:bt((null===(c=null==t?void 0:t.video)||void 0===c?void 0:c.frameRate)||Ve.FPS_15),width:R,height:m,facingMode:null===(d=null==t?void 0:t.video)||void 0===d?void 0:d.faceMode},audio:{deviceId:null==I?void 0:I.micphoneId,sampleRate:null==I?void 0:I.sampleRate,noiseSuppression:null==I?void 0:I.noiseSuppression,echoCancellation:null==I?void 0:I.echoCancellation,autoGainControl:null==I?void 0:I.autoGainControl}});return S!==T.SUCCESS?(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:C.FAILED,code:S,msg:this._getMediaStreamErrorReason(S)})),{code:S,tracks:g}):(E.getTracks().forEach((t=>{"video"===t.kind?g.push(new _t(e,v,t)):g.unshift(new dt(e,v,t))})),null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(f.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:C.SUCCESSED,trackIds:g.map((e=>e.getTrackId()))})),{code:S,tracks:g})}))}createScreenVideoTrack(e="screenshare",t){return S(this,void 0,void 0,(function*(){const i=yield this._createScreenTracks(e,!1,f.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_TRACK_O,t);return i.code===T.SUCCESS?{code:i.code,track:i.tracks[0]}:i}))}createScreenWithAudioTracks(e="screenshare",t){return S(this,void 0,void 0,(function*(){return this._createScreenTracks(e,!0,f.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_AND_AUDIO_TRACKS_O,t)}))}_createScreenTracks(e,t,i,r){var n,o,s,a,c,d,_,u,h,g,v,p,m,I,E,O;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(i,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS};const S=this._context.getCurrentId();if(!S)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(i,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID};if(!Mt())return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.BROWSER_NOT_SUPPORT,msg:"browser not support"})),{code:T.BROWSER_NOT_SUPPORT};const L=/macintosh|mac os x/i.test(navigator.userAgent);this._isElectron&&L&&t&&(null===(u=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===u||u.warn(i,JSON.stringify({status:C.INFO,code:T.MAC_IN_ELECTRON_NOT_SUPPORT_SCREEN_SHARE_WITH_AUDIO,msg:"mac in electron not support screen share with audio"})));const N=(!this._isElectron||!L)&&t;if(this._isElectron&&!R(null==r?void 0:r.chromeMediaSourceId)&&!l(null==r?void 0:r.chromeMediaSourceId))return null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.error(i,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> options.chromeMediaSourceId type is string"})),{code:T.PARAMS_ERROR};const A=kt(null==r?void 0:r.resolution)?r.resolution:Fe.W1280_H720,{width:y,height:k}=yt(A),D=this._isElectron?{mandatory:{chromeMediaSourceId:null==r?void 0:r.chromeMediaSourceId,chromeMediaSource:"desktop",minWidth:y,maxWidth:y,minHeight:k,maxHeight:k}}:{frameRate:bt((null==r?void 0:r.frameRate)||Ve.FPS_15),width:y,height:k};!(null==r?void 0:r.chromeMediaSourceId)&&this._isElectron&&(null===(v=D.mandatory)||void 0===v||delete v.chromeMediaSourceId);let b=null;N&&this._isElectron&&(null===(p=D.mandatory)||void 0===p||delete p.chromeMediaSourceId,b={mandatory:{chromeMediaSource:"desktop"}});const{stream:U,code:P}=yield this._getMediaStream({video:D,audio:b||N},this._isElectron?"getUserMedia":"getDisplayMedia");if(P!==T.SUCCESS)return null===(I=null===(m=this._context)||void 0===m?void 0:m.logger)||void 0===I||I.error(i,JSON.stringify({status:C.FAILED,code:P,msg:this._getMediaStreamErrorReason(P)})),{code:P};const M=U.getVideoTracks()[0],x=[new lt(e,S,M)];if(N){const t=U.getAudioTracks()[0];t&&x.push(new ut(e,S,t))}return null===(O=null===(E=this._context)||void 0===E?void 0:E.logger)||void 0===O||O.info(i,JSON.stringify({status:C.SUCCESSED,trackIds:x.map((e=>e.getTrackId()))})),{code:P,tracks:x}}))}createLocalAudioTrack(e,t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS};if(!t||"[object MediaStreamTrack]"!==t.toString()||"audio"!==t.kind)return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.CREATE_CUSTOM_TRACK_FAILED,msg:"params track is not MediaStreamTrack or kind is not audio"})),{code:T.CREATE_CUSTOM_TRACK_FAILED};const _=this._context.getCurrentId();if(!_)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID};const l=new nt(e,_,t);return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:C.SUCCESSED,trackId:l.getTrackId()})),{code:T.SUCCESS,track:l}}))}createLocalVideoTrack(e,t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS};if(!(t&&t instanceof MediaStreamTrack&&"video"===t.kind))return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.CREATE_CUSTOM_TRACK_FAILED,msg:"params track is not MediaStreamTrack or kind is not video"})),{code:T.CREATE_CUSTOM_TRACK_FAILED};const _=this._context.getCurrentId();if(!_)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID};const l=new ot(e,_,t);return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:C.SUCCESSED,trackId:l.getTrackId()})),{code:T.SUCCESS,track:l}}))}createLocalFileTracks(e,t,i){var r,n,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS,tracks:[]};if(!Pt())return null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.BROWSER_NOT_SUPPORT,msg:"browser not support"})),{code:T.BROWSER_NOT_SUPPORT,tracks:[]};const l=t instanceof File?URL.createObjectURL(t):t;if(!v(l)&&!/^blob:/.test(l))return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> file"})),{code:T.PARAMS_ERROR,tracks:[]};const u=this._context.getCurrentId();return u?new Promise((t=>{const r=document.createElement("video");(null==i?void 0:i.withoutAudio)&&(r.muted=!0),r.onloadedmetadata=()=>{var n,o,s,a;const c=[];let d;try{const e=r.mozCaptureStream?"mozCaptureStream":"captureStream";d=r[e]()}catch(e){null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.CREATE_FILE_TRACK_FAILED,msg:`captureSteam error -> ${JSON.stringify(e)}`})),t({code:T.CREATE_FILE_TRACK_FAILED,tracks:c})}const[_,l]=ta.getTracksWithOptions(d,i);_&&c.push(new ct(e,u,_,r)),l&&c.push(new at(e,u,l,r)),0===c.length&&(r.pause(),r.src=""),r.onerror=null,null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.SUCCESSED,trackIds:c.map((e=>e.getTrackId()))})),t({code:T.SUCCESS,tracks:c})},r.onerror=()=>{var e,i;null===(i=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===i||i.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.CREATE_FILE_TRACK_FAILED,msg:"Failed to create file stream, video onerror"})),t({code:T.CREATE_FILE_TRACK_FAILED,tracks:[]})},r.src=l,r.loop=!0,r.play()})):(null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID,tracks:[]})}))}createLocalTracks(e,t,i){var r,n,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=[];if(!mt(e))return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS,tracks:l};if(!(t instanceof MediaStream))return null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> stream"})),{code:T.PARAMS_ERROR,tracks:l};const u=this._context.getCurrentId();if(!u)return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID,tracks:l};const[h,g]=ta.getTracksWithOptions(t,i);return h&&l.push(new nt(e,u,h)),g&&l.push(new ot(e,u,g)),null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:C.SUCCESSED,trackIds:l.map((e=>e.getTrackId()))})),{code:T.SUCCESS,tracks:l}}))}static getTracksWithOptions(e,t){const i=[];return i[0]=(null==t?void 0:t.withoutAudio)?void 0:e.getAudioTracks()[0],i[1]=(null==t?void 0:t.withoutVideo)?void 0:e.getVideoTracks()[0],i}}class ia{constructor(){this.tasks=[]}static handler(){return this.retryHandler||(this.retryHandler=new ia),this.retryHandler}execute(){for(const e of this.tasks)e();this.destroy()}task(e){return S(this,void 0,void 0,(function*(){return new Promise((t=>{this.tasks.push((()=>{t(e())}))}))}))}destroy(){this.tasks=[]}}class ra extends ta{constructor(e,t,i){super(e),this._context=e,this._runtime=t,this._options=i,this._crtRoom=null,this._audience=null,this._crtAudienceLivingRoom=null,yo.setSdpSemantics(i.sdpSemantics||"plan-b"),this._service=new zn(this._runtime,this._context,this._options.mediaServer,this._options.timeout),this._context.registerConnectionStateChangeListener(this._onIMStatusChange.bind(this)),this._context.registerDisconnectListener(this._onIMDisconnect.bind(this)),this._context.registerDestroyListener(this._onIMUninit.bind(this)),this._context.registerMessageListener(this._handleMessage.bind(this)),this._context.getPluginContext().onnavidatachange=this.naviDataChange.bind(this)}_handleMessage(e){var t,i,r,n,o,s;if(e.conversationType!==g.RTC_ROOM)return!1;const a=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();if(this._crtRoom instanceof Ks){this._getJoinedPKRoomList().forEach((t=>{t.__parseInnerMessage(e,a)}))}return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_RTC_CLIENT_MESSAGE_O,JSON.stringify({status:C.SUCCESSED,message:e}),a),this._crtRoom?(this._crtRoom.__parseInnerMessage(e,a),!0):(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.warn(f.L_RTC_CLIENT_MESSAGE_O,JSON.stringify({status:C.FAILED,message:"the crtRoom is empty"}),a),!0)}naviDataChange(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_RTC_CLIENT_NAVI_CHANGE_O,`on navi change data => ${JSON.stringify(e)}`),this._service.detectorMediaSever(),Bo.logServer=null==e?void 0:e.logServer,Bo.dc=null==e?void 0:e.dc}_getJoinedPKRoomList(){const{code:e,roomPKHandler:t}=this._crtRoom.getRoomPKHandler();if(e===T.SUCCESS&&t){const e=t.getJoinedPKRooms()||{};return Object.values(e)}return[]}getCurrentId(){return this._context.getCurrentId()}joinRTCRoom(e,t,i,r,n=mo.RTC,o){var s,a,c,d,_,l;return S(this,void 0,void 0,(function*(){const u=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_RTC_CLIENT_JOIN_RTC_ROOM_T,JSON.stringify({roomId:e,joinType:t,outerUserDatas:i,useMutilPeerC:r,roomType:n}),u),this._crtRoom)return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(f.L_RTC_CLIENT_JOIN_RTC_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),u),{code:T.REPERT_JOIN_ROOM};const h=this._crtRoom=new js(this._context,this._runtime,e,this._service,this._options,!1,!1,r,jn(),o),{code:g}=yield h.__innerInit(n,t,void 0,void 0,i,u);return g!==T.SUCCESS?(this._crtRoom=null,{code:g}):(h.once(Ns,(()=>{this._crtRoom=null})),{code:g,room:h,userIds:h.getRemoteUserIds(),tracks:h.getRemoteTracks()})}))}joinCrossRTCRoom(e,t,i,r,n=mo.CROSS_MUTI){var o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();if(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_T,JSON.stringify({roomId:e,joinType:t,outerUserDatas:i,useMutilPeerC:r,roomType:n}),l),this._crtRoom)return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),l),{code:T.REPERT_JOIN_ROOM};const u=this._crtRoom=new js(this._context,this._runtime,e,this._service,this._options,!1,!1,r,jn(),n),{code:h}=yield u.__innerInit(n,t,void 0,void 0,i,l);return h!==T.SUCCESS?(this._crtRoom=null,{code:h}):(u.once(Ns,(()=>{this._crtRoom=null})),{code:h,room:u,userIds:u.getRemoteUserIds(),tracks:u.getRemoteTracks()})}))}joinLivingRoom(e,t,i,r,n){var o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();if(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_T,JSON.stringify({roomId:e,livingType:t,joinType:i,outerUserDatas:r,useMutilPeerC:n}),l),this._crtRoom)return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:`Join the room repeatedly -> roomId: ${e}`}),l),{code:T.REPERT_JOIN_ROOM};const u=this._crtRoom=new Ks(this._context,this._runtime,e,this._service,this._options,t,!1,!0,n),{code:h}=yield u.__innerInit(mo.LIVE,i,t,void 0,r,l);if(h!==T.SUCCESS)return this._crtRoom=null,{code:h};u.once(Ns,(()=>{this._crtRoom=null}));const g={code:h,room:u,userIds:u.getRemoteUserIds(),tracks:u.getRemoteTracks()};return u.__getCDNPushMode()===Xs.MANUAL&&Object.assign(g,{CDNEnable:u.__getCDNEnable()}),g}))}getAudienceClient(e){var t,i;return this._audience||(this._audience=new Ys(this._context,this._runtime,this._options,e)),null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_RTC_CLIENT_GET_AUDIENCE_CLIENT_O,JSON.stringify({useMutilPeerC:e})),this._audience}_onIMStatusChange(e){var t,i;if(null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_RTC_CLIENT_IM_CONNECTION_STATE_S,JSON.stringify({status:e})),e===a.CONNECTED){if(this._service.detectorMediaSever(),this._crtRoom instanceof Ks){this._getJoinedPKRoomList().forEach((e=>{e.__onReconnected()}))}this._crtRoom&&this._crtRoom.__onReconnected().then((e=>{if(e&&e.data&&e.data.sessionId){ia.handler().execute()}}))}}_onIMDisconnect(){var e,t;null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_RTC_CLIENT_IM_DISCONNECT_S,JSON.stringify({msg:"TODO -> on IM disconnect"}))}_onIMUninit(){var e,t,i;null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_RTC_CLIENT_DESTROY_S,JSON.stringify({msg:"TODO -> on IM client ondestroy"})),null===(i=this._crtRoom)||void 0===i||i.__destroy(!0)}leaveRoom(e){var t,i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){const _=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_RTC_CLIENT_LEAVE_ROOM_T,JSON.stringify({roomId:e.getRoomId()}),_),this._crtRoom?(yield this._crtRoom.__destroy(!0),this._service.detectorMediaSever(),null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_RTC_CLIENT_LEAVE_ROOM_R,JSON.stringify({status:C.SUCCESSED,roomId:null===(d=this._crtRoom)||void 0===d?void 0:d.getRoomId()}),_),this._crtRoom=null,{code:T.SUCCESS}):(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.warn(f.L_RTC_CLIENT_LEAVE_ROOM_R,JSON.stringify({status:C.FAILED,msg:"Room does not exist, without leave"}),_),{code:T.SUCCESS})}))}joinLivingRoomAsAudience(e,t,r){var o,s,a,c,d,l,u,h,g,v,p,R,m,I,E,O;return S(this,void 0,void 0,(function*(){const S=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();if(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_T,JSON.stringify({roomId:e,livingType:t,useMutilPeerC:r}),S),this._service.detectorMediaSever(),wt(this._context.getNaviInfo()))return null===(l=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===l||l.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:T.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"}),S),{code:T.PACKAGE_ENVIRONMENT_ERROR};if(!i("roomId",e,_,!0)||!i("livingType",t,(e=>e===xs.AUDIO||e===xs.VIDEO)))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> roomId or livingType"}),S),{code:T.PARAMS_ERROR};if(this._crtAudienceLivingRoom)return null===(v=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),S),{code:T.REPERT_JOIN_ROOM};if(!this._service.getNaviMS().length)return null===(R=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===R||R.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:T.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"No audio / video server address available"}),S),{code:T.NOT_OPEN_VIDEO_AUDIO_SERVER};const{code:L,data:N}=yield this._context.joinLivingRoomAsAudience(e,mo.LIVE,t);if(L!==n.SUCCESS)return null===(I=null===(m=this._context)||void 0===m?void 0:m.logger)||void 0===I||I.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:L,msg:"signal error -> audience join room"}),S),{code:T.SIGNAL_AUDIENCE_JOIN_ROOM_FAILED};const A=jn(),y=new Zs(this._context,this._runtime,this._options,e,N,t,r,A);return this._crtAudienceLivingRoom=y,null===(O=null===(E=this._context)||void 0===E?void 0:E.logger)||void 0===O||O.info(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.SUCCESSED,roomData:N}),S),{room:y,code:T.SUCCESS,userIds:y.getRemoteUserIds(),RTCTracks:y.getRemoteRTCTracks(),MCUTracks:y.getRemoteMCUTracks(),CDNUris:y.getCDNInfo()}}))}leaveLivingRoomAsAudience(e){var t,i,r,n,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_T,JSON.stringify({roomId:e.getRoomId(),userId:this._context.getCurrentId()}),l),this._crtAudienceLivingRoom?this._crtAudienceLivingRoom!==e?(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> room"}),l),{code:T.PARAMS_ERROR}):(yield this._crtAudienceLivingRoom.__destroy(!0),this._crtAudienceLivingRoom=null,null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.SUCCESSED}),l),{code:T.SUCCESS}):(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.warn(f.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,msg:"Room does not exist, without leave"}),l),{code:T.SUCCESS})}))}upgradeToAnchorRoom(e){var t,r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId();if(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_T,void 0,l),!i("room",e,(()=>e instanceof Zs),!0))return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> room"}),l),{code:T.PARAMS_ERROR};const u=e.getRoomId();if(this._crtRoom)return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly",roomId:u}),l),{code:T.REPERT_JOIN_ROOM};const h=this._crtRoom=new Ks(this._context,this._runtime,u,this._service,this._options,e.livingType,!0,!0,!1,e.getClientSessionId());if((yield h.__innerInitByIdentityChange(l))!==n.SUCCESS)return this._crtRoom=null,{code:T.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED};h.once(Ns,(()=>{this._crtRoom=null})),yield this._crtAudienceLivingRoom.__destroy(!1),this._crtAudienceLivingRoom=null;const g={room:h,code:T.SUCCESS,userIds:h.getRemoteUserIds(),tracks:h.getRemoteTracks()};return h.__getCDNPushMode()===Xs.MANUAL&&Object.assign(g,{CDNEnable:h.__getCDNEnable()}),g}))}downgradeToAudienceRoom(e){var t,r,o,s,a,c,d,_,l,u,h,g,v,p;return S(this,void 0,void 0,(function*(){const R=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId();if(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_T,JSON.stringify({roomId:e._roomId,userId:this._context.getCurrentId()}),R),!e.isMainRoom())return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:C.FAILED,code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"the `downgradeToAudienceRoom` is disabled in PK room"}),R),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM};if(!i("room",e,(()=>e instanceof Ks),!0))return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> room"}),R),{code:T.PARAMS_ERROR};if(this._crtAudienceLivingRoom)return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),R),{code:T.REPERT_JOIN_ROOM};const{code:m,data:I}=yield this._context.rtcIdentityChange(e._roomId,Bs.AnchorToViewer,e.getLivingType());if(m!==n.SUCCESS)return null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.error(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:C.FAILED,code:T.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED}),R),{code:T.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED};null===(p=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===p||p.info(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:C.SUCCESSED,roomData:I}),R);const E=e.getClientSessionId(),S=new Zs(this._context,this._runtime,this._options,e._roomId,I,e.getLivingType(),!1,E);return this._crtAudienceLivingRoom=S,this._crtRoom.__destroy(!1),this._crtRoom=null,{room:S,code:T.SUCCESS,userIds:S.getRemoteUserIds(),RTCTracks:S.getRemoteRTCTracks(),MCUTracks:S.getRemoteMCUTracks(),CDNUris:S.getCDNInfo()}}))}getJoinedRoomInfo(){var e,t,i,r,o,s,a,c;return S(this,void 0,void 0,(function*(){const d=null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t?void 0:t.createTraceId(),_=this._context.getCurrentId();null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_T,JSON.stringify({userId:_}),d);const{code:l,data:u}=yield this._context.getRTCJoinedUserInfo(_);return l!==n.SUCCESS?(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_R,JSON.stringify({status:C.FAILED,code:l}),d),{code:l}):(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_R,JSON.stringify({status:C.SUCCESSED,roomInfo:u}),d),{code:T.SUCCESS,data:u})}))}reportSDKInfo(){this._context.reportSDKInfo({"plugin-rtc":"5.6.8"})}}!function(e){e[e.KICK=0]="KICK",e[e.REFUSE=1]="REFUSE",e[e.COEXIST=2]="COEXIST"}(ea||(ea={}));const na="rtcRJoin_data",oa="rtcRExit",sa="rtcRInfo",aa="rtcUData",ca="rtcUDel",da="rtcSetData",_a="userSetData",la="rtcQryData",ua="rtcDelData",ha="rtcToken",ga="rtcUserState",va="rtcUList",pa="viewerJoinR",Ra="viewerExitR",ma="rtcPullKv",Ia="rtcIdentityChange",Ea="rtcInvite",Sa="rtcCancelInvite",Ta="rtcInviteAnswer",fa="rtcEndInvite",Ca="rtcQueryJoined",Oa="rtcPullRoomStatus",La="reportsdk",Na="rtcPing";var Aa;!function(e){e.RtcInput="RtcInput",e.RtcOutput="RtcOutput",e.RtcUserListOutput="RtcUserListOutput",e.SetUserStatusInput="SetUserStatusInput",e.RtcSetDataInput="RtcSetDataInput",e.RtcUserSetDataInput="RtcUserSetDataInput",e.RtcDataInput="RtcDataInput",e.RtcSetOutDataInput="RtcSetOutDataInput",e.MCFollowInput="MCFollowInput",e.RtcTokenOutput="RtcTokenOutput",e.RtcQryOutput="RtcQryOutput",e.RtcQryUserOutDataInput="RtcQryUserOutDataInput",e.RtcUserOutDataOutput="RtcUserOutDataOutput",e.RtcQueryListInput="RtcQueryListInput",e.RtcRoomInfoOutput="RtcRoomInfoOutput",e.RtcValueInfo="RtcValueInfo",e.RtcKeyDeleteInput="RtcKeyDeleteInput",e.RtcNotifyMsg="RtcNotifyMsg",e.RtcPullKV="RtcPullKV",e.RtcKVOutput="RtcKVOutput",e.RtcQueryUserJoinedInput="RtcQueryUserJoinedInput",e.RtcQueryUserJoinedOutput="RtcQueryUserJoinedOutput",e.RtcViewerJoinedOutput="RtcViewerJoinedOutput",e.RtcInviteInput="RtcInviteInput",e.RtcCancelInviteInput="RtcCancelInviteInput",e.RtcInviteAnswerInput="RtcInviteAnswerInput",e.RtcEndInviteInput="RtcEndInviteInput",e.RtcRoomStatusInput="RtcRoomStatusInput",e.RtcRoomStatusOutput="RtcRoomStatusOutput",e.RtcReportSDKInput="RtcReportSDKInput",e.RtcPBPolaris="RCRTCPBPolaris",e.RtcPBR1Info="RCRTCPBR1Info",e.RtcPBR2Info="RCRTCPBR2Info",e.RtcPBR3Info="RCRTCPBR3Info",e.RtcPBR4Info="RCRTCPBR4Info",e.RtcPBStatusInfo="RCRTCPBStatusInfo",e.RtcPBStreamInfo="RCRTCPBStreamInfo"}(Aa||(Aa={}));const ya={[Aa.RtcInput]:["roomType","broadcastType","extraInnerData","needSysChatroom","identityChangeType","joinType","innerDatas","outerDatas","supportNtf"],[Aa.RtcOutput]:["version"],[Aa.RtcUserListOutput]:["users","token","sessionId","roomInfo","version"],[Aa.SetUserStatusInput]:["status"],[Aa.RtcSetDataInput]:["interior","target","key","value","objectName","content"],[Aa.RtcUserSetDataInput]:["valueInfo","objectName","content"],[Aa.RtcDataInput]:["interior","target","key","objectName","content"],[Aa.RtcSetOutDataInput]:["target","valueInfo","objectName","content"],[Aa.MCFollowInput]:["state"],[Aa.RtcTokenOutput]:["rtcToken"],[Aa.RtcQryOutput]:["outInfo"],[Aa.RtcQryUserOutDataInput]:["userId"],[Aa.RtcUserOutDataOutput]:["user"],[Aa.RtcQueryListInput]:["order"],[Aa.RtcRoomInfoOutput]:["roomId","roomData","userCount","list"],[Aa.RtcValueInfo]:["key","value"],[Aa.RtcKeyDeleteInput]:["key"],[Aa.RtcNotifyMsg]:["type","time","roomId"],[Aa.RtcPullKV]:["timestamp","roomId"],[Aa.RtcKVOutput]:["entries","bFullUpdate","syncTime"],[Aa.RtcQueryUserJoinedInput]:["userId"],[Aa.RtcQueryUserJoinedOutput]:["info"],[Aa.RtcInviteInput]:["invitedUserId","timeoutTime","invitedRoomId","inviteInfo","inviteSessionId"],[Aa.RtcCancelInviteInput]:["invitedUserId","invitedRoomId","inviteInfo","inviteSessionId"],[Aa.RtcInviteAnswerInput]:["inviteUserId","answerCode","inviteRoomId","inviteSessionId","content","key","value"],[Aa.RtcEndInviteInput]:["inviteRoomId","inviteSessionId","inviteContent","inviteRoomKeys"],[Aa.RtcRoomStatusInput]:["version"],[Aa.RtcRoomStatusOutput]:["bFullStatus","version","usersData","roomStatus"],[Aa.RtcReportSDKInput]:["sdkInfo"],[Aa.RtcPBPolaris]:["type","appKey","sessionId","roomId","roomCreateTime","userId","userRole","joinTime","signalDataCenter","r1Info","r2Info","r3Info","r4Info"],[Aa.RtcPBR1Info]:["joinTime","rtcVersion","imVersion","platform","device","os","browserName","browserVersion"],[Aa.RtcPBR2Info]:["joinTime","sendTime","rtcActionType","rtcActionStatus","trackId"],[Aa.RtcPBR3Info]:["info"],[Aa.RtcPBR4Info]:["info"],[Aa.RtcPBStatusInfo]:["joinTime","receiveTime","totalBitRate","appCPUUsage","systemCPUUsage","systemCPUFrequency","networkStatus","googleRTTNetwork","ipAddress","useReceiveBroadBand","useSendBroadBand","packetLossCount","streams"],[Aa.RtcPBStreamInfo]:["trackId","codeName","volume","samplingRate","bitRate","packetLossRate","frameRate","resolution","blockTime","jitterData","nAckCount","pliCount","googleRTTTotalTime","isReceiveFirstFrameRate","codeType","isEnabled"]},ka=`\npackage Modules;\nmessage probuf {\n enum JoinType {\n KICK = 0; //踢前一个设备\n REFUSE = 1; //当前加入拒绝\n COEXIST = 2; //两个设备共存\n }\n enum targetType {\n ROOM =1 ;\n PERSON = 2;\n }\n message ${Aa.SetUserStatusInput}\n {\n optional int32 status=1;\n }\n message ${Aa.MCFollowInput}\n {\n required string state = 1;\n }\n message ${Aa.RtcQueryListInput}{\n optional int32 order=1;\n }\n message ${Aa.RtcKeyDeleteInput}{\n repeated string key=1;\n }\n message ${Aa.RtcValueInfo}{\n required string key=1;\n required string value=2;\n }\n message RtcUserInfo{\n required string userId=1;\n repeated ${Aa.RtcValueInfo} userData=2; //用户资源信息\n }\n message ${Aa.RtcRoomStatusInput}{ // rtc 和 living room 拉房间资源状态使用的参数\n required int64 version =1; //当前客户端最大的房间状态的version\n }\n message ${Aa.RtcRoomStatusOutput}{ // rtc 和 living room 拉房间资源状态返回的数据\n required bool bFullStatus =1; //标识此次给的数据是否是全量数据\n required int64 version =2; //当前获取后房间的最大版本号\n repeated RtcUserInfo usersData=3;//如果是全量数据,这个不为空,给的是房间全部的人以及发布的资源\n repeated RtcRoomStatus roomStatus=4;//房间增量数据\n }\n message RtcRoomStatus{ //房间状态变动\n required string userId = 1;//用户ID\n required int32 event = 2;//房间状态变更的event(人员加入/退出/离线/发布资源) (0:加入;1:离开;2:离线;3:资源变动) \n required int64 time = 3;//本次变更的版本号\n repeated RtcValueInfo userData = 4;//用户变更的资源(event为0或者3时可能有值)\n optional int32 switchRoleType = 5;//如果是切换角色导致的加入房间或退出房间的类型\n optional string extra = 6;\n }\n message ${Aa.RtcUserListOutput}{\n repeated RtcUserInfo users=1;\n optional string token=2;\n optional string sessionId=3;\n repeated RtcValueInfo roomInfo = 4; //房间key value\n repeated RtcKVEntity entries = 5;//直播KV属性对象集合\n optional int64 syncTime = 6;//所有属性的最大时间戳(下次拉取KV时用)。\n optional int32 offlineKickTime = 7;//server超时踢人时间,默认60s\n repeated string codeFormat = 8; //当前房间用户支持的编码交集\n optional int64 roomCreateTime = 9;//房间创建时间\n optional int64 userJoinTime = 10;//用户加入房间\n optional int64 version = 11;//当前房间的版本号\n }\n message RtcRoomInfoOutput{\n optional string roomId = 1;\n repeated ${Aa.RtcValueInfo} roomData = 2;\n optional int32 userCount = 3;\n repeated RtcUserInfo list=4;\n }\n message ${Aa.RtcInput}{\n required int32 roomType=1;\n optional int32 broadcastType=2;\n optional RtcValueInfo extraInnerData = 3;\n optional bool needSysChatroom = 4; //是否需要同步聊天室\n optional IdentityChangeType identityChangeType = 5; //身份变更类型\n optional JoinType joinType = 6; // 加入房间类型\n repeated ${Aa.RtcValueInfo} innerDatas = 7; //用户内部inner数据,角色或者连麦信息等\n repeated ${Aa.RtcValueInfo} outerDatas = 8; //用户内部outer数据,自定义数据结构RtcInput。\n optional bool supportNtf = 9; //是否支持房间状态的变更通过通知拉取的方式获取\n }\n message ${Aa.RtcQryOutput}{\n repeated ${Aa.RtcValueInfo} outInfo=1;\n }\n message ${Aa.RtcDataInput}{\n required bool interior=1;\n required targetType target=2;\n repeated string key=3;\n optional string objectName=4;\n optional string content=5;\n }\n message ${Aa.RtcSetDataInput}{\n required bool interior=1;\n required targetType target=2;\n required string key=3;\n required string value=4;\n optional string objectName=5;\n optional string content=6;\n }\n message ${Aa.RtcUserSetDataInput} {\n repeated ${Aa.RtcValueInfo} valueInfo = 1;\n required string objectName = 2;\n repeated ${Aa.RtcValueInfo} content = 3;\n }\n message RtcQryInput{\n required bool isInterior=1;\n required targetType target=2;\n repeated string key=3;\n }\n message RtcDelDataInput{\n repeated string key=1;\n required bool isInterior=2;\n required targetType target=3;\n }\n message RtcOutput\n {\n optional int32 nothing=1;\n optional int64 version=2;\n }\n message ${Aa.RtcTokenOutput}{\n required string rtcToken=1;\n }\n message ${Aa.RtcSetOutDataInput}{\n required targetType target=1;\n repeated ${Aa.RtcValueInfo} valueInfo=2;\n optional string objectName=3;\n optional string content=4;\n }\n message ${Aa.RtcQryUserOutDataInput}{\n repeated string userId = 1;\n }\n message ${Aa.RtcUserOutDataOutput}{\n repeated RtcUserInfo user = 1;\n }\n message ${Aa.RtcNotifyMsg} \n {\n required int32 type= 1; //(通知类型 1:rtc房间状态KV变更通知)\n optional int64 time= 2; //消息产生时间\n optional string roomId=3; //主播房间id\n }\n message ${Aa.RtcPullKV}\n {\n required int64 timestamp = 1;\n required string roomId = 2;\n }\n message RtcKVEntity \n {\n required string key = 1;\n required string value = 2;\n optional int32 status = 3;\n optional int64 timestamp = 4;\n optional string uid = 5;\n }\n message ${Aa.RtcKVOutput}\n {\n repeated RtcKVEntity entries = 1;\n optional bool bFullUpdate = 2;\n optional int64 syncTime = 3; \n }\n enum IdentityChangeType \n {\n AnchorToViewer = 1; //1为主播变观众\n ViewerToAnchor = 2; //2为观众变主播\n }\n message ${Aa.RtcQueryUserJoinedInput}\n {\n required string userId = 1;\n }\n message RtcJoinedInfo\n {\n required string deviceId = 1; //设备ID\n required string roomId = 2; //加入的房间ID\n optional int64 joinTime = 3; //加入的时间\n }\n message ${Aa.RtcQueryUserJoinedOutput}\n {\n repeated RtcJoinedInfo info = 1;\n }\n message ${Aa.RtcViewerJoinedOutput}\n {\n required string rtcToken=1;\n repeated RtcKVEntity entries = 2;//KV属性对象集合\n optional int64 syncTime = 3;//所有属性的最大时间戳(下次拉取KV时用)。\n optional string sessionId=4;\n optional int64 roomCreateTime = 5;//房间创建时间\n optional int64 userJoinTime = 6;//用户加入房间\n }\n message ${Aa.RtcInviteInput}\n {\n required string invitedUserId=1; //被邀请的人的uid\n optional int32 timeoutTime=2; //邀请超时时间(秒),默认三十秒\n required string invitedRoomId=3; //被邀请的房间\n required string inviteInfo=4; //邀请的信息(包含邀请人,被邀请人,各自userid)客户端定义好.协议栈和server透传\n required string inviteSessionId= 5; //客户端保证唯一性(建议roomid_userid_时间戳_随机数)\n }\n message ${Aa.RtcCancelInviteInput}\n {\n required string invitedUserId=1; //被邀请的人的uid\n required string invitedRoomId=2; //被邀请的房间\n required string inviteInfo=3; //取消邀请的信息(包含邀请人,被邀请人,各自userid)客户端定义好.协议栈和server透传\n required string inviteSessionId=4; //邀请的sessionId,客户端发起邀请时产生\n }\n message ${Aa.RtcInviteAnswerInput}\n {\n required string inviteUserId=1; //邀请的人的uid\n required int32 answerCode=2; //是否接受连麦邀请.0为拒绝,1为接受\n required string inviteRoomId=3; //邀请的房间\n required string inviteSessionId=4; //邀请的sessionId\n required string content=5; //需要转发的content\n optional string key=6; //如果接受的话,需要加这个字段,放在room级别的k和v,新加入房间的能拉取到\n optional string value=7; //如果接受的话,需要加这个字段,放在room级别的k和v,新加入房间的能拉取到\n }\n message ${Aa.RtcEndInviteInput}\n {\n required string inviteRoomId=1; //邀请的房间\n required string inviteSessionId=2; //邀请的sessionId\n required string inviteContent=3; //结束连麦的信息(需要透传给房间内其他人)\n repeated string inviteRoomKeys=4; //需要删除连麦的信息的key\n }\n message ${Aa.RtcReportSDKInput} {\n required string sdkInfo=1; // 用户集成的 sdk 信息,json 格式 {"web-rtc": "4.0.3.7"}\n }\n // ---- 北极星数据上报 -------\n message ${Aa.RtcPBPolaris} {\n required string type = 1;//上报数据类型 R1-R4\n required string appKey = 2;\n required string sessionId = 3;//房间通话id\n required string roomId = 4;\n required int64 roomCreateTime = 5;//房间创建时间\n required string userId = 6;\n required int32 userRole = 7;\n required int64 joinTime = 8;\n required string signalDataCenter = 9;//signal数据中心\n optional ${Aa.RtcPBR1Info} r1Info = 10;\n optional ${Aa.RtcPBR2Info} r2Info = 11;\n optional ${Aa.RtcPBR3Info} r3Info = 12;\n optional ${Aa.RtcPBR4Info} r4Info = 13;\n }\n message ${Aa.RtcPBR1Info} {\n required int64 joinTime = 1;//用户加入房间的时间\n required string rtcVersion = 2;//Rtc版本号\n required string imVersion = 3;//IM SDK 版本\n required string platform = 4;//平台(如:Android、iOS、Web)\n required string device = 5; //设备信息(手机名称+型号)\n required string os = 6;//系统版本(手机系统版本)\n optional string browserName = 7; //浏览器名称, 没有用 -1 表示\n optional string browserVersion = 8;//浏览器版本, 没有用 -1 表示\n optional int64 receiveTime = 9; // 发送数据的时间\n }\n message ${Aa.RtcPBR2Info} {\n required int64 joinTime = 1;\n required int64 sendTime = 2;\n required string rtcActionType = 3;//发布类型 subscribe : 订阅 publish : 发布\n required string rtcActionStatus = 4;//发布状态 begin : 开始 tend : 结束\n repeated string trackId = 5;\n optional int64 receiveTime = 6; // 发送数据的时间\n }\n message ${Aa.RtcPBR3Info} {\n required ${Aa.RtcPBStatusInfo} info = 1;\n }\n message ${Aa.RtcPBR4Info} {\n required ${Aa.RtcPBStatusInfo} info = 1;\n }\n message ${Aa.RtcPBStatusInfo} {\n optional int64 joinTime = 1;//用户加入房间的时间\n optional int64 receiveTime = 2;//用户发布数据流的时间(毫秒),暂时由客户端生成,后期如果有问题服务端做兜底处理\n optional int64 totalBitRate = 3;//总码率\n optional float appCPUUsage = 4;//APP CPU占用率\n optional float systemCPUUsage = 5;////系统 CPU占用率\n optional float systemCPUFrequency = 6;//系统CPU频率 (安卓8.0以上)\n optional string networkStatus = 7;//实时网络状态(2g、3g、4g、wifi)\n optional int32 googleRTTNetwork = 8;//Goog rtt 网络延迟\n optional string ipAddress = 9;//ip地址\n optional string useReceiveBroadBand = 10; //可接收带宽(单位: bit)\n optional string useSendBroadBand = 11;//可用发送带宽(单位: bit)\n optional string packetLossCount = 12;//丢包数\n repeated ${Aa.RtcPBStreamInfo} streams = 13;\n }\n message ${Aa.RtcPBStreamInfo} {\n required string trackId = 1;\n optional string codeName = 2;//编解码名称\n optional string volume = 3;//音频播放音量\n optional int32 samplingRate = 4; //音频采样率\n optional float bitRate = 5;//下行码率\n optional float packetLossRate = 6;\n optional int32 frameRate = 7;//视频接收帧率(单位:fps)\n optional string resolution = 8;//视频分辨率(格式:640*480)\n optional int64 blockTime = 9;//接收卡顿(间隔时间, 单位: ms)\n optional int32 jitterData = 10;//jitter数据抖动\n optional string nAckCount = 11;//nack数量\n optional string pliCount = 12; //PLI请求数\n optional int64 googleRTTTotalTime = 13; //googRtt往返时长\n optional int32 isReceiveFirstFrameRate = 14;//第一个关键帧是否正常收到\n optional string codeType = 15;//编码方式\n optional int32 isEnabled = 16; //当前流的状态是否可用\n }\n // ---- 北极星数据上报 -------\n}\n`,Da=(e,t,i,r,n,o,s)=>{const a=n?Object.keys(n).map((t=>e.encode(Aa.RtcValueInfo,{key:t,value:n[t]},!0))):void 0,c=o?Object.keys(o).map((t=>e.encode(Aa.RtcValueInfo,{key:t,value:o[t]},!0))):void 0;return e.encode(Aa.RtcInput,{roomType:t,broadcastType:i,joinType:r,innerDatas:a,outerDatas:c,supportNtf:s})},ba=(e,t)=>{const i=e.decode(Aa.RtcUserListOutput,t),{users:r,token:n,sessionId:o,roomInfo:s,entries:a,offlineKickTime:c=60,codeFormat:d,roomCreateTime:_,userJoinTime:l,version:u}=i,h={};return m(r,(e=>{const{userId:t,userData:i}=e,r={};m(i,(e=>{const{key:t,value:i}=e;r[t]=i})),h[t]=r})),{users:h,token:n,sessionId:o,roomInfo:s,kvEntries:a,offlineKickTime:c,codeFormat:d,roomCreateTime:Ft(_),userJoinTime:Ft(l),version:u}};class Ua{constructor(e,t){this.context=e,this.codec=t,this.roomCreateTime=0,this.userJoinTime=0,this.logger=null,this.logger=We.getLogger()}joinRTCRoom(e,t,i,r,o,s){return S(this,void 0,void 0,(function*(){const a=Da(this.codec,t,i,r,o,s,!1),{code:c,buffer:d}=yield this.context.rtcSignaling(e,na,!0,a);let _;if(c===n.SUCCESS&&d){_=ba(this.codec,d);const{users:e,token:t,sessionId:i,roomInfo:r,kvEntries:n,offlineKickTime:o,roomCreateTime:s,userJoinTime:a,version:l}=_;return this.roomCreateTime=s,this.userJoinTime=a,{code:c,data:{users:e,token:t,sessionId:i,roomInfo:r,kvEntries:n,offlineKickTime:o,version:l}}}return{code:c,data:_}}))}quitRTCRoom(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Aa.SetUserStatusInput,{status:0}),{code:i}=yield this.context.rtcSignaling(e,oa,!0,t);return i}))}getRTCRoomInfo(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Aa.RtcQueryListInput,{order:2}),{code:i,buffer:r}=yield this.context.rtcSignaling(e,sa,!0,t);let o;return i===n.SUCCESS&&r&&(o=this.codec.decode(Aa.RtcRoomInfoOutput,r)),{code:i,data:o}}))}getRTCUserInfoList(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Aa.RtcQueryListInput,{order:2}),{code:i,buffer:r}=yield this.context.rtcSignaling(e,aa,!0,t);let o;if(i===n.SUCCESS&&r){o={users:ba(this.codec,r).users}}return{code:i,data:o}}))}getRTCUserInfo(e){throw new Error("Method not implemented.")}removeRTCUserInfo(e,t){return S(this,void 0,void 0,(function*(){const i=this.codec.encode(Aa.RtcKeyDeleteInput,{key:t}),{code:r}=yield this.context.rtcSignaling(e,ca,!1,i);return r}))}setRTCData(e,t,i,r,n,o){return S(this,void 0,void 0,(function*(){const s=this.codec.encode(Aa.RtcSetDataInput,{interior:r,target:n,key:t,value:i,objectName:null==o?void 0:o.name,content:null==o?void 0:o.content}),{code:a}=yield this.context.rtcSignaling(e,da,!1,s);return a}))}setRTCTotalRes(e,t,i,r,n,o){return S(this,void 0,void 0,(function*(){const s={objectName:r,content:[],valueInfo:[this.codec.encode(Aa.RtcValueInfo,{key:"uris",value:i},!0)]};t.forEach((e=>{const t=this.codec.encode(Aa.RtcValueInfo,{key:e.name,value:e.content},!0);s.content.push(t)})),n&&s.valueInfo.push(this.codec.encode(Aa.RtcValueInfo,{key:"mcu_uris",value:n},!0)),o&&s.valueInfo.push(this.codec.encode(Aa.RtcValueInfo,{key:"cdn_uris",value:o},!0));const a=this.codec.encode(Aa.RtcUserSetDataInput,s),{code:c}=yield this.context.rtcSignaling(e,_a,!0,a);return c}))}setRTCCDNUris(e,t,i){return S(this,void 0,void 0,(function*(){const r=this.codec.encode(Aa.RtcUserSetDataInput,{objectName:t,valueInfo:this.codec.encode(Aa.RtcValueInfo,{key:"cdn_uris",value:i},!0)}),{code:n}=yield this.context.rtcSignaling(e,_a,!0,r);return n}))}getRTCData(e,t,i,r){return S(this,void 0,void 0,(function*(){const o=this.codec.encode(Aa.RtcDataInput,{interior:i,target:r,key:t}),{code:s,buffer:a}=yield this.context.rtcSignaling(e,la,!0,o);if(s!==n.SUCCESS||!a)return{code:s};const{outInfo:c}=this.codec.decode(Aa.RtcQryOutput,a),d={};return c.forEach((e=>{d[e.key]=e.value})),{code:s,data:d}}))}removeRTCData(e,t,i,r,n){return S(this,void 0,void 0,(function*(){const o=this.codec.encode(Aa.RtcDataInput,{interior:i,target:r,key:t,objectName:(null==n?void 0:n.name)||"",content:(null==n?void 0:n.content)||""}),{code:s}=yield this.context.rtcSignaling(e,ua,!1,o);return s}))}setRTCOutData(e,t,i,r){return S(this,void 0,void 0,(function*(){throw new Error("JSEngine's method not implemented.")}))}getRTCOutData(e,t){return S(this,void 0,void 0,(function*(){throw new Error("JSEngine's method not implemented.")}))}getRTCToken(e,t,i){return S(this,void 0,void 0,(function*(){const r=Da(this.codec,t,i),{code:o,buffer:s}=yield this.context.rtcSignaling(e,ha,!0,r);if(o!==n.SUCCESS||!s)return{code:o};const{rtcToken:a}=this.codec.decode(Aa.RtcTokenOutput,s);return{code:o,data:{rtcToken:a}}}))}setRTCState(e,t){return S(this,void 0,void 0,(function*(){const i=this.codec.encode(Aa.MCFollowInput,{state:t}),{code:r}=yield this.context.rtcSignaling(e,ga,!0,i);return r}))}setRTCStateByHttp(e,t,i,r){return S(this,void 0,void 0,(function*(){const n=((e,t,i)=>{const{type:r,appKey:n,sessionId:o,roomId:s,roomCreateTime:a,userId:c,userRole:d,joinTime:_,signalDataCenter:l,r1Info:u,r2Info:h,r3Info:g,r4Info:v}=t,p={type:r,appKey:n,sessionId:o,roomId:s,roomCreateTime:a,userId:c,userRole:d,joinTime:_,signalDataCenter:l};if(i===uo.R1&&u){const t=e.encode(Aa.RtcPBR1Info,u,!0);return e.encode(Aa.RtcPBPolaris,Object.assign(Object.assign({},p),{r1Info:t}))}if(i===uo.R2&&h){const t=e.encode(Aa.RtcPBR2Info,h,!0);return e.encode(Aa.RtcPBPolaris,Object.assign(Object.assign({},p),{r2Info:t}))}if(i===uo.R3&&g){const{info:t}=g,{streams:i}=t;let r=Array.isArray(i)&&i.map((t=>t&&e.encode(Aa.RtcPBStreamInfo,t,!0))),n=e.encode(Aa.RtcPBStatusInfo,Object.assign(Object.assign({},t),{streams:r}),!0),o=e.encode(Aa.RtcPBR3Info,{info:n},!0);return e.encode(Aa.RtcPBPolaris,Object.assign(Object.assign({},p),{r3Info:o}))}if(i===uo.R4&&v){const{info:t}=v,{streams:i}=t;let r=Array.isArray(i)&&i.map((t=>t&&e.encode(Aa.RtcPBStreamInfo,t,!0))),n=e.encode(Aa.RtcPBStatusInfo,Object.assign(Object.assign({},t),{streams:r}),!0),o=e.encode(Aa.RtcPBR4Info,{info:n},!0);return e.encode(Aa.RtcPBPolaris,Object.assign(Object.assign({},p),{r4Info:o}))}return{}})(this.codec,i,r);let s=e;/^https:\/\//.test(e)||(s=`https://${e}`);try{const e=yield t.httpReq({url:`${s}/rtc/logserver/polaris`,body:n,method:o.POST,headers:{jwt:zn.jwtToken},timeout:2e3});if(!e.data)throw new Error("http request fail");return JSON.parse(e.data).resultCode}catch(e){return lo.REPORT_FAIL}}))}getRTCUserList(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Aa.RtcQueryListInput,{order:2}),{code:i,buffer:r}=yield this.context.rtcSignaling(e,va,!0,t);if(i!==n.SUCCESS||!r)return{code:i};return{code:i,data:ba(this.codec,r)}}))}joinLivingRoomAsAudience(e,t,i){return S(this,void 0,void 0,(function*(){const r=Da(this.codec,t,i),{code:o,buffer:s}=yield this.context.rtcSignaling(e,pa,!0,r);if(o!==n.SUCCESS||!s)return{code:o};const{rtcToken:a,entries:c,roomCreateTime:d,userJoinTime:_}=this.codec.decode(Aa.RtcViewerJoinedOutput,s);return this.roomCreateTime=Ft(d),this.userJoinTime=Ft(_),{code:o,data:{token:a,kvEntries:c}}}))}quitLivingRoomAsAudience(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Aa.SetUserStatusInput,{status:0}),{code:i}=yield this.context.rtcSignaling(e,Ra,!0,t);return i}))}rtcIdentityChange(e,t,i){return S(this,void 0,void 0,(function*(){const r=this.codec.encode(Aa.RtcInput,{roomType:mo.LIVE,broadcastType:i,identityChangeType:t,needSysChatroom:!1}),{code:o,buffer:s}=yield this.context.rtcSignaling(e,Ia,!0,r);if(o!==n.SUCCESS||!s)return{code:o};return{code:o,data:ba(this.codec,s)}}))}requestRoomPK(e){return S(this,void 0,void 0,(function*(){const{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteTimeout:n,inviteInfo:o,roomId:s}=e,a=this.codec.encode(Aa.RtcInviteInput,{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,timeoutTime:n,inviteInfo:o}),{code:c}=yield this.context.rtcSignaling(s,Ea,!0,a);return c}))}cancelRoomPK(e){return S(this,void 0,void 0,(function*(){const{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteInfo:n,roomId:o}=e,s=this.codec.encode(Aa.RtcCancelInviteInput,{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteInfo:n}),{code:a}=yield this.context.rtcSignaling(o,Sa,!0,s);return a}))}responseRoomPK(e){return S(this,void 0,void 0,(function*(){const{inviteUserId:t,inviteRoomId:i,inviteSessionId:r,content:n,key:o,value:s,agree:a,roomId:c}=e,d=this.codec.encode(Aa.RtcInviteAnswerInput,{inviteUserId:t,inviteRoomId:i,inviteSessionId:r,content:n,key:o,value:s,answerCode:a?1:0}),{code:_}=yield this.context.rtcSignaling(c,Ta,!0,d);return _}))}endRoomPK(e){return S(this,void 0,void 0,(function*(){const{endRoomId:t,sessionId:i,content:r,keys:n,roomId:o}=e,s=this.codec.encode(Aa.RtcEndInviteInput,{inviteRoomId:t,inviteSessionId:i,inviteContent:r,inviteRoomKeys:n}),{code:a}=yield this.context.rtcSignaling(o,fa,!0,s);return a}))}getRTCJoinedUserInfo(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Aa.RtcQueryUserJoinedInput,{userId:e}),{code:i,buffer:r}=yield this.context.rtcSignaling("",Ca,!0,t);if(i!==n.SUCCESS||!r)return{code:i};return{code:i,data:(this.codec.decode(Aa.RtcQueryUserJoinedOutput,r).info||[]).map((e=>({deviceId:e.deviceId,roomId:e.roomId,joinTime:Ft(e.joinTime)})))}}))}pullRTCRoomEntry(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Aa.RtcPullKV,{timestamp:0,roomId:e}),{code:i,buffer:r}=yield this.context.rtcSignaling(e,ma,!0,t);if(i!==n.SUCCESS)return{code:i};const o=this.codec.decode(Aa.RtcKVOutput,r);let{entries:s,syncTime:a}=o;return s=(s||[]).map((e=>Object.assign(Object.assign({},e),{timestamp:Ft(e.timestamp)}))),{code:i,data:{kvEntries:s,syncTime:Ft(a)}}}))}pullRTCRoomStatus(e,t){return S(this,void 0,void 0,(function*(){const i=this.codec.encode(Aa.RtcRoomStatusInput,{version:t}),{code:r,buffer:o}=yield this.context.rtcSignaling(e,Oa,!0,i);if(r!==n.SUCCESS)return{code:r};return{code:r,data:this.codec.decode(Aa.RtcRoomStatusOutput,o)}}))}decodeRtcNotify(e){const{time:t,type:i,roomId:r}=this.codec.decode(Aa.RtcNotifyMsg,e);return{time:Ft(t),type:i,roomId:r}}getCurrentId(){return this.context.getCurrentId()}getNaviInfo(){return this.context.getNaviInfo()}getConnectionStatus(){return this.context.getConnectionStatus()}getAppkey(){return this.context.getAppkey()}webRtcPing(e,t,i){return S(this,void 0,void 0,(function*(){const r=this.codec.encode(Aa.RtcInput,{roomType:t,broadcastType:i}),{code:o,buffer:s}=yield this.context.rtcSignaling(e,Na,!0,r);if(o!==n.SUCCESS)return{code:o};const a=this.codec.decode(Aa.RtcOutput,s);return a.version=Ft(a.version),{code:o,data:a}}))}rtcPing(e,t,i){return/Electron/.test(navigator.userAgent)?this.context.rtcPingResVersion(e,t,i):this.webRtcPing(e,t,i)}sendMessage(e,t,i){return this.context.sendMessage(e,t,i)}registerRTCSignalListener(e){this.context.registerRTCSignalListener(e)}registerConnectionStateChangeListener(e){this.context.onconnectionstatechange=e}registerDisconnectListener(e){this.context.ondisconnect=e}registerDestroyListener(e){this.context.ondestroy=e}registerMessageListener(e){this.context.onmessage=e}getCoreVersion(){return this.context.getCoreVersion()}getPluginContext(){return this.context}reportSDKInfo(e){const t=this.codec.encode(Aa.RtcReportSDKInput,{sdkInfo:JSON.stringify(e)});this.context.rtcSignaling("",La,!0,t)}}var Pa;!function(e){e.RTC="RTC"}(Pa||(Pa={}));const Ma={tag:"RCRTC",verify:e=>"browser"!==e.tag?(console.error(`RCRTC Plugin is not support the runtime '${e.tag}'`),!1):It?(I.add("plugin-rtc","5.6.8"),!!I.validEngine("^5.6.0")||(console.error(`The current engine version '${I.getInfo().engine}' error, plugin-rtc required engine version at least '^5.6.0'.`),!1)):(console.error("Please use the https protocol or use `http://localhost` to open the page!"),!1),setup(e,i,r={}){var n,o,s,a,c,d,_,l;const u=e.createLogger("RCRTC",Pa.RTC);return u.setOutputLevel(r.logLevel||E.DEBUG),We.setLogger(u),Ye.setLogger(u),u.warn(f.L_INDEX_INSTALL_RTC_PLUGIN_O,JSON.stringify({"RCRTC Version":"5.6.8",Commit:"5b57db6e6132740cd12ae9f67466cab1090ce82c","browserInfo.browser":Ut.browser,"browserInfo.supportsUnifiedPlan":Ut.supportsUnifiedPlan,"browserInfo.version":Ut.version})),h("options.mediaServer",r.mediaServer,(e=>!(!v(e)||"https:"===location.protocol&&!/^https/.test(e)))),h("options.timeout",r.timeout,(e=>t(e)&&e>=5e3&&e<=3e4)),h("options.pingGap",r.pingGap,(e=>t(e)&&e>=3e3&&e<=1e4)),(null==r?void 0:r.audio)&&((null===(n=r.audio)||void 0===n?void 0:n.workletModule)&&(it.workletModule=null===(o=r.audio)||void 0===o?void 0:o.workletModule),(null===(s=r.audio)||void 0===s?void 0:s.workletWasm)&&(it.workletWasm=null===(a=r.audio)||void 0===a?void 0:a.workletWasm),(null===(c=r.audio)||void 0===c?void 0:c.workletModule)&&(null===(d=r.audio)||void 0===d?void 0:d.workletWasm)&&(it.isOpen=!0),void 0!==(null===(_=r.audio)||void 0===_?void 0:_.isOpen)&&(it.isOpen=null===(l=r.audio)||void 0===l?void 0:l.isOpen)),new ra(new Ua(e,e.createCodec(ya,ka)),i,r)}},xa={DEFAULT:"RongCloudRTC"},wa={transResolution:yt,transFrameRate:bt,parseTrackId:Ct,ifSupportLocalFileTrack:Pt,ifSupportScreenShare:Mt};export{ks as BackgroundPictureFillMode,Ds as MixLayoutMode,bs as MixVideoRenderMode,As as RCAbstractRoom,Ys as RCAudienceClient,Zs as RCAudienceLivingRoom,Qe as RCAudioBitrate,_t as RCCameraVideoTrack,Ve as RCFrameRate,zs as RCInnerCDNPullIsHttps,qs as RCInnerCDNPullKind,Os as RCKickReason,Ks as RCLivingRoom,xs as RCLivingType,nt as RCLocalAudioTrack,ct as RCLocalFileAudioTrack,st as RCLocalFileTrack,at as RCLocalFileVideoTrack,rt as RCLocalTrack,ot as RCLocalVideoTrack,Ms as RCMCUConfigBuilder,ta as RCMediaStreamCapture,Je as RCMediaType,dt as RCMicphoneAudioTrack,ra as RCRTCClient,T as RCRTCCode,ho as RCRTCLiveRole,Gt as RCRTCPingResult,js as RCRTCRoom,gt as RCRemoteAudioTrack,ht as RCRemoteTrack,vt as RCRemoteVideoTrack,Fe as RCResolution,ut as RCScreenAudioTrack,lt as RCScreenVideoTrack,xa as RCTag,Ze as RCTrack,et as RCVideoBitrate,ea as RTCJoinType,qe as device,wa as helper,Ma as installer};
15
+ ***************************************************************************** */function S(e,t,i,r){return new(i||(i=Promise))((function(n,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}var T,f,C;!function(e){e[e.SUCCESS=1e4]="SUCCESS",e[e.PB_ERROR=40001]="PB_ERROR",e[e.SIGNAL_DISCONNECTED=5e4]="SIGNAL_DISCONNECTED",e[e.PARAMS_ERROR=50001]="PARAMS_ERROR",e[e.REPERT_JOIN_ROOM=50002]="REPERT_JOIN_ROOM",e[e.NOT_IN_ROOM=50003]="NOT_IN_ROOM",e[e.SERVICE_INVALID=50004]="SERVICE_INVALID",e[e.RTC_TOKEN_INVALID=50006]="RTC_TOKEN_INVALID",e[e.SIGNAL_ERROR=53001]="SIGNAL_ERROR",e[e.CREATE_OFFER_FAILED=53003]="CREATE_OFFER_FAILED",e[e.REQUEST_FAILED=53004]="REQUEST_FAILED",e[e.MCU_SERVER_NOT_FOUND=53005]="MCU_SERVER_NOT_FOUND",e[e.BROADCAST_SUB_LIST_NOT_EMPTY=53007]="BROADCAST_SUB_LIST_NOT_EMPTY",e[e.ROOM_HAS_BEEN_DESTROYED=53008]="ROOM_HAS_BEEN_DESTROYED",e[e.NOT_OPEN_VIDEO_AUDIO_SERVER=53009]="NOT_OPEN_VIDEO_AUDIO_SERVER",e[e.GET_USER_MEDIA_FAILED=53010]="GET_USER_MEDIA_FAILED",e[e.GET_DISPLAY_MEDIA_FAILED=53011]="GET_DISPLAY_MEDIA_FAILED",e[e.BROWSER_PERMISSION_DENIED=53012]="BROWSER_PERMISSION_DENIED",e[e.CREATE_CUSTOM_TRACK_FAILED=53013]="CREATE_CUSTOM_TRACK_FAILED",e[e.INVALID_TAGS=53014]="INVALID_TAGS",e[e.INVALID_USER_ID=53015]="INVALID_USER_ID",e[e.CREATE_FILE_TRACK_FAILED=53016]="CREATE_FILE_TRACK_FAILED",e[e.INVALID_FILE_INSTANCE=53017]="INVALID_FILE_INSTANCE",e[e.SET_REMOTE_DESCRIPTION_FAILED=53018]="SET_REMOTE_DESCRIPTION_FAILED",e[e.BROWSER_NOT_SUPPORT=53019]="BROWSER_NOT_SUPPORT",e[e.TRACK_NOT_READY=53020]="TRACK_NOT_READY",e[e.VIDEO_TRACK_MISS_MEDIA_ELEMENT=53021]="VIDEO_TRACK_MISS_MEDIA_ELEMENT",e[e.TRACK_PLAY_ERROR=53022]="TRACK_PLAY_ERROR",e[e.SIGNAL_AUDIENCE_JOIN_ROOM_FAILED=53023]="SIGNAL_AUDIENCE_JOIN_ROOM_FAILED",e[e.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED=53024]="SIGNAL_ROOM_CHANGE_IDENTITY_FAILED",e[e.PACKAGE_ENVIRONMENT_ERROR=53025]="PACKAGE_ENVIRONMENT_ERROR",e[e.PUBLISH_TRACK_LIMIT_EXCEEDED=53026]="PUBLISH_TRACK_LIMIT_EXCEEDED",e[e.CDN_RESOURCE_IS_EMPTY=53027]="CDN_RESOURCE_IS_EMPTY",e[e.SIGNAL_JOIN_RTC_ROOM_REFUSED=53028]="SIGNAL_JOIN_RTC_ROOM_REFUSED",e[e.NO_PERMISSION_TO_USE_REQUESTED_DEVICE=53029]="NO_PERMISSION_TO_USE_REQUESTED_DEVICE",e[e.THE_FUNCTION_IS_DISABLED_IN_PKROOM=53030]="THE_FUNCTION_IS_DISABLED_IN_PKROOM",e[e.SOME_TRACKS_PUBLISH_FAILED=53031]="SOME_TRACKS_PUBLISH_FAILED",e[e.MAC_IN_ELECTRON_NOT_SUPPORT_SCREEN_SHARE_WITH_AUDIO=53032]="MAC_IN_ELECTRON_NOT_SUPPORT_SCREEN_SHARE_WITH_AUDIO",e[e.JWT_TIME_OUT=1004]="JWT_TIME_OUT",e[e.SYSTEM_PERMISSION_DENIED=53033]="SYSTEM_PERMISSION_DENIED",e[e.PUBLISH_TRACKS_IS_INVALID=53034]="PUBLISH_TRACKS_IS_INVALID",e[e.TRACK_READYSTATE_IS_ENDED=53035]="TRACK_READYSTATE_IS_ENDED"}(T||(T={})),function(e){e.L_INDEX_INSTALL_RTC_PLUGIN_O="L-index_install_rtc_plugin-O",e.L_RTC_CLIENT_IM_CONNECTION_STATE_S="L-rtc_client_im_connection_state-S",e.L_RTC_CLIENT_IM_DISCONNECT_S="L-rtc_client_im_disconnect-S",e.L_RTC_CLIENT_MESSAGE_O="L-rtc_client_message-O",e.L_RTC_CLIENT_DESTROY_S="L-rtc_client_destroy-S",e.L_RTC_CLIENT_JOIN_RTC_ROOM_T="L-rtc_client_join_rtc_room-T",e.L_RTC_CLIENT_JOIN_RTC_ROOM_R="L-rtc_client_join_rtc_room-R",e.L_RTC_CLIENT_JOIN_LIVING_ROOM_T="L-rtc_client_join_living_room-T",e.L_RTC_CLIENT_JOIN_LIVING_ROOM_R="L-rtc_client_join_living_room-R",e.L_RTC_CLIENT_GET_AUDIENCE_CLIENT_O="L-rtc_client_get_audience_client-O",e.L_RTC_CLIENT_LEAVE_ROOM_T="L-rtc_client_leave_room-T",e.L_RTC_CLIENT_LEAVE_ROOM_R="L-rtc_client_leave_room-R",e.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O="L-rtc_client_create_microphone_audio_track-O",e.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O="L-rtc_client_create_camera_video_track-O",e.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O="L-rtc_client_create_microphone_and_camera_tracks-O",e.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_TRACK_O="L-rtc_client_create_screen_video_track-O",e.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_AND_AUDIO_TRACKS_O="L-rtc_client_create_screen_video_and_audio_tracks-O",e.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O="L-rtc_client_create_local_audio_track-O",e.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O="L-rtc_client_create_local_video_track-O",e.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O="L-rtc_client_create_local_file_tracks-O",e.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O="L-rtc_client_create_local_tracks-O",e.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_T="L-rtc_client_join_living_room_as_audience-T",e.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R="L-rtc_client_join_living_room_as_audience_R",e.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_T="L-rtc_client_leave_living_room_as_audience-T",e.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R="L-rtc_client_leave_living_room_as_audience-R",e.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_T="L-rtc_client_upgrade_to_anchor_room-T",e.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R="L-rtc_client_upgrade_to_anchor_room-R",e.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_T="L-rtc_client_downgrade_to_audience_room-T",e.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R="L-rtc_client_downgrade_to_audience_room-R",e.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_T="L-rtc_client_get_joined_room_info-T",e.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_R="L-rtc_client_get_joined_room_info-R",e.L_AUDIENCE_CLIENT_CALL_ONTRACKREADY_O="L-audinence_client_call_onTrackReady-O",e.L_AUDIENCE_CLIENT_SUBSCRIBE_T="L-audinence_client_subscribe-T",e.L_AUDIENCE_CLIENT_SUBSCRIBE_R="L-audinence_client_subscribe-R",e.L_AUDIENCE_CLIENT_UNSUBSCRIBE_T="L-audinence_client_unsubscribe-T",e.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R="L-audinence_client_unsubscribe-R",e.L_PINGER_START_O="L-pinger_start-O",e.L_PINGER_STOP_O="L-pinger_stop-O",e.L_PINGER_SEND_RTCPING_T="L-pinger_send_rtcping-T",e.L_PINGER_SEND_RTCPING_R="L-pinger_send_rtcping-R",e.L_ABSTRACT_ROOM_SEND_MESSAGE_T="L-abstract_room_send_message-T",e.L_ABSTRACT_ROOM_SEND_MESSAGE_R="L-abstract_room_send_message-R",e.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_T="L-abstract_room_set_room_attribute-T",e.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_R="L-abstract_room_set_room_attribute_R",e.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_T="L-abstract_room_delete_room_attribute_T",e.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R="L-abstract_room_delete_room_attribute_R",e.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_T="L-abstract_room_get_room_attribute_T",e.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_R="L-abstract_room_get_room_attribute_R",e.L_ABSTRACT_ROOM_PUBLISH_T="L-abstract_room_publish-T",e.L_ABSTRACT_ROOM_PUBLISH_R="L-abstract_room_publish-R",e.L_ABSTRACT_ROOM_PUBLISH_P="L-abstract_room_publish-P",e.L_ABSTRACT_ROOM_UNPUBLISH_T="L-abstract_room_unpublish-T",e.L_ABSTRACT_ROOM_UNPUBLISH_R="L-abstract_room_unpublish-R",e.L_ABSTRACT_ROOM_UNPUBLISH_P="L-abstract_room_unpublish-P",e.L_ABSTRACT_ROOM_SUBSCRIBE_T="L-abstract_room_subscribe-T",e.L_ABSTRACT_ROOM_SUBSCRIBE_R="L-abstract_room_subscribe-R",e.L_ABSTRACT_ROOM_UNSUBSCRIBE_T="L-abstract_room_unsubscribe-T",e.L_ABSTRACT_ROOM_UNSUBSCRIBE_R="L-abstract_room_unsubscribe-R",e.L_APP_CALL_UNSUBSCRIBE_O="L-app_call_unsubscribe-O",e.L_USER_LEFT_UNSUBSCRIBE_O="L-user_left_unsubscribe-O",e.L_RES_UNPUB_UNSUBSCRIBE_O="L-res_unpub_unsubscribe-O",e.L_ABSTRACT_ROOM_REGISTER_ROOM_EVENT_LISTENER_O="L-abstract_room_register_room_event_listener-O",e.L_ABSTRACT_ROOM_REGISTER_REPORT_LISTENER_O="L-abstract_room_register_report_listener-O",e.L_ABSTRACT_ROOM_AUDIO_LEVEL_O="L-abstract_room_audio_level-O",e.L_ABSTRACT_ROOM_IM_RECONNECTED_T="L-abstract_room_im_reconnected-T",e.L_ABSTRACT_ROOM_IM_RECONNECTED_R="L-abstract_room_im_reconnected-R",e.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O="L-abstract_room_call_app_listener-O",e.L_ABSTRACT_ROOM_SETBITRATE_O="L-abstract_room_setBitrate-O",e.L_ABSTRACT_ROOM_ONTRACKREADY_O="L-abstract_room_onTrackReady-O",e.L_ABSTRACT_ROOM_RECEIVE_MESSAGE_O="L-abstract_room_receive_message-O",e.L_ABSTRACT_ROOM_ONKICKOFF_O="L-abstract_room_onKickoff-O",e.L_LIVING_ROOM_RECONNECTED_T="L-living_room_reconnected-T",e.L_LIVING_ROOM_RECONNECTED_R="L-living_room_reconnected-R",e.L_LIVING_ROOM_ENABLE_INNER_CDN_T="L-living_room_enable_inner_cdn-T",e.L_LIVING_ROOM_ENABLE_INNER_CDN_R="L-living_room_enable_inner_cdn-R",e.L_LIVING_ROOM_SPREAD_CDN_INFO_T="L-living_room_spread_cdn_info-T",e.L_LIVING_ROOM_SPREAD_CDN_INFO_R="L-living_room_spread_cdn_info-R",e.L_LIVING_ROOM_SET_ROOM_CDN_INFO_T="L-living_room_set_room_cdn_info-T",e.L_LIVING_ROOM_SET_ROOM_CDN_INFO_R="L-living_room_set_room_cdn_info-R",e.L_LIVING_ROOM_JOINED_PK_ROOM_T="L-living_room_joined_pk_room-T",e.L_LIVING_ROOM_JOINED_PK_ROOM_R="L-living_room_joined_pk_room-R",e.L_LIVING_ROOM_LEAVE_PK_ROOM_T="L-living_room_leave_pk_room-T",e.L_LIVING_ROOM_LEAVE_PK_ROOM_R="L-living_room_leave_pk_room-R",e.L_APP_CALL_LEAVE_PK_ROOM_O="L-app_call_leave_pk_room-O",e.L_QUIT_PK_LEAVE_PK_ROOM_O="L-quit_pk_leave_pk_room-O",e.L_LIVING_ROOM_GET_ROOM_PK_HANDLER_O="L-living_room_get_room_pk_handler-O",e.L_LIVING_ROOM_GET_MCU_CONFIG_BUILDER_O="L-living_room_get_mcu_config_builder-O",e.L_LIVING_ROOM_QUIT_ALL_PK_ROOM_O="L-living_room_quit_all_pk_room-O",e.L_LIVING_PK_HANDLER_REGISTER_ROOM_PK_EVENT_LISTENER_O="L-living_pk_handler_register_room_pk_event_listener-O",e.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O="L-living_pk_handler_call_app_listener-O",e.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_T="L-living_pk_handler_request_join_other_room-T",e.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R="L-living_pk_handler_request_join_other_room-R",e.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_T="L-living_pk_handler_cancel_request_join_other_room-T",e.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R="L-living_pk_handler_cancel_request_join_other_room-R",e.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_T="L-living_pk_handler_response_join_other_room-T",e.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R="L-living_pk_handler_response_join_other_room-R",e.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_T="L-living_pk_handler_join_other_room-T",e.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R="L-living_pk_handler_join_other_room-R",e.L_LIVING_PK_HANDLER_LEAVE_OTHER_ROOM_T="L-living_pk_handler_leave_other_room-T",e.L_LIVING_PK_HANDLER_LEAVE_OTHER_ROOM_R="L-living_pk_handler_leave_other_room-R",e.L_QUIT_PK_T="L-quit_pk-T",e.L_QUIT_PK_R="L-quit_pk-R",e.L_EXCHANGE_WITH_PUSHOTHERROOM_T="L-exchange_with_pushotherroom-T",e.L_EXCHANGE_WITH_PUSHOTHERROOM_R="L-exchange_with_pushotherroom-R",e.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O="L-audience_living_room_call_app_listener-O",e.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_O="L-audience_living_room_pull_kvEntries-O",e.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_T="L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_T",e.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R="L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R",e.L_AUDIENCE_LIVING_ROOM_SINGAL_DATA_CHANGE_P="L-audience_living_room_singal_data_change-P",e.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_T="L-audience_living_room_get_cdn_play_url-T",e.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R="L-audience_living_room_get_cdn_play_url-R",e.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_T="L-audience_living_room_subscribe-T",e.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R="L-audience_living_room_subscribe-R",e.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_T="L-audience_living_room_unsubscribe-T",e.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_R="L-audience_living_room_unsubscribe-R",e.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_T="L-audience_living_room_update_subscribeList-T",e.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R="L-audience_living_room_update_subscribeList-R",e.L_AUDIENCE_LIVING_ROOM_ONTRACKREADY_O="L-audience_living_room_onTrackReady-O",e.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_R="L-audience_living_room_im_reconnected-R",e.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_T="L-audience_living_room_im_reconnected-T",e.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O="L-mcu_config_builder_set_host_video_track-O",e.L_MCU_CONFIG_BUILDER_SET_MIX_LAYOUT_MODE_O="L-mcu_config_builder_set_mix_layout_mode-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RESOLUTION_O="L-mcu_config_builder_set_output_video_resolution-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_FPS_O="L-mcu_config_builder_set_output_video_fps-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_BITRATE_O="L-mcu_config_builder_set_output_video_bitrate-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_RESOLUTION_O="L-mcu_config_builder_set_output_tiny_video_resolution-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_FPS_O="L-mcu_config_builder_set_output_tiny_video_fps-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_BITRATE_O="L-mcu_config_builder_set_output_tiny_video_bitrate-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RENDER_MODE_O="L-mcu_config_builder_set_output_video_render_mode-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_AUDIO_BITRATE_O="L-mcu_config_builder_set_output_audio_bitrate-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_COLOR_O="L-mcu_config_builder_set_output_background_color-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O="L-mcu_config_builder_add_output_background_picture-O",e.L_MCU_CONFIG_BUILDER_REMOVE_OUTPUT_BACKGROUND_PICTURE_O="L-mcu_config_builder_remove_output_background_picture-O",e.L_MCU_CONFIG_BUILDER_CLEAR_OUTPUT_BACKGROUND_PICTURE_O="L-mcu_config_builder_clear_output_background_picture-O",e.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O="L-mcu_config_builder_set_output_background_picture-fill-mode-O",e.L_MCU_CONFIG_BUILDER_ADD_PUBLISH_STREAM_URLS_O="L-mcu_config_builder_add_publish_stream_urls-O",e.L_MCU_CONFIG_BUILDER_REMOVE_PUBLISH_STREAM_URLS_O="L-mcu_config_builder_remove_publish_stream_urls-O",e.L_MCU_CONFIG_BUILDER_CLEAR_PUBLISH_STREAM_URLS_O="L-mcu_config_builder_clear_publish_stream_urls-O",e.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O="L-mcu_config_builder_add_customize_layout_video-O",e.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O="L-mcu_config_builder_remove_customize_layout_video-O",e.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_LAYOUT_VIDEO_O="L-mcu_config_builder_clear_customize_layout_video-O",e.L_MCU_CONFIG_BUILDER_SET_CUSTOMIZE_INPUT_AUDIO_O="L-mcu_config_builder_set_customize_input_audio-O",e.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O="L-mcu_config_builder_add_customize_input_audio-O",e.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O="L-mcu_config_builder_remove_customize_input_audio-O",e.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_INPUT_AUDIO_O="L-mcu_config_builder_clear_customize_input_audio-O",e.L_MCU_CONFIG_BUILDER_RESET_O="L-mcu_config_builder_reset-O",e.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O="L-mcu_config_builder_add_single_water_mark-O",e.L_MCU_CONFIG_BUILDER_REMOVE_SINGLE_WATER_MARK_O="L-mcu_config_builder_remove_single_water_mark-O",e.L_MCU_CONFIG_BUILDER_CLEAR_SINGLE_WATER_MARK_O="L-mcu_config_builder_clear_single_water_mark-O",e.L_MEDIA_SERVICE_SET_MCU_CONFIG_T="L-media_service_set_mcu_config-T",e.L_MEDIA_SERVICE_SET_MCU_CONFIG_R="L-media_service_set_mcu_config-R",e.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_T="L-media_service_get_cnd_resource_info-T",e.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_R="L-media_service_get_cnd_resource_info-R",e.L_MEDIA_SERVICE_MSLIST_CHANGE_O="L-media_service_msList_change-O",e.L_MEDIA_SERVICE_PARSE_NAVI_CALLVOIP_INFO_O="L-media_service_parse_navi_callvoip_info-O",e.L_MEDIA_SERVICE_REQUEST_T="L-media_service_request-T",e.L_MEDIA_SERVICE_REQUEST_R="L-media_service_request-R",e.L_LOCAL_TRACK_DESTROY_O="L-loacl_track_destroy-O",e.L_LOCAL_TRACK_SET_BITRATE_O="L-loacl_track_set_bitrate-O",e.L_LOCAL_TRACK_SET_LOCAL_MUTED_O="L-loacl_track_set_local_muted-O",e.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_T="L-loacl_track_set_local_muted_spread-T",e.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_R="L-loacl_track_set_local_muted_spread-R",e.L_TRACK_PLAY_O="L-track_play-O",e.L_TRACK_PLAY_E="L-track_play-E",e.L_TRACK_LOAD_START_O="L-track_load_start-O",e.L_TRACK_DURATION_CHANGE_O="L-track_duration_change-O",e.L_TRACK_LOADED_META_DATA_O="L-track_loaded_meta_data-O",e.L_TRACK_LOADED_DATA_O="L-track_loaded_data-O",e.L_TRACK_ABORT_O="L-track_abort-O",e.L_TRACK_VOLUME_CHANGE_O="L-track_volume_change-O",e.L_TRACK_CANPLAY_O="L-track_canplay-O",e.L_ABSTRACT_STAT_PARSER_FORMAT_RTC_STATE_REPORT_O="L-abstract_stat_parser_format_rtc_state_report-O",e.L_A_SDP_STRATEGY_SET_SDP_SEMANTICS_O="L-a_sdp_strategy_set_sdp_semantics-O",e.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O="L-a_sdp_strategy_set_remote_answer-O",e.L_RTC_PEER_CONNECTION_ADD_LOCAL_TRACK_O="L-rtc_peer_connection_add_local_track-O",e.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_S="L-rtc_peer_connection_ice_connection_state-S",e.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_REPORT_R="L-rtc_peer_connection_ice_connection_state_report-R",e.L_RTC_PEER_CONNECTION_CONNECTION_STATE_S="L-rtc_peer_connection_connection_state-S",e.L_RTC_PEER_CONNECTION_SET_BITRATE_O="L-rtc_peer_connection_set_bitrate-O",e.L_RTC_PEER_CONNECTION_CREATE_OFFER_O="L-rtc_peer_connection_create_offer-O",e.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_BY_ID_O="L-rtc_peer_connection_remove_local_track_by_id-O",e.L_RTC_PEER_CONNECTION_REMOVE_ALL_LOCAL_TRACK_O="L-rtc_peer_connection_remove_all_local_track-O",e.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_O="L-rtc_peer_connection_remove_local_track-O",e.L_RTC_PEER_CONNECTION_DESTROY_O="L-rtc_peer_connection_destroy-O",e.L_RTC_SET_RECOMMEND_BITRATE_O="L_rtc_set_recommend_bitrate_O",e.L_RTC_3ANOISE_NODE_O="L_RTC_AAAnoiseNode_O",e.L_RTC_3ANOISE_NODE_E="L_RTC_AAAnoiseNode_E",e.L_RTC_3ANOISE_NODE_STOP_O="L_RTC_AAAnoiseNode_Stop_O",e.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_T="L_rtc_client_join_cross_rtc_room_T",e.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_R="L_rtc_client_join_cross_rtc_room_R",e.L_QS_JOIN_ROOM_S="RTC-joinRoomRtc-S",e.L_QS_SUBSCRIBE_S="RTC-subscribe-S",e.L_QS_UNSUBSCRIBE_S="RTC-unsubscribe-S",e.L_QS_PUBLISH_S="RTC-publishRtc-S",e.L_QS_UNPUBLISH_S="RTC-unpublishRtc-S",e.L_QS_ICE_STATUS_S="RTC-iceStatus-S",e.L_QS_KICKED_S="RTC-forcedOffline-S",e.L_QS_PUB_ICE_STATUS_S="RTC-pubIceConnected-S",e.L_QS_SUB_ICE_STATUS_S="RTC-subIceConnected-S",e.L_QS_RECV_PUB_MSG_S="RTC-recvPubMsg-S",e.L_SET_ENCODER_PREFERENCES_S="RTC-set_Encoder_Preferences-S",e.L_RTCNTF_PULL_ROOM_STATUS_O="L-rtcntf_pull_room_status-O",e.L_RTCPING_PULL_ROOM_STATUS_O="L-rtcping_pull_room_status-O",e.L_PULL_ROOM_STATUS_T="L-pull_room_status-T",e.L_PULL_ROOM_STATUS_R="L-pull_room_status-R",e.L_OLD_DAILY_RECORD_O="L-old_daily_record-O",e.L_REMOTE_USER_JOINED_RESOURCES_O="L-remote_user_joined_resources-O",e.L_REMOTE_USER_STATE_HANDLE_O="L-remote_user_state_handle-O",e.L_HTTP_POLARIS_REPORT_FAIL_O="L-http_polaris_report_fail-O",e.L_UPDATE_SUBSCRIBELIST_COMMAND_T="L-update_subscribeList_command-T",e.L_UPDATE_SUBSCRIBELIST_COMMAND_P="L-update_subscribeList_command-P",e.L_UPDATE_SUBSCRIBELIST_COMMAND_R="L-update_subscribeList_command-R",e.L_RTC_CLIENT_NAVI_CHANGE_O="L-rtc_client_navi_change-O",e.L_UNPUBLISH_PREV_COMMAND_T="L-unpublish_prev_command-T",e.L_UNPUBLISH_PREV_COMMAND_R="L-unpublish_prev_command-R",e.L_RETRY_EXCHANGE_COMMAND_T="L-retry_exchange_command-T",e.L_RETRY_EXCHANGE_SPREAD_T="L-retry_exchange_spread-T",e.L_RETRY_EXCHANGE_SPREAD_R="L-retry_exchange_spread-R",e.L_PARSE_USERSTATE_COMMAND_R="L-parse_userstate_command-R",e.L_RESUB_REPUB_RES_R="L-resub_repub_res-R",e.L_PARSE_ROOMDATA_URIS_R="L-parse_roomdata_uris-R",e.L_SET_AUDIO_CONSTRAINTS_O="L-set_audio_constraints-O",e.L_FUNCTION_IS_UNAVAILABLE="L-function_is_unavailable",e.L_CLEAR_UNSUBSCRIBE_LIST_O="L-clear_unsubscribe_list-O",e.L_INVOKER_PUSH_O="L-invoker_push-O",e.L_INVOKER_EXECUTE_T="L-invoker_execute-T",e.L_INVOKER_EXECUTE_R="L-invoker_execute-R",e.L_INVOKER_DESTROY_O="L-invoker_destroy-R"}(f||(f={})),function(e){e.FAILED="fail",e.SUCCESSED="success",e.TIMEOUT="timeout",e.INFO="info"}(C||(C={}));let O=!0,L=!0;function N(e,t,i){const r=e.match(t);return r&&r.length>=i&&parseInt(r[i],10)}function A(e,t,i){if(!e.RTCPeerConnection)return;const r=e.RTCPeerConnection.prototype,n=r.addEventListener;r.addEventListener=function(e,r){if(e!==t)return n.apply(this,arguments);const o=e=>{const t=i(e);t&&(r.handleEvent?r.handleEvent(t):r(t))};return this._eventMap=this._eventMap||{},this._eventMap[t]||(this._eventMap[t]=new Map),this._eventMap[t].set(r,o),n.apply(this,[e,o])};const o=r.removeEventListener;r.removeEventListener=function(e,i){if(e!==t||!this._eventMap||!this._eventMap[t])return o.apply(this,arguments);if(!this._eventMap[t].has(i))return o.apply(this,arguments);const r=this._eventMap[t].get(i);return this._eventMap[t].delete(i),0===this._eventMap[t].size&&delete this._eventMap[t],0===Object.keys(this._eventMap).length&&delete this._eventMap,o.apply(this,[e,r])},Object.defineProperty(r,"on"+t,{get(){return this["_on"+t]},set(e){this["_on"+t]&&(this.removeEventListener(t,this["_on"+t]),delete this["_on"+t]),e&&this.addEventListener(t,this["_on"+t]=e)},enumerable:!0,configurable:!0})}function y(e){return"boolean"!=typeof e?new Error("Argument type: "+typeof e+". Please use a boolean."):(O=e,e?"adapter.js logging disabled":"adapter.js logging enabled")}function k(e){return"boolean"!=typeof e?new Error("Argument type: "+typeof e+". Please use a boolean."):(L=!e,"adapter.js deprecation warnings "+(e?"disabled":"enabled"))}function D(){if("object"==typeof window){if(O)return;"undefined"!=typeof console&&"function"==typeof console.log&&console.log.apply(console,arguments)}}function b(e,t){L&&console.warn(e+" is deprecated, please use "+t+" instead.")}function U(e){return"[object Object]"===Object.prototype.toString.call(e)}function P(e){return U(e)?Object.keys(e).reduce((function(t,i){const r=U(e[i]),n=r?P(e[i]):e[i],o=r&&!Object.keys(n).length;return void 0===n||o?t:Object.assign(t,{[i]:n})}),{}):e}function M(e,t,i){t&&!i.has(t.id)&&(i.set(t.id,t),Object.keys(t).forEach((r=>{r.endsWith("Id")?M(e,e.get(t[r]),i):r.endsWith("Ids")&&t[r].forEach((t=>{M(e,e.get(t),i)}))})))}function x(e,t,i){const r=i?"outbound-rtp":"inbound-rtp",n=new Map;if(null===t)return n;const o=[];return e.forEach((e=>{"track"===e.type&&e.trackIdentifier===t.id&&o.push(e)})),o.forEach((t=>{e.forEach((i=>{i.type===r&&i.trackId===t.id&&M(e,i,n)}))})),n}const w=D;function B(e,t){const i=e&&e.navigator;if(!i.mediaDevices)return;const r=function(e){if("object"!=typeof e||e.mandatory||e.optional)return e;const t={};return Object.keys(e).forEach((i=>{if("require"===i||"advanced"===i||"mediaSource"===i)return;const r="object"==typeof e[i]?e[i]:{ideal:e[i]};void 0!==r.exact&&"number"==typeof r.exact&&(r.min=r.max=r.exact);const n=function(e,t){return e?e+t.charAt(0).toUpperCase()+t.slice(1):"deviceId"===t?"sourceId":t};if(void 0!==r.ideal){t.optional=t.optional||[];let e={};"number"==typeof r.ideal?(e[n("min",i)]=r.ideal,t.optional.push(e),e={},e[n("max",i)]=r.ideal,t.optional.push(e)):(e[n("",i)]=r.ideal,t.optional.push(e))}void 0!==r.exact&&"number"!=typeof r.exact?(t.mandatory=t.mandatory||{},t.mandatory[n("",i)]=r.exact):["min","max"].forEach((e=>{void 0!==r[e]&&(t.mandatory=t.mandatory||{},t.mandatory[n(e,i)]=r[e])}))})),e.advanced&&(t.optional=(t.optional||[]).concat(e.advanced)),t},n=function(e,n){if(t.version>=61)return n(e);if((e=JSON.parse(JSON.stringify(e)))&&"object"==typeof e.audio){const t=function(e,t,i){t in e&&!(i in e)&&(e[i]=e[t],delete e[t])};t((e=JSON.parse(JSON.stringify(e))).audio,"autoGainControl","googAutoGainControl"),t(e.audio,"noiseSuppression","googNoiseSuppression"),e.audio=r(e.audio)}if(e&&"object"==typeof e.video){let o=e.video.facingMode;o=o&&("object"==typeof o?o:{ideal:o});const s=t.version<66;if(o&&("user"===o.exact||"environment"===o.exact||"user"===o.ideal||"environment"===o.ideal)&&(!i.mediaDevices.getSupportedConstraints||!i.mediaDevices.getSupportedConstraints().facingMode||s)){let t;if(delete e.video.facingMode,"environment"===o.exact||"environment"===o.ideal?t=["back","rear"]:"user"!==o.exact&&"user"!==o.ideal||(t=["front"]),t)return i.mediaDevices.enumerateDevices().then((i=>{let s=(i=i.filter((e=>"videoinput"===e.kind))).find((e=>t.some((t=>e.label.toLowerCase().includes(t)))));return!s&&i.length&&t.includes("back")&&(s=i[i.length-1]),s&&(e.video.deviceId=o.exact?{exact:s.deviceId}:{ideal:s.deviceId}),e.video=r(e.video),w("chrome: "+JSON.stringify(e)),n(e)}))}e.video=r(e.video)}return w("chrome: "+JSON.stringify(e)),n(e)},o=function(e){return t.version>=64?e:{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}}};if(i.getUserMedia=function(e,t,r){n(e,(e=>{i.webkitGetUserMedia(e,t,(e=>{r&&r(o(e))}))}))}.bind(i),i.mediaDevices.getUserMedia){const e=i.mediaDevices.getUserMedia.bind(i.mediaDevices);i.mediaDevices.getUserMedia=function(t){return n(t,(t=>e(t).then((e=>{if(t.audio&&!e.getAudioTracks().length||t.video&&!e.getVideoTracks().length)throw e.getTracks().forEach((e=>{e.stop()})),new DOMException("","NotFoundError");return e}),(e=>Promise.reject(o(e))))))}}}function V(e){e.MediaStream=e.MediaStream||e.webkitMediaStream}function F(e){if("object"==typeof e&&e.RTCPeerConnection&&!("ontrack"in e.RTCPeerConnection.prototype)){Object.defineProperty(e.RTCPeerConnection.prototype,"ontrack",{get(){return this._ontrack},set(e){this._ontrack&&this.removeEventListener("track",this._ontrack),this.addEventListener("track",this._ontrack=e)},enumerable:!0,configurable:!0});const t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=t=>{t.stream.addEventListener("addtrack",(i=>{let r;r=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find((e=>e.track&&e.track.id===i.track.id)):{track:i.track};const n=new Event("track");n.track=i.track,n.receiver=r,n.transceiver={receiver:r},n.streams=[t.stream],this.dispatchEvent(n)})),t.stream.getTracks().forEach((i=>{let r;r=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find((e=>e.track&&e.track.id===i.id)):{track:i};const n=new Event("track");n.track=i,n.receiver=r,n.transceiver={receiver:r},n.streams=[t.stream],this.dispatchEvent(n)}))},this.addEventListener("addstream",this._ontrackpoly)),t.apply(this,arguments)}}else A(e,"track",(e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e)))}function J(e){if("object"==typeof e&&e.RTCPeerConnection&&!("getSenders"in e.RTCPeerConnection.prototype)&&"createDTMFSender"in e.RTCPeerConnection.prototype){const t=function(e,t){return{track:t,get dtmf(){return void 0===this._dtmf&&("audio"===t.kind?this._dtmf=e.createDTMFSender(t):this._dtmf=null),this._dtmf},_pc:e}};if(!e.RTCPeerConnection.prototype.getSenders){e.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};const i=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,r){let n=i.apply(this,arguments);return n||(n=t(this,e),this._senders.push(n)),n};const r=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){r.apply(this,arguments);const t=this._senders.indexOf(e);-1!==t&&this._senders.splice(t,1)}}const i=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){this._senders=this._senders||[],i.apply(this,[e]),e.getTracks().forEach((e=>{this._senders.push(t(this,e))}))};const r=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){this._senders=this._senders||[],r.apply(this,[e]),e.getTracks().forEach((e=>{const t=this._senders.find((t=>t.track===e));t&&this._senders.splice(this._senders.indexOf(t),1)}))}}else if("object"==typeof e&&e.RTCPeerConnection&&"getSenders"in e.RTCPeerConnection.prototype&&"createDTMFSender"in e.RTCPeerConnection.prototype&&e.RTCRtpSender&&!("dtmf"in e.RTCRtpSender.prototype)){const t=e.RTCPeerConnection.prototype.getSenders;e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e},Object.defineProperty(e.RTCRtpSender.prototype,"dtmf",{get(){return void 0===this._dtmf&&("audio"===this.track.kind?this._dtmf=this._pc.createDTMFSender(this.track):this._dtmf=null),this._dtmf}})}}function G(e){if(!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){const[e,i,r]=arguments;if(arguments.length>0&&"function"==typeof e)return t.apply(this,arguments);if(0===t.length&&(0===arguments.length||"function"!=typeof e))return t.apply(this,[]);const n=function(e){const t={};return e.result().forEach((e=>{const i={id:e.id,timestamp:e.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[e.type]||e.type};e.names().forEach((t=>{i[t]=e.stat(t)})),t[i.id]=i})),t},o=function(e){return new Map(Object.keys(e).map((t=>[t,e[t]])))};if(arguments.length>=2){const r=function(e){i(o(n(e)))};return t.apply(this,[r,e])}return new Promise(((e,i)=>{t.apply(this,[function(t){e(o(n(t)))},i])})).then(i,r)}}function H(e){if(!("object"==typeof e&&e.RTCPeerConnection&&e.RTCRtpSender&&e.RTCRtpReceiver))return;if(!("getStats"in e.RTCRtpSender.prototype)){const t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e});const i=e.RTCPeerConnection.prototype.addTrack;i&&(e.RTCPeerConnection.prototype.addTrack=function(){const e=i.apply(this,arguments);return e._pc=this,e}),e.RTCRtpSender.prototype.getStats=function(){const e=this;return this._pc.getStats().then((t=>x(t,e.track,!0)))}}if(!("getStats"in e.RTCRtpReceiver.prototype)){const t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e}),A(e,"track",(e=>(e.receiver._pc=e.srcElement,e))),e.RTCRtpReceiver.prototype.getStats=function(){const e=this;return this._pc.getStats().then((t=>x(t,e.track,!1)))}}if(!("getStats"in e.RTCRtpSender.prototype)||!("getStats"in e.RTCRtpReceiver.prototype))return;const t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof e.MediaStreamTrack){const e=arguments[0];let t,i,r;return this.getSenders().forEach((i=>{i.track===e&&(t?r=!0:t=i)})),this.getReceivers().forEach((t=>(t.track===e&&(i?r=!0:i=t),t.track===e))),r||t&&i?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):t?t.getStats():i?i.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return t.apply(this,arguments)}}function K(e){e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map((e=>this._shimmedLocalStreams[e][0]))};const t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,i){if(!i)return t.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};const r=t.apply(this,arguments);return this._shimmedLocalStreams[i.id]?-1===this._shimmedLocalStreams[i.id].indexOf(r)&&this._shimmedLocalStreams[i.id].push(r):this._shimmedLocalStreams[i.id]=[i,r],r};const i=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){this._shimmedLocalStreams=this._shimmedLocalStreams||{},e.getTracks().forEach((e=>{if(this.getSenders().find((t=>t.track===e)))throw new DOMException("Track already exists.","InvalidAccessError")}));const t=this.getSenders();i.apply(this,arguments);const r=this.getSenders().filter((e=>-1===t.indexOf(e)));this._shimmedLocalStreams[e.id]=[e].concat(r)};const r=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[e.id],r.apply(this,arguments)};const n=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},e&&Object.keys(this._shimmedLocalStreams).forEach((t=>{const i=this._shimmedLocalStreams[t].indexOf(e);-1!==i&&this._shimmedLocalStreams[t].splice(i,1),1===this._shimmedLocalStreams[t].length&&delete this._shimmedLocalStreams[t]})),n.apply(this,arguments)}}function j(e,t){if(!e.RTCPeerConnection)return;if(e.RTCPeerConnection.prototype.addTrack&&t.version>=65)return K(e);const i=e.RTCPeerConnection.prototype.getLocalStreams;e.RTCPeerConnection.prototype.getLocalStreams=function(){const e=i.apply(this);return this._reverseStreams=this._reverseStreams||{},e.map((e=>this._reverseStreams[e.id]))};const r=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(t){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},t.getTracks().forEach((e=>{if(this.getSenders().find((t=>t.track===e)))throw new DOMException("Track already exists.","InvalidAccessError")})),!this._reverseStreams[t.id]){const i=new e.MediaStream(t.getTracks());this._streams[t.id]=i,this._reverseStreams[i.id]=t,t=i}r.apply(this,[t])};const n=e.RTCPeerConnection.prototype.removeStream;function o(e,t){let i=t.sdp;return Object.keys(e._reverseStreams||[]).forEach((t=>{const r=e._reverseStreams[t],n=e._streams[r.id];i=i.replace(new RegExp(n.id,"g"),r.id)})),new RTCSessionDescription({type:t.type,sdp:i})}e.RTCPeerConnection.prototype.removeStream=function(e){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},n.apply(this,[this._streams[e.id]||e]),delete this._reverseStreams[this._streams[e.id]?this._streams[e.id].id:e.id],delete this._streams[e.id]},e.RTCPeerConnection.prototype.addTrack=function(t,i){if("closed"===this.signalingState)throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");const r=[].slice.call(arguments,1);if(1!==r.length||!r[0].getTracks().find((e=>e===t)))throw new DOMException("The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.","NotSupportedError");if(this.getSenders().find((e=>e.track===t)))throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};const n=this._streams[i.id];if(n)n.addTrack(t),Promise.resolve().then((()=>{this.dispatchEvent(new Event("negotiationneeded"))}));else{const r=new e.MediaStream([t]);this._streams[i.id]=r,this._reverseStreams[r.id]=i,this.addStream(r)}return this.getSenders().find((e=>e.track===t))},["createOffer","createAnswer"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],r={[t](){const e=arguments;return arguments.length&&"function"==typeof arguments[0]?i.apply(this,[t=>{const i=o(this,t);e[0].apply(null,[i])},t=>{e[1]&&e[1].apply(null,t)},arguments[2]]):i.apply(this,arguments).then((e=>o(this,e)))}};e.RTCPeerConnection.prototype[t]=r[t]}));const s=e.RTCPeerConnection.prototype.setLocalDescription;e.RTCPeerConnection.prototype.setLocalDescription=function(){return arguments.length&&arguments[0].type?(arguments[0]=function(e,t){let i=t.sdp;return Object.keys(e._reverseStreams||[]).forEach((t=>{const r=e._reverseStreams[t],n=e._streams[r.id];i=i.replace(new RegExp(r.id,"g"),n.id)})),new RTCSessionDescription({type:t.type,sdp:i})}(this,arguments[0]),s.apply(this,arguments)):s.apply(this,arguments)};const a=Object.getOwnPropertyDescriptor(e.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(e.RTCPeerConnection.prototype,"localDescription",{get(){const e=a.get.apply(this);return""===e.type?e:o(this,e)}}),e.RTCPeerConnection.prototype.removeTrack=function(e){if("closed"===this.signalingState)throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");if(!e._pc)throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.","TypeError");if(!(e._pc===this))throw new DOMException("Sender was not created by this connection.","InvalidAccessError");let t;this._streams=this._streams||{},Object.keys(this._streams).forEach((i=>{this._streams[i].getTracks().find((t=>e.track===t))&&(t=this._streams[i])})),t&&(1===t.getTracks().length?this.removeStream(this._reverseStreams[t.id]):t.removeTrack(e.track),this.dispatchEvent(new Event("negotiationneeded")))}}function $(e,t){!e.RTCPeerConnection&&e.webkitRTCPeerConnection&&(e.RTCPeerConnection=e.webkitRTCPeerConnection),e.RTCPeerConnection&&t.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],r={[t](){return arguments[0]=new("addIceCandidate"===t?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),i.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=r[t]}))}function W(e,t){A(e,"negotiationneeded",(e=>{const i=e.target;if(!(t.version<72||i.getConfiguration&&"plan-b"===i.getConfiguration().sdpSemantics)||"stable"===i.signalingState)return e}))}var Y=Object.freeze({__proto__:null,shimMediaStream:V,shimOnTrack:F,shimGetSendersWithDtmf:J,shimGetStats:G,shimSenderReceiverGetStats:H,shimAddTrackRemoveTrackWithNative:K,shimAddTrackRemoveTrack:j,shimPeerConnection:$,fixNegotiationNeeded:W,shimGetUserMedia:B,shimGetDisplayMedia:function(e,t){e.navigator.mediaDevices&&"getDisplayMedia"in e.navigator.mediaDevices||e.navigator.mediaDevices&&("function"==typeof t?e.navigator.mediaDevices.getDisplayMedia=function(i){return t(i).then((t=>{const r=i.video&&i.video.width,n=i.video&&i.video.height,o=i.video&&i.video.frameRate;return i.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:t,maxFrameRate:o||3}},r&&(i.video.mandatory.maxWidth=r),n&&(i.video.mandatory.maxHeight=n),e.navigator.mediaDevices.getUserMedia(i)}))}:console.error("shimGetDisplayMedia: getSourceId argument is not a function"))}});var q,z,Q=(q=function(e){var t={generateIdentifier:function(){return Math.random().toString(36).substr(2,10)}};t.localCName=t.generateIdentifier(),t.splitLines=function(e){return e.trim().split("\n").map((function(e){return e.trim()}))},t.splitSections=function(e){return e.split("\nm=").map((function(e,t){return(t>0?"m="+e:e).trim()+"\r\n"}))},t.getDescription=function(e){var i=t.splitSections(e);return i&&i[0]},t.getMediaSections=function(e){var i=t.splitSections(e);return i.shift(),i},t.matchPrefix=function(e,i){return t.splitLines(e).filter((function(e){return 0===e.indexOf(i)}))},t.parseCandidate=function(e){for(var t,i={foundation:(t=0===e.indexOf("a=candidate:")?e.substring(12).split(" "):e.substring(10).split(" "))[0],component:parseInt(t[1],10),protocol:t[2].toLowerCase(),priority:parseInt(t[3],10),ip:t[4],address:t[4],port:parseInt(t[5],10),type:t[7]},r=8;r<t.length;r+=2)switch(t[r]){case"raddr":i.relatedAddress=t[r+1];break;case"rport":i.relatedPort=parseInt(t[r+1],10);break;case"tcptype":i.tcpType=t[r+1];break;case"ufrag":i.ufrag=t[r+1],i.usernameFragment=t[r+1];break;default:i[t[r]]=t[r+1]}return i},t.writeCandidate=function(e){var t=[];t.push(e.foundation),t.push(e.component),t.push(e.protocol.toUpperCase()),t.push(e.priority),t.push(e.address||e.ip),t.push(e.port);var i=e.type;return t.push("typ"),t.push(i),"host"!==i&&e.relatedAddress&&e.relatedPort&&(t.push("raddr"),t.push(e.relatedAddress),t.push("rport"),t.push(e.relatedPort)),e.tcpType&&"tcp"===e.protocol.toLowerCase()&&(t.push("tcptype"),t.push(e.tcpType)),(e.usernameFragment||e.ufrag)&&(t.push("ufrag"),t.push(e.usernameFragment||e.ufrag)),"candidate:"+t.join(" ")},t.parseIceOptions=function(e){return e.substr(14).split(" ")},t.parseRtpMap=function(e){var t=e.substr(9).split(" "),i={payloadType:parseInt(t.shift(),10)};return t=t[0].split("/"),i.name=t[0],i.clockRate=parseInt(t[1],10),i.channels=3===t.length?parseInt(t[2],10):1,i.numChannels=i.channels,i},t.writeRtpMap=function(e){var t=e.payloadType;void 0!==e.preferredPayloadType&&(t=e.preferredPayloadType);var i=e.channels||e.numChannels||1;return"a=rtpmap:"+t+" "+e.name+"/"+e.clockRate+(1!==i?"/"+i:"")+"\r\n"},t.parseExtmap=function(e){var t=e.substr(9).split(" ");return{id:parseInt(t[0],10),direction:t[0].indexOf("/")>0?t[0].split("/")[1]:"sendrecv",uri:t[1]}},t.writeExtmap=function(e){return"a=extmap:"+(e.id||e.preferredId)+(e.direction&&"sendrecv"!==e.direction?"/"+e.direction:"")+" "+e.uri+"\r\n"},t.parseFmtp=function(e){for(var t,i={},r=e.substr(e.indexOf(" ")+1).split(";"),n=0;n<r.length;n++)i[(t=r[n].trim().split("="))[0].trim()]=t[1];return i},t.writeFmtp=function(e){var t="",i=e.payloadType;if(void 0!==e.preferredPayloadType&&(i=e.preferredPayloadType),e.parameters&&Object.keys(e.parameters).length){var r=[];Object.keys(e.parameters).forEach((function(t){e.parameters[t]?r.push(t+"="+e.parameters[t]):r.push(t)})),t+="a=fmtp:"+i+" "+r.join(";")+"\r\n"}return t},t.parseRtcpFb=function(e){var t=e.substr(e.indexOf(" ")+1).split(" ");return{type:t.shift(),parameter:t.join(" ")}},t.writeRtcpFb=function(e){var t="",i=e.payloadType;return void 0!==e.preferredPayloadType&&(i=e.preferredPayloadType),e.rtcpFeedback&&e.rtcpFeedback.length&&e.rtcpFeedback.forEach((function(e){t+="a=rtcp-fb:"+i+" "+e.type+(e.parameter&&e.parameter.length?" "+e.parameter:"")+"\r\n"})),t},t.parseSsrcMedia=function(e){var t=e.indexOf(" "),i={ssrc:parseInt(e.substr(7,t-7),10)},r=e.indexOf(":",t);return r>-1?(i.attribute=e.substr(t+1,r-t-1),i.value=e.substr(r+1)):i.attribute=e.substr(t+1),i},t.parseSsrcGroup=function(e){var t=e.substr(13).split(" ");return{semantics:t.shift(),ssrcs:t.map((function(e){return parseInt(e,10)}))}},t.getMid=function(e){var i=t.matchPrefix(e,"a=mid:")[0];if(i)return i.substr(6)},t.parseFingerprint=function(e){var t=e.substr(14).split(" ");return{algorithm:t[0].toLowerCase(),value:t[1]}},t.getDtlsParameters=function(e,i){return{role:"auto",fingerprints:t.matchPrefix(e+i,"a=fingerprint:").map(t.parseFingerprint)}},t.writeDtlsParameters=function(e,t){var i="a=setup:"+t+"\r\n";return e.fingerprints.forEach((function(e){i+="a=fingerprint:"+e.algorithm+" "+e.value+"\r\n"})),i},t.parseCryptoLine=function(e){var t=e.substr(9).split(" ");return{tag:parseInt(t[0],10),cryptoSuite:t[1],keyParams:t[2],sessionParams:t.slice(3)}},t.writeCryptoLine=function(e){return"a=crypto:"+e.tag+" "+e.cryptoSuite+" "+("object"==typeof e.keyParams?t.writeCryptoKeyParams(e.keyParams):e.keyParams)+(e.sessionParams?" "+e.sessionParams.join(" "):"")+"\r\n"},t.parseCryptoKeyParams=function(e){if(0!==e.indexOf("inline:"))return null;var t=e.substr(7).split("|");return{keyMethod:"inline",keySalt:t[0],lifeTime:t[1],mkiValue:t[2]?t[2].split(":")[0]:void 0,mkiLength:t[2]?t[2].split(":")[1]:void 0}},t.writeCryptoKeyParams=function(e){return e.keyMethod+":"+e.keySalt+(e.lifeTime?"|"+e.lifeTime:"")+(e.mkiValue&&e.mkiLength?"|"+e.mkiValue+":"+e.mkiLength:"")},t.getCryptoParameters=function(e,i){return t.matchPrefix(e+i,"a=crypto:").map(t.parseCryptoLine)},t.getIceParameters=function(e,i){var r=t.matchPrefix(e+i,"a=ice-ufrag:")[0],n=t.matchPrefix(e+i,"a=ice-pwd:")[0];return r&&n?{usernameFragment:r.substr(12),password:n.substr(10)}:null},t.writeIceParameters=function(e){return"a=ice-ufrag:"+e.usernameFragment+"\r\na=ice-pwd:"+e.password+"\r\n"},t.parseRtpParameters=function(e){for(var i={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},r=t.splitLines(e)[0].split(" "),n=3;n<r.length;n++){var o=r[n],s=t.matchPrefix(e,"a=rtpmap:"+o+" ")[0];if(s){var a=t.parseRtpMap(s),c=t.matchPrefix(e,"a=fmtp:"+o+" ");switch(a.parameters=c.length?t.parseFmtp(c[0]):{},a.rtcpFeedback=t.matchPrefix(e,"a=rtcp-fb:"+o+" ").map(t.parseRtcpFb),i.codecs.push(a),a.name.toUpperCase()){case"RED":case"ULPFEC":i.fecMechanisms.push(a.name.toUpperCase())}}}return t.matchPrefix(e,"a=extmap:").forEach((function(e){i.headerExtensions.push(t.parseExtmap(e))})),i},t.writeRtpDescription=function(e,i){var r="";r+="m="+e+" ",r+=i.codecs.length>0?"9":"0",r+=" UDP/TLS/RTP/SAVPF ",r+=i.codecs.map((function(e){return void 0!==e.preferredPayloadType?e.preferredPayloadType:e.payloadType})).join(" ")+"\r\n",r+="c=IN IP4 0.0.0.0\r\n",r+="a=rtcp:9 IN IP4 0.0.0.0\r\n",i.codecs.forEach((function(e){r+=t.writeRtpMap(e),r+=t.writeFmtp(e),r+=t.writeRtcpFb(e)}));var n=0;return i.codecs.forEach((function(e){e.maxptime>n&&(n=e.maxptime)})),n>0&&(r+="a=maxptime:"+n+"\r\n"),r+="a=rtcp-mux\r\n",i.headerExtensions&&i.headerExtensions.forEach((function(e){r+=t.writeExtmap(e)})),r},t.parseRtpEncodingParameters=function(e){var i,r=[],n=t.parseRtpParameters(e),o=-1!==n.fecMechanisms.indexOf("RED"),s=-1!==n.fecMechanisms.indexOf("ULPFEC"),a=t.matchPrefix(e,"a=ssrc:").map((function(e){return t.parseSsrcMedia(e)})).filter((function(e){return"cname"===e.attribute})),c=a.length>0&&a[0].ssrc,d=t.matchPrefix(e,"a=ssrc-group:FID").map((function(e){return e.substr(17).split(" ").map((function(e){return parseInt(e,10)}))}));d.length>0&&d[0].length>1&&d[0][0]===c&&(i=d[0][1]),n.codecs.forEach((function(e){if("RTX"===e.name.toUpperCase()&&e.parameters.apt){var t={ssrc:c,codecPayloadType:parseInt(e.parameters.apt,10)};c&&i&&(t.rtx={ssrc:i}),r.push(t),o&&((t=JSON.parse(JSON.stringify(t))).fec={ssrc:c,mechanism:s?"red+ulpfec":"red"},r.push(t))}})),0===r.length&&c&&r.push({ssrc:c});var _=t.matchPrefix(e,"b=");return _.length&&(_=0===_[0].indexOf("b=TIAS:")?parseInt(_[0].substr(7),10):0===_[0].indexOf("b=AS:")?1e3*parseInt(_[0].substr(5),10)*.95-16e3:void 0,r.forEach((function(e){e.maxBitrate=_}))),r},t.parseRtcpParameters=function(e){var i={},r=t.matchPrefix(e,"a=ssrc:").map((function(e){return t.parseSsrcMedia(e)})).filter((function(e){return"cname"===e.attribute}))[0];r&&(i.cname=r.value,i.ssrc=r.ssrc);var n=t.matchPrefix(e,"a=rtcp-rsize");i.reducedSize=n.length>0,i.compound=0===n.length;var o=t.matchPrefix(e,"a=rtcp-mux");return i.mux=o.length>0,i},t.parseMsid=function(e){var i,r=t.matchPrefix(e,"a=msid:");if(1===r.length)return{stream:(i=r[0].substr(7).split(" "))[0],track:i[1]};var n=t.matchPrefix(e,"a=ssrc:").map((function(e){return t.parseSsrcMedia(e)})).filter((function(e){return"msid"===e.attribute}));return n.length>0?{stream:(i=n[0].value.split(" "))[0],track:i[1]}:void 0},t.parseSctpDescription=function(e){var i,r=t.parseMLine(e),n=t.matchPrefix(e,"a=max-message-size:");n.length>0&&(i=parseInt(n[0].substr(19),10)),isNaN(i)&&(i=65536);var o=t.matchPrefix(e,"a=sctp-port:");if(o.length>0)return{port:parseInt(o[0].substr(12),10),protocol:r.fmt,maxMessageSize:i};if(t.matchPrefix(e,"a=sctpmap:").length>0){var s=t.matchPrefix(e,"a=sctpmap:")[0].substr(10).split(" ");return{port:parseInt(s[0],10),protocol:s[1],maxMessageSize:i}}},t.writeSctpDescription=function(e,t){var i=[];return i="DTLS/SCTP"!==e.protocol?["m="+e.kind+" 9 "+e.protocol+" "+t.protocol+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctp-port:"+t.port+"\r\n"]:["m="+e.kind+" 9 "+e.protocol+" "+t.port+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctpmap:"+t.port+" "+t.protocol+" 65535\r\n"],void 0!==t.maxMessageSize&&i.push("a=max-message-size:"+t.maxMessageSize+"\r\n"),i.join("")},t.generateSessionId=function(){return Math.random().toString().substr(2,21)},t.writeSessionBoilerplate=function(e,i,r){var n=void 0!==i?i:2;return"v=0\r\no="+(r||"thisisadapterortc")+" "+(e||t.generateSessionId())+" "+n+" IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"},t.writeMediaSection=function(e,i,r,n){var o=t.writeRtpDescription(e.kind,i);if(o+=t.writeIceParameters(e.iceGatherer.getLocalParameters()),o+=t.writeDtlsParameters(e.dtlsTransport.getLocalParameters(),"offer"===r?"actpass":"active"),o+="a=mid:"+e.mid+"\r\n",e.direction?o+="a="+e.direction+"\r\n":e.rtpSender&&e.rtpReceiver?o+="a=sendrecv\r\n":e.rtpSender?o+="a=sendonly\r\n":e.rtpReceiver?o+="a=recvonly\r\n":o+="a=inactive\r\n",e.rtpSender){var s="msid:"+n.id+" "+e.rtpSender.track.id+"\r\n";o+="a="+s,o+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" "+s,e.sendEncodingParameters[0].rtx&&(o+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" "+s,o+="a=ssrc-group:FID "+e.sendEncodingParameters[0].ssrc+" "+e.sendEncodingParameters[0].rtx.ssrc+"\r\n")}return o+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" cname:"+t.localCName+"\r\n",e.rtpSender&&e.sendEncodingParameters[0].rtx&&(o+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" cname:"+t.localCName+"\r\n"),o},t.getDirection=function(e,i){for(var r=t.splitLines(e),n=0;n<r.length;n++)switch(r[n]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return r[n].substr(2)}return i?t.getDirection(i):"sendrecv"},t.getKind=function(e){return t.splitLines(e)[0].split(" ")[0].substr(2)},t.isRejected=function(e){return"0"===e.split(" ",2)[1]},t.parseMLine=function(e){var i=t.splitLines(e)[0].substr(2).split(" ");return{kind:i[0],port:parseInt(i[1],10),protocol:i[2],fmt:i.slice(3).join(" ")}},t.parseOLine=function(e){var i=t.matchPrefix(e,"o=")[0].substr(2).split(" ");return{username:i[0],sessionId:i[1],sessionVersion:parseInt(i[2],10),netType:i[3],addressType:i[4],address:i[5]}},t.isValidSDP=function(e){if("string"!=typeof e||0===e.length)return!1;for(var i=t.splitLines(e),r=0;r<i.length;r++)if(i[r].length<2||"="!==i[r].charAt(1))return!1;return!0},e.exports=t},q(z={exports:{}},z.exports),z.exports);function Z(e,t,i,r,n){var o=Q.writeRtpDescription(e.kind,t);if(o+=Q.writeIceParameters(e.iceGatherer.getLocalParameters()),o+=Q.writeDtlsParameters(e.dtlsTransport.getLocalParameters(),"offer"===i?"actpass":n||"active"),o+="a=mid:"+e.mid+"\r\n",e.rtpSender&&e.rtpReceiver?o+="a=sendrecv\r\n":e.rtpSender?o+="a=sendonly\r\n":e.rtpReceiver?o+="a=recvonly\r\n":o+="a=inactive\r\n",e.rtpSender){var s=e.rtpSender._initialTrackId||e.rtpSender.track.id;e.rtpSender._initialTrackId=s;var a="msid:"+(r?r.id:"-")+" "+s+"\r\n";o+="a="+a,o+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" "+a,e.sendEncodingParameters[0].rtx&&(o+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" "+a,o+="a=ssrc-group:FID "+e.sendEncodingParameters[0].ssrc+" "+e.sendEncodingParameters[0].rtx.ssrc+"\r\n")}return o+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" cname:"+Q.localCName+"\r\n",e.rtpSender&&e.sendEncodingParameters[0].rtx&&(o+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" cname:"+Q.localCName+"\r\n"),o}function X(e,t){var i={codecs:[],headerExtensions:[],fecMechanisms:[]},r=function(e,t){e=parseInt(e,10);for(var i=0;i<t.length;i++)if(t[i].payloadType===e||t[i].preferredPayloadType===e)return t[i]},n=function(e,t,i,n){var o=r(e.parameters.apt,i),s=r(t.parameters.apt,n);return o&&s&&o.name.toLowerCase()===s.name.toLowerCase()};return e.codecs.forEach((function(r){for(var o=0;o<t.codecs.length;o++){var s=t.codecs[o];if(r.name.toLowerCase()===s.name.toLowerCase()&&r.clockRate===s.clockRate){if("rtx"===r.name.toLowerCase()&&r.parameters&&s.parameters.apt&&!n(r,s,e.codecs,t.codecs))continue;(s=JSON.parse(JSON.stringify(s))).numChannels=Math.min(r.numChannels,s.numChannels),i.codecs.push(s),s.rtcpFeedback=s.rtcpFeedback.filter((function(e){for(var t=0;t<r.rtcpFeedback.length;t++)if(r.rtcpFeedback[t].type===e.type&&r.rtcpFeedback[t].parameter===e.parameter)return!0;return!1}));break}}})),e.headerExtensions.forEach((function(e){for(var r=0;r<t.headerExtensions.length;r++){var n=t.headerExtensions[r];if(e.uri===n.uri){i.headerExtensions.push(n);break}}})),i}function ee(e,t,i){return-1!=={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"]}}[t][e].indexOf(i)}function te(e,t){var i=e.getRemoteCandidates().find((function(e){return t.foundation===e.foundation&&t.ip===e.ip&&t.port===e.port&&t.priority===e.priority&&t.protocol===e.protocol&&t.type===e.type}));return i||e.addRemoteCandidate(t),!i}function ie(e,t){var i=new Error(t);return i.name=e,i.code={NotSupportedError:9,InvalidStateError:11,InvalidAccessError:15,TypeError:void 0,OperationError:void 0}[e],i}var re=function(e,t){function i(t,i){i.addTrack(t),i.dispatchEvent(new e.MediaStreamTrackEvent("addtrack",{track:t}))}function r(t,i,r,n){var o=new Event("track");o.track=i,o.receiver=r,o.transceiver={receiver:r},o.streams=n,e.setTimeout((function(){t._dispatchEvent("track",o)}))}var n=function(i){var r=this,n=document.createDocumentFragment();if(["addEventListener","removeEventListener","dispatchEvent"].forEach((function(e){r[e]=n[e].bind(n)})),this.canTrickleIceCandidates=null,this.needNegotiation=!1,this.localStreams=[],this.remoteStreams=[],this._localDescription=null,this._remoteDescription=null,this.signalingState="stable",this.iceConnectionState="new",this.connectionState="new",this.iceGatheringState="new",i=JSON.parse(JSON.stringify(i||{})),this.usingBundle="max-bundle"===i.bundlePolicy,"negotiate"===i.rtcpMuxPolicy)throw ie("NotSupportedError","rtcpMuxPolicy 'negotiate' is not supported");switch(i.rtcpMuxPolicy||(i.rtcpMuxPolicy="require"),i.iceTransportPolicy){case"all":case"relay":break;default:i.iceTransportPolicy="all"}switch(i.bundlePolicy){case"balanced":case"max-compat":case"max-bundle":break;default:i.bundlePolicy="balanced"}if(i.iceServers=function(e,t){var i=!1;return(e=JSON.parse(JSON.stringify(e))).filter((function(e){if(e&&(e.urls||e.url)){var r=e.urls||e.url;e.url&&!e.urls&&console.warn("RTCIceServer.url is deprecated! Use urls instead.");var n="string"==typeof r;return n&&(r=[r]),r=r.filter((function(e){return 0!==e.indexOf("turn:")||-1===e.indexOf("transport=udp")||-1!==e.indexOf("turn:[")||i?0===e.indexOf("stun:")&&t>=14393&&-1===e.indexOf("?transport=udp"):(i=!0,!0)})),delete e.url,e.urls=n?r[0]:r,!!r.length}}))}(i.iceServers||[],t),this._iceGatherers=[],i.iceCandidatePoolSize)for(var o=i.iceCandidatePoolSize;o>0;o--)this._iceGatherers.push(new e.RTCIceGatherer({iceServers:i.iceServers,gatherPolicy:i.iceTransportPolicy}));else i.iceCandidatePoolSize=0;this._config=i,this.transceivers=[],this._sdpSessionId=Q.generateSessionId(),this._sdpSessionVersion=0,this._dtlsRole=void 0,this._isClosed=!1};Object.defineProperty(n.prototype,"localDescription",{configurable:!0,get:function(){return this._localDescription}}),Object.defineProperty(n.prototype,"remoteDescription",{configurable:!0,get:function(){return this._remoteDescription}}),n.prototype.onicecandidate=null,n.prototype.onaddstream=null,n.prototype.ontrack=null,n.prototype.onremovestream=null,n.prototype.onsignalingstatechange=null,n.prototype.oniceconnectionstatechange=null,n.prototype.onconnectionstatechange=null,n.prototype.onicegatheringstatechange=null,n.prototype.onnegotiationneeded=null,n.prototype.ondatachannel=null,n.prototype._dispatchEvent=function(e,t){this._isClosed||(this.dispatchEvent(t),"function"==typeof this["on"+e]&&this["on"+e](t))},n.prototype._emitGatheringStateChange=function(){var e=new Event("icegatheringstatechange");this._dispatchEvent("icegatheringstatechange",e)},n.prototype.getConfiguration=function(){return this._config},n.prototype.getLocalStreams=function(){return this.localStreams},n.prototype.getRemoteStreams=function(){return this.remoteStreams},n.prototype._createTransceiver=function(e,t){var i=this.transceivers.length>0,r={track:null,iceGatherer:null,iceTransport:null,dtlsTransport:null,localCapabilities:null,remoteCapabilities:null,rtpSender:null,rtpReceiver:null,kind:e,mid:null,sendEncodingParameters:null,recvEncodingParameters:null,stream:null,associatedRemoteMediaStreams:[],wantReceive:!0};if(this.usingBundle&&i)r.iceTransport=this.transceivers[0].iceTransport,r.dtlsTransport=this.transceivers[0].dtlsTransport;else{var n=this._createIceAndDtlsTransports();r.iceTransport=n.iceTransport,r.dtlsTransport=n.dtlsTransport}return t||this.transceivers.push(r),r},n.prototype.addTrack=function(t,i){if(this._isClosed)throw ie("InvalidStateError","Attempted to call addTrack on a closed peerconnection.");var r;if(this.transceivers.find((function(e){return e.track===t})))throw ie("InvalidAccessError","Track already exists.");for(var n=0;n<this.transceivers.length;n++)this.transceivers[n].track||this.transceivers[n].kind!==t.kind||(r=this.transceivers[n]);return r||(r=this._createTransceiver(t.kind)),this._maybeFireNegotiationNeeded(),-1===this.localStreams.indexOf(i)&&this.localStreams.push(i),r.track=t,r.stream=i,r.rtpSender=new e.RTCRtpSender(t,r.dtlsTransport),r.rtpSender},n.prototype.addStream=function(e){var i=this;if(t>=15025)e.getTracks().forEach((function(t){i.addTrack(t,e)}));else{var r=e.clone();e.getTracks().forEach((function(e,t){var i=r.getTracks()[t];e.addEventListener("enabled",(function(e){i.enabled=e.enabled}))})),r.getTracks().forEach((function(e){i.addTrack(e,r)}))}},n.prototype.removeTrack=function(t){if(this._isClosed)throw ie("InvalidStateError","Attempted to call removeTrack on a closed peerconnection.");if(!(t instanceof e.RTCRtpSender))throw new TypeError("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.");var i=this.transceivers.find((function(e){return e.rtpSender===t}));if(!i)throw ie("InvalidAccessError","Sender was not created by this connection.");var r=i.stream;i.rtpSender.stop(),i.rtpSender=null,i.track=null,i.stream=null,-1===this.transceivers.map((function(e){return e.stream})).indexOf(r)&&this.localStreams.indexOf(r)>-1&&this.localStreams.splice(this.localStreams.indexOf(r),1),this._maybeFireNegotiationNeeded()},n.prototype.removeStream=function(e){var t=this;e.getTracks().forEach((function(e){var i=t.getSenders().find((function(t){return t.track===e}));i&&t.removeTrack(i)}))},n.prototype.getSenders=function(){return this.transceivers.filter((function(e){return!!e.rtpSender})).map((function(e){return e.rtpSender}))},n.prototype.getReceivers=function(){return this.transceivers.filter((function(e){return!!e.rtpReceiver})).map((function(e){return e.rtpReceiver}))},n.prototype._createIceGatherer=function(t,i){var r=this;if(i&&t>0)return this.transceivers[0].iceGatherer;if(this._iceGatherers.length)return this._iceGatherers.shift();var n=new e.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(n,"state",{value:"new",writable:!0}),this.transceivers[t].bufferedCandidateEvents=[],this.transceivers[t].bufferCandidates=function(e){var i=!e.candidate||0===Object.keys(e.candidate).length;n.state=i?"completed":"gathering",null!==r.transceivers[t].bufferedCandidateEvents&&r.transceivers[t].bufferedCandidateEvents.push(e)},n.addEventListener("localcandidate",this.transceivers[t].bufferCandidates),n},n.prototype._gather=function(t,i){var r=this,n=this.transceivers[i].iceGatherer;if(!n.onlocalcandidate){var o=this.transceivers[i].bufferedCandidateEvents;this.transceivers[i].bufferedCandidateEvents=null,n.removeEventListener("localcandidate",this.transceivers[i].bufferCandidates),n.onlocalcandidate=function(e){if(!(r.usingBundle&&i>0)){var o=new Event("icecandidate");o.candidate={sdpMid:t,sdpMLineIndex:i};var s=e.candidate,a=!s||0===Object.keys(s).length;if(a)"new"!==n.state&&"gathering"!==n.state||(n.state="completed");else{"new"===n.state&&(n.state="gathering"),s.component=1,s.ufrag=n.getLocalParameters().usernameFragment;var c=Q.writeCandidate(s);o.candidate=Object.assign(o.candidate,Q.parseCandidate(c)),o.candidate.candidate=c,o.candidate.toJSON=function(){return{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex,usernameFragment:o.candidate.usernameFragment}}}var d=Q.getMediaSections(r._localDescription.sdp);d[o.candidate.sdpMLineIndex]+=a?"a=end-of-candidates\r\n":"a="+o.candidate.candidate+"\r\n",r._localDescription.sdp=Q.getDescription(r._localDescription.sdp)+d.join("");var _=r.transceivers.every((function(e){return e.iceGatherer&&"completed"===e.iceGatherer.state}));"gathering"!==r.iceGatheringState&&(r.iceGatheringState="gathering",r._emitGatheringStateChange()),a||r._dispatchEvent("icecandidate",o),_&&(r._dispatchEvent("icecandidate",new Event("icecandidate")),r.iceGatheringState="complete",r._emitGatheringStateChange())}},e.setTimeout((function(){o.forEach((function(e){n.onlocalcandidate(e)}))}),0)}},n.prototype._createIceAndDtlsTransports=function(){var t=this,i=new e.RTCIceTransport(null);i.onicestatechange=function(){t._updateIceConnectionState(),t._updateConnectionState()};var r=new e.RTCDtlsTransport(i);return r.ondtlsstatechange=function(){t._updateConnectionState()},r.onerror=function(){Object.defineProperty(r,"state",{value:"failed",writable:!0}),t._updateConnectionState()},{iceTransport:i,dtlsTransport:r}},n.prototype._disposeIceAndDtlsTransports=function(e){var t=this.transceivers[e].iceGatherer;t&&(delete t.onlocalcandidate,delete this.transceivers[e].iceGatherer);var i=this.transceivers[e].iceTransport;i&&(delete i.onicestatechange,delete this.transceivers[e].iceTransport);var r=this.transceivers[e].dtlsTransport;r&&(delete r.ondtlsstatechange,delete r.onerror,delete this.transceivers[e].dtlsTransport)},n.prototype._transceive=function(e,i,r){var n=X(e.localCapabilities,e.remoteCapabilities);i&&e.rtpSender&&(n.encodings=e.sendEncodingParameters,n.rtcp={cname:Q.localCName,compound:e.rtcpParameters.compound},e.recvEncodingParameters.length&&(n.rtcp.ssrc=e.recvEncodingParameters[0].ssrc),e.rtpSender.send(n)),r&&e.rtpReceiver&&n.codecs.length>0&&("video"===e.kind&&e.recvEncodingParameters&&t<15019&&e.recvEncodingParameters.forEach((function(e){delete e.rtx})),e.recvEncodingParameters.length?n.encodings=e.recvEncodingParameters:n.encodings=[{}],n.rtcp={compound:e.rtcpParameters.compound},e.rtcpParameters.cname&&(n.rtcp.cname=e.rtcpParameters.cname),e.sendEncodingParameters.length&&(n.rtcp.ssrc=e.sendEncodingParameters[0].ssrc),e.rtpReceiver.receive(n))},n.prototype.setLocalDescription=function(e){var t,i,r=this;if(-1===["offer","answer"].indexOf(e.type))return Promise.reject(ie("TypeError",'Unsupported type "'+e.type+'"'));if(!ee("setLocalDescription",e.type,r.signalingState)||r._isClosed)return Promise.reject(ie("InvalidStateError","Can not set local "+e.type+" in state "+r.signalingState));if("offer"===e.type)t=Q.splitSections(e.sdp),i=t.shift(),t.forEach((function(e,t){var i=Q.parseRtpParameters(e);r.transceivers[t].localCapabilities=i})),r.transceivers.forEach((function(e,t){r._gather(e.mid,t)}));else if("answer"===e.type){t=Q.splitSections(r._remoteDescription.sdp),i=t.shift();var n=Q.matchPrefix(i,"a=ice-lite").length>0;t.forEach((function(e,t){var o=r.transceivers[t],s=o.iceGatherer,a=o.iceTransport,c=o.dtlsTransport,d=o.localCapabilities,_=o.remoteCapabilities;if(!(Q.isRejected(e)&&0===Q.matchPrefix(e,"a=bundle-only").length)&&!o.rejected){var l=Q.getIceParameters(e,i),u=Q.getDtlsParameters(e,i);n&&(u.role="server"),r.usingBundle&&0!==t||(r._gather(o.mid,t),"new"===a.state&&a.start(s,l,n?"controlling":"controlled"),"new"===c.state&&c.start(u));var h=X(d,_);r._transceive(o,h.codecs.length>0,!1)}}))}return r._localDescription={type:e.type,sdp:e.sdp},"offer"===e.type?r._updateSignalingState("have-local-offer"):r._updateSignalingState("stable"),Promise.resolve()},n.prototype.setRemoteDescription=function(n){var o=this;if(-1===["offer","answer"].indexOf(n.type))return Promise.reject(ie("TypeError",'Unsupported type "'+n.type+'"'));if(!ee("setRemoteDescription",n.type,o.signalingState)||o._isClosed)return Promise.reject(ie("InvalidStateError","Can not set remote "+n.type+" in state "+o.signalingState));var s={};o.remoteStreams.forEach((function(e){s[e.id]=e}));var a=[],c=Q.splitSections(n.sdp),d=c.shift(),_=Q.matchPrefix(d,"a=ice-lite").length>0,l=Q.matchPrefix(d,"a=group:BUNDLE ").length>0;o.usingBundle=l;var u=Q.matchPrefix(d,"a=ice-options:")[0];return o.canTrickleIceCandidates=!!u&&u.substr(14).split(" ").indexOf("trickle")>=0,c.forEach((function(r,c){var u=Q.splitLines(r),h=Q.getKind(r),g=Q.isRejected(r)&&0===Q.matchPrefix(r,"a=bundle-only").length,v=u[0].substr(2).split(" ")[2],p=Q.getDirection(r,d),R=Q.parseMsid(r),m=Q.getMid(r)||Q.generateIdentifier();if(g||"application"===h&&("DTLS/SCTP"===v||"UDP/DTLS/SCTP"===v))o.transceivers[c]={mid:m,kind:h,protocol:v,rejected:!0};else{var I,E,S,T,f,C,O,L,N;!g&&o.transceivers[c]&&o.transceivers[c].rejected&&(o.transceivers[c]=o._createTransceiver(h,!0));var A,y,k=Q.parseRtpParameters(r);g||(A=Q.getIceParameters(r,d),(y=Q.getDtlsParameters(r,d)).role="client"),O=Q.parseRtpEncodingParameters(r);var D=Q.parseRtcpParameters(r),b=Q.matchPrefix(r,"a=end-of-candidates",d).length>0,U=Q.matchPrefix(r,"a=candidate:").map((function(e){return Q.parseCandidate(e)})).filter((function(e){return 1===e.component}));if(("offer"===n.type||"answer"===n.type)&&!g&&l&&c>0&&o.transceivers[c]&&(o._disposeIceAndDtlsTransports(c),o.transceivers[c].iceGatherer=o.transceivers[0].iceGatherer,o.transceivers[c].iceTransport=o.transceivers[0].iceTransport,o.transceivers[c].dtlsTransport=o.transceivers[0].dtlsTransport,o.transceivers[c].rtpSender&&o.transceivers[c].rtpSender.setTransport(o.transceivers[0].dtlsTransport),o.transceivers[c].rtpReceiver&&o.transceivers[c].rtpReceiver.setTransport(o.transceivers[0].dtlsTransport)),"offer"!==n.type||g){if("answer"===n.type&&!g){E=(I=o.transceivers[c]).iceGatherer,S=I.iceTransport,T=I.dtlsTransport,f=I.rtpReceiver,C=I.sendEncodingParameters,L=I.localCapabilities,o.transceivers[c].recvEncodingParameters=O,o.transceivers[c].remoteCapabilities=k,o.transceivers[c].rtcpParameters=D,U.length&&"new"===S.state&&(!_&&!b||l&&0!==c?U.forEach((function(e){te(I.iceTransport,e)})):S.setRemoteCandidates(U)),l&&0!==c||("new"===S.state&&S.start(E,A,"controlling"),"new"===T.state&&T.start(y)),!X(I.localCapabilities,I.remoteCapabilities).codecs.filter((function(e){return"rtx"===e.name.toLowerCase()})).length&&I.sendEncodingParameters[0].rtx&&delete I.sendEncodingParameters[0].rtx,o._transceive(I,"sendrecv"===p||"recvonly"===p,"sendrecv"===p||"sendonly"===p),!f||"sendrecv"!==p&&"sendonly"!==p?delete I.rtpReceiver:(N=f.track,R?(s[R.stream]||(s[R.stream]=new e.MediaStream),i(N,s[R.stream]),a.push([N,f,s[R.stream]])):(s.default||(s.default=new e.MediaStream),i(N,s.default),a.push([N,f,s.default])))}}else{(I=o.transceivers[c]||o._createTransceiver(h)).mid=m,I.iceGatherer||(I.iceGatherer=o._createIceGatherer(c,l)),U.length&&"new"===I.iceTransport.state&&(!b||l&&0!==c?U.forEach((function(e){te(I.iceTransport,e)})):I.iceTransport.setRemoteCandidates(U)),L=e.RTCRtpReceiver.getCapabilities(h),t<15019&&(L.codecs=L.codecs.filter((function(e){return"rtx"!==e.name}))),C=I.sendEncodingParameters||[{ssrc:1001*(2*c+2)}];var P,M=!1;if("sendrecv"===p||"sendonly"===p){if(M=!I.rtpReceiver,f=I.rtpReceiver||new e.RTCRtpReceiver(I.dtlsTransport,h),M)N=f.track,R&&"-"===R.stream||(R?(s[R.stream]||(s[R.stream]=new e.MediaStream,Object.defineProperty(s[R.stream],"id",{get:function(){return R.stream}})),Object.defineProperty(N,"id",{get:function(){return R.track}}),P=s[R.stream]):(s.default||(s.default=new e.MediaStream),P=s.default)),P&&(i(N,P),I.associatedRemoteMediaStreams.push(P)),a.push([N,f,P])}else I.rtpReceiver&&I.rtpReceiver.track&&(I.associatedRemoteMediaStreams.forEach((function(t){var i=t.getTracks().find((function(e){return e.id===I.rtpReceiver.track.id}));i&&function(t,i){i.removeTrack(t),i.dispatchEvent(new e.MediaStreamTrackEvent("removetrack",{track:t}))}(i,t)})),I.associatedRemoteMediaStreams=[]);I.localCapabilities=L,I.remoteCapabilities=k,I.rtpReceiver=f,I.rtcpParameters=D,I.sendEncodingParameters=C,I.recvEncodingParameters=O,o._transceive(o.transceivers[c],!1,M)}}})),void 0===o._dtlsRole&&(o._dtlsRole="offer"===n.type?"active":"passive"),o._remoteDescription={type:n.type,sdp:n.sdp},"offer"===n.type?o._updateSignalingState("have-remote-offer"):o._updateSignalingState("stable"),Object.keys(s).forEach((function(t){var i=s[t];if(i.getTracks().length){if(-1===o.remoteStreams.indexOf(i)){o.remoteStreams.push(i);var n=new Event("addstream");n.stream=i,e.setTimeout((function(){o._dispatchEvent("addstream",n)}))}a.forEach((function(e){var t=e[0],n=e[1];i.id===e[2].id&&r(o,t,n,[i])}))}})),a.forEach((function(e){e[2]||r(o,e[0],e[1],[])})),e.setTimeout((function(){o&&o.transceivers&&o.transceivers.forEach((function(e){e.iceTransport&&"new"===e.iceTransport.state&&e.iceTransport.getRemoteCandidates().length>0&&(console.warn("Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification"),e.iceTransport.addRemoteCandidate({}))}))}),4e3),Promise.resolve()},n.prototype.close=function(){this.transceivers.forEach((function(e){e.iceTransport&&e.iceTransport.stop(),e.dtlsTransport&&e.dtlsTransport.stop(),e.rtpSender&&e.rtpSender.stop(),e.rtpReceiver&&e.rtpReceiver.stop()})),this._isClosed=!0,this._updateSignalingState("closed")},n.prototype._updateSignalingState=function(e){this.signalingState=e;var t=new Event("signalingstatechange");this._dispatchEvent("signalingstatechange",t)},n.prototype._maybeFireNegotiationNeeded=function(){var t=this;"stable"===this.signalingState&&!0!==this.needNegotiation&&(this.needNegotiation=!0,e.setTimeout((function(){if(t.needNegotiation){t.needNegotiation=!1;var e=new Event("negotiationneeded");t._dispatchEvent("negotiationneeded",e)}}),0))},n.prototype._updateIceConnectionState=function(){var e,t={new:0,closed:0,checking:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach((function(e){e.iceTransport&&!e.rejected&&t[e.iceTransport.state]++})),e="new",t.failed>0?e="failed":t.checking>0?e="checking":t.disconnected>0?e="disconnected":t.new>0?e="new":t.connected>0?e="connected":t.completed>0&&(e="completed"),e!==this.iceConnectionState){this.iceConnectionState=e;var i=new Event("iceconnectionstatechange");this._dispatchEvent("iceconnectionstatechange",i)}},n.prototype._updateConnectionState=function(){var e,t={new:0,closed:0,connecting:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach((function(e){e.iceTransport&&e.dtlsTransport&&!e.rejected&&(t[e.iceTransport.state]++,t[e.dtlsTransport.state]++)})),t.connected+=t.completed,e="new",t.failed>0?e="failed":t.connecting>0?e="connecting":t.disconnected>0?e="disconnected":t.new>0?e="new":t.connected>0&&(e="connected"),e!==this.connectionState){this.connectionState=e;var i=new Event("connectionstatechange");this._dispatchEvent("connectionstatechange",i)}},n.prototype.createOffer=function(){var i=this;if(i._isClosed)return Promise.reject(ie("InvalidStateError","Can not call createOffer after close"));var r=i.transceivers.filter((function(e){return"audio"===e.kind})).length,n=i.transceivers.filter((function(e){return"video"===e.kind})).length,o=arguments[0];if(o){if(o.mandatory||o.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");void 0!==o.offerToReceiveAudio&&(r=!0===o.offerToReceiveAudio?1:!1===o.offerToReceiveAudio?0:o.offerToReceiveAudio),void 0!==o.offerToReceiveVideo&&(n=!0===o.offerToReceiveVideo?1:!1===o.offerToReceiveVideo?0:o.offerToReceiveVideo)}for(i.transceivers.forEach((function(e){"audio"===e.kind?--r<0&&(e.wantReceive=!1):"video"===e.kind&&--n<0&&(e.wantReceive=!1)}));r>0||n>0;)r>0&&(i._createTransceiver("audio"),r--),n>0&&(i._createTransceiver("video"),n--);var s=Q.writeSessionBoilerplate(i._sdpSessionId,i._sdpSessionVersion++);i.transceivers.forEach((function(r,n){var o=r.track,s=r.kind,a=r.mid||Q.generateIdentifier();r.mid=a,r.iceGatherer||(r.iceGatherer=i._createIceGatherer(n,i.usingBundle));var c=e.RTCRtpSender.getCapabilities(s);t<15019&&(c.codecs=c.codecs.filter((function(e){return"rtx"!==e.name}))),c.codecs.forEach((function(e){"H264"===e.name&&void 0===e.parameters["level-asymmetry-allowed"]&&(e.parameters["level-asymmetry-allowed"]="1"),r.remoteCapabilities&&r.remoteCapabilities.codecs&&r.remoteCapabilities.codecs.forEach((function(t){e.name.toLowerCase()===t.name.toLowerCase()&&e.clockRate===t.clockRate&&(e.preferredPayloadType=t.payloadType)}))})),c.headerExtensions.forEach((function(e){(r.remoteCapabilities&&r.remoteCapabilities.headerExtensions||[]).forEach((function(t){e.uri===t.uri&&(e.id=t.id)}))}));var d=r.sendEncodingParameters||[{ssrc:1001*(2*n+1)}];o&&t>=15019&&"video"===s&&!d[0].rtx&&(d[0].rtx={ssrc:d[0].ssrc+1}),r.wantReceive&&(r.rtpReceiver=new e.RTCRtpReceiver(r.dtlsTransport,s)),r.localCapabilities=c,r.sendEncodingParameters=d})),"max-compat"!==i._config.bundlePolicy&&(s+="a=group:BUNDLE "+i.transceivers.map((function(e){return e.mid})).join(" ")+"\r\n"),s+="a=ice-options:trickle\r\n",i.transceivers.forEach((function(e,t){s+=Z(e,e.localCapabilities,"offer",e.stream,i._dtlsRole),s+="a=rtcp-rsize\r\n",!e.iceGatherer||"new"===i.iceGatheringState||0!==t&&i.usingBundle||(e.iceGatherer.getLocalCandidates().forEach((function(e){e.component=1,s+="a="+Q.writeCandidate(e)+"\r\n"})),"completed"===e.iceGatherer.state&&(s+="a=end-of-candidates\r\n"))}));var a=new e.RTCSessionDescription({type:"offer",sdp:s});return Promise.resolve(a)},n.prototype.createAnswer=function(){var i=this;if(i._isClosed)return Promise.reject(ie("InvalidStateError","Can not call createAnswer after close"));if("have-remote-offer"!==i.signalingState&&"have-local-pranswer"!==i.signalingState)return Promise.reject(ie("InvalidStateError","Can not call createAnswer in signalingState "+i.signalingState));var r=Q.writeSessionBoilerplate(i._sdpSessionId,i._sdpSessionVersion++);i.usingBundle&&(r+="a=group:BUNDLE "+i.transceivers.map((function(e){return e.mid})).join(" ")+"\r\n"),r+="a=ice-options:trickle\r\n";var n=Q.getMediaSections(i._remoteDescription.sdp).length;i.transceivers.forEach((function(e,o){if(!(o+1>n)){if(e.rejected)return"application"===e.kind?"DTLS/SCTP"===e.protocol?r+="m=application 0 DTLS/SCTP 5000\r\n":r+="m=application 0 "+e.protocol+" webrtc-datachannel\r\n":"audio"===e.kind?r+="m=audio 0 UDP/TLS/RTP/SAVPF 0\r\na=rtpmap:0 PCMU/8000\r\n":"video"===e.kind&&(r+="m=video 0 UDP/TLS/RTP/SAVPF 120\r\na=rtpmap:120 VP8/90000\r\n"),void(r+="c=IN IP4 0.0.0.0\r\na=inactive\r\na=mid:"+e.mid+"\r\n");var s;if(e.stream)"audio"===e.kind?s=e.stream.getAudioTracks()[0]:"video"===e.kind&&(s=e.stream.getVideoTracks()[0]),s&&t>=15019&&"video"===e.kind&&!e.sendEncodingParameters[0].rtx&&(e.sendEncodingParameters[0].rtx={ssrc:e.sendEncodingParameters[0].ssrc+1});var a=X(e.localCapabilities,e.remoteCapabilities);!a.codecs.filter((function(e){return"rtx"===e.name.toLowerCase()})).length&&e.sendEncodingParameters[0].rtx&&delete e.sendEncodingParameters[0].rtx,r+=Z(e,a,"answer",e.stream,i._dtlsRole),e.rtcpParameters&&e.rtcpParameters.reducedSize&&(r+="a=rtcp-rsize\r\n")}}));var o=new e.RTCSessionDescription({type:"answer",sdp:r});return Promise.resolve(o)},n.prototype.addIceCandidate=function(e){var t,i=this;return e&&void 0===e.sdpMLineIndex&&!e.sdpMid?Promise.reject(new TypeError("sdpMLineIndex or sdpMid required")):new Promise((function(r,n){if(!i._remoteDescription)return n(ie("InvalidStateError","Can not add ICE candidate without a remote description"));if(e&&""!==e.candidate){var o=e.sdpMLineIndex;if(e.sdpMid)for(var s=0;s<i.transceivers.length;s++)if(i.transceivers[s].mid===e.sdpMid){o=s;break}var a=i.transceivers[o];if(!a)return n(ie("OperationError","Can not add ICE candidate"));if(a.rejected)return r();var c=Object.keys(e.candidate).length>0?Q.parseCandidate(e.candidate):{};if("tcp"===c.protocol&&(0===c.port||9===c.port))return r();if(c.component&&1!==c.component)return r();if((0===o||o>0&&a.iceTransport!==i.transceivers[0].iceTransport)&&!te(a.iceTransport,c))return n(ie("OperationError","Can not add ICE candidate"));var d=e.candidate.trim();0===d.indexOf("a=")&&(d=d.substr(2)),(t=Q.getMediaSections(i._remoteDescription.sdp))[o]+="a="+(c.type?d:"end-of-candidates")+"\r\n",i._remoteDescription.sdp=Q.getDescription(i._remoteDescription.sdp)+t.join("")}else for(var _=0;_<i.transceivers.length&&(i.transceivers[_].rejected||(i.transceivers[_].iceTransport.addRemoteCandidate({}),(t=Q.getMediaSections(i._remoteDescription.sdp))[_]+="a=end-of-candidates\r\n",i._remoteDescription.sdp=Q.getDescription(i._remoteDescription.sdp)+t.join(""),!i.usingBundle));_++);r()}))},n.prototype.getStats=function(t){if(t&&t instanceof e.MediaStreamTrack){var i=null;if(this.transceivers.forEach((function(e){e.rtpSender&&e.rtpSender.track===t?i=e.rtpSender:e.rtpReceiver&&e.rtpReceiver.track===t&&(i=e.rtpReceiver)})),!i)throw ie("InvalidAccessError","Invalid selector.");return i.getStats()}var r=[];return this.transceivers.forEach((function(e){["rtpSender","rtpReceiver","iceGatherer","iceTransport","dtlsTransport"].forEach((function(t){e[t]&&r.push(e[t].getStats())}))})),Promise.all(r).then((function(e){var t=new Map;return e.forEach((function(e){e.forEach((function(e){t.set(e.id,e)}))})),t}))};["RTCRtpSender","RTCRtpReceiver","RTCIceGatherer","RTCIceTransport","RTCDtlsTransport"].forEach((function(t){var i=e[t];if(i&&i.prototype&&i.prototype.getStats){var r=i.prototype.getStats;i.prototype.getStats=function(){return r.apply(this).then((function(e){var t=new Map;return Object.keys(e).forEach((function(i){var r;e[i].type={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[(r=e[i]).type]||r.type,t.set(i,e[i])})),t}))}}}));var o=["createOffer","createAnswer"];return o.forEach((function(e){var t=n.prototype[e];n.prototype[e]=function(){var e=arguments;return"function"==typeof e[0]||"function"==typeof e[1]?t.apply(this,[arguments[2]]).then((function(t){"function"==typeof e[0]&&e[0].apply(null,[t])}),(function(t){"function"==typeof e[1]&&e[1].apply(null,[t])})):t.apply(this,arguments)}})),(o=["setLocalDescription","setRemoteDescription","addIceCandidate"]).forEach((function(e){var t=n.prototype[e];n.prototype[e]=function(){var e=arguments;return"function"==typeof e[1]||"function"==typeof e[2]?t.apply(this,arguments).then((function(){"function"==typeof e[1]&&e[1].apply(null)}),(function(t){"function"==typeof e[2]&&e[2].apply(null,[t])})):t.apply(this,arguments)}})),["getStats"].forEach((function(e){var t=n.prototype[e];n.prototype[e]=function(){var e=arguments;return"function"==typeof e[1]?t.apply(this,arguments).then((function(){"function"==typeof e[1]&&e[1].apply(null)})):t.apply(this,arguments)}})),n};function ne(e){const t=e&&e.navigator,i=t.mediaDevices.getUserMedia.bind(t.mediaDevices);t.mediaDevices.getUserMedia=function(e){return i(e).catch((e=>Promise.reject(function(e){return{name:{PermissionDeniedError:"NotAllowedError"}[e.name]||e.name,message:e.message,constraint:e.constraint,toString(){return this.name}}}(e))))}}function oe(e){"getDisplayMedia"in e.navigator&&e.navigator.mediaDevices&&(e.navigator.mediaDevices&&"getDisplayMedia"in e.navigator.mediaDevices||(e.navigator.mediaDevices.getDisplayMedia=e.navigator.getDisplayMedia.bind(e.navigator)))}function se(e,t){if(e.RTCIceGatherer&&(e.RTCIceCandidate||(e.RTCIceCandidate=function(e){return e}),e.RTCSessionDescription||(e.RTCSessionDescription=function(e){return e}),t.version<15025)){const t=Object.getOwnPropertyDescriptor(e.MediaStreamTrack.prototype,"enabled");Object.defineProperty(e.MediaStreamTrack.prototype,"enabled",{set(e){t.set.call(this,e);const i=new Event("enabled");i.enabled=e,this.dispatchEvent(i)}})}e.RTCRtpSender&&!("dtmf"in e.RTCRtpSender.prototype)&&Object.defineProperty(e.RTCRtpSender.prototype,"dtmf",{get(){return void 0===this._dtmf&&("audio"===this.track.kind?this._dtmf=new e.RTCDtmfSender(this):"video"===this.track.kind&&(this._dtmf=null)),this._dtmf}}),e.RTCDtmfSender&&!e.RTCDTMFSender&&(e.RTCDTMFSender=e.RTCDtmfSender);const i=re(e,t.version);e.RTCPeerConnection=function(e){return e&&e.iceServers&&(e.iceServers=function(e,t){let i=!1;return(e=JSON.parse(JSON.stringify(e))).filter((e=>{if(e&&(e.urls||e.url)){let t=e.urls||e.url;e.url&&!e.urls&&b("RTCIceServer.url","RTCIceServer.urls");const r="string"==typeof t;return r&&(t=[t]),t=t.filter((e=>{if(0===e.indexOf("stun:"))return!1;const t=e.startsWith("turn")&&!e.startsWith("turn:[")&&e.includes("transport=udp");return t&&!i?(i=!0,!0):t&&!i})),delete e.url,e.urls=r?t[0]:t,!!t.length}}))}(e.iceServers,t.version),D("ICE servers after filtering:",e.iceServers)),new i(e)},e.RTCPeerConnection.prototype=i.prototype}function ae(e){e.RTCRtpSender&&!("replaceTrack"in e.RTCRtpSender.prototype)&&(e.RTCRtpSender.prototype.replaceTrack=e.RTCRtpSender.prototype.setTrack)}var ce=Object.freeze({__proto__:null,shimPeerConnection:se,shimReplaceTrack:ae,shimGetUserMedia:ne,shimGetDisplayMedia:oe});function de(e,t){const i=e&&e.navigator,r=e&&e.MediaStreamTrack;if(i.getUserMedia=function(e,t,r){b("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),i.mediaDevices.getUserMedia(e).then(t,r)},!(t.version>55&&"autoGainControl"in i.mediaDevices.getSupportedConstraints())){const e=function(e,t,i){t in e&&!(i in e)&&(e[i]=e[t],delete e[t])},t=i.mediaDevices.getUserMedia.bind(i.mediaDevices);if(i.mediaDevices.getUserMedia=function(i){return"object"==typeof i&&"object"==typeof i.audio&&(i=JSON.parse(JSON.stringify(i)),e(i.audio,"autoGainControl","mozAutoGainControl"),e(i.audio,"noiseSuppression","mozNoiseSuppression")),t(i)},r&&r.prototype.getSettings){const t=r.prototype.getSettings;r.prototype.getSettings=function(){const i=t.apply(this,arguments);return e(i,"mozAutoGainControl","autoGainControl"),e(i,"mozNoiseSuppression","noiseSuppression"),i}}if(r&&r.prototype.applyConstraints){const t=r.prototype.applyConstraints;r.prototype.applyConstraints=function(i){return"audio"===this.kind&&"object"==typeof i&&(i=JSON.parse(JSON.stringify(i)),e(i,"autoGainControl","mozAutoGainControl"),e(i,"noiseSuppression","mozNoiseSuppression")),t.apply(this,[i])}}}}function _e(e){"object"==typeof e&&e.RTCTrackEvent&&"receiver"in e.RTCTrackEvent.prototype&&!("transceiver"in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function le(e,t){if("object"!=typeof e||!e.RTCPeerConnection&&!e.mozRTCPeerConnection)return;!e.RTCPeerConnection&&e.mozRTCPeerConnection&&(e.RTCPeerConnection=e.mozRTCPeerConnection),t.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],r={[t](){return arguments[0]=new("addIceCandidate"===t?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),i.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=r[t]}));const i={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},r=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){const[e,n,o]=arguments;return r.apply(this,[e||null]).then((e=>{if(t.version<53&&!n)try{e.forEach((e=>{e.type=i[e.type]||e.type}))}catch(t){if("TypeError"!==t.name)throw t;e.forEach(((t,r)=>{e.set(r,Object.assign({},t,{type:i[t.type]||t.type}))}))}return e})).then(n,o)}}function ue(e){if("object"!=typeof e||!e.RTCPeerConnection||!e.RTCRtpSender)return;if(e.RTCRtpSender&&"getStats"in e.RTCRtpSender.prototype)return;const t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e});const i=e.RTCPeerConnection.prototype.addTrack;i&&(e.RTCPeerConnection.prototype.addTrack=function(){const e=i.apply(this,arguments);return e._pc=this,e}),e.RTCRtpSender.prototype.getStats=function(){return this.track?this._pc.getStats(this.track):Promise.resolve(new Map)}}function he(e){if("object"!=typeof e||!e.RTCPeerConnection||!e.RTCRtpSender)return;if(e.RTCRtpSender&&"getStats"in e.RTCRtpReceiver.prototype)return;const t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e}),A(e,"track",(e=>(e.receiver._pc=e.srcElement,e))),e.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function ge(e){e.RTCPeerConnection&&!("removeStream"in e.RTCPeerConnection.prototype)&&(e.RTCPeerConnection.prototype.removeStream=function(e){b("removeStream","removeTrack"),this.getSenders().forEach((t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)}))})}function ve(e){e.DataChannel&&!e.RTCDataChannel&&(e.RTCDataChannel=e.DataChannel)}function pe(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.addTransceiver;t&&(e.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];const e=arguments[1],i=e&&"sendEncodings"in e;i&&e.sendEncodings.forEach((e=>{if("rid"in e){if(!/^[a-z0-9]{0,16}$/i.test(e.rid))throw new TypeError("Invalid RID value provided.")}if("scaleResolutionDownBy"in e&&!(parseFloat(e.scaleResolutionDownBy)>=1))throw new RangeError("scale_resolution_down_by must be >= 1.0");if("maxFramerate"in e&&!(parseFloat(e.maxFramerate)>=0))throw new RangeError("max_framerate must be >= 0.0")}));const r=t.apply(this,arguments);if(i){const{sender:t}=r,i=t.getParameters();(!("encodings"in i)||1===i.encodings.length&&0===Object.keys(i.encodings[0]).length)&&(i.encodings=e.sendEncodings,t.sendEncodings=e.sendEncodings,this.setParametersPromises.push(t.setParameters(i).then((()=>{delete t.sendEncodings})).catch((()=>{delete t.sendEncodings}))))}return r})}function Re(e){if("object"!=typeof e||!e.RTCRtpSender)return;const t=e.RTCRtpSender.prototype.getParameters;t&&(e.RTCRtpSender.prototype.getParameters=function(){const e=t.apply(this,arguments);return"encodings"in e||(e.encodings=[].concat(this.sendEncodings||[{}])),e})}function me(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then((()=>t.apply(this,arguments))).finally((()=>{this.setParametersPromises=[]})):t.apply(this,arguments)}}function Ie(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.createAnswer;e.RTCPeerConnection.prototype.createAnswer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then((()=>t.apply(this,arguments))).finally((()=>{this.setParametersPromises=[]})):t.apply(this,arguments)}}var Ee=Object.freeze({__proto__:null,shimOnTrack:_e,shimPeerConnection:le,shimSenderGetStats:ue,shimReceiverGetStats:he,shimRemoveStream:ge,shimRTCDataChannel:ve,shimAddTransceiver:pe,shimGetParameters:Re,shimCreateOffer:me,shimCreateAnswer:Ie,shimGetUserMedia:de,shimGetDisplayMedia:function(e,t){e.navigator.mediaDevices&&"getDisplayMedia"in e.navigator.mediaDevices||e.navigator.mediaDevices&&(e.navigator.mediaDevices.getDisplayMedia=function(i){if(!i||!i.video){const e=new DOMException("getDisplayMedia without video constraints is undefined");return e.name="NotFoundError",e.code=8,Promise.reject(e)}return!0===i.video?i.video={mediaSource:t}:i.video.mediaSource=t,e.navigator.mediaDevices.getUserMedia(i)})}});function Se(e){if("object"==typeof e&&e.RTCPeerConnection){if("getLocalStreams"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),!("addStream"in e.RTCPeerConnection.prototype)){const t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addStream=function(e){this._localStreams||(this._localStreams=[]),this._localStreams.includes(e)||this._localStreams.push(e),e.getAudioTracks().forEach((i=>t.call(this,i,e))),e.getVideoTracks().forEach((i=>t.call(this,i,e)))},e.RTCPeerConnection.prototype.addTrack=function(e,...i){return i&&i.forEach((e=>{this._localStreams?this._localStreams.includes(e)||this._localStreams.push(e):this._localStreams=[e]})),t.apply(this,arguments)}}"removeStream"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.removeStream=function(e){this._localStreams||(this._localStreams=[]);const t=this._localStreams.indexOf(e);if(-1===t)return;this._localStreams.splice(t,1);const i=e.getTracks();this.getSenders().forEach((e=>{i.includes(e.track)&&this.removeTrack(e)}))})}}function Te(e){if("object"==typeof e&&e.RTCPeerConnection&&("getRemoteStreams"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),!("onaddstream"in e.RTCPeerConnection.prototype))){Object.defineProperty(e.RTCPeerConnection.prototype,"onaddstream",{get(){return this._onaddstream},set(e){this._onaddstream&&(this.removeEventListener("addstream",this._onaddstream),this.removeEventListener("track",this._onaddstreampoly)),this.addEventListener("addstream",this._onaddstream=e),this.addEventListener("track",this._onaddstreampoly=e=>{e.streams.forEach((e=>{if(this._remoteStreams||(this._remoteStreams=[]),this._remoteStreams.includes(e))return;this._remoteStreams.push(e);const t=new Event("addstream");t.stream=e,this.dispatchEvent(t)}))})}});const t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){const e=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(t){t.streams.forEach((t=>{if(e._remoteStreams||(e._remoteStreams=[]),e._remoteStreams.indexOf(t)>=0)return;e._remoteStreams.push(t);const i=new Event("addstream");i.stream=t,e.dispatchEvent(i)}))}),t.apply(e,arguments)}}}function fe(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype,i=t.createOffer,r=t.createAnswer,n=t.setLocalDescription,o=t.setRemoteDescription,s=t.addIceCandidate;t.createOffer=function(e,t){const r=arguments.length>=2?arguments[2]:arguments[0],n=i.apply(this,[r]);return t?(n.then(e,t),Promise.resolve()):n},t.createAnswer=function(e,t){const i=arguments.length>=2?arguments[2]:arguments[0],n=r.apply(this,[i]);return t?(n.then(e,t),Promise.resolve()):n};let a=function(e,t,i){const r=n.apply(this,[e]);return i?(r.then(t,i),Promise.resolve()):r};t.setLocalDescription=a,a=function(e,t,i){const r=o.apply(this,[e]);return i?(r.then(t,i),Promise.resolve()):r},t.setRemoteDescription=a,a=function(e,t,i){const r=s.apply(this,[e]);return i?(r.then(t,i),Promise.resolve()):r},t.addIceCandidate=a}function Ce(e){const t=e&&e.navigator;if(t.mediaDevices&&t.mediaDevices.getUserMedia){const e=t.mediaDevices,i=e.getUserMedia.bind(e);t.mediaDevices.getUserMedia=e=>i(Oe(e))}!t.getUserMedia&&t.mediaDevices&&t.mediaDevices.getUserMedia&&(t.getUserMedia=function(e,i,r){t.mediaDevices.getUserMedia(e).then(i,r)}.bind(t))}function Oe(e){return e&&void 0!==e.video?Object.assign({},e,{video:P(e.video)}):e}function Le(e){if(!e.RTCPeerConnection)return;const t=e.RTCPeerConnection;e.RTCPeerConnection=function(e,i){if(e&&e.iceServers){const t=[];for(let i=0;i<e.iceServers.length;i++){let r=e.iceServers[i];!r.hasOwnProperty("urls")&&r.hasOwnProperty("url")?(b("RTCIceServer.url","RTCIceServer.urls"),r=JSON.parse(JSON.stringify(r)),r.urls=r.url,delete r.url,t.push(r)):t.push(e.iceServers[i])}e.iceServers=t}return new t(e,i)},e.RTCPeerConnection.prototype=t.prototype,"generateCertificate"in t&&Object.defineProperty(e.RTCPeerConnection,"generateCertificate",{get:()=>t.generateCertificate})}function Ne(e){"object"==typeof e&&e.RTCTrackEvent&&"receiver"in e.RTCTrackEvent.prototype&&!("transceiver"in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function Ae(e){const t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(e){if(e){void 0!==e.offerToReceiveAudio&&(e.offerToReceiveAudio=!!e.offerToReceiveAudio);const t=this.getTransceivers().find((e=>"audio"===e.receiver.track.kind));!1===e.offerToReceiveAudio&&t?"sendrecv"===t.direction?t.setDirection?t.setDirection("sendonly"):t.direction="sendonly":"recvonly"===t.direction&&(t.setDirection?t.setDirection("inactive"):t.direction="inactive"):!0!==e.offerToReceiveAudio||t||this.addTransceiver("audio"),void 0!==e.offerToReceiveVideo&&(e.offerToReceiveVideo=!!e.offerToReceiveVideo);const i=this.getTransceivers().find((e=>"video"===e.receiver.track.kind));!1===e.offerToReceiveVideo&&i?"sendrecv"===i.direction?i.setDirection?i.setDirection("sendonly"):i.direction="sendonly":"recvonly"===i.direction&&(i.setDirection?i.setDirection("inactive"):i.direction="inactive"):!0!==e.offerToReceiveVideo||i||this.addTransceiver("video")}return t.apply(this,arguments)}}function ye(e){"object"!=typeof e||e.AudioContext||(e.AudioContext=e.webkitAudioContext)}var ke=Object.freeze({__proto__:null,shimLocalStreamsAPI:Se,shimRemoteStreamsAPI:Te,shimCallbacksAPI:fe,shimGetUserMedia:Ce,shimConstraints:Oe,shimRTCIceServerUrls:Le,shimTrackEventTransceiver:Ne,shimCreateOfferLegacy:Ae,shimAudioContext:ye});function De(e){if(!e.RTCIceCandidate||e.RTCIceCandidate&&"foundation"in e.RTCIceCandidate.prototype)return;const t=e.RTCIceCandidate;e.RTCIceCandidate=function(e){if("object"==typeof e&&e.candidate&&0===e.candidate.indexOf("a=")&&((e=JSON.parse(JSON.stringify(e))).candidate=e.candidate.substr(2)),e.candidate&&e.candidate.length){const i=new t(e),r=Q.parseCandidate(e.candidate),n=Object.assign(i,r);return n.toJSON=function(){return{candidate:n.candidate,sdpMid:n.sdpMid,sdpMLineIndex:n.sdpMLineIndex,usernameFragment:n.usernameFragment}},n}return new t(e)},e.RTCIceCandidate.prototype=t.prototype,A(e,"icecandidate",(t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new e.RTCIceCandidate(t.candidate),writable:"false"}),t)))}function be(e,t){if(!e.RTCPeerConnection)return;"sctp"in e.RTCPeerConnection.prototype||Object.defineProperty(e.RTCPeerConnection.prototype,"sctp",{get(){return void 0===this._sctp?null:this._sctp}});const i=function(e){if(!e||!e.sdp)return!1;const t=Q.splitSections(e.sdp);return t.shift(),t.some((e=>{const t=Q.parseMLine(e);return t&&"application"===t.kind&&-1!==t.protocol.indexOf("SCTP")}))},r=function(e){const t=e.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(null===t||t.length<2)return-1;const i=parseInt(t[1],10);return i!=i?-1:i},n=function(e){let i=65536;return"firefox"===t.browser&&(i=t.version<57?-1===e?16384:2147483637:t.version<60?57===t.version?65535:65536:2147483637),i},o=function(e,i){let r=65536;"firefox"===t.browser&&57===t.version&&(r=65535);const n=Q.matchPrefix(e.sdp,"a=max-message-size:");return n.length>0?r=parseInt(n[0].substr(19),10):"firefox"===t.browser&&-1!==i&&(r=2147483637),r},s=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,"chrome"===t.browser&&t.version>=76){const{sdpSemantics:e}=this.getConfiguration();"plan-b"===e&&Object.defineProperty(this,"sctp",{get(){return void 0===this._sctp?null:this._sctp},enumerable:!0,configurable:!0})}if(i(arguments[0])){const e=r(arguments[0]),t=n(e),i=o(arguments[0],e);let s;s=0===t&&0===i?Number.POSITIVE_INFINITY:0===t||0===i?Math.max(t,i):Math.min(t,i);const a={};Object.defineProperty(a,"maxMessageSize",{get:()=>s}),this._sctp=a}return s.apply(this,arguments)}}function Ue(e){if(!e.RTCPeerConnection||!("createDataChannel"in e.RTCPeerConnection.prototype))return;function t(e,t){const i=e.send;e.send=function(){const r=arguments[0],n=r.length||r.size||r.byteLength;if("open"===e.readyState&&t.sctp&&n>t.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+t.sctp.maxMessageSize+" bytes)");return i.apply(e,arguments)}}const i=e.RTCPeerConnection.prototype.createDataChannel;e.RTCPeerConnection.prototype.createDataChannel=function(){const e=i.apply(this,arguments);return t(e,this),e},A(e,"datachannel",(e=>(t(e.channel,e.target),e)))}function Pe(e){if(!e.RTCPeerConnection||"connectionState"in e.RTCPeerConnection.prototype)return;const t=e.RTCPeerConnection.prototype;Object.defineProperty(t,"connectionState",{get(){return{completed:"connected",checking:"connecting"}[this.iceConnectionState]||this.iceConnectionState},enumerable:!0,configurable:!0}),Object.defineProperty(t,"onconnectionstatechange",{get(){return this._onconnectionstatechange||null},set(e){this._onconnectionstatechange&&(this.removeEventListener("connectionstatechange",this._onconnectionstatechange),delete this._onconnectionstatechange),e&&this.addEventListener("connectionstatechange",this._onconnectionstatechange=e)},enumerable:!0,configurable:!0}),["setLocalDescription","setRemoteDescription"].forEach((e=>{const i=t[e];t[e]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=e=>{const t=e.target;if(t._lastConnectionState!==t.connectionState){t._lastConnectionState=t.connectionState;const i=new Event("connectionstatechange",e);t.dispatchEvent(i)}return e},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),i.apply(this,arguments)}}))}function Me(e,t){if(!e.RTCPeerConnection)return;if("chrome"===t.browser&&t.version>=71)return;if("safari"===t.browser&&t.version>=605)return;const i=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(t){if(t&&t.sdp&&-1!==t.sdp.indexOf("\na=extmap-allow-mixed")){const i=t.sdp.split("\n").filter((e=>"a=extmap-allow-mixed"!==e.trim())).join("\n");e.RTCSessionDescription&&t instanceof e.RTCSessionDescription?arguments[0]=new e.RTCSessionDescription({type:t.type,sdp:i}):t.sdp=i}return i.apply(this,arguments)}}function xe(e,t){if(!e.RTCPeerConnection||!e.RTCPeerConnection.prototype)return;const i=e.RTCPeerConnection.prototype.addIceCandidate;i&&0!==i.length&&(e.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?("chrome"===t.browser&&t.version<78||"firefox"===t.browser&&t.version<68||"safari"===t.browser)&&arguments[0]&&""===arguments[0].candidate?Promise.resolve():i.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}var we=Object.freeze({__proto__:null,shimRTCIceCandidate:De,shimMaxMessageSize:be,shimSendThrowTypeError:Ue,shimConnectionState:Pe,removeExtmapAllowMixed:Me,shimAddIceCandidateNullOrEmpty:xe});const Be=function({window:e}={},t={shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0}){const i=D,r=function(e){const t={browser:null,version:null};if(void 0===e||!e.navigator)return t.browser="Not a browser.",t;const{navigator:i}=e;if(i.mozGetUserMedia)t.browser="firefox",t.version=N(i.userAgent,/Firefox\/(\d+)\./,1);else if(i.webkitGetUserMedia||!1===e.isSecureContext&&e.webkitRTCPeerConnection&&!e.RTCIceGatherer)t.browser="chrome",t.version=N(i.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(i.mediaDevices&&i.userAgent.match(/Edge\/(\d+).(\d+)$/))t.browser="edge",t.version=N(i.userAgent,/Edge\/(\d+).(\d+)$/,2);else{if(!e.RTCPeerConnection||!i.userAgent.match(/AppleWebKit\/(\d+)\./))return t.browser="Not a supported browser.",t;t.browser="safari",t.version=N(i.userAgent,/AppleWebKit\/(\d+)\./,1),t.supportsUnifiedPlan=e.RTCRtpTransceiver&&"currentDirection"in e.RTCRtpTransceiver.prototype}return t}(e),n={browserDetails:r,commonShim:we,extractVersion:N,disableLog:y,disableWarnings:k};switch(r.browser){case"chrome":if(!Y||!$||!t.shimChrome)return i("Chrome shim is not included in this adapter release."),n;if(null===r.version)return i("Chrome shim can not determine version, not shimming."),n;i("adapter.js shimming chrome."),n.browserShim=Y,xe(e,r),B(e,r),V(e),$(e,r),F(e),j(e,r),J(e),G(e),H(e),W(e,r),De(e),Pe(e),be(e,r),Ue(e),Me(e,r);break;case"firefox":if(!Ee||!le||!t.shimFirefox)return i("Firefox shim is not included in this adapter release."),n;i("adapter.js shimming firefox."),n.browserShim=Ee,xe(e,r),de(e,r),le(e,r),_e(e),ge(e),ue(e),he(e),ve(e),pe(e),Re(e),me(e),Ie(e),De(e),Pe(e),be(e,r),Ue(e);break;case"edge":if(!ce||!se||!t.shimEdge)return i("MS edge shim is not included in this adapter release."),n;i("adapter.js shimming edge."),n.browserShim=ce,ne(e),oe(e),se(e,r),ae(e),be(e,r),Ue(e);break;case"safari":if(!ke||!t.shimSafari)return i("Safari shim is not included in this adapter release."),n;i("adapter.js shimming safari."),n.browserShim=ke,xe(e,r),Le(e),Ae(e),fe(e),Se(e),Te(e),Ne(e),Ce(e),ye(e),De(e),be(e,r),Ue(e),Me(e,r);break;default:i("Unsupported browser!")}return n}({window:"undefined"==typeof window?void 0:window});var Ve,Fe,Je;!function(e){e.FPS_10="FPS_10",e.FPS_15="FPS_15",e.FPS_24="FPS_24",e.FPS_30="FPS_30"}(Ve||(Ve={})),function(e){e.W176_H132="W176_H132",e.W176_H144="W176_H144",e.W180_H180="W180_H180",e.W240_H180="W240_H180",e.W240_H240="W240_H240",e.W256_H144="W256_H144",e.W320_H180="W320_H180",e.W320_H240="W320_H240",e.W360_H360="W360_H360",e.W480_H360="W480_H360",e.W480_H480="W480_H480",e.W640_H360="W640_H360",e.W640_H480="W640_H480",e.W720_H480="W720_H480",e.W848_H480="W848_H480",e.W960_H720="W960_H720",e.W1280_H720="W1280_H720",e.W1920_H1080="W1920_H1080",e.W144_H176="W144_H176",e.W144_H256="W144_H256",e.W180_H240="W180_H240",e.W180_H320="W180_H320",e.W240_H320="W240_H320",e.W360_H480="W360_H480",e.W360_H640="W360_H640",e.W480_H640="W480_H640",e.W480_H720="W480_H720",e.W480_H848="W480_H848",e.W720_H1280="W720_H1280",e.W720_H960="W720_H960",e.W1080_H1920="W1080_H1920"}(Fe||(Fe={})),function(e){e[e.AUDIO_ONLY=0]="AUDIO_ONLY",e[e.VIDEO_ONLY=1]="VIDEO_ONLY",e[e.AUDIO_VIDEO=2]="AUDIO_VIDEO"}(Je||(Je={}));const Ge={[Fe.W176_H132]:{width:176,height:132,maxBitrate:150,minBitrate:80},[Fe.W176_H144]:{width:176,height:144,maxBitrate:150,minBitrate:80},[Fe.W180_H180]:{width:180,height:180,maxBitrate:200,minBitrate:100},[Fe.W240_H180]:{width:240,height:180,maxBitrate:240,minBitrate:120},[Fe.W240_H240]:{width:240,height:240,maxBitrate:280,minBitrate:120},[Fe.W256_H144]:{width:256,height:144,maxBitrate:240,minBitrate:120},[Fe.W320_H180]:{width:320,height:180,maxBitrate:280,minBitrate:120},[Fe.W320_H240]:{width:320,height:240,maxBitrate:400,minBitrate:120},[Fe.W360_H360]:{width:360,height:360,maxBitrate:520,minBitrate:140},[Fe.W480_H360]:{width:480,height:360,maxBitrate:650,minBitrate:150},[Fe.W480_H480]:{width:480,height:480,maxBitrate:800,minBitrate:180},[Fe.W640_H360]:{width:640,height:360,maxBitrate:800,minBitrate:180},[Fe.W640_H480]:{width:640,height:480,maxBitrate:900,minBitrate:200},[Fe.W720_H480]:{width:720,height:480,maxBitrate:1e3,minBitrate:200},[Fe.W848_H480]:{width:848,height:480,maxBitrate:1860,minBitrate:200},[Fe.W960_H720]:{width:960,height:720,maxBitrate:2e3,minBitrate:250},[Fe.W1280_H720]:{width:1280,height:720,maxBitrate:2200,minBitrate:250},[Fe.W1920_H1080]:{width:1920,height:1080,maxBitrate:4e3,minBitrate:400},[Fe.W144_H176]:{width:144,height:176,maxBitrate:150,minBitrate:80},[Fe.W144_H256]:{width:144,height:256,maxBitrate:240,minBitrate:120},[Fe.W180_H240]:{width:180,height:240,maxBitrate:240,minBitrate:120},[Fe.W180_H320]:{width:180,height:320,maxBitrate:280,minBitrate:120},[Fe.W240_H320]:{width:240,height:320,maxBitrate:400,minBitrate:120},[Fe.W360_H480]:{width:360,height:480,maxBitrate:650,minBitrate:150},[Fe.W360_H640]:{width:360,height:640,maxBitrate:800,minBitrate:180},[Fe.W480_H640]:{width:480,height:640,maxBitrate:900,minBitrate:200},[Fe.W480_H720]:{width:480,height:720,maxBitrate:1e3,minBitrate:200},[Fe.W480_H848]:{width:480,height:848,maxBitrate:1860,minBitrate:930},[Fe.W720_H1280]:{width:720,height:1280,maxBitrate:2200,minBitrate:250},[Fe.W720_H960]:{width:720,height:960,maxBitrate:2760,minBitrate:910},[Fe.W1080_H1920]:{width:1080,height:1920,maxBitrate:4e3,minBitrate:400}},He=e=>{const t={192:180,368:360,1088:1080};return t[e]?t[e]:e},Ke=(e,t)=>{e=He(e),t=He(t);const i=Ge[`W${e}_H${t}`];if(i)return i;const r=e*t;return Object.keys(Ge).map((e=>Ge[e])).sort(((e,t)=>e.height*e.width-t.width*t.height)).filter((e=>e.height*e.width>=r))[0]||Ge.W1920_H1080},je={10:1,15:1,24:1.5,30:1.5},$e=e=>{let t=Number.MAX_VALUE,i=1;for(const r in je){const n=Math.abs(e-parseInt(r));n<t&&(t=n,i=je[r])}return i};class We{constructor(){this._logger=null}setLogger(e){this._logger=e}getLogger(){return this._logger}createTraceId(){var e;return(null===(e=this._logger)||void 0===e?void 0:e.createTraceId())||`${Date.now()}`}debug(e,t,i){var r;null===(r=this._logger)||void 0===r||r.debug(e,t,i)}info(e,t,i){var r;null===(r=this._logger)||void 0===r||r.info(e,t,i)}warn(e,t,i){var r;null===(r=this._logger)||void 0===r||r.warn(e,t,i)}error(e,t,i){var r;null===(r=this._logger)||void 0===r||r.error(e,t,i)}__statistics(e,t,i){var r;null===(r=this._logger)||void 0===r||r.__statistics(e,t,i)}static setLogger(e){this._logger=e}static getLogger(){return this._logger}}We._logger=null;const Ye=new We,qe={getCameras:()=>S(void 0,void 0,void 0,(function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind))})),getMicrophones:()=>S(void 0,void 0,void 0,(function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"audioinput"===e.kind))})),getSpeakers:()=>S(void 0,void 0,void 0,(function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"audiooutput"===e.kind))}))};var ze,Qe;!function(e){e.AUDIO="audio",e.VIDEO="video"}(ze||(ze={}));class Ze extends e{constructor(e,t,i,r,n){super(),this._tag=e,this._userId=t,this._kind=i,this._isLocalTrack=r,this._roomId=n,this._localMuted=!1,this._remoteMuted=!1,this._logger=null,this.DataTrackId="data-track-id",this._streamId=[this._userId||this._roomId,this._tag].join("_"),this._id=[this._streamId,this.isAudioTrack()?0:1].join("_"),this._logger=We.getLogger()}getStreamId(){return this._streamId}getTrackId(){return this._id}getUserId(){return this._userId}__innerGetMediaStreamTrack(){return this._msTrack}get streamTrack(){return this._msTrack}getTag(){return this._tag}isLocalTrack(){return this._isLocalTrack}isVideoTrack(){return"video"===this._kind}isAudioTrack(){return"audio"===this._kind}isReady(){var e;return"live"===(null===(e=this._msTrack)||void 0===e?void 0:e.readyState)}__innerSetMediaStreamTrack(e){this._msTrack=e,this._setLocalMuted(this._localMuted);const t=this._msStream=this._msStream||new MediaStream,i=t.getTracks()[0];i&&t.removeTrack(i),e?t.addTrack(e):this._element&&this._element.getAttribute(this.DataTrackId)===this.getTrackId()&&(this._element.pause(),this._element.srcObject=null)}_setLocalMuted(e){this._msTrack&&(this._msTrack.enabled=!e),this._localMuted=e}mute(){return this._setLocalMuted(!0)}unmute(){return this._setLocalMuted(!1)}isLocalMuted(){return this._localMuted}isMCUTrack(){return Boolean(this._roomId)}isOwnerMuted(){return this._remoteMuted}play(e,i){var r,n,o,s,a,c,d,_,l,u,h,g,v;return S(this,void 0,void 0,(function*(){if(null===(r=this._logger)||void 0===r||r.info(f.L_TRACK_PLAY_O,JSON.stringify({element:e,options:i,kind:null!==(n=this._kind)&&void 0!==n?n:"",msg:`start play trackId: ${this._id}`})),!this._msTrack)return null===(o=this._logger)||void 0===o||o.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,code:T.TRACK_NOT_READY,kind:null!==(s=this._kind)&&void 0!==s?s:"",msg:`the track is not ready to play -> id: ${this._id}`})),{code:T.TRACK_NOT_READY};if("ended"===this._msTrack.readyState)return null===(a=this._logger)||void 0===a||a.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,kind:null!==(c=this._kind)&&void 0!==c?c:"",msg:`the track's readyState is ended -> id: ${this._id}`})),{code:T.TRACK_READYSTATE_IS_ENDED};if(null==i?void 0:i.volume){if(!t(null==i?void 0:i.volume))return null===(d=this._logger)||void 0===d||d.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> options.volume not a number"})),{code:T.PARAMS_ERROR};(null==i?void 0:i.volume)<0&&(i.volume=0,null===(_=this._logger)||void 0===_||_.warn(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,msg:"params error -> options.volume < 0",tips:"the valid range of options.volume is 0-100, the value of volume has been set 0"}))),(null==i?void 0:i.volume)>100&&(i.volume=100,null===(l=this._logger)||void 0===l||l.warn(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,msg:"params error -> options.volume > 100",tips:"the valid range of options.volume is 0-100, the value of volume has been set 100"})))}if(null==i?void 0:i.audioDeviceId){if(!(yield qe.getSpeakers()).map((e=>e.deviceId)).includes(i.audioDeviceId))return null===(u=this._logger)||void 0===u||u.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> options.audioDeviceId"})),{code:T.PARAMS_ERROR}}const p=this.isVideoTrack();return!p||e&&(e instanceof HTMLVideoElement||this.__validateVideoNodeName(e))?(this._element=p?e:new Audio,this._localMuted&&this._setLocalMuted(!1),this._element.srcObject&&this._element.srcObject===this._msStream||this._element.pause(),this._element.onloadstart=e=>{var t,i,r;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_LOAD_START_O,JSON.stringify({status:C.INFO,kind:null!==(i=this._kind)&&void 0!==i?i:"",msg:`HTMLMediaElement onloadstart -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, trackId: ${this._id}`}))},this._element.ondurationchange=e=>{var t,i,r;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_DURATION_CHANGE_O,JSON.stringify({status:C.INFO,kind:null!==(i=this._kind)&&void 0!==i?i:"",msg:`HTMLMediaElement ondurationchange -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, trackId: ${this._id}`}))},this._element.onloadedmetadata=e=>{var t,i,r;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_LOADED_META_DATA_O,JSON.stringify({status:C.INFO,kind:null!==(i=this._kind)&&void 0!==i?i:"",msg:`HTMLMediaElement onloadedmetadata -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, trackId: ${this._id}`}))},this._element.onloadeddata=e=>{var t,i,r;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_LOADED_DATA_O,JSON.stringify({status:C.INFO,kind:null!==(i=this._kind)&&void 0!==i?i:"",msg:`HTMLMediaElement onloadeddata -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, trackId: ${this._id}`}))},this._element.onabort=e=>{var t,i,r;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_ABORT_O,JSON.stringify({status:C.INFO,kind:null!==(i=this._kind)&&void 0!==i?i:"",msg:`HTMLMediaElement onabort -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, trackId: ${this._id}`}))},this._element.oncanplay=e=>S(this,void 0,void 0,(function*(){var t,r,n,o,s,a,c,d;null===(t=this._logger)||void 0===t||t.info(f.L_TRACK_CANPLAY_O,JSON.stringify({status:C.INFO,kind:null!==(r=this._kind)&&void 0!==r?r:"",msg:`HTMLMediaElement oncanplay -> id: ${null===(n=e.target)||void 0===n?void 0:n.id}, trackId: ${this._id}`}));try{(null==i?void 0:i.audioDeviceId)&&!p&&(yield this._element.setSinkId(i.audioDeviceId)),yield null===(o=this._element)||void 0===o?void 0:o.play()}catch(e){if("No permission to use requested device"===e.message)return void(null===(s=this._logger)||void 0===s||s.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,kind:null!==(a=this._kind)&&void 0!==a?a:"",code:T.NO_PERMISSION_TO_USE_REQUESTED_DEVICE,msg:`setSinkId failed, error msg: ${e.message}`})));null===(c=this._logger)||void 0===c||c.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,code:T.TRACK_PLAY_ERROR,kind:null!==(d=this._kind)&&void 0!==d?d:"",msg:`play error, error msg: ${e.message}`}))}})),this._element.onvolumechange=e=>{var t,i,r;const n=Math.floor(100*(null===(t=e.target)||void 0===t?void 0:t.volume));null===(i=this._logger)||void 0===i||i.info(f.L_TRACK_VOLUME_CHANGE_O,JSON.stringify({status:C.INFO,msg:`HTMLMediaElement onvolumechange -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, volume: ${n}, trackId: ${this._id}`}))},this._element.srcObject=this._msStream,this._element.autoplay=!0,p&&(this._element.playsInline=!0,this._element.x5PlaysInline=!0,this._element.webkitPlaysInline=!0),(null==i?void 0:i.audioDeviceId)&&!p&&(yield this._element.setSinkId(i.audioDeviceId)),p||!(null==i?void 0:i.volume)&&0!==(null==i?void 0:i.volume)||(this._element.volume=(null==i?void 0:i.volume)/100),null===(v=this._element)||void 0===v||v.setAttribute(this.DataTrackId,this.getTrackId()),{code:T.SUCCESS}):(null===(h=this._logger)||void 0===h||h.error(f.L_TRACK_PLAY_E,JSON.stringify({status:C.FAILED,code:T.VIDEO_TRACK_MISS_MEDIA_ELEMENT,kind:null!==(g=this._kind)&&void 0!==g?g:"",msg:"params element is not a HTMLVideoElement"})),{code:T.VIDEO_TRACK_MISS_MEDIA_ELEMENT})}))}__innerDestroy(){this.__innerSetMediaStreamTrack(void 0)}__releaseMediaElement(){this._element&&this._element.getAttribute(this.DataTrackId)===this.getTrackId()&&(this._element.remove(),this._element.srcObject=null)}__validateVideoNodeName(e){return e&&e.nodeName&&"VIDEO"===e.nodeName.toUpperCase()}}!function(e){e.Speech="Speech",e.Music="Music",e.MusicHigh="MusicHigh"}(Qe||(Qe={}));const Xe={[Qe.Music]:{max:64,min:64},[Qe.MusicHigh]:{max:128,min:128},[Qe.Speech]:{max:32,min:32}};var et;!function(e){e.LEVEL0="LEVEL0",e.LEVEL1="LEVEL1",e.LEVEL2="LEVEL2",e.LEVEL3="LEVEL3",e.LEVEL4="LEVEL4",e.LEVEL5="LEVEL5"}(et||(et={}));const tt={[et.LEVEL0]:{max:150,min:80},[et.LEVEL1]:{max:280,min:120},[et.LEVEL2]:{max:650,min:150},[et.LEVEL3]:{max:1e3,min:200},[et.LEVEL4]:{max:2200,min:250},[et.LEVEL5]:{max:4e3,min:400}};class it{static setStatus(e=!0){it.isOpen=e}static setWroklet(e,t){it.workletModule=e,it.workletModule=t}static transformStreamTrack(e){var t;return S(this,void 0,void 0,(function*(){const i=We.getLogger();if(!it.isOpen)return new Promise((t=>{t({track:null==e?void 0:e.getAudioTracks()[0],stop:()=>{}})}));let r=new AudioContext({sampleRate:44100}),n=r.createMediaStreamSource(e),o=r.createMediaStreamDestination(),s=null,a=null;if(s=yield r.audioWorklet.addModule(it.workletModule).then((()=>(null==i||i.info(f.L_RTC_3ANOISE_NODE_O,JSON.stringify({status:C.SUCCESSED,message:{msg:"addModule RC3AnoiseTrack.workletModule success"}})),fetch(it.workletWasm,{cache:"force-cache",credentials:"same-origin"}).then((e=>e.arrayBuffer())).catch((e=>{throw new Error(e.message)}))))).then((e=>(a=new AudioWorkletNode(r,"process-worklet",{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[1],processorOptions:{binary:e}}),a))).catch((e=>{null==i||i.info(f.L_RTC_3ANOISE_NODE_E,JSON.stringify({status:C.FAILED,message:{msg:e.message}}))})),!s)return new Promise((t=>{t({track:null==e?void 0:e.getAudioTracks()[0],stop:()=>{}})}));n.connect(s).connect(o);let c=null===(t=null==o?void 0:o.stream)||void 0===t?void 0:t.getAudioTracks()[0],d=()=>{null==i||i.info(f.L_RTC_3ANOISE_NODE_STOP_O,JSON.stringify({status:C.SUCCESSED,message:{msg:"call stop RC3AnoiseTrack.workletModule"}})),null==s||s.port.postMessage({type:"stop",msg:""}),setTimeout((()=>{const t=null==e?void 0:e.getAudioTracks()[0];null==t||t.stop(),null==r||r.suspend(),null==r||r.close(),null==o||o.disconnect(),null==s||s.disconnect(),null==n||n.disconnect(),r=null,s=null,o=null,n=null,a=null,e=null,null==c||c.stop(),c=null,d=null}),200)};return{track:c,stop:d}}))}}it.workletModule="https://cdn.ronghub.com/plugin-rtc/wasm/5.0.0-alpha.2/process-worklet.js",it.workletWasm="https://cdn.ronghub.com/plugin-rtc/wasm/5.0.0-alpha.2/AudioProcessing.wasm",it.isOpen=!1;class rt extends Ze{constructor(e,t,i,r){super(e,t,i,!0),this._isDestroyed=!1,this._isPublished=!1,this.__innerSetMediaStreamTrack(r),r.onended=()=>{r.onended=null,this.emit(rt.EVENT_LOCAL_TRACK_END,this),this.removeAll(rt.EVENT_LOCAL_TRACK_END)}}_setLocalMuted(e){return new Promise(((t,i)=>{var r;const n=this._localMuted!==e;super._setLocalMuted(e),this._remoteMuted=this._localMuted,n&&this.emit(rt.__INNER_EVENT_MUTED_CHANGE__,this,t),null===(r=this._logger)||void 0===r||r.info(f.L_LOCAL_TRACK_SET_LOCAL_MUTED_O,JSON.stringify({enable:e,trackId:this._id}))}))}__innerSetPublished(e){this._isPublished=e}isPublished(){return this._isPublished}destroy(){var e,t;this._isDestroyed=!0,null===(e=this._msTrack)||void 0===e||e.stop(),super.__innerDestroy(),this.isAudioTrack()&&super.__releaseMediaElement(),this.emit(rt.__INNER_EVENT_DESTROY__,this),null===(t=this._logger)||void 0===t||t.info(f.L_LOCAL_TRACK_DESTROY_O,JSON.stringify({status:C.SUCCESSED,trackId:this._id}))}isDestroyed(){return this._isDestroyed}setBitrate(e=0,i=0,r=0){var n,o;!t(e)||!t(i)||!t(r)||e<=0||i<=0||e<i?null===(n=this._logger)||void 0===n||n.error(f.L_LOCAL_TRACK_SET_BITRATE_O,JSON.stringify({status:C.FAILED,msg:`params error -> max: ${e},min: ${i}, start: ${r}`,trackId:this._id})):(null===(o=this._logger)||void 0===o||o.info(f.L_LOCAL_TRACK_SET_BITRATE_O,JSON.stringify({status:C.SUCCESSED,max:e,min:i,start:r,trackId:this._id})),this._bitrateInfo={max:e,min:i,start:r})}getBitrate(){var e,t,i,r,n,o,s;let{min:a,max:c,start:d}={min:0,max:0,start:0};return(null===(e=this._msTrack)||void 0===e?void 0:e.kind)===ze.VIDEO?({min:a,max:c}=Tt(this._msTrack)):(null===(t=this._msTrack)||void 0===t?void 0:t.kind)===ze.AUDIO&&({min:a,max:c}={min:32,max:32}),(null===(i=this._bitrateInfo)||void 0===i?void 0:i.max)&&(d=.7*(null===(r=this._bitrateInfo)||void 0===r?void 0:r.max)),{min:(null===(n=this._bitrateInfo)||void 0===n?void 0:n.min)||a,max:(null===(o=this._bitrateInfo)||void 0===o?void 0:o.max)||c,start:(null===(s=this._bitrateInfo)||void 0===s?void 0:s.start)||d}}}rt.EVENT_LOCAL_TRACK_END="local-track-end",rt.__INNER_EVENT_MUTED_CHANGE__="inner-muted-change",rt.__INNER_EVENT_DESTROY__="inner-destroy";class nt extends rt{constructor(e,t,i){super(e,t,"audio",i),this._stopProcess=()=>{}}setRecommendBitrate(e){const t=We.getLogger();if(!i("audioBitrate",e,(e=>e in Qe)))return void(null==t||t.warn(f.L_RTC_SET_RECOMMEND_BITRATE_O,JSON.stringify({status:C.FAILED,msg:"params error -> params type is RCAudioBitrate"})));const r=Xe[e];this.setBitrate(r.max,r.min,r.start||.7*r.max)}setBitrate(e,...t){const[i=1,r=.7*e||1]=t;super.setBitrate(e,i,r)}__innerSetMediaStreamTrack(e){if(e)if(it.isOpen){const t=new MediaStream([e]);it.transformStreamTrack(t).then((({track:e,stop:t})=>{super.__innerSetMediaStreamTrack(e),this._stopProcess=t}))}else super.__innerSetMediaStreamTrack(e);else super.__innerSetMediaStreamTrack(e),this._stopProcess()}}class ot extends rt{constructor(e,t,i,r=!1){super(e,t,"video",i),this._isTiny=r}__isTiny(){return this._isTiny}getStreamId(){const e=super.getStreamId();return this._isTiny?`${e}_tiny`:e}getTrackId(){const e=super.getTrackId();return this._isTiny?`${e}_tiny`:e}setRecommendBitrate(e){const t=We.getLogger();if(!i("videoBitrate",e,(e=>e in et)))return void(null==t||t.warn(f.L_RTC_SET_RECOMMEND_BITRATE_O,JSON.stringify({status:C.FAILED,msg:"params error -> params type is RCVideoBitrate"})));const r=tt[e];this.setBitrate(r.max,r.min,r.start||.7*r.max)}setBitrate(e,...t){const[i=1,r=.7*e||1]=t;super.setBitrate(e,i,r)}}class st extends rt{static __innerSetMapping(e,t){const i=this._mapping.get(t)||[];i.push(e),this._mapping.set(t,i)}static __innerRemoveMapping(e,t){var i,r;const n=null===(i=this._mapping.get(t))||void 0===i?void 0:i.filter((t=>t!==e));n&&n.length>0?this._mapping.set(t,n):(this._mapping.delete(t),t.pause(),t.src="",null===(r=t.parentNode)||void 0===r||r.removeChild(t))}constructor(e,t,i,r,n){super(e,t,i,r),this._resource=n,st.__innerSetMapping(this.getTrackId(),n)}destroy(){this.isAudioTrack()&&this.mute(),st.__innerRemoveMapping(this.getTrackId(),this._resource),super.destroy()}}st._mapping=new Map;class at extends st{constructor(e,t,i,r){super(e,t,"video",i,r)}}class ct extends st{constructor(e,t,i,r){super(e,t,"audio",i,r),this._stopProcess=()=>{}}_setLocalMuted(e){const t=Object.create(null,{_setLocalMuted:{get:()=>super._setLocalMuted}});return S(this,void 0,void 0,(function*(){return this._resource&&(this._resource.muted=e),t._setLocalMuted.call(this,e)}))}play(){return this._setLocalMuted(!1),Promise.resolve({code:T.SUCCESS})}__innerSetMediaStreamTrack(e){if(e)if(it.isOpen){const t=new MediaStream([e]);it.transformStreamTrack(t).then((({track:e,stop:t})=>{super.__innerSetMediaStreamTrack(e),this._stopProcess=t}))}else super.__innerSetMediaStreamTrack(e);else super.__innerSetMediaStreamTrack(e),this._stopProcess()}}class dt extends nt{}class _t extends ot{}class lt extends ot{}class ut extends nt{}class ht extends Ze{constructor(e,t,i,r){super(e,t,i,!1,r),this._isSubscribed=!1}__innerSetRemoteMuted(e){this._remoteMuted=e}__innerSetSubscribed(e){this._isSubscribed=e}isSubscribed(){return this._isSubscribed}}class gt extends ht{constructor(e,t,i){super(e,t,"audio",i)}}class vt extends ht{constructor(e,t,i){super(e,t,"video",i),this._isSubTiny=!1}__innerSetIsTinyTrack(e){this._isSubTiny=e}isSubTiny(){return this._isSubTiny}}const pt=(e,t)=>({name:e,content:JSON.stringify({uris:t,ignore:!0})}),Rt=e=>JSON.stringify(e),mt=e=>/^[a-zA-Z\d-=]+$/g.test(e),It="http:"!==location.protocol||["localhost","127.0.0.1"].includes(location.hostname),Et=e=>{if(void 0===e)return 0;if(t(e))return e;const i=e;return i.exact||i.ideal||i.max||0},St=e=>{const t=e.getSettings(),i=e.getConstraints();return{width:Et(i.width)||t.width||0,height:Et(i.height)||t.height||0,frameRate:t.frameRate||Et(i.frameRate)}},Tt=e=>{const{width:t,height:i,frameRate:r}=St(e),n=Ke(t||1920,i||1080),o=$e(r);return{min:n.minBitrate*o,max:n.maxBitrate*o}},ft=e=>[e.msid,e.mediaType].join("_"),Ct=e=>{const t=e.split("_");return{mediaType:parseInt(t.pop()),tag:t.pop(),userId:t.join("_")}},Ot=(e,t)=>[e,t].join("_"),Lt=e=>e.map((e=>Object.assign({},e))),Nt=(e,t,i=!1)=>{e=e.slice();const r=[],n=[],o=[];return t.forEach((t=>{const n=ft(t);let s=e.findIndex((e=>ft(e)===n));if(i&&(s=e.findIndex((e=>e.uri===t.uri))),-1===s)return void r.push(t);const a=e[s];a.uri!==t.uri?r.push(t):a.state!==t.state&&o.push(t),e.splice(s,1)})),n.push(...e),{publishedList:r,unpublishedList:n,modifiedList:o}},At=()=>{let e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}));return e=`${e.replace(/-/g,"")}0`,e=parseInt(e,16),e=(e=>{const t="0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ+/".split(""),i=t.length+1;let r=+e;const n=[];do{const e=r%i;r=(r-e)/i,n.unshift(t[e])}while(r);return n.join("")})(e),e.length>22&&(e=e.slice(0,22)),e},yt=e=>{if(Ge[e]){const{width:t,height:i}=Ge[e];return{width:t,height:i}}const[t,i]=e.split("_").map((e=>parseInt(e.replace(/[^\d]/g,""))));return{width:t,height:i}},kt=e=>!!Fe[e],Dt=e=>!!Ve[e],bt=e=>parseInt(e.replace("FPS_","")),Ut=(()=>{const{browser:e,version:t,supportsUnifiedPlan:i}=Be.browserDetails;return{browser:e,version:t,supportsUnifiedPlan:!1!==i}})();function Pt(){return"captureStream"in HTMLMediaElement.prototype||"mozCaptureStream"in HTMLMediaElement.prototype}function Mt(){return"mediaDevices"in navigator&&"getDisplayMedia"in navigator.mediaDevices}const xt=e=>"[object Null]"===Object.prototype.toString.call(e),wt=e=>1===e.type,Bt=(e,t,i)=>{const r={},n=Object.keys(e.users);return n.length&&n.forEach((n=>{const o=[],s=e.users[n];if(s.extra){const{roomId:e}=JSON.parse(s.extra);if(t!==e)return}if(s.uris)try{o.push(...JSON.parse(s.uris))}catch(e){const t=We.getLogger();null==t||t.warn(f.L_PARSE_ROOMDATA_URIS_R,`invalid user data -> userId: ${n}, userData: ${s}`,i)}r[n]=o})),r},Vt=e=>e instanceof Ze?e.getTrackId():e.track.getTrackId(),Ft=e=>{if(!r(e)||void 0===e.low||void 0===e.high)return e;let{low:t}=e;t<0&&(t+=4294967296),t=t.toString(16);return parseInt(e.high.toString(16)+"00000000".replace(new RegExp(`0{${t.length}}$`),t),16)};var Jt,Gt;!function(e){e.PUBLISH="RCRTC:PublishResource",e.UNPUBLISH="RCRTC:UnpublishResource",e.MODIFY="RCRTC:ModifyResource",e.TOTAL_CONTENT_RESOURCE="RCRTC:TotalContentResources",e.STATE="RCRTC:state",e.ROOM_NOTIFY="RCRTC:RoomNtf",e.USER_NOTIFY="RCRTC:UserNtf",e.KICK="RCRTC:kick",e.PK_INVITE="RCRTC:invite",e.PK_INVITE_TIMEOUT="RCRTC:inviteTimeout",e.PK_CANCEL_INVITE="RCRTC:cancelInvite",e.PK_INVITE_ANSWER="RCRTC:answerInvite",e.PK_END="RCRTC:endInvite",e.OTHER_ROOM_OFFLINE="RCRTC:otherRoomOffline",e.ROOM_TASK_FINISH="RCRTC:roomTaskFinish"}(Jt||(Jt={})),function(e){e.SUCCESS="Success",e.FAIL="Fail"}(Gt||(Gt={}));class Ht{constructor(e,t,i=5e3,r=6e4){this._store=e,this._context=t,this._gap=i,this._offlineKickTime=r,this._latestTimestamp=Date.now(),this._started=!1,this._timer=null,this._pullRTCRoomStatus=(e,t,i)=>{};const{roomId:n,roomMode:o}=this._store;this._roomId=n,this._roomMode=o,this._offlineKickTime<15e3&&(this._offlineKickTime=15e3)}start(e){var t,i;this._pullRTCRoomStatus=e,this._started||(null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_PINGER_START_O,JSON.stringify({interval:this._gap,offlineKickTime:this._offlineKickTime})),this._started=!0,this._checkAlive())}_sendPing(e){return new Promise((t=>{this._context.rtcPing(this._roomId,this._roomMode).then(t).catch((i=>{var r,o;null===(o=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===o||o.error(f.L_PINGER_SEND_RTCPING_R,JSON.stringify({status:C.FAILED,msg:i}),e),t({code:n.UNKNOWN})})),setTimeout(t,5e3,n.TIMEOUT)}))}_diffPullRTCRoomStatus(e){var t,i,r,n;if(e>this._store.getRoomStatusVersion()){const o=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_RTCPING_PULL_ROOM_STATUS_O,JSON.stringify({pingerVersion:e}),o),this._pullRTCRoomStatus(this._roomId,o,e)}}_checkAlive(){var e,t,i,r,o,s,a,c,d,_,l;return S(this,void 0,void 0,(function*(){const u=null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t?void 0:t.createTraceId();null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_PINGER_SEND_RTCPING_T,JSON.stringify({roomId:this._roomId}),u);const{code:h,data:g}=yield this._sendPing(u),v=Date.now();return h===n.SUCCESS?(this._diffPullRTCRoomStatus(g.version),null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_PINGER_SEND_RTCPING_R,JSON.stringify({roomId:this._roomId,status:C.SUCCESSED}),u),this._latestTimestamp=v,null===(a=this.onPingResult)||void 0===a||a.call(this,Gt.SUCCESS),void(this._timer=setTimeout((()=>this._checkAlive()),this._gap))):(null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_PINGER_SEND_RTCPING_R,JSON.stringify({roomId:this._roomId,status:C.FAILED,code:h}),u),null===(_=this.onPingResult)||void 0===_||_.call(this,Gt.FAIL),40003===h||v-this._latestTimestamp>this._offlineKickTime?(this.stop(),void(null===(l=this.onFailed)||void 0===l||l.call(this,40003===h))):void(this._timer=setTimeout((()=>this._checkAlive()),500)))}))}stop(){var e,t;this._started&&(null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_PINGER_STOP_O),this._started=!1,this._timer&&(clearTimeout(this._timer),this._timer=null))}}
16
+ /*! pako 2.0.4 https://github.com/nodeca/pako @license (MIT AND Zlib) */function Kt(e){let t=e.length;for(;--t>=0;)e[t]=0}const jt=256,$t=286,Wt=30,Yt=15,qt=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),zt=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),Qt=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),Zt=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Xt=new Array(576);Kt(Xt);const ei=new Array(60);Kt(ei);const ti=new Array(512);Kt(ti);const ii=new Array(256);Kt(ii);const ri=new Array(29);Kt(ri);const ni=new Array(Wt);function oi(e,t,i,r,n){this.static_tree=e,this.extra_bits=t,this.extra_base=i,this.elems=r,this.max_length=n,this.has_stree=e&&e.length}let si,ai,ci;function di(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}Kt(ni);const _i=e=>e<256?ti[e]:ti[256+(e>>>7)],li=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},ui=(e,t,i)=>{e.bi_valid>16-i?(e.bi_buf|=t<<e.bi_valid&65535,li(e,e.bi_buf),e.bi_buf=t>>16-e.bi_valid,e.bi_valid+=i-16):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=i)},hi=(e,t,i)=>{ui(e,i[2*t],i[2*t+1])},gi=(e,t)=>{let i=0;do{i|=1&e,e>>>=1,i<<=1}while(--t>0);return i>>>1},vi=(e,t,i)=>{const r=new Array(16);let n,o,s=0;for(n=1;n<=Yt;n++)r[n]=s=s+i[n-1]<<1;for(o=0;o<=t;o++){let t=e[2*o+1];0!==t&&(e[2*o]=gi(r[t]++,t))}},pi=e=>{let t;for(t=0;t<$t;t++)e.dyn_ltree[2*t]=0;for(t=0;t<Wt;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0},Ri=e=>{e.bi_valid>8?li(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},mi=(e,t,i,r)=>{const n=2*t,o=2*i;return e[n]<e[o]||e[n]===e[o]&&r[t]<=r[i]},Ii=(e,t,i)=>{const r=e.heap[i];let n=i<<1;for(;n<=e.heap_len&&(n<e.heap_len&&mi(t,e.heap[n+1],e.heap[n],e.depth)&&n++,!mi(t,r,e.heap[n],e.depth));)e.heap[i]=e.heap[n],i=n,n<<=1;e.heap[i]=r},Ei=(e,t,i)=>{let r,n,o,s,a=0;if(0!==e.last_lit)do{r=e.pending_buf[e.d_buf+2*a]<<8|e.pending_buf[e.d_buf+2*a+1],n=e.pending_buf[e.l_buf+a],a++,0===r?hi(e,n,t):(o=ii[n],hi(e,o+jt+1,t),s=qt[o],0!==s&&(n-=ri[o],ui(e,n,s)),r--,o=_i(r),hi(e,o,i),s=zt[o],0!==s&&(r-=ni[o],ui(e,r,s)))}while(a<e.last_lit);hi(e,256,t)},Si=(e,t)=>{const i=t.dyn_tree,r=t.stat_desc.static_tree,n=t.stat_desc.has_stree,o=t.stat_desc.elems;let s,a,c,d=-1;for(e.heap_len=0,e.heap_max=573,s=0;s<o;s++)0!==i[2*s]?(e.heap[++e.heap_len]=d=s,e.depth[s]=0):i[2*s+1]=0;for(;e.heap_len<2;)c=e.heap[++e.heap_len]=d<2?++d:0,i[2*c]=1,e.depth[c]=0,e.opt_len--,n&&(e.static_len-=r[2*c+1]);for(t.max_code=d,s=e.heap_len>>1;s>=1;s--)Ii(e,i,s);c=o;do{s=e.heap[1],e.heap[1]=e.heap[e.heap_len--],Ii(e,i,1),a=e.heap[1],e.heap[--e.heap_max]=s,e.heap[--e.heap_max]=a,i[2*c]=i[2*s]+i[2*a],e.depth[c]=(e.depth[s]>=e.depth[a]?e.depth[s]:e.depth[a])+1,i[2*s+1]=i[2*a+1]=c,e.heap[1]=c++,Ii(e,i,1)}while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],((e,t)=>{const i=t.dyn_tree,r=t.max_code,n=t.stat_desc.static_tree,o=t.stat_desc.has_stree,s=t.stat_desc.extra_bits,a=t.stat_desc.extra_base,c=t.stat_desc.max_length;let d,_,l,u,h,g,v=0;for(u=0;u<=Yt;u++)e.bl_count[u]=0;for(i[2*e.heap[e.heap_max]+1]=0,d=e.heap_max+1;d<573;d++)_=e.heap[d],u=i[2*i[2*_+1]+1]+1,u>c&&(u=c,v++),i[2*_+1]=u,_>r||(e.bl_count[u]++,h=0,_>=a&&(h=s[_-a]),g=i[2*_],e.opt_len+=g*(u+h),o&&(e.static_len+=g*(n[2*_+1]+h)));if(0!==v){do{for(u=c-1;0===e.bl_count[u];)u--;e.bl_count[u]--,e.bl_count[u+1]+=2,e.bl_count[c]--,v-=2}while(v>0);for(u=c;0!==u;u--)for(_=e.bl_count[u];0!==_;)l=e.heap[--d],l>r||(i[2*l+1]!==u&&(e.opt_len+=(u-i[2*l+1])*i[2*l],i[2*l+1]=u),_--)}})(e,t),vi(i,d,e.bl_count)},Ti=(e,t,i)=>{let r,n,o=-1,s=t[1],a=0,c=7,d=4;for(0===s&&(c=138,d=3),t[2*(i+1)+1]=65535,r=0;r<=i;r++)n=s,s=t[2*(r+1)+1],++a<c&&n===s||(a<d?e.bl_tree[2*n]+=a:0!==n?(n!==o&&e.bl_tree[2*n]++,e.bl_tree[32]++):a<=10?e.bl_tree[34]++:e.bl_tree[36]++,a=0,o=n,0===s?(c=138,d=3):n===s?(c=6,d=3):(c=7,d=4))},fi=(e,t,i)=>{let r,n,o=-1,s=t[1],a=0,c=7,d=4;for(0===s&&(c=138,d=3),r=0;r<=i;r++)if(n=s,s=t[2*(r+1)+1],!(++a<c&&n===s)){if(a<d)do{hi(e,n,e.bl_tree)}while(0!=--a);else 0!==n?(n!==o&&(hi(e,n,e.bl_tree),a--),hi(e,16,e.bl_tree),ui(e,a-3,2)):a<=10?(hi(e,17,e.bl_tree),ui(e,a-3,3)):(hi(e,18,e.bl_tree),ui(e,a-11,7));a=0,o=n,0===s?(c=138,d=3):n===s?(c=6,d=3):(c=7,d=4)}};let Ci=!1;const Oi=(e,t,i,r)=>{ui(e,0+(r?1:0),3),((e,t,i,r)=>{Ri(e),r&&(li(e,i),li(e,~i)),e.pending_buf.set(e.window.subarray(t,t+i),e.pending),e.pending+=i})(e,t,i,!0)};var Li=(e,t,i,r)=>{let n,o,s=0;e.level>0?(2===e.strm.data_type&&(e.strm.data_type=(e=>{let t,i=4093624447;for(t=0;t<=31;t++,i>>>=1)if(1&i&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t<jt;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0})(e)),Si(e,e.l_desc),Si(e,e.d_desc),s=(e=>{let t;for(Ti(e,e.dyn_ltree,e.l_desc.max_code),Ti(e,e.dyn_dtree,e.d_desc.max_code),Si(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*Zt[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),n=e.opt_len+3+7>>>3,o=e.static_len+3+7>>>3,o<=n&&(n=o)):n=o=i+5,i+4<=n&&-1!==t?Oi(e,t,i,r):4===e.strategy||o===n?(ui(e,2+(r?1:0),3),Ei(e,Xt,ei)):(ui(e,4+(r?1:0),3),((e,t,i,r)=>{let n;for(ui(e,t-257,5),ui(e,i-1,5),ui(e,r-4,4),n=0;n<r;n++)ui(e,e.bl_tree[2*Zt[n]+1],3);fi(e,e.dyn_ltree,t-1),fi(e,e.dyn_dtree,i-1)})(e,e.l_desc.max_code+1,e.d_desc.max_code+1,s+1),Ei(e,e.dyn_ltree,e.dyn_dtree)),pi(e),r&&Ri(e)},Ni={_tr_init:e=>{Ci||((()=>{let e,t,i,r,n;const o=new Array(16);for(i=0,r=0;r<28;r++)for(ri[r]=i,e=0;e<1<<qt[r];e++)ii[i++]=r;for(ii[i-1]=r,n=0,r=0;r<16;r++)for(ni[r]=n,e=0;e<1<<zt[r];e++)ti[n++]=r;for(n>>=7;r<Wt;r++)for(ni[r]=n<<7,e=0;e<1<<zt[r]-7;e++)ti[256+n++]=r;for(t=0;t<=Yt;t++)o[t]=0;for(e=0;e<=143;)Xt[2*e+1]=8,e++,o[8]++;for(;e<=255;)Xt[2*e+1]=9,e++,o[9]++;for(;e<=279;)Xt[2*e+1]=7,e++,o[7]++;for(;e<=287;)Xt[2*e+1]=8,e++,o[8]++;for(vi(Xt,287,o),e=0;e<Wt;e++)ei[2*e+1]=5,ei[2*e]=gi(e,5);si=new oi(Xt,qt,257,$t,Yt),ai=new oi(ei,zt,0,Wt,Yt),ci=new oi(new Array(0),Qt,0,19,7)})(),Ci=!0),e.l_desc=new di(e.dyn_ltree,si),e.d_desc=new di(e.dyn_dtree,ai),e.bl_desc=new di(e.bl_tree,ci),e.bi_buf=0,e.bi_valid=0,pi(e)},_tr_stored_block:Oi,_tr_flush_block:Li,_tr_tally:(e,t,i)=>(e.pending_buf[e.d_buf+2*e.last_lit]=t>>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&i,e.last_lit++,0===t?e.dyn_ltree[2*i]++:(e.matches++,t--,e.dyn_ltree[2*(ii[i]+jt+1)]++,e.dyn_dtree[2*_i(t)]++),e.last_lit===e.lit_bufsize-1),_tr_align:e=>{ui(e,2,3),hi(e,256,Xt),(e=>{16===e.bi_valid?(li(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)})(e)}};var Ai=(e,t,i,r)=>{let n=65535&e|0,o=e>>>16&65535|0,s=0;for(;0!==i;){s=i>2e3?2e3:i,i-=s;do{n=n+t[r++]|0,o=o+n|0}while(--s);n%=65521,o%=65521}return n|o<<16|0};const yi=new Uint32Array((()=>{let e,t=[];for(var i=0;i<256;i++){e=i;for(var r=0;r<8;r++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t})());var ki=(e,t,i,r)=>{const n=yi,o=r+i;e^=-1;for(let i=r;i<o;i++)e=e>>>8^n[255&(e^t[i])];return-1^e},Di={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},bi={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:Ui,_tr_stored_block:Pi,_tr_flush_block:Mi,_tr_tally:xi,_tr_align:wi}=Ni,{Z_NO_FLUSH:Bi,Z_PARTIAL_FLUSH:Vi,Z_FULL_FLUSH:Fi,Z_FINISH:Ji,Z_BLOCK:Gi,Z_OK:Hi,Z_STREAM_END:Ki,Z_STREAM_ERROR:ji,Z_DATA_ERROR:$i,Z_BUF_ERROR:Wi,Z_DEFAULT_COMPRESSION:Yi,Z_FILTERED:qi,Z_HUFFMAN_ONLY:zi,Z_RLE:Qi,Z_FIXED:Zi,Z_DEFAULT_STRATEGY:Xi,Z_UNKNOWN:er,Z_DEFLATED:tr}=bi,ir=286,rr=30,nr=19,or=2*ir+1,sr=15,ar=258,cr=262,dr=103,_r=113,lr=666,ur=(e,t)=>(e.msg=Di[t],t),hr=e=>(e<<1)-(e>4?9:0),gr=e=>{let t=e.length;for(;--t>=0;)e[t]=0};let vr=(e,t,i)=>(t<<e.hash_shift^i)&e.hash_mask;const pr=e=>{const t=e.state;let i=t.pending;i>e.avail_out&&(i=e.avail_out),0!==i&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+i),e.next_out),e.next_out+=i,t.pending_out+=i,e.total_out+=i,e.avail_out-=i,t.pending-=i,0===t.pending&&(t.pending_out=0))},Rr=(e,t)=>{Mi(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,pr(e.strm)},mr=(e,t)=>{e.pending_buf[e.pending++]=t},Ir=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},Er=(e,t,i,r)=>{let n=e.avail_in;return n>r&&(n=r),0===n?0:(e.avail_in-=n,t.set(e.input.subarray(e.next_in,e.next_in+n),i),1===e.state.wrap?e.adler=Ai(e.adler,t,n,i):2===e.state.wrap&&(e.adler=ki(e.adler,t,n,i)),e.next_in+=n,e.total_in+=n,n)},Sr=(e,t)=>{let i,r,n=e.max_chain_length,o=e.strstart,s=e.prev_length,a=e.nice_match;const c=e.strstart>e.w_size-cr?e.strstart-(e.w_size-cr):0,d=e.window,_=e.w_mask,l=e.prev,u=e.strstart+ar;let h=d[o+s-1],g=d[o+s];e.prev_length>=e.good_match&&(n>>=2),a>e.lookahead&&(a=e.lookahead);do{if(i=t,d[i+s]===g&&d[i+s-1]===h&&d[i]===d[o]&&d[++i]===d[o+1]){o+=2,i++;do{}while(d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&d[++o]===d[++i]&&o<u);if(r=ar-(u-o),o=u-ar,r>s){if(e.match_start=t,s=r,r>=a)break;h=d[o+s-1],g=d[o+s]}}}while((t=l[t&_])>c&&0!=--n);return s<=e.lookahead?s:e.lookahead},Tr=e=>{const t=e.w_size;let i,r,n,o,s;do{if(o=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-cr)){e.window.set(e.window.subarray(t,t+t),0),e.match_start-=t,e.strstart-=t,e.block_start-=t,r=e.hash_size,i=r;do{n=e.head[--i],e.head[i]=n>=t?n-t:0}while(--r);r=t,i=r;do{n=e.prev[--i],e.prev[i]=n>=t?n-t:0}while(--r);o+=t}if(0===e.strm.avail_in)break;if(r=Er(e.strm,e.window,e.strstart+e.lookahead,o),e.lookahead+=r,e.lookahead+e.insert>=3)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=vr(e,e.ins_h,e.window[s+1]);e.insert&&(e.ins_h=vr(e,e.ins_h,e.window[s+3-1]),e.prev[s&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=s,s++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookahead<cr&&0!==e.strm.avail_in)},fr=(e,t)=>{let i,r;for(;;){if(e.lookahead<cr){if(Tr(e),e.lookahead<cr&&t===Bi)return 1;if(0===e.lookahead)break}if(i=0,e.lookahead>=3&&(e.ins_h=vr(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==i&&e.strstart-i<=e.w_size-cr&&(e.match_length=Sr(e,i)),e.match_length>=3)if(r=xi(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do{e.strstart++,e.ins_h=vr(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart}while(0!=--e.match_length);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=vr(e,e.ins_h,e.window[e.strstart+1]);else r=xi(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(r&&(Rr(e,!1),0===e.strm.avail_out))return 1}return e.insert=e.strstart<2?e.strstart:2,t===Ji?(Rr(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(Rr(e,!1),0===e.strm.avail_out)?1:2},Cr=(e,t)=>{let i,r,n;for(;;){if(e.lookahead<cr){if(Tr(e),e.lookahead<cr&&t===Bi)return 1;if(0===e.lookahead)break}if(i=0,e.lookahead>=3&&(e.ins_h=vr(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==i&&e.prev_length<e.max_lazy_match&&e.strstart-i<=e.w_size-cr&&(e.match_length=Sr(e,i),e.match_length<=5&&(e.strategy===qi||3===e.match_length&&e.strstart-e.match_start>4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){n=e.strstart+e.lookahead-3,r=xi(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do{++e.strstart<=n&&(e.ins_h=vr(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart)}while(0!=--e.prev_length);if(e.match_available=0,e.match_length=2,e.strstart++,r&&(Rr(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if(r=xi(e,0,e.window[e.strstart-1]),r&&Rr(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(r=xi(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===Ji?(Rr(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(Rr(e,!1),0===e.strm.avail_out)?1:2};function Or(e,t,i,r,n){this.good_length=e,this.max_lazy=t,this.nice_length=i,this.max_chain=r,this.func=n}const Lr=[new Or(0,0,0,0,((e,t)=>{let i=65535;for(i>e.pending_buf_size-5&&(i=e.pending_buf_size-5);;){if(e.lookahead<=1){if(Tr(e),0===e.lookahead&&t===Bi)return 1;if(0===e.lookahead)break}e.strstart+=e.lookahead,e.lookahead=0;const r=e.block_start+i;if((0===e.strstart||e.strstart>=r)&&(e.lookahead=e.strstart-r,e.strstart=r,Rr(e,!1),0===e.strm.avail_out))return 1;if(e.strstart-e.block_start>=e.w_size-cr&&(Rr(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ji?(Rr(e,!0),0===e.strm.avail_out?3:4):(e.strstart>e.block_start&&(Rr(e,!1),e.strm.avail_out),1)})),new Or(4,4,8,4,fr),new Or(4,5,16,8,fr),new Or(4,6,32,32,fr),new Or(4,4,16,16,Cr),new Or(8,16,32,32,Cr),new Or(8,16,128,128,Cr),new Or(8,32,128,256,Cr),new Or(32,128,258,1024,Cr),new Or(32,258,258,4096,Cr)];function Nr(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=tr,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(2*or),this.dyn_dtree=new Uint16Array(2*(2*rr+1)),this.bl_tree=new Uint16Array(2*(2*nr+1)),gr(this.dyn_ltree),gr(this.dyn_dtree),gr(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(sr+1),this.heap=new Uint16Array(2*ir+1),gr(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*ir+1),gr(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Ar=e=>{if(!e||!e.state)return ur(e,ji);e.total_in=e.total_out=0,e.data_type=er;const t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?42:_r,e.adler=2===t.wrap?0:1,t.last_flush=Bi,Ui(t),Hi},yr=e=>{const t=Ar(e);var i;return t===Hi&&((i=e.state).window_size=2*i.w_size,gr(i.head),i.max_lazy_match=Lr[i.level].max_lazy,i.good_match=Lr[i.level].good_length,i.nice_match=Lr[i.level].nice_length,i.max_chain_length=Lr[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),t},kr=(e,t,i,r,n,o)=>{if(!e)return ji;let s=1;if(t===Yi&&(t=6),r<0?(s=0,r=-r):r>15&&(s=2,r-=16),n<1||n>9||i!==tr||r<8||r>15||t<0||t>9||o<0||o>Zi)return ur(e,ji);8===r&&(r=9);const a=new Nr;return e.state=a,a.strm=e,a.wrap=s,a.gzhead=null,a.w_bits=r,a.w_size=1<<a.w_bits,a.w_mask=a.w_size-1,a.hash_bits=n+7,a.hash_size=1<<a.hash_bits,a.hash_mask=a.hash_size-1,a.hash_shift=~~((a.hash_bits+3-1)/3),a.window=new Uint8Array(2*a.w_size),a.head=new Uint16Array(a.hash_size),a.prev=new Uint16Array(a.w_size),a.lit_bufsize=1<<n+6,a.pending_buf_size=4*a.lit_bufsize,a.pending_buf=new Uint8Array(a.pending_buf_size),a.d_buf=1*a.lit_bufsize,a.l_buf=3*a.lit_bufsize,a.level=t,a.strategy=o,a.method=i,yr(e)};var Dr={deflateInit:(e,t)=>kr(e,t,tr,15,8,Xi),deflateInit2:kr,deflateReset:yr,deflateResetKeep:Ar,deflateSetHeader:(e,t)=>e&&e.state?2!==e.state.wrap?ji:(e.state.gzhead=t,Hi):ji,deflate:(e,t)=>{let i,r;if(!e||!e.state||t>Gi||t<0)return e?ur(e,ji):ji;const n=e.state;if(!e.output||!e.input&&0!==e.avail_in||n.status===lr&&t!==Ji)return ur(e,0===e.avail_out?Wi:ji);n.strm=e;const o=n.last_flush;if(n.last_flush=t,42===n.status)if(2===n.wrap)e.adler=0,mr(n,31),mr(n,139),mr(n,8),n.gzhead?(mr(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),mr(n,255&n.gzhead.time),mr(n,n.gzhead.time>>8&255),mr(n,n.gzhead.time>>16&255),mr(n,n.gzhead.time>>24&255),mr(n,9===n.level?2:n.strategy>=zi||n.level<2?4:0),mr(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(mr(n,255&n.gzhead.extra.length),mr(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=ki(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(mr(n,0),mr(n,0),mr(n,0),mr(n,0),mr(n,0),mr(n,9===n.level?2:n.strategy>=zi||n.level<2?4:0),mr(n,3),n.status=_r);else{let t=tr+(n.w_bits-8<<4)<<8,i=-1;i=n.strategy>=zi||n.level<2?0:n.level<6?1:6===n.level?2:3,t|=i<<6,0!==n.strstart&&(t|=32),t+=31-t%31,n.status=_r,Ir(n,t),0!==n.strstart&&(Ir(n,e.adler>>>16),Ir(n,65535&e.adler)),e.adler=1}if(69===n.status)if(n.gzhead.extra){for(i=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),pr(e),i=n.pending,n.pending!==n.pending_buf_size));)mr(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=73)}else n.status=73;if(73===n.status)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),pr(e),i=n.pending,n.pending===n.pending_buf_size)){r=1;break}r=n.gzindex<n.gzhead.name.length?255&n.gzhead.name.charCodeAt(n.gzindex++):0,mr(n,r)}while(0!==r);n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),0===r&&(n.gzindex=0,n.status=91)}else n.status=91;if(91===n.status)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),pr(e),i=n.pending,n.pending===n.pending_buf_size)){r=1;break}r=n.gzindex<n.gzhead.comment.length?255&n.gzhead.comment.charCodeAt(n.gzindex++):0,mr(n,r)}while(0!==r);n.gzhead.hcrc&&n.pending>i&&(e.adler=ki(e.adler,n.pending_buf,n.pending-i,i)),0===r&&(n.status=dr)}else n.status=dr;if(n.status===dr&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&pr(e),n.pending+2<=n.pending_buf_size&&(mr(n,255&e.adler),mr(n,e.adler>>8&255),e.adler=0,n.status=_r)):n.status=_r),0!==n.pending){if(pr(e),0===e.avail_out)return n.last_flush=-1,Hi}else if(0===e.avail_in&&hr(t)<=hr(o)&&t!==Ji)return ur(e,Wi);if(n.status===lr&&0!==e.avail_in)return ur(e,Wi);if(0!==e.avail_in||0!==n.lookahead||t!==Bi&&n.status!==lr){let i=n.strategy===zi?((e,t)=>{let i;for(;;){if(0===e.lookahead&&(Tr(e),0===e.lookahead)){if(t===Bi)return 1;break}if(e.match_length=0,i=xi(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,i&&(Rr(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ji?(Rr(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(Rr(e,!1),0===e.strm.avail_out)?1:2})(n,t):n.strategy===Qi?((e,t)=>{let i,r,n,o;const s=e.window;for(;;){if(e.lookahead<=ar){if(Tr(e),e.lookahead<=ar&&t===Bi)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(n=e.strstart-1,r=s[n],r===s[++n]&&r===s[++n]&&r===s[++n])){o=e.strstart+ar;do{}while(r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&n<o);e.match_length=ar-(o-n),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(i=xi(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(i=xi(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),i&&(Rr(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ji?(Rr(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(Rr(e,!1),0===e.strm.avail_out)?1:2})(n,t):Lr[n.level].func(n,t);if(3!==i&&4!==i||(n.status=lr),1===i||3===i)return 0===e.avail_out&&(n.last_flush=-1),Hi;if(2===i&&(t===Vi?wi(n):t!==Gi&&(Pi(n,0,0,!1),t===Fi&&(gr(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),pr(e),0===e.avail_out))return n.last_flush=-1,Hi}return t!==Ji?Hi:n.wrap<=0?Ki:(2===n.wrap?(mr(n,255&e.adler),mr(n,e.adler>>8&255),mr(n,e.adler>>16&255),mr(n,e.adler>>24&255),mr(n,255&e.total_in),mr(n,e.total_in>>8&255),mr(n,e.total_in>>16&255),mr(n,e.total_in>>24&255)):(Ir(n,e.adler>>>16),Ir(n,65535&e.adler)),pr(e),n.wrap>0&&(n.wrap=-n.wrap),0!==n.pending?Hi:Ki)},deflateEnd:e=>{if(!e||!e.state)return ji;const t=e.state.status;return 42!==t&&69!==t&&73!==t&&91!==t&&t!==dr&&t!==_r&&t!==lr?ur(e,ji):(e.state=null,t===_r?ur(e,$i):Hi)},deflateSetDictionary:(e,t)=>{let i=t.length;if(!e||!e.state)return ji;const r=e.state,n=r.wrap;if(2===n||1===n&&42!==r.status||r.lookahead)return ji;if(1===n&&(e.adler=Ai(e.adler,t,i,0)),r.wrap=0,i>=r.w_size){0===n&&(gr(r.head),r.strstart=0,r.block_start=0,r.insert=0);let e=new Uint8Array(r.w_size);e.set(t.subarray(i-r.w_size,i),0),t=e,i=r.w_size}const o=e.avail_in,s=e.next_in,a=e.input;for(e.avail_in=i,e.next_in=0,e.input=t,Tr(r);r.lookahead>=3;){let e=r.strstart,t=r.lookahead-2;do{r.ins_h=vr(r,r.ins_h,r.window[e+3-1]),r.prev[e&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=e,e++}while(--t);r.strstart=e,r.lookahead=2,Tr(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=2,r.match_available=0,e.next_in=s,e.input=a,e.avail_in=o,r.wrap=n,Hi},deflateInfo:"pako deflate (from Nodeca project)"};const br=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var Ur={assign:function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const i=t.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const t in i)br(i,t)&&(e[t]=i[t])}}return e},flattenChunks:e=>{let t=0;for(let i=0,r=e.length;i<r;i++)t+=e[i].length;const i=new Uint8Array(t);for(let t=0,r=0,n=e.length;t<n;t++){let n=e[t];i.set(n,r),r+=n.length}return i}};let Pr=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(e){Pr=!1}const Mr=new Uint8Array(256);for(let e=0;e<256;e++)Mr[e]=e>=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;Mr[254]=Mr[254]=1;var xr={string2buf:e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);let t,i,r,n,o,s=e.length,a=0;for(n=0;n<s;n++)i=e.charCodeAt(n),55296==(64512&i)&&n+1<s&&(r=e.charCodeAt(n+1),56320==(64512&r)&&(i=65536+(i-55296<<10)+(r-56320),n++)),a+=i<128?1:i<2048?2:i<65536?3:4;for(t=new Uint8Array(a),o=0,n=0;o<a;n++)i=e.charCodeAt(n),55296==(64512&i)&&n+1<s&&(r=e.charCodeAt(n+1),56320==(64512&r)&&(i=65536+(i-55296<<10)+(r-56320),n++)),i<128?t[o++]=i:i<2048?(t[o++]=192|i>>>6,t[o++]=128|63&i):i<65536?(t[o++]=224|i>>>12,t[o++]=128|i>>>6&63,t[o++]=128|63&i):(t[o++]=240|i>>>18,t[o++]=128|i>>>12&63,t[o++]=128|i>>>6&63,t[o++]=128|63&i);return t},buf2string:(e,t)=>{const i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));let r,n;const o=new Array(2*i);for(n=0,r=0;r<i;){let t=e[r++];if(t<128){o[n++]=t;continue}let s=Mr[t];if(s>4)o[n++]=65533,r+=s-1;else{for(t&=2===s?31:3===s?15:7;s>1&&r<i;)t=t<<6|63&e[r++],s--;s>1?o[n++]=65533:t<65536?o[n++]=t:(t-=65536,o[n++]=55296|t>>10&1023,o[n++]=56320|1023&t)}}return((e,t)=>{if(t<65534&&e.subarray&&Pr)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let i="";for(let r=0;r<t;r++)i+=String.fromCharCode(e[r]);return i})(o,n)},utf8border:(e,t)=>{(t=t||e.length)>e.length&&(t=e.length);let i=t-1;for(;i>=0&&128==(192&e[i]);)i--;return i<0||0===i?t:i+Mr[e[i]]>t?i:t}};var wr=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Br=Object.prototype.toString,{Z_NO_FLUSH:Vr,Z_SYNC_FLUSH:Fr,Z_FULL_FLUSH:Jr,Z_FINISH:Gr,Z_OK:Hr,Z_STREAM_END:Kr,Z_DEFAULT_COMPRESSION:jr,Z_DEFAULT_STRATEGY:$r,Z_DEFLATED:Wr}=bi;function Yr(e){this.options=Ur.assign({level:jr,method:Wr,chunkSize:16384,windowBits:15,memLevel:8,strategy:$r},e||{});let t=this.options;t.raw&&t.windowBits>0?t.windowBits=-t.windowBits:t.gzip&&t.windowBits>0&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new wr,this.strm.avail_out=0;let i=Dr.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(i!==Hr)throw new Error(Di[i]);if(t.header&&Dr.deflateSetHeader(this.strm,t.header),t.dictionary){let e;if(e="string"==typeof t.dictionary?xr.string2buf(t.dictionary):"[object ArrayBuffer]"===Br.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,i=Dr.deflateSetDictionary(this.strm,e),i!==Hr)throw new Error(Di[i]);this._dict_set=!0}}function qr(e,t){const i=new Yr(t);if(i.push(e,!0),i.err)throw i.msg||Di[i.err];return i.result}Yr.prototype.push=function(e,t){const i=this.strm,r=this.options.chunkSize;let n,o;if(this.ended)return!1;for(o=t===~~t?t:!0===t?Gr:Vr,"string"==typeof e?i.input=xr.string2buf(e):"[object ArrayBuffer]"===Br.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(r),i.next_out=0,i.avail_out=r),(o===Fr||o===Jr)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(n=Dr.deflate(i,o),n===Kr)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),n=Dr.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===Hr;if(0!==i.avail_out){if(o>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},Yr.prototype.onData=function(e){this.chunks.push(e)},Yr.prototype.onEnd=function(e){e===Hr&&(this.result=Ur.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var zr={Deflate:Yr,deflate:qr,deflateRaw:function(e,t){return(t=t||{}).raw=!0,qr(e,t)},gzip:function(e,t){return(t=t||{}).gzip=!0,qr(e,t)},constants:bi};var Qr=function(e,t){let i,r,n,o,s,a,c,d,_,l,u,h,g,v,p,R,m,I,E,S,T,f,C,O;const L=e.state;i=e.next_in,C=e.input,r=i+(e.avail_in-5),n=e.next_out,O=e.output,o=n-(t-e.avail_out),s=n+(e.avail_out-257),a=L.dmax,c=L.wsize,d=L.whave,_=L.wnext,l=L.window,u=L.hold,h=L.bits,g=L.lencode,v=L.distcode,p=(1<<L.lenbits)-1,R=(1<<L.distbits)-1;e:do{h<15&&(u+=C[i++]<<h,h+=8,u+=C[i++]<<h,h+=8),m=g[u&p];t:for(;;){if(I=m>>>24,u>>>=I,h-=I,I=m>>>16&255,0===I)O[n++]=65535&m;else{if(!(16&I)){if(0==(64&I)){m=g[(65535&m)+(u&(1<<I)-1)];continue t}if(32&I){L.mode=12;break e}e.msg="invalid literal/length code",L.mode=30;break e}E=65535&m,I&=15,I&&(h<I&&(u+=C[i++]<<h,h+=8),E+=u&(1<<I)-1,u>>>=I,h-=I),h<15&&(u+=C[i++]<<h,h+=8,u+=C[i++]<<h,h+=8),m=v[u&R];i:for(;;){if(I=m>>>24,u>>>=I,h-=I,I=m>>>16&255,!(16&I)){if(0==(64&I)){m=v[(65535&m)+(u&(1<<I)-1)];continue i}e.msg="invalid distance code",L.mode=30;break e}if(S=65535&m,I&=15,h<I&&(u+=C[i++]<<h,h+=8,h<I&&(u+=C[i++]<<h,h+=8)),S+=u&(1<<I)-1,S>a){e.msg="invalid distance too far back",L.mode=30;break e}if(u>>>=I,h-=I,I=n-o,S>I){if(I=S-I,I>d&&L.sane){e.msg="invalid distance too far back",L.mode=30;break e}if(T=0,f=l,0===_){if(T+=c-I,I<E){E-=I;do{O[n++]=l[T++]}while(--I);T=n-S,f=O}}else if(_<I){if(T+=c+_-I,I-=_,I<E){E-=I;do{O[n++]=l[T++]}while(--I);if(T=0,_<E){I=_,E-=I;do{O[n++]=l[T++]}while(--I);T=n-S,f=O}}}else if(T+=_-I,I<E){E-=I;do{O[n++]=l[T++]}while(--I);T=n-S,f=O}for(;E>2;)O[n++]=f[T++],O[n++]=f[T++],O[n++]=f[T++],E-=3;E&&(O[n++]=f[T++],E>1&&(O[n++]=f[T++]))}else{T=n-S;do{O[n++]=O[T++],O[n++]=O[T++],O[n++]=O[T++],E-=3}while(E>2);E&&(O[n++]=O[T++],E>1&&(O[n++]=O[T++]))}break}}break}}while(i<r&&n<s);E=h>>3,i-=E,h-=E<<3,u&=(1<<h)-1,e.next_in=i,e.next_out=n,e.avail_in=i<r?r-i+5:5-(i-r),e.avail_out=n<s?s-n+257:257-(n-s),L.hold=u,L.bits=h};const Zr=15,Xr=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),en=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),tn=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),rn=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var nn=(e,t,i,r,n,o,s,a)=>{const c=a.bits;let d,_,l,u,h,g,v=0,p=0,R=0,m=0,I=0,E=0,S=0,T=0,f=0,C=0,O=null,L=0;const N=new Uint16Array(16),A=new Uint16Array(16);let y,k,D,b=null,U=0;for(v=0;v<=Zr;v++)N[v]=0;for(p=0;p<r;p++)N[t[i+p]]++;for(I=c,m=Zr;m>=1&&0===N[m];m--);if(I>m&&(I=m),0===m)return n[o++]=20971520,n[o++]=20971520,a.bits=1,0;for(R=1;R<m&&0===N[R];R++);for(I<R&&(I=R),T=1,v=1;v<=Zr;v++)if(T<<=1,T-=N[v],T<0)return-1;if(T>0&&(0===e||1!==m))return-1;for(A[1]=0,v=1;v<Zr;v++)A[v+1]=A[v]+N[v];for(p=0;p<r;p++)0!==t[i+p]&&(s[A[t[i+p]]++]=p);if(0===e?(O=b=s,g=19):1===e?(O=Xr,L-=257,b=en,U-=257,g=256):(O=tn,b=rn,g=-1),C=0,p=0,v=R,h=o,E=I,S=0,l=-1,f=1<<I,u=f-1,1===e&&f>852||2===e&&f>592)return 1;for(;;){y=v-S,s[p]<g?(k=0,D=s[p]):s[p]>g?(k=b[U+s[p]],D=O[L+s[p]]):(k=96,D=0),d=1<<v-S,_=1<<E,R=_;do{_-=d,n[h+(C>>S)+_]=y<<24|k<<16|D|0}while(0!==_);for(d=1<<v-1;C&d;)d>>=1;if(0!==d?(C&=d-1,C+=d):C=0,p++,0==--N[v]){if(v===m)break;v=t[i+s[p]]}if(v>I&&(C&u)!==l){for(0===S&&(S=I),h+=R,E=v-S,T=1<<E;E+S<m&&(T-=N[E+S],!(T<=0));)E++,T<<=1;if(f+=1<<E,1===e&&f>852||2===e&&f>592)return 1;l=C&u,n[l]=I<<24|E<<16|h-o|0}}return 0!==C&&(n[h+C]=v-S<<24|64<<16|0),a.bits=I,0};const{Z_FINISH:on,Z_BLOCK:sn,Z_TREES:an,Z_OK:cn,Z_STREAM_END:dn,Z_NEED_DICT:_n,Z_STREAM_ERROR:ln,Z_DATA_ERROR:un,Z_MEM_ERROR:hn,Z_BUF_ERROR:gn,Z_DEFLATED:vn}=bi,pn=12,Rn=30,mn=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function In(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const En=e=>{if(!e||!e.state)return ln;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,cn},Sn=e=>{if(!e||!e.state)return ln;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,En(e)},Tn=(e,t)=>{let i;if(!e||!e.state)return ln;const r=e.state;return t<0?(i=0,t=-t):(i=1+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?ln:(null!==r.window&&r.wbits!==t&&(r.window=null),r.wrap=i,r.wbits=t,Sn(e))},fn=(e,t)=>{if(!e)return ln;const i=new In;e.state=i,i.window=null;const r=Tn(e,t);return r!==cn&&(e.state=null),r};let Cn,On,Ln=!0;const Nn=e=>{if(Ln){Cn=new Int32Array(512),On=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(nn(1,e.lens,0,288,Cn,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;nn(2,e.lens,0,32,On,0,e.work,{bits:5}),Ln=!1}e.lencode=Cn,e.lenbits=9,e.distcode=On,e.distbits=5},An=(e,t,i,r)=>{let n;const o=e.state;return null===o.window&&(o.wsize=1<<o.wbits,o.wnext=0,o.whave=0,o.window=new Uint8Array(o.wsize)),r>=o.wsize?(o.window.set(t.subarray(i-o.wsize,i),0),o.wnext=0,o.whave=o.wsize):(n=o.wsize-o.wnext,n>r&&(n=r),o.window.set(t.subarray(i-r,i-r+n),o.wnext),(r-=n)?(o.window.set(t.subarray(i-r,i),0),o.wnext=r,o.whave=o.wsize):(o.wnext+=n,o.wnext===o.wsize&&(o.wnext=0),o.whave<o.wsize&&(o.whave+=n))),0};var yn={inflateReset:Sn,inflateReset2:Tn,inflateResetKeep:En,inflateInit:e=>fn(e,15),inflateInit2:fn,inflate:(e,t)=>{let i,r,n,o,s,a,c,d,_,l,u,h,g,v,p,R,m,I,E,S,T,f,C=0;const O=new Uint8Array(4);let L,N;const A=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!e||!e.state||!e.output||!e.input&&0!==e.avail_in)return ln;i=e.state,i.mode===pn&&(i.mode=13),s=e.next_out,n=e.output,c=e.avail_out,o=e.next_in,r=e.input,a=e.avail_in,d=i.hold,_=i.bits,l=a,u=c,f=cn;e:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;_<16;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(2&i.wrap&&35615===d){i.check=0,O[0]=255&d,O[1]=d>>>8&255,i.check=ki(i.check,O,2,0),d=0,_=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&d)<<8)+(d>>8))%31){e.msg="incorrect header check",i.mode=Rn;break}if((15&d)!==vn){e.msg="unknown compression method",i.mode=Rn;break}if(d>>>=4,_-=4,T=8+(15&d),0===i.wbits)i.wbits=T;else if(T>i.wbits){e.msg="invalid window size",i.mode=Rn;break}i.dmax=1<<i.wbits,e.adler=i.check=1,i.mode=512&d?10:pn,d=0,_=0;break;case 2:for(;_<16;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(i.flags=d,(255&i.flags)!==vn){e.msg="unknown compression method",i.mode=Rn;break}if(57344&i.flags){e.msg="unknown header flags set",i.mode=Rn;break}i.head&&(i.head.text=d>>8&1),512&i.flags&&(O[0]=255&d,O[1]=d>>>8&255,i.check=ki(i.check,O,2,0)),d=0,_=0,i.mode=3;case 3:for(;_<32;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.head&&(i.head.time=d),512&i.flags&&(O[0]=255&d,O[1]=d>>>8&255,O[2]=d>>>16&255,O[3]=d>>>24&255,i.check=ki(i.check,O,4,0)),d=0,_=0,i.mode=4;case 4:for(;_<16;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.head&&(i.head.xflags=255&d,i.head.os=d>>8),512&i.flags&&(O[0]=255&d,O[1]=d>>>8&255,i.check=ki(i.check,O,2,0)),d=0,_=0,i.mode=5;case 5:if(1024&i.flags){for(;_<16;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.length=d,i.head&&(i.head.extra_len=d),512&i.flags&&(O[0]=255&d,O[1]=d>>>8&255,i.check=ki(i.check,O,2,0)),d=0,_=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(h=i.length,h>a&&(h=a),h&&(i.head&&(T=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(r.subarray(o,o+h),T)),512&i.flags&&(i.check=ki(i.check,r,h,o)),a-=h,o+=h,i.length-=h),i.length))break e;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===a)break e;h=0;do{T=r[o+h++],i.head&&T&&i.length<65536&&(i.head.name+=String.fromCharCode(T))}while(T&&h<a);if(512&i.flags&&(i.check=ki(i.check,r,h,o)),a-=h,o+=h,T)break e}else i.head&&(i.head.name=null);i.length=0,i.mode=8;case 8:if(4096&i.flags){if(0===a)break e;h=0;do{T=r[o+h++],i.head&&T&&i.length<65536&&(i.head.comment+=String.fromCharCode(T))}while(T&&h<a);if(512&i.flags&&(i.check=ki(i.check,r,h,o)),a-=h,o+=h,T)break e}else i.head&&(i.head.comment=null);i.mode=9;case 9:if(512&i.flags){for(;_<16;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(d!==(65535&i.check)){e.msg="header crc mismatch",i.mode=Rn;break}d=0,_=0}i.head&&(i.head.hcrc=i.flags>>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=pn;break;case 10:for(;_<32;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}e.adler=i.check=mn(d),d=0,_=0,i.mode=11;case 11:if(0===i.havedict)return e.next_out=s,e.avail_out=c,e.next_in=o,e.avail_in=a,i.hold=d,i.bits=_,_n;e.adler=i.check=1,i.mode=pn;case pn:if(t===sn||t===an)break e;case 13:if(i.last){d>>>=7&_,_-=7&_,i.mode=27;break}for(;_<3;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}switch(i.last=1&d,d>>>=1,_-=1,3&d){case 0:i.mode=14;break;case 1:if(Nn(i),i.mode=20,t===an){d>>>=2,_-=2;break e}break;case 2:i.mode=17;break;case 3:e.msg="invalid block type",i.mode=Rn}d>>>=2,_-=2;break;case 14:for(d>>>=7&_,_-=7&_;_<32;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if((65535&d)!=(d>>>16^65535)){e.msg="invalid stored block lengths",i.mode=Rn;break}if(i.length=65535&d,d=0,_=0,i.mode=15,t===an)break e;case 15:i.mode=16;case 16:if(h=i.length,h){if(h>a&&(h=a),h>c&&(h=c),0===h)break e;n.set(r.subarray(o,o+h),s),a-=h,o+=h,c-=h,s+=h,i.length-=h;break}i.mode=pn;break;case 17:for(;_<14;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(i.nlen=257+(31&d),d>>>=5,_-=5,i.ndist=1+(31&d),d>>>=5,_-=5,i.ncode=4+(15&d),d>>>=4,_-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=Rn;break}i.have=0,i.mode=18;case 18:for(;i.have<i.ncode;){for(;_<3;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.lens[A[i.have++]]=7&d,d>>>=3,_-=3}for(;i.have<19;)i.lens[A[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,L={bits:i.lenbits},f=nn(0,i.lens,0,19,i.lencode,0,i.work,L),i.lenbits=L.bits,f){e.msg="invalid code lengths set",i.mode=Rn;break}i.have=0,i.mode=19;case 19:for(;i.have<i.nlen+i.ndist;){for(;C=i.lencode[d&(1<<i.lenbits)-1],p=C>>>24,R=C>>>16&255,m=65535&C,!(p<=_);){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(m<16)d>>>=p,_-=p,i.lens[i.have++]=m;else{if(16===m){for(N=p+2;_<N;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(d>>>=p,_-=p,0===i.have){e.msg="invalid bit length repeat",i.mode=Rn;break}T=i.lens[i.have-1],h=3+(3&d),d>>>=2,_-=2}else if(17===m){for(N=p+3;_<N;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}d>>>=p,_-=p,T=0,h=3+(7&d),d>>>=3,_-=3}else{for(N=p+7;_<N;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}d>>>=p,_-=p,T=0,h=11+(127&d),d>>>=7,_-=7}if(i.have+h>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=Rn;break}for(;h--;)i.lens[i.have++]=T}}if(i.mode===Rn)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=Rn;break}if(i.lenbits=9,L={bits:i.lenbits},f=nn(1,i.lens,0,i.nlen,i.lencode,0,i.work,L),i.lenbits=L.bits,f){e.msg="invalid literal/lengths set",i.mode=Rn;break}if(i.distbits=6,i.distcode=i.distdyn,L={bits:i.distbits},f=nn(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,L),i.distbits=L.bits,f){e.msg="invalid distances set",i.mode=Rn;break}if(i.mode=20,t===an)break e;case 20:i.mode=21;case 21:if(a>=6&&c>=258){e.next_out=s,e.avail_out=c,e.next_in=o,e.avail_in=a,i.hold=d,i.bits=_,Qr(e,u),s=e.next_out,n=e.output,c=e.avail_out,o=e.next_in,r=e.input,a=e.avail_in,d=i.hold,_=i.bits,i.mode===pn&&(i.back=-1);break}for(i.back=0;C=i.lencode[d&(1<<i.lenbits)-1],p=C>>>24,R=C>>>16&255,m=65535&C,!(p<=_);){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(R&&0==(240&R)){for(I=p,E=R,S=m;C=i.lencode[S+((d&(1<<I+E)-1)>>I)],p=C>>>24,R=C>>>16&255,m=65535&C,!(I+p<=_);){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}d>>>=I,_-=I,i.back+=I}if(d>>>=p,_-=p,i.back+=p,i.length=m,0===R){i.mode=26;break}if(32&R){i.back=-1,i.mode=pn;break}if(64&R){e.msg="invalid literal/length code",i.mode=Rn;break}i.extra=15&R,i.mode=22;case 22:if(i.extra){for(N=i.extra;_<N;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.length+=d&(1<<i.extra)-1,d>>>=i.extra,_-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;C=i.distcode[d&(1<<i.distbits)-1],p=C>>>24,R=C>>>16&255,m=65535&C,!(p<=_);){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(0==(240&R)){for(I=p,E=R,S=m;C=i.distcode[S+((d&(1<<I+E)-1)>>I)],p=C>>>24,R=C>>>16&255,m=65535&C,!(I+p<=_);){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}d>>>=I,_-=I,i.back+=I}if(d>>>=p,_-=p,i.back+=p,64&R){e.msg="invalid distance code",i.mode=Rn;break}i.offset=m,i.extra=15&R,i.mode=24;case 24:if(i.extra){for(N=i.extra;_<N;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}i.offset+=d&(1<<i.extra)-1,d>>>=i.extra,_-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=Rn;break}i.mode=25;case 25:if(0===c)break e;if(h=u-c,i.offset>h){if(h=i.offset-h,h>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=Rn;break}h>i.wnext?(h-=i.wnext,g=i.wsize-h):g=i.wnext-h,h>i.length&&(h=i.length),v=i.window}else v=n,g=s-i.offset,h=i.length;h>c&&(h=c),c-=h,i.length-=h;do{n[s++]=v[g++]}while(--h);0===i.length&&(i.mode=21);break;case 26:if(0===c)break e;n[s++]=i.length,c--,i.mode=21;break;case 27:if(i.wrap){for(;_<32;){if(0===a)break e;a--,d|=r[o++]<<_,_+=8}if(u-=c,e.total_out+=u,i.total+=u,u&&(e.adler=i.check=i.flags?ki(i.check,n,u,s-u):Ai(i.check,n,u,s-u)),u=c,(i.flags?d:mn(d))!==i.check){e.msg="incorrect data check",i.mode=Rn;break}d=0,_=0}i.mode=28;case 28:if(i.wrap&&i.flags){for(;_<32;){if(0===a)break e;a--,d+=r[o++]<<_,_+=8}if(d!==(4294967295&i.total)){e.msg="incorrect length check",i.mode=Rn;break}d=0,_=0}i.mode=29;case 29:f=dn;break e;case Rn:f=un;break e;case 31:return hn;default:return ln}return e.next_out=s,e.avail_out=c,e.next_in=o,e.avail_in=a,i.hold=d,i.bits=_,(i.wsize||u!==e.avail_out&&i.mode<Rn&&(i.mode<27||t!==on))&&An(e,e.output,e.next_out,u-e.avail_out),l-=e.avail_in,u-=e.avail_out,e.total_in+=l,e.total_out+=u,i.total+=u,i.wrap&&u&&(e.adler=i.check=i.flags?ki(i.check,n,u,e.next_out-u):Ai(i.check,n,u,e.next_out-u)),e.data_type=i.bits+(i.last?64:0)+(i.mode===pn?128:0)+(20===i.mode||15===i.mode?256:0),(0===l&&0===u||t===on)&&f===cn&&(f=gn),f},inflateEnd:e=>{if(!e||!e.state)return ln;let t=e.state;return t.window&&(t.window=null),e.state=null,cn},inflateGetHeader:(e,t)=>{if(!e||!e.state)return ln;const i=e.state;return 0==(2&i.wrap)?ln:(i.head=t,t.done=!1,cn)},inflateSetDictionary:(e,t)=>{const i=t.length;let r,n,o;return e&&e.state?(r=e.state,0!==r.wrap&&11!==r.mode?ln:11===r.mode&&(n=1,n=Ai(n,t,i,0),n!==r.check)?un:(o=An(e,t,i,i),o?(r.mode=31,hn):(r.havedict=1,cn))):ln},inflateInfo:"pako inflate (from Nodeca project)"};var kn=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Dn=Object.prototype.toString,{Z_NO_FLUSH:bn,Z_FINISH:Un,Z_OK:Pn,Z_STREAM_END:Mn,Z_NEED_DICT:xn,Z_STREAM_ERROR:wn,Z_DATA_ERROR:Bn,Z_MEM_ERROR:Vn}=bi;function Fn(e){this.options=Ur.assign({chunkSize:65536,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new wr,this.strm.avail_out=0;let i=yn.inflateInit2(this.strm,t.windowBits);if(i!==Pn)throw new Error(Di[i]);if(this.header=new kn,yn.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=xr.string2buf(t.dictionary):"[object ArrayBuffer]"===Dn.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=yn.inflateSetDictionary(this.strm,t.dictionary),i!==Pn)))throw new Error(Di[i])}Fn.prototype.push=function(e,t){const i=this.strm,r=this.options.chunkSize,n=this.options.dictionary;let o,s,a;if(this.ended)return!1;for(s=t===~~t?t:!0===t?Un:bn,"[object ArrayBuffer]"===Dn.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(r),i.next_out=0,i.avail_out=r),o=yn.inflate(i,s),o===xn&&n&&(o=yn.inflateSetDictionary(i,n),o===Pn?o=yn.inflate(i,s):o===Bn&&(o=xn));i.avail_in>0&&o===Mn&&i.state.wrap>0&&0!==e[i.next_in];)yn.inflateReset(i),o=yn.inflate(i,s);switch(o){case wn:case Bn:case xn:case Vn:return this.onEnd(o),this.ended=!0,!1}if(a=i.avail_out,i.next_out&&(0===i.avail_out||o===Mn))if("string"===this.options.to){let e=xr.utf8border(i.output,i.next_out),t=i.next_out-e,n=xr.buf2string(i.output,e);i.next_out=t,i.avail_out=r-t,t&&i.output.set(i.output.subarray(e,e+t),0),this.onData(n)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(o!==Pn||0!==a){if(o===Mn)return o=yn.inflateEnd(this.strm),this.onEnd(o),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},Fn.prototype.onData=function(e){this.chunks.push(e)},Fn.prototype.onEnd=function(e){e===Pn&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ur.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};const{Deflate:Jn,deflate:Gn,deflateRaw:Hn,gzip:Kn}=zr;var jn=Kn;const $n=-1,Wn=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})),Yn=(e,t,i)=>S(void 0,void 0,void 0,(function*(){const r=[];return new Promise(((n,s)=>{e.map((e=>S(void 0,void 0,void 0,(function*(){const s=`${e.detectorAddr.replace(/^(https?:\/\/)?/,"https://")}/rtc/detector/ping?t=${a=1e3,c=9999,a+Math.floor(Math.random()*(c-a))}`;var a,c;const d={jwt:i};200===(yield t.httpReq({url:s,body:JSON.stringify(d),timeout:5e3,method:o.POST})).status&&r.push(e.clusterId),n(r)}))))}))})),qn=e=>{if(!e)return"";return e.jwt||""},zn=(e,t)=>S(void 0,void 0,void 0,(function*(){const i=(e=>{var t;if(!e)return"";let i;try{i=JSON.parse(e.voipCallInfo||'{ "strategy": 0 }')}catch(t){const i=We.getLogger();return null==i||i.warn(f.L_MEDIA_SERVICE_PARSE_NAVI_CALLVOIP_INFO_O,`parse \`voipCallInfo\` of navi failed: ${e.voipCallInfo}`),""}if(0===i.strategy)return"";const r=null===(t=i.callEngine)||void 0===t?void 0:t.filter((e=>4===e.engineType));if(!r||0===r.length)return"";const n=r[0];return n.detectorManager?n.detectorManager:""})(t),r=qn(t);let n=null,a=120,c=0;const d={jwt:r};if(i&&r){const t=yield e.httpReq({url:`${i}/rtc/detector/servers`,body:JSON.stringify(d),headers:{"Content-Type":"application/json;charset=UTF-8","Cache-Control":"no-cache",ClientType:`web|${Ut.browser}|${Ut.version}`,ClientVersion:"5.6.9","Client-Session-Id":Wn(),"Request-Id":Date.now().toString()},method:o.POST}),_=t.data&&JSON.parse(t.data).detectorAddrs;a=t.data&&JSON.parse(t.data).clientDetectMinute,c=t.data&&JSON.parse(t.data).resultCode,_&&s(_)&&(n=yield Yn(_,e,r))}return{fastMediaUrl:n,clientDetectMinute:a,status:c}})),Qn=()=>({"Content-Type":"application/json;charset=UTF-8","Cache-Control":"no-cache",ClientType:`web|${Ut.browser}|${Ut.version}`,ClientVersion:"5.6.9","Client-Session-Id":Wn(),"Request-Id":Date.now().toString()});class Zn{constructor(e,t,i,r=5e3){this._runtime=e,this._context=t,this._msUrl=i,this._timeout=r,this._msInNavi=[],this._failedMs=[],this._rtcFinger=void 0,this._clusterId="",this._configUrl="",this._msList=[],this._qualityMsList=[],Zn.isDetector||t.getConnectionStatus()!==a.CONNECTED||this.detectorMediaSever()}detectorMediaSever(){const e=this._context.getNaviInfo();if(Zn.jwtToken=(null==e?void 0:e.jwt)||"",this._msUrl)return;const t=Date.now(),i=Zn.detectValidMinute+Zn.detectorTime>t;Zn.isDetector=i,!i&&e&&c(e)&&(this._msList=[],this._getDetectorUrls(e))}_getDetectorUrls(e){return S(this,void 0,void 0,(function*(){if(Zn.isDetector)return;Zn.isDetector=!0;const{fastMediaUrl:t,clientDetectMinute:i,status:r}=yield zn(this._runtime,e);if(r===T.JWT_TIME_OUT){const e=this._context.getPluginContext();yield e.refetchNaviInfo(),this.detectorMediaSever()}Zn.msInDetector=t||[],Zn.detectorTime=Date.now(),Zn.detectValidMinute=60*i*1e3}))}getNaviMS(){return this._msUrl?[this._msUrl]:(d(this._msList)&&!this._clusterId||(this._msList=this.setMediaServiceList()),this._msList)}setMediaServiceList(){var e,t;let i=[],r=[];return this._clusterId&&(this._clusterId=this._clusterId.replace(/^(https?:\/\/)?/,"https://"),this._msList.push(this._clusterId)),d(Zn.msInDetector)&&(Zn.msInDetector=Zn.msInDetector.map((e=>e.replace(/^(https?:\/\/)?/,"https://"))),this._msList.push(Zn.msInDetector[0]),i=Zn.msInDetector.concat().splice(1,Zn.msInDetector.length-1)),0===this._msInNavi.length&&(0===this._failedMs.length?this._msInNavi.push(...(e=>{var t;if(!e)return[];let i;try{i=JSON.parse(e.voipCallInfo||'{ "strategy": 0 }')}catch(t){const i=We.getLogger();return null==i||i.warn(`parse \`voipCallInfo\` of navi failed: ${e.voipCallInfo}`),[]}if(0===i.strategy)return[];const r=null===(t=i.callEngine)||void 0===t?void 0:t.filter((e=>4===e.engineType));if(!r||0===r.length)return[];const n=r[0],o=[];return n.mediaServer&&o.push(n.mediaServer.replace(/^(https?:\/\/)?/,"https://")),n.backupMediaServer&&n.backupMediaServer.forEach((e=>{o.push(e.replace(/^(https?:\/\/)?/,"https://"))})),o})(this._context.getNaviInfo())):(this._msInNavi.push(...this._failedMs),this._failedMs.length=0)),r=this._msInNavi.concat().splice(1,this._msInNavi.length-1),this._msList.push(this._msInNavi[0]),this._msList=[...this._msList,...i,...r],this._msList=[...new Set(this._msList)],null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_MEDIA_SERVICE_MSLIST_CHANGE_O,`MediaServiceList msList -> ${JSON.stringify(this._msList)}`),this._msList}_request(e,t,i,r,n){var s,a,c,d,_,l,u,h,g;return S(this,void 0,void 0,(function*(){this._qualityMsList=[];if((null===(s=this._context.getNaviInfo())||void 0===s?void 0:s.openGzip)||!1){const e=JSON.stringify(i),r=e.length,n=new Uint8Array(r);for(let t=0;t<r;t++)n[t]=e.charCodeAt(t);const o={"Content-Encoding":"gzip","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"};t=Object.assign(Object.assign({},t),o),i=jn(n,v)}var v;const p=this.getNaviMS();if(0===p.length)return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:C.FAILED,code:T.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"have no valid service address"}),r),{code:T.NOT_OPEN_VIDEO_AUDIO_SERVER};this._rtcFinger&&(i.rtcFinger=this._rtcFinger);for(let s=0;s<p.length;s+=1){const a=Date.now(),c=`${p[s]}${e}`,v=Qn(),R=Object.assign(Object.assign({},v),t),m=/x-www-form-urlencoded/.test(R["Content-Type"])?i:JSON.stringify(i),I=v["Request-Id"];null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_MEDIA_SERVICE_REQUEST_T,JSON.stringify({url:c,"Request-Id":I}),r);const{status:E,data:S}=yield this._runtime.httpReq({url:c,body:m,headers:R,method:o.POST,timeout:this._timeout});if(n&&this._qualityMsList.push({rsdur:Date.now()-a,rsid:I,rscod:200===E?T.SUCCESS:T.REQUEST_FAILED,msa:c}),200===E){const e=JSON.parse(S);return e.rtcFinger&&(this._rtcFinger=e.rtcFinger),e.clusterId&&(this._clusterId=e.clusterId),null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(f.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:C.SUCCESSED,url:c}),r),{code:T.SUCCESS,data:e,qualityMsList:this._qualityMsList}}this._failedMs.push(...this._msInNavi.splice(s,1)),null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.error(f.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:C.FAILED,msg:`request error -> Request-Id: ${I}, status: ${E}, url: ${c}`,timeout:this._timeout}),r)}return{code:T.REQUEST_FAILED,qualityMsList:this._qualityMsList}}))}exchange(e,t,i,r){var n;return S(this,void 0,void 0,(function*(){const o=yield this._request("/exchange",e,t,i,r);if(o.code===T.SUCCESS&&(null===(n=o.data)||void 0===n?void 0:n.resultCode)===T.SUCCESS){const{urls:e}=o.data;e&&(this._configUrl=e.configUrl)}return o}))}exit(e){var t,i;return S(this,void 0,void 0,(function*(){const r=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId(),{code:n}=yield this._request("/exit",e,{},r);return n}))}broadcastSubscribe(e,t){var i,r;const n=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();return this._request("/broadcast/subscribe",e,t,n,!0)}broadcastExit(e){var t,i;return S(this,void 0,void 0,(function*(){const r=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId(),{code:n}=yield this._request("/broadcast/exit",e,{},r,!0);return{code:n}}))}setMcuConfig(e,t){var i,r,n,s,a,c,d,_,l,u,h,g;return S(this,void 0,void 0,(function*(){const v=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();if(null===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.info(f.L_MEDIA_SERVICE_SET_MCU_CONFIG_T,JSON.stringify({body:t}),v),!this._configUrl)return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:C.FAILED,code:T.MCU_SERVER_NOT_FOUND,msg:"MCU server not found"}),v),{code:T.MCU_SERVER_NOT_FOUND};const p=`${this._configUrl.replace(/^(https?:\/\/)?/,"https://")}/server/mcu/config`,R=Qn(),m=Object.assign(Object.assign({},R),e),I=JSON.stringify(t),E=R["Request-Id"],{status:S,data:O}=yield this._runtime.httpReq({url:p,headers:m,body:I,method:o.POST});if(200===S){const e=JSON.parse(O),t=e.resultCode;return t===T.SUCCESS?null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:C.SUCCESSED,"Request-Id":E}),v):null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.warn(f.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({code:t,"Request-Id":E}),v),{code:t,res:e}}return null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.error(f.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:C.FAILED,code:T.REQUEST_FAILED,msg:`request error -> Request-Id: ${E}, status: ${S}, url: ${p}`}),v),{code:T.REQUEST_FAILED}}))}getCDNResourceInfo(e,t,i){var r,n,s,a,c,d;return S(this,void 0,void 0,(function*(){const _=Qn(),l=Object.assign(Object.assign({},_),e),u=_["Request-Id"];null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_T,`Request-Id: ${u}, url: ${t}`,i);const{status:h,data:g}=yield this._runtime.httpReq({url:t,headers:l,method:o.GET});if(200===h){const e=JSON.parse(g);return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_R,JSON.stringify({status:C.SUCCESSED,cdnPlayerUrl:null==e?void 0:e.data.pull_url}),i),{code:e.resultCode,res:e}}return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_R,JSON.stringify({status:C.FAILED,code:T.REQUEST_FAILED}),i),{code:T.REQUEST_FAILED}}))}}var Xn;Zn.isDetector=!1,Zn.msInDetector=[],Zn.detectorTime=0,Zn.detectValidMinute=72e5,Zn.jwtToken="",function(e){e[e.NORMAL=1]="NORMAL",e[e.TINY=2]="TINY"}(Xn||(Xn={}));const eo=(e,t)=>Math.round(8*t/e),to=(e,t=2)=>{const i=10**t;return Math.round(e*i)/i},io=(e,t=2)=>{e>1&&(e=1);const i=10**t;return Math.round(e*i)},ro=(e,t,i,r)=>{if(0===t)return 0;if(!i||!r)return to(e/t,3);const n=t-r;if(0===n)return 0;const o=e-i;return o<0||n<0?0:to(o/n,3)},no=e=>{const{jitter:t,rtt:i,packetsLostRate:r}=e;return!xt(t)||!xt(i)||0!==r};class oo{constructor(){}static getInstance(){return this._instance||(this._instance=new Map([["sourceIdForPublishMap",new Map],["sourceIdForSubscribeMap",new Map]])),this._instance}static destroy(){this._instance=new Map([["sourceIdForPublishMap",new Map],["sourceIdForSubscribeMap",new Map]])}}var so,ao,co,_o,lo,uo,ho,go,vo,po,Ro,mo,Io,Eo,So,To,fo,Co,Oo;oo._instance=new Map([["sourceIdForPublishMap",new Map],["sourceIdForSubscribeMap",new Map]]),function(e){e.TRACK="track",e.STREAM="stream",e.MEDIASOURCE="media-source",e.INBOUNDRTP="inbound-rtp",e.OUTBOUNDRTP="outbound-rtp",e.REMOTEINBOUNDRTP="remote-inbound-rtp",e.PEERCONNECTION="peer-connection",e.TRANSPORT="transport",e.CERTIFICATE="certificate",e.CANDIDATEPAIR="candidate-pair",e.REMOTECANDIDATE="remote-candidate",e.LOCALCANDIDATE="local-candidate"}(so||(so={}));class Lo{constructor(e,t,i,r){this._rtcPeerConn=e,this._sdpSemantics=t,this._currentUserId=i,this._store=r,this._logger=null,this._latestPacketsSent={},this._latestBytesSent={},this._latestBytesRecv={},this._latestPacketsRecv={},this._logger=We.getLogger()}updateBytesSent(e,t,i){let r,n;if(this._latestBytesSent[e]&&t<this._latestBytesSent[e].bytesSent&&this.clearLatestpacketsSent([e]),this._latestBytesSent[e]){const{bytesSent:o,timestamp:s}=this._latestBytesSent[e];r=t-o,n=i-s,this._latestBytesSent[e]={bytesSent:t,timestamp:i}}else r=t,n=1e3,this._latestBytesSent[e]={bytesSent:t,timestamp:i};return eo(n,r)}updateBytesRecv(e,t,i){let r,n;if(this._latestBytesRecv[e]&&t<this._latestBytesRecv[e].bytesRecv&&this.clearLatestPacketsRecv([e]),this._latestBytesRecv[e]){const{bytesRecv:o,timestamp:s}=this._latestBytesRecv[e];r=t-o,n=i-s,this._latestBytesRecv[e]={bytesRecv:t,timestamp:i}}else r=t,n=1e3,this._latestBytesRecv[e]={bytesRecv:t,timestamp:i};return eo(n,r)}updateSenderPacketsLost(e,t,i){let r;if(Object.prototype.hasOwnProperty.call(this._latestPacketsSent[e],"packetsSent")){const{packetsLost:n,packetsSent:o}=this._latestPacketsSent[e];r=ro(t,i,n,o),this._latestPacketsSent[e].packetsLost=t,this._latestPacketsSent[e].packetsSent=n===t?o:i}else r=ro(t,i),this._latestPacketsSent[e].packetsLost=t,this._latestPacketsSent[e].packetsSent=i;return r}updateReceiverPacketsLost(e,t,i){let r;if(this._latestPacketsRecv[e]){const{packetsLost:n,packetsRecv:o}=this._latestPacketsRecv[e];r=ro(t,i+t,n,o+n)}else r=ro(t,i);return this._latestPacketsRecv[e]={packetsLost:t,packetsRecv:i},r}clearLatestpacketsSent(e){e.forEach((e=>{if(parseInt(e.split("_").pop())===Je.VIDEO_ONLY){const t=`${e}_tiny`;delete this._latestPacketsSent[t],delete this._latestBytesSent[t]}delete this._latestPacketsSent[e],delete this._latestBytesSent[e]}))}clearLatestPacketsRecv(e){e.forEach((e=>{delete this._latestPacketsRecv[e],delete this._latestBytesRecv[e]}))}parseRTCStatsReport(e){const t={};for(const[i,r]of e.entries())/codec/gi.test(r)&&i.includes("RTCCodec_")||(t[i]=r);return t}formatRCRTCStateReport(e){var t;const i={senders:[],receivers:[]};return null===(t=this._logger)||void 0===t||t.info(f.L_ABSTRACT_STAT_PARSER_FORMAT_RTC_STATE_REPORT_O,JSON.stringify({status:C.SUCCESSED,stats:e,reports:i})),i}getAudioLevelList(e){return[]}isValidSender(e){var t;const i=null===(t=this._rtcPeerConn.currentLocalDescription)||void 0===t?void 0:t.sdp,{ssrc:r}=e;return!(null==i?void 0:i.split("\r\nm=").some((e=>e.includes(r)&&e.includes("a=inactive"))))}isValidReceiver(e){var t;const i=null===(t=this._rtcPeerConn.currentRemoteDescription)||void 0===t?void 0:t.sdp,{ssrc:r}=e;return!(null==i?void 0:i.split("\r\nm=").some((e=>e.includes(r)&&e.includes("a=inactive"))))}formatStateData(e){return Object.values(e).reduce(((e,t)=>t.type===so.REMOTEINBOUNDRTP?(e.remoteInbound.push(t),e):t.type===so.INBOUNDRTP?(e.inbound.push(t),e):t.type===so.OUTBOUNDRTP?(e.outbound.push(t),e):t.type===so.TRANSPORT?(e.transport.push(t),e):t.type===so.PEERCONNECTION?(e.connection.push(t),e):e),{outbound:[],remoteInbound:[],inbound:[],transport:[],connection:[]})}}Lo.formatSourceIdMapFromSdp=(e,t)=>{const i=oo.getInstance(),r=null==e?void 0:e.match(/a=ssrc:(.*) msid:(.*?) /gi);if(r){if("publish"===t){const e=i.get("sourceIdForPublishMap");null==e||e.clear(),r.forEach((t=>{const[i,r]=t.split(" ").map((e=>e.split(":")[1]));null==e||e.set(i,r)}))}if("subscribe"===t){const e=i.get("sourceIdForSubscribeMap");null==e||e.clear(),r.forEach((t=>{const[i,r]=t.split(" ").map((e=>e.split(":")[1]));null==e||e.set(i,r)}))}}};class No extends Lo{formatRCRTCStateReport(e){const{outbound:t,remoteInbound:i,inbound:r,transport:n,connection:o}=this.formatStateData(e),s={senders:[],receivers:[]},a=Math.floor(o[0].timestamp);s.timestamp=a;let c=0,d=0;({totalPacketsLost:c,bitrateSend:d,senders:s.senders}=this.pickOutbound(t,e,c,a,d)),i.length>0&&s.senders.length>0&&this.pickRemoteInbound(i,s.senders,e);let _=0;if(({totalPacketsLost:c,bitrateRecv:_,receivers:s.receivers}=this.pickInbound(r,e,c,a,_)),n.length>0){const t=n[0];this.pickRtcTransport(t,e,s,_,d,c)}return s}pickRtcTransport(e,t,i,r,n,o){const{selectedCandidatePairId:s}=e;if(s){const e=t[s],{availableOutgoingBitrate:a,availableIncomingBitrate:c,currentRoundTripTime:d,localCandidateId:_,remoteCandidateId:l}=e,u=t[_],{ip:h,port:g,networkType:v}=u,p=t[l],{ip:R,port:m,protocol:I}=p;i.iceCandidatePair={IP:h,port:g,networkType:v,remoteIP:R,remotePort:m,protocol:I,bitrateRecv:r,bitrateSend:n,rtt:1e3*d,availableOutgoingBitrate:a,availableIncomingBitrate:c,totalPacketsLost:o},i.receivers.forEach((e=>{e.rtt=d}))}}pickRemoteInbound(e,t,i){e.forEach((e=>{var r;const{localId:n,jitter:o,roundTripTime:s,packetsLost:a}=e,c=t.filter((e=>e.id===n))[0];if(c&&!no(c)){const e=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i[c.id].ssrc);c.jitter=Math.round(1e3*o),c.rtt=s;const t=this._latestPacketsSent[e].crtPacketsSent;c.packetsLostRate=this.updateSenderPacketsLost(e,a,t)}}))}pickOutbound(e,t,i,r,n){const o=[];return e.forEach((e=>{var s;if("unified-plan"===this._sdpSemantics&&!this.isValidSender(e))return;const{id:a,kind:c,transportId:d,mediaSourceId:_,remoteId:l,packetsSent:u,bytesSent:h,trackId:g,encoderImplementation:v,pliCount:p,nackCount:R,firCount:m}=e;if(!g)return;let{framesPerSecond:I,frameWidth:E,frameHeight:S}=e;"video"!==c||E||S||I||(E=t[g].frameWidth,S=t[g].frameHeight,I=_?t[_].framesPerSecond:null);const T=t[l];let f=null,C=null,O=0;T&&(f=T.jitter,C=T.roundTripTime,O=T.packetsLost),i+=O;const L=null===(s=this._store)||void 0===s?void 0:s.getTrackIdBySSRC(e.ssrc);if(!L)return;const N=_?t[_].audioLevel:t[g].audioLevel;let A=null;!this._latestPacketsSent[L]&&(this._latestPacketsSent[L]={}),T?A=this.updateSenderPacketsLost(L,O,u):this._latestPacketsSent[L].crtPacketsSent=u;let y=this.updateBytesSent(L,h,r);y<0&&(y=0),n+=y,o.push({id:a,trackId:L,kind:c,packetsLostRate:A,remoteResource:!1,audioLevel:N||0===N?io(N):null,frameWidth:E,frameHeight:S,frameRate:I,bitrate:y,jitter:f?Math.round(1e3*f):f,rtt:C,encoderImplementation:v,pliCount:p,nackCount:R,googFirsSent:$n,samplingRate:$n,googRenderDelayMs:$n,trackState:$n})})),{totalPacketsLost:i,bitrateSend:n,senders:o}}pickInbound(e,t,i,r,n){let o=[];return e.forEach((e=>{var s;if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(e))return;const{trackId:a,packetsLost:c,packetsReceived:d,jitter:_,bytesReceived:l,framesPerSecond:u,kind:h,codecImplementationName:g,nackCount:v,pliCount:p}=e;if(!a)return;let{frameWidth:R,frameHeight:m,audioLevel:I}=e;"video"===h?R||m||(R=t[a].frameWidth,m=t[a].frameHeight):I||(I=t[a].audioLevel),i+=c;const E=null===(s=this._store)||void 0===s?void 0:s.getTrackIdBySSRC(e.ssrc),S=this.updateReceiverPacketsLost(E,c,d);let T=this.updateBytesRecv(E,l,r);T<0&&(T=0),n+=T,o.push({trackId:E,kind:h,packetsLostRate:S,remoteResource:!0,audioLevel:I||0===I?io(I):null,frameWidth:R,frameHeight:m,frameRate:u,bitrate:T,jitter:_?Math.round(1e3*_):0,codecImplementationName:g,nackCount:v,pliCount:p,rtt:null,samplingRate:$n,googFirsReceived:$n,googRenderDelayMs:$n,trackState:$n})})),{totalPacketsLost:i,bitrateRecv:n,receivers:o}}getAudioLevelList(e){const t=[],{outbound:i,inbound:r}=this.formatStateData(e);i.filter((e=>"audio"===(null==e?void 0:e.kind))).forEach((i=>{var r,n;if("unified-plan"===this._sdpSemantics&&!this.isValidSender(i))return;const{mediaSourceId:o,trackId:s,kind:a}=i,c=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i.ssrc),d=o&&e[o]?e[o].audioLevel:(null===(n=e[s])||void 0===n?void 0:n.audioLevel)||null;c&&t.push({trackId:c,audioLevel:d||0===d?io(d):null})}));return r.filter((e=>"audio"===(null==e?void 0:e.kind))).forEach((i=>{var r;if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(i))return;const{trackId:n}=i,o=i.audioLevel||e[n].audioLevel,s=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i.ssrc);s&&t.push({trackId:s,audioLevel:o||0===o?io(o):null})})),t}}class Ao extends Lo{formatRCRTCStateReport(e){var t,i,r;const n=+new Date,o={senders:[],receivers:[],timestamp:n};let s=0,a=0,c=0;for(const d in e){const _=e[d],{type:l}=_;if("outbound-rtp"===l){if("unified-plan"===this._sdpSemantics&&!this.isValidSender(_))continue;const{id:i,kind:r,bytesSent:c,packetsSent:d,bitrateMean:l,framerateMean:u,nackCount:h,pliCount:g,remoteId:v}=_,{jitter:p,roundTripTime:R,packetsLost:m}=v?e[v]:{jitter:null,roundTripTime:null,packetsLost:0},I=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(_.ssrc);s+=m;let E=null;!this._latestPacketsSent[I]&&(this._latestPacketsSent[I]={}),v?E=this.updateSenderPacketsLost(I,m,d):this._latestPacketsSent[I].crtPacketsSent=d;let S=0;"video"===r?l&&(S=Math.floor(l/1e3)):S=this.updateBytesSent(I,c,n),S<0&&(S=0),a+=S,o.senders.push({trackId:I,kind:r,packetsLostRate:E,remoteResource:!1,audioLevel:null,frameWidth:null,frameHeight:null,frameRate:Math.floor(u),bitrate:S,jitter:p?Math.round(1e3*p):null,rtt:R,encoderImplementation:null,pliCount:g,nackCount:h,googFirsSent:$n,samplingRate:$n,googRenderDelayMs:$n,trackState:$n})}if("remote-inbound-rtp"===l){const{localId:t}=_,r=null===(i=this._store)||void 0===i?void 0:i.getTrackIdBySSRC(e[t].ssrc),n=o.senders.filter((e=>e.trackId===r))[0];n&&no(n)&&(n.jitter=Math.round(1e3*_.jitter),n.rtt=_.rtt,n.packetsLostRate=this.updateSenderPacketsLost(r,_.packetsLost,this._latestPacketsSent[r].crtPacketsSent))}if("inbound-rtp"===l){if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(_))continue;const{id:e,packetsLost:t,bytesReceived:i,packetsReceived:a,jitter:d,framerateMean:l,kind:u,bitrateMean:h,nackCount:g,pliCount:v}=_,p=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(_.ssrc);s+=t;const R=this.updateReceiverPacketsLost(p,t,a);let m=0;"video"===u?h&&(m=Math.floor(h/1e3)):m=this.updateBytesRecv(p,i,n),m<0&&(m=0),c+=m,o.receivers.push({trackId:p,kind:u,packetsLostRate:R,remoteResource:!0,audioLevel:null,frameWidth:null,frameHeight:null,frameRate:Math.floor(l),bitrate:m,jitter:d?Math.round(1e3*d):null,codecImplementationName:null,nackCount:g,pliCount:v,rtt:null,samplingRate:$n,googFirsReceived:$n,googRenderDelayMs:$n,trackState:$n})}if("candidate-pair"===l&&"succeeded"===_.state){const t=e[_.localCandidateId],{address:i,port:r}=t,n=e[_.remoteCandidateId],{address:d,port:l,protocol:u}=n;o.iceCandidatePair={IP:i,port:r,networkType:null,remoteIP:d,remotePort:l,protocol:u,bitrateRecv:c,bitrateSend:a,rtt:null,availableOutgoingBitrate:null,availableIncomingBitrate:null,totalPacketsLost:s}}}return o.iceCandidatePair&&(o.iceCandidatePair.bitrateSend=a),o.iceCandidatePair&&(o.iceCandidatePair.bitrateRecv=c),o}getAudioLevelList(e){var t,i;const r=[];for(const n in e){const o=e[n],{type:s}=o;if("outbound-rtp"===s){if("unified-plan"===this._sdpSemantics&&!this.isValidSender(o))continue;const{kind:e}=o;if("video"===e)continue;const i=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(o.ssrc);r.push({trackId:i,audioLevel:null})}if("inbound-rtp"===s){if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(o))continue;const{kind:e}=o;if("video"===e)continue;const t=null===(i=this._store)||void 0===i?void 0:i.getTrackIdBySSRC(o.ssrc);r.push({trackId:t,audioLevel:null})}}return r}}class yo extends Lo{formatRCRTCStateReport(e){const t={senders:[],receivers:[]},i=Math.floor(e.RTCPeerConnection.timestamp);t.timestamp=i;const r=Object.keys(e);let n=0,o=0;r.filter((e=>/^RTCOutboundRTP(Video|Audio)Stream_/.test(e))).forEach((r=>{var n;const s=e[r];if("unified-plan"===this._sdpSemantics&&!this.isValidSender(s))return;const a=null===(n=this._store)||void 0===n?void 0:n.getTrackIdBySSRC(s.ssrc),{mediaType:c,transportId:d,remoteId:_,packetsSent:l,bytesSent:u,trackId:h,encoderImplementation:g,pliCount:v,nackCount:p,firCount:R}=s;if(!h)return;const{audioLevel:m,frameHeight:I,frameWidth:E}=e[h];let S=this.updateBytesSent(a,u,i);S<0&&(S=0),o+=S,t.senders.push({trackId:a,kind:c,packetsLostRate:null,remoteResource:!1,audioLevel:m||0===m?io(m):null,frameWidth:E,frameHeight:I,frameRate:null,bitrate:S,jitter:null,rtt:null,encoderImplementation:g,pliCount:v,nackCount:p,googFirsSent:$n,samplingRate:$n,googRenderDelayMs:$n,trackState:$n})}));let s=0;r.filter((e=>/^RTCInboundRTP(Video|Audio)Stream_/.test(e))).forEach((r=>{var o;const a=e[r];if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(a))return;const{trackId:c,packetsLost:d,packetsReceived:_,jitter:l,bytesReceived:u,mediaType:h,nackCount:g,pliCount:v}=a,p=null===(o=this._store)||void 0===o?void 0:o.getTrackIdBySSRC(a.ssrc);if(!c)return;const{frameHeight:R,frameWidth:m,audioLevel:I}=e[c];n+=d;const E=this.updateReceiverPacketsLost(p,d,_);let S=this.updateBytesRecv(p,u,i);S<0&&(S=0),s+=S,t.receivers.push({trackId:p,kind:h,packetsLostRate:E,remoteResource:!0,audioLevel:I||0===I?io(I):null,frameWidth:m,frameHeight:R,frameRate:null,bitrate:S,jitter:l,codecImplementationName:null,nackCount:g,pliCount:v,rtt:null,samplingRate:$n,googFirsReceived:$n,googRenderDelayMs:$n,trackState:$n})}));const a=r.filter((e=>/^RTCTransport_/.test(e)))[0];if(a){const i=e[a],{selectedCandidatePairId:r}=i;if(r){const i=e[r],{availableOutgoingBitrate:a,availableIncomingBitrate:c,currentRoundTripTime:d,localCandidateId:_,remoteCandidateId:l}=i,u=e[_],{address:h,port:g}=u,v=e[l],{address:p,port:R,protocol:m}=v;t.iceCandidatePair={IP:h||null,port:g,networkType:null,remoteIP:p,remotePort:R,protocol:m,bitrateRecv:s,bitrateSend:o,rtt:1e3*d,availableOutgoingBitrate:a,availableIncomingBitrate:c,totalPacketsLost:n},t.receivers.forEach((e=>{e.rtt=d}))}}return t}getAudioLevelList(e){const t=[],i=Object.keys(e);i.filter((e=>/^RTCOutboundRTP(Video|Audio)Stream_/.test(e))).forEach((i=>{var r;const n=e[i];if("unified-plan"===this._sdpSemantics&&!this.isValidSender(n))return;const{trackId:o,mediaType:s}=n;if("video"===s)return;const a=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(n.ssrc),c=e[o];t.push({trackId:a,audioLevel:c||0===c?io(c):null})}));return i.filter((e=>/^RTCInboundRTP(Video|Audio)Stream_/.test(e))).forEach((i=>{var r;const n=e[i];if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(n))return;const{trackId:o,mediaType:s}=n;if(!o||"video"===s)return;const{audioLevel:a}=e[o],c=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(n.ssrc);t.push({trackId:c,audioLevel:a||0===a?io(a):null})})),t}}class ko{get videoSdps(){return this.videoStreams.slice()}get audioSdps(){return this.audioStreams.slice()}constructor(e,t){this.SDP=e,this.type=t,this.SDPHeader="",this.videoStreams=[],this.audioStreams=[],this._logger=null;const i=this.getStreamIndex();this.spliteStreams(i),this._logger=We.getLogger()}static trimBlankLine(e){return e.replace(/\n\r\s*\r\n/g,"\r\n").replace(/\s+\r\n/g,"\r\n")}getStreamIndex(){const e=new RegExp("m=(?:video|audio)","img"),t=new Set([0]);let i=e.exec(this.SDP);for(;null!==i;)t.add(null==i?void 0:i.index),i=e.exec(this.SDP);return t.add(this.SDP.length),[...t]}spliteStreams(e){this.SDPHeader=this.SDP.substring(e[0],e[1]).replace(/\r\ns=-/g,`\r\ns=${(new Date).valueOf()}`);for(let t=1;t<e.length;t++){const i=this.SDP.substring(e[t],e[t+1]);/^\bm=video\b/.test(i)?this.videoStreams.push(i):this.audioStreams.push(i)}}static clearInactiveOrRecvonly(e){return/\ba=(recvonly|inactive)\b/.test(e)?e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,""):e}setHeaderBitrate(e){this.SDPHeader=this.SDPHeader.replace(/(\r\ns=[^\r\n]+)/gi,`$1\r\nc=IN IP4 0.0.0.0\r\nb=AS:${e*ko.KBitrate}\r\nb=TIAS:${e*ko.KBitrate*850}`)}setAudiosBitrate(e){return this.audioStreams=this.audioStreams.map((t=>this.setAudioItemBitrate(t,e))),this}setAudioBitrateWithStreamId(e,t){return this.audioStreams=this.audioStreams.map((i=>new RegExp(`\\bmsid:${t}\\b`,"ig").test(i)?this.setAudioItemBitrate(i,e):i)),this}setAudioBitrateWithMid(e,t){return this.audioStreams=this.audioStreams.map((i=>new RegExp(`\\bmid:${t}\\b`,"ig").test(i)?this.setAudioItemBitrate(i,e):i)),this}setAudioItemBitrate(e,t){if(0===t.max&&/\ba=inactive\b/gi.test(e))return e;if(!/\bmaxaveragebitrate\b/gi.test(e)){const i=["$1","maxaveragebitrate="+t.max*ko.KBitrate];e=e.replace(/(\buseinbandfec=[^\r\n]+)/gi,i.join(";"))}return this.addAudioBlineAS(e,t)}addAudioBlineAS(e,t){return/\bb=AS:\d+\b/gi.test(e)?e:e.replace(/(\bc=IN[^\r\n]+)/gi,`$1\r\nb=AS:${t.max*ko.KBitrate}\r\nb=TIAS:${t.max*ko.KBitrate*850}`)}setVideosBitrate(e){return this.videoStreams=this.videoStreams.map((t=>this.setVideoItemBitrate(t,e))),this}setVideoBitrateWithStreamId(e,t){return this.videoStreams=this.videoStreams.map((i=>new RegExp(`\\bmsid:${t}\\b`,"ig").test(i)?this.setVideoItemBitrate(i,e):i)),this}setVideoBitrateWithMid(e,t){return this.videoStreams=this.videoStreams.map((i=>new RegExp(`\\bmid:${t}\\b`,"ig").test(i)?this.setVideoItemBitrate(i,e):i)),this}setVideoItemBitrate(e,t){if(0===t.max&&/\ba=inactive\b/gi.test(e))return e;if(!/\bx-google-max-bitrate\b/.test(e)){const i=["$1","x-google-max-bitrate="+t.max*ko.KBitrate,"x-google-min-bitrate="+t.min*ko.KBitrate,`x-google-start-bitrate=${t.start||t.max*ko.KBitrate*.7}`];e=e.replace(/(\bprofile-level-id=42[e0]01f\b)/gi,i.join(";"))}return this.addVideoBlineAS(e,t)}addVideoBlineAS(e,t){return/\bb=AS:\d+\b/gi.test(e)?e:e.replace(/(\bc=IN[^\r\n]+)/gi,`$1\r\nb=AS:${t.max*ko.KBitrate}\r\nb=TIAS:${t.max*ko.KBitrate*850}`)}clearnSsrcWithMid(e,t){return this.audioStreams=this.audioStreams.map((i=>new RegExp(`\\bmid:${e}\\b`,"ig").test(i)?this.clearSSRC(i,t):i)),this.videoStreams=this.videoStreams.map((i=>new RegExp(`\\bmid:${e}\\b`,"ig").test(i)?this.clearSSRC(i,t):i)),this}clearSSRC(e,t){if(t===co.SENDONLY){if(/\ba=sendonly\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}if(t===co.RECVONLY){if(/\ba=recvonly\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}if(t===co.INACTIVE){if(/\ba=inactive\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}return e}}ko.KBitrate=1,function(e){e.PLANB="plan-b",e.UNIFIEDPLAN="unified-plan"}(ao||(ao={})),function(e){e.SENDONLY="sendonly",e.RECVONLY="recvonly",e.INACTIVE="inactive"}(co||(co={}));class Do{static setSdpSemantics(e){const t=We.getLogger(),{browser:i,version:r,supportsUnifiedPlan:n}=Ut;if(null==t||t.info(f.L_A_SDP_STRATEGY_SET_SDP_SEMANTICS_O,JSON.stringify({sdpSemantics:e,supportsUnifiedPlan:n,browser:i,version:r})),n)return/chrome/i.test(i)?r?void(this._sdpSemantics=r>92?"unified-plan":r<72?"plan-b":e):void(this._sdpSemantics="unified-plan"):void(/firefox/i.test(i)?this._sdpSemantics="unified-plan":/safari/i.test(i)?this._sdpSemantics=r<12?"plan-b":"unified-plan":this._sdpSemantics="unified-plan");this._sdpSemantics="plan-b"}static getSdpSemantics(){return Do._sdpSemantics}constructor(e){this._peer=e,this._outboundStreams={},this._logger=null,this._logger=We.getLogger()}getOutboundVideoInfo(){const e=[];for(const t in this._outboundStreams){const i=this._outboundStreams[t].getVideoTracks()[0];if(!i)continue;const r=/_tiny$/.test(t),{width:n,height:o}=St(i);e.push({trackId:i.id,simulcast:r?Xn.TINY:Xn.NORMAL,resolution:`${n}x${o}`})}return e}setRemoteAnswer(e){var t,i,r;return S(this,void 0,void 0,(function*(){if(e=ko.trimBlankLine(e),"disconnected"===this._peer.connectionState||"closed"===this._peer.connectionState)return null===(t=this._logger)||void 0===t||t.info(f.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:C.FAILED,msg:`peer.connectionState is ${this._peer.connectionState}`})),T.SET_REMOTE_DESCRIPTION_FAILED;try{yield this._peer.setRemoteDescription({type:"answer",sdp:e})}catch(e){return null===(i=this._logger)||void 0===i||i.info(f.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:C.FAILED,msg:e})),T.SET_REMOTE_DESCRIPTION_FAILED}return null===(r=this._logger)||void 0===r||r.info(f.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:C.SUCCESSED,sdp:e})),T.SUCCESS}))}getStatParsr(e,t,i,r){return/chrome/i.test(Ut.browser)?new No(e,t,i,r):/Firefox/i.test(Ut.browser)?new Ao(e,t,i,r):/Safari/i.test(Ut.browser)?new yo(e,t,i,r):null}resetSdp(e){return ko.trimBlankLine(e)}}class bo extends ko{constructor(e){super(e,ao.PLANB),this.SDP=e}stringify(){const e=[this.SDPHeader];[...this.audioStreams,...this.videoStreams].forEach((t=>{const i=t.match(/\ba=mid:(video|audio)\b/),r=ko.clearInactiveOrRecvonly(t);i&&i[1]===ze.AUDIO&&(e[1]=r),i&&i[1]===ze.VIDEO&&(e[2]=r)}));const t=e.join("");return ko.trimBlankLine(t)}setAudioBitrateWithStreamId(e,t){var i;return null===(i=this._logger)||void 0===i||i.warn(f.L_FUNCTION_IS_UNAVAILABLE,"plan-b not support set Audio Bitrate With Stream Id"),this}setVideoBitrateWithStreamId(e,t){var i;return null===(i=this._logger)||void 0===i||i.warn(f.L_FUNCTION_IS_UNAVAILABLE,"plan-b not support set Video Bitrate With Stream Id"),this}}class Uo extends Do{constructor(){super(...arguments),this.senders={},this._localTracks=[]}addLocalTrack(e){this._localTracks.includes(e)||this._localTracks.push(e);const t=e.getStreamId(),i=e.__innerGetMediaStreamTrack(),r=this._outboundStreams[t]||(this._outboundStreams[t]=new MediaStream);r.getTracks().forEach((e=>{e.kind===i.kind&&r.removeTrack(e)})),r.addTrack(i);const n=e.getTrackId(),o=this.senders[n];o?o.replaceTrack(i):(this.senders[n]=this._peer.addTrack(i,r),Object.defineProperty(i,"trackId",{value:n,writable:!1,enumerable:!1,configurable:!1}))}removeLocalTrack(e){const t=this._localTracks.findIndex((t=>t===e));t>=0&&this._localTracks.splice(t,1);const i=e.getTrackId(),r=this.senders[i];r&&(r.replaceTrack(null),this._peer.removeTrack(r),delete this.senders[i])}updateSubRemoteTracks(e){}updateRecvTransceiverMap(e,t){}setBitrate(e,t,i){this._maxBitrate=e,this._minBitrate=t,this._startBitrate=i||.7*e}createOffer(e){return S(this,void 0,void 0,(function*(){const t=yield this._peer.createOffer({iceRestart:e,offerToReceiveAudio:!0,offerToReceiveVideo:!0});for(const e in this._outboundStreams){const i=this._outboundStreams[e].id;t.sdp=t.sdp.replace(new RegExp(i,"g"),e)}return t.sdp&&(t.sdp=this.resetSdp(t.sdp)),yield this._peer.setLocalDescription(t),{type:"offer",semantics:"plan-b",sdp:t.sdp}}))}setRemoteAnswer(e){return e=this.resetSdp(e),super.setRemoteAnswer(e)}resetSdp(e){const t=new bo(e),i={max:0,min:0},r={max:0,min:0};return this._localTracks.forEach((e=>{const{min:t,max:n,start:o}=e.getBitrate();e.isAudioTrack()&&(r.max=r.max<n?n:r.max,r.min=r.min>t?t:r.min,r.max===n?r.start=o:r.start=.7*r.max),e.isVideoTrack()&&(i.max=i.max<n?n:i.max,i.min=i.min>t?t:i.min,i.max===n?i.start=o:i.start=.7*i.max)})),t.setAudiosBitrate(r),t.setVideosBitrate(i),t.stringify()}}class Po extends ko{constructor(e){super(e,ao.UNIFIEDPLAN),this.SDP=e}stringify(){const e=[this.SDPHeader];[...this.audioStreams,...this.videoStreams].forEach((t=>{const i=t.match(/\ba=mid:(\d+)\b/);i&&i[1]&&(e[+i[1]+1]=t)})),this.SDPHeader="",this.videoStreams=[],this.audioStreams=[];const t=e.join("");return ko.trimBlankLine(t)}}class Mo{static splitSections(e){return e.split("\nm=").map(((e,t)=>`${(t>0?`m=${e}`:e).trim()}\r\n`))}static getMediaSections(e){const t=Mo.splitSections(e);return t.shift(),t}static parseExtmap(e){const t=e.substr(9).split(" ");return{id:parseInt(t[0],10),direction:t[0].indexOf("/")>0?t[0].split("/")[1]:"sendrecv",uri:t[1]}}static splitLines(e){return e.trim().split("\n").map((e=>e.trim()))}static parseMLine(e){const t=Mo.splitLines(e)[0].substr(2).split(" ");return{kind:t[0],port:parseInt(t[1],10),protocol:t[2],fmt:t.slice(3).join(" ")}}static matchPrefix(e,t){return Mo.splitLines(e).filter((e=>0===e.indexOf(t)))}static parseMsid(e){let t;const i=Mo.matchPrefix(e,"a=msid:");if(1===i.length)return t=i[0].substr(7).split(" "),{stream:t[0],track:t[1]};const r=Mo.matchPrefix(e,"a=ssrc:").map((e=>Mo.parseSsrcMedia(e))).filter((e=>"msid"===e.attribute));return r.length>0&&r[0].value?(t=r[0].value.split(" "),{stream:t[0],track:t[1]}):{stream:"",track:""}}static parseSsrcMedia(e){const t=e.indexOf(" "),i={ssrc:parseInt(e.substr(7,t-7),10)},r=e.indexOf(":",t);return r>-1?(i.attribute=e.substr(t+1,r-t-1),i.value=e.substr(r+1)):i.attribute=e.substr(t+1),i}static getMid(e){const t=Mo.matchPrefix(e,"a=mid:")[0];if(t)return t.substr(6)}}class xo{constructor(){this.__streams=new Map}static getInstance(){return xo.instance||(xo.instance=new xo),xo.instance}push(e,t){return this.__streams.set(e,t),t}pickup(e){return this.__streams.get(e)}delete(e){return this.__streams.delete(e)}get streams(){const e=new Map;for(const t of this.__streams.keys())e.set(t,this.pickup(t));return e}}class wo extends Do{constructor(){super(...arguments),this._sendTransceiver={},this._localTracks={},this._recvAudio=[],this._recvVideo=[],this._recvTransceiver={},this._subedTracks=[],this.midMsid={}}setBitrate(e,t,i){var r;null===(r=this._logger)||void 0===r||r.warn(f.L_FUNCTION_IS_UNAVAILABLE,"the interface named `setBitrate` is invalid while sdpSemantics value is `unified-plan`")}addLocalTrack(e){var t;const i=e.getTrackId(),r=e.getStreamId(),n=e.__innerGetMediaStreamTrack();this._localTracks[i]=e;const o=this._outboundStreams[r]||(this._outboundStreams[r]=new MediaStream);o.getTracks().forEach((e=>{e.kind===n.kind&&o.removeTrack(e)})),o.addTrack(n);const s=this._sendTransceiver[i];s?(s.sender.replaceTrack(n),s.direction="sendonly"):this._sendTransceiver[i]=this._peer.addTransceiver(n,{direction:"sendonly",streams:[o]});xo.getInstance().push(i,{msid:r,id:this._outboundStreams[r].id,kind:null===(t=e.streamTrack)||void 0===t?void 0:t.kind})}removeLocalTrack(e){const t=e.getTrackId(),i=e.getStreamId();e.__innerGetMediaStreamTrack(),delete this._localTracks[t];const r=this._sendTransceiver[t];if(!r)return;"closed"!==this._peer.connectionState&&(r.direction="inactive",this._peer.removeTrack(r.sender),r.sender.replaceTrack(null));const n=this._outboundStreams[i];(e.isAudioTrack()?n.getAudioTracks():n.getVideoTracks()).forEach((e=>n.removeTrack(e)));const o=this._sendTransceiver[`${t}_tiny`];if(o&&"inactive"!==o.direction&&"closed"!==this._peer.connectionState){o.direction="inactive";const{sender:e}=o,t=e.track;this._peer.removeTrack(e),e.replaceTrack(null);this._outboundStreams[`${i}_tiny`].removeTrack(t),t.stop()}}updateRecvTransceiverMap(e,t){const{mediaType:i}=Ct(e);this._recvTransceiver[e]=t;const r=i===Je.AUDIO_ONLY?this._recvAudio:this._recvVideo,n=r.findIndex((e=>e===t));n>=0&&r.splice(n,1)}updateSubRemoteTracks(e){const t=e.slice(),i=this._subedTracks.slice();this._subedTracks=e.slice();for(let e=t.length-1;e>=0;e-=1){const r=t[e],n=i.findIndex((e=>e===r));n>=0&&(t.splice(e,1),i.splice(n,1))}i.length&&i.forEach((e=>{const t=e.getTrackId();e.__innerSetMediaStreamTrack(void 0);const i=this._recvTransceiver[t];i&&(i.direction="inactive")}));const r={audio:0,video:0};t.length&&t.forEach((e=>{const t=e.isAudioTrack()?"audio":"video",i=this._recvTransceiver[e.getTrackId()];i?i.direction="recvonly":r[t]+=1}));for(let e=this._recvAudio.length;e<r.audio;e+=1)this._recvAudio.push(this._peer.addTransceiver("audio",{direction:"recvonly"}));for(let e=this._recvVideo.length;e<r.video;e+=1)this._recvVideo.push(this._peer.addTransceiver("video",{direction:"recvonly"}))}createOffer(e){return S(this,void 0,void 0,(function*(){const t=yield this._peer.createOffer({iceRestart:e});let i=t.sdp;for(const e in this._outboundStreams){const t=this._outboundStreams[e].id;i=i.replace(new RegExp(t,"g"),e)}return i=this.resetOfferSdp(i),i=i.replace(/(a=ice-options:trickle)/g,"$1\r\na=ice-options:renomination"),t.sdp=i,yield this._peer.setLocalDescription(t),{type:"offer",semantics:"unified-plan",sdp:i}}))}setRemoteAnswer(e){e=this.resetAnswerSdp(e);const t=/[\r\n]+\r\n[\r\n]+/g;return t.test(e)&&(e=e.replace(t,"\r\n")),super.setRemoteAnswer(e)}resetOfferSdp(e){var t;const i=new Po(e);for(const r in this._sendTransceiver){const n=this._sendTransceiver[r],o=null===(t=n.sender.track)||void 0===t?void 0:t.kind;let{direction:s,mid:a}=n;if(!a){Mo.getMediaSections(e).forEach((e=>{Mo.parseExtmap(e);const{kind:t}=Mo.parseMLine(e);let{stream:i}=Mo.parseMsid(e);const n=Mo.getMid(e);"video"===o?/tiny$/.test(i)?i=i.replace(/tiny$/gi,"1_tiny"):i+="_1":i+="_0",i===r&&o===t&&n&&(a=n)}))}if(a){if(s===co.SENDONLY){const e=this._localTracks[r],t=null==e?void 0:e.getBitrate();o===ze.AUDIO&&t&&i.setAudioBitrateWithMid(t,a),o===ze.VIDEO&&t&&i.setVideoBitrateWithMid(t,a)}s===co.INACTIVE&&i.clearnSsrcWithMid(a,co.INACTIVE)}}for(const e in this._recvTransceiver){const t=this._recvTransceiver[e],{direction:r,mid:n}=t;n&&r===co.INACTIVE&&i.clearnSsrcWithMid(n,co.RECVONLY)}return i.stringify()}resetAnswerSdp(e){var t;const i=new Po(e);for(const e in this._sendTransceiver){const r=this._sendTransceiver[e],{mid:n}=r;if(n){const o=this._localTracks[e],s=null==o?void 0:o.getBitrate(),a=null===(t=r.sender.track)||void 0===t?void 0:t.kind;a===ze.AUDIO&&s&&i.setAudioBitrateWithMid(s,n),a===ze.VIDEO&&s&&i.setVideoBitrateWithMid(s,n)}}return i.stringify()}}!function(e){e.VP8="VP8",e.VP9="VP9",e.H264="H264"}(_o||(_o={}));class Bo extends e{constructor(e,t,i,r,n,o,s=!1,a){super(),this._pcName=e,this._reTryExchange=t,this._currentUserId=i,this._polarisReport=r,this.onTrackTrouble=n,this._store=o,this._isRoomAudience=s,this._initOptions=a,this.senderAndReciveSize=32,this.pubLocalTracks={},this._reTryExchangeTimer=null,this._reportStatsTimer=null,this._reportR3R4ToPolarisTimer=null,this._isDestroyed=!1,this._formatStatsData=null,this._logger=null,this._reportListener=null,this.troubleTracksCollection=new Map;const c=Do.getSdpSemantics(),d=this._rtcPeerConn=new RTCPeerConnection({sdpSemantics:c});this._sdpStrategy="plan-b"===c?new Uo(d):new wo(d),this._rtcPeerConn.oniceconnectionstatechange=this._onICEConnectionStateChange.bind(this),this._rtcPeerConn.onconnectionstatechange=this._onConnectionStateChange.bind(this),this._rtcPeerConn.ontrack=this._onTrackReady.bind(this),this.reportParser=this._sdpStrategy.getStatParsr(this._rtcPeerConn,c,this._currentUserId,this._store),this._logger=We.getLogger()}getName(){return this._pcName}getLocalTracks(){return Object.values(this.pubLocalTracks)}_onConnectionStateChange(){var e;null===(e=this._logger)||void 0===e||e.info(f.L_RTC_PEER_CONNECTION_CONNECTION_STATE_S,JSON.stringify({connectionState:this._rtcPeerConn.connectionState,pcName:this._pcName}))}startAutoExecute(e){this.stopAutoExecute(),this._reportStatsTimer=setTimeout((()=>{this._reportHandle(),this.startAutoExecute(e)}),e)}stopAutoExecute(){clearTimeout(this._reportStatsTimer)}_onICEConnectionStateChange(){var e,t,i,r;return S(this,void 0,void 0,(function*(){null===(e=this._logger)||void 0===e||e.info(f.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_S,JSON.stringify({connectionState:this._rtcPeerConn.connectionState,pcName:this._pcName}));const n=yield this._getStatsData(),o=n?this._createRCRTCStateReport(n).iceCandidatePair:null,{iceConnectionState:s}=this._rtcPeerConn;this.emit(Bo.__INNER_ICE_STATE_CHANGE__,{status:s,time:Date.now(),iceCandidatePair:o}),"connected"===s&&(this.emit(Bo.__INNER_ICE_CONNECTED__),this.startAutoExecute(1e3)),"failed"!==s&&"disconnected"!==s||(this._reTryExchange(),this._reTryExchangeTimer=setInterval(this._reTryExchange,15e3));try{null===(i=null===(t=this._reportListener)||void 0===t?void 0:t.onICEConnectionStateChange)||void 0===i||i.call(t,s,this._pcName)}catch(e){null===(r=this._logger)||void 0===r||r.error(f.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_REPORT_R,JSON.stringify({status:C.FAILED,pcName:this._pcName,mag:e}))}}))}_onTrackReady(e){if(!e.streams.length)return;const t=e.streams[0].id,{track:i}=e.receiver,r=[t,"audio"===i.kind?Je.AUDIO_ONLY:Je.VIDEO_ONLY].join("_");Object.defineProperty(i,"trackId",{value:r,writable:!1,enumerable:!1,configurable:!1}),this._updateRecvTransceiverMap(r,e.transceiver),this.emit(Bo.__INNER_EVENT_TRACK_READY__,e)}setBitrate(e,t,i){var r;return S(this,void 0,void 0,(function*(){this._sdpStrategy.setBitrate(e,t,i),null===(r=this._logger)||void 0===r||r.info(f.L_RTC_PEER_CONNECTION_SET_BITRATE_O,JSON.stringify({status:C.SUCCESSED,max:e,min:t,start:i}))}))}createOffer(e){var t;return S(this,void 0,void 0,(function*(){const i=yield this._sdpStrategy.createOffer(e);return null===(t=this._logger)||void 0===t||t.info(f.L_RTC_PEER_CONNECTION_CREATE_OFFER_O,JSON.stringify({offerSDP:i.sdp,sdpDemantics:i.semantics})),i}))}setRemoteAnswer(e){return S(this,void 0,void 0,(function*(){return this._sdpStrategy.setRemoteAnswer(e)}))}getLocalTrack(e){return this.pubLocalTracks[e]||null}addLocalTrack(e){var t;this.pubLocalTracks[e.getTrackId()]=e,this._sdpStrategy.addLocalTrack(e),e.off(rt.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(rt.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),e.on(rt.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.on(rt.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),null===(t=this._logger)||void 0===t||t.info(f.L_RTC_PEER_CONNECTION_ADD_LOCAL_TRACK_O,JSON.stringify({trackId:e.getTrackId()}))}removeLocalTrackById(e){var t,i;const r=this.getLocalTrack(e);r?(null===(i=this._logger)||void 0===i||i.info(f.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_BY_ID_O,JSON.stringify({status:C.SUCCESSED,trackId:e})),this.removeLocalTrack(r)):null===(t=this._logger)||void 0===t||t.warn(f.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_BY_ID_O,JSON.stringify({status:C.FAILED,msg:"track not found",trackId:e}))}removeAllLocalTrack(){Object.keys(this.pubLocalTracks).forEach((e=>{/_tiny$/.test(e)||this.removeLocalTrackById(e)}))}removeLocalTrack(e){var t;const i=e.getTrackId();delete this.pubLocalTracks[i],this._sdpStrategy.removeLocalTrack(e),e.__innerSetPublished(!1),e.off(rt.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(rt.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this);const r=`${i}_tiny`,n=this.getLocalTrack(r);n&&(this._sdpStrategy.removeLocalTrack(n),delete this.pubLocalTracks[r],n.destroy()),null===(t=this._logger)||void 0===t||t.info(f.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_O,JSON.stringify({trackId:i}))}_updateRecvTransceiverMap(e,t){this._sdpStrategy.updateRecvTransceiverMap(e,t)}updateSubRemoteTracks(e){this._sdpStrategy.updateSubRemoteTracks(e)}getOutboundVideoInfo(){return this._sdpStrategy.getOutboundVideoInfo()}_onLocalTrackMuted(e,t){const i=this.getLocalTrack(`${e.getTrackId()}_tiny`);i&&(i.__innerGetMediaStreamTrack().enabled=!e.isLocalMuted()),this.emit(rt.__INNER_EVENT_MUTED_CHANGE__,e,t)}_onLocalTrackDestroied(e){this.emit(rt.__INNER_EVENT_DESTROY__,e)}registerReportListener(e){this._reportListener=e}_createRCRTCStateReport(e){const{timestamp:t,iceCandidatePair:i,senders:r,receivers:n}=e;(null==i?void 0:i.totalPacketsLost)&&(null==i||delete i.totalPacketsLost);for(const e in i)xt(i[e])&&delete i[e];const o=[];r.forEach((e=>{const{trackId:t,kind:i,packetsLostRate:r,remoteResource:n,bitrate:s,jitter:a}=e,c={trackId:t,kind:i,packetsLostRate:r,remoteResource:n,bitrate:s,jitter:a};(e.audioLevel||0===e.audioLevel)&&(c.audioLevel=e.audioLevel),e.frameWidth&&(c.frameWidth=e.frameWidth),e.frameHeight&&(c.frameHeight=e.frameHeight),e.frameRate&&(c.frameRate=e.frameRate),e.trackId&&o.push(Object.assign({},c))}));const s=[];return n.forEach((e=>{const{trackId:t,kind:i,packetsLostRate:r,remoteResource:n,bitrate:o,jitter:a}=e,c={trackId:t,kind:i,packetsLostRate:r,remoteResource:n,bitrate:o,jitter:a};(e.audioLevel||0===e.audioLevel)&&(c.audioLevel=e.audioLevel),e.frameWidth&&(c.frameWidth=e.frameWidth),e.frameHeight&&(c.frameHeight=e.frameHeight),e.frameRate&&(c.frameRate=e.frameRate),e.trackId&&s.push(Object.assign({},c))})),{timestamp:t,iceCandidatePair:i,senders:o,receivers:s,pcName:this._pcName}}_getStatsData(){var e,t;return S(this,void 0,void 0,(function*(){this._formatStatsData=null;let i=null;const r=yield this._rtcPeerConn.getStats();i=null===(e=this.reportParser)||void 0===e?void 0:e.parseRTCStatsReport(r);const n=null===(t=this.reportParser)||void 0===t?void 0:t.formatRCRTCStateReport(i);return this._formatStatsData=n,n}))}_reportHandle(){var e,t,i,r,n,o,s;return S(this,void 0,void 0,(function*(){const a=yield this._getStatsData();if(!a)return;const c=this._createRCRTCStateReport(a);try{null===(t=null===(e=this._reportListener)||void 0===e?void 0:e.onStateReport)||void 0===t||t.call(e,JSON.parse(JSON.stringify(c)))}catch(e){null===(i=this._logger)||void 0===i||i.error(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,null==e?void 0:e.stack)}const d=[...a.receivers,...a.senders].filter((e=>!("audio"!==e.kind))).map((e=>({trackId:e.trackId,audioLevel:e.audioLevel})));if(this.emit(Bo.__INNER_AUDIOLEVEL_CHANGE__,d),this._isRoomAudience&&(null===(r=this._reportListener)||void 0===r?void 0:r.onReportLiveAudioStates)){const e=this._getLiveAudioState();try{e.length&&(null===(o=null===(n=this._reportListener)||void 0===n?void 0:n.onReportLiveAudioStates)||void 0===o||o.call(n,e))}catch(e){null===(s=this._logger)||void 0===s||s.error(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,null==e?void 0:e.stack)}}}))}_getLiveAudioState(){const e=[];return this._rtcPeerConn.getReceivers().forEach((t=>{const i=t.getContributingSources();i.length&&e.push(...i)})),e.map((e=>{var t;const{source:i,audioLevel:r}=e,n=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(i);if(!n)return{};const{userId:o}=Ct(n);return{audioLevel:io(r),userId:o,trackId:n}})).filter((e=>!!e.userId))}_sendR3R4Data(){var e,t;return S(this,void 0,void 0,(function*(){const i=this._formatStatsData;if(!i)return!0;if((null===(e=null==this?void 0:this._initOptions)||void 0===e?void 0:e.polarisThrottle)&&i.receivers.length+i.senders.length>this.senderAndReciveSize)return!0;if(i.senders.length||i.receivers.length){const e=yield null===(t=this._polarisReport)||void 0===t?void 0:t.sendR3R4Data(i);return i.senders.length>0&&i.senders.forEach((e=>{if("video"===e.kind){const{encoderImplementation:t,frameRate:i,frameWidth:r,frameHeight:n}=e;let o=0;"unknown"!==(null==t?void 0:t.toLowerCase())&&i&&r&&n||(o=1),this.setTroubleTrack(e.trackId,o)}})),e}return!0}))}__reportR3R4ToPolaris(){return S(this,void 0,void 0,(function*(){clearTimeout(this._reportR3R4ToPolarisTimer),this._reportR3R4ToPolarisTimer=setTimeout((()=>S(this,void 0,void 0,(function*(){this._sendR3R4Data().then((()=>{this.__reportR3R4ToPolaris()}))}))),2e3)}))}getRTCPeerConn(){return this._rtcPeerConn}getCapabilitiesCodes(e=_o.H264){var t;let i=null===(t=RTCRtpSender.getCapabilities("video"))||void 0===t?void 0:t.codecs,r=null;switch(e){case _o.VP8:case _o.VP9:r=i.find((t=>t.mimeType.match(e)));break;case _o.H264:r=i.find((t=>{var i;return t.mimeType.match(e)&&(null===(i=t.sdpFmtpLine)||void 0===i?void 0:i.match("42e01f"))}))}return i=i.filter((e=>e!==r)),i=[r,...i],i}setEncoderPreferences(e){var t;return S(this,void 0,void 0,(function*(){const i=this.getRTCPeerConn(),r=this.getCapabilitiesCodes(e);null===(t=this._logger)||void 0===t||t.info(f.L_SET_ENCODER_PREFERENCES_S,JSON.stringify({status:C.SUCCESSED,codecCap:r})),i.getTransceivers().forEach((e=>{var t;"video"===(null===(t=e.sender.track)||void 0===t?void 0:t.kind)&&e.setCodecPreferences(r)}))}))}destroy(){var e;this.clear(),this.clearReTryExchangeTimer(),clearTimeout(this._reportR3R4ToPolarisTimer),this.stopAutoExecute(),this.registerReportListener(null),this._rtcPeerConn.close(),this._isDestroyed=!0,this.reportParser=null,null===(e=this._logger)||void 0===e||e.info(f.L_RTC_PEER_CONNECTION_DESTROY_O,JSON.stringify({status:C.SUCCESSED}))}clearReTryExchangeTimer(){clearInterval(this._reTryExchangeTimer),this._reTryExchangeTimer=null}isDestroyed(){return this._isDestroyed}setTroubleTrack(e,t=0){let i=this.troubleTracksCollection.get(e);if(0!==t&&i){if(this.troubleTracksCollection.set(e,i+1),i+1>5&&this.onTrackTrouble){let e=[];for(const t of this.troubleTracksCollection.keys()){const i=this.troubleTracksCollection.get(t);i&&i>5&&this.pubLocalTracks[t]&&e.push(this.pubLocalTracks[t])}e.length>0&&this.onTrackTrouble(e)}}else this.troubleTracksCollection.set(e,0)}}Bo.__INNER_EVENT_TRACK_READY__="inner-track-ready",Bo.__INNER_AUDIOLEVEL_CHANGE__="inner-audio-level-change",Bo.__INNER_ICE_STATE_CHANGE__="inner-ice-state-change",Bo.__INNER_ICE_CONNECTED__="inner-ice-connected",function(e){e[e.DISABLE=0]="DISABLE",e[e.ENABLE=1]="ENABLE"}(lo||(lo={})),function(e){e[e.MeetingOrAnchor=1]="MeetingOrAnchor",e[e.Audience=2]="Audience"}(uo||(uo={})),function(e){e[e.NOT_REPORT=-1]="NOT_REPORT",e[e.REPORT_SUCCESS=1e4]="REPORT_SUCCESS",e[e.REPORT_FAIL=0]="REPORT_FAIL",e[e.PB_ERROR=40001]="PB_ERROR"}(ho||(ho={})),function(e){e.R1="R1",e.R2="R2",e.R3="R3",e.R4="R4"}(go||(go={}));class Vo{constructor(e,t,i,r,n=uo.MeetingOrAnchor){this._context=e,this._runtime=t,this._roomId=i,this._crtRTCRoom=r,this._userRole=n}_send(e){return S(this,void 0,void 0,(function*(){if(this._context.getConnectionStatus()!==a.CONNECTED)return ho.NOT_REPORT;return(yield this._context.setRTCState(this._roomId,e))===n.SUCCESS?ho.REPORT_SUCCESS:ho.REPORT_FAIL}))}_getClientID(){const e="uuid";let t=this._runtime.localStorage.getItem(e);return t||(t=At(),this._runtime.localStorage.setItem(e,t)),t}_getRealResourceId(e){let t=e;const i=e.indexOf("_tiny");return i>-1&&(t=e.slice(0,i)),t}_getPolarisTrackId(e){let t="";const i=e.split("_");if(e.includes("_tiny")){const e=i.pop(),r=parseInt(i.pop())===Je.AUDIO_ONLY?"audio":"video",n=i.pop();t=[i.join("_"),n,e,r].join("_")}else{const e=parseInt(i.pop())===Je.AUDIO_ONLY?"audio":"video",r=i.pop();t=[i.join("_"),r,e].join("_")}return t}sendR3R4Data(e){return S(this,void 0,void 0,(function*(){const{iceCandidatePair:t,senders:i,receivers:r}=e,n=(null==t?void 0:t.bitrateSend)||$n,o=(null==t?void 0:t.bitrateRecv)||$n,s=(null==t?void 0:t.networkType)||"unknown",a=(null==t?void 0:t.rtt)||$n,c=`${(null==t?void 0:t.IP)||$n}:${null==t?void 0:t.port}`,d=(null==t||t.remoteIP,null==t||t.remotePort,(null==t?void 0:t.availableIncomingBitrate)||$n),_=(null==t?void 0:t.availableOutgoingBitrate)||$n,l=(null==t?void 0:t.totalPacketsLost)||$n,u=this._context.getCurrentId();let h=`R3\t${n}\t-1\t-1\t-1\t${s}\t${a}\t${c}\t${d}\t${_}\t${l}\t${u}\r`,g=`R4\t${o}\t-1\t-1\t-1\t${s}\t${a}\t${c}\t${d}\t${_}\t${l}\t${u}\r`;const v=i.map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:n,bitrate:o,packetsLostRate:s,frameRate:a,frameWidth:c,frameHeight:d,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:g,googFirsSent:v,encoderImplementation:p}=e,R=this._getPolarisTrackId(i),m=this._getRealResourceId(i);return{trackId:R,googCodecName:p||String($n),audioLevel:r||0===r?r:$n,bitrate:o||0===o?o:$n,packetsLostRate:s||0===s?s:$n,frameRate:a||$n,resolution:c&&d?`${c} * ${d}`:"-1",jitter:l||$n,nackCount:u||0===u?u:$n,pliCount:h||0===h?h:$n,rtt:g||$n,googFirsSent:v,samplingRate:n,googRenderDelayMs:_,encoderImplementation:p||String($n),trackState:(null===(t=this._crtRTCRoom.getLocalTrack(m))||void 0===t?void 0:t.isLocalMuted())?lo.DISABLE:lo.ENABLE}})),p=r.filter((e=>!!e.trackId)).map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:n,bitrate:o,packetsLostRate:s,frameRate:a,frameWidth:c,frameHeight:d,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:g,googFirsReceived:v,codecImplementationName:p}=e,R=this._getPolarisTrackId(i),m=this._getRealResourceId(i);return{trackId:R,googCodecName:p||String($n),audioLevel:r||0===r?r:$n,bitrate:o||0===o?o:$n,packetsLostRate:s||0===s?s:$n,frameRate:a||$n,resolution:c&&d?`${c} * ${d}`:"-1",jitter:l||$n,nackCount:u||0===u?u:$n,pliCount:h||0===h?h:$n,rtt:g||$n,googFirsReceived:v,samplingRate:n,googRenderDelayMs:_,codecImplementationName:p||String($n),trackState:(null===(t=this._crtRTCRoom.getRemoteTrack(m))||void 0===t?void 0:t.isLocalMuted())?lo.DISABLE:lo.ENABLE}}));let R=ho.REPORT_FAIL;h+=v.map((e=>`${e.trackId}\t${e.googCodecName}\t${e.audioLevel}\t${e.samplingRate}\t${e.bitrate}\t${e.packetsLostRate}\t${e.frameRate}\t${e.resolution}\t${e.googRenderDelayMs}\t${e.jitter}\t${e.nackCount}\t${e.pliCount}\t${e.rtt}\t${e.googFirsSent}\t${e.encoderImplementation}\t${e.trackState}`)).join("\n"),e.senders.length&&(R=yield this._send(`${h}\r${this._userRole}`));let m=ho.REPORT_FAIL;return g+=p.map((e=>`${e.trackId}\t${e.googCodecName}\t${e.audioLevel}\t${e.samplingRate}\t${e.bitrate}\t${e.packetsLostRate}\t${e.frameRate}\t${e.resolution}\t${e.googRenderDelayMs}\t${e.jitter}\t${e.nackCount}\t${e.pliCount}\t${e.rtt}\t${e.googFirsReceived}\t${e.codecImplementationName}\t${e.trackState}`)).join("\n"),e.receivers.length&&(m=yield this._send(`${g}\r${this._userRole}`)),R!==ho.REPORT_SUCCESS&&m!==ho.REPORT_SUCCESS?ho.REPORT_FAIL:ho.REPORT_SUCCESS}))}sendR1(){const e=this._context.getCoreVersion(),t=navigator.platform,i=`R1\t5.6.9\t${e}\tweb\t${t}\t-1\t${Ut.browser}\t${Ut.version}\t${this._getClientID()}\t${this._userRole}`;this._send(i)}sendR2(e,t,i){const r=`R2\t${e}\t${t}\t${this._getClientID()}\r${i.join("\t")}\r${this._userRole}`;this._send(r)}}class Fo{constructor(e,t,i,r,n=uo.MeetingOrAnchor){this._context=e,this._runtime=t,this._roomId=i,this._crtRTCRoom=r,this._userRole=n,this._useHttp=!0;const o=this._context.getNaviInfo();Fo.logServer=null==o?void 0:o.logServer,Fo.dc=null==o?void 0:o.dc,this._polarisSignalReporter=new Vo(e,t,i,r,n)}_send(e,t){var i,r;return S(this,void 0,void 0,(function*(){if(this._context.getConnectionStatus()!==a.CONNECTED)return ho.NOT_REPORT;const{logServer:n}=Fo;if(!n||!this._useHttp||!Zn.jwtToken)return ho.REPORT_FAIL;const o=yield this._context.setRTCStateByHttp(n,this._runtime,e,t);return o===ho.REPORT_SUCCESS?ho.REPORT_SUCCESS:o===T.JWT_TIME_OUT?(this._refetchNaviInfo(),ho.REPORT_FAIL):o===ho.REPORT_FAIL||o===ho.PB_ERROR?(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_HTTP_POLARIS_REPORT_FAIL_O,`send data fail -> code: ${o}`),this._useHttp=!1,ho.REPORT_FAIL):ho.REPORT_FAIL}))}_refetchNaviInfo(){return S(this,void 0,void 0,(function*(){const{jwt:e,naviInfo:t}=yield(i=this._context,S(void 0,void 0,void 0,(function*(){const e=i.getPluginContext();yield e.refetchNaviInfo();const t=i.getNaviInfo();return{naviInfo:t,jwt:qn(t)}})));var i;Zn.jwtToken=e,Fo.logServer=null==t?void 0:t.logServer,Fo.dc=null==t?void 0:t.dc}))}_getRealResourceId(e){let t=e;const i=e.indexOf("_tiny");return i>-1&&(t=e.slice(0,i)),t}_getPolarisTrackId(e){let t="";const i=e.split("_");if(e.includes("_tiny")){const e=i.pop(),r=parseInt(i.pop())===Je.AUDIO_ONLY?"audio":"video",n=i.pop();t=[i.join("_"),n,e,r].join("_")}else{const e=parseInt(i.pop())===Je.AUDIO_ONLY?"audio":"video",r=i.pop();t=[i.join("_"),r,e].join("_")}return t}_formatReportBaseData(e){return{type:e,appKey:this._context.getAppkey(),sessionId:this._crtRTCRoom.getSessionId(),roomId:this._roomId,roomCreateTime:this._context.roomCreateTime||0,userId:this._context.getCurrentId(),userRole:this._userRole,joinTime:this._context.userJoinTime||0,signalDataCenter:Fo.dc||""}}_formatReportData(e,t){let i=this._formatReportBaseData(e),r={};switch(e){case go.R1:r=this._formatR1Data();break;case go.R2:r=this._formatR2Data(t);break;case go.R3:case go.R4:r=this._formatR3R4Data(e,t)}return Object.assign(Object.assign({},i),{[{R1:"r1Info",R2:"r2Info",R3:"r3Info",R4:"r4Info"}[e]]:r})}_formatR1Data(){return{joinTime:this._context.userJoinTime||0,rtcVersion:"5.6.9",imVersion:this._context.getCoreVersion(),platform:"web",device:navigator.platform,os:String($n),browserName:Ut.browser,browserVersion:String(Ut.version),receiveTime:Date.now()}}_formatR2Data(e){const{action:t,status:i,trackIds:r}=e;return{joinTime:this._context.userJoinTime||0,sendTime:Date.now(),rtcActionType:t,rtcActionStatus:i,trackId:r,receiveTime:Date.now()}}_formatR3R4Data(e,t){const{iceCandidatePair:i,senders:r,receivers:n}=t;let o=0,s=[];return e===go.R3?(o=(null==i?void 0:i.bitrateSend)||$n,s=r.map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:n,bitrate:o,packetsLostRate:s,frameRate:a,frameWidth:c,frameHeight:d,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:g,googFirsSent:v,encoderImplementation:p}=e,R=this._getPolarisTrackId(i),m=this._getRealResourceId(i);return{trackId:R,codeName:p||String($n),volume:String(r||0===r?r:$n),samplingRate:n||$n,bitRate:o||0===o?o:$n,packetLossRate:s||0===s?s:$n,frameRate:a||$n,resolution:c&&d?`${c} * ${d}`:"-1",blockTime:_,jitterData:l||$n,nAckCount:String(u||0===u?u:$n),pliCount:String(h||0===h?h:$n),googleRTTTotalTime:g||$n,isReceiveFirstFrameRate:v,codeType:p||String($n),isEnabled:(null===(t=this._crtRTCRoom.getLocalTrack(m))||void 0===t?void 0:t.isLocalMuted())?lo.DISABLE:lo.ENABLE}}))):e===go.R4&&(o=(null==i?void 0:i.bitrateRecv)||$n,s=n.filter((e=>!!e.trackId)).map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:n,bitrate:o,packetsLostRate:s,frameRate:a,frameWidth:c,frameHeight:d,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:g,googFirsReceived:v,codecImplementationName:p}=e,R=this._getPolarisTrackId(i),m=this._getRealResourceId(i);return{trackId:R,codeName:p||String($n),volume:String(r||0===r?r:$n),samplingRate:n||$n,bitRate:o||0===o?o:$n,packetLossRate:s||0===s?s:$n,frameRate:a||$n,resolution:c&&d?`${c} * ${d}`:"-1",blockTime:_,jitterData:l||$n,nAckCount:String(u||0===u?u:$n),pliCount:String(h||0===h?h:$n),googleRTTTotalTime:g||$n,isReceiveFirstFrameRate:v,codeType:p||String($n),isEnabled:(null===(t=this._crtRTCRoom.getRemoteTrack(m))||void 0===t?void 0:t.isLocalMuted())?lo.DISABLE:lo.ENABLE}}))),{info:{joinTime:this._context.userJoinTime||0,receiveTime:Date.now(),totalBitRate:o,appCPUUsage:-1,systemCPUUsage:-1,systemCPUFrequency:-1,networkStatus:(null==i?void 0:i.networkType)||"unknown",googleRTTNetwork:(null==i?void 0:i.rtt)||$n,ipAddress:`${(null==i?void 0:i.IP)||$n}:${null==i?void 0:i.port}`,useReceiveBroadBand:String((null==i?void 0:i.availableIncomingBitrate)||$n),useSendBroadBand:String((null==i?void 0:i.availableOutgoingBitrate)||$n),packetLossCount:String((null==i?void 0:i.totalPacketsLost)||$n),streams:s}}}sendR3R4Data(e){return S(this,void 0,void 0,(function*(){let t=ho.REPORT_FAIL;if(e.senders.length){const i=this._formatReportData(go.R3,e);t=yield this._send(i,go.R3),t===ho.REPORT_FAIL&&(t=yield this._polarisSignalReporter.sendR3R4Data(e))}let i=ho.REPORT_FAIL;if(e.receivers.length){const t=this._formatReportData(go.R4,e);i=yield this._send(t,go.R4),i===ho.REPORT_FAIL&&(i=yield this._polarisSignalReporter.sendR3R4Data(e))}return t!==ho.REPORT_SUCCESS&&i!==ho.REPORT_SUCCESS?ho.REPORT_FAIL:ho.REPORT_SUCCESS}))}sendR1(){var e;return S(this,void 0,void 0,(function*(){const t=this._formatReportData(go.R1);(yield this._send(t,go.R1))===ho.REPORT_FAIL&&(null===(e=this._polarisSignalReporter)||void 0===e||e.sendR1())}))}sendR2(e,t,i){var r;return S(this,void 0,void 0,(function*(){const n=this._formatReportData(go.R2,{action:e,status:t,trackIds:i});(yield this._send(n,go.R2))===ho.REPORT_FAIL&&(null===(r=this._polarisSignalReporter)||void 0===r||r.sendR2(e,t,i))}))}}class Jo{constructor(e){this._room=e,this._audioLevelChangeHandler=null}audioLevelReport(e){if(!this._audioLevelChangeHandler)return;const t=[];e.forEach((e=>{const{userId:i}=Ct(e.trackId),r=this._room.getCrtUserId()===i?this._room.getLocalTrack(e.trackId):this._room.getRemoteTrack(e.trackId);r&&t.push({track:r,audioLevel:e.audioLevel||0})})),this._audioLevelChangeHandler(t)}onAudioLevelChange(e){this._audioLevelChangeHandler=e}}!function(e){e[e.ANCHOR=1]="ANCHOR",e[e.AUDIENCE=2]="AUDIENCE"}(vo||(vo={}));class Go{constructor(e=!1,t,i,r,n,o,s,a){this._useMutilPeerC=e,this._roomId=t,this._reTryExchange=i,this._currentUserId=r,this._polarisReport=n,this._isRoomAudience=o,this._initOptions=s,this._isAudience=a,this._mutilPeerC={}}get useMutilPeerC(){return this._useMutilPeerC}_isPub(e){if(this._isAudience)return!1;if(!this._useMutilPeerC)return!0;if(!e.length)return!1;const{track:t}=e[0]instanceof rt||e[0]instanceof ht?{track:e[0]}:e[0];return t.isLocalTrack()}_groupTracksByTag(e){const t={};return e.forEach((e=>{const{track:i}=e instanceof rt?{track:e}:e,r=i.getTag();t[r]?t[r].push(e):t[r]=[e]})),t}_genPCName(e,t){let i=null;return i=e?this._useMutilPeerC?`${this._roomId}_${t}`:`${this._roomId}_pub`:`${this._roomId}_sub`,i}_createOnePeerCItem(e,t){if(this._mutilPeerC[e]&&!this._mutilPeerC[e].pc.isDestroyed())this._mutilPeerC[e].tracks=t;else{const i=this._isPub(t),r=new Bo(e,(()=>this._reTryExchange(e,i)),this._currentUserId,this._polarisReport,this.onTrackTrouble,this._store,this._isRoomAudience,this._initOptions);this._mutilPeerC[e]={pc:r,tracks:t,isPub:i}}return Object.assign(Object.assign({},this._mutilPeerC[e]),{pcName:e})}createPeerCList(e){const t=[],i=this._isPub(e);if(!this._useMutilPeerC||this._useMutilPeerC&&!i){const r=this._genPCName(i);return t.push(this._createOnePeerCItem(r,e)),t}const r=this._groupTracksByTag(e);for(const e in r){const n=this._genPCName(i,e),o=r[e];t.push(this._createOnePeerCItem(n,o))}return t}_removeAllLocalTrack(){this.getPCList().forEach((e=>e.removeAllLocalTrack()))}destroyPeerC(e){this._mutilPeerC[e].pc.destroy()}_destroyAllPeerC(){this.getPCList().forEach((e=>e.destroy()))}getPCItemByPCName(e){return this._mutilPeerC[e]}getPCByTrackId(e,t=!0){const{tag:i}=Ct(e),r=this._genPCName(t,i);return this._mutilPeerC[r].pc}getPCList(){const e=[];for(const t in this._mutilPeerC)e.push(this._mutilPeerC[t].pc);return e}getMutilPeerCData(){return this._mutilPeerC}setPeerCData(e,t,i){}clear(){this._removeAllLocalTrack(),this._destroyAllPeerC()}setStore(e){this._store=e}}!function(e){e.UNPUBLISH_PREV="UnpublishPrevCommand",e.PULL_RTCROOM_STATUS="PullRTCRoomStatusCommand",e.JOINROOM="JoinRoomCommand",e.PARSE_REMOTERES="ParseRemoteResCommand",e.PARSE_USERSTATE="ParseUserStateCommand",e.LOCAL_TRACK_MUTE="LocalTrackMuteCommand",e.PUBLISH="PublishCommand",e.RETRY_EXCHANGE="RetryExchangeCommand",e.UNPUBLISH="UnpublishCommand",e.SUBSCRIBE="SubscribeCommand",e.ASYNC_COMMAND="AsyncCommand",e.UNSUBSCRIBE="UnsubscribeCommand",e.UPDATE_SUBSCRIBE_LIST="UpdateSubscribeListCommand",e.ON_SIGNAL_RECONNECTED="OnSignalReconnectedCommand",e.LEAVE_OTHER_ROOM="LeaveOtherRoomCommand",e.RTC_IDENTITY_CHANGE="RTCIdentityChangeCommand",e.ENABLE_INNER_CDN="EnableInnerCDNCommand",e.EXCHANGE_WITH_PUSH_OTHER_ROOM="ExchangeWithPushOtherRoomCommand",e.MCUCONFIG_FLUSH="MCUConfigFlushCommand",e.UNKNOWN="Unknown"}(po||(po={})),function(e){e.NORMAL="normal",e.MIDDLE="middle",e.TAIL="tail"}(Ro||(Ro={})),function(e){e[e.LOW=0]="LOW",e[e.NORMAL=1]="NORMAL",e[e.HIGH=2]="HIGH"}(mo||(mo={})),function(e){e[e.Destroy=40400]="Destroy"}(Io||(Io={}));class Ho{get priority(){return mo.LOW}get kind(){return po.UNKNOWN}}class Ko extends Ho{constructor(e=Ro.NORMAL){super(),this.state=e}get kind(){return po.ASYNC_COMMAND}setState(e){this.state=e}pickoutSubscribed(e,t){const{unsubscribe:i,subscribe:r}=this.calcSubscribeList(e,t);return Ko.AsyncSubscribeTasks=[],Ko.AsyncUnsubscribeTasks=[],Ko.AsyncUpdateSubscribeTasks=[],{subscribe:r,unsubscribe:i}}calcSubscribeList(e,t){const i=[],r=new Set,n=[],o=new Set,s=this.formateTrack(e),a=this.formateTrack(t);return a.forEach((e=>{const t=`${e.track.getTrackId()}_SUB_${e.subTiny?"0":"1"}`;this.trackInSubscribeList(e,s)||r.has(t)||(i.push(e),r.add(t))})),s.forEach((e=>{const t=`${e.track.getTrackId()}_SUB_${e.subTiny?"0":"1"}`;this.trackInSubscribeList(e,a)||o.has(t)||(n.push(e),o.add(t))})),{unsubscribe:i,subscribe:n}}formateTrack(e){return e.map((e=>e instanceof ht?{track:e,subTiny:!1}:Object.assign({subTiny:!1},e)))}trackInSubscribeList(e,t){if(0===t.length)return!1;return t.findIndex((t=>t.track.getTrackId()===e.track.getTrackId()&&t.subTiny===e.subTiny))>-1}}Ko.AsyncSubscribeTasks=[],Ko.AsyncUnsubscribeTasks=[],Ko.AsyncUpdateSubscribeTasks=[];class jo{constructor(e,t,i,r,n,o,s,a,c){this.context=e,this.service=t,this.peerMgr=i,this.roomId=r,this.crtUserId=n,this.roomMode=o,this.polarisReport=s,this.isUpgrade=a,this.isMainRoom=c,this._roomResources={},this._remoteTracks={},this._subscribedList=[],this._collectSubscribeList=[],this._CDNUris=null,this._CDNEnable=!1,this._destroyed=!1,this._trackIdSSRCMap=new Map,this._roomStatusVersion=0}get useMutilPeerC(){return this.peerMgr.useMutilPeerC}getResourcesByUserId(e){return this._roomResources[e]}getRemoteTrack(e){return this._remoteTracks[e]}getRemoteTracksByUserId(e){const t=[];for(const i in this._remoteTracks){const r=this._remoteTracks[i];r.getUserId()===e&&t.push(r)}return t}getRemoteTracks(){return this._remoteTracks}getSessionId(){return this._sessionId}getAllUserIds(){return Object.keys(this._roomResources)}getRemoteUserIds(){return this.getAllUserIds().filter((e=>e!==this.crtUserId))}getSubscribedList(){return this._subscribedList}getCollectSubscribeList(){return this._collectSubscribeList}getPublishedResourceByTrackId(e){const{userId:t}=Ct(e);return this._roomResources[t].find((t=>ft(t)===e))}getToken(){return this._token}getLocalTrack(e){return this.peerMgr.getPCByTrackId(e).getLocalTrack(e)}getLocalTracks(){const e=[];return this.peerMgr.getPCList().forEach((t=>{e.push(...t.getLocalTracks())})),e}getTrackState(e){var t;return(null===(t=this.getLocalTrack(e))||void 0===t?void 0:t.isLocalMuted())?0:1}getCDNEnable(){return this._CDNEnable}getCDNUris(){return this._CDNUris}getRoomStatusVersion(){return this._roomStatusVersion}getTrackIdBySSRC(e){return this._trackIdSSRCMap.get(e)}}class $o extends jo{_updateTrackIdSSRCMap(){Object.values(this._roomResources).forEach((e=>{e.forEach((e=>{const{ssrc:t,resourceId:i}=JSON.parse(e.uri);this._trackIdSSRCMap.set(t,i)}))}))}setTrackIdSSRCMap(e,t){this._trackIdSSRCMap.set(e,t)}_initRemoteTracks(){for(const e in this._roomResources){const t=this._roomResources[e];e!==this.crtUserId&&0!==t.length&&t.forEach((e=>{const t=ft(e),{tag:i,userId:r,mediaType:n}=Ct(t),o=n===Je.AUDIO_ONLY?new gt(i,r):new vt(i,r);o.__innerSetRemoteMuted(0===e.state),this._remoteTracks[t]=o}))}}initWithRoomData(e,t){this._sessionId=e.sessionId,this._token=e.token,this._roomStatusVersion=Ft(e.version),this._roomResources=Bt(e,this.roomId,t),this._updateTrackIdSSRCMap(),this._initRemoteTracks(),this.setResourcesByUserId(this.crtUserId,this.getResourcesByUserId(this.crtUserId)||[]);const i=We.getLogger();null==i||i.info(f.L_PARSE_ROOMDATA_URIS_R,`room data -> ${JSON.stringify(this._roomResources)}`,t)}assignRoomData(e){Object.assign(this._roomResources,e),this._updateTrackIdSSRCMap()}setResourcesByUserId(e,t){this._roomResources[e]=t,this._updateTrackIdSSRCMap()}removeRemoteTrack(e){delete this._remoteTracks[e]}removeResourcesByUserId(e){delete this._roomResources[e],this._updateTrackIdSSRCMap()}addRemoteTrack(e){this._remoteTracks[e.getTrackId()]=e}removeRemoteTracks(){const e=Object.values(this._remoteTracks);e.length&&(e.forEach((e=>{e.isAudioTrack()&&e.__releaseMediaElement()})),this._remoteTracks={})}setCDNEnabel(e){this._CDNEnable=e}setCDNUris(e){this._CDNUris=e}resetSubscribedList(e){this._subscribedList.splice(0,this._subscribedList.length,...e),this.resetCollectSubscribeList(e)}resetCollectSubscribeList(e){this._collectSubscribeList.splice(0,this._collectSubscribeList.length,...e)}setRoomStatusVersion(e){this._roomStatusVersion=Ft(e)}}class Wo{constructor(e,t,i){this.context=e,this._store=t,this.abortCode=i,this._queue=[],this._busy=!1,this._isDestroyed=!1}_next(){this._busy=!1,this._execute()}_execute(){var e,t,i,r;return S(this,void 0,void 0,(function*(){if(this._isDestroyed||this._busy||0===this._queue.length)return;this._busy=!0;const{command:n,resolve:o,reject:s}=this._queue.shift();let a;const c=this._queue.map((e=>{var t;return null===(t=null==e?void 0:e.command)||void 0===t?void 0:t.kind})),d=null===(e=this.context.logger)||void 0===e?void 0:e.createTraceId();try{null===(t=this.context.logger)||void 0===t||t.info(f.L_INVOKER_EXECUTE_T,`commandKind: ${n.kind}, kinds:${c.join(",")}, length: ${this._queue.length}`,d),a=yield n.execute(this._store,this)}catch(e){return null===(i=this.context.logger)||void 0===i||i.error(f.L_INVOKER_EXECUTE_R,JSON.stringify({error:e,status:C.FAILED,commandKind:n.kind,kinds:c.join(",")}),d),s(e),void this._next()}null===(r=this.context.logger)||void 0===r||r.info(f.L_INVOKER_EXECUTE_R,`status: ${C.SUCCESSED}, commandKind: ${n.kind}`,d),o(a),this._next()}))}push(e){return new Promise(((t,i)=>{var r;if(null===(r=this.context.logger)||void 0===r||r.info(f.L_INVOKER_PUSH_O,JSON.stringify({isDestroyed:this._isDestroyed,commandKind:e.kind,length:this._queue.length})),this._isDestroyed)return void i({code:T.NOT_IN_ROOM});const{kind:n}=e;this._queue.length>0&&n===po.ASYNC_COMMAND&&({command:e,resolve:t,reject:i}=this.commandOffset(e,t,i));const{priority:o}=e;if(o===mo.LOW)this._queue.push({command:e,resolve:t,reject:i});else{const r=this._queue.findIndex((e=>e.command.priority<o)),n=-1===r?this._queue.length-1:r;this._queue.splice(n,0,{command:e,resolve:t,reject:i})}Promise.resolve().then((()=>{this._execute()}))}))}commandOffset(e,t,i){const r=this._queue.length-1;if(!(this._queue[r].command.kind===po.ASYNC_COMMAND))return{command:e,resolve:t,reject:i};const[n]=this._queue.splice(r,1);n.command instanceof Ko&&(n.command.setState(Ro.MIDDLE),e instanceof Ko&&e.setState(Ro.TAIL));const o=e.execute;return e.execute=function(t,i){return S(this,void 0,void 0,(function*(){return n.command.execute.call(n.command,t,i),o.call(e,t,i)}))},{command:e,resolve:e=>{n.resolve.call(n,e),t(e)},reject:e=>{n.reject.call(n,e),i(e)}}}isDestroyed(){var e;return null===(e=this.context.logger)||void 0===e||e.info(f.L_INVOKER_DESTROY_O,JSON.stringify({isDestroyed:this._isDestroyed})),this._isDestroyed}destroy(){var e;null===(e=this.context.logger)||void 0===e||e.info(f.L_INVOKER_DESTROY_O,JSON.stringify({isDestroyed:this._isDestroyed})),this._isDestroyed||(this._isDestroyed=!0,this._queue.forEach((e=>{e.resolve({code:this.abortCode})})),this._queue.length=0)}}class Yo extends Wo{constructor(e,t,i,r,n,o,s,a,c){super(e,new $o(e,t,i,r,n,o,s,a,c),T.ROOM_HAS_BEEN_DESTROYED)}get store(){return this._store}destroy(){super.destroy(),this._store.removeRemoteTracks()}}class qo extends Ho{get kind(){return po.UNPUBLISH_PREV}execute(e){var t,i,r,o,s,a,c,d;return S(this,void 0,void 0,(function*(){const _=e.getResourcesByUserId(e.crtUserId),l=_.slice();_.length=0;const u=null===(i=null===(t=e.context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();null===(o=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===o||o.info(f.L_UNPUBLISH_PREV_COMMAND_T,JSON.stringify({resource:l}),u);const h=yield e.context.setRTCTotalRes(e.roomId,[pt(Jt.UNPUBLISH,l)],Rt([]),Jt.TOTAL_CONTENT_RESOURCE,Rt([]));h!==n.SUCCESS?null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_UNPUBLISH_PREV_COMMAND_R,JSON.stringify({status:C.FAILED,code:h}),u):null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_UNPUBLISH_PREV_COMMAND_R,JSON.stringify({status:C.SUCCESSED}),u)}))}}!function(e){e[e.RTC=0]="RTC",e[e.LIVE=2]="LIVE",e[e.CROSS_MUTI=7]="CROSS_MUTI",e[e.CROSS_LIVE=8]="CROSS_LIVE",e[e.SIP=4]="SIP",e[e.CALL=5]="CALL",e[e.MEETING=6]="MEETING"}(Eo||(Eo={}));class zo extends Ho{constructor(e,t,i,r,n,o,s,a,c){super(),this.roomId=e,this.roomType=t,this.context=i,this.joinType=r,this.livingType=n,this.innerUserDatas=o,this.outerUserDatas=s,this.traceId=a,this._reportMediaActionLogger=c}get kind(){return po.JOINROOM}execute(e,t){var o,s,c,d,u,h,g,v,p,R,m,I,E,O,L,N,A,y,k,D;return S(this,void 0,void 0,(function*(){const S=Date.now(),{context:b,service:U}=e;let P=f.L_RTC_CLIENT_JOIN_RTC_ROOM_R;if(this.roomType===Eo.LIVE?P=f.L_RTC_CLIENT_JOIN_LIVING_ROOM_R:this.roomType===Eo.CROSS_MUTI&&(P=f.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_R),b.getConnectionStatus()!==a.CONNECTED)return null===(s=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===s||s.error(P,JSON.stringify({status:C.FAILED,code:T.SIGNAL_DISCONNECTED,msg:"im not connected"}),this.traceId),{code:T.SIGNAL_DISCONNECTED};if(U.detectorMediaSever(),wt(b.getNaviInfo()))return null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(P,JSON.stringify({status:C.FAILED,code:T.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"}),this.traceId),{code:T.PACKAGE_ENVIRONMENT_ERROR};if(!i("roomId",this.roomId,_,!0))return null===(h=null===(u=e.context)||void 0===u?void 0:u.logger)||void 0===h||h.error(P,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> roomId"}),this.traceId),{code:T.PARAMS_ERROR};if(!i("roomType",this.roomType,(e=>void 0!==Eo[e])))return null===(v=null===(g=e.context)||void 0===g?void 0:g.logger)||void 0===v||v.error(P,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> roomType"}),this.traceId),{code:T.PARAMS_ERROR};if(!i("outerUserDatas",this.outerUserDatas,r,!1))return null===(R=null===(p=e.context)||void 0===p?void 0:p.logger)||void 0===R||R.error(P,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> outerUserDatas"}),this.traceId),{code:T.PARAMS_ERROR};if(this.outerUserDatas){if(!Object.keys(this.outerUserDatas).every((e=>i(`outerUserDatas.${e}`,this.outerUserDatas[e],l,!0))))return null===(I=null===(m=e.context)||void 0===m?void 0:m.logger)||void 0===I||I.error(P,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> outerUserDatas"}),this.traceId),{code:T.PARAMS_ERROR}}if(!U.getNaviMS().length)return null===(O=null===(E=e.context)||void 0===E?void 0:E.logger)||void 0===O||O.error(P,JSON.stringify({status:C.FAILED,code:T.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"No audio / video server address available"}),this.traceId),{code:T.NOT_OPEN_VIDEO_AUDIO_SERVER};const{code:M,data:x}=yield b.joinRTCRoom(this.roomId,this.roomType,this.livingType,this.joinType,this.innerUserDatas,this.outerUserDatas);if(null===(L=this._reportMediaActionLogger)||void 0===L||L.reportQualityJoinRoomData(S,M,this.roomType,null==x?void 0:x.sessionId),M!==n.SUCCESS||!x){const t=40032===M?T.SIGNAL_JOIN_RTC_ROOM_REFUSED:M;return null===(A=null===(N=e.context)||void 0===N?void 0:N.logger)||void 0===A||A.error(P,JSON.stringify({status:C.FAILED,code:t,msg:"joinRoom failed"}),this.traceId),{code:t}}e.initWithRoomData(x,this.traceId);e.getResourcesByUserId(e.crtUserId).length>0&&t.push(new qo);const w=null===(y=x.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===y?void 0:y.value;return w&&e.setCDNUris(JSON.parse(w)[0]),null===(D=null===(k=e.context)||void 0===k?void 0:k.logger)||void 0===D||D.info(P,JSON.stringify({status:C.SUCCESSED,userId:e.crtUserId,roomId:this.roomId}),this.traceId),{code:T.SUCCESS,data:x}}))}}!function(e){e[e.ROOM=1]="ROOM",e[e.PERSON=2]="PERSON"}(So||(So={})),function(e){e.PUBLISH="publish",e.SUBSCRIBE="subscribe"}(To||(To={})),function(e){e.BEGIN="begin",e.END="end"}(fo||(fo={})),function(e){e[e.SPREAD=0]="SPREAD",e[e.NO_SPREAD=-1]="NO_SPREAD"}(Co||(Co={}));class Qo extends Ho{constructor(e,t,i,r){super(),this.headers=e,this.reqBody=t,this.traceId=i,this.isNeedUpdateMsas=r}execute(e,t){var i,r;return S(this,void 0,void 0,(function*(){const t=yield e.service.exchange(this.headers,this.reqBody,this.traceId,this.isNeedUpdateMsas);if(e.roomMode!==Eo.LIVE)return t;const n=null===(r=null===(i=t.data)||void 0===i?void 0:i.urls)||void 0===r?void 0:r.pull_url;if(t.code!==T.SUCCESS||!n)return t;const o=JSON.parse(n);if(e.setCDNUris(o),(null==o?void 0:o.broadcast)===Co.SPREAD){e.setCDNEnabel(!0);const t=Object.assign(Object.assign({},o),{enableInnerCDN:!0});rs(e.context,e.roomId,t)}return t}))}}!function(e){e.PUB="pub",e.UNPUB="unpub",e.SUB="sub",e.UNSUB="unsub"}(Oo||(Oo={}));class Zo extends Ho{constructor(e,t,i,r,n,o=Oo.SUB,s){super(),this.tracks=e,this.subhook=t,this.forceReq=i,this.traceId=r,this._reportMediaActionLogger=n,this.fromCommand=o,this.unsubTracks=s,this._actionStartTime=Date.now(),this._trackMediaMap={}}get kind(){return po.UPDATE_SUBSCRIBE_LIST}execute(e,t){var r,n,o,a,c,d,_,l,u,h,g,v,p,R,m,I,E,O;return S(this,void 0,void 0,(function*(){this._actionStartTime=Date.now();const{tracks:S,forceReq:L}=this,{roomId:N}=e;if(null===(n=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_UPDATE_SUBSCRIBELIST_COMMAND_T,`roomId: ${N}, forceReq: ${L}, trackIds: ${S.map(Vt)}`,this.traceId),!i("tracks",S,(()=>s(S)&&S.every((e=>e instanceof ht||e.track instanceof ht))),!0))return null===(a=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===a||a.warn(f.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"tracks is invalid"}),this.traceId),{code:T.PARAMS_ERROR};let A=S.map((e=>e instanceof ht?{track:e}:Object.assign({},e)));const y={};A=A.filter((t=>{var i,r;const n=t.track.getTrackId();return e.getRemoteTrack(n)?!y[n]&&(y[n]=!0,!0):(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(f.L_UPDATE_SUBSCRIBELIST_COMMAND_P,`track cannot found in room -> trackId: ${n}`,this.traceId),!1)})).map((e=>Object.assign({},e)));const k=e.getSubscribedList().map((e=>Object.assign({},e)));if(!L){let t=!1;if(A.forEach((e=>{const i=k.findIndex((t=>t.track===e.track));if(-1===i)return void(t=!0);k.splice(i,1)[0].subTiny!==e.subTiny&&(t=!0)})),k.length){t=!0;const i=k.map((e=>e.track));null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.warn(f.L_CLEAR_UNSUBSCRIBE_LIST_O,JSON.stringify({list:i.map((e=>e.getTrackId()))}),this.traceId);const r=e.getSubscribedList().filter((e=>!i.includes(e.track)));e.resetSubscribedList(r)}if(!t)return null===(l=null===(_=e.context)||void 0===_?void 0:_.logger)||void 0===l||l.warn(f.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:C.SUCCESSED,msg:"subscribe list unchanged"}),this.traceId),{code:T.SUCCESS}}const{pc:D,pushOtherRooms:b,headers:U}=this.subhook(S);D.updateSubRemoteTracks(A.map((e=>e.track)));const P=yield ts(A,!1,D,e);b&&(P.pushOtherRooms=b);const M=yield new Qo(U,P,this.traceId,!0).execute(e,t);S.forEach((e=>{const t=e instanceof ht?e.getTrackId():e.track.getTrackId();this._trackMediaMap[t]=M.qualityMsList||[]})),A.map((e=>e.track.getTrackId()));const x=this.fromCommand===Oo.SUB?S:this.unsubTracks;if(M.code!==T.SUCCESS)return(null==x?void 0:x.length)&&(null===(u=this._reportMediaActionLogger)||void 0===u||u.reportPubOrSubQualityData(this.fromCommand,this._actionStartTime,x,M.code,this._trackMediaMap)),null===(g=null===(h=e.context)||void 0===h?void 0:h.logger)||void 0===g||g.error(f.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:C.FAILED,code:M.code}),this.traceId),{code:M.code};const{sdp:w,resultCode:B,message:V,subscribedList:F}=M.data;if(B!==T.SUCCESS)return(null==x?void 0:x.length)&&(null===(v=this._reportMediaActionLogger)||void 0===v||v.reportPubOrSubQualityData(this.fromCommand,this._actionStartTime,x,B,this._trackMediaMap)),null===(R=null===(p=e.context)||void 0===p?void 0:p.logger)||void 0===R||R.error(f.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:C.FAILED,code:B}),this.traceId),{code:B};null===(m=this._reportMediaActionLogger)||void 0===m||m.setPubOrSubSuccessTime(Date.now());const J=yield D.setRemoteAnswer(w.sdp);if((null==x?void 0:x.length)&&(null===(I=this._reportMediaActionLogger)||void 0===I||I.reportPubOrSubQualityData(this.fromCommand,this._actionStartTime,x,J,this._trackMediaMap)),J!==T.SUCCESS)return{code:J};Lo.formatSourceIdMapFromSdp(w.sdp,"subscribe");const G=null==F?void 0:F.map((e=>`${e.msid}_${e.mediaType}`)),H=A.filter((e=>null==G?void 0:G.includes(e.track.getTrackId()))),K=A.filter((e=>!(null==G?void 0:G.includes(e.track.getTrackId()))));null===(O=null===(E=e.context)||void 0===E?void 0:E.logger)||void 0===O||O.info(f.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.SUCCESSED,subSuccessTrackIds:G,failedList:K}),this.traceId);const j=e.getRemoteTracks();for(const e in j){const t=H.some((t=>t.track.getTrackId()===e));j[e].__innerSetSubscribed(t);const i=H.some((t=>t.track.getTrackId()===e&&t.subTiny));j[e].isVideoTrack()&&j[e].__innerSetIsTinyTrack(i)}return e.resetSubscribedList(H),K.length?{code:T.SUCCESS,failedList:K}:{code:T.SUCCESS}}))}}class Xo extends Ho{constructor(e,t,i,r){super(),this.tracks=e,this.subhook=t,this.traceId=i,this._reportMediaActionLogger=r}get kind(){return po.UNSUBSCRIBE}execute(e,t){var r,n,o,a;return S(this,void 0,void 0,(function*(){const{tracks:c}=this;if(null===(n=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_ABSTRACT_ROOM_UNSUBSCRIBE_T,JSON.stringify({unSubscribeTrackIds:c.map(Vt)}),this.traceId),!i("tracks",c,(()=>s(c)&&c.length>0&&c.every((e=>e instanceof ht))),!0))return null===(a=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===a||a.warn(f.L_ABSTRACT_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:T.PARAMS_ERROR};const d=e.getSubscribedList().map((e=>Object.assign({},e))).filter((e=>!c.includes(e.track)));return e.polarisReport.sendR2(To.SUBSCRIBE,fo.END,c.map((e=>e.getTrackId()))),new Zo(d,this.subhook,!1,this.traceId,this._reportMediaActionLogger,Oo.UNSUB,this.tracks).execute(e,t)}))}}class es extends Ho{constructor(e,t,i){super(),this.subhook=e,this.tracks=t,this.onTrackUnpublish=i}execute(e,t){var i,r;return S(this,void 0,void 0,(function*(){const{tracks:n}=this,o=null===(i=e.context.logger)||void 0===i?void 0:i.createTraceId();null===(r=e.context.logger)||void 0===r||r.info(f.L_USER_LEFT_UNSUBSCRIBE_O,void 0,o),yield new Xo(n,this.subhook,o).execute(e,t),n.forEach((t=>{t.__innerDestroy(),e.removeRemoteTrack(t.getTrackId())})),this.onTrackUnpublish(n)}))}}function ts(e,t,i,r){return S(this,void 0,void 0,(function*(){return{sdp:yield i.createOffer(t),extend:JSON.stringify({resolutionInfo:i.getOutboundVideoInfo()}),subscribeList:e.filter((e=>{const t=e.track.getTrackId(),{userId:i}=Ct(t),n=r.getResourcesByUserId(i);if(!n)return!1;const o=n.filter((e=>t===`${e.msid}_${e.mediaType}`)).length;return o})).map((e=>({simulcast:e.subTiny?Xn.TINY:Xn.NORMAL,resolution:"",uri:r.getPublishedResourceByTrackId(e.track.getTrackId()).uri}))),switchstream:!1}}))}function is(e,t,i){var r,o,s,a;return S(this,void 0,void 0,(function*(){const c=null===(r=null==e?void 0:e.logger)||void 0===r?void 0:r.createTraceId();null===(o=null==e?void 0:e.logger)||void 0===o||o.info(f.L_LIVING_ROOM_SPREAD_CDN_INFO_T,JSON.stringify({CDNUris:i}),c);const d=yield e.setRTCCDNUris(t,Jt.TOTAL_CONTENT_RESOURCE,JSON.stringify([i]));return d!==n.SUCCESS?(null===(s=null==e?void 0:e.logger)||void 0===s||s.error(f.L_LIVING_ROOM_SPREAD_CDN_INFO_R,`status: ${C.FAILED}, code: ${d}`,c),{code:T.SIGNAL_ERROR}):(null===(a=null==e?void 0:e.logger)||void 0===a||a.info(f.L_LIVING_ROOM_SPREAD_CDN_INFO_R,`status: ${C.SUCCESSED}`,c),{code:T.SUCCESS})}))}function rs(e,t,i){var r,o,s,a;return S(this,void 0,void 0,(function*(){const c=null===(r=null==e?void 0:e.logger)||void 0===r?void 0:r.createTraceId();null===(o=null==e?void 0:e.logger)||void 0===o||o.info(f.L_LIVING_ROOM_SET_ROOM_CDN_INFO_T,`CDNUris: ${i}`,c);const d=yield e.setRTCData(t,"cdn_uris",JSON.stringify([i]),!0,So.ROOM);return d!==n.SUCCESS?(null===(s=null==e?void 0:e.logger)||void 0===s||s.error(f.L_LIVING_ROOM_SET_ROOM_CDN_INFO_R,`status: ${C.FAILED}, code: ${d}`,c),{code:T.SIGNAL_ERROR}):(null===(a=null==e?void 0:e.logger)||void 0===a||a.info(f.L_LIVING_ROOM_SET_ROOM_CDN_INFO_R,`status: ${C.SUCCESSED}`,c),{code:T.SUCCESS})}))}function ns(e){return S(this,void 0,void 0,(function*(){const{context:t}=e,{roomId:i}=e,r=Object.assign({},e.getCDNUris(),{enableInnerCDN:e.getCDNEnable()});return(yield Promise.all([is(t,i,r),rs(t,i,r)])).every((e=>e.code===T.SUCCESS))?{code:T.SUCCESS}:{code:T.SIGNAL_ERROR}}))}function os(e,t,i,r,n,o,s){return S(this,void 0,void 0,(function*(){const{roomId:a,crtUserId:c,roomMode:d}=t,_=[],l={},h={},g={},v=Bt(e,a,s),p=Object.keys(v),R=t.getAllUserIds();for(let e=p.length-1;e>=0;e-=1){const i=p[e],r=R.indexOf(i);if(-1===r){_.push(i),l[i]=Lt(v[i]);continue}const n=t.getResourcesByUserId(i),o=v[i],{publishedList:s,modifiedList:a,unpublishedList:c}=Nt(n,o,!0);l[i]=Lt(s),h[i]=Lt(c),g[i]=Lt(a),R.splice(r,1)}R.length&&R.forEach((e=>{t.removeResourcesByUserId(e)})),t.assignRoomData(v),R.length&&(yield ss(R,t,n,r,s),i.onUserLeave(R)),_.length&&i.onUserJoin(_);for(const e in h){if(e===c)continue;const o=h[e];if(o.length){const e=o.map((e=>t.getRemoteTrack(ft(e))));yield new es(n,e,i.onTrackUnpublish).execute(t,r)}}Object.keys(l).forEach((e=>{const r=l[e];if(0===r.length)return;const n=r.map((e=>{const i=ft(e),{userId:r,tag:n,mediaType:o}=Ct(i),s=o===Je.AUDIO_ONLY?new gt(n,r):new vt(n,r);return t.addRemoteTrack(s),s.__innerSetRemoteMuted(0===e.state),s}));i.onTrackPublish(n)})),Object.keys(g).forEach((e=>{g[e].forEach((e=>{const r=ft(e),n=t.getRemoteTrack(r);n.__innerSetRemoteMuted(0===e.state),n.isAudioTrack()?i.onAudioMuteChange(n):i.onVideoMuteChange(n)}))})),d===u.LIVE&&function(e,t,i){var r,n,o;if(!i)return void(null===(n=null===(r=t.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_LIVING_ROOM_RECONNECTED_R,JSON.stringify({status:C.FAILED,code:"",msg:"cdn_uris not found"})));const s=JSON.parse(i),a=(null===(o=t.getCDNUris())||void 0===o?void 0:o.enableInnerCDN)!==s.enableInnerCDN;t.setCDNUris(s),a&&e.onCDNEnableChange(s.enableInnerCDN)}(i,t,o)}))}function ss(e,t,i,r,n){var o;return S(this,void 0,void 0,(function*(){const s=[],a=[];e.forEach((e=>{s.push(...t.getRemoteTracksByUserId(e)),a.push(e)})),s.length&&(null===(o=t.context.logger)||void 0===o||o.info(f.L_RES_UNPUB_UNSUBSCRIBE_O,void 0,n),yield new Xo(s,i,n).execute(t,r),s.forEach((e=>t.removeRemoteTrack(e.getTrackId())))),a.length&&a.forEach((e=>t.removeResourcesByUserId(e)))}))}function as(e){var t;const{userId:i,userData:r,event:n,switchRoleType:o}=e;return{users:[{userId:i,extra:null===(t=r.filter((e=>"extra"===e.key))[0])||void 0===t?void 0:t.value,state:n,switchRoleType:o}]}}const cs=e=>e.some((e=>"uris"===e.key||"cdn_uris"===e.key));function ds(e){var t,i;const{userId:r,userData:n}=e;if(!cs(n))return;const o=null===(t=n.filter((e=>"uris"===e.key))[0])||void 0===t?void 0:t.value,s=null===(i=n.filter((e=>"cdn_uris"===e.key))[0])||void 0===i?void 0:i.value;return{userId:r,content:{uris:o?JSON.parse(o):[],cdn_uris:s&&JSON.parse(s)}}}const _s=(e,t,i)=>{const r=e.split("\r\nm"),n=i===Je.AUDIO_ONLY?"audio":"video",o=r.filter((e=>e.includes(`=${n}`)&&e.includes(t)))[0];let s=new RegExp(`a=ssrc:(.*?) msid:${t}`);const a=o.match(s);return a?a[1]:""};class ls extends Ho{constructor(e,t,i){super(),this.msgContent=e,this.subhook=t,this.traceId=i}get kind(){return po.PARSE_USERSTATE}get priority(){return mo.NORMAL}execute(e,t){return S(this,void 0,void 0,(function*(){const i=[],r=[],n=[],o=[],s={joined:i,left:r,upgrade:n,downgrade:o},{users:a}=this.msgContent;if(0===a.length)return s;for(let t=0;t<a.length;t++){const i=a[t];if(i.extra&&i.extra.roomId!==e.roomId)return s;if(1===Number(i.state)&&!e.getRemoteUserIds().includes(i.userId))return s}a.forEach((t=>{var s,a,c,d;const{userId:_}=t;if(0===Number(t.state)){const r=e.getResourcesByUserId(_);r||(t.switchRoleType?n.push(_):i.push(_),null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_PARSE_USERSTATE_COMMAND_R,JSON.stringify({userId:_,msg:"user "+(t.switchRoleType?"upgrade":"joined")}),this.traceId)),e.setResourcesByUserId(_,r||[])}else null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_PARSE_USERSTATE_COMMAND_R,JSON.stringify({userId:_,msg:"user "+(t.switchRoleType?"downgrade":"left")}),this.traceId),t.switchRoleType?o.push(_):r.push(_)}));const c=[...r,...o];return c.length&&(yield ss(c,e,this.subhook,t,this.traceId)),s}))}}class us extends Ho{constructor(e,t,i,r,n,o,s,a){super(),this.msgContent=e,this.messageType=t,this.senderId=i,this.subhook=r,this.callback=n,this.traceId=o,this.sentTime=s,this._reportMediaActionLogger=a}get kind(){return po.PARSE_REMOTERES}get priority(){return mo.NORMAL}execute(e,t){var i,r,n,o,s;return S(this,void 0,void 0,(function*(){const{uris:a}=this.msgContent,c=[],d=[],_=[];let l;const u=this.senderId,{messageType:h}=this;if(!e.getRemoteUserIds().includes(u))return;const g=e.getResourcesByUserId(u)||[];switch(h){case Jt.MODIFY:_.push(...a);break;case Jt.PUBLISH:c.push(...a);break;case Jt.UNPUBLISH:d.push(...a);break;case Jt.TOTAL_CONTENT_RESOURCE:l=Nt(g,a),c.push(...l.publishedList),d.push(...l.unpublishedList),_.push(...l.modifiedList)}if(c.length>0){const o=g.map(ft),s=[],a=[];if(c.forEach((t=>{const i=ft(t),r=o.indexOf(i),{userId:n,tag:c,mediaType:d}=Ct(i);r>-1?g[r]=t:g.push(t);let _=e.getRemoteTrack(i);_?_.isSubscribed()&&s.push(_):(_=d===Je.AUDIO_ONLY?new gt(c,n):new vt(c,n),e.addRemoteTrack(_),a.push(_)),_.__innerSetRemoteMuted(0===t.state)})),s.length){const n=s.map((e=>e.getTrackId())),{code:o}=yield new Zo(s,this.subhook,!0,this.traceId).execute(e,t);o!==T.SUCCESS&&(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RESUB_REPUB_RES_R,JSON.stringify({status:C.FAILED,trackIds:n,code:o}),this.traceId))}this.callback.onTrackPublish(a),null===(n=this._reportMediaActionLogger)||void 0===n||n.reportQualityRecvPubMsgData(this.sentTime,this.senderId)}if(d.length>0){const i=d.map(ft);for(let e=g.length-1;e>=0;e-=1){const t=g[e];i.includes(ft(t))&&g.splice(e,1)}const r=d.map((t=>{const i=ft(t);return e.getRemoteTrack(i)}));yield new es(this.subhook,r,this.callback.onTrackUnpublish).execute(e,t)}if(_.length>0){const t=g.map(ft);for(let i=0;i<_.length;i+=1){const r=_[i],n=ft(r),o=t.indexOf(n);g[o].state=r.state;const s=e.getRemoteTrack(n);s.__innerSetRemoteMuted(0===r.state),s.isAudioTrack()?this.callback.onAudioMuteChange(s):this.callback.onVideoMuteChange(s)}}if(e.setResourcesByUserId(u,g),e.roomMode!==Eo.LIVE)return;const v=this.msgContent;if(!v.cdn_uris)return;const p=(null===(o=e.getCDNUris())||void 0===o?void 0:o.enableInnerCDN)!==v.cdn_uris[0].enableInnerCDN;e.setCDNUris(v.cdn_uris[0]),p&&this.callback.onCDNEnableChange(!!(null===(s=e.getCDNUris())||void 0===s?void 0:s.enableInnerCDN))}))}}class hs extends Ho{constructor(e,t,i,r,n){super(),this.tracks=e,this.subhook=t,this.forceReq=i,this.traceId=r,this._reportMediaActionLogger=n}get kind(){return po.SUBSCRIBE}execute(e,t){var r,n,o,a,c,d;return S(this,void 0,void 0,(function*(){const{tracks:_,forceReq:l}=this;if(null===(n=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_ABSTRACT_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:_.map(Vt),forceReq:l}),this.traceId),!i("tracks",_,(()=>s(_)&&_.length>0&&_.every((e=>e instanceof ht||e.track instanceof ht))),!0))return null===(a=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===a||a.error(f.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:T.PARAMS_ERROR};const u=e.getSubscribedList().map((e=>Object.assign({},e))),h=_.map((e=>e instanceof ht?{track:e}:e));let g=!1;const v=[];return h.forEach((e=>{const t=e.track.getTrackId();v.push(t);const i=u.find((e=>e.track.getTrackId()===t));i&&i.subTiny===e.subTiny||(i?i.subTiny=e.subTiny:u.push(e),g=!0)})),g||l?(e.polarisReport.sendR2(To.SUBSCRIBE,fo.BEGIN,v),new Zo(u,this.subhook,!0,this.traceId,this._reportMediaActionLogger).execute(e,t)):(null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.warn(f.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.SUCCESSED,msg:"repeat subscribe"}),this.traceId),{code:T.SUCCESS})}))}}class gs extends Ho{constructor(e,t,i=3e4,r){var n;super(),this.tracks=e,this.pubhook=t,this.signalRetryTime=i,this._reportMediaActionLogger=r,this._logger=null,this._actionStartTime=Date.now(),this._trackMediaMap={},this._logger=We.getLogger(),this._traceId=null===(n=this._logger)||void 0===n?void 0:n.createTraceId()}get kind(){return po.PUBLISH}_removePubFailedTracks(e,t){e.forEach((e=>{var i;const r=e instanceof rt?e:e.track;null===(i=this._logger)||void 0===i||i.debug(f.L_ABSTRACT_ROOM_PUBLISH_P,`remove pub failed track from peerconnection -> trackId: ${r.getTrackId()}`,this._traceId),t.removeLocalTrackById(r.getTrackId())}))}__publish(e,t,i,r,n){var o,s,a,c,d,_,l,u,h,g;return S(this,void 0,void 0,(function*(){const{pcName:v,pc:p,headers:R}=t,{roomId:m}=e,I=[];i.forEach((e=>{const{track:t}=e instanceof rt?{track:e}:e;I.push(t)})),i.sort(((e,t)=>{const{track:i}=e instanceof rt?{track:e}:e,{max:r}=i.getBitrate(),{track:n}=t instanceof rt?{track:t}:t,{max:o}=n.getBitrate();return r-o}));if(p.getLocalTracks().length+((e,t)=>{let i=0;return e.forEach((e=>{const r=e instanceof rt?e.getTrackId():e.track.getTrackId();t.getLocalTrack(r)||(e instanceof rt?i++:e.pubTiny&&e.track.isVideoTrack()&&(i+=2))})),i})(i,p)>10)return null===(o=this._logger)||void 0===o||o.error(f.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:C.FAILED,code:T.PUBLISH_TRACK_LIMIT_EXCEEDED,trackIds:i.map(Vt),msg:`pcName: ${v} publish track limit exceeded`}),this._traceId),{code:T.PUBLISH_TRACK_LIMIT_EXCEEDED,tracks:I};null===(s=this._logger)||void 0===s||s.info(f.L_ABSTRACT_ROOM_PUBLISH_P,`publish tracks -> roomId: ${m}, tracks: ${i.map(Vt)}`,this._traceId);const E=[];for(let e=0;e<i.length;e++){const t=i[e],{track:r,pubTiny:n}=t instanceof rt?{pubTiny:!1,track:t}:t;if(r.isVideoTrack()&&n){let e;try{e=r.__innerGetMediaStreamTrack().clone();const t=n.frameRate||Ve.FPS_15,i=n.resolution||Fe.W176_H144,{width:o,height:s}=yt(i),a=bt(t);yield e.applyConstraints({width:o,height:s,frameRate:a})}catch(t){null==e||e.stop(),null===(a=this._logger)||void 0===a||a.warn(f.L_ABSTRACT_ROOM_PUBLISH_P,`pubTiny failed -> id: ${r.getTrackId()}, msg: ${t.message}`,this._traceId);break}const t=new ot(r.getTag(),r.getUserId(),e,!0);E.push(t),p.addLocalTrack(t)}p.addLocalTrack(r)}p.clearReTryExchangeTimer();const S=e.useMutilPeerC?[]:e.getSubscribedList(),O=yield ts(S,!1,p,e);r&&(O.pushOtherRooms=r),Lo.formatSourceIdMapFromSdp(O.sdp.sdp,"publish");const L=yield new Qo(R,O,this._traceId,!0).execute(e,n);if(I.forEach((e=>{const t=e.getTrackId();this._trackMediaMap[t]=L.qualityMsList||[]})),L.code!==T.SUCCESS)return null===(c=this._reportMediaActionLogger)||void 0===c||c.reportPubOrSubQualityData(Oo.PUB,this._actionStartTime,I,L.code,this._trackMediaMap),null===(d=this._logger)||void 0===d||d.error(f.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:C.FAILED,tracks:i.map(Vt),code:L.code,msg:"exchange failed"}),this._traceId),this._removePubFailedTracks(i,p),{code:L.code,tracks:I};const{sdp:N,resultCode:A,message:y}=L.data;if(A!==T.SUCCESS)return null===(_=this._reportMediaActionLogger)||void 0===_||_.reportPubOrSubQualityData(Oo.PUB,this._actionStartTime,I,A,this._trackMediaMap),null===(l=this._logger)||void 0===l||l.error(f.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:C.FAILED,trackIds:i.map(Vt),code:A,msg:`exchange inner failed: ${y}`}),this._traceId),this._removePubFailedTracks(i,p),{code:A,tracks:I};null===(u=this._reportMediaActionLogger)||void 0===u||u.setPubOrSubSuccessTime(Date.now());const k=yield p.setRemoteAnswer(N.sdp);return k!==T.SUCCESS?(null===(h=this._reportMediaActionLogger)||void 0===h||h.reportPubOrSubQualityData(Oo.PUB,this._actionStartTime,I,k,this._trackMediaMap),null===(g=this._logger)||void 0===g||g.error(f.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:C.FAILED,trackIds:i.map(Vt),code:k,msg:"set remote answer error"}),this._traceId),{code:k,tracks:I}):(E.length&&this._updateTinyTrackIdSSRCMap(e,O.sdp.sdp,E),Object.assign(Object.assign({},L),{tracks:I}))}))}_updateTinyTrackIdSSRCMap(e,t,i){i.forEach((i=>{const r=_s(t,i.getStreamId(),Je.VIDEO_ONLY);e.setTrackIdSSRCMap(Number(r),i.getTrackId())}))}_mergePublishRes(e,t){var i,r,o;return S(this,void 0,void 0,(function*(){const s=t.crtUserId,{roomId:a}=t;let c="";const d=[],_=[],l=t.getResourcesByUserId(s),u=[...l];let h=[];e.forEach((e=>{const{tracks:i}=e;if(e.code!==T.SUCCESS)return void d.push({code:e.code,tracks:i});_.push(...i);const{publishList:r,urls:n,mcuPublishList:o}=e.data;c=null==n?void 0:n.liveUrl;r.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:t.getTrackState(ft(e))},e))).forEach((e=>{const{isInclude:t,index:i}=((e,t)=>{let i=!1,r=0;for(let n=0;n<t.length;n++){const o=t[n];if(`${e.msid}_${e.mediaType}`==`${o.msid}_${o.mediaType}`){i=!0,r=n;break}}return{isInclude:i,index:r}})(e,u);t?u.splice(i,1,e):u.push(e)}));const s=(null==o?void 0:o.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:1},e))))||[];h=s}));const{publishedList:g}=Nt(l,u),v=Object.assign(Object.assign({},t.getCDNUris()),{enableInnerCDN:t.getCDNEnable()}),p=v&&v.broadcast===Co.SPREAD?JSON.stringify([v]):"",R=Date.now(),m=yield t.context.setRTCTotalRes(a,[pt(Jt.PUBLISH,g)],Rt(u),Jt.TOTAL_CONTENT_RESOURCE,Rt(h),p);if(null===(i=this._reportMediaActionLogger)||void 0===i||i.reportPubOrSubQualityData(Oo.PUB,this._actionStartTime,_,m,this._trackMediaMap,[{dur:Date.now()-R,cod:m}]),m!==n.SUCCESS)return null===(r=this._logger)||void 0===r||r.error(f.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:C.FAILED,code:m,msg:"send publish streams notification failed"}),this._traceId),{code:T.SIGNAL_ERROR};t.setResourcesByUserId(s,u);const I=g.map((e=>ft(e)));t.polarisReport&&t.polarisReport.sendR2(To.PUBLISH,fo.BEGIN,I),g.forEach((e=>{const i=t.useMutilPeerC?`${a}_${(e=>{const t=e.split("_");return{tag:t.pop(),userId:t.join("_")}})(e.msid).tag}`:`${a}_pub`,{pc:r}=t.peerMgr.getPCItemByPCName(i);r.getLocalTrack(`${e.msid}_${e.mediaType}`).__innerSetPublished(!0)})),null===(o=this._logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:C.SUCCESSED,code:d.length?T.SOME_TRACKS_PUBLISH_FAILED:T.SUCCESS,pubSuccessTrackIds:I}),this._traceId);const E={code:T.SUCCESS};return c&&(E.liveUrl=c),d.length&&(E.failedTracks=d,E.code=T.SOME_TRACKS_PUBLISH_FAILED),E}))}execute(e,t){var r,n,o,a,c,d;return S(this,void 0,void 0,(function*(){this._actionStartTime=Date.now();let{tracks:_}=this;if(null===(n=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_ABSTRACT_ROOM_PUBLISH_T,JSON.stringify({trackIds:_.map(Vt)})),!i("tracks",_,(()=>s(_)&&_.length>0&&_.every((e=>e instanceof rt||e.track instanceof rt))),!0))return null===(a=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===a||a.error(f.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),this._traceId),{code:T.PARAMS_ERROR};if(_=_.filter((t=>{var i,r;const{track:n}=t instanceof rt?{track:t}:t,o=n.isDestroyed();return o&&(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(f.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({msg:`track -> ${n.getTrackId()} has beem destroyed`}),this._traceId)),!o})),!_.length)return null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:C.FAILED,code:T.PUBLISH_TRACKS_IS_INVALID,msg:"params tracks is invalid"}),this._traceId),{code:T.PUBLISH_TRACKS_IS_INVALID};const l=[],{plist:u,pushOtherRooms:h}=this.pubhook(_);for(let i=0;i<u.length;i++){const r=u[i];l.push(this.__publish(e,r,r.tracks,h,t))}const g=yield Promise.all(l);return yield this._mergePublishRes(g,e)}))}}class vs extends Ho{constructor(e,t,i){super(),this.tracks=e,this.unpubhook=t,this._reportMediaActionLogger=i,this._actionStartTime=Date.now(),this._trackMediaMap={}}get kind(){return po.UNPUBLISH}__unpublish(e,t,i,r){var n,o,s,a;return S(this,void 0,void 0,(function*(){const{pcName:c,pc:d}=i,_=r.map((e=>e.getTrackId()));if(0===_.map(e.getPublishedResourceByTrackId.bind(e)).filter((e=>!!e)).length)return{code:T.SUCCESS,tracks:r};_.forEach((e=>d.removeLocalTrackById(e))),e.polarisReport.sendR2(To.PUBLISH,fo.END,_),d.clearReTryExchangeTimer();const l=e.useMutilPeerC?[]:e.getSubscribedList(),u=yield ts(l,!1,d,e),{pushOtherRooms:h,headers:g}=this.unpubhook(r,c);h&&(u.pushOtherRooms=h);const v=yield new Qo(g,u,this._traceId,!0).execute(e,t);if(r.forEach((e=>{const t=e.getTrackId();this._trackMediaMap[t]=v.qualityMsList||[]})),v.code!==T.SUCCESS)return this._reportMediaActionLogger.reportPubOrSubQualityData(Oo.UNPUB,this._actionStartTime,r,v.code,this._trackMediaMap),null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_ABSTRACT_ROOM_UNPUBLISH_P,JSON.stringify({status:C.FAILED,code:v.code,trackIds:r.map(Vt),msg:"exchange failed"}),this._traceId),{code:v.code,tracks:r};const{resultCode:p,message:R}=v.data;return p!==T.SUCCESS?(this._reportMediaActionLogger.reportPubOrSubQualityData(Oo.UNPUB,this._actionStartTime,r,v.data.resultCode,this._trackMediaMap),null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_ABSTRACT_ROOM_UNPUBLISH_P,JSON.stringify({status:C.FAILED,code:p,trackIds:r.map(Vt),msg:`exchange inner failed: ${R}`}),this._traceId),{code:p,tracks:r}):Object.assign(Object.assign({},v),{tracks:r})}))}_mergeUnpublishRes(e,t){var i,r,o,s;return S(this,void 0,void 0,(function*(){const a=e.context.getCurrentId(),{roomId:c}=e,d=[],_=[],l=[],u=[],h=[];let g=[];for(let i=0;i<t.length;i++){const r=t[i],{tracks:n}=r;if(r.code!==T.SUCCESS){_.push({code:r.code,tracks:n});continue}l.push(...n);const{mcuPublishList:o}=r.data,s=r.tracks.map((e=>e.getTrackId()));h.push(...s);const a=s.map(e.getPublishedResourceByTrackId.bind(e)).filter((e=>!!e));u.push(...a),d.push(r);const c=o?o.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:1},e))):[];g=c}const v=e.getResourcesByUserId(a).filter((e=>!u.includes(e))),p=Date.now(),R=yield e.context.setRTCTotalRes(c,[pt(Jt.UNPUBLISH,u)],Rt(v),Jt.TOTAL_CONTENT_RESOURCE,Rt(g));if(this._reportMediaActionLogger.reportPubOrSubQualityData(Oo.UNPUB,this._actionStartTime,l,R,this._trackMediaMap,[{dur:Date.now()-p,cod:R}]),R!==n.SUCCESS)return null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:C.FAILED,code:R,msg:"send unpublish notification failed"}),this._traceId),{code:T.SIGNAL_ERROR};null===(s=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:C.SUCCESSED,code:_.length?T.SOME_TRACKS_PUBLISH_FAILED:T.SUCCESS,msg:"unpublish success",unPubResourceIds:h}),this._traceId),d.forEach((t=>S(this,void 0,void 0,(function*(){const{sdp:i}=t.data,{tracks:r}=t,n=e.peerMgr.getPCByTrackId(r[0].getTrackId());yield n.setRemoteAnswer(i.sdp)})))),e.setResourcesByUserId(a,v);const m={code:T.SUCCESS};return _.length&&(m.failedTracks=_,m.code=T.SOME_TRACKS_PUBLISH_FAILED),m}))}execute(e,t){var r,n,o,s,a;return S(this,void 0,void 0,(function*(){this._actionStartTime=Date.now();const{crtUserId:c,roomId:d}=e,{tracks:_}=this;this._traceId=null===(r=e.context.logger)||void 0===r?void 0:r.createTraceId(),null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_UNPUBLISH_T,JSON.stringify({trackIds:_.map(Vt)}));if(!i("tracks",_,(()=>_.every((e=>e.getUserId()===c&&e instanceof rt))),!0))return null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"})),{code:T.PARAMS_ERROR};const l=e.peerMgr.createPeerCList(_),u=[];for(let i=0;i<l.length;i++){const{tracks:r}=l[i];u.push(this.__unpublish(e,t,l[i],r))}const h=yield Promise.all(u);let g=h.length;if(h.forEach((e=>{e.code!==T.SUCCESS||e.data||(g-=1)})),0===g)return{code:T.SUCCESS};return yield this._mergeUnpublishRes(e,h)}))}}class ps extends Ho{constructor(e,t){super(),this.localTrack=e,this._recvSignalResultFn=t}get kind(){return po.LOCAL_TRACK_MUTE}execute(e,t){var i,r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const{localTrack:t}=this,l=t.getTrackId(),{crtUserId:u,roomId:h}=e,g=!t.isLocalMuted(),v=null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_T,JSON.stringify({enabled:g,trackId:this.localTrack.getTrackId()}),v);const p=[{resourceId:l,enabled:g}],R=e.getResourcesByUserId(u),m=[];for(let e=0;e<R.length;e+=1){const t=R[e],i=ft(t),r=p.findIndex((e=>e.resourceId===i));if(r>=0){const{enabled:e}=p[r];t.state=e?1:0,m.push(t);break}}const I=yield e.context.setRTCTotalRes(h,[pt(Jt.MODIFY,m)],Rt(R),Jt.TOTAL_CONTENT_RESOURCE);this._recvSignalResultFn(I),I!==n.SUCCESS&&(null===(c=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_R,JSON.stringify({status:C.FAILED,code:I,msg:"signal error"}),v)),null===(_=null===(d=e.context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_R,JSON.stringify({status:C.SUCCESSED}),v)}))}}class Rs extends Ho{constructor(e,t,i){super(),this.pcName=e,this.isPub=t,this.retryHook=i}get kind(){return po.RETRY_EXCHANGE}get priority(){return mo.HIGH}execute(e,t){var i,r,n,o,s;return S(this,void 0,void 0,(function*(){const a=null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_RETRY_EXCHANGE_COMMAND_T),this._store=e,this._userId=e.context.getCurrentId();const{pcName:c,isPub:d}=this,{useMutilPeerC:_}=e,{pc:l}=e.peerMgr.getPCItemByPCName(c),u=d&&_?[]:e.getSubscribedList(),h=yield ts(u,!0,l,e),{pushOtherRooms:g,headers:v}=this.retryHook(c);g&&(h.pushOtherRooms=g);const p=yield new Qo(v,h,a).execute(e,t);if(p.code!==T.SUCCESS)return;const{sdp:R,resultCode:m}=p.data;if(m!==T.SUCCESS)return;l.clearReTryExchangeTimer();if((yield l.setRemoteAnswer(R.sdp))!==T.SUCCESS)return;if(!this.isPub)return;const I=(null===(s=p.data)||void 0===s?void 0:s.publishList)||[],{plus:E,minus:S}=this._diffPublishListChange(I);(E.length||S.length)&&(yield this._spreadPublishListUri(E,S,a))}))}_diffPublishListChange(e){const t=this._store.getResourcesByUserId(this._userId),{useMutilPeerC:i}=this._store;let r=JSON.parse(JSON.stringify(t));i?e.forEach((e=>{const{mediaType:t,msid:i}=e,n=r.findIndex((e=>{const{mediaType:r,msid:n}=e;return t===r&&i===n}));if(-1===n){const t=Object.assign({tag:i.split("_").pop(),state:this._store.getTrackState(ft(e))},e);r.push(t)}else r[n].uri=e.uri})):r=e.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:this._store.getTrackState(ft(e))},e)));const{publishedList:n,unpublishedList:o}=Nt(t,r,!0);return this._store.setResourcesByUserId(this._userId,r),{plus:n,minus:o}}_spreadPublishListUri(e,t,i){var r,o,s;return S(this,void 0,void 0,(function*(){const a=this._store.getResourcesByUserId(this._userId);null===(r=this._store.context.logger)||void 0===r||r.info(f.L_RETRY_EXCHANGE_SPREAD_T,JSON.stringify({plus:e,minus:t,allPublishList:a,pcName:this.pcName}),i);const c=[];t.length&&c.push(pt(Jt.UNPUBLISH,t)),e.length&&c.push(pt(Jt.PUBLISH,e));(yield this._store.context.setRTCTotalRes(this._store.roomId,c,Rt(a),Jt.TOTAL_CONTENT_RESOURCE))===n.SUCCESS?null===(o=this._store.context.logger)||void 0===o||o.info(f.L_RETRY_EXCHANGE_SPREAD_R,`status: ${C.SUCCESSED}`,i):null===(s=this._store.context.logger)||void 0===s||s.error(f.L_RETRY_EXCHANGE_SPREAD_R,`status: ${C.FAILED}`,i)}))}}class ms extends Ho{constructor(e,t,i,r,n=3e4,o,s){super(),this.subhook=e,this.callbacks=t,this._retryHook=i,this._pubhook=r,this._signalRetryTime=n,this._pullRTCRoomStatus=o,this.livingType=s}get kind(){return po.ON_SIGNAL_RECONNECTED}get priority(){return mo.HIGH}execute(e,t){var i,r,o,s,a,c;return S(this,void 0,void 0,(function*(){const{roomId:d,roomMode:_}=e;this._roomId=d,this._roomMode=_;const l=null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(o=e.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_ABSTRACT_ROOM_IM_RECONNECTED_T,void 0,l);if(e.peerMgr.getPCList().some((e=>"closed"===e.getRTCPeerConn().connectionState)))return null===(c=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:C.FAILED,msg:"RTCPeerConnection closed. Please rejoin room to restore services"}),l),void(this.callbacks.onPeerClosed&&this.callbacks.onPeerClosed());const{code:u}=yield e.context.rtcPing(d,_);if(40001===u){(yield this._joinRoom(e,l,t))===n.SUCCESS&&(yield this._restoreMediaServer(e,t))}else yield this._pullRTCRoomStatus(this._roomId,l).execute(e,t)}))}_joinRoom(e,t,i){var r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const{code:l,data:u}=yield e.context.joinRTCRoom(this._roomId,this._roomMode,this.livingType);if(l!==n.SUCCESS)return void(null===(o=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===o||o.error(f.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:C.FAILED,code:l,msg:"im reconnect joinRTCRoom failed"}),t));if(!u)return void(null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:C.FAILED,msg:"im reconnect joinRTCRoom, roomData is empty"}),t));const h=null===(c=u.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===c?void 0:c.value;return yield os(u,e,this.callbacks,i,this.subhook,h,t),null===(_=null===(d=e.context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:C.SUCCESSED,roomData:u}),t),l}))}_restoreMediaServer(e,t){return S(this,void 0,void 0,(function*(){const{useMutilPeerC:i}=e.peerMgr,r=e.getLocalTracks(),n=Object.values(e.getRemoteTracks()).filter((e=>!!e.isSubscribed()));if(i)return n.length&&(yield new hs(n,this.subhook,!0).execute(e,t)),void(r.length&&(yield new gs(r,this._pubhook,this._signalRetryTime).execute(e,t)));r.length&&(yield new gs(r,this._pubhook,this._signalRetryTime).execute(e,t)),!r.length&&n.length&&(yield new hs(n,this.subhook,!0).execute(e,t))}))}}class Is extends Ko{constructor(e,t,i,r=Ro.NORMAL,n){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=n,this._logger=null,this._logger=We.getLogger()}get kind(){return po.ASYNC_COMMAND}execute(e,t){var i,r,n;return S(this,void 0,void 0,(function*(){const{tracks:o}=this;if(this.state===Ro.NORMAL){const r=e.getSubscribedList().slice(),{code:n,failedList:s}=yield new Zo(o,this.subhook,!0,this.traceId).execute(e,t),a=e.getSubscribedList().slice(),{subscribe:c,unsubscribe:d}=this.pickoutSubscribed(a,r);return null===(i=this.callbacks)||void 0===i||i.onTaskCompleted({code:n,subscribe:c,unsubscribe:d,failedList:s}),{code:n,failedList:s}}if(this.state===Ro.TAIL){const{code:i}=yield new Is(this.tracks,this.subhook,this.callbacks,Ro.MIDDLE,this.traceId).execute(e,t);if(i===T.SUCCESS){const i=e.getCollectSubscribeList().slice(0),o=e.getSubscribedList().slice(),{code:s,failedList:a}=yield new Zo(i,this.subhook,!0).execute(e,t);if(s!==T.SUCCESS)return null===(r=this.callbacks)||void 0===r||r.onTaskCompleted({code:s,subscribe:[],unsubscribe:[],failedList:a}),{code:s,failedList:a};const c=e.getSubscribedList().slice(0),{subscribe:d,unsubscribe:_}=this.pickoutSubscribed(c,o);return null===(n=this.callbacks)||void 0===n||n.onTaskCompleted({code:s,subscribe:d,unsubscribe:_,failedList:a}),{code:s,failedList:a}}return{code:i}}return Ko.AsyncUpdateSubscribeTasks.splice(Ko.AsyncUpdateSubscribeTasks.length,0,...this.tracks),new Promise((t=>{const i=this.formateTrack(o);e.resetCollectSubscribeList(i),t({code:T.SUCCESS})}))}))}}class Es extends Ko{constructor(e,t,i,r=Ro.NORMAL,n){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=n}get kind(){return po.ASYNC_COMMAND}execute(e,t){var r,n,o,a,c;return S(this,void 0,void 0,(function*(){const{tracks:d}=this;if(this.state===Ro.NORMAL){const i=e.getSubscribedList().slice(),{code:n,failedList:o}=yield new hs(d,this.subhook,!1,this.traceId).execute(e,t),s=e.getSubscribedList().slice(),{subscribe:a,unsubscribe:c}=this.pickoutSubscribed(s,i);return null===(r=this.callbacks)||void 0===r||r.onTaskCompleted({code:n,subscribe:a,unsubscribe:c,failedList:o}),{code:n,failedList:o}}if(null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:d.map(Vt)}),this.traceId),!i("tracks",d,(()=>s(d)&&d.length>0&&d.every((e=>e instanceof ht||e.track instanceof ht))),!0))return null===(c=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:T.PARAMS_ERROR};const _=this.getSubscribedList(e).map((e=>Object.assign({},e))),l=d.map((e=>e instanceof ht?{track:e}:e)),u=[];if(l.forEach((e=>{const t=e.track.getTrackId();u.push(t);const i=_.find((e=>e.track.getTrackId()===t));if(i){if(i.subTiny===e.subTiny)return;i.subTiny=e.subTiny}else _.push(e)})),e.polarisReport.sendR2(To.SUBSCRIBE,fo.BEGIN,u),this.state===Ro.TAIL){const{code:i}=yield new Es(this.tracks,this.subhook,this.callbacks,Ro.MIDDLE,this.traceId).execute(e,t);if(i===T.SUCCESS){const i=e.getCollectSubscribeList().slice(0);return new Is(i,this.subhook,this.callbacks,Ro.NORMAL,this.traceId).execute(e,t)}return{code:i}}return Ko.AsyncSubscribeTasks.splice(Ko.AsyncSubscribeTasks.length,0,...this.tracks),new Promise((t=>{e.resetCollectSubscribeList(_),t({code:T.SUCCESS})}))}))}getSubscribedList(e){return this.state===Ro.MIDDLE?e.getCollectSubscribeList():e.getSubscribedList()}}class Ss extends Ko{constructor(e,t,i,r=Ro.NORMAL,n){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=n}get kind(){return po.ASYNC_COMMAND}execute(e,t){var r,n,o,a,c;return S(this,void 0,void 0,(function*(){const{tracks:d}=this;if(this.state===Ro.NORMAL){const i=e.getSubscribedList().slice(),{code:n,failedList:o}=yield new Xo(d,this.subhook,this.traceId).execute(e,t),s=e.getSubscribedList().slice(),{subscribe:a,unsubscribe:c}=this.pickoutSubscribed(s,i);return null===(r=this.callbacks)||void 0===r||r.onTaskCompleted({code:n,subscribe:a,unsubscribe:c,failedList:o}),{code:n,failedList:o}}if(null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_UNSUBSCRIBE_T,JSON.stringify({trackIds:d.map(Vt)}),this.traceId),!i("tracks",d,(()=>s(d)&&d.length>0&&d.every((e=>e instanceof ht))),!0))return null===(c=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===c||c.warn(f.L_ABSTRACT_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:T.PARAMS_ERROR};const _=this.getSubscribedList(e).map((e=>Object.assign({},e))).filter((e=>!d.includes(e.track)));if(e.polarisReport.sendR2(To.SUBSCRIBE,fo.END,d.map((e=>e.getTrackId()))),this.state===Ro.TAIL){const{code:i}=yield new Ss(this.tracks,this.subhook,this.callbacks,Ro.MIDDLE,this.traceId).execute(e,t);if(i===T.SUCCESS){const i=e.getCollectSubscribeList().slice(0).map((e=>e.track));return new Is(i,this.subhook,this.callbacks,Ro.NORMAL,this.traceId).execute(e,t)}return{code:i}}return Ko.AsyncUnsubscribeTasks.splice(Ko.AsyncUnsubscribeTasks.length,0,...this.tracks),new Promise((t=>{e.resetCollectSubscribeList(_),t({code:T.SUCCESS})}))}))}getSubscribedList(e){return this.state===Ro.MIDDLE?e.getCollectSubscribeList():e.getSubscribedList()}}var Ts;!function(e){e[e.JOIN=0]="JOIN",e[e.LEAVE=1]="LEAVE",e[e.OFFLINE=2]="OFFLINE",e[e.RESOURCECHANGE=3]="RESOURCECHANGE"}(Ts||(Ts={}));class fs extends Ho{constructor(e,t,i,r,n,o,s){super(),this._roomId=e,this._traceId=t,this._context=i,this._callbacks=r,this._subhook=n,this._dealUserAppListener=o,this._targetPullVersion=s}get kind(){return po.PULL_RTCROOM_STATUS}execute(e,t){var i,r,o,s;return S(this,void 0,void 0,(function*(){const a=e.getRoomStatusVersion();if(null===(i=this._context.logger)||void 0===i||i.info(f.L_PULL_ROOM_STATUS_T,JSON.stringify({roomId:this._roomId,localVersion:a}),this._traceId),this._targetPullVersion&&this._targetPullVersion<=a)return null===(r=this._context.logger)||void 0===r||r.info(f.L_PULL_ROOM_STATUS_R,JSON.stringify({status:C.SUCCESSED,msg:"the roomData has been pulled",localVersion:a,targetPullVersion:this._targetPullVersion}),this._traceId),{code:n.SUCCESS};const{code:c,data:d}=yield this._context.pullRTCRoomStatus(this._roomId,a);if(c!==n.SUCCESS)return null===(o=this._context.logger)||void 0===o||o.info(f.L_PULL_ROOM_STATUS_R,JSON.stringify({status:C.FAILED,code:c}),this._traceId),{code:c};const{bFullStatus:_,version:l,usersData:u,roomStatus:h}=d;if(null===(s=this._context.logger)||void 0===s||s.info(f.L_PULL_ROOM_STATUS_R,JSON.stringify({bFullStatus:_,version:Ft(l),usersData:u,roomStatus:h}),this._traceId),e.setRoomStatusVersion(l),_){const{urisData:i,CDNUris:r}=function(e){const t={users:{}};let i="";return e.forEach((e=>{var r,n;const{userId:o,userData:s}=e;t.users[o]={};const a=null===(r=s.filter((e=>"uris"===e.key))[0])||void 0===r?void 0:r.value,c=null===(n=s.filter((e=>"cdn_uris"===e.key))[0])||void 0===n?void 0:n.value;i=c||i,t.users[o]={uris:a}})),{urisData:t,CDNUris:i&&JSON.stringify(JSON.parse(i)[0])}}(u);return yield os(i,e,this._callbacks,t,this._subhook,r,this._traceId),{code:c}}for(let i=0;i<h.length;i++){const r=h[i];if(r.event===Ts.RESOURCECHANGE){const i=ds(r);if(!i)continue;const{content:n,userId:o}=i;if(o===e.crtUserId)continue;yield new us(n,Jt.TOTAL_CONTENT_RESOURCE,o,this._subhook.bind(this),this._callbacks,this._traceId).execute(e,t)}else{const i=as(r),n=yield new ls(i,this._subhook.bind(this),this._traceId).execute(e,t);this._dealUserAppListener(n)}}return{code:c}}))}}class Cs{constructor(){}static getMemo(){return this._memo||(this._memo={}),window.__memo__=this._memo,this._memo}static destroy(){this._memo={}}}Cs._memo={};const Os=1,Ls=5;var Ns,As;!function(e){e[e.new=0]="new",e[e.checking=1]="checking",e[e.connected=2]="connected",e[e.completed=3]="completed",e[e.failed=4]="failed",e[e.disconnected=5]="disconnected",e[e.closed=6]="closed"}(Ns||(Ns={})),function(e){e[e.SERVER_KICK=1]="SERVER_KICK",e[e.OTHER_KICK=2]="OTHER_KICK"}(As||(As={}));class ys{constructor(e,t,i){this._roomId=e,this._clientSessionId=t,this._userId=i,this._iceCandidatePair={},this._peerCStatus={},this.reportQualityJoinRoomData=(e,t,i,r)=>{this._baseReportData=Object.assign(this._baseReportData,{snid:r});const n=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{cod:t,time:e,dur:Date.now()-e,rtp:i});Ye.__statistics(f.L_QS_JOIN_ROOM_S,JSON.stringify(n))},this._baseReportData={rid:this._roomId,csnid:this._clientSessionId,snid:"",time:Date.now(),uid:this._userId},this._networkReportData={cr:"unknown",net:"unknown"}}reportQualityKickedData(e){const t=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{time:Date.now(),cod:e===As.OTHER_KICK?Ls:Os});Ye.__statistics(f.L_QS_KICKED_S,JSON.stringify(t))}reportPubOrSubQualityData(e,t,i,r,n,o){i.forEach((i=>{var s,a;const c=i instanceof rt||i instanceof ht?i:i.track,d=c.getTrackId(),{mediaType:_}=Ct(d);let l=!1;l=c instanceof rt?!!c.isVideoTrack()&&(null===(a=(s=c).__isTiny)||void 0===a?void 0:a.call(s)):i.subTiny||!1;const u=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{resid:d,mtp:_,smct:l?Xn.TINY:Xn.NORMAL,stp:"Rongcloud"!==c.getTag()?1:0,cod:r,msas:n?n[d]:[],sigs:o,time:Date.now(),dur:Date.now()-t});switch(e){case"pub":Ye.__statistics(f.L_QS_PUBLISH_S,JSON.stringify(u));break;case"unpub":Ye.__statistics(f.L_QS_UNPUBLISH_S,JSON.stringify(u));break;case"sub":Ye.__statistics(f.L_QS_SUBSCRIBE_S,JSON.stringify(u));break;case"unsub":Ye.__statistics(f.L_QS_UNSUBSCRIBE_S,JSON.stringify(u))}}))}reportQualityRecvPubMsgData(e,t){const i=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{puid:t,time:Date.now(),dur:Date.now()-e});Ye.__statistics(f.L_QS_RECV_PUB_MSG_S,JSON.stringify(i))}setPubOrSubSuccessTime(e){this._pubOrSubSuccessTime=e}reportIceFirstConnectData(e){const t=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{time:this._pubOrSubSuccessTime,dur:Date.now()-this._pubOrSubSuccessTime}),i="pub"===e?f.L_QS_PUB_ICE_STATUS_S:f.L_QS_SUB_ICE_STATUS_S;Ye.__statistics(i,JSON.stringify(t))}setIceCandidatePair(e,t){this._iceCandidatePair[e]=t}recordQualityIceStatusData(e,t,i){const{status:r,time:n}=this._peerCStatus[e]||{};if(!n)return void(this._peerCStatus[e]={status:t,time:i});const{IP:o,port:s,networkType:a,remoteIP:c,remotePort:d}=this._iceCandidatePair[e],_=Object.assign(Object.assign(Object.assign({},this._baseReportData),this._networkReportData),{dur:i-n,time:i,pices:Ns[r],ices:Ns[t],rcdts:[{ip:`${c}:${d}`}],lcdts:[{ip:`${o}:${s}`,nttp:a}],cncdts:[]});Ye.__statistics(f.L_QS_ICE_STATUS_S,JSON.stringify(_)),this._peerCStatus[e]={status:t,time:i}}}const ks="evt-leave";class Ds extends e{constructor(e,t,i,r,n,o,s,a,c,d=Wn(),_=3e4){super(),this._context=e,this._runtime=t,this._roomId=i,this._service=n,this._initOptions=o,this._useMutilPeerC=c,this._clientSessionId=d,this.signalRetryTime=_,this._appListener=null,this._reportListener=null,this._onRecvPKMsg=null,this._reportMediaActionLogger=new ys(this._roomId,this._clientSessionId,this._context.getCurrentId()),this._polarisReport=new Fo(this._context,this._runtime,this._roomId,this),this._peerCManager=new Go(this._useMutilPeerC,this._roomId,this._reTryExchange.bind(this),this._context.getCurrentId(),this._polarisReport,!1,o),this._invoker=new Yo(this._context,this._service,this._peerCManager,i,this._context.getCurrentId(),r,this._polarisReport,s,a),this._store=this._invoker.store,this._peerCManager.setStore(this._store),this._context.registerRTCSignalListener((e=>S(this,void 0,void 0,(function*(){var t,i,r,n,o,s;const{time:a,type:c,roomId:d}=this._context.decodeRtcNotify(e);if(this._invoker.isDestroyed())null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_RTCNTF_PULL_ROOM_STATUS_O,JSON.stringify({isDestroyed:!0,type:c,time:a,roomId:d}));else if(2===c){if(d!==this._roomId)return;const e=null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n?void 0:n.createTraceId();null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_RTCNTF_PULL_ROOM_STATUS_O,null,e),this._startPullRTCRoomStatus(d,e,a)}}))))}_pullRTCRoomStatus(e,t,i){return new fs(e,t,this._context,{onUserJoin:this._callAppListener.bind(this,"onUserJoin"),onUserLeave:this._callAppListener.bind(this,"onUserLeave"),onAudioMuteChange:this._onAudioMuteChange.bind(this),onVideoMuteChange:this._onVideoMuteChange.bind(this),onTrackPublish:this._onTrackPublish.bind(this),onTrackUnpublish:this._onTrackUnpublish.bind(this),onCDNEnableChange:this._callAppListener.bind(this,"onCDNEnableChange")},this._subhook.bind(this),this._dealUserAppListener.bind(this),i)}_startPullRTCRoomStatus(e,t,i){return S(this,void 0,void 0,(function*(){yield this._invoker.push(this._pullRTCRoomStatus(e,t,i))}))}__innerInit(e,t,i,r,n,o){return S(this,void 0,void 0,(function*(){const{code:s,data:a}=yield this._invoker.push(new zo(this._roomId,e,this._context,t,i,r,n,o,this._reportMediaActionLogger));return s!==T.SUCCESS?{code:s}:(this._initWithRoomData(a.offlineKickTime),{code:s,data:a})}))}_initWithRoomData(e){var t;const i=this._invoker.store;this._pinger=new Ht(i,this._context,this._initOptions.pingGap,1e3*e),this._pinger.onFailed=this._kickoff.bind(this),this._pinger.onPingResult=this._handlePingResult.bind(this),this._pinger.start(this._startPullRTCRoomStatus.bind(this)),null===(t=this._polarisReport)||void 0===t||t.sendR1()}_handlePingResult(e){this._callAppListener("onPing",e)}setBitrate(e,i,r){var n,o,s,a;if(this._useMutilPeerC)return void(null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_ABSTRACT_ROOM_SETBITRATE_O,"`RCAbstractRoom.setBitrate` is disabled, use `RCLocalTrack.setBitrate` instead."));null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.warn(f.L_ABSTRACT_ROOM_SETBITRATE_O,"`RCAbstractRoom.setBitrate` will be deprecated, use `RCLocalTrack.setBitrate` instead."),h("max",e,(e=>t(e)&&e>Math.max(i||1,200)),!0),h("min",i,(i=>t(i)&&i>=1&&(!t(e)||i<e)),!0),h("start",r,(r=>t(r)&&r>i&&r<=e));this._peerCManager.getPCList().forEach((t=>{t.setBitrate(e,i,r)}))}_onTrackReady(e){var t,i,r,n;const o=e.streams[0].id,{track:s}=e.receiver,a=[o,"audio"===s.kind?Je.AUDIO_ONLY:Je.VIDEO_ONLY].join("_"),c=this._store.getRemoteTrack(a);c?(c.__innerSetMediaStreamTrack(s),null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onTrackReady",trackId:c.getTrackId()})),this._callAppListener("onTrackReady",c)):null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.warn(f.L_ABSTRACT_ROOM_ONTRACKREADY_O,`cannot found remote track ${s.id}`)}_callAppListener(e,...t){var i,r,n;const o=null===(i=this._appListener)||void 0===i?void 0:i[e];if(o)try{o(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,null==e?void 0:e.stack)}}_onTrackUnpublish(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onTrackUnpublish",trackIds:null==e?void 0:e.map((e=>e.getTrackId()))})),this._callAppListener("onTrackUnpublish",e)}__parseInnerMessage(e,t){var i,r,n,o,s,a,c,d,_,l;const{targetId:u,conversationType:h}=e;if(u!==this._roomId)return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(f.L_ABSTRACT_ROOM_RECEIVE_MESSAGE_O,JSON.stringify({status:C.FAILED,message:`roomId is different, msg roomId-> ${u}, this._roomId-> ${this._roomId} `}),t),!0;null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_RECEIVE_MESSAGE_O,`recv inner msg -> message: ${JSON.stringify(e)} | roomid: ${this._roomId}`,t);const{content:g}=e;switch(e.messageType){case Jt.KICK:this._kickoff(!0,g);break;case Jt.STATE:this._stateHandle(g,t);break;case Jt.MODIFY:case Jt.PUBLISH:case Jt.UNPUBLISH:case Jt.TOTAL_CONTENT_RESOURCE:this._resourceHandle(g,e.messageType,e.senderUserId,e.sentTime,t);break;case Jt.ROOM_NOTIFY:null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onRoomAttributeChange",messageType:e.messageType,messageContent:e.content})),this._callAppListener("onRoomAttributeChange",e.messageType,e.content);break;case Jt.USER_NOTIFY:null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.warn(f.L_OLD_DAILY_RECORD_O,`TODO: ${Jt.USER_NOTIFY}`);break;case Jt.PK_INVITE:case Jt.PK_CANCEL_INVITE:case Jt.PK_INVITE_TIMEOUT:case Jt.PK_INVITE_ANSWER:case Jt.PK_END:this._onRecvPKMsg&&this._onRecvPKMsg(e);break;case Jt.OTHER_ROOM_OFFLINE:break;default:null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onMessageReceive",messageType:e.messageType,messageContent:e.content,senderUserId:e.senderUserId,messageUId:e.messageUId})),this._callAppListener("onMessageReceive",e.messageType,g,e.senderUserId,e.messageUId)}return!0}_kickoff(e,t){var i,r,n,o;return S(this,void 0,void 0,(function*(){if(this._invoker.isDestroyed())return;let s,a;null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(f.L_ABSTRACT_ROOM_ONKICKOFF_O,`onKickOff -> byServer: ${e}, kickContent: ${JSON.stringify(t)}`),this.emit(ks),this._leaveHandle(!e),e&&((null==t?void 0:t.users)||[]).forEach((e=>{e.userId===this._context.getCurrentId()&&(a=e.type,s=e.kickExtra,this._reportMediaActionLogger.reportQualityKickedData(a))})),null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onKickOff",byServer:e,kickType:a,kickExtra:s})),this._callAppListener("onKickOff",e,a,s)}))}_rtcpeerClosed(){var e,t;this.emit(ks),this._leaveHandle(!0),null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onRTCPeerConnectionCloseByException"})),this._callAppListener("onRTCPeerConnectionCloseByException")}_resourceHandle(e,t,i,r,n){return S(this,void 0,void 0,(function*(){const{uris:o,ignore:s}=e;!s&&o&&this._invoker.push(new us(e,t,i,this._subhook.bind(this),{onAudioMuteChange:this._onAudioMuteChange.bind(this),onVideoMuteChange:this._onVideoMuteChange.bind(this),onTrackPublish:this._onTrackPublish.bind(this),onTrackUnpublish:this._onTrackUnpublish.bind(this),onCDNEnableChange:this._callAppListener.bind(this,"onCDNEnableChange")},n,r,this._reportMediaActionLogger))}))}_onTrackPublish(e,t,i){var r,n;null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onTrackPublish",trackIds:null==e?void 0:e.map((e=>e.getTrackId()))})),this._callAppListener("onTrackPublish",e)}_stateHandle(e,t){return S(this,void 0,void 0,(function*(){const i=yield this._invoker.push(new ls(e,this._subhook.bind(this),t));this._dealUserAppListener(i)}))}_dealUserAppListener(e){var t,i,r,n,o,s,a,c,d;const{left:_,joined:l,upgrade:u,downgrade:h}=e;if(null===(t=this._appListener)||void 0===t?void 0:t.onSwitchRole)return null==u||u.forEach((e=>{var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onSwitchRole",userId:e,role:vo.ANCHOR})),this._callAppListener("onSwitchRole",e,vo.ANCHOR)})),null==h||h.forEach((e=>{var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onSwitchRole",userId:e,role:vo.AUDIENCE})),this._callAppListener("onSwitchRole",e,vo.AUDIENCE)})),l.length>0&&(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onUserJoin",joined:l})),this._callAppListener("onUserJoin",l)),void(_.length>0&&(null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onUserLeave",left:_})),this._callAppListener("onUserLeave",_)));const g=[...l,...u],v=[..._,...h];g.length>0&&(null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onUserJoin",allJoined:g})),this._callAppListener("onUserJoin",g)),v.length>0&&(v.length&&(null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onUserLeave",allLeft:v}))),this._callAppListener("onUserLeave",v))}getRoomId(){return this._roomId}getCrtUserId(){return this._context.getCurrentId()}__getPC(){return this._store.peerMgr.getPCList()}getRemoteUserIds(){return this._store.getRemoteUserIds()}getRemoteTracks(){const e=[];return this.getRemoteUserIds().forEach((t=>{e.push(...this.getRemoteTracksByUserId(t))})),e}getRemoteTracksByUserId(e){return this._store.getRemoteTracksByUserId(e)}getSessionId(){return this._store.getSessionId()}sendMessage(e,t){var i,r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_ABSTRACT_ROOM_SEND_MESSAGE_T,JSON.stringify({name:e,content:t}),l);const{code:u}=yield this._context.sendMessage(g.RTC_ROOM,this._roomId,{messageType:e,content:t,isStatusMessage:!0});return u!==n.SUCCESS?(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_ABSTRACT_ROOM_SEND_MESSAGE_R,JSON.stringify({status:C.FAILED,code:u}),l),{code:T.SIGNAL_ERROR}):(null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_ABSTRACT_ROOM_SEND_MESSAGE_R,JSON.stringify({status:C.SUCCESSED,name:e,content:t}),l),{code:T.SUCCESS})}))}setRoomAttribute(e,t,i,r=!1){var o,s,a,c,d,_,l,u;return S(this,void 0,void 0,(function*(){const h=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,key:e,value:t,message:i,isInner:r}),h);const g=yield this._context.setRTCData(this._roomId,e,t,r,So.ROOM,i);return g!==n.SUCCESS?(null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_R,JSON.stringify({status:C.FAILED,code:g}),h),{code:T.SIGNAL_ERROR}):(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(f.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_R,JSON.stringify({status:C.SUCCESSED,roomId:this._roomId,key:e,value:t,message:i,isInner:r}),h),{code:T.SUCCESS})}))}deleteRoomAttributes(e,t,i=!1){var r,o,s,a,c,d,_,l;return S(this,void 0,void 0,(function*(){const u=null===(o=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===o?void 0:o.createTraceId();null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,keys:e,message:t,isInner:i}),u);const h=yield this._context.removeRTCData(this._roomId,e,i,So.ROOM,t);return h!==n.SUCCESS?(null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:C.FAILED,code:h}),u),{code:T.SIGNAL_ERROR}):(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(f.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:C.SUCCESSED,roomId:this._roomId,keys:e,message:t,isInner:i}),u),{code:T.SUCCESS})}))}getRoomAttributes(e=[],t=!1){var i,r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,keys:e,isInner:t}),l);const{code:u,data:h}=yield this._context.getRTCData(this._roomId,e,t,So.ROOM);return u!==n.SUCCESS?(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_R,`GetRoomAttributes Failed: ${u}`,l),{code:T.SIGNAL_ERROR}):(null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:C.SUCCESSED,data:h}),l),{code:T.SUCCESS,data:h})}))}_setUserAttributeValue(e,t,i){return this._context.setRTCData(this._roomId,e,t,!1,So.PERSON,i)}_deleteUserAttributes(e,t){return this._context.removeRTCData(this._roomId,e,!1,So.PERSON,t)}_getUserAttributes(e){return this._context.getRTCData(this._roomId,e,!1,So.PERSON)}isDestroyed(){return this._invoker.isDestroyed()}__destroy(e){return this._leaveHandle(e)}_muteRemoteTracksBeforeQuit(){const e=Object.values(this._store.getRemoteTracks());e.length&&e.forEach((e=>e.mute()))}_leaveHandle(e){return S(this,void 0,void 0,(function*(){if(this._invoker.isDestroyed())return;Cs.destroy(),this._invoker.destroy(),this._muteRemoteTracksBeforeQuit(),e&&(yield this._context.quitRTCRoom(this._roomId)),this._store.isMainRoom&&(yield this._quitAllPKRoom()),this._pinger.stop();const t=[];Object.keys(this._peerCManager.getMutilPeerCData()).forEach((e=>{t.push(this._service.exit(this._getRTCReqestHeaders(e)))})),yield Promise.all(t),this._releasePCManager(),this._polarisReport=null}))}_releasePCManager(){const e=this._peerCManager.getPCList();null==e||e.forEach((e=>{e.off(rt.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(rt.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this)})),this._peerCManager.clear(),this._peerCManager=null}_onLocalTrackDestroied(e){e instanceof ot&&e.__isTiny()||this.unpublish([e])}_onLocalTrackMuted(e,t){return S(this,void 0,void 0,(function*(){this._invoker.push(new ps(e,t))}))}publish(e){return S(this,void 0,void 0,(function*(){return this._invoker.push(new gs(e,this._pubhook.bind(this),this.signalRetryTime,this._reportMediaActionLogger))}))}_getPushOtherRoomsParams(){return[]}_reTryExchange(e,t){return S(this,void 0,void 0,(function*(){this._invoker.push(new Rs(e,t,(e=>({pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(e)}))))}))}_getRTCReqestHeaders(e){const t=this._useMutilPeerC?{"Peer-Connection-Id":e}:{};return Object.assign({"App-Key":this._context.getAppkey(),RoomId:this._roomId,Token:this._store.getToken(),RoomType:this._store.roomMode,UserId:this._context.getCurrentId(),"Client-Session-Id":this._clientSessionId},t)}unpublish(e){return S(this,void 0,void 0,(function*(){return this._invoker.push(new vs(e,((e,t)=>({pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(t)})),this._reportMediaActionLogger))}))}_getResourceById(e){return this._store.getPublishedResourceByTrackId(e)}_isValidResourceId(e){var t;const{userId:i}=Ct(e);return!!(null===(t=this._store.getResourcesByUserId(i))||void 0===t?void 0:t.find((t=>ft(t)===e)))}_subhook(e){const{pc:t,pcName:i}=this._peerCManager.createPeerCList(e)[0];return t.on(Bo.__INNER_EVENT_TRACK_READY__,this._onTrackReady,this),this._audioLevelReport&&t.on(Bo.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport),t.once(Bo.__INNER_ICE_CONNECTED__,(()=>{this._reportMediaActionLogger.reportIceFirstConnectData("sub")}),this),t.on(Bo.__INNER_ICE_STATE_CHANGE__,(e=>{const{status:t,time:r,iceCandidatePair:n}=e;n&&this._reportMediaActionLogger.setIceCandidatePair(i,n),n&&this._reportMediaActionLogger.recordQualityIceStatusData(i,t,r)})),t.__reportR3R4ToPolaris(),t.registerReportListener(this._reportListener),t.clearReTryExchangeTimer(),{pc:t,pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(i)}}_pubhook(e){return{plist:this._peerCManager.createPeerCList(e).map((e=>{const{pc:t,pcName:i}=e;return t.on(rt.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),t.on(rt.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),this._audioLevelReport&&t.on(Bo.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport),t.once(Bo.__INNER_ICE_CONNECTED__,(()=>{this._reportMediaActionLogger.reportIceFirstConnectData("pub")}),this),t.on(Bo.__INNER_ICE_STATE_CHANGE__,(e=>{const{status:t,time:r,iceCandidatePair:n}=e;n&&this._reportMediaActionLogger.setIceCandidatePair(i,n),n&&this._reportMediaActionLogger.recordQualityIceStatusData(i,t,r)})),t.registerReportListener(this._reportListener),t.__reportR3R4ToPolaris(),Object.assign(Object.assign({},e),{headers:this._getRTCReqestHeaders(i)})})),pushOtherRooms:this._getPushOtherRoomsParams()}}subscribe(e){return S(this,void 0,void 0,(function*(){return this._invoker.push(new hs(e,this._subhook.bind(this),void 0,void 0,this._reportMediaActionLogger))}))}addSubscribeTask(e){var t;const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();this._invoker.push(new Es(e,this._subhook.bind(this),{onTaskCompleted:this._onTaskCompleted.bind(this)},Ro.NORMAL,i))}unsubscribe(e){var t,i;return S(this,void 0,void 0,(function*(){const r=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();return null===(i=this._context.logger)||void 0===i||i.info(f.L_APP_CALL_UNSUBSCRIBE_O,void 0,r),this._invoker.push(new Xo(e,this._subhook.bind(this),r,this._reportMediaActionLogger))}))}addUnsubscribeTask(e){var t;const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();this._invoker.push(new Ss(e,this._subhook.bind(this),{onTaskCompleted:this._onTaskCompleted.bind(this)},Ro.NORMAL,i))}updateSubList(e){var t,i;return S(this,void 0,void 0,(function*(){return this._invoker.push(new Zo(e,this._subhook.bind(this),!0,null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId(),this._reportMediaActionLogger))}))}addUpdateSubscribeListTask(e){var t;const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();this._invoker.push(new Is(e,this._subhook.bind(this),{onTaskCompleted:this._onTaskCompleted.bind(this)},Ro.NORMAL,i))}_onTaskCompleted(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onTaskCompleted",code:e.code,subscribe:e.subscribe,unsubscribe:e.unsubscribe,failedList:e.failedList})),this._callAppListener("onTaskCompleted",e.code,e.subscribe,e.unsubscribe,e.failedList)}getLocalTrack(e){return this._store.getLocalTrack(e)}getLocalTracks(){return this._store.getLocalTracks()}getRemoteTrack(e){return this._store.getRemoteTrack(e)||null}get subscribedTracks(){return this._store.getSubscribedList().slice()}registerRoomEventListener(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_REGISTER_ROOM_EVENT_LISTENER_O,JSON.stringify({status:C.SUCCESSED,listener:e&&Object.keys(e)})),this._appListener=e,(null==e?void 0:e.onTrackTrouble)&&this._peerCManager&&(this._peerCManager.onTrackTrouble=null==e?void 0:e.onTrackTrouble.bind(this))}registerReportListener(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_REGISTER_REPORT_LISTENER_O,JSON.stringify({status:C.SUCCESSED,listener:e&&Object.keys(e)})),this._reportListener=e}onAudioLevelChange(e,t){var i,r;null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_ABSTRACT_ROOM_AUDIO_LEVEL_O,JSON.stringify({status:C.SUCCESSED,handler:null==e?void 0:e.name,gap:t})),this._audioLevelReport=new Jo(this),this._audioLevelReport.onAudioLevelChange(e)}__onReconnected(e){return S(this,void 0,void 0,(function*(){return this._invoker.push(new ms(this._subhook.bind(this),{onPeerClosed:this._rtcpeerClosed.bind(this),onAudioMuteChange:this._onAudioMuteChange.bind(this),onVideoMuteChange:this._onVideoMuteChange.bind(this),onUserJoin:this._callAppListener.bind(this,"onUserJoin"),onUserLeave:this._callAppListener.bind(this,"onUserLeave"),onTrackPublish:this._onTrackPublish.bind(this),onTrackUnpublish:this._onTrackUnpublish.bind(this),onCDNEnableChange:this._callAppListener.bind(this,"onCDNEnableChange")},(e=>({pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(e)})),this._pubhook.bind(this),this.signalRetryTime,this._pullRTCRoomStatus.bind(this),e))}))}_onAudioMuteChange(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onAudioMuteChange",trackId:e.getTrackId()})),this._callAppListener("onAudioMuteChange",e)}_onVideoMuteChange(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:C.SUCCESSED,eventType:"onVideoMuteChange",trackId:e.getTrackId()})),this._callAppListener("onVideoMuteChange",e)}_registerPKMsgListener(e){this._onRecvPKMsg=e}_quitAllPKRoom(){}getClientSessionId(){return this._clientSessionId}}class bs extends Ho{constructor(e,t){super(),this.data=e,this.cdnValues=t}get kind(){return po.MCUCONFIG_FLUSH}execute(e,t){var i,r,n,o;return S(this,void 0,void 0,(function*(){const t={"App-Key":e.context.getAppkey(),Token:e.getToken(),RoomId:e.roomId,UserId:e.context.getCurrentId(),SessionId:e.getSessionId()},{code:s,res:a}=yield e.service.setMcuConfig(t,this.data);if(s!==T.SUCCESS)return{code:s};a.pull_url&&e.setCDNUris(JSON.parse(a.pull_url));const c=this.cdnValues;return s===T.SUCCESS&&((null===(r=null===(i=c.output)||void 0===i?void 0:i.video.normal)||void 0===r?void 0:r.width)||(null===(o=null===(n=c.output)||void 0===n?void 0:n.video.normal)||void 0===o?void 0:o.fps))&&ns(e),{code:s,res:a}}))}}var Us,Ps,Ms,xs;!function(e){e[e.CROP=1]="CROP",e[e.WHOLE=2]="WHOLE"}(Us||(Us={})),function(e){e[e.CUSTOMIZE=1]="CUSTOMIZE",e[e.SUSPENSION=2]="SUSPENSION",e[e.ADAPTATION=3]="ADAPTATION"}(Ps||(Ps={})),function(e){e[e.CROP=1]="CROP",e[e.WHOLE=2]="WHOLE"}(Ms||(Ms={})),function(e){e[e.AUDIO_VIDEO_ALL=0]="AUDIO_VIDEO_ALL",e[e.AUDIO_VIDEO_NO=1]="AUDIO_VIDEO_NO",e[e.AUDIO_ALL_VIDEO_NO=2]="AUDIO_ALL_VIDEO_NO",e[e.AUDIO_NO_VIDEO_ALL=3]="AUDIO_NO_VIDEO_ALL",e[e.AUDIO_VIDEO_INPUT=4]="AUDIO_VIDEO_INPUT",e[e.AUDIO_ALL_VIDEO_INPUT=5]="AUDIO_ALL_VIDEO_INPUT",e[e.AUDIO_NO_VIDEO_INPUT=6]="AUDIO_NO_VIDEO_INPUT",e[e.AUDIO_INPUT_VIDEO_ALL=7]="AUDIO_INPUT_VIDEO_ALL",e[e.AUDIO_INPUT_VIDEO_NO=8]="AUDIO_INPUT_VIDEO_NO",e[e.ROOM_AUDIO_VIDEO_APPEND=9]="ROOM_AUDIO_VIDEO_APPEND",e[e.ROOM_AUDIO_VIDEO_NOT_APPEND=10]="ROOM_AUDIO_VIDEO_NOT_APPEND",e[e.ROOM_AUDIO_APPEND=11]="ROOM_AUDIO_APPEND",e[e.ROOM_AUDIO_NOT_APPEND=12]="ROOM_AUDIO_NOT_APPEND",e[e.ROOM_VIDEO_APPEND=13]="ROOM_VIDEO_APPEND",e[e.ROOM_VIDEO_NOT_APPEND=14]="ROOM_VIDEO_NOT_APPEND"}(xs||(xs={}));const ws=()=>({version:2,mode:Ps.SUSPENSION});class Bs{constructor(e,t){this._invoker=e,this._isValidTrackId=t,this._values=ws()}setHostVideoTrack(e){var t,i,r,n,o,s,a,c,d;if(!this._isValidTrackId(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,msg:`videoTrackId: ${e} is invalid`})),this;const{mediaType:_,tag:l,userId:u}=Ct(e);return _!==Je.VIDEO_ONLY?(null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,msg:`kind of ${e} is not video`})),this):(this._values.host_stream_id=Ot(u,l),null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:C.SUCCESSED,videoTrackId:e})),this)}setMixLayoutMode(e){var t,i,r,n,o,s;return[Ps.CUSTOMIZE,Ps.SUSPENSION,Ps.ADAPTATION].includes(e)?(this._values.mode=e,null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_MIX_LAYOUT_MODE_O,JSON.stringify({status:C.SUCCESSED,mode:e})),this):(null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_MIX_LAYOUT_MODE_O,JSON.stringify({status:C.SUCCESSED,msg:`mode: ${e} is invalid`})),this)}_addOutputValue(e,t,i="normal"){const r=this._values.output||(this._values.output={video:{normal:{width:640,height:480}}});if("cdn"===e)return void(r.cdn=t);if("audio"===e)return void(r.audio={bitrate:t});const{video:n}=r;if("normal"!==i&&"tiny"!==i)if("backgroundColor"!==i)if("exparams"!==i){if("backgroundPicture"===i){const e=n.backgroundPicture||(n.backgroundPicture={fillMode:Us.CROP,picture:[]});Object.assign(e,t)}}else n.exparams={renderMode:t};else n.backgroundColor=t;else{const e=n[i]||(n[i]={});Object.assign(e,t)}}setOutputVideoResolution(e){var t,i,r,n,o,s;if(!kt(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RESOLUTION_O,JSON.stringify({status:C.FAILED,msg:`params error -> resolution: ${e}`})),this;const{width:a,height:c}=yt(e);return this._addOutputValue("video",{width:a,height:c},"normal"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RESOLUTION_O,JSON.stringify({status:C.SUCCESSED,resolution:e})),this}setOutputVideoFPS(e){var t,i,r,n,o,s;if(!Dt(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_FPS_O,JSON.stringify({status:C.FAILED,msg:`params error -> fps: ${e}`})),this;const a=bt(e);return this._addOutputValue("video",{fps:a},"normal"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_FPS_O,JSON.stringify({status:C.SUCCESSED,fps:e})),this}setOutputVideoBitrate(e){var i,r,n,o,s,a;return!t(e)||e<=0?(null===(n=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_BITRATE_O,JSON.stringify({status:C.FAILED,msg:`params error -> bitrate: ${e}`})),this):(this._addOutputValue("video",{bitrate:e},"normal"),null===(a=null===(s=null===(o=this._invoker.store)||void 0===o?void 0:o.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_BITRATE_O,JSON.stringify({status:C.SUCCESSED,bitrate:e})),this)}setOutputTinyVideoResolution(e){var t,i,r,n,o,s;if(!kt(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_RESOLUTION_O,JSON.stringify({status:C.FAILED,msg:`params error -> resolution: ${e}`})),this;const{width:a,height:c}=yt(e);return this._addOutputValue("video",{width:a,height:c},"tiny"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_RESOLUTION_O,JSON.stringify({status:C.SUCCESSED,resolution:e})),this}setOutputTinyVideoFPS(e){var t,i,r,n,o,s;if(!Dt(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_FPS_O,JSON.stringify({status:C.FAILED,msg:`params error -> fps: ${e}`})),this;const a=bt(e);return this._addOutputValue("video",{fps:a},"tiny"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_FPS_O,JSON.stringify({status:C.SUCCESSED,fps:e})),this}setOutputTinyVideoBitrate(e){var i,r,n,o,s,a;return!t(e)||e<=0?(null===(n=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_BITRATE_O,JSON.stringify({status:C.FAILED,msg:`params error -> bitrate: ${e}`})),this):(this._addOutputValue("video",{bitrate:e},"tiny"),null===(a=null===(s=null===(o=this._invoker.store)||void 0===o?void 0:o.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_BITRATE_O,JSON.stringify({status:C.SUCCESSED,bitrate:e})),this)}setOutputVideoRenderMode(e){var t,i,r,n,o,s;return[Ms.CROP,Ms.WHOLE].includes(e)?(this._addOutputValue("video",e,"exparams"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RENDER_MODE_O,JSON.stringify({status:C.SUCCESSED,renderMode:e})),this):(null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RENDER_MODE_O,JSON.stringify({status:C.FAILED,msg:`params error -> renderMode: ${e}`})),this)}setOutputAudioBitrate(e){var i,r,n,o,s,a;return t(e)&&e>0?(this._addOutputValue("audio",e),null===(n=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_AUDIO_BITRATE_O,JSON.stringify({status:C.SUCCESSED,bitrate:e})),this):(null===(a=null===(s=null===(o=this._invoker.store)||void 0===o?void 0:o.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_AUDIO_BITRATE_O,JSON.stringify({status:C.FAILED,msg:`params error -> bitrate: ${e}`})),this)}setOutputBackgroundColor(e){var t,i,r,n,o,s;return/^0x[a-fA-F0-9]{6}$/.test(e)?(this._addOutputValue("video",e,"backgroundColor"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_COLOR_O,JSON.stringify({status:C.SUCCESSED,color:e})),this):(null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_COLOR_O,JSON.stringify({status:C.FAILED,msg:`params error -> color: ${e}`})),this)}addOutputBackgroundPicture(e,i,r,n,o){var s,a,c,d,_,l,u,h,g,p,R,m;if(!v(e))return null===(c=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:C.FAILED,msg:`params error -> uri: ${e}`})),this;if([i,r,n,o].some((e=>!t(e)||e<0||e>1)))return null===(l=null===(_=null===(d=this._invoker.store)||void 0===d?void 0:d.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:C.FAILED,msg:`params of (x, y, w, h) error -> x: ${i}, y: ${r}, w: ${n}, h: ${o}`})),this;const I=(null===(g=null===(h=null===(u=this._values.output)||void 0===u?void 0:u.video)||void 0===h?void 0:h.backgroundPicture)||void 0===g?void 0:g.picture)||[];return I.push({uri:e,w:n,h:o,x:i,y:r}),this._addOutputValue("video",{picture:I},"backgroundPicture"),null===(m=null===(R=null===(p=this._invoker.store)||void 0===p?void 0:p.context)||void 0===R?void 0:R.logger)||void 0===m||m.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:C.SUCCESSED,uri:e,x:i,y:r,w:n,h:o})),this}removeOutputBackgroundPicture(e){var t,i,r,n,o,s,a,c,d;if(!v(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_REMOVE_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:C.FAILED,msg:`params error -> uri: ${e}`})),this;let _=null===(s=null===(o=null===(n=this._values.output)||void 0===n?void 0:n.video)||void 0===o?void 0:o.backgroundPicture)||void 0===s?void 0:s.picture;return _&&(_=_.filter((t=>t.uri!==e)),this._addOutputValue("video",{pictures:_},"backgroundPicture")),null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_REMOVE_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:C.SUCCESSED,uri:e})),this}clearOutputBackgroundPicture(){var e,t,i;return this._addOutputValue("video",{pictures:[]},"backgroundPicture"),null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_CLEAR_OUTPUT_BACKGROUND_PICTURE_O),this}setOutputBackgroundPictureFillMode(e){var t,i,r,n,o,s;return[Us.CROP,Us.WHOLE].includes(e)?(this._addOutputValue("video",{fillMode:e},"backgroundPicture"),null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:C.SUCCESSED,fillMode:e})),this):(null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:C.FAILED,msg:`params error -> fillMode: ${e}`})),this)}addPublishStreamUrls(e){var t,i,r,n,o,a,c,d,_,l,u;const h=/^rtmp:\/\/.+/;if(!s(e)||0===e.length||e.some((e=>!h.test(e))))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:C.FAILED,msg:`params error -> urls: ${e.join(",")}`})),this;const g=(null===(o=null===(n=this._values.output)||void 0===n?void 0:n.cdn)||void 0===o?void 0:o.concat())||[];let v=!1;return e.forEach((e=>{g.some((t=>t.pushurl===e))||(v=!0,g.push({pushurl:e}))})),g.length>5?(null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:C.FAILED,msg:`params error -> publish stream urls no more than 5, length: ${e.length}`})),this):(v&&this._addOutputValue("cdn",g),null===(u=null===(l=null===(_=this._invoker.store)||void 0===_?void 0:_.context)||void 0===l?void 0:l.logger)||void 0===u||u.info(f.L_MCU_CONFIG_BUILDER_ADD_PUBLISH_STREAM_URLS_O,JSON.stringify({status:C.SUCCESSED,urls:e})),this)}removePublishStreamUrls(e){var t,i,r,n,o,a,c,d;const _=/^rtmp:\/\/.+/;if(!s(e)||0===e.length||e.some((e=>!_.test(e))))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_REMOVE_PUBLISH_STREAM_URLS_O,JSON.stringify({status:C.FAILED,msg:`params error -> urls: ${e.join(",")}`})),this;const l=(null===(o=null===(n=this._values.output)||void 0===n?void 0:n.cdn)||void 0===o?void 0:o.concat())||[];for(let t=l.length-1;t>=0;t-=1){const{pushurl:i}=l[t],r=e.indexOf(i);r>=0&&(e.splice(r,1),l.splice(t,1))}return this._addOutputValue("cdn",l),null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_REMOVE_PUBLISH_STREAM_URLS_O,JSON.stringify({status:C.SUCCESSED,urls:e})),this}clearPublishStreamUrls(){var e,t,i;return this._addOutputValue("cdn",[]),null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_CLEAR_PUBLISH_STREAM_URLS_O),this}addCustomizeLayoutVideo(e,i,r,n,o){var s,a,c,d,l,u,h,g,v,p,R,m,I,E,S,T,O,L;if(!_(e)||!this._isValidTrackId(e))return null===(c=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;if(!t(i)||!t(r))return null===(u=null===(l=null===(d=this._invoker.store)||void 0===d?void 0:d.context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`params x or y is error -> x: ${i}, y: ${r}`})),this;if([n,o].some((e=>!t(e)||e<0)))return null===(v=null===(g=null===(h=this._invoker.store)||void 0===h?void 0:h.context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`params width or height error -> width: ${n}, height: ${o}`})),this;const{userId:N,tag:A,mediaType:y}=Ct(e);if(y!==Je.VIDEO_ONLY)return null===(m=null===(R=null===(p=this._invoker.store)||void 0===p?void 0:p.context)||void 0===R?void 0:R.logger)||void 0===m||m.error(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`type of trackId: ${e} is not video`})),this;const k=Ot(N,A),D=this._values.input||(this._values.input={}),b=D.video||(D.video=[]);return b.some((e=>e.height===o&&e.width===n&&e.stream_id===k&&e.user_id===N&&e.x===i&&e.y===r))?(null===(S=null===(E=null===(I=this._invoker.store)||void 0===I?void 0:I.context)||void 0===E?void 0:E.logger)||void 0===S||S.warn(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:"Duplicate configuration item place ignored"})),this):(b.push({user_id:N,stream_id:k,x:i,y:r,width:n,height:o}),null===(L=null===(O=null===(T=this._invoker.store)||void 0===T?void 0:T.context)||void 0===O?void 0:O.logger)||void 0===L||L.info(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.SUCCESSED,trackId:e,x:i,y:r,width:n,height:o})),this)}removeCustomizeLayoutVideo(e){var t,i,r,n,o,s,a,c,d;if(!this._isValidTrackId(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;const{userId:_,tag:l,mediaType:u}=Ct(e);if(u!==Je.VIDEO_ONLY)return null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.FAILED,msg:`type of trackId: ${e} is not video`})),this;const h=Ot(_,l),{input:g}=this._values;return(null==g?void 0:g.video)&&g.video.length>0&&(g.video=g.video.filter((e=>e.stream_id===h))),null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:C.SUCCESSED,trackId:e})),this}clearCustomizeLayoutVideo(){var e,t,i;const{input:r}=this._values;return null==r||delete r.video,null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_LAYOUT_VIDEO_O),this}setCustomizeInputAudio(e){var t,i,r,n,o,s;if(e.some((e=>this._isValidTrackId(e))))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_SET_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.FAILED,msg:`trackIds contain invalid item -> trackIds: ${e.join(",")}`})),this;return(this._values.input||(this._values.input={})).audio=e.map((e=>{const{userId:t,tag:i}=Ct(e);return{stream_id:Ot(t,i),user_id:t}})),this._values.inputFilterMode=xs.AUDIO_INPUT_VIDEO_ALL,null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_MCU_CONFIG_BUILDER_SET_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.SUCCESSED,trackIds:e})),this}addCustomizeInputAudio(e){var t,i,r,n,o,s,a,c,d;if(!this._isValidTrackId(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;const _=this._values.input||(this._values.input={}),l=_.audio||(_.audio=[]),{userId:u,tag:h}=Ct(e),g=Ot(u,h);return l.some((e=>e.stream_id===g&&e.user_id===u))?(null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.warn(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.FAILED,msg:`trackId: ${e} is exist`})),this):(l.push({user_id:u,stream_id:g}),this._values.inputFilterMode=xs.AUDIO_INPUT_VIDEO_ALL,null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.SUCCESSED,trackId:e})),this)}removeCustomizeInputAudio(e){var t,i,r,n,o,s,a,c,d;if(!this._isValidTrackId(e))return null===(r=null===(i=null===(t=this._invoker.store)||void 0===t?void 0:t.context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;const{input:_}=this._values;if(!(null==_?void 0:_.audio)||0===_.audio.length)return null===(s=null===(o=null===(n=this._invoker.store)||void 0===n?void 0:n.context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.FAILED,msg:`type of trackId: ${e} is not audio`})),this;const{userId:l,tag:u}=Ct(e),h=Ot(l,u);return _.audio=_.audio.filter((e=>l!==e.user_id||h!==e.stream_id)),null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:C.SUCCESSED,trackId:e})),this}clearCustomizeInputAudio(){var e,t,i;const{input:r}=this._values;return(null==r?void 0:r.audio)&&delete r.audio,this._values.inputFilterMode=xs.AUDIO_VIDEO_ALL,null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_INPUT_AUDIO_O),this}addPictureWaterMark(e,i,r,n,o,s){var a,c,d,_,l,u,h,g,p,R,m,I;if(!this._isValidTrackId(e))return null===(d=null===(c=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;if(!v(i))return null===(u=null===(l=null===(_=this._invoker.store)||void 0===_?void 0:_.context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:C.FAILED,msg:`params error -> uri: ${i}`})),this;if([r,n,o,s].some((e=>!t(e)||e<0||e>1))||r+o>1||n+s>1)return null===(p=null===(g=null===(h=this._invoker.store)||void 0===h?void 0:h.context)||void 0===g?void 0:g.logger)||void 0===p||p.error(f.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:C.FAILED,msg:`some attrs of (x, y, w, h) is invalid -> x: ${r}, y: ${n}, w: ${o}, h: ${s}`})),this;const{userId:E,tag:S}=Ct(e),T=Ot(E,S),O=this._values.waterMark||(this._values.waterMark={enable:"on",singleScreen:[]}),{singleScreen:L}=O,N=L.filter((e=>e.streamId===T))[0];return N?N.picture.push({uri:i,w:o,h:s,x:r,y:n}):L.push({streamId:T,picture:[{uri:i,w:o,h:s,x:r,y:n}]}),this._values.waterMark.singleScreen=L,null===(I=null===(m=null===(R=this._invoker.store)||void 0===R?void 0:R.context)||void 0===m?void 0:m.logger)||void 0===I||I.info(f.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:C.SUCCESSED,trackId:e,uri:i,x:r,y:n,w:o,h:s,singleScreen:L})),this}clearPictureWaterMark(){var e,t,i;return(this._values.waterMark||(this._values.waterMark={enable:"on",singleScreen:[]})).singleScreen=[],null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_CLEAR_OUTPUT_BACKGROUND_PICTURE_O),this}removePictureWaterMark(e,t){var i,r,n,o,s,a;if(!_(e)||!this._isValidTrackId(e))return null===(n=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_MCU_CONFIG_BUILDER_REMOVE_SINGLE_WATER_MARK_O,JSON.stringify({status:C.FAILED,msg:`params error -> trackId: ${e}`})),this;const{userId:c,tag:d}=Ct(e),l=Ot(c,d),u=this._values.waterMark||(this._values.waterMark={enable:"on",singleScreen:[]}),{singleScreen:h}=u;return h.forEach((e=>{e.streamId===l&&(e.picture=e.picture.filter((e=>e.uri!==t)))})),null===(a=null===(s=null===(o=this._invoker.store)||void 0===o?void 0:o.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_MCU_CONFIG_BUILDER_REMOVE_SINGLE_WATER_MARK_O,JSON.stringify({status:C.SUCCESSED,trackId:e,uri:t})),this}reset(){var e,t,i;return this._values=ws(),null===(i=null===(t=null===(e=this._invoker.store)||void 0===e?void 0:e.context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_MCU_CONFIG_BUILDER_RESET_O),this}flush(e=!0){return S(this,void 0,void 0,(function*(){const t=JSON.parse(JSON.stringify(this._values)),{code:i}=yield this._invoker.push(new bs(t,this._values));return e&&(this._values=ws()),{code:i}}))}__innerGetValues(){return JSON.parse(JSON.stringify(this._values))}}var Vs,Fs,Js;!function(e){e[e.VIDEO=0]="VIDEO",e[e.AUDIO=1]="AUDIO"}(Vs||(Vs={}));class Gs extends Ho{constructor(e,t,i,r){super(),this.roomId=e,this.hooks=t,this.roomPKHandler=i,this.traceId=r}_exchangeWithPushOtherRoom(e,t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){if(!e.getLocalTracks().length)return void(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.SUCCESSED,msg:"have not published resource"}),this.traceId));const _=Object.values(e.peerMgr.getMutilPeerCData()),l=Object.keys(e.peerMgr.getMutilPeerCData());for(let i=0;i<_.length;i++){const{pc:r,isPub:u}=_[i],h=u&&e.useMutilPeerC?[]:e.getSubscribedList(),g=yield ts(h,!1,r,e),{pushOtherRooms:v,headers:p}=this.hooks(l[i]);g.pushOtherRooms=v;const R=yield new Qo(p,g,this.traceId,!0).execute(e,t);if(R.code!==T.SUCCESS)return void(null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.FAILED,code:R.code,pushOtherRooms:v}),this.traceId));const{sdp:m,resultCode:I}=R.data;if(I!==T.SUCCESS)return void(null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.FAILED,code:I,pushOtherRooms:v}),this.traceId));null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.SUCCESSED,pushOtherRooms:v}),this.traceId),r.setRemoteAnswer(m.sdp)}}))}get kind(){return po.EXCHANGE_WITH_PUSH_OTHER_ROOM}execute(e,t){var i,r,n,o,s,a;return S(this,void 0,void 0,(function*(){const{roomId:c}=this;if(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_EXCHANGE_WITH_PUSHOTHERROOM_T,JSON.stringify({roomId:c})),!this.roomPKHandler)return void(null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.FAILED,msg:"_roomPKHandler not exist"}),this.traceId));this.roomPKHandler.getPKInfo(c)?yield this._exchangeWithPushOtherRoom(e,t):null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:C.FAILED,msg:"PKInfo not exist"}),this.traceId)}))}}class Hs extends Ho{constructor(e,t,i,r,n,o,s){super(),this.pkHandler=e,this.room=t,this._PKInfo=i,this.hooks=r,this._joinedPKRooms=n,this.isQuitPK=o,this.traceId=s}get kind(){return po.LEAVE_OTHER_ROOM}quitRoomPK(e,t,i){var r,o,s,a,c,d,_,l;return S(this,void 0,void 0,(function*(){if(null===(o=null===(r=null==t?void 0:t.context)||void 0===r?void 0:r.logger)||void 0===o||o.info(f.L_QUIT_PK_T,`roomId: ${e}`,i),!this._PKInfo[e])return void(null===(a=null===(s=null==t?void 0:t.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_QUIT_PK_R,`status: ${C.FAILED}, msg: pkinfo is empty`,i));const{inviterRoomId:u,inviteeRoomId:h,inviterUserId:g,inviteSessionId:v}=this._PKInfo[e],p={inviteeRoomId:h,inviterRoomId:u,userId:t.crtUserId},R={roomId:t.roomId,endRoomId:e,sessionId:v,content:JSON.stringify(p),keys:[`${u}|${g}`]},m=yield t.context.endRoomPK(R);return m!==n.SUCCESS?(null===(d=null===(c=null==t?void 0:t.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_QUIT_PK_R,`status: ${C.FAILED}, code: ${m}`,i),{code:T.SIGNAL_ERROR}):(null===(l=null===(_=null==t?void 0:t.context)||void 0===_?void 0:_.logger)||void 0===l||l.info(f.L_QUIT_PK_R,`status: ${C.SUCCESSED}`,i),delete this._PKInfo[e],{code:T.SUCCESS})}))}execute(e,t){var i,r,n,o;return S(this,void 0,void 0,(function*(){const{room:s,isQuitPK:a}=this,c=s.getRoomId();return null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_LIVING_ROOM_LEAVE_PK_ROOM_T,JSON.stringify({roomId:c,isQuitPK:a}),this.traceId),yield s.__destroy(!0),delete this._joinedPKRooms[c],yield new Gs(c,this.hooks,this.pkHandler,this.traceId).execute(e,t),a&&this.quitRoomPK(c,e,this.traceId),null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_LIVING_ROOM_LEAVE_PK_ROOM_R,JSON.stringify({status:C.SUCCESSED}),this.traceId),{code:T.SUCCESS}}))}}class Ks{constructor(e,t,i,r,n,o,s,a,c,d,_){this._invoker=e,this._PKInfo=t,this._hooks=i,this._context=r,this._runtime=n,this._service=o,this._initOptions=s,this._mainLivingRoom=a,this._registerPKMsgListener=c,this._onJoinedPKRoom=d,this._clientSessionId=_,this._inviteTimeout=30,this._appListener=null,this._joinedPKRooms={},this._registerPKMsgListener(this._onRecvPKMsg.bind(this)),this._mainRoomId=this._mainLivingRoom.getRoomId()}_callAppListener(e,...t){var i,r,n;const o=null===(i=this._appListener)||void 0===i?void 0:i[e];if(o)try{o(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify(e))}}_onInvite(e){var t,i;const r=e.inviteInfo||{},{inviterRoomId:n,inviterUserId:o,extra:s}=r,a={inviterRoomId:n,inviterUserId:o,extra:s};this._PKInfo[n]=r,null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onRequestJoinOtherRoom",info:a})),this._callAppListener("onRequestJoinOtherRoom",a)}_onCancelInvite(e){var t,i;const{inviterRoomId:r,inviterUserId:n,extra:o}=e.inviteInfo||{},s={inviterRoomId:r,inviterUserId:n,extra:o};delete this._PKInfo[r],null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onCancelRequestOtherRoom",cancelInfo:s})),this._callAppListener("onCancelRequestOtherRoom",s)}_onInviteTimeout(e){}_onInviteAnswer(e){var t,i;const{answerCode:r,inviteContent:n}=e,{inviteSessionId:o,inviterUserId:s,inviterRoomId:a,inviteeUserId:c,inviterUserAutoMix:d,inviteeUserAutoMix:_,inviteeRoomId:l,extra:u}=n,h={agree:1===r,inviterRoomId:a,inviterUserId:s,inviteeRoomId:l,inviteeUserId:c,extra:u};this._PKInfo[l]=this._PKInfo[l]||{inviteSessionId:o,inviterRoomId:a,inviterUserId:s,inviterUserAutoMix:d,inviteeRoomId:l},this._PKInfo[l].inviteeUserAutoMix=_,null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onResponseJoinOtherRoom",answerInfo:h})),this._callAppListener("onResponseJoinOtherRoom",h)}createLeaveOtherRoomCommand(e,t,i){return new Hs(this,e,this._PKInfo,this._hooks,this._joinedPKRooms,t,i)}_onPKEnd(e){var t,i,r,n,o,s;return S(this,void 0,void 0,(function*(){const{inviteeRoomId:a,inviterRoomId:c,userId:d}=e.inviteInfo,_=c===this._mainRoomId?a:c,l={endRoomId:_,endUserId:d},u=this._joinedPKRooms[_],h=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_QUIT_PK_LEAVE_PK_ROOM_O,void 0,h),u&&(yield this._invoker.push(this.createLeaveOtherRoomCommand(u,!0,h))),delete this._PKInfo[_],null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onFinishOtherRoom",endInfo:l})),this._callAppListener("onFinishOtherRoom",l)}))}_onRecvPKMsg(e){const{targetId:t,content:i,messageType:r}=e;switch(r){case Jt.PK_INVITE:this._onInvite(i);break;case Jt.PK_CANCEL_INVITE:this._onCancelInvite(i);break;case Jt.PK_INVITE_TIMEOUT:this._onInviteTimeout(i);break;case Jt.PK_INVITE_ANSWER:this._onInviteAnswer(i);break;case Jt.PK_END:this._onPKEnd(i)}}registerRoomPKEventListener(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_LIVING_PK_HANDLER_REGISTER_ROOM_PK_EVENT_LISTENER_O,JSON.stringify({listener:e&&Object.keys(e)})),this._appListener=e}requestJoinOtherRoom(e,t,r){var o,s,a,c,d,l,u,h,g,v;return S(this,void 0,void 0,(function*(){const R=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();if(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_T,JSON.stringify({inviteeRoomId:e,inviteeUserId:t,options:r}),R),!i("inviteeRoomId",e,_,!0)||!i("inviteeUserId",t,_,!0))return null===(l=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===l||l.error(f.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> inviteeRoomId or inviteeUserId"}),R),{code:T.PARAMS_ERROR};const m=Wn(),I=!p(null==r?void 0:r.autoMix)||(null==r?void 0:r.autoMix),E={inviteSessionId:m,inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviterUserAutoMix:I,inviteeRoomId:e,inviteeUserId:t,inviteeTimeoutTime:this._inviteTimeout,extra:(null==r?void 0:r.extra)||""},S={roomId:this._mainRoomId,invitedRoomId:e,invitedUserId:t,inviteTimeout:this._inviteTimeout,inviteInfo:JSON.stringify(E),inviteSessionId:m},O=yield this._context.requestRoomPK(S);return O!==n.SUCCESS?(null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(f.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:O}),R),{code:O}):(this._PKInfo[e]={inviteSessionId:m,inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviterUserAutoMix:I,inviteeRoomId:e},null===(v=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===v||v.info(f.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.SUCCESSED}),R),{code:T.SUCCESS})}))}cancelRequestJoinOtherRoom(e,t,r){var o,s,a,c,d,l,u,h,g,v,p,R;return S(this,void 0,void 0,(function*(){const m=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();if(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_T,JSON.stringify({inviteeRoomId:e,inviteeUserId:t,extra:r}),m),!i("inviteeRoomId",e,_,!0)||!i("inviteeUserId",t,_,!0))return null===(l=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===l||l.error(f.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> inviteeRoomId or inviteeUserId"}),m),{code:T.PARAMS_ERROR};if(!this._PKInfo[e])return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(f.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:`The request to connect with ${t} user in room ${e} is not initiated`}),m),{code:T.PARAMS_ERROR};const I={inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviteeRoomId:e,inviteeUserId:t,extra:r||""},E={roomId:this._mainRoomId,invitedRoomId:e,invitedUserId:t,inviteSessionId:this._PKInfo[e].inviteSessionId,inviteInfo:JSON.stringify(I)},S=yield this._context.cancelRoomPK(E);return S!==n.SUCCESS?(null===(v=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:S}),m),{code:S}):(null===(R=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===R||R.info(f.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.SUCCESSED}),m),delete this._PKInfo[e],{code:T.SUCCESS})}))}responseJoinOtherRoom(e,t,r,o){var s,a,c,d,l,u,h,g,v,m,I,E;return S(this,void 0,void 0,(function*(){const S=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_T,JSON.stringify({inviterRoomId:e,inviterUserId:t,agree:r,options:o}),S),!i("inviterRoomId",e,_,!0)||!i("inviterUserId",t,_,!0))return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> inviterRoomId or inviterUserId"}),S),{code:T.PARAMS_ERROR};if(!this._PKInfo[e])return null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.error(f.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:`User ${t} in room ${e} did not send a request for connection`}),S),{code:T.PARAMS_ERROR};const{inviteSessionId:O,inviterUserAutoMix:L}=this._PKInfo[e],N=!p(null==o?void 0:o.autoMix)||(null==o?void 0:o.autoMix),A={inviteSessionId:O,inviterRoomId:e,inviterUserId:t,inviterUserAutoMix:L,inviteeRoomId:this._mainRoomId,inviteeUserId:this._context.getCurrentId(),inviteeUserAutoMix:N},y=Object.assign(A,{inviterUserAutoMix:L}),k=r?Object.assign(A,{MultiRoomKey:`${e}|${this._mainRoomId}`,MultiRoomValue:JSON.stringify(y)}):A;!R(null==o?void 0:o.extra)&&Object.assign(k,{extra:o.extra});const D={agree:r,roomId:this._mainRoomId,inviteSessionId:O,inviteRoomId:e,inviteUserId:t,content:JSON.stringify(k),key:`${e}|${this._mainRoomId}`,value:JSON.stringify(A)},b=yield this._context.responseRoomPK(D);return b!==n.SUCCESS?(null===(m=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===m||m.error(f.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:b}),S),{code:b}):(null===(E=null===(I=this._context)||void 0===I?void 0:I.logger)||void 0===E||E.info(f.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.SUCCESSED}),S),this._PKInfo[e].inviteeUserAutoMix=N,{code:T.SUCCESS})}))}joinOtherRoom(e){var t,r,n,o,s,c,d,l,u,h,g,v,p,R;return S(this,void 0,void 0,(function*(){const m=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId();if(null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_T,JSON.stringify({roomId:e}),m),!i("roomId",e,_,!0))return null===(c=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===c||c.error(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> roomId"}),m),{code:T.PARAMS_ERROR};if(this._context.getConnectionStatus()!==a.CONNECTED)return null===(l=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===l||l.error(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.SIGNAL_DISCONNECTED,msg:"IM disconnected"}),m),{code:T.SIGNAL_DISCONNECTED};if(this._joinedPKRooms[e])return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.warn(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),m),{code:T.REPERT_JOIN_ROOM};const I=Vs.VIDEO,E={extra:`{"roomId": "${this._mainRoomId}"}`},S=new Ws(this._context,this._runtime,e,this._service,this._initOptions,I,!1,!1,!1,this._clientSessionId),{code:O,data:L}=yield S.__innerInit(Eo.LIVE,void 0,I,E);return O!==T.SUCCESS?(null===(v=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.FAILED,code:O}),m),{code:O}):(this._joinedPKRooms[e]=S,yield this._onJoinedPKRoom(e,m),null===(R=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===R||R.info(f.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:C.SUCCESSED}),m),{room:S,code:T.SUCCESS,userIds:S.getRemoteUserIds(),tracks:S.getRemoteTracks()})}))}leaveOtherRoom(e,t){var i,r,n,o;return S(this,void 0,void 0,(function*(){const s=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_APP_CALL_LEAVE_PK_ROOM_O,void 0,s),this._invoker.push(this.createLeaveOtherRoomCommand(e,t,s))}))}getPKInfo(e){return this._PKInfo[e]}getAllPKInfo(){return this._PKInfo}getJoinedPKRooms(){return this._joinedPKRooms}}!function(e){e[e.OPEN=1]="OPEN",e[e.STOP=2]="STOP"}(Fs||(Fs={}));class js extends Ho{constructor(e,t){super(),this.cdnValues=e,this.enable=t}get kind(){return po.ENABLE_INNER_CDN}execute(e,t){var i,r,n,o,s,a,c,d,_,l,u,h,g,v;return S(this,void 0,void 0,(function*(){const{enable:R}=this;if(null===(r=null===(i=e.context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_LIVING_ROOM_ENABLE_INNER_CDN_T,JSON.stringify({roomId:e.roomId,enable:R})),!e.isMainRoom)return null===(o=null===(n=e.context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.FAILED,code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM};if(!p(R))return null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> enable"})),{code:T.PARAMS_ERROR};e.setCDNEnabel(R);const m={version:2,output:{inCDNModel:R?Fs.OPEN:Fs.STOP}},{code:I}=yield new bs(m,this.cdnValues).execute(e,t);if(I!==T.SUCCESS)return null===(d=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.FAILED,code:I,msg:"signal error"})),{code:T.SIGNAL_ERROR};const E=e.getCDNUris();if(E&&E.broadcast!==Co.SPREAD)return null===(l=null===(_=e.context)||void 0===_?void 0:_.logger)||void 0===l||l.info(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.SUCCESSED,enable:R})),{code:T.SUCCESS};const{code:S}=yield ns(e);return S===T.SUCCESS?(null===(h=null===(u=e.context)||void 0===u?void 0:u.logger)||void 0===h||h.info(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.SUCCESSED,enable:R})),{code:T.SUCCESS}):(null===(v=null===(g=e.context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:C.FAILED,code:S})),{code:S})}))}}!function(e){e[e.AnchorToViewer=1]="AnchorToViewer",e[e.ViewerToAnchor=2]="ViewerToAnchor"}(Js||(Js={}));class $s extends Ho{constructor(e,t){super(),this.livingType=e,this.traceId=t}get kind(){return po.RTC_IDENTITY_CHANGE}execute(e,t){var i;return S(this,void 0,void 0,(function*(){const{code:r,data:o}=yield e.context.rtcIdentityChange(e.roomId,Js.ViewerToAnchor,this.livingType);if(r!==n.SUCCESS||!o)return{code:r};e.initWithRoomData(o,this.traceId);e.getResourcesByUserId(e.crtUserId).length>0&&t.push(new qo);const s=null===(i=o.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===i?void 0:i.value;return s&&e.setCDNUris(JSON.parse(s)[0]),{code:r,data:o}}))}}class Ws extends Ds{constructor(e,t,i,r,n,o,s,a,c,d){super(e,t,i,Eo.LIVE,r,n,s,a,c,d),this._livingType=o,this._mcuConfigBuilder=new Bs(this._invoker,this._isValidResourceId.bind(this))}_initRoomPKHandler(e){if(this._store.isMainRoom){const t=((e,t)=>{const i={};return t.forEach((t=>{const r=JSON.parse(t.value),{inviterRoomId:n,inviteeRoomId:o}=r;i[e===n?o:n]=JSON.parse(t.value)})),i})(this._roomId,e.roomInfo);this._roomPKHandler=new Ks(this._invoker,t,(e=>({headers:this._getRTCReqestHeaders(e),pushOtherRooms:this._getPushOtherRoomsParams()})),this._context,this._runtime,this._service,this._initOptions,this,super._registerPKMsgListener.bind(this),this._onJoinedPKRoom.bind(this),this._clientSessionId)}}__innerInit(e,t,r,n,o,s){const a=Object.create(null,{__innerInit:{get:()=>super.__innerInit}});var c,d;return S(this,void 0,void 0,(function*(){if(!i("livingType",r,(e=>e===Vs.AUDIO||e===Vs.VIDEO)))return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> livingType"}),s),{code:T.PARAMS_ERROR};const{code:_,data:l}=yield a.__innerInit.call(this,e,t,r,n,o,s);return _===T.SUCCESS&&l&&this._initRoomPKHandler(l),{code:_,data:l}}))}__innerInitByIdentityChange(e){var t,i,r,o;return S(this,void 0,void 0,(function*(){const{code:s,data:a}=yield this._invoker.push(new $s(this._livingType,e));return s===n.SUCCESS&&a?(this._initRoomPKHandler(a),this._initWithRoomData(a.offlineKickTime),null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:C.SUCCESSED,roomData:a}),e)):null===(o=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===o||o.error(f.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:C.FAILED,code:s}),e),s}))}publish(e){const t=Object.create(null,{publish:{get:()=>super.publish}});var i,r;return S(this,void 0,void 0,(function*(){return this._store.isMainRoom?t.publish.call(this,e):(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:C.FAILED,code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}))}unpublish(e){const t=Object.create(null,{unpublish:{get:()=>super.unpublish}});var i,r;return S(this,void 0,void 0,(function*(){return this._store.isMainRoom?t.unpublish.call(this,e):(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:C.FAILED,code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}))}_isValidResourceId(e){var t;const{userId:i}=Ct(e),r=!!(null===(t=this._store.getResourcesByUserId(i))||void 0===t?void 0:t.find((t=>ft(t)===e)));let n=!1;const{code:o,roomPKHandler:s}=this.getRoomPKHandler();if(o!==T.SUCCESS||!s)return r;const a=s.getJoinedPKRooms(),c=[];return Object.values(a).forEach((e=>{c.push(...e.getRemoteTracks())})),n=c.some((t=>e===t.getTrackId())),r||n}getLivingType(){return this._livingType}getMCUConfigBuilder(){var e,t;return this._store.isMainRoom?this._mcuConfigBuilder:(null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.error(f.L_LIVING_ROOM_GET_MCU_CONFIG_BUILDER_O,"the `getMCUConfigBuilder` is disabled in PK room"),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}enableInnerCDN(e){return S(this,void 0,void 0,(function*(){return this._invoker.push(new js(this._mcuConfigBuilder.__innerGetValues(),e))}))}_resourceHandle(e,t,i,r,n){const o=Object.create(null,{_resourceHandle:{get:()=>super._resourceHandle}});return S(this,void 0,void 0,(function*(){o._resourceHandle.call(this,e,t,i,r,n)}))}__getCDNEnable(){var e;return!!(null===(e=this._store.getCDNUris())||void 0===e?void 0:e.enableInnerCDN)}__getCDNPushMode(){var e;return null===(e=this._store.getCDNUris())||void 0===e?void 0:e.push_mode}_onJoinedPKRoom(e,t){return S(this,void 0,void 0,(function*(){this._invoker.push(new Gs(e,(e=>({pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(e)})),this._roomPKHandler,t))}))}_getPushOtherRoomsParams(){const e=[];if(!this.isMainRoom()||!this._roomPKHandler)return e;const t=this._roomPKHandler.getJoinedPKRooms();for(const i in t){const r=t[i].getSessionId(),n=this._roomPKHandler.getPKInfo(i);if(!n)continue;const{inviterUserAutoMix:o,inviteeUserAutoMix:s,inviterUserId:a}=n,c=this._context.getCurrentId()===a;e.push({roomId:i,sessionId:r,autoMix:c?!!o:!!s})}return e}getRoomPKHandler(){var e,t,i,r;return this._store.isMainRoom?(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_LIVING_ROOM_GET_ROOM_PK_HANDLER_O,JSON.stringify({status:C.SUCCESSED})),{code:T.SUCCESS,roomPKHandler:this._roomPKHandler}):(null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.error(f.L_LIVING_ROOM_GET_ROOM_PK_HANDLER_O,JSON.stringify({status:C.SUCCESSED,code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}_quitAllPKRoom(){var e,t;return S(this,void 0,void 0,(function*(){const i=this._roomPKHandler.getJoinedPKRooms();for(const e in i)this._roomPKHandler.leaveOtherRoom(i[e]);null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_LIVING_ROOM_QUIT_ALL_PK_ROOM_O,JSON.stringify({status:C.SUCCESSED,roomIds:Object.keys(i)}))}))}isMainRoom(){return this._store.isMainRoom}}class Ys extends Ds{constructor(e,t,i,r,n,o,s,a,c,d=Eo.RTC,_=3e4){super(e,t,i,d,r,n,o,s,a,c,_)}}const qs=new class{constructor(){this.queue=[],this.locked=!1,this.taskCount=0}checkToStart(){return S(this,void 0,void 0,(function*(){if(0===this.queue.length||this.locked)return;this.locked=!0;const{resolve:e,task:t,reject:i}=this.queue.shift();let r;try{r=yield t(),e(r)}catch(e){i(e)}this.locked=!1,this.checkToStart()}))}push(e,t=""){const i=new Promise(((t,i)=>{this.queue.push({resolve:t,task:e,reject:i})}));return this.checkToStart(),i}},zs=(e,t="")=>qs.push(e,t);class Qs{constructor(e,t,i,r){this._context=e,this._useMutilPeerC=r,this._rtcToken="",this._liveUrl="",this._subTracks=[],this._subscribedList=[],this._clientSessionId=Wn(),this._livingType=null,this._mediaType=null,this._subTiny=!1,this._fromRetry=!1,this._appListener=null,this._crtUserId=this._context.getCurrentId(),this._service=new Zn(t,e,i.mediaServer),this._peerCManager=new Go(this._useMutilPeerC,this._crtUserId,this._reTryExchange.bind(this),this._crtUserId,void 0,!1,i,!0),this._store=new $o(this._context,this._service,this._peerCManager,this._crtUserId,this._crtUserId),this._peerCManager.setStore(this._store)}_getReqHeaders(e){return S(this,void 0,void 0,(function*(){const t=this._crtUserId;if(!this._rtcToken){const{code:i,data:r}=yield this._context.getRTCToken(t,Eo.LIVE,e);if(i!==n.SUCCESS)return{code:T.SIGNAL_ERROR};this._rtcToken=r.rtcToken}const i=this._useMutilPeerC?{"Peer-Connection-Id":this._pcName}:{};return{code:T.SUCCESS,headers:Object.assign({"App-Key":this._context.getAppkey(),UserId:this._crtUserId,RoomId:t,RoomType:Eo.LIVE,Token:this._rtcToken,"Client-Session-Id":this._clientSessionId},i)}}))}_clearSubscribeInfo(){var e;this._liveUrl="",this._livingType=null,this._mediaType=null,this._subTiny=!1,this._subTracks.length=0,null===(e=this._pc)||void 0===e||e.destroy(),this._pc=null}_reTryExchange(){var e;return S(this,void 0,void 0,(function*(){this._fromRetry=!0;const{code:t}=yield this.subscribe(this._liveUrl,this._livingType,this._mediaType,this._subTiny);t===T.SUCCESS&&(null===(e=this._pc)||void 0===e||e.clearReTryExchangeTimer())}))}subscribe(e,t,i,r=!1){return S(this,void 0,void 0,(function*(){return zs((()=>this.__subscribe(e,t,i,r)),"audience-client-sub")}))}__subscribe(e,t,i,r=!1){var n,o,s,a,c,d,_,u,h,g,v,p,R,m,I,E,O,L,N,A,y,k,D;return S(this,void 0,void 0,(function*(){null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_AUDIENCE_CLIENT_SUBSCRIBE_T,JSON.stringify({liveUrl:e,livingType:t,mediaType:i,subTiny:r}));const S=[];if(wt(this._context.getNaviInfo()))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"})),{code:T.PACKAGE_ENVIRONMENT_ERROR,tracks:S};if(!this._fromRetry&&(null===(c=this._pc)||void 0===c||c.clearReTryExchangeTimer()),this._fromRetry=!1,!l(e))return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:`params error -> liveUrl: ${e}`})),{code:T.PARAMS_ERROR,tracks:S};if(![Vs.AUDIO,Vs.VIDEO].includes(t))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(`livingType is invalid: ${t}`),null===(v=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:`params error -> livingType: ${t}`})),{code:T.PARAMS_ERROR,tracks:S};if(![Je.AUDIO_ONLY,Je.VIDEO_ONLY,Je.AUDIO_VIDEO].includes(i))return null===(R=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===R||R.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:`params error -> -> mediaType: ${i}`})),{code:T.PARAMS_ERROR,tracks:S};if(this._liveUrl&&this._liveUrl!==e)return null===(I=null===(m=this._context)||void 0===m?void 0:m.logger)||void 0===I||I.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.BROADCAST_SUB_LIST_NOT_EMPTY,msg:"repeat subscribe"})),{code:T.BROADCAST_SUB_LIST_NOT_EMPTY,tracks:S};if(!this._pc){const{pcName:e,pc:t}=this._peerCManager.createPeerCList(S)[0];this._pc=t,this._pcName=e,this._pc.on(Bo.__INNER_EVENT_TRACK_READY__,this._onTrackReady,this),this._pc.registerReportListener(this._reportListener),this._pc.__reportR3R4ToPolaris()}this._liveUrl=e;const{code:b,headers:U}=yield this._getReqHeaders(t);if(b!==T.SUCCESS)return null===(O=null===(E=this._context)||void 0===E?void 0:E.logger)||void 0===O||O.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:b,msg:"getRTCToken failed"})),{code:b,tracks:S};const P=`rc_mcu_${Date.now()}`,M="RongCloudRTC";0===this._subTracks.length&&(this._subTracks.push(new gt(M,P),new vt(M,P)),this._pc.updateSubRemoteTracks(this._subTracks.slice()));const x={sdp:yield this._pc.createOffer(!0),liveUrl:e,mediaType:i,simulcast:r?Xn.TINY:Xn.NORMAL,switchstream:!1},w=yield this._service.broadcastSubscribe(U,x);if(w.code!==T.SUCCESS)return null===(N=null===(L=this._context)||void 0===L?void 0:L.logger)||void 0===N||N.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:w.code})),{code:w.code,tracks:S};const B=w.data;if(B.resultCode!==T.SUCCESS)return null===(y=null===(A=this._context)||void 0===A?void 0:A.logger)||void 0===y||y.error(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:B.resultCode,msg:B.message})),{code:B.resultCode,tracks:S};this._livingType=t,this._mediaType=i,this._subTiny=r;const{sdp:V,subscribedList:F}=B;this._subscribedList=F;const J=[];return F.forEach((e=>{const{mediaType:t}=e,i=this._subTracks[t];J.push(i),i.__innerSetRemoteMuted(!0)})),this._pc.setRemoteAnswer(V.sdp),J&&this._updateTrackIdSSRCMap(V.sdp,J),null===(D=null===(k=this._context)||void 0===k?void 0:k.logger)||void 0===D||D.info(f.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:C.SUCCESSED,liveUrl:e})),{code:T.SUCCESS,tracks:J}}))}_updateTrackIdSSRCMap(e,t){t.forEach((t=>{const i=t.getTrackId(),{mediaType:r}=Ct(i),{msid:n}=this._subscribedList.filter((e=>e.mediaType===r))[0],o=_s(e,n,r);this._store.setTrackIdSSRCMap(Number(o),i)}))}unsubscribe(){return S(this,void 0,void 0,(function*(){return zs((()=>this.__unsubscribe()),"audience-client-unsub")}))}__unsubscribe(){var e,t,i,r,n,o,s,a,c;return S(this,void 0,void 0,(function*(){if(null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_AUDIENCE_CLIENT_UNSUBSCRIBE_T,JSON.stringify({liveUrl:this._liveUrl})),null===(i=this._pc)||void 0===i||i.clearReTryExchangeTimer(),!this._rtcToken||!this._liveUrl)return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.warn(f.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:"",msg:"Address does not exist, without unsubscribe"})),{code:T.SUCCESS};const{headers:d}=yield this._getReqHeaders(),{code:_}=yield this._service.broadcastExit(d);return _!==T.SUCCESS?null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:_})):(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:C.SUCCESSED,liveUrl:this._liveUrl})),this._subscribedList=[]),this._clearSubscribeInfo(),{code:_}}))}registerReportListener(e){this._reportListener=e}registerTrackEventListener(e){this._appListener=e}_onTrackReady(e){var t,i,r,n,o,s;const{track:a}=e.receiver,c="audio"===a.kind?Je.AUDIO_ONLY:Je.VIDEO_ONLY,d=this._subTracks[c];d.__innerSetMediaStreamTrack(a);try{null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_AUDIENCE_CLIENT_CALL_ONTRACKREADY_O,`trackId: ${d.getTrackId()}`),null===(n=null===(r=this._appListener)||void 0===r?void 0:r.onTrackReady)||void 0===n||n.call(r,d)}catch(e){null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_AUDIENCE_CLIENT_CALL_ONTRACKREADY_O,JSON.stringify(e))}}}var Zs,Xs;!function(e){e.RTMP="rtmp",e.FLV="flv",e.HLS="hls"}(Zs||(Zs={})),function(e){e[e.NOT_HTTPS=0]="NOT_HTTPS",e[e.HTTPS=1]="HTTPS"}(Xs||(Xs={}));const ea=Object.assign(Object.assign({},yt(Fe.W176_H144)),{frameRate:bt(Ve.FPS_15)});class ta{constructor(e,t,i,r,n,o,s,a=Wn()){this._context=e,this._runtime=t,this._initOptions=i,this._roomId=r,this._joinResData=n,this.livingType=o,this._useMutilPeerC=s,this._clientSessionId=a,this._roomAnchorList=[],this._roomRes={},this._roomAnchorRes={},this._remoteTracks={},this._appListener=null,this._pc=null,this._subscribedList=[],this._sessionId="",this._destroyed=!1,this._isPulling=!1,this._pullTime=0,this._actionStartTime=Date.now(),this._trackMediaMap={},this._reportListener=null,this._crtUserId=this._context.getCurrentId(),this._reportMediaActionLogger=new ys(this._roomId,this._clientSessionId,this._crtUserId),this._service=new Zn(this._runtime,this._context,this._initOptions.mediaServer,this._initOptions.timeout),this._polarisReport=new Fo(this._context,this._runtime,this._roomId,this,uo.Audience),this._polarisReport.sendR1(),this._peerCManager=new Go(this._useMutilPeerC,this._roomId,this._reTryExchange.bind(this),this._crtUserId,this._polarisReport,!0,this._initOptions,!0),this._context.registerRTCSignalListener((e=>S(this,void 0,void 0,(function*(){const{time:t,type:i,roomId:r}=this._context.decodeRtcNotify(e);if(1===i)this._startPull(r,t)})))),this._store=new $o(this._context,this._service,this._peerCManager,this._roomId,this._crtUserId,Eo.LIVE,this._polarisReport),this._peerCManager.setStore(this._store),this._setInitData()}_startPull(e,t){var i,r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){if(this._isPulling)return;this._isPulling=!0;if(this._pullTime>t)return void(this._isPulling=!1);const l=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_T,`pullTime: ${this._pullTime}`,l);const{code:u,data:h}=yield this._context.pullRTCRoomEntry(e);if(u===n.SUCCESS){this._isPulling=!1,this._pullTime=h.syncTime||0;const t=(null==h?void 0:h.kvEntries)||[];null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R,`status: ${C.SUCCESSED}, kvEntries: ${JSON.stringify(t)}`,l),this.singalDataChange(t,e,l)}null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R,`status: ${C.FAILED}, code: ${u}`,l)}))}_setInitData(){const{sessionId:e,remoteUserIds:t,remoteRTCUris:i,remoteMUCUris:r,remoteTracks:n,CDNUris:o}=((e,t)=>{const i=t.filter((e=>"RC_RTC_SESSIONID"===e.key))[0],r=i?i.value:"",n=t.filter((e=>"RC_ANCHOR_LIST"===e.key)).map((e=>JSON.parse(e.value||"[]")))[0],o=t.filter((e=>e.key.includes("RC_RES_"))).map((e=>JSON.parse(e.value||"{}"))),s=o.length?JSON.parse(o[0].mcu_uris||"[]"):[],a=[];s.forEach((t=>{const{mediaType:i,tag:r}=t,n=i===Je.AUDIO_ONLY?new gt(r,"",e):new vt(r,"",e);a.push(n)}));const c=[],d=[];o.forEach((e=>{const t=JSON.parse(e.uris||"[]");c.push(...t),t.forEach((e=>{const{mediaType:t,tag:i,msid:r}=e,n=r.split("_")[0],o=t===Je.AUDIO_ONLY?new gt(i,n):new vt(i,n);d.push(o)}))}));const _=t.filter((e=>"RC_CDN"===e.key)).map((e=>{const t=JSON.parse(e.value||"[]");return JSON.parse(t.cdn_uris)[0]}))[0];return{sessionId:r,remoteUserIds:n||[],remoteRTCUris:c,remoteMUCUris:s,remoteRTCTracks:d,remoteMCUTracks:a,remoteTracks:[...d,...a],CDNUris:_||{}}})(this._roomId,this._joinResData.kvEntries);this._sessionId=e,this._roomAnchorList=t,n.forEach((e=>{this._remoteTracks[e.getTrackId()]=e})),this._CDNUris=o,i.forEach((e=>{const t=e.msid.split("_")[0];this._roomAnchorRes[t]?this._roomAnchorRes[t].push(e):this._roomAnchorRes[t]=[e];const{ssrc:i,resourceId:r}=JSON.parse(e.uri);this._store.setTrackIdSSRCMap(i,r)})),r.forEach((e=>{const{mediaType:t,tag:i}=e,r=[this._roomId,i,t].join("_");this._roomRes[r]=e;const{ssrc:n}=JSON.parse(e.uri);this._store.setTrackIdSSRCMap(n,r)})),i.forEach((e=>{const t=ft(e);this._roomRes[t]=e}))}_assertRoomDestroyed(){if(this._destroyed)return T.ROOM_HAS_BEEN_DESTROYED}singalDataChange(e,t,i){var r,n,o;if(t!==this._roomId)return void(null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_AUDIENCE_LIVING_ROOM_SINGAL_DATA_CHANGE_P,JSON.stringify({status:C.FAILED,msg:`roomId inconsistency -> params roomId:${t}, current roomId:${this._roomId}`}),i));const s=[],a=null===(o=e.filter((e=>"RC_CDN"===e.key))[0])||void 0===o?void 0:o.value;a&&this._diffCDNUris(JSON.parse(JSON.parse(a).cdn_uris)[0],i),e.forEach((e=>{const{key:t,value:r,timestamp:n,uid:o}=e;if(-1!==t.indexOf("RC_RES_")){const e=JSON.parse(r||"{}"),t=JSON.parse(e.mcu_uris||"[]"),n=JSON.parse(e.uris||"[]");return s.push(...t),void this._diffAnchorResource(n,o,i)}if("RC_ANCHOR_LIST"===t){const e=JSON.parse(r||"[]"),{joinUserIds:t,leftUserIds:n}=this._diffAnchorList(e);t.length>0&&this._handleNewJoinedAnchor(t,i),n.length>0&&this._handleLeftedAnchor(n,i)}})),this._diffRoomResource(s,i)}_diffAnchorList(e){const t=e.filter((e=>this._roomAnchorList.indexOf(e)<0));return{leftUserIds:this._roomAnchorList.filter((t=>e.indexOf(t)<0)),joinUserIds:t}}_handleNewJoinedAnchor(e,t){var i,r;this._roomAnchorList.push(...e),null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorJoin",list:e}),t),this._callAppListener("onAnchorJoin",e)}_handleLeftedAnchor(e,t){var i,r;return S(this,void 0,void 0,(function*(){this._roomAnchorList=this._roomAnchorList.filter((t=>!(e.indexOf(t)>-1)));const n=[];e.forEach((e=>{n.push(...this.getRemoteTracksByUserId(e)),delete this._roomAnchorRes[e]})),n.length&&(yield this.unsubscribe(n),n.forEach((e=>delete this._remoteTracks[e.getTrackId()]))),null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorLeave",list:e}),t),this._callAppListener("onAnchorLeave",e)}))}_diffRoomResource(e,t){var i,r;return S(this,void 0,void 0,(function*(){const n=[],o=[],s=[];e.forEach((e=>{const t=ft(e),{userId:i,tag:r,mediaType:o}=Ct(t),a=[this._roomId,r,o].join("_"),{ssrc:c}=JSON.parse(e.uri);if(this._store.setTrackIdSSRCMap(c,a),!this._remoteTracks[a]){const t=o===Je.AUDIO_ONLY?new gt(r,"",this._roomId):new vt(r,"",this._roomId);n.push(t),this._remoteTracks[a]=t,this._roomRes[t.getTrackId()]=e}s.push(a)})),Object.keys(this._remoteTracks).forEach((e=>{s.indexOf(e)<0&&this._remoteTracks[e].isMCUTrack()&&o.push(this._remoteTracks[e])})),n.length>0&&(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onTrackPublish",trackIds:n.map((e=>e.getTrackId()))}),t),this._callAppListener("onTrackPublish",n)),o.length>0&&this._onUserUnpublish(o,"onTrackUnpublish",t)}))}_diffAnchorResource(e,t,i){var r,n,o,s,a,c;return S(this,void 0,void 0,(function*(){const d=this._roomAnchorRes[t]||(this._roomAnchorRes[t]=[]),{publishedList:_,unpublishedList:l,modifiedList:u}=Nt(d,e);if(_.length){const e=d.map(ft),t=[],a=[];if(_.forEach((i=>{const r=ft(i),n=e.indexOf(r),{userId:o,tag:s,mediaType:c}=Ct(r),{ssrc:_}=JSON.parse(i.uri);this._store.setTrackIdSSRCMap(_,r),n>-1?d[n]=i:d.push(i);let l=this._remoteTracks[r];this._roomRes[r]=i,l?l.isSubscribed()&&t.push(l):(l=c===Je.AUDIO_ONLY?new gt(s,o):new vt(s,o),this._remoteTracks[r]=l,a.push(l)),l.__innerSetRemoteMuted(0===i.state)})),t.length){const e=t.map((e=>e.getTrackId())),{code:i}=yield zs((()=>this._subscribeHandle(t,!0)));i!==T.SUCCESS&&(null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_RESUB_REPUB_RES_R,JSON.stringify({status:C.FAILED,trackIds:e,code:i})))}null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorTrackPublish",trackIds:a.map((e=>e.getTrackId()))}),i),this._callAppListener("onAnchorTrackPublish",a)}if(l.length){const e=l.map(ft);for(let t=d.length-1;t>=0;t-=1){const i=d[t];e.includes(ft(i))&&d.splice(t,1)}const t=l.map((e=>{const t=ft(e);return this._remoteTracks[t]}));yield this._onUserUnpublish(t,"onAnchorTrackUnpublish",i)}if(u.length){const e=d.map(ft);for(let t=0;t<u.length;t++){const r=u[t],n=ft(r),o=e.indexOf(n);d[o].state=r.state;const s=this._remoteTracks[n];s.__innerSetRemoteMuted(0===r.state);const _=s.isAudioTrack()?"onAudioMuteChange":"onVideoMuteChange";null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:_,trackId:s.getTrackId()}),i),this._callAppListener(_,s)}}}))}_onUserUnpublish(e,t,i){var r,n;return S(this,void 0,void 0,(function*(){yield this.unsubscribe(e),e.forEach((e=>{this._subscribedList=this._subscribedList.filter((t=>t.track.getTrackId()!==e.getTrackId())),delete this._roomRes[e.getTrackId()],e.__innerDestroy(),delete this._remoteTracks[e.getTrackId()]})),null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:t,trackIds:e.map((e=>e.getTrackId()))}),i),this._callAppListener(t,e)}))}_callAppListener(e,...t){var i,r,n;const o=null===(i=this._appListener)||void 0===i?void 0:i[e];if(o)try{o(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify(e))}}_reTryExchange(){return S(this,void 0,void 0,(function*(){zs((()=>S(this,void 0,void 0,(function*(){var e;const{reqBody:t}=yield this._createSubscribeParams(this._subscribedList,{},!0),i=yield this._exchangeHandle(t);if(i.code!==T.SUCCESS)return{code:i.code};const{sdp:r,resultCode:n}=i.data;if(n!==T.SUCCESS)return{code:n};this._pc.clearReTryExchangeTimer();const o=this._subscribedList.filter((e=>e.track.isMCUTrack()));if(o.length>0){const t=o[0].track.getTrackId(),i=null===(e=this._roomRes[t])||void 0===e?void 0:e.msid,n=[this._roomId,"RongCloudRTC"].join("_");r.sdp=r.sdp.replace(new RegExp(i,"g"),n)}const s=yield this._pc.setRemoteAnswer(r.sdp);return s!==T.SUCCESS?{code:s}:void 0}))),"audience-retry-exchange")}))}_createSubscribeParams(e,t,i){return S(this,void 0,void 0,(function*(){const r=yield this._pc.createOffer(i),n={resolutionInfo:[]},o={min:0,max:0};Object.keys(t).forEach((e=>{const{mediaStream:i,tinyStream:s}=t[e];[i,s].forEach(((t,i)=>{var s;const a=1===i?[e,"tiny"].join("_"):e;r.sdp=null===(s=r.sdp)||void 0===s?void 0:s.replace(new RegExp(t.id,"g"),a);const c=t.getVideoTracks()[0];if(!c)return;const d=0===i,{width:_,height:l,frameRate:u}=d?St(c):ea;n.resolutionInfo.push({trackId:c.id,simulcast:d?Xn.NORMAL:Xn.TINY,resolution:`${_}x${l}`});const h=Ke(_,l),g=$e(u);o.min+=h.minBitrate*g,o.max+=h.maxBitrate*g}))}));return{reqBody:{sdp:r,switchstream:!1,newVersionFlag:!0,subscribeList:e.map((e=>({simulcast:e.subTiny?Xn.TINY:Xn.NORMAL,resolution:"",uri:this._roomRes[e.track.getTrackId()].uri})))},dynamicBitrate:o,offer:r}}))}_subscribeHandle(e,t=!1,r=!1){var n,o,a,c,d,_,l,u,h,g,v;return S(this,void 0,void 0,(function*(){const p=Date.now(),R=r?Oo.SUB:void 0,m=null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o?void 0:o.createTraceId();null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:e.map(Vt),forceReq:t}),m);if(this._assertRoomDestroyed())return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.ROOM_HAS_BEEN_DESTROYED,msg:"room destroyed"}),m),R&&this._reportMediaActionLogger.reportPubOrSubQualityData(R,p,e,T.ROOM_HAS_BEEN_DESTROYED),{code:T.ROOM_HAS_BEEN_DESTROYED};if(!i("tracks",e,(()=>s(e)&&e.length>0&&e.every((e=>e instanceof ht||e.track instanceof ht))),!0))return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),m),R&&this._reportMediaActionLogger.reportPubOrSubQualityData(R,p,e,T.PARAMS_ERROR),{code:T.PARAMS_ERROR};const{pc:I,pcName:E}=this._peerCManager.createPeerCList(e)[0];this._pc=I,this._pc.__reportR3R4ToPolaris(),this._pcName=E,this._pc.registerReportListener(this._reportListener),this._addPeerCEvent();const S=this._subscribedList.map((e=>Object.assign({},e))),O=e.map((e=>e instanceof ht?{track:e}:e));let L=!1;const N=[];return O.forEach((e=>{const t=e.track.getTrackId();N.push(t);const i=S.find((e=>e.track.getTrackId()===t));i&&i.subTiny===e.subTiny||(i?i.subTiny=e.subTiny:S.push(e),L=!0)})),L||t?(null===(v=this._polarisReport)||void 0===v||v.sendR2(To.SUBSCRIBE,fo.BEGIN,N),this._updateSubListHandle(S,!0,m,p,R)):(null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.warn(f.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:C.SUCCESSED,msg:"repeat subscribe"}),m),{code:T.SUCCESS})}))}_addPeerCEvent(){this._pc.on(Bo.__INNER_EVENT_TRACK_READY__,(e=>{var t,i,r,n;const o=e.streams[0].id,{track:s}=e.receiver,a=[o,"audio"===s.kind?Je.AUDIO_ONLY:Je.VIDEO_ONLY].join("_"),c=this._remoteTracks[a];c?(c.__innerSetMediaStreamTrack(s),null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onTrackReady",trackId:c.getTrackId()})),this._callAppListener("onTrackReady",c)):null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.warn(f.L_AUDIENCE_LIVING_ROOM_ONTRACKREADY_O,`cannot found RCRemoteTrack: ${s.id}`)})),this._audioLevelReport&&this._pc.on(Bo.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport),this._pc.once(Bo.__INNER_ICE_CONNECTED__,(()=>{this._reportMediaActionLogger.reportIceFirstConnectData("sub")}),this),this._pc.on(Bo.__INNER_ICE_STATE_CHANGE__,(e=>{const{status:t,time:i,iceCandidatePair:r}=e;r&&this._reportMediaActionLogger.setIceCandidatePair(this._pcName,r),this._reportMediaActionLogger.recordQualityIceStatusData(this._pcName,t,i)}))}_getReqHeaders(){const e=this._crtUserId,t=this._useMutilPeerC?{"Peer-Connection-Id":this._pcName}:{};return Object.assign({"App-Key":this._context.getAppkey(),RoomId:e,Token:this._joinResData.token,RoomType:Eo.LIVE,UserId:e,"Session-Id":this._sessionId,"Client-Session-Id":this._clientSessionId},t)}_exchangeHandle(e){return this._service.broadcastSubscribe(this._getReqHeaders(),e)}_updateSubListHandle(e,t=!1,i,r,n){var o,s,a,c,d,_,l,u,h,g,v,p;return S(this,void 0,void 0,(function*(){null===(o=this._context.logger)||void 0===o||o.info(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_T,JSON.stringify({trackIds:e.map(Vt),forceReq:t}),i);let R=e.map((e=>e instanceof ht?{track:e}:Object.assign({},e)));const m={};R=R.filter((e=>{const t=e.track.getTrackId();return!m[t]&&(m[t]=!0,!0)})).map((e=>Object.assign({},e)));const I=this._subscribedList.map((e=>Object.assign({},e)));if(!t){let e=!1;if(R.forEach((t=>{const i=I.findIndex((e=>e.track===t.track));if(-1===i)return void(e=!0);I.splice(i,1)[0].subTiny!==t.subTiny&&(e=!0)})),I.length&&(e=!0),!e)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:C.SUCCESSED,msg:"repeat subscribe"}),i),{code:T.SUCCESS}}this._pc.clearReTryExchangeTimer(),this._pc.updateSubRemoteTracks(R.map((e=>e.track)));const{reqBody:E}=yield this._createSubscribeParams(R,{},!1),S=yield this._exchangeHandle(E);if(I.length){const e=[];I.forEach((t=>{e.push(t.track.getTrackId())})),null===(c=this._pc.reportParser)||void 0===c||c.clearLatestPacketsRecv(e)}if(e.forEach((e=>{const t=e instanceof ht?e.getTrackId():e.track.getTrackId();this._trackMediaMap[t]=S.qualityMsList||[]})),S.code!==T.SUCCESS)return n&&this._reportMediaActionLogger.reportPubOrSubQualityData(n,r,e,S.code,this._trackMediaMap),null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:C.FAILED,code:S.code}),i),{code:S.code};const{sdp:O,resultCode:L,message:N,subscribedList:A}=S.data;if(L!==T.SUCCESS)return n&&this._reportMediaActionLogger.reportPubOrSubQualityData(n,r,e,L,this._trackMediaMap),null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:C.FAILED,code:L,msg:N}),i),{code:L};R.forEach((e=>{const{track:t}=e;if(t.isMCUTrack()){const e=this._roomRes[t.getTrackId()].msid,{tag:i,userId:r}=Ct(t.getTrackId()),n=[r,i].join("_");O.sdp=O.sdp.replace(new RegExp(e,"g"),n)}}));const y=yield this._pc.setRemoteAnswer(O.sdp);if(n&&this._reportMediaActionLogger.reportPubOrSubQualityData(n,r,e,y,this._trackMediaMap),y!==T.SUCCESS)return null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.error(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:C.FAILED,code:y,msg:"set remote answer error"}),i),{code:y};const k=null==A?void 0:A.map((e=>`${e.msid}_${e.mediaType}`)),D=R.filter((e=>{if(e.track.isMCUTrack()){const t=this._roomRes[e.track.getTrackId()],i=`${t.msid}_${t.mediaType}`;return k.includes(i)}return null==k?void 0:k.includes(e.track.getTrackId())})),b=null==D?void 0:D.map((e=>`${e.track.getTrackId()}`)),U=R.filter((e=>!(null==b?void 0:b.includes(e.track.getTrackId()))));for(const e in this._remoteTracks){const t=D.some((t=>t.track.getTrackId()===e));this._remoteTracks[e].__innerSetSubscribed(t)}return this._subscribedList.splice(0,this._subscribedList.length,...D),null===(p=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===p||p.info(f.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:C.SUCCESSED,subSuccessTrackIds:k,failedList:U}),i),U.length?{code:T.SUCCESS,failedList:U}:{code:T.SUCCESS}}))}_diffCDNUris(e,t){var i,r,n,o,s,a;return S(this,void 0,void 0,(function*(){if(this._CDNUris.url&&!e.url)return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onCDNInfoDisable"}),t),this._callAppListener("onCDNInfoDisable"),void(this._CDNUris=e);(!this._CDNUris||!this._CDNUris.url&&e.url)&&(null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onCDNInfoEnable",resolution:`W${e.w}_H${e.h}`,fps:`FPS_${e.fps}`}),t),this._callAppListener("onCDNInfoEnable",{resolution:`W${e.w}_H${e.h}`,fps:`FPS_${e.fps}`}));const c=this._CDNUris.w&&e.w&&this._CDNUris.w!==e.w,d=this._CDNUris.h&&e.h&&this._CDNUris.h!==e.h,_=this._CDNUris.fps&&e.fps&&this._CDNUris.fps!==e.fps;(c||d||_)&&(null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onCDNInfoChange",resolution:`W${e.w}_H${e.h}`,fps:`FPS_${e.fps}`}),t),this._callAppListener("onCDNInfoChange",{resolution:`W${e.w}_H${e.h}`,fps:`FPS_${e.fps}`})),this._CDNUris=e}))}_getCDNPlayUrl(e,t){var i,r;return S(this,void 0,void 0,(function*(){const{w:n,h:o,fps:s}=e,a=this._initOptions.pullInnerCDNProtocol||Zs.FLV,c=this._initOptions.pullInnerCDNUseHttps===Xs.NOT_HTTPS?Xs.NOT_HTTPS:Xs.HTTPS;if(!this._CDNUris.url)return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:C.FAILED,code:T.CDN_RESOURCE_IS_EMPTY,msg:"cdn_uris url is empty, the anchor need to open or push CDN"}),t),{code:T.CDN_RESOURCE_IS_EMPTY};const d={"App-Key":this._context.getAppkey(),Token:this._joinResData.token,RoomId:this.getRoomId(),UserId:this._crtUserId,SessionId:this.getSessionId()},_=[],{w:l=0,h:u=1}=this._CDNUris;l/u>1?(n&&_.push(`w=${n}`),o&&_.push(`h=${o}`)):(n&&_.push(`h=${n}`),o&&_.push(`w=${o}`)),s&&_.push(`fps=${s}`),_.push(`kind=${a}`),_.push(`is_https=${c}`);const h=_.join("&");let g=`${this._CDNUris.url}?`;h&&(g+=h);const{code:v,res:p}=yield this._service.getCDNResourceInfo(d,g,t);return v!==T.SUCCESS?{code:v}:{code:v,CDNPlayUrl:null==p?void 0:p.data.pull_url}}))}getCDNPlayUrl(e,t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){const _=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();if(null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_T,JSON.stringify({resolution:e,fps:t}),_),e&&!kt(e))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> resolution"}),_),{code:T.PARAMS_ERROR};if(t&&!Dt(t))return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> fps"}),_),{code:T.PARAMS_ERROR};const{width:l,height:u}=e?yt(e):{width:null,height:null},h=t?bt(t):null,g={};return l&&(g.w=l),u&&(g.h=u),h&&(g.fps=h),this._getCDNPlayUrl(g,_)}))}subscribe(e){return S(this,void 0,void 0,(function*(){return zs((()=>this._subscribeHandle(e,!1,!0)),"audience-sub")}))}addSubscribeTask(e){return S(this,void 0,void 0,(function*(){return zs((()=>this._subscribeHandle(e,!1,!0)),"audience-sub")}))}__unsubscribe(e){var t,r,n,o,a,c,d,_,l;return S(this,void 0,void 0,(function*(){const u=Date.now(),h=Oo.UNSUB,g=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId();null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.info(f.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_T,JSON.stringify({trackIds:e.map((e=>e.getTrackId()))}),g);if(this._assertRoomDestroyed())return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.ROOM_HAS_BEEN_DESTROYED,msg:"room destroyed"}),g),{code:T.ROOM_HAS_BEEN_DESTROYED};if(!i("tracks",e,(()=>s(e)&&e.length>0&&e.every((e=>e instanceof ht))),!0))return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> tracks"}),g),{code:T.PARAMS_ERROR};const v=this._subscribedList.map((e=>Object.assign({},e))).filter((t=>!e.includes(t.track)));return null===(l=this._polarisReport)||void 0===l||l.sendR2(To.SUBSCRIBE,fo.END,e.map((e=>e.getTrackId()))),this._updateSubListHandle(v,!1,g,u,h)}))}unsubscribe(e){return S(this,void 0,void 0,(function*(){return zs((()=>this.__unsubscribe(e)),"audience-unsub")}))}addUnsubscribeTask(e){return S(this,void 0,void 0,(function*(){return zs((()=>this.__unsubscribe(e)),"audience-unsub")}))}__destroy(e){var t;return S(this,void 0,void 0,(function*(){this._destroyed||(this._destroyed=!0,e&&(yield this._context.quitLivingRoomAsAudience(this._roomId)),yield this._service.broadcastExit(this._getReqHeaders()),null===(t=this._pc)||void 0===t||t.destroy(),Cs.destroy(),this._polarisReport=null,this._context.registerRTCSignalListener(void 0))}))}getRemoteTrack(e){return this._remoteTracks[e]}__getPC(){return this._peerCManager.getPCList()}getLocalTrack(e){return{}}__onReconnected(){var e,t,i,r,o,s,a,c;return S(this,void 0,void 0,(function*(){const d=null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t?void 0:t.createTraceId();null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_T,void 0,d);const{code:_}=yield this._context.joinLivingRoomAsAudience(this._roomId,Eo.LIVE);_!==n.SUCCESS&&(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_R,`status: ${C.FAILED}`,d)),null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_R,`status: ${C.SUCCESSED}`,d)}))}registerRoomEventListener(e){this._appListener=e}onAudioLevelChange(e,t){var i,r;this._audioLevelReport=new Jo(this),this._audioLevelReport.onAudioLevelChange(e),null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(f.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({handler:null==e?void 0:e.name,gap:t}))}registerReportListener(e){this._reportListener=e}getRoomId(){return this._roomId}getCrtUserId(){return this._crtUserId}getSessionId(){return this._sessionId}getRemoteUserIds(){return this._roomAnchorList}getRemoteTracksByUserId(e){const t=[];for(const i in this._remoteTracks){const r=this._remoteTracks[i];r.getUserId()===e&&t.push(r)}return t}getRemoteTracks(){const e=[],t=[];for(const e in this._remoteTracks){if(2===t.length)break;const i=this._remoteTracks[e];i.isMCUTrack()&&t.push(i)}return this._roomAnchorList.forEach((t=>{e.push(...this.getRemoteTracksByUserId(t))})),[...t,...e]}getRemoteRTCTracks(){const e=[];for(const t in this._remoteTracks){const i=this._remoteTracks[t];i.isMCUTrack()||e.push(i)}return e}getRemoteMCUTracks(){const e=[];for(const t in this._remoteTracks){const i=this._remoteTracks[t];i.isMCUTrack()&&e.push(i)}return e}getCDNInfo(){return this._CDNUris.w?{resolution:`W${this._CDNUris.w}_H${this._CDNUris.h}`,fps:`FPS_${this._CDNUris.fps}`,CDNEnable:this._CDNUris.enableInnerCDN}:{CDNEnable:!1}}getClientSessionId(){return this._clientSessionId}}var ia,ra;!function(e){e[e.AUTOMATIC=0]="AUTOMATIC",e[e.MANUAL=1]="MANUAL"}(ia||(ia={}));class na{constructor(e){this._context=e,this._isElectron=/Electron/.test(navigator.userAgent)}_getMediaStream(e,t="getUserMedia"){return S(this,void 0,void 0,(function*(){try{const i=this.setConstraintsConfig(e),r=yield navigator.mediaDevices[t](i);return{code:T.SUCCESS,stream:r}}catch(e){if("Permission denied"===e.message)return{code:T.BROWSER_PERMISSION_DENIED};if("Permission denied by system"===e.message)return{code:T.SYSTEM_PERMISSION_DENIED}}return{code:"getUserMedia"===t?T.GET_USER_MEDIA_FAILED:T.GET_DISPLAY_MEDIA_FAILED}}))}_getMediaStreamErrorReason(e){let t="";return e===T.BROWSER_PERMISSION_DENIED&&(t="Permission denied"),e===T.SYSTEM_PERMISSION_DENIED&&(t="Permission denied by system"),t}setConstraintsConfig(e){var t,i;if((null==e?void 0:e.audio)&&!this._isElectron){"boolean"==typeof e.audio&&(e.audio={});const r=navigator.mediaDevices.getSupportedConstraints();r.noiseSuppression&&(e.audio.noiseSuppression=!!r.noiseSuppression),r.autoGainControl&&(e.audio.autoGainControl=!!r.autoGainControl),r.echoCancellation&&(e.audio.echoCancellation=!!r.echoCancellation),null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_SET_AUDIO_CONSTRAINTS_O,`browser supported -> ${JSON.stringify(r)}`)}return e}createMicrophoneAudioTrack(e="RongCloudRTC",t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS};const _=this._context.getCurrentId();if(!_)return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID};const{stream:l,code:u}=yield this._getMediaStream({audio:{deviceId:null==t?void 0:t.micphoneId,sampleRate:null==t?void 0:t.sampleRate,noiseSuppression:null==t?void 0:t.noiseSuppression,echoCancellation:null==t?void 0:t.echoCancellation,autoGainControl:null==t?void 0:t.autoGainControl}});if(u!==T.SUCCESS)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:u,msg:this._getMediaStreamErrorReason(u)})),{code:u};const h=l.getAudioTracks()[0],g=new dt(e,_,h);return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:C.SUCCESSED,trackId:g.getTrackId()})),{code:u,track:g}}))}createCameraVideoTrack(e="RongCloudRTC",t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS};const _=this._context.getCurrentId();if(!_)return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID};const l=kt(null==t?void 0:t.resolution)?t.resolution:Fe.W640_H480,{width:u,height:h}=yt(l),{stream:g,code:v}=yield this._getMediaStream({video:{deviceId:null==t?void 0:t.cameraId,frameRate:bt((null==t?void 0:t.frameRate)||Ve.FPS_15),width:u,height:h,facingMode:null==t?void 0:t.faceMode}});if(v!==T.SUCCESS)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:this._getMediaStreamErrorReason(v)})),{code:v};const p=g.getVideoTracks()[0],R=new _t(e,_,p);return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:C.SUCCESSED,trackId:R.getTrackId()})),{code:v,track:R}}))}createMicrophoneAndCameraTracks(e="RongCloudRTC",t){var i,r,n,o,s,a,c,d,_,l,u,h;return S(this,void 0,void 0,(function*(){const g=[];if(!mt(e))return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS,tracks:g};const v=this._context.getCurrentId();if(!v)return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID,tracks:g};const p=kt(null===(s=null==t?void 0:t.video)||void 0===s?void 0:s.resolution)?t.video.resolution:Fe.W640_H480,{width:R,height:m}=yt(p),I=null==t?void 0:t.audio,{stream:E,code:S}=yield this._getMediaStream({video:{deviceId:null===(a=null==t?void 0:t.video)||void 0===a?void 0:a.cameraId,frameRate:bt((null===(c=null==t?void 0:t.video)||void 0===c?void 0:c.frameRate)||Ve.FPS_15),width:R,height:m,facingMode:null===(d=null==t?void 0:t.video)||void 0===d?void 0:d.faceMode},audio:{deviceId:null==I?void 0:I.micphoneId,sampleRate:null==I?void 0:I.sampleRate,noiseSuppression:null==I?void 0:I.noiseSuppression,echoCancellation:null==I?void 0:I.echoCancellation,autoGainControl:null==I?void 0:I.autoGainControl}});return S!==T.SUCCESS?(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(f.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:C.FAILED,code:S,msg:this._getMediaStreamErrorReason(S)})),{code:S,tracks:g}):(E.getTracks().forEach((t=>{"video"===t.kind?g.push(new _t(e,v,t)):g.unshift(new dt(e,v,t))})),null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(f.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:C.SUCCESSED,trackIds:g.map((e=>e.getTrackId()))})),{code:S,tracks:g})}))}createScreenVideoTrack(e="screenshare",t){return S(this,void 0,void 0,(function*(){const i=yield this._createScreenTracks(e,!1,f.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_TRACK_O,t);return i.code===T.SUCCESS?{code:i.code,track:i.tracks[0]}:i}))}createScreenWithAudioTracks(e="screenshare",t){return S(this,void 0,void 0,(function*(){return this._createScreenTracks(e,!0,f.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_AND_AUDIO_TRACKS_O,t)}))}_createScreenTracks(e,t,i,r){var n,o,s,a,c,d,_,u,h,g,v,p,m,I,E,O;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(i,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS};const S=this._context.getCurrentId();if(!S)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(i,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID};if(!Mt())return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.error(f.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.BROWSER_NOT_SUPPORT,msg:"browser not support"})),{code:T.BROWSER_NOT_SUPPORT};const L=/macintosh|mac os x/i.test(navigator.userAgent);this._isElectron&&L&&t&&(null===(u=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===u||u.warn(i,JSON.stringify({status:C.INFO,code:T.MAC_IN_ELECTRON_NOT_SUPPORT_SCREEN_SHARE_WITH_AUDIO,msg:"mac in electron not support screen share with audio"})));const N=(!this._isElectron||!L)&&t;if(this._isElectron&&!R(null==r?void 0:r.chromeMediaSourceId)&&!l(null==r?void 0:r.chromeMediaSourceId))return null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.error(i,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> options.chromeMediaSourceId type is string"})),{code:T.PARAMS_ERROR};const A=kt(null==r?void 0:r.resolution)?r.resolution:Fe.W1280_H720,{width:y,height:k}=yt(A),D=this._isElectron?{mandatory:{chromeMediaSourceId:null==r?void 0:r.chromeMediaSourceId,chromeMediaSource:"desktop",minWidth:y,maxWidth:y,minHeight:k,maxHeight:k}}:{frameRate:bt((null==r?void 0:r.frameRate)||Ve.FPS_15),width:y,height:k};!(null==r?void 0:r.chromeMediaSourceId)&&this._isElectron&&(null===(v=D.mandatory)||void 0===v||delete v.chromeMediaSourceId);let b=null;N&&this._isElectron&&(null===(p=D.mandatory)||void 0===p||delete p.chromeMediaSourceId,b={mandatory:{chromeMediaSource:"desktop"}});const{stream:U,code:P}=yield this._getMediaStream({video:D,audio:b||N},this._isElectron?"getUserMedia":"getDisplayMedia");if(P!==T.SUCCESS)return null===(I=null===(m=this._context)||void 0===m?void 0:m.logger)||void 0===I||I.error(i,JSON.stringify({status:C.FAILED,code:P,msg:this._getMediaStreamErrorReason(P)})),{code:P};const M=U.getVideoTracks()[0],x=[new lt(e,S,M)];if(N){const t=U.getAudioTracks()[0];t&&x.push(new ut(e,S,t))}return null===(O=null===(E=this._context)||void 0===E?void 0:E.logger)||void 0===O||O.info(i,JSON.stringify({status:C.SUCCESSED,trackIds:x.map((e=>e.getTrackId()))})),{code:P,tracks:x}}))}createLocalAudioTrack(e,t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS};if(!t||"[object MediaStreamTrack]"!==t.toString()||"audio"!==t.kind)return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.CREATE_CUSTOM_TRACK_FAILED,msg:"params track is not MediaStreamTrack or kind is not audio"})),{code:T.CREATE_CUSTOM_TRACK_FAILED};const _=this._context.getCurrentId();if(!_)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID};const l=new nt(e,_,t);return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:C.SUCCESSED,trackId:l.getTrackId()})),{code:T.SUCCESS,track:l}}))}createLocalVideoTrack(e,t){var i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS};if(!(t&&t instanceof MediaStreamTrack&&"video"===t.kind))return null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.CREATE_CUSTOM_TRACK_FAILED,msg:"params track is not MediaStreamTrack or kind is not video"})),{code:T.CREATE_CUSTOM_TRACK_FAILED};const _=this._context.getCurrentId();if(!_)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(f.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID};const l=new ot(e,_,t);return null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:C.SUCCESSED,trackId:l.getTrackId()})),{code:T.SUCCESS,track:l}}))}createLocalFileTracks(e,t,i){var r,n,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){if(!mt(e))return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS,tracks:[]};if(!Pt())return null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.BROWSER_NOT_SUPPORT,msg:"browser not support"})),{code:T.BROWSER_NOT_SUPPORT,tracks:[]};const l=t instanceof File?URL.createObjectURL(t):t;if(!v(l)&&!/^blob:/.test(l))return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> file"})),{code:T.PARAMS_ERROR,tracks:[]};const u=this._context.getCurrentId();return u?new Promise((t=>{const r=document.createElement("video");(null==i?void 0:i.withoutAudio)&&(r.muted=!0),r.onloadedmetadata=()=>{var n,o,s,a;const c=[];let d;try{const e=r.mozCaptureStream?"mozCaptureStream":"captureStream";d=r[e]()}catch(e){null===(o=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===o||o.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.CREATE_FILE_TRACK_FAILED,msg:`captureSteam error -> ${JSON.stringify(e)}`})),t({code:T.CREATE_FILE_TRACK_FAILED,tracks:c})}const[_,l]=na.getTracksWithOptions(d,i);_&&c.push(new ct(e,u,_,r)),l&&c.push(new at(e,u,l,r)),0===c.length&&(r.pause(),r.src=""),r.onerror=null,null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.SUCCESSED,trackIds:c.map((e=>e.getTrackId()))})),t({code:T.SUCCESS,tracks:c})},r.onerror=()=>{var e,i;null===(i=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===i||i.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.CREATE_FILE_TRACK_FAILED,msg:"Failed to create file stream, video onerror"})),t({code:T.CREATE_FILE_TRACK_FAILED,tracks:[]})},r.src=l,r.loop=!0,r.play()})):(null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID,tracks:[]})}))}createLocalTracks(e,t,i){var r,n,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=[];if(!mt(e))return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(f.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_TAGS,msg:"invalid tag"})),{code:T.INVALID_TAGS,tracks:l};if(!(t instanceof MediaStream))return null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> stream"})),{code:T.PARAMS_ERROR,tracks:l};const u=this._context.getCurrentId();if(!u)return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:C.FAILED,code:T.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:T.INVALID_USER_ID,tracks:l};const[h,g]=na.getTracksWithOptions(t,i);return h&&l.push(new nt(e,u,h)),g&&l.push(new ot(e,u,g)),null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:C.SUCCESSED,trackIds:l.map((e=>e.getTrackId()))})),{code:T.SUCCESS,tracks:l}}))}static getTracksWithOptions(e,t){const i=[];return i[0]=(null==t?void 0:t.withoutAudio)?void 0:e.getAudioTracks()[0],i[1]=(null==t?void 0:t.withoutVideo)?void 0:e.getVideoTracks()[0],i}}class oa{constructor(){this.tasks=[]}static handler(){return this.retryHandler||(this.retryHandler=new oa),this.retryHandler}execute(){for(const e of this.tasks)e();this.destroy()}task(e){return S(this,void 0,void 0,(function*(){return new Promise((t=>{this.tasks.push((()=>{t(e())}))}))}))}destroy(){this.tasks=[]}}class sa extends na{constructor(e,t,i){super(e),this._context=e,this._runtime=t,this._options=i,this._crtRoom=null,this._audience=null,this._crtAudienceLivingRoom=null,Do.setSdpSemantics(i.sdpSemantics||"unified-plan"),this._service=new Zn(this._runtime,this._context,this._options.mediaServer,this._options.timeout),this._context.registerConnectionStateChangeListener(this._onIMStatusChange.bind(this)),this._context.registerDisconnectListener(this._onIMDisconnect.bind(this)),this._context.registerDestroyListener(this._onIMUninit.bind(this)),this._context.registerMessageListener(this._handleMessage.bind(this)),this._context.getPluginContext().onnavidatachange=this.naviDataChange.bind(this)}_handleMessage(e){var t,i,r,n,o,s;if(e.conversationType!==g.RTC_ROOM)return!1;const a=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();if(this._crtRoom instanceof Ws){this._getJoinedPKRoomList().forEach((t=>{t.__parseInnerMessage(e,a)}))}return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_RTC_CLIENT_MESSAGE_O,JSON.stringify({status:C.SUCCESSED,message:e}),a),this._crtRoom?(this._crtRoom.__parseInnerMessage(e,a),!0):(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.warn(f.L_RTC_CLIENT_MESSAGE_O,JSON.stringify({status:C.FAILED,message:"the crtRoom is empty"}),a),!0)}naviDataChange(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_RTC_CLIENT_NAVI_CHANGE_O,`on navi change data => ${JSON.stringify(e)}`),this._service.detectorMediaSever(),Fo.logServer=null==e?void 0:e.logServer,Fo.dc=null==e?void 0:e.dc}_getJoinedPKRoomList(){const{code:e,roomPKHandler:t}=this._crtRoom.getRoomPKHandler();if(e===T.SUCCESS&&t){const e=t.getJoinedPKRooms()||{};return Object.values(e)}return[]}getCurrentId(){return this._context.getCurrentId()}joinRTCRoom(e,t,i,r,n=Eo.RTC,o){var s,a,c,d,_,l;return S(this,void 0,void 0,(function*(){const u=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(d=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===d||d.info(f.L_RTC_CLIENT_JOIN_RTC_ROOM_T,JSON.stringify({roomId:e,joinType:t,outerUserDatas:i,useMutilPeerC:r,roomType:n}),u),this._crtRoom)return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(f.L_RTC_CLIENT_JOIN_RTC_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),u),{code:T.REPERT_JOIN_ROOM};const h=this._crtRoom=new Ys(this._context,this._runtime,e,this._service,this._options,!1,!1,r,Wn(),o),{code:g}=yield h.__innerInit(n,t,void 0,void 0,i,u);return g!==T.SUCCESS?(this._crtRoom=null,{code:g}):(h.once(ks,(()=>{this._crtRoom=null})),{code:g,room:h,userIds:h.getRemoteUserIds(),tracks:h.getRemoteTracks()})}))}joinCrossRTCRoom(e,t,i,r,n=Eo.CROSS_MUTI){var o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();if(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_T,JSON.stringify({roomId:e,joinType:t,outerUserDatas:i,useMutilPeerC:r,roomType:n}),l),this._crtRoom)return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),l),{code:T.REPERT_JOIN_ROOM};const u=this._crtRoom=new Ys(this._context,this._runtime,e,this._service,this._options,!1,!1,r,Wn(),n),{code:h}=yield u.__innerInit(n,t,void 0,void 0,i,l);return h!==T.SUCCESS?(this._crtRoom=null,{code:h}):(u.once(ks,(()=>{this._crtRoom=null})),{code:h,room:u,userIds:u.getRemoteUserIds(),tracks:u.getRemoteTracks()})}))}joinLivingRoom(e,t,i,r,n){var o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();if(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_T,JSON.stringify({roomId:e,livingType:t,joinType:i,outerUserDatas:r,useMutilPeerC:n}),l),this._crtRoom)return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:`Join the room repeatedly -> roomId: ${e}`}),l),{code:T.REPERT_JOIN_ROOM};const u=this._crtRoom=new Ws(this._context,this._runtime,e,this._service,this._options,t,!1,!0,n),{code:h}=yield u.__innerInit(Eo.LIVE,i,t,void 0,r,l);if(h!==T.SUCCESS)return this._crtRoom=null,{code:h};u.once(ks,(()=>{this._crtRoom=null}));const g={code:h,room:u,userIds:u.getRemoteUserIds(),tracks:u.getRemoteTracks()};return u.__getCDNPushMode()===ia.MANUAL&&Object.assign(g,{CDNEnable:u.__getCDNEnable()}),g}))}getAudienceClient(e){var t,i;return this._audience||(this._audience=new Qs(this._context,this._runtime,this._options,e)),null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_RTC_CLIENT_GET_AUDIENCE_CLIENT_O,JSON.stringify({useMutilPeerC:e})),this._audience}_onIMStatusChange(e){var t,i;if(null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(f.L_RTC_CLIENT_IM_CONNECTION_STATE_S,JSON.stringify({status:e})),e===a.CONNECTED){if(this._service.detectorMediaSever(),this._crtRoom instanceof Ws){this._getJoinedPKRoomList().forEach((e=>{e.__onReconnected()}))}this._crtRoom&&this._crtRoom.__onReconnected().then((e=>{if(e&&e.data&&e.data.sessionId){oa.handler().execute()}}))}}_onIMDisconnect(){var e,t;null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_RTC_CLIENT_IM_DISCONNECT_S,JSON.stringify({msg:"TODO -> on IM disconnect"}))}_onIMUninit(){var e,t,i;null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(f.L_RTC_CLIENT_DESTROY_S,JSON.stringify({msg:"TODO -> on IM client ondestroy"})),null===(i=this._crtRoom)||void 0===i||i.__destroy(!0)}leaveRoom(e){var t,i,r,n,o,s,a,c,d;return S(this,void 0,void 0,(function*(){const _=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_RTC_CLIENT_LEAVE_ROOM_T,JSON.stringify({roomId:e.getRoomId()}),_),this._crtRoom?(yield this._crtRoom.__destroy(!0),this._service.detectorMediaSever(),null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_RTC_CLIENT_LEAVE_ROOM_R,JSON.stringify({status:C.SUCCESSED,roomId:null===(d=this._crtRoom)||void 0===d?void 0:d.getRoomId()}),_),this._crtRoom=null,{code:T.SUCCESS}):(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.warn(f.L_RTC_CLIENT_LEAVE_ROOM_R,JSON.stringify({status:C.FAILED,msg:"Room does not exist, without leave"}),_),{code:T.SUCCESS})}))}joinLivingRoomAsAudience(e,t,r){var o,s,a,c,d,l,u,h,g,v,p,R,m,I,E,O;return S(this,void 0,void 0,(function*(){const S=null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s?void 0:s.createTraceId();if(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_T,JSON.stringify({roomId:e,livingType:t,useMutilPeerC:r}),S),this._service.detectorMediaSever(),wt(this._context.getNaviInfo()))return null===(l=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===l||l.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:T.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"}),S),{code:T.PACKAGE_ENVIRONMENT_ERROR};if(!i("roomId",e,_,!0)||!i("livingType",t,(e=>e===Vs.AUDIO||e===Vs.VIDEO)))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> roomId or livingType"}),S),{code:T.PARAMS_ERROR};if(this._crtAudienceLivingRoom)return null===(v=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===v||v.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),S),{code:T.REPERT_JOIN_ROOM};if(!this._service.getNaviMS().length)return null===(R=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===R||R.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:T.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"No audio / video server address available"}),S),{code:T.NOT_OPEN_VIDEO_AUDIO_SERVER};const{code:L,data:N}=yield this._context.joinLivingRoomAsAudience(e,Eo.LIVE,t);if(L!==n.SUCCESS)return null===(I=null===(m=this._context)||void 0===m?void 0:m.logger)||void 0===I||I.error(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:L,msg:"signal error -> audience join room"}),S),{code:T.SIGNAL_AUDIENCE_JOIN_ROOM_FAILED};const A=Wn(),y=new ta(this._context,this._runtime,this._options,e,N,t,r,A);return this._crtAudienceLivingRoom=y,null===(O=null===(E=this._context)||void 0===E?void 0:E.logger)||void 0===O||O.info(f.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.SUCCESSED,roomData:N}),S),{room:y,code:T.SUCCESS,userIds:y.getRemoteUserIds(),RTCTracks:y.getRemoteRTCTracks(),MCUTracks:y.getRemoteMCUTracks(),CDNUris:y.getCDNInfo()}}))}leaveLivingRoomAsAudience(e){var t,i,r,n,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i?void 0:i.createTraceId();return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(f.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_T,JSON.stringify({roomId:e.getRoomId(),userId:this._context.getCurrentId()}),l),this._crtAudienceLivingRoom?this._crtAudienceLivingRoom!==e?(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> room"}),l),{code:T.PARAMS_ERROR}):(yield this._crtAudienceLivingRoom.__destroy(!0),this._crtAudienceLivingRoom=null,null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.info(f.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.SUCCESSED}),l),{code:T.SUCCESS}):(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.warn(f.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:C.FAILED,msg:"Room does not exist, without leave"}),l),{code:T.SUCCESS})}))}upgradeToAnchorRoom(e){var t,r,o,s,a,c,d,_;return S(this,void 0,void 0,(function*(){const l=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId();if(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_T,void 0,l),!i("room",e,(()=>e instanceof ta),!0))return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> room"}),l),{code:T.PARAMS_ERROR};const u=e.getRoomId();if(this._crtRoom)return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly",roomId:u}),l),{code:T.REPERT_JOIN_ROOM};const h=this._crtRoom=new Ws(this._context,this._runtime,u,this._service,this._options,e.livingType,!0,!0,!1,e.getClientSessionId());if((yield h.__innerInitByIdentityChange(l))!==n.SUCCESS)return this._crtRoom=null,{code:T.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED};h.once(ks,(()=>{this._crtRoom=null})),yield this._crtAudienceLivingRoom.__destroy(!1),this._crtAudienceLivingRoom=null;const g={room:h,code:T.SUCCESS,userIds:h.getRemoteUserIds(),tracks:h.getRemoteTracks()};return h.__getCDNPushMode()===ia.MANUAL&&Object.assign(g,{CDNEnable:h.__getCDNEnable()}),g}))}downgradeToAudienceRoom(e){var t,r,o,s,a,c,d,_,l,u,h,g,v,p;return S(this,void 0,void 0,(function*(){const R=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId();if(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.info(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_T,JSON.stringify({roomId:e._roomId,userId:this._context.getCurrentId()}),R),!e.isMainRoom())return null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.error(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:C.FAILED,code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"the `downgradeToAudienceRoom` is disabled in PK room"}),R),{code:T.THE_FUNCTION_IS_DISABLED_IN_PKROOM};if(!i("room",e,(()=>e instanceof Ws),!0))return null===(_=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===_||_.error(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:C.FAILED,code:T.PARAMS_ERROR,msg:"params error -> room"}),R),{code:T.PARAMS_ERROR};if(this._crtAudienceLivingRoom)return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:C.FAILED,code:T.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),R),{code:T.REPERT_JOIN_ROOM};const{code:m,data:I}=yield this._context.rtcIdentityChange(e._roomId,Js.AnchorToViewer,e.getLivingType());if(m!==n.SUCCESS)return null===(g=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===g||g.error(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:C.FAILED,code:T.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED}),R),{code:T.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED};null===(p=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===p||p.info(f.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:C.SUCCESSED,roomData:I}),R);const E=e.getClientSessionId(),S=new ta(this._context,this._runtime,this._options,e._roomId,I,e.getLivingType(),!1,E);return this._crtAudienceLivingRoom=S,this._crtRoom.__destroy(!1),this._crtRoom=null,{room:S,code:T.SUCCESS,userIds:S.getRemoteUserIds(),RTCTracks:S.getRemoteRTCTracks(),MCUTracks:S.getRemoteMCUTracks(),CDNUris:S.getCDNInfo()}}))}getJoinedRoomInfo(){var e,t,i,r,o,s,a,c;return S(this,void 0,void 0,(function*(){const d=null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t?void 0:t.createTraceId(),_=this._context.getCurrentId();null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(f.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_T,JSON.stringify({userId:_}),d);const{code:l,data:u}=yield this._context.getRTCJoinedUserInfo(_);return l!==n.SUCCESS?(null===(s=null===(o=this._context)||void 0===o?void 0:o.logger)||void 0===s||s.error(f.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_R,JSON.stringify({status:C.FAILED,code:l}),d),{code:l}):(null===(c=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===c||c.info(f.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_R,JSON.stringify({status:C.SUCCESSED,roomInfo:u}),d),{code:T.SUCCESS,data:u})}))}reportSDKInfo(){this._context.reportSDKInfo({"plugin-rtc":"5.6.9"})}}!function(e){e[e.KICK=0]="KICK",e[e.REFUSE=1]="REFUSE",e[e.COEXIST=2]="COEXIST"}(ra||(ra={}));const aa="rtcRJoin_data",ca="rtcRExit",da="rtcRInfo",_a="rtcUData",la="rtcUDel",ua="rtcSetData",ha="userSetData",ga="rtcQryData",va="rtcDelData",pa="rtcToken",Ra="rtcUserState",ma="rtcUList",Ia="viewerJoinR",Ea="viewerExitR",Sa="rtcPullKv",Ta="rtcIdentityChange",fa="rtcInvite",Ca="rtcCancelInvite",Oa="rtcInviteAnswer",La="rtcEndInvite",Na="rtcQueryJoined",Aa="rtcPullRoomStatus",ya="reportsdk",ka="rtcPing";var Da;!function(e){e.RtcInput="RtcInput",e.RtcOutput="RtcOutput",e.RtcUserListOutput="RtcUserListOutput",e.SetUserStatusInput="SetUserStatusInput",e.RtcSetDataInput="RtcSetDataInput",e.RtcUserSetDataInput="RtcUserSetDataInput",e.RtcDataInput="RtcDataInput",e.RtcSetOutDataInput="RtcSetOutDataInput",e.MCFollowInput="MCFollowInput",e.RtcTokenOutput="RtcTokenOutput",e.RtcQryOutput="RtcQryOutput",e.RtcQryUserOutDataInput="RtcQryUserOutDataInput",e.RtcUserOutDataOutput="RtcUserOutDataOutput",e.RtcQueryListInput="RtcQueryListInput",e.RtcRoomInfoOutput="RtcRoomInfoOutput",e.RtcValueInfo="RtcValueInfo",e.RtcKeyDeleteInput="RtcKeyDeleteInput",e.RtcNotifyMsg="RtcNotifyMsg",e.RtcPullKV="RtcPullKV",e.RtcKVOutput="RtcKVOutput",e.RtcQueryUserJoinedInput="RtcQueryUserJoinedInput",e.RtcQueryUserJoinedOutput="RtcQueryUserJoinedOutput",e.RtcViewerJoinedOutput="RtcViewerJoinedOutput",e.RtcInviteInput="RtcInviteInput",e.RtcCancelInviteInput="RtcCancelInviteInput",e.RtcInviteAnswerInput="RtcInviteAnswerInput",e.RtcEndInviteInput="RtcEndInviteInput",e.RtcRoomStatusInput="RtcRoomStatusInput",e.RtcRoomStatusOutput="RtcRoomStatusOutput",e.RtcReportSDKInput="RtcReportSDKInput",e.RtcPBPolaris="RCRTCPBPolaris",e.RtcPBR1Info="RCRTCPBR1Info",e.RtcPBR2Info="RCRTCPBR2Info",e.RtcPBR3Info="RCRTCPBR3Info",e.RtcPBR4Info="RCRTCPBR4Info",e.RtcPBStatusInfo="RCRTCPBStatusInfo",e.RtcPBStreamInfo="RCRTCPBStreamInfo"}(Da||(Da={}));const ba={[Da.RtcInput]:["roomType","broadcastType","extraInnerData","needSysChatroom","identityChangeType","joinType","innerDatas","outerDatas","supportNtf"],[Da.RtcOutput]:["version"],[Da.RtcUserListOutput]:["users","token","sessionId","roomInfo","version"],[Da.SetUserStatusInput]:["status"],[Da.RtcSetDataInput]:["interior","target","key","value","objectName","content"],[Da.RtcUserSetDataInput]:["valueInfo","objectName","content"],[Da.RtcDataInput]:["interior","target","key","objectName","content"],[Da.RtcSetOutDataInput]:["target","valueInfo","objectName","content"],[Da.MCFollowInput]:["state"],[Da.RtcTokenOutput]:["rtcToken"],[Da.RtcQryOutput]:["outInfo"],[Da.RtcQryUserOutDataInput]:["userId"],[Da.RtcUserOutDataOutput]:["user"],[Da.RtcQueryListInput]:["order"],[Da.RtcRoomInfoOutput]:["roomId","roomData","userCount","list"],[Da.RtcValueInfo]:["key","value"],[Da.RtcKeyDeleteInput]:["key"],[Da.RtcNotifyMsg]:["type","time","roomId"],[Da.RtcPullKV]:["timestamp","roomId"],[Da.RtcKVOutput]:["entries","bFullUpdate","syncTime"],[Da.RtcQueryUserJoinedInput]:["userId"],[Da.RtcQueryUserJoinedOutput]:["info"],[Da.RtcInviteInput]:["invitedUserId","timeoutTime","invitedRoomId","inviteInfo","inviteSessionId"],[Da.RtcCancelInviteInput]:["invitedUserId","invitedRoomId","inviteInfo","inviteSessionId"],[Da.RtcInviteAnswerInput]:["inviteUserId","answerCode","inviteRoomId","inviteSessionId","content","key","value"],[Da.RtcEndInviteInput]:["inviteRoomId","inviteSessionId","inviteContent","inviteRoomKeys"],[Da.RtcRoomStatusInput]:["version"],[Da.RtcRoomStatusOutput]:["bFullStatus","version","usersData","roomStatus"],[Da.RtcReportSDKInput]:["sdkInfo"],[Da.RtcPBPolaris]:["type","appKey","sessionId","roomId","roomCreateTime","userId","userRole","joinTime","signalDataCenter","r1Info","r2Info","r3Info","r4Info"],[Da.RtcPBR1Info]:["joinTime","rtcVersion","imVersion","platform","device","os","browserName","browserVersion"],[Da.RtcPBR2Info]:["joinTime","sendTime","rtcActionType","rtcActionStatus","trackId"],[Da.RtcPBR3Info]:["info"],[Da.RtcPBR4Info]:["info"],[Da.RtcPBStatusInfo]:["joinTime","receiveTime","totalBitRate","appCPUUsage","systemCPUUsage","systemCPUFrequency","networkStatus","googleRTTNetwork","ipAddress","useReceiveBroadBand","useSendBroadBand","packetLossCount","streams"],[Da.RtcPBStreamInfo]:["trackId","codeName","volume","samplingRate","bitRate","packetLossRate","frameRate","resolution","blockTime","jitterData","nAckCount","pliCount","googleRTTTotalTime","isReceiveFirstFrameRate","codeType","isEnabled"]},Ua=`\npackage Modules;\nmessage probuf {\n enum JoinType {\n KICK = 0; //踢前一个设备\n REFUSE = 1; //当前加入拒绝\n COEXIST = 2; //两个设备共存\n }\n enum targetType {\n ROOM =1 ;\n PERSON = 2;\n }\n message ${Da.SetUserStatusInput}\n {\n optional int32 status=1;\n }\n message ${Da.MCFollowInput}\n {\n required string state = 1;\n }\n message ${Da.RtcQueryListInput}{\n optional int32 order=1;\n }\n message ${Da.RtcKeyDeleteInput}{\n repeated string key=1;\n }\n message ${Da.RtcValueInfo}{\n required string key=1;\n required string value=2;\n }\n message RtcUserInfo{\n required string userId=1;\n repeated ${Da.RtcValueInfo} userData=2; //用户资源信息\n }\n message ${Da.RtcRoomStatusInput}{ // rtc 和 living room 拉房间资源状态使用的参数\n required int64 version =1; //当前客户端最大的房间状态的version\n }\n message ${Da.RtcRoomStatusOutput}{ // rtc 和 living room 拉房间资源状态返回的数据\n required bool bFullStatus =1; //标识此次给的数据是否是全量数据\n required int64 version =2; //当前获取后房间的最大版本号\n repeated RtcUserInfo usersData=3;//如果是全量数据,这个不为空,给的是房间全部的人以及发布的资源\n repeated RtcRoomStatus roomStatus=4;//房间增量数据\n }\n message RtcRoomStatus{ //房间状态变动\n required string userId = 1;//用户ID\n required int32 event = 2;//房间状态变更的event(人员加入/退出/离线/发布资源) (0:加入;1:离开;2:离线;3:资源变动) \n required int64 time = 3;//本次变更的版本号\n repeated RtcValueInfo userData = 4;//用户变更的资源(event为0或者3时可能有值)\n optional int32 switchRoleType = 5;//如果是切换角色导致的加入房间或退出房间的类型\n optional string extra = 6;\n }\n message ${Da.RtcUserListOutput}{\n repeated RtcUserInfo users=1;\n optional string token=2;\n optional string sessionId=3;\n repeated RtcValueInfo roomInfo = 4; //房间key value\n repeated RtcKVEntity entries = 5;//直播KV属性对象集合\n optional int64 syncTime = 6;//所有属性的最大时间戳(下次拉取KV时用)。\n optional int32 offlineKickTime = 7;//server超时踢人时间,默认60s\n repeated string codeFormat = 8; //当前房间用户支持的编码交集\n optional int64 roomCreateTime = 9;//房间创建时间\n optional int64 userJoinTime = 10;//用户加入房间\n optional int64 version = 11;//当前房间的版本号\n }\n message RtcRoomInfoOutput{\n optional string roomId = 1;\n repeated ${Da.RtcValueInfo} roomData = 2;\n optional int32 userCount = 3;\n repeated RtcUserInfo list=4;\n }\n message ${Da.RtcInput}{\n required int32 roomType=1;\n optional int32 broadcastType=2;\n optional RtcValueInfo extraInnerData = 3;\n optional bool needSysChatroom = 4; //是否需要同步聊天室\n optional IdentityChangeType identityChangeType = 5; //身份变更类型\n optional JoinType joinType = 6; // 加入房间类型\n repeated ${Da.RtcValueInfo} innerDatas = 7; //用户内部inner数据,角色或者连麦信息等\n repeated ${Da.RtcValueInfo} outerDatas = 8; //用户内部outer数据,自定义数据结构RtcInput。\n optional bool supportNtf = 9; //是否支持房间状态的变更通过通知拉取的方式获取\n }\n message ${Da.RtcQryOutput}{\n repeated ${Da.RtcValueInfo} outInfo=1;\n }\n message ${Da.RtcDataInput}{\n required bool interior=1;\n required targetType target=2;\n repeated string key=3;\n optional string objectName=4;\n optional string content=5;\n }\n message ${Da.RtcSetDataInput}{\n required bool interior=1;\n required targetType target=2;\n required string key=3;\n required string value=4;\n optional string objectName=5;\n optional string content=6;\n }\n message ${Da.RtcUserSetDataInput} {\n repeated ${Da.RtcValueInfo} valueInfo = 1;\n required string objectName = 2;\n repeated ${Da.RtcValueInfo} content = 3;\n }\n message RtcQryInput{\n required bool isInterior=1;\n required targetType target=2;\n repeated string key=3;\n }\n message RtcDelDataInput{\n repeated string key=1;\n required bool isInterior=2;\n required targetType target=3;\n }\n message RtcOutput\n {\n optional int32 nothing=1;\n optional int64 version=2;\n }\n message ${Da.RtcTokenOutput}{\n required string rtcToken=1;\n }\n message ${Da.RtcSetOutDataInput}{\n required targetType target=1;\n repeated ${Da.RtcValueInfo} valueInfo=2;\n optional string objectName=3;\n optional string content=4;\n }\n message ${Da.RtcQryUserOutDataInput}{\n repeated string userId = 1;\n }\n message ${Da.RtcUserOutDataOutput}{\n repeated RtcUserInfo user = 1;\n }\n message ${Da.RtcNotifyMsg} \n {\n required int32 type= 1; //(通知类型 1:rtc房间状态KV变更通知)\n optional int64 time= 2; //消息产生时间\n optional string roomId=3; //主播房间id\n }\n message ${Da.RtcPullKV}\n {\n required int64 timestamp = 1;\n required string roomId = 2;\n }\n message RtcKVEntity \n {\n required string key = 1;\n required string value = 2;\n optional int32 status = 3;\n optional int64 timestamp = 4;\n optional string uid = 5;\n }\n message ${Da.RtcKVOutput}\n {\n repeated RtcKVEntity entries = 1;\n optional bool bFullUpdate = 2;\n optional int64 syncTime = 3; \n }\n enum IdentityChangeType \n {\n AnchorToViewer = 1; //1为主播变观众\n ViewerToAnchor = 2; //2为观众变主播\n }\n message ${Da.RtcQueryUserJoinedInput}\n {\n required string userId = 1;\n }\n message RtcJoinedInfo\n {\n required string deviceId = 1; //设备ID\n required string roomId = 2; //加入的房间ID\n optional int64 joinTime = 3; //加入的时间\n }\n message ${Da.RtcQueryUserJoinedOutput}\n {\n repeated RtcJoinedInfo info = 1;\n }\n message ${Da.RtcViewerJoinedOutput}\n {\n required string rtcToken=1;\n repeated RtcKVEntity entries = 2;//KV属性对象集合\n optional int64 syncTime = 3;//所有属性的最大时间戳(下次拉取KV时用)。\n optional string sessionId=4;\n optional int64 roomCreateTime = 5;//房间创建时间\n optional int64 userJoinTime = 6;//用户加入房间\n }\n message ${Da.RtcInviteInput}\n {\n required string invitedUserId=1; //被邀请的人的uid\n optional int32 timeoutTime=2; //邀请超时时间(秒),默认三十秒\n required string invitedRoomId=3; //被邀请的房间\n required string inviteInfo=4; //邀请的信息(包含邀请人,被邀请人,各自userid)客户端定义好.协议栈和server透传\n required string inviteSessionId= 5; //客户端保证唯一性(建议roomid_userid_时间戳_随机数)\n }\n message ${Da.RtcCancelInviteInput}\n {\n required string invitedUserId=1; //被邀请的人的uid\n required string invitedRoomId=2; //被邀请的房间\n required string inviteInfo=3; //取消邀请的信息(包含邀请人,被邀请人,各自userid)客户端定义好.协议栈和server透传\n required string inviteSessionId=4; //邀请的sessionId,客户端发起邀请时产生\n }\n message ${Da.RtcInviteAnswerInput}\n {\n required string inviteUserId=1; //邀请的人的uid\n required int32 answerCode=2; //是否接受连麦邀请.0为拒绝,1为接受\n required string inviteRoomId=3; //邀请的房间\n required string inviteSessionId=4; //邀请的sessionId\n required string content=5; //需要转发的content\n optional string key=6; //如果接受的话,需要加这个字段,放在room级别的k和v,新加入房间的能拉取到\n optional string value=7; //如果接受的话,需要加这个字段,放在room级别的k和v,新加入房间的能拉取到\n }\n message ${Da.RtcEndInviteInput}\n {\n required string inviteRoomId=1; //邀请的房间\n required string inviteSessionId=2; //邀请的sessionId\n required string inviteContent=3; //结束连麦的信息(需要透传给房间内其他人)\n repeated string inviteRoomKeys=4; //需要删除连麦的信息的key\n }\n message ${Da.RtcReportSDKInput} {\n required string sdkInfo=1; // 用户集成的 sdk 信息,json 格式 {"web-rtc": "4.0.3.7"}\n }\n // ---- 北极星数据上报 -------\n message ${Da.RtcPBPolaris} {\n required string type = 1;//上报数据类型 R1-R4\n required string appKey = 2;\n required string sessionId = 3;//房间通话id\n required string roomId = 4;\n required int64 roomCreateTime = 5;//房间创建时间\n required string userId = 6;\n required int32 userRole = 7;\n required int64 joinTime = 8;\n required string signalDataCenter = 9;//signal数据中心\n optional ${Da.RtcPBR1Info} r1Info = 10;\n optional ${Da.RtcPBR2Info} r2Info = 11;\n optional ${Da.RtcPBR3Info} r3Info = 12;\n optional ${Da.RtcPBR4Info} r4Info = 13;\n }\n message ${Da.RtcPBR1Info} {\n required int64 joinTime = 1;//用户加入房间的时间\n required string rtcVersion = 2;//Rtc版本号\n required string imVersion = 3;//IM SDK 版本\n required string platform = 4;//平台(如:Android、iOS、Web)\n required string device = 5; //设备信息(手机名称+型号)\n required string os = 6;//系统版本(手机系统版本)\n optional string browserName = 7; //浏览器名称, 没有用 -1 表示\n optional string browserVersion = 8;//浏览器版本, 没有用 -1 表示\n optional int64 receiveTime = 9; // 发送数据的时间\n }\n message ${Da.RtcPBR2Info} {\n required int64 joinTime = 1;\n required int64 sendTime = 2;\n required string rtcActionType = 3;//发布类型 subscribe : 订阅 publish : 发布\n required string rtcActionStatus = 4;//发布状态 begin : 开始 tend : 结束\n repeated string trackId = 5;\n optional int64 receiveTime = 6; // 发送数据的时间\n }\n message ${Da.RtcPBR3Info} {\n required ${Da.RtcPBStatusInfo} info = 1;\n }\n message ${Da.RtcPBR4Info} {\n required ${Da.RtcPBStatusInfo} info = 1;\n }\n message ${Da.RtcPBStatusInfo} {\n optional int64 joinTime = 1;//用户加入房间的时间\n optional int64 receiveTime = 2;//用户发布数据流的时间(毫秒),暂时由客户端生成,后期如果有问题服务端做兜底处理\n optional int64 totalBitRate = 3;//总码率\n optional float appCPUUsage = 4;//APP CPU占用率\n optional float systemCPUUsage = 5;////系统 CPU占用率\n optional float systemCPUFrequency = 6;//系统CPU频率 (安卓8.0以上)\n optional string networkStatus = 7;//实时网络状态(2g、3g、4g、wifi)\n optional int32 googleRTTNetwork = 8;//Goog rtt 网络延迟\n optional string ipAddress = 9;//ip地址\n optional string useReceiveBroadBand = 10; //可接收带宽(单位: bit)\n optional string useSendBroadBand = 11;//可用发送带宽(单位: bit)\n optional string packetLossCount = 12;//丢包数\n repeated ${Da.RtcPBStreamInfo} streams = 13;\n }\n message ${Da.RtcPBStreamInfo} {\n required string trackId = 1;\n optional string codeName = 2;//编解码名称\n optional string volume = 3;//音频播放音量\n optional int32 samplingRate = 4; //音频采样率\n optional float bitRate = 5;//下行码率\n optional float packetLossRate = 6;\n optional int32 frameRate = 7;//视频接收帧率(单位:fps)\n optional string resolution = 8;//视频分辨率(格式:640*480)\n optional int64 blockTime = 9;//接收卡顿(间隔时间, 单位: ms)\n optional int32 jitterData = 10;//jitter数据抖动\n optional string nAckCount = 11;//nack数量\n optional string pliCount = 12; //PLI请求数\n optional int64 googleRTTTotalTime = 13; //googRtt往返时长\n optional int32 isReceiveFirstFrameRate = 14;//第一个关键帧是否正常收到\n optional string codeType = 15;//编码方式\n optional int32 isEnabled = 16; //当前流的状态是否可用\n }\n // ---- 北极星数据上报 -------\n}\n`,Pa=(e,t,i,r,n,o,s)=>{const a=n?Object.keys(n).map((t=>e.encode(Da.RtcValueInfo,{key:t,value:n[t]},!0))):void 0,c=o?Object.keys(o).map((t=>e.encode(Da.RtcValueInfo,{key:t,value:o[t]},!0))):void 0;return e.encode(Da.RtcInput,{roomType:t,broadcastType:i,joinType:r,innerDatas:a,outerDatas:c,supportNtf:s})},Ma=(e,t)=>{const i=e.decode(Da.RtcUserListOutput,t),{users:r,token:n,sessionId:o,roomInfo:s,entries:a,offlineKickTime:c=60,codeFormat:d,roomCreateTime:_,userJoinTime:l,version:u}=i,h={};return m(r,(e=>{const{userId:t,userData:i}=e,r={};m(i,(e=>{const{key:t,value:i}=e;r[t]=i})),h[t]=r})),{users:h,token:n,sessionId:o,roomInfo:s,kvEntries:a,offlineKickTime:c,codeFormat:d,roomCreateTime:Ft(_),userJoinTime:Ft(l),version:u}};class xa{constructor(e,t){this.context=e,this.codec=t,this.roomCreateTime=0,this.userJoinTime=0,this.logger=null,this.logger=We.getLogger()}joinRTCRoom(e,t,i,r,o,s){return S(this,void 0,void 0,(function*(){const a=Pa(this.codec,t,i,r,o,s,!1),{code:c,buffer:d}=yield this.context.rtcSignaling(e,aa,!0,a);let _;if(c===n.SUCCESS&&d){_=Ma(this.codec,d);const{users:e,token:t,sessionId:i,roomInfo:r,kvEntries:n,offlineKickTime:o,roomCreateTime:s,userJoinTime:a,version:l}=_;return this.roomCreateTime=s,this.userJoinTime=a,{code:c,data:{users:e,token:t,sessionId:i,roomInfo:r,kvEntries:n,offlineKickTime:o,version:l}}}return{code:c,data:_}}))}quitRTCRoom(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Da.SetUserStatusInput,{status:0}),{code:i}=yield this.context.rtcSignaling(e,ca,!0,t);return i}))}getRTCRoomInfo(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Da.RtcQueryListInput,{order:2}),{code:i,buffer:r}=yield this.context.rtcSignaling(e,da,!0,t);let o;return i===n.SUCCESS&&r&&(o=this.codec.decode(Da.RtcRoomInfoOutput,r)),{code:i,data:o}}))}getRTCUserInfoList(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Da.RtcQueryListInput,{order:2}),{code:i,buffer:r}=yield this.context.rtcSignaling(e,_a,!0,t);let o;if(i===n.SUCCESS&&r){o={users:Ma(this.codec,r).users}}return{code:i,data:o}}))}getRTCUserInfo(e){throw new Error("Method not implemented.")}removeRTCUserInfo(e,t){return S(this,void 0,void 0,(function*(){const i=this.codec.encode(Da.RtcKeyDeleteInput,{key:t}),{code:r}=yield this.context.rtcSignaling(e,la,!1,i);return r}))}setRTCData(e,t,i,r,n,o){return S(this,void 0,void 0,(function*(){const s=this.codec.encode(Da.RtcSetDataInput,{interior:r,target:n,key:t,value:i,objectName:null==o?void 0:o.name,content:null==o?void 0:o.content}),{code:a}=yield this.context.rtcSignaling(e,ua,!1,s);return a}))}setRTCTotalRes(e,t,i,r,n,o){return S(this,void 0,void 0,(function*(){const s={objectName:r,content:[],valueInfo:[this.codec.encode(Da.RtcValueInfo,{key:"uris",value:i},!0)]};t.forEach((e=>{const t=this.codec.encode(Da.RtcValueInfo,{key:e.name,value:e.content},!0);s.content.push(t)})),n&&s.valueInfo.push(this.codec.encode(Da.RtcValueInfo,{key:"mcu_uris",value:n},!0)),o&&s.valueInfo.push(this.codec.encode(Da.RtcValueInfo,{key:"cdn_uris",value:o},!0));const a=this.codec.encode(Da.RtcUserSetDataInput,s),{code:c}=yield this.context.rtcSignaling(e,ha,!0,a);return c}))}setRTCCDNUris(e,t,i){return S(this,void 0,void 0,(function*(){const r=this.codec.encode(Da.RtcUserSetDataInput,{objectName:t,valueInfo:this.codec.encode(Da.RtcValueInfo,{key:"cdn_uris",value:i},!0)}),{code:n}=yield this.context.rtcSignaling(e,ha,!0,r);return n}))}getRTCData(e,t,i,r){return S(this,void 0,void 0,(function*(){const o=this.codec.encode(Da.RtcDataInput,{interior:i,target:r,key:t}),{code:s,buffer:a}=yield this.context.rtcSignaling(e,ga,!0,o);if(s!==n.SUCCESS||!a)return{code:s};const{outInfo:c}=this.codec.decode(Da.RtcQryOutput,a),d={};return c.forEach((e=>{d[e.key]=e.value})),{code:s,data:d}}))}removeRTCData(e,t,i,r,n){return S(this,void 0,void 0,(function*(){const o=this.codec.encode(Da.RtcDataInput,{interior:i,target:r,key:t,objectName:(null==n?void 0:n.name)||"",content:(null==n?void 0:n.content)||""}),{code:s}=yield this.context.rtcSignaling(e,va,!1,o);return s}))}setRTCOutData(e,t,i,r){return S(this,void 0,void 0,(function*(){throw new Error("JSEngine's method not implemented.")}))}getRTCOutData(e,t){return S(this,void 0,void 0,(function*(){throw new Error("JSEngine's method not implemented.")}))}getRTCToken(e,t,i){return S(this,void 0,void 0,(function*(){const r=Pa(this.codec,t,i),{code:o,buffer:s}=yield this.context.rtcSignaling(e,pa,!0,r);if(o!==n.SUCCESS||!s)return{code:o};const{rtcToken:a}=this.codec.decode(Da.RtcTokenOutput,s);return{code:o,data:{rtcToken:a}}}))}setRTCState(e,t){return S(this,void 0,void 0,(function*(){const i=this.codec.encode(Da.MCFollowInput,{state:t}),{code:r}=yield this.context.rtcSignaling(e,Ra,!0,i);return r}))}setRTCStateByHttp(e,t,i,r){return S(this,void 0,void 0,(function*(){const n=((e,t,i)=>{const{type:r,appKey:n,sessionId:o,roomId:s,roomCreateTime:a,userId:c,userRole:d,joinTime:_,signalDataCenter:l,r1Info:u,r2Info:h,r3Info:g,r4Info:v}=t,p={type:r,appKey:n,sessionId:o,roomId:s,roomCreateTime:a,userId:c,userRole:d,joinTime:_,signalDataCenter:l};if(i===go.R1&&u){const t=e.encode(Da.RtcPBR1Info,u,!0);return e.encode(Da.RtcPBPolaris,Object.assign(Object.assign({},p),{r1Info:t}))}if(i===go.R2&&h){const t=e.encode(Da.RtcPBR2Info,h,!0);return e.encode(Da.RtcPBPolaris,Object.assign(Object.assign({},p),{r2Info:t}))}if(i===go.R3&&g){const{info:t}=g,{streams:i}=t;let r=Array.isArray(i)&&i.map((t=>t&&e.encode(Da.RtcPBStreamInfo,t,!0))),n=e.encode(Da.RtcPBStatusInfo,Object.assign(Object.assign({},t),{streams:r}),!0),o=e.encode(Da.RtcPBR3Info,{info:n},!0);return e.encode(Da.RtcPBPolaris,Object.assign(Object.assign({},p),{r3Info:o}))}if(i===go.R4&&v){const{info:t}=v,{streams:i}=t;let r=Array.isArray(i)&&i.map((t=>t&&e.encode(Da.RtcPBStreamInfo,t,!0))),n=e.encode(Da.RtcPBStatusInfo,Object.assign(Object.assign({},t),{streams:r}),!0),o=e.encode(Da.RtcPBR4Info,{info:n},!0);return e.encode(Da.RtcPBPolaris,Object.assign(Object.assign({},p),{r4Info:o}))}return{}})(this.codec,i,r);let s=e;/^https:\/\//.test(e)||(s=`https://${e}`);try{const e=yield t.httpReq({url:`${s}/rtc/logserver/polaris`,body:n,method:o.POST,headers:{jwt:Zn.jwtToken},timeout:2e3});if(!e.data)throw new Error("http request fail");return JSON.parse(e.data).resultCode}catch(e){return ho.REPORT_FAIL}}))}getRTCUserList(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Da.RtcQueryListInput,{order:2}),{code:i,buffer:r}=yield this.context.rtcSignaling(e,ma,!0,t);if(i!==n.SUCCESS||!r)return{code:i};return{code:i,data:Ma(this.codec,r)}}))}joinLivingRoomAsAudience(e,t,i){return S(this,void 0,void 0,(function*(){const r=Pa(this.codec,t,i),{code:o,buffer:s}=yield this.context.rtcSignaling(e,Ia,!0,r);if(o!==n.SUCCESS||!s)return{code:o};const{rtcToken:a,entries:c,roomCreateTime:d,userJoinTime:_}=this.codec.decode(Da.RtcViewerJoinedOutput,s);return this.roomCreateTime=Ft(d),this.userJoinTime=Ft(_),{code:o,data:{token:a,kvEntries:c}}}))}quitLivingRoomAsAudience(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Da.SetUserStatusInput,{status:0}),{code:i}=yield this.context.rtcSignaling(e,Ea,!0,t);return i}))}rtcIdentityChange(e,t,i){return S(this,void 0,void 0,(function*(){const r=this.codec.encode(Da.RtcInput,{roomType:Eo.LIVE,broadcastType:i,identityChangeType:t,needSysChatroom:!1}),{code:o,buffer:s}=yield this.context.rtcSignaling(e,Ta,!0,r);if(o!==n.SUCCESS||!s)return{code:o};return{code:o,data:Ma(this.codec,s)}}))}requestRoomPK(e){return S(this,void 0,void 0,(function*(){const{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteTimeout:n,inviteInfo:o,roomId:s}=e,a=this.codec.encode(Da.RtcInviteInput,{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,timeoutTime:n,inviteInfo:o}),{code:c}=yield this.context.rtcSignaling(s,fa,!0,a);return c}))}cancelRoomPK(e){return S(this,void 0,void 0,(function*(){const{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteInfo:n,roomId:o}=e,s=this.codec.encode(Da.RtcCancelInviteInput,{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteInfo:n}),{code:a}=yield this.context.rtcSignaling(o,Ca,!0,s);return a}))}responseRoomPK(e){return S(this,void 0,void 0,(function*(){const{inviteUserId:t,inviteRoomId:i,inviteSessionId:r,content:n,key:o,value:s,agree:a,roomId:c}=e,d=this.codec.encode(Da.RtcInviteAnswerInput,{inviteUserId:t,inviteRoomId:i,inviteSessionId:r,content:n,key:o,value:s,answerCode:a?1:0}),{code:_}=yield this.context.rtcSignaling(c,Oa,!0,d);return _}))}endRoomPK(e){return S(this,void 0,void 0,(function*(){const{endRoomId:t,sessionId:i,content:r,keys:n,roomId:o}=e,s=this.codec.encode(Da.RtcEndInviteInput,{inviteRoomId:t,inviteSessionId:i,inviteContent:r,inviteRoomKeys:n}),{code:a}=yield this.context.rtcSignaling(o,La,!0,s);return a}))}getRTCJoinedUserInfo(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Da.RtcQueryUserJoinedInput,{userId:e}),{code:i,buffer:r}=yield this.context.rtcSignaling("",Na,!0,t);if(i!==n.SUCCESS||!r)return{code:i};return{code:i,data:(this.codec.decode(Da.RtcQueryUserJoinedOutput,r).info||[]).map((e=>({deviceId:e.deviceId,roomId:e.roomId,joinTime:Ft(e.joinTime)})))}}))}pullRTCRoomEntry(e){return S(this,void 0,void 0,(function*(){const t=this.codec.encode(Da.RtcPullKV,{timestamp:0,roomId:e}),{code:i,buffer:r}=yield this.context.rtcSignaling(e,Sa,!0,t);if(i!==n.SUCCESS)return{code:i};const o=this.codec.decode(Da.RtcKVOutput,r);let{entries:s,syncTime:a}=o;return s=(s||[]).map((e=>Object.assign(Object.assign({},e),{timestamp:Ft(e.timestamp)}))),{code:i,data:{kvEntries:s,syncTime:Ft(a)}}}))}pullRTCRoomStatus(e,t){return S(this,void 0,void 0,(function*(){const i=this.codec.encode(Da.RtcRoomStatusInput,{version:t}),{code:r,buffer:o}=yield this.context.rtcSignaling(e,Aa,!0,i);if(r!==n.SUCCESS)return{code:r};return{code:r,data:this.codec.decode(Da.RtcRoomStatusOutput,o)}}))}decodeRtcNotify(e){const{time:t,type:i,roomId:r}=this.codec.decode(Da.RtcNotifyMsg,e);return{time:Ft(t),type:i,roomId:r}}getCurrentId(){return this.context.getCurrentId()}getNaviInfo(){return this.context.getNaviInfo()}getConnectionStatus(){return this.context.getConnectionStatus()}getAppkey(){return this.context.getAppkey()}webRtcPing(e,t,i){return S(this,void 0,void 0,(function*(){const r=this.codec.encode(Da.RtcInput,{roomType:t,broadcastType:i}),{code:o,buffer:s}=yield this.context.rtcSignaling(e,ka,!0,r);if(o!==n.SUCCESS)return{code:o};const a=this.codec.decode(Da.RtcOutput,s);return a.version=Ft(a.version),{code:o,data:a}}))}rtcPing(e,t,i){return/Electron/.test(navigator.userAgent)?this.context.rtcPingResVersion(e,t,i):this.webRtcPing(e,t,i)}sendMessage(e,t,i){return this.context.sendMessage(e,t,i)}registerRTCSignalListener(e){this.context.registerRTCSignalListener(e)}registerConnectionStateChangeListener(e){this.context.onconnectionstatechange=e}registerDisconnectListener(e){this.context.ondisconnect=e}registerDestroyListener(e){this.context.ondestroy=e}registerMessageListener(e){this.context.onmessage=e}getCoreVersion(){return this.context.getCoreVersion()}getPluginContext(){return this.context}reportSDKInfo(e){const t=this.codec.encode(Da.RtcReportSDKInput,{sdkInfo:JSON.stringify(e)});this.context.rtcSignaling("",ya,!0,t)}}var wa;!function(e){e.RTC="RTC"}(wa||(wa={}));const Ba={tag:"RCRTC",verify:e=>"browser"!==e.tag?(console.error(`RCRTC Plugin is not support the runtime '${e.tag}'`),!1):It?(I.add("plugin-rtc","5.6.9"),!!I.validEngine("^5.7.2")||(console.error(`The current engine version '${I.getInfo().engine}' error, plugin-rtc required engine version at least '^5.7.2'.`),!1)):(console.error("Please use the https protocol or use `http://localhost` to open the page!"),!1),setup(e,i,r={}){var n,o,s,a,c,d,_,l;const u=e.createLogger("RCRTC",wa.RTC);return u.setOutputLevel(r.logLevel||E.DEBUG),We.setLogger(u),Ye.setLogger(u),u.warn(f.L_INDEX_INSTALL_RTC_PLUGIN_O,JSON.stringify({"RCRTC Version":"5.6.9",Commit:"45e154cdd19e668fbab571c3c725758847ad35bd","browserInfo.browser":Ut.browser,"browserInfo.supportsUnifiedPlan":Ut.supportsUnifiedPlan,"browserInfo.version":Ut.version})),h("options.mediaServer",r.mediaServer,(e=>!(!v(e)||"https:"===location.protocol&&!/^https/.test(e)))),h("options.timeout",r.timeout,(e=>t(e)&&e>=5e3&&e<=3e4)),h("options.pingGap",r.pingGap,(e=>t(e)&&e>=3e3&&e<=1e4)),(null==r?void 0:r.audio)&&((null===(n=r.audio)||void 0===n?void 0:n.workletModule)&&(it.workletModule=null===(o=r.audio)||void 0===o?void 0:o.workletModule),(null===(s=r.audio)||void 0===s?void 0:s.workletWasm)&&(it.workletWasm=null===(a=r.audio)||void 0===a?void 0:a.workletWasm),(null===(c=r.audio)||void 0===c?void 0:c.workletModule)&&(null===(d=r.audio)||void 0===d?void 0:d.workletWasm)&&(it.isOpen=!0),void 0!==(null===(_=r.audio)||void 0===_?void 0:_.isOpen)&&(it.isOpen=null===(l=r.audio)||void 0===l?void 0:l.isOpen)),new sa(new xa(e,e.createCodec(ba,Ua)),i,r)}},Va={DEFAULT:"RongCloudRTC"},Fa={transResolution:yt,transFrameRate:bt,parseTrackId:Ct,ifSupportLocalFileTrack:Pt,ifSupportScreenShare:Mt};export{Us as BackgroundPictureFillMode,Ps as MixLayoutMode,Ms as MixVideoRenderMode,Ds as RCAbstractRoom,Qs as RCAudienceClient,ta as RCAudienceLivingRoom,Qe as RCAudioBitrate,_t as RCCameraVideoTrack,Ve as RCFrameRate,Xs as RCInnerCDNPullIsHttps,Zs as RCInnerCDNPullKind,As as RCKickReason,Ws as RCLivingRoom,Vs as RCLivingType,nt as RCLocalAudioTrack,ct as RCLocalFileAudioTrack,st as RCLocalFileTrack,at as RCLocalFileVideoTrack,rt as RCLocalTrack,ot as RCLocalVideoTrack,Bs as RCMCUConfigBuilder,na as RCMediaStreamCapture,Je as RCMediaType,dt as RCMicphoneAudioTrack,sa as RCRTCClient,T as RCRTCCode,vo as RCRTCLiveRole,Gt as RCRTCPingResult,Ys as RCRTCRoom,gt as RCRemoteAudioTrack,ht as RCRemoteTrack,vt as RCRemoteVideoTrack,Fe as RCResolution,ut as RCScreenAudioTrack,lt as RCScreenVideoTrack,Va as RCTag,Ze as RCTrack,et as RCVideoBitrate,ra as RTCJoinType,qe as device,Fa as helper,Ba as installer};