@rongcloud/plugin-rtc 5.6.6 → 5.6.7
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.d.ts +3 -3
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
15
|
***************************************************************************** */function i(e,t,i,r){return new(i||(i=Promise))((function(o,n){function s(e){try{d(r.next(e))}catch(e){n(e)}}function a(e){try{d(r.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}d((r=r.apply(e,t||[])).next())}))}var r,o,n;e.RCRTCCode=void 0,(r=e.RCRTCCode||(e.RCRTCCode={}))[r.SUCCESS=1e4]="SUCCESS",r[r.PB_ERROR=40001]="PB_ERROR",r[r.SIGNAL_DISCONNECTED=5e4]="SIGNAL_DISCONNECTED",r[r.PARAMS_ERROR=50001]="PARAMS_ERROR",r[r.REPERT_JOIN_ROOM=50002]="REPERT_JOIN_ROOM",r[r.NOT_IN_ROOM=50003]="NOT_IN_ROOM",r[r.SERVICE_INVALID=50004]="SERVICE_INVALID",r[r.RTC_TOKEN_INVALID=50006]="RTC_TOKEN_INVALID",r[r.SIGNAL_ERROR=53001]="SIGNAL_ERROR",r[r.CREATE_OFFER_FAILED=53003]="CREATE_OFFER_FAILED",r[r.REQUEST_FAILED=53004]="REQUEST_FAILED",r[r.MCU_SERVER_NOT_FOUND=53005]="MCU_SERVER_NOT_FOUND",r[r.BROADCAST_SUB_LIST_NOT_EMPTY=53007]="BROADCAST_SUB_LIST_NOT_EMPTY",r[r.ROOM_HAS_BEEN_DESTROYED=53008]="ROOM_HAS_BEEN_DESTROYED",r[r.NOT_OPEN_VIDEO_AUDIO_SERVER=53009]="NOT_OPEN_VIDEO_AUDIO_SERVER",r[r.GET_USER_MEDIA_FAILED=53010]="GET_USER_MEDIA_FAILED",r[r.GET_DISPLAY_MEDIA_FAILED=53011]="GET_DISPLAY_MEDIA_FAILED",r[r.BROWSER_PERMISSION_DENIED=53012]="BROWSER_PERMISSION_DENIED",r[r.CREATE_CUSTOM_TRACK_FAILED=53013]="CREATE_CUSTOM_TRACK_FAILED",r[r.INVALID_TAGS=53014]="INVALID_TAGS",r[r.INVALID_USER_ID=53015]="INVALID_USER_ID",r[r.CREATE_FILE_TRACK_FAILED=53016]="CREATE_FILE_TRACK_FAILED",r[r.INVALID_FILE_INSTANCE=53017]="INVALID_FILE_INSTANCE",r[r.SET_REMOTE_DESCRIPTION_FAILED=53018]="SET_REMOTE_DESCRIPTION_FAILED",r[r.BROWSER_NOT_SUPPORT=53019]="BROWSER_NOT_SUPPORT",r[r.TRACK_NOT_READY=53020]="TRACK_NOT_READY",r[r.VIDEO_TRACK_MISS_MEDIA_ELEMENT=53021]="VIDEO_TRACK_MISS_MEDIA_ELEMENT",r[r.TRACK_PLAY_ERROR=53022]="TRACK_PLAY_ERROR",r[r.SIGNAL_AUDIENCE_JOIN_ROOM_FAILED=53023]="SIGNAL_AUDIENCE_JOIN_ROOM_FAILED",r[r.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED=53024]="SIGNAL_ROOM_CHANGE_IDENTITY_FAILED",r[r.PACKAGE_ENVIRONMENT_ERROR=53025]="PACKAGE_ENVIRONMENT_ERROR",r[r.PUBLISH_TRACK_LIMIT_EXCEEDED=53026]="PUBLISH_TRACK_LIMIT_EXCEEDED",r[r.CDN_RESOURCE_IS_EMPTY=53027]="CDN_RESOURCE_IS_EMPTY",r[r.SIGNAL_JOIN_RTC_ROOM_REFUSED=53028]="SIGNAL_JOIN_RTC_ROOM_REFUSED",r[r.NO_PERMISSION_TO_USE_REQUESTED_DEVICE=53029]="NO_PERMISSION_TO_USE_REQUESTED_DEVICE",r[r.THE_FUNCTION_IS_DISABLED_IN_PKROOM=53030]="THE_FUNCTION_IS_DISABLED_IN_PKROOM",r[r.SOME_TRACKS_PUBLISH_FAILED=53031]="SOME_TRACKS_PUBLISH_FAILED",r[r.MAC_IN_ELECTRON_NOT_SUPPORT_SCREEN_SHARE_WITH_AUDIO=53032]="MAC_IN_ELECTRON_NOT_SUPPORT_SCREEN_SHARE_WITH_AUDIO",r[r.JWT_TIME_OUT=1004]="JWT_TIME_OUT",r[r.SYSTEM_PERMISSION_DENIED=53033]="SYSTEM_PERMISSION_DENIED",r[r.PUBLISH_TRACKS_IS_INVALID=53034]="PUBLISH_TRACKS_IS_INVALID",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"}(o||(o={})),function(e){e.FAILED="fail",e.SUCCESSED="success",e.TIMEOUT="timeout",e.INFO="info"}(n||(n={}));let s=!0,a=!0;function d(e,t,i){const r=e.match(t);return r&&r.length>=i&&parseInt(r[i],10)}function c(e,t,i){if(!e.RTCPeerConnection)return;const r=e.RTCPeerConnection.prototype,o=r.addEventListener;r.addEventListener=function(e,r){if(e!==t)return o.apply(this,arguments);const n=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,n),o.apply(this,[e,n])};const n=r.removeEventListener;r.removeEventListener=function(e,i){if(e!==t||!this._eventMap||!this._eventMap[t])return n.apply(this,arguments);if(!this._eventMap[t].has(i))return n.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,n.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 _(e){return"boolean"!=typeof e?new Error("Argument type: "+typeof e+". Please use a boolean."):(s=e,e?"adapter.js logging disabled":"adapter.js logging enabled")}function l(e){return"boolean"!=typeof e?new Error("Argument type: "+typeof e+". Please use a boolean."):(a=!e,"adapter.js deprecation warnings "+(e?"disabled":"enabled"))}function u(){if("object"==typeof window){if(s)return;"undefined"!=typeof console&&"function"==typeof console.log&&console.log.apply(console,arguments)}}function h(e,t){a&&console.warn(e+" is deprecated, please use "+t+" instead.")}function R(e){return"[object Object]"===Object.prototype.toString.call(e)}function v(e){return R(e)?Object.keys(e).reduce((function(t,i){const r=R(e[i]),o=r?v(e[i]):e[i],n=r&&!Object.keys(o).length;return void 0===o||n?t:Object.assign(t,{[i]:o})}),{}):e}function C(e,t,i){t&&!i.has(t.id)&&(i.set(t.id,t),Object.keys(t).forEach((r=>{r.endsWith("Id")?C(e,e.get(t[r]),i):r.endsWith("Ids")&&t[r].forEach((t=>{C(e,e.get(t),i)}))})))}function p(e,t,i){const r=i?"outbound-rtp":"inbound-rtp",o=new Map;if(null===t)return o;const n=[];return e.forEach((e=>{"track"===e.type&&e.trackIdentifier===t.id&&n.push(e)})),n.forEach((t=>{e.forEach((i=>{i.type===r&&i.trackId===t.id&&C(e,i,o)}))})),o}const g=u;function m(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 o=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[o("min",i)]=r.ideal,t.optional.push(e),e={},e[o("max",i)]=r.ideal,t.optional.push(e)):(e[o("",i)]=r.ideal,t.optional.push(e))}void 0!==r.exact&&"number"!=typeof r.exact?(t.mandatory=t.mandatory||{},t.mandatory[o("",i)]=r.exact):["min","max"].forEach((e=>{void 0!==r[e]&&(t.mandatory=t.mandatory||{},t.mandatory[o(e,i)]=r[e])}))})),e.advanced&&(t.optional=(t.optional||[]).concat(e.advanced)),t},o=function(e,o){if(t.version>=61)return o(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 n=e.video.facingMode;n=n&&("object"==typeof n?n:{ideal:n});const s=t.version<66;if(n&&("user"===n.exact||"environment"===n.exact||"user"===n.ideal||"environment"===n.ideal)&&(!i.mediaDevices.getSupportedConstraints||!i.mediaDevices.getSupportedConstraints().facingMode||s)){let t;if(delete e.video.facingMode,"environment"===n.exact||"environment"===n.ideal?t=["back","rear"]:"user"!==n.exact&&"user"!==n.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=n.exact?{exact:s.deviceId}:{ideal:s.deviceId}),e.video=r(e.video),g("chrome: "+JSON.stringify(e)),o(e)}))}e.video=r(e.video)}return g("chrome: "+JSON.stringify(e)),o(e)},n=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){o(e,(e=>{i.webkitGetUserMedia(e,t,(e=>{r&&r(n(e))}))}))}.bind(i),i.mediaDevices.getUserMedia){const e=i.mediaDevices.getUserMedia.bind(i.mediaDevices);i.mediaDevices.getUserMedia=function(t){return o(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(n(e))))))}}}function T(e){e.MediaStream=e.MediaStream||e.webkitMediaStream}function I(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 o=new Event("track");o.track=i.track,o.receiver=r,o.transceiver={receiver:r},o.streams=[t.stream],this.dispatchEvent(o)})),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 o=new Event("track");o.track=i,o.receiver=r,o.transceiver={receiver:r},o.streams=[t.stream],this.dispatchEvent(o)}))},this.addEventListener("addstream",this._ontrackpoly)),t.apply(this,arguments)}}else c(e,"track",(e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e)))}function E(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 o=i.apply(this,arguments);return o||(o=t(this,e),this._senders.push(o)),o};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 S(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 o=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},n=function(e){return new Map(Object.keys(e).map((t=>[t,e[t]])))};if(arguments.length>=2){const r=function(e){i(n(o(e)))};return t.apply(this,[r,e])}return new Promise(((e,i)=>{t.apply(this,[function(t){e(n(o(t)))},i])})).then(i,r)}}function f(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=>p(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}),c(e,"track",(e=>(e.receiver._pc=e.srcElement,e))),e.RTCRtpReceiver.prototype.getStats=function(){const e=this;return this._pc.getStats().then((t=>p(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 O(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 o=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]})),o.apply(this,arguments)}}function L(e,t){if(!e.RTCPeerConnection)return;if(e.RTCPeerConnection.prototype.addTrack&&t.version>=65)return O(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 o=e.RTCPeerConnection.prototype.removeStream;function n(e,t){let i=t.sdp;return Object.keys(e._reverseStreams||[]).forEach((t=>{const r=e._reverseStreams[t],o=e._streams[r.id];i=i.replace(new RegExp(o.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],o=e._streams[r.id];i=i.replace(new RegExp(r.id,"g"),o.id)})),new RTCSessionDescription({type:t.type,sdp:i})}e.RTCPeerConnection.prototype.removeStream=function(e){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},o.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 o=this.getSenders().find((e=>e.track===t));if(o)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=n(this,t);e[0].apply(null,[i])},t=>{e[1]&&e[1].apply(null,t)},arguments[2]]):i.apply(this,arguments).then((e=>n(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 d=Object.getOwnPropertyDescriptor(e.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(e.RTCPeerConnection.prototype,"localDescription",{get(){const e=d.get.apply(this);return""===e.type?e:n(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 N(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 A(e,t){c(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:T,shimOnTrack:I,shimGetSendersWithDtmf:E,shimGetStats:S,shimSenderReceiverGetStats:f,shimAddTrackRemoveTrackWithNative:O,shimAddTrackRemoveTrack:L,shimPeerConnection:N,fixNegotiationNeeded:A,shimGetUserMedia:m,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,o=i.video&&i.video.height,n=i.video&&i.video.frameRate;return i.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:t,maxFrameRate:n||3}},r&&(i.video.mandatory.maxWidth=r),o&&(i.video.mandatory.maxHeight=o),e.navigator.mediaDevices.getUserMedia(i)}))}:console.error("shimGetDisplayMedia: getSourceId argument is not a function"))}});var k=function(e){var t={exports:{}};return e(t,t.exports),t.exports}((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(";"),o=0;o<r.length;o++)i[(t=r[o].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],o=t.matchPrefix(e+i,"a=ice-pwd:")[0];return r&&o?{usernameFragment:r.substr(12),password:o.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(" "),o=3;o<r.length;o++){var n=r[o],s=t.matchPrefix(e,"a=rtpmap:"+n+" ")[0];if(s){var a=t.parseRtpMap(s),d=t.matchPrefix(e,"a=fmtp:"+n+" ");switch(a.parameters=d.length?t.parseFmtp(d[0]):{},a.rtcpFeedback=t.matchPrefix(e,"a=rtcp-fb:"+n+" ").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 o=0;return i.codecs.forEach((function(e){e.maxptime>o&&(o=e.maxptime)})),o>0&&(r+="a=maxptime:"+o+"\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=[],o=t.parseRtpParameters(e),n=-1!==o.fecMechanisms.indexOf("RED"),s=-1!==o.fecMechanisms.indexOf("ULPFEC"),a=t.matchPrefix(e,"a=ssrc:").map((function(e){return t.parseSsrcMedia(e)})).filter((function(e){return"cname"===e.attribute})),d=a.length>0&&a[0].ssrc,c=t.matchPrefix(e,"a=ssrc-group:FID").map((function(e){return e.substr(17).split(" ").map((function(e){return parseInt(e,10)}))}));c.length>0&&c[0].length>1&&c[0][0]===d&&(i=c[0][1]),o.codecs.forEach((function(e){if("RTX"===e.name.toUpperCase()&&e.parameters.apt){var t={ssrc:d,codecPayloadType:parseInt(e.parameters.apt,10)};d&&i&&(t.rtx={ssrc:i}),r.push(t),n&&((t=JSON.parse(JSON.stringify(t))).fec={ssrc:d,mechanism:s?"red+ulpfec":"red"},r.push(t))}})),0===r.length&&d&&r.push({ssrc:d});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 o=t.matchPrefix(e,"a=rtcp-rsize");i.reducedSize=o.length>0,i.compound=0===o.length;var n=t.matchPrefix(e,"a=rtcp-mux");return i.mux=n.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 o=t.matchPrefix(e,"a=ssrc:").map((function(e){return t.parseSsrcMedia(e)})).filter((function(e){return"msid"===e.attribute}));return o.length>0?{stream:(i=o[0].value.split(" "))[0],track:i[1]}:void 0},t.parseSctpDescription=function(e){var i,r=t.parseMLine(e),o=t.matchPrefix(e,"a=max-message-size:");o.length>0&&(i=parseInt(o[0].substr(19),10)),isNaN(i)&&(i=65536);var n=t.matchPrefix(e,"a=sctp-port:");if(n.length>0)return{port:parseInt(n[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 o=void 0!==i?i:2;return"v=0\r\no="+(r||"thisisadapterortc")+" "+(e||t.generateSessionId())+" "+o+" IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"},t.writeMediaSection=function(e,i,r,o){var n=t.writeRtpDescription(e.kind,i);if(n+=t.writeIceParameters(e.iceGatherer.getLocalParameters()),n+=t.writeDtlsParameters(e.dtlsTransport.getLocalParameters(),"offer"===r?"actpass":"active"),n+="a=mid:"+e.mid+"\r\n",e.direction?n+="a="+e.direction+"\r\n":e.rtpSender&&e.rtpReceiver?n+="a=sendrecv\r\n":e.rtpSender?n+="a=sendonly\r\n":e.rtpReceiver?n+="a=recvonly\r\n":n+="a=inactive\r\n",e.rtpSender){var s="msid:"+o.id+" "+e.rtpSender.track.id+"\r\n";n+="a="+s,n+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" "+s,e.sendEncodingParameters[0].rtx&&(n+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" "+s,n+="a=ssrc-group:FID "+e.sendEncodingParameters[0].ssrc+" "+e.sendEncodingParameters[0].rtx.ssrc+"\r\n")}return n+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" cname:"+t.localCName+"\r\n",e.rtpSender&&e.sendEncodingParameters[0].rtx&&(n+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" cname:"+t.localCName+"\r\n"),n},t.getDirection=function(e,i){for(var r=t.splitLines(e),o=0;o<r.length;o++)switch(r[o]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return r[o].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}));function D(e,t,i,r,o){var n=k.writeRtpDescription(e.kind,t);if(n+=k.writeIceParameters(e.iceGatherer.getLocalParameters()),n+=k.writeDtlsParameters(e.dtlsTransport.getLocalParameters(),"offer"===i?"actpass":o||"active"),n+="a=mid:"+e.mid+"\r\n",e.rtpSender&&e.rtpReceiver?n+="a=sendrecv\r\n":e.rtpSender?n+="a=sendonly\r\n":e.rtpReceiver?n+="a=recvonly\r\n":n+="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";n+="a="+a,n+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" "+a,e.sendEncodingParameters[0].rtx&&(n+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" "+a,n+="a=ssrc-group:FID "+e.sendEncodingParameters[0].ssrc+" "+e.sendEncodingParameters[0].rtx.ssrc+"\r\n")}return n+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" cname:"+k.localCName+"\r\n",e.rtpSender&&e.sendEncodingParameters[0].rtx&&(n+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" cname:"+k.localCName+"\r\n"),n}function b(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]},o=function(e,t,i,o){var n=r(e.parameters.apt,i),s=r(t.parameters.apt,o);return n&&s&&n.name.toLowerCase()===s.name.toLowerCase()};return e.codecs.forEach((function(r){for(var n=0;n<t.codecs.length;n++){var s=t.codecs[n];if(r.name.toLowerCase()===s.name.toLowerCase()&&r.clockRate===s.clockRate){if("rtx"===r.name.toLowerCase()&&r.parameters&&s.parameters.apt&&!o(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 o=t.headerExtensions[r];if(e.uri===o.uri){i.headerExtensions.push(o);break}}})),i}function U(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 P(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 M(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 x=function(e,t){function i(t,i){i.addTrack(t),i.dispatchEvent(new e.MediaStreamTrackEvent("addtrack",{track:t}))}function r(t,i,r,o){var n=new Event("track");n.track=i,n.receiver=r,n.transceiver={receiver:r},n.streams=o,e.setTimeout((function(){t._dispatchEvent("track",n)}))}var o=function(i){var r=this,o=document.createDocumentFragment();if(["addEventListener","removeEventListener","dispatchEvent"].forEach((function(e){r[e]=o[e].bind(o)})),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 M("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 o="string"==typeof r;return o&&(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=o?r[0]:r,!!r.length}}))}(i.iceServers||[],t),this._iceGatherers=[],i.iceCandidatePoolSize)for(var n=i.iceCandidatePoolSize;n>0;n--)this._iceGatherers.push(new e.RTCIceGatherer({iceServers:i.iceServers,gatherPolicy:i.iceTransportPolicy}));else i.iceCandidatePoolSize=0;this._config=i,this.transceivers=[],this._sdpSessionId=k.generateSessionId(),this._sdpSessionVersion=0,this._dtlsRole=void 0,this._isClosed=!1};Object.defineProperty(o.prototype,"localDescription",{configurable:!0,get:function(){return this._localDescription}}),Object.defineProperty(o.prototype,"remoteDescription",{configurable:!0,get:function(){return this._remoteDescription}}),o.prototype.onicecandidate=null,o.prototype.onaddstream=null,o.prototype.ontrack=null,o.prototype.onremovestream=null,o.prototype.onsignalingstatechange=null,o.prototype.oniceconnectionstatechange=null,o.prototype.onconnectionstatechange=null,o.prototype.onicegatheringstatechange=null,o.prototype.onnegotiationneeded=null,o.prototype.ondatachannel=null,o.prototype._dispatchEvent=function(e,t){this._isClosed||(this.dispatchEvent(t),"function"==typeof this["on"+e]&&this["on"+e](t))},o.prototype._emitGatheringStateChange=function(){var e=new Event("icegatheringstatechange");this._dispatchEvent("icegatheringstatechange",e)},o.prototype.getConfiguration=function(){return this._config},o.prototype.getLocalStreams=function(){return this.localStreams},o.prototype.getRemoteStreams=function(){return this.remoteStreams},o.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 o=this._createIceAndDtlsTransports();r.iceTransport=o.iceTransport,r.dtlsTransport=o.dtlsTransport}return t||this.transceivers.push(r),r},o.prototype.addTrack=function(t,i){if(this._isClosed)throw M("InvalidStateError","Attempted to call addTrack on a closed peerconnection.");var r;if(this.transceivers.find((function(e){return e.track===t})))throw M("InvalidAccessError","Track already exists.");for(var o=0;o<this.transceivers.length;o++)this.transceivers[o].track||this.transceivers[o].kind!==t.kind||(r=this.transceivers[o]);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},o.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)}))}},o.prototype.removeTrack=function(t){if(this._isClosed)throw M("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 M("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()},o.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)}))},o.prototype.getSenders=function(){return this.transceivers.filter((function(e){return!!e.rtpSender})).map((function(e){return e.rtpSender}))},o.prototype.getReceivers=function(){return this.transceivers.filter((function(e){return!!e.rtpReceiver})).map((function(e){return e.rtpReceiver}))},o.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 o=new e.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(o,"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;o.state=i?"completed":"gathering",null!==r.transceivers[t].bufferedCandidateEvents&&r.transceivers[t].bufferedCandidateEvents.push(e)},o.addEventListener("localcandidate",this.transceivers[t].bufferCandidates),o},o.prototype._gather=function(t,i){var r=this,o=this.transceivers[i].iceGatherer;if(!o.onlocalcandidate){var n=this.transceivers[i].bufferedCandidateEvents;this.transceivers[i].bufferedCandidateEvents=null,o.removeEventListener("localcandidate",this.transceivers[i].bufferCandidates),o.onlocalcandidate=function(e){if(!(r.usingBundle&&i>0)){var n=new Event("icecandidate");n.candidate={sdpMid:t,sdpMLineIndex:i};var s=e.candidate,a=!s||0===Object.keys(s).length;if(a)"new"!==o.state&&"gathering"!==o.state||(o.state="completed");else{"new"===o.state&&(o.state="gathering"),s.component=1,s.ufrag=o.getLocalParameters().usernameFragment;var d=k.writeCandidate(s);n.candidate=Object.assign(n.candidate,k.parseCandidate(d)),n.candidate.candidate=d,n.candidate.toJSON=function(){return{candidate:n.candidate.candidate,sdpMid:n.candidate.sdpMid,sdpMLineIndex:n.candidate.sdpMLineIndex,usernameFragment:n.candidate.usernameFragment}}}var c=k.getMediaSections(r._localDescription.sdp);c[n.candidate.sdpMLineIndex]+=a?"a=end-of-candidates\r\n":"a="+n.candidate.candidate+"\r\n",r._localDescription.sdp=k.getDescription(r._localDescription.sdp)+c.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",n),_&&(r._dispatchEvent("icecandidate",new Event("icecandidate")),r.iceGatheringState="complete",r._emitGatheringStateChange())}},e.setTimeout((function(){n.forEach((function(e){o.onlocalcandidate(e)}))}),0)}},o.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}},o.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)},o.prototype._transceive=function(e,i,r){var o=b(e.localCapabilities,e.remoteCapabilities);i&&e.rtpSender&&(o.encodings=e.sendEncodingParameters,o.rtcp={cname:k.localCName,compound:e.rtcpParameters.compound},e.recvEncodingParameters.length&&(o.rtcp.ssrc=e.recvEncodingParameters[0].ssrc),e.rtpSender.send(o)),r&&e.rtpReceiver&&o.codecs.length>0&&("video"===e.kind&&e.recvEncodingParameters&&t<15019&&e.recvEncodingParameters.forEach((function(e){delete e.rtx})),e.recvEncodingParameters.length?o.encodings=e.recvEncodingParameters:o.encodings=[{}],o.rtcp={compound:e.rtcpParameters.compound},e.rtcpParameters.cname&&(o.rtcp.cname=e.rtcpParameters.cname),e.sendEncodingParameters.length&&(o.rtcp.ssrc=e.sendEncodingParameters[0].ssrc),e.rtpReceiver.receive(o))},o.prototype.setLocalDescription=function(e){var t,i,r=this;if(-1===["offer","answer"].indexOf(e.type))return Promise.reject(M("TypeError",'Unsupported type "'+e.type+'"'));if(!U("setLocalDescription",e.type,r.signalingState)||r._isClosed)return Promise.reject(M("InvalidStateError","Can not set local "+e.type+" in state "+r.signalingState));if("offer"===e.type)t=k.splitSections(e.sdp),i=t.shift(),t.forEach((function(e,t){var i=k.parseRtpParameters(e);r.transceivers[t].localCapabilities=i})),r.transceivers.forEach((function(e,t){r._gather(e.mid,t)}));else if("answer"===e.type){t=k.splitSections(r._remoteDescription.sdp),i=t.shift();var o=k.matchPrefix(i,"a=ice-lite").length>0;t.forEach((function(e,t){var n=r.transceivers[t],s=n.iceGatherer,a=n.iceTransport,d=n.dtlsTransport,c=n.localCapabilities,_=n.remoteCapabilities;if(!(k.isRejected(e)&&0===k.matchPrefix(e,"a=bundle-only").length)&&!n.rejected){var l=k.getIceParameters(e,i),u=k.getDtlsParameters(e,i);o&&(u.role="server"),r.usingBundle&&0!==t||(r._gather(n.mid,t),"new"===a.state&&a.start(s,l,o?"controlling":"controlled"),"new"===d.state&&d.start(u));var h=b(c,_);r._transceive(n,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()},o.prototype.setRemoteDescription=function(o){var n=this;if(-1===["offer","answer"].indexOf(o.type))return Promise.reject(M("TypeError",'Unsupported type "'+o.type+'"'));if(!U("setRemoteDescription",o.type,n.signalingState)||n._isClosed)return Promise.reject(M("InvalidStateError","Can not set remote "+o.type+" in state "+n.signalingState));var s={};n.remoteStreams.forEach((function(e){s[e.id]=e}));var a=[],d=k.splitSections(o.sdp),c=d.shift(),_=k.matchPrefix(c,"a=ice-lite").length>0,l=k.matchPrefix(c,"a=group:BUNDLE ").length>0;n.usingBundle=l;var u=k.matchPrefix(c,"a=ice-options:")[0];return n.canTrickleIceCandidates=!!u&&u.substr(14).split(" ").indexOf("trickle")>=0,d.forEach((function(r,d){var u=k.splitLines(r),h=k.getKind(r),R=k.isRejected(r)&&0===k.matchPrefix(r,"a=bundle-only").length,v=u[0].substr(2).split(" ")[2],C=k.getDirection(r,c),p=k.parseMsid(r),g=k.getMid(r)||k.generateIdentifier();if(R||"application"===h&&("DTLS/SCTP"===v||"UDP/DTLS/SCTP"===v))n.transceivers[d]={mid:g,kind:h,protocol:v,rejected:!0};else{var m,T,I,E,S,f,O,L,N;!R&&n.transceivers[d]&&n.transceivers[d].rejected&&(n.transceivers[d]=n._createTransceiver(h,!0));var A,y,D=k.parseRtpParameters(r);R||(A=k.getIceParameters(r,c),(y=k.getDtlsParameters(r,c)).role="client"),O=k.parseRtpEncodingParameters(r);var U=k.parseRtcpParameters(r),M=k.matchPrefix(r,"a=end-of-candidates",c).length>0,x=k.matchPrefix(r,"a=candidate:").map((function(e){return k.parseCandidate(e)})).filter((function(e){return 1===e.component}));if(("offer"===o.type||"answer"===o.type)&&!R&&l&&d>0&&n.transceivers[d]&&(n._disposeIceAndDtlsTransports(d),n.transceivers[d].iceGatherer=n.transceivers[0].iceGatherer,n.transceivers[d].iceTransport=n.transceivers[0].iceTransport,n.transceivers[d].dtlsTransport=n.transceivers[0].dtlsTransport,n.transceivers[d].rtpSender&&n.transceivers[d].rtpSender.setTransport(n.transceivers[0].dtlsTransport),n.transceivers[d].rtpReceiver&&n.transceivers[d].rtpReceiver.setTransport(n.transceivers[0].dtlsTransport)),"offer"!==o.type||R){if("answer"===o.type&&!R){T=(m=n.transceivers[d]).iceGatherer,I=m.iceTransport,E=m.dtlsTransport,S=m.rtpReceiver,f=m.sendEncodingParameters,L=m.localCapabilities,n.transceivers[d].recvEncodingParameters=O,n.transceivers[d].remoteCapabilities=D,n.transceivers[d].rtcpParameters=U,x.length&&"new"===I.state&&(!_&&!M||l&&0!==d?x.forEach((function(e){P(m.iceTransport,e)})):I.setRemoteCandidates(x)),l&&0!==d||("new"===I.state&&I.start(T,A,"controlling"),"new"===E.state&&E.start(y)),!b(m.localCapabilities,m.remoteCapabilities).codecs.filter((function(e){return"rtx"===e.name.toLowerCase()})).length&&m.sendEncodingParameters[0].rtx&&delete m.sendEncodingParameters[0].rtx,n._transceive(m,"sendrecv"===C||"recvonly"===C,"sendrecv"===C||"sendonly"===C),!S||"sendrecv"!==C&&"sendonly"!==C?delete m.rtpReceiver:(N=S.track,p?(s[p.stream]||(s[p.stream]=new e.MediaStream),i(N,s[p.stream]),a.push([N,S,s[p.stream]])):(s.default||(s.default=new e.MediaStream),i(N,s.default),a.push([N,S,s.default])))}}else{(m=n.transceivers[d]||n._createTransceiver(h)).mid=g,m.iceGatherer||(m.iceGatherer=n._createIceGatherer(d,l)),x.length&&"new"===m.iceTransport.state&&(!M||l&&0!==d?x.forEach((function(e){P(m.iceTransport,e)})):m.iceTransport.setRemoteCandidates(x)),L=e.RTCRtpReceiver.getCapabilities(h),t<15019&&(L.codecs=L.codecs.filter((function(e){return"rtx"!==e.name}))),f=m.sendEncodingParameters||[{ssrc:1001*(2*d+2)}];var w,B=!1;if("sendrecv"===C||"sendonly"===C){if(B=!m.rtpReceiver,S=m.rtpReceiver||new e.RTCRtpReceiver(m.dtlsTransport,h),B)N=S.track,p&&"-"===p.stream||(p?(s[p.stream]||(s[p.stream]=new e.MediaStream,Object.defineProperty(s[p.stream],"id",{get:function(){return p.stream}})),Object.defineProperty(N,"id",{get:function(){return p.track}}),w=s[p.stream]):(s.default||(s.default=new e.MediaStream),w=s.default)),w&&(i(N,w),m.associatedRemoteMediaStreams.push(w)),a.push([N,S,w])}else m.rtpReceiver&&m.rtpReceiver.track&&(m.associatedRemoteMediaStreams.forEach((function(t){var i=t.getTracks().find((function(e){return e.id===m.rtpReceiver.track.id}));i&&function(t,i){i.removeTrack(t),i.dispatchEvent(new e.MediaStreamTrackEvent("removetrack",{track:t}))}(i,t)})),m.associatedRemoteMediaStreams=[]);m.localCapabilities=L,m.remoteCapabilities=D,m.rtpReceiver=S,m.rtcpParameters=U,m.sendEncodingParameters=f,m.recvEncodingParameters=O,n._transceive(n.transceivers[d],!1,B)}}})),void 0===n._dtlsRole&&(n._dtlsRole="offer"===o.type?"active":"passive"),n._remoteDescription={type:o.type,sdp:o.sdp},"offer"===o.type?n._updateSignalingState("have-remote-offer"):n._updateSignalingState("stable"),Object.keys(s).forEach((function(t){var i=s[t];if(i.getTracks().length){if(-1===n.remoteStreams.indexOf(i)){n.remoteStreams.push(i);var o=new Event("addstream");o.stream=i,e.setTimeout((function(){n._dispatchEvent("addstream",o)}))}a.forEach((function(e){var t=e[0],o=e[1];i.id===e[2].id&&r(n,t,o,[i])}))}})),a.forEach((function(e){e[2]||r(n,e[0],e[1],[])})),e.setTimeout((function(){n&&n.transceivers&&n.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()},o.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")},o.prototype._updateSignalingState=function(e){this.signalingState=e;var t=new Event("signalingstatechange");this._dispatchEvent("signalingstatechange",t)},o.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))},o.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)}},o.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)}},o.prototype.createOffer=function(){var i=this;if(i._isClosed)return Promise.reject(M("InvalidStateError","Can not call createOffer after close"));var r=i.transceivers.filter((function(e){return"audio"===e.kind})).length,o=i.transceivers.filter((function(e){return"video"===e.kind})).length,n=arguments[0];if(n){if(n.mandatory||n.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");void 0!==n.offerToReceiveAudio&&(r=!0===n.offerToReceiveAudio?1:!1===n.offerToReceiveAudio?0:n.offerToReceiveAudio),void 0!==n.offerToReceiveVideo&&(o=!0===n.offerToReceiveVideo?1:!1===n.offerToReceiveVideo?0:n.offerToReceiveVideo)}for(i.transceivers.forEach((function(e){"audio"===e.kind?--r<0&&(e.wantReceive=!1):"video"===e.kind&&--o<0&&(e.wantReceive=!1)}));r>0||o>0;)r>0&&(i._createTransceiver("audio"),r--),o>0&&(i._createTransceiver("video"),o--);var s=k.writeSessionBoilerplate(i._sdpSessionId,i._sdpSessionVersion++);i.transceivers.forEach((function(r,o){var n=r.track,s=r.kind,a=r.mid||k.generateIdentifier();r.mid=a,r.iceGatherer||(r.iceGatherer=i._createIceGatherer(o,i.usingBundle));var d=e.RTCRtpSender.getCapabilities(s);t<15019&&(d.codecs=d.codecs.filter((function(e){return"rtx"!==e.name}))),d.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)}))})),d.headerExtensions.forEach((function(e){(r.remoteCapabilities&&r.remoteCapabilities.headerExtensions||[]).forEach((function(t){e.uri===t.uri&&(e.id=t.id)}))}));var c=r.sendEncodingParameters||[{ssrc:1001*(2*o+1)}];n&&t>=15019&&"video"===s&&!c[0].rtx&&(c[0].rtx={ssrc:c[0].ssrc+1}),r.wantReceive&&(r.rtpReceiver=new e.RTCRtpReceiver(r.dtlsTransport,s)),r.localCapabilities=d,r.sendEncodingParameters=c})),"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+=D(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="+k.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)},o.prototype.createAnswer=function(){var i=this;if(i._isClosed)return Promise.reject(M("InvalidStateError","Can not call createAnswer after close"));if("have-remote-offer"!==i.signalingState&&"have-local-pranswer"!==i.signalingState)return Promise.reject(M("InvalidStateError","Can not call createAnswer in signalingState "+i.signalingState));var r=k.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 o=k.getMediaSections(i._remoteDescription.sdp).length;i.transceivers.forEach((function(e,n){if(!(n+1>o)){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=b(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+=D(e,a,"answer",e.stream,i._dtlsRole),e.rtcpParameters&&e.rtcpParameters.reducedSize&&(r+="a=rtcp-rsize\r\n")}}));var n=new e.RTCSessionDescription({type:"answer",sdp:r});return Promise.resolve(n)},o.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,o){if(!i._remoteDescription)return o(M("InvalidStateError","Can not add ICE candidate without a remote description"));if(e&&""!==e.candidate){var n=e.sdpMLineIndex;if(e.sdpMid)for(var s=0;s<i.transceivers.length;s++)if(i.transceivers[s].mid===e.sdpMid){n=s;break}var a=i.transceivers[n];if(!a)return o(M("OperationError","Can not add ICE candidate"));if(a.rejected)return r();var d=Object.keys(e.candidate).length>0?k.parseCandidate(e.candidate):{};if("tcp"===d.protocol&&(0===d.port||9===d.port))return r();if(d.component&&1!==d.component)return r();if((0===n||n>0&&a.iceTransport!==i.transceivers[0].iceTransport)&&!P(a.iceTransport,d))return o(M("OperationError","Can not add ICE candidate"));var c=e.candidate.trim();0===c.indexOf("a=")&&(c=c.substr(2)),(t=k.getMediaSections(i._remoteDescription.sdp))[n]+="a="+(d.type?c:"end-of-candidates")+"\r\n",i._remoteDescription.sdp=k.getDescription(i._remoteDescription.sdp)+t.join("")}else for(var _=0;_<i.transceivers.length&&(i.transceivers[_].rejected||(i.transceivers[_].iceTransport.addRemoteCandidate({}),(t=k.getMediaSections(i._remoteDescription.sdp))[_]+="a=end-of-candidates\r\n",i._remoteDescription.sdp=k.getDescription(i._remoteDescription.sdp)+t.join(""),!i.usingBundle));_++);r()}))},o.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 M("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 n=["createOffer","createAnswer"];return n.forEach((function(e){var t=o.prototype[e];o.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)}})),(n=["setLocalDescription","setRemoteDescription","addIceCandidate"]).forEach((function(e){var t=o.prototype[e];o.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=o.prototype[e];o.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)}})),o};function w(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 B(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 V(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=x(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&&h("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),u("ICE servers after filtering:",e.iceServers)),new i(e)},e.RTCPeerConnection.prototype=i.prototype}function F(e){e.RTCRtpSender&&!("replaceTrack"in e.RTCRtpSender.prototype)&&(e.RTCRtpSender.prototype.replaceTrack=e.RTCRtpSender.prototype.setTrack)}var J=Object.freeze({__proto__:null,shimPeerConnection:V,shimReplaceTrack:F,shimGetUserMedia:w,shimGetDisplayMedia:B});function H(e,t){const i=e&&e.navigator,r=e&&e.MediaStreamTrack;if(i.getUserMedia=function(e,t,r){h("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 G(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 K(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,o,n]=arguments;return r.apply(this,[e||null]).then((e=>{if(t.version<53&&!o)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(o,n)}}function j(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 $(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}),c(e,"track",(e=>(e.receiver._pc=e.srcElement,e))),e.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function W(e){e.RTCPeerConnection&&!("removeStream"in e.RTCPeerConnection.prototype)&&(e.RTCPeerConnection.prototype.removeStream=function(e){h("removeStream","removeTrack"),this.getSenders().forEach((t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)}))})}function q(e){e.DataChannel&&!e.RTCDataChannel&&(e.RTCDataChannel=e.DataChannel)}function Y(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 z(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 Z(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 Q(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 X=Object.freeze({__proto__:null,shimOnTrack:G,shimPeerConnection:K,shimSenderGetStats:j,shimReceiverGetStats:$,shimRemoveStream:W,shimRTCDataChannel:q,shimAddTransceiver:Y,shimGetParameters:z,shimCreateOffer:Z,shimCreateAnswer:Q,shimGetUserMedia:H,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 ee(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 ie(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype,i=t.createOffer,r=t.createAnswer,o=t.setLocalDescription,n=t.setRemoteDescription,s=t.addIceCandidate;t.createOffer=function(e,t){const r=arguments.length>=2?arguments[2]:arguments[0],o=i.apply(this,[r]);return t?(o.then(e,t),Promise.resolve()):o},t.createAnswer=function(e,t){const i=arguments.length>=2?arguments[2]:arguments[0],o=r.apply(this,[i]);return t?(o.then(e,t),Promise.resolve()):o};let a=function(e,t,i){const r=o.apply(this,[e]);return i?(r.then(t,i),Promise.resolve()):r};t.setLocalDescription=a,a=function(e,t,i){const r=n.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 re(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:v(e.video)}):e}function ne(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")?(h("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 se(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 de(e){"object"!=typeof e||e.AudioContext||(e.AudioContext=e.webkitAudioContext)}var ce=Object.freeze({__proto__:null,shimLocalStreamsAPI:ee,shimRemoteStreamsAPI:te,shimCallbacksAPI:ie,shimGetUserMedia:re,shimConstraints:oe,shimRTCIceServerUrls:ne,shimTrackEventTransceiver:se,shimCreateOfferLegacy:ae,shimAudioContext:de});function _e(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=k.parseCandidate(e.candidate),o=Object.assign(i,r);return o.toJSON=function(){return{candidate:o.candidate,sdpMid:o.sdpMid,sdpMLineIndex:o.sdpMLineIndex,usernameFragment:o.usernameFragment}},o}return new t(e)},e.RTCIceCandidate.prototype=t.prototype,c(e,"icecandidate",(t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new e.RTCIceCandidate(t.candidate),writable:"false"}),t)))}function le(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=k.splitSections(e.sdp);return t.shift(),t.some((e=>{const t=k.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},o=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},n=function(e,i){let r=65536;"firefox"===t.browser&&57===t.version&&(r=65535);const o=k.matchPrefix(e.sdp,"a=max-message-size:");return o.length>0?r=parseInt(o[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=o(e),i=n(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],o=r.length||r.size||r.byteLength;if("open"===e.readyState&&t.sctp&&o>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},c(e,"datachannel",(e=>(t(e.channel,e.target),e)))}function he(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 Re(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 ve(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 Ce=Object.freeze({__proto__:null,shimRTCIceCandidate:_e,shimMaxMessageSize:le,shimSendThrowTypeError:ue,shimConnectionState:he,removeExtmapAllowMixed:Re,shimAddIceCandidateNullOrEmpty:ve});const pe=function({window:e}={},t={shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0}){const i=u,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=d(i.userAgent,/Firefox\/(\d+)\./,1);else if(i.webkitGetUserMedia||!1===e.isSecureContext&&e.webkitRTCPeerConnection&&!e.RTCIceGatherer)t.browser="chrome",t.version=d(i.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(i.mediaDevices&&i.userAgent.match(/Edge\/(\d+).(\d+)$/))t.browser="edge",t.version=d(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=d(i.userAgent,/AppleWebKit\/(\d+)\./,1),t.supportsUnifiedPlan=e.RTCRtpTransceiver&&"currentDirection"in e.RTCRtpTransceiver.prototype}return t}(e),o={browserDetails:r,commonShim:Ce,extractVersion:d,disableLog:_,disableWarnings:l};switch(r.browser){case"chrome":if(!y||!N||!t.shimChrome)return i("Chrome shim is not included in this adapter release."),o;if(null===r.version)return i("Chrome shim can not determine version, not shimming."),o;i("adapter.js shimming chrome."),o.browserShim=y,ve(e,r),m(e,r),T(e),N(e,r),I(e),L(e,r),E(e),S(e),f(e),A(e,r),_e(e),he(e),le(e,r),ue(e),Re(e,r);break;case"firefox":if(!X||!K||!t.shimFirefox)return i("Firefox shim is not included in this adapter release."),o;i("adapter.js shimming firefox."),o.browserShim=X,ve(e,r),H(e,r),K(e,r),G(e),W(e),j(e),$(e),q(e),Y(e),z(e),Z(e),Q(e),_e(e),he(e),le(e,r),ue(e);break;case"edge":if(!J||!V||!t.shimEdge)return i("MS edge shim is not included in this adapter release."),o;i("adapter.js shimming edge."),o.browserShim=J,w(e),B(e),V(e,r),F(e),le(e,r),ue(e);break;case"safari":if(!ce||!t.shimSafari)return i("Safari shim is not included in this adapter release."),o;i("adapter.js shimming safari."),o.browserShim=ce,ve(e,r),ne(e),ae(e),ie(e),ee(e),te(e),se(e),re(e),de(e),_e(e),le(e,r),ue(e),Re(e,r);break;default:i("Unsupported browser!")}return o}({window:"undefined"==typeof window?void 0:window});var ge,me,Te;e.RCFrameRate=void 0,(ge=e.RCFrameRate||(e.RCFrameRate={})).FPS_10="FPS_10",ge.FPS_15="FPS_15",ge.FPS_24="FPS_24",ge.FPS_30="FPS_30",e.RCResolution=void 0,(me=e.RCResolution||(e.RCResolution={})).W176_H132="W176_H132",me.W176_H144="W176_H144",me.W180_H180="W180_H180",me.W240_H180="W240_H180",me.W240_H240="W240_H240",me.W256_H144="W256_H144",me.W320_H180="W320_H180",me.W320_H240="W320_H240",me.W360_H360="W360_H360",me.W480_H360="W480_H360",me.W480_H480="W480_H480",me.W640_H360="W640_H360",me.W640_H480="W640_H480",me.W720_H480="W720_H480",me.W848_H480="W848_H480",me.W960_H720="W960_H720",me.W1280_H720="W1280_H720",me.W1920_H1080="W1920_H1080",me.W144_H176="W144_H176",me.W144_H256="W144_H256",me.W180_H240="W180_H240",me.W180_H320="W180_H320",me.W240_H320="W240_H320",me.W360_H480="W360_H480",me.W360_H640="W360_H640",me.W480_H640="W480_H640",me.W480_H720="W480_H720",me.W480_H848="W480_H848",me.W720_H1280="W720_H1280",me.W720_H960="W720_H960",me.W1080_H1920="W1080_H1920",e.RCMediaType=void 0,(Te=e.RCMediaType||(e.RCMediaType={}))[Te.AUDIO_ONLY=0]="AUDIO_ONLY",Te[Te.VIDEO_ONLY=1]="VIDEO_ONLY",Te[Te.AUDIO_VIDEO=2]="AUDIO_VIDEO";const Ie={[e.RCResolution.W176_H132]:{width:176,height:132,maxBitrate:150,minBitrate:80},[e.RCResolution.W176_H144]:{width:176,height:144,maxBitrate:150,minBitrate:80},[e.RCResolution.W180_H180]:{width:180,height:180,maxBitrate:200,minBitrate:100},[e.RCResolution.W240_H180]:{width:240,height:180,maxBitrate:240,minBitrate:120},[e.RCResolution.W240_H240]:{width:240,height:240,maxBitrate:280,minBitrate:120},[e.RCResolution.W256_H144]:{width:256,height:144,maxBitrate:240,minBitrate:120},[e.RCResolution.W320_H180]:{width:320,height:180,maxBitrate:280,minBitrate:120},[e.RCResolution.W320_H240]:{width:320,height:240,maxBitrate:400,minBitrate:120},[e.RCResolution.W360_H360]:{width:360,height:360,maxBitrate:520,minBitrate:140},[e.RCResolution.W480_H360]:{width:480,height:360,maxBitrate:650,minBitrate:150},[e.RCResolution.W480_H480]:{width:480,height:480,maxBitrate:800,minBitrate:180},[e.RCResolution.W640_H360]:{width:640,height:360,maxBitrate:800,minBitrate:180},[e.RCResolution.W640_H480]:{width:640,height:480,maxBitrate:900,minBitrate:200},[e.RCResolution.W720_H480]:{width:720,height:480,maxBitrate:1e3,minBitrate:200},[e.RCResolution.W848_H480]:{width:848,height:480,maxBitrate:1860,minBitrate:200},[e.RCResolution.W960_H720]:{width:960,height:720,maxBitrate:2e3,minBitrate:250},[e.RCResolution.W1280_H720]:{width:1280,height:720,maxBitrate:2200,minBitrate:250},[e.RCResolution.W1920_H1080]:{width:1920,height:1080,maxBitrate:4e3,minBitrate:400},[e.RCResolution.W144_H176]:{width:144,height:176,maxBitrate:150,minBitrate:80},[e.RCResolution.W144_H256]:{width:144,height:256,maxBitrate:240,minBitrate:120},[e.RCResolution.W180_H240]:{width:180,height:240,maxBitrate:240,minBitrate:120},[e.RCResolution.W180_H320]:{width:180,height:320,maxBitrate:280,minBitrate:120},[e.RCResolution.W240_H320]:{width:240,height:320,maxBitrate:400,minBitrate:120},[e.RCResolution.W360_H480]:{width:360,height:480,maxBitrate:650,minBitrate:150},[e.RCResolution.W360_H640]:{width:360,height:640,maxBitrate:800,minBitrate:180},[e.RCResolution.W480_H640]:{width:480,height:640,maxBitrate:900,minBitrate:200},[e.RCResolution.W480_H720]:{width:480,height:720,maxBitrate:1e3,minBitrate:200},[e.RCResolution.W480_H848]:{width:480,height:848,maxBitrate:1860,minBitrate:930},[e.RCResolution.W720_H1280]:{width:720,height:1280,maxBitrate:2200,minBitrate:250},[e.RCResolution.W720_H960]:{width:720,height:960,maxBitrate:2760,minBitrate:910},[e.RCResolution.W1080_H1920]:{width:1080,height:1920,maxBitrate:4e3,minBitrate:400}},Ee=e=>{const t={192:180,368:360,1088:1080};return t[e]?t[e]:e},Se=(e,t)=>{e=Ee(e),t=Ee(t);const i=Ie[`W${e}_H${t}`];if(i)return i;const r=e*t;return Object.keys(Ie).map((e=>Ie[e])).sort(((e,t)=>e.height*e.width-t.width*t.height)).filter((e=>e.height*e.width>=r))[0]||Ie.W1920_H1080},fe={10:1,15:1,24:1.5,30:1.5},Oe=e=>{let t=Number.MAX_VALUE,i=1;for(const r in fe){const o=Math.abs(e-parseInt(r));o<t&&(t=o,i=fe[r])}return i};class Le{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}}Le._logger=null;const Ne=new Le,Ae={getCameras:()=>i(void 0,void 0,void 0,(function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind))})),getMicrophones:()=>i(void 0,void 0,void 0,(function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"audioinput"===e.kind))})),getSpeakers:()=>i(void 0,void 0,void 0,(function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"audiooutput"===e.kind))}))};var ye,ke;!function(e){e.AUDIO="audio",e.VIDEO="video"}(ye||(ye={}));class De extends t.EventEmitter{constructor(e,t,i,r,o){super(),this._tag=e,this._userId=t,this._kind=i,this._isLocalTrack=r,this._roomId=o,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=Le.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(r,s){var a,d,c,_,l,u,h,R,v,C,p,g,m;return i(this,void 0,void 0,(function*(){if(null===(a=this._logger)||void 0===a||a.info(o.L_TRACK_PLAY_O,JSON.stringify({element:r,options:s,kind:null!==(d=this._kind)&&void 0!==d?d:"",msg:`start play trackId: ${this._id}`})),!this._msTrack)return null===(c=this._logger)||void 0===c||c.error(o.L_TRACK_PLAY_E,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.TRACK_NOT_READY,kind:null!==(_=this._kind)&&void 0!==_?_:"",msg:`the track is not ready to play -> id: ${this._id}`})),{code:e.RCRTCCode.TRACK_NOT_READY};if("ended"===this._msTrack.readyState&&(null===(l=this._logger)||void 0===l||l.error(o.L_TRACK_PLAY_E,JSON.stringify({status:n.FAILED,kind:null!==(u=this._kind)&&void 0!==u?u:"",msg:`the track's readyState is ended -> id: ${this._id}`}))),null==s?void 0:s.volume){if(!t.isNumber(null==s?void 0:s.volume))return null===(h=this._logger)||void 0===h||h.error(o.L_TRACK_PLAY_E,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> options.volume not a number"})),{code:e.RCRTCCode.PARAMS_ERROR};(null==s?void 0:s.volume)<0&&(s.volume=0,null===(R=this._logger)||void 0===R||R.warn(o.L_TRACK_PLAY_E,JSON.stringify({status:n.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==s?void 0:s.volume)>100&&(s.volume=100,null===(v=this._logger)||void 0===v||v.warn(o.L_TRACK_PLAY_E,JSON.stringify({status:n.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==s?void 0:s.audioDeviceId){if(!(yield Ae.getSpeakers()).map((e=>e.deviceId)).includes(s.audioDeviceId))return null===(C=this._logger)||void 0===C||C.error(o.L_TRACK_PLAY_E,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> options.audioDeviceId"})),{code:e.RCRTCCode.PARAMS_ERROR}}const T=this.isVideoTrack();return!T||r&&(r instanceof HTMLVideoElement||this.__validateVideoNodeName(r))?(this._element=T?r: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(o.L_TRACK_LOAD_START_O,JSON.stringify({status:n.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(o.L_TRACK_DURATION_CHANGE_O,JSON.stringify({status:n.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(o.L_TRACK_LOADED_META_DATA_O,JSON.stringify({status:n.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(o.L_TRACK_LOADED_DATA_O,JSON.stringify({status:n.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(o.L_TRACK_ABORT_O,JSON.stringify({status:n.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=t=>i(this,void 0,void 0,(function*(){var i,r,a,d,c,_,l,u;null===(i=this._logger)||void 0===i||i.info(o.L_TRACK_CANPLAY_O,JSON.stringify({status:n.INFO,kind:null!==(r=this._kind)&&void 0!==r?r:"",msg:`HTMLMediaElement oncanplay -> id: ${null===(a=t.target)||void 0===a?void 0:a.id}, trackId: ${this._id}`}));try{(null==s?void 0:s.audioDeviceId)&&!T&&(yield this._element.setSinkId(s.audioDeviceId)),yield null===(d=this._element)||void 0===d?void 0:d.play()}catch(t){if("No permission to use requested device"===t.message)return void(null===(c=this._logger)||void 0===c||c.error(o.L_TRACK_PLAY_E,JSON.stringify({status:n.FAILED,kind:null!==(_=this._kind)&&void 0!==_?_:"",code:e.RCRTCCode.NO_PERMISSION_TO_USE_REQUESTED_DEVICE,msg:`setSinkId failed, error msg: ${t.message}`})));null===(l=this._logger)||void 0===l||l.error(o.L_TRACK_PLAY_E,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.TRACK_PLAY_ERROR,kind:null!==(u=this._kind)&&void 0!==u?u:"",msg:`play error, error msg: ${t.message}`}))}})),this._element.onvolumechange=e=>{var t,i,r;const s=Math.floor(100*(null===(t=e.target)||void 0===t?void 0:t.volume));null===(i=this._logger)||void 0===i||i.info(o.L_TRACK_VOLUME_CHANGE_O,JSON.stringify({status:n.INFO,msg:`HTMLMediaElement onvolumechange -> id: ${null===(r=e.target)||void 0===r?void 0:r.id}, volume: ${s}, trackId: ${this._id}`}))},this._element.srcObject=this._msStream,this._element.autoplay=!0,T&&(this._element.playsInline=!0,this._element.x5PlaysInline=!0,this._element.webkitPlaysInline=!0),(null==s?void 0:s.audioDeviceId)&&!T&&(yield this._element.setSinkId(s.audioDeviceId)),T||!(null==s?void 0:s.volume)&&0!==(null==s?void 0:s.volume)||(this._element.volume=(null==s?void 0:s.volume)/100),null===(m=this._element)||void 0===m||m.setAttribute(this.DataTrackId,this.getTrackId()),{code:e.RCRTCCode.SUCCESS}):(null===(p=this._logger)||void 0===p||p.error(o.L_TRACK_PLAY_E,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.VIDEO_TRACK_MISS_MEDIA_ELEMENT,kind:null!==(g=this._kind)&&void 0!==g?g:"",msg:"params element is not a HTMLVideoElement"})),{code:e.RCRTCCode.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()}}e.RCAudioBitrate=void 0,(ke=e.RCAudioBitrate||(e.RCAudioBitrate={})).Speech="Speech",ke.Music="Music",ke.MusicHigh="MusicHigh";const be={[e.RCAudioBitrate.Music]:{max:64,min:64},[e.RCAudioBitrate.MusicHigh]:{max:128,min:128},[e.RCAudioBitrate.Speech]:{max:32,min:32}};var Ue;e.RCVideoBitrate=void 0,(Ue=e.RCVideoBitrate||(e.RCVideoBitrate={})).LEVEL0="LEVEL0",Ue.LEVEL1="LEVEL1",Ue.LEVEL2="LEVEL2",Ue.LEVEL3="LEVEL3",Ue.LEVEL4="LEVEL4",Ue.LEVEL5="LEVEL5";const Pe={[e.RCVideoBitrate.LEVEL0]:{max:150,min:80},[e.RCVideoBitrate.LEVEL1]:{max:280,min:120},[e.RCVideoBitrate.LEVEL2]:{max:650,min:150},[e.RCVideoBitrate.LEVEL3]:{max:1e3,min:200},[e.RCVideoBitrate.LEVEL4]:{max:2200,min:250},[e.RCVideoBitrate.LEVEL5]:{max:4e3,min:400}};class Me{static setStatus(e=!0){Me.isOpen=e}static setWroklet(e,t){Me.workletModule=e,Me.workletModule=t}static transformStreamTrack(e){var t;return i(this,void 0,void 0,(function*(){const i=Le.getLogger();if(!Me.isOpen)return new Promise((t=>{t({track:null==e?void 0:e.getAudioTracks()[0],stop:()=>{}})}));let r=new AudioContext({sampleRate:44100}),s=r.createMediaStreamSource(e),a=r.createMediaStreamDestination(),d=null,c=null;if(d=yield r.audioWorklet.addModule(Me.workletModule).then((()=>(null==i||i.info(o.L_RTC_3ANOISE_NODE_O,JSON.stringify({status:n.SUCCESSED,message:{msg:"addModule RC3AnoiseTrack.workletModule success"}})),fetch(Me.workletWasm,{cache:"force-cache",credentials:"same-origin"}).then((e=>e.arrayBuffer())).catch((e=>{throw new Error(e.message)}))))).then((e=>(c=new AudioWorkletNode(r,"process-worklet",{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[1],processorOptions:{binary:e}}),c))).catch((e=>{null==i||i.info(o.L_RTC_3ANOISE_NODE_E,JSON.stringify({status:n.FAILED,message:{msg:e.message}}))})),!d)return new Promise((t=>{t({track:null==e?void 0:e.getAudioTracks()[0],stop:()=>{}})}));s.connect(d).connect(a);let _=null===(t=null==a?void 0:a.stream)||void 0===t?void 0:t.getAudioTracks()[0],l=()=>{null==i||i.info(o.L_RTC_3ANOISE_NODE_STOP_O,JSON.stringify({status:n.SUCCESSED,message:{msg:"call stop RC3AnoiseTrack.workletModule"}})),null==d||d.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==a||a.disconnect(),null==d||d.disconnect(),null==s||s.disconnect(),r=null,d=null,a=null,s=null,c=null,e=null,null==_||_.stop(),_=null,l=null}),200)};return{track:_,stop:l}}))}}Me.workletModule="https://cdn.ronghub.com/plugin-rtc/wasm/5.0.0-alpha.2/process-worklet.js",Me.workletWasm="https://cdn.ronghub.com/plugin-rtc/wasm/5.0.0-alpha.2/AudioProcessing.wasm",Me.isOpen=!1;class xe extends De{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(xe.EVENT_LOCAL_TRACK_END,this),this.removeAll(xe.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(xe.__INNER_EVENT_MUTED_CHANGE__,this,t),null===(r=this._logger)||void 0===r||r.info(o.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(xe.__INNER_EVENT_DESTROY__,this),null===(t=this._logger)||void 0===t||t.info(o.L_LOCAL_TRACK_DESTROY_O,JSON.stringify({status:n.SUCCESSED,trackId:this._id}))}isDestroyed(){return this._isDestroyed}setBitrate(e=0,i=0,r=0){var s,a;!t.isNumber(e)||!t.isNumber(i)||!t.isNumber(r)||e<=0||i<=0||e<i?null===(s=this._logger)||void 0===s||s.error(o.L_LOCAL_TRACK_SET_BITRATE_O,JSON.stringify({status:n.FAILED,msg:`params error -> max: ${e},min: ${i}, start: ${r}`,trackId:this._id})):(null===(a=this._logger)||void 0===a||a.info(o.L_LOCAL_TRACK_SET_BITRATE_O,JSON.stringify({status:n.SUCCESSED,max:e,min:i,start:r,trackId:this._id})),this._bitrateInfo={max:e,min:i,start:r})}getBitrate(){var e,t,i,r,o,n,s;let{min:a,max:d,start:c}={min:0,max:0,start:0};return(null===(e=this._msTrack)||void 0===e?void 0:e.kind)===ye.VIDEO?({min:a,max:d}=tt(this._msTrack)):(null===(t=this._msTrack)||void 0===t?void 0:t.kind)===ye.AUDIO&&({min:a,max:d}={min:32,max:32}),(null===(i=this._bitrateInfo)||void 0===i?void 0:i.max)&&(c=.7*(null===(r=this._bitrateInfo)||void 0===r?void 0:r.max)),{min:(null===(o=this._bitrateInfo)||void 0===o?void 0:o.min)||a,max:(null===(n=this._bitrateInfo)||void 0===n?void 0:n.max)||d,start:(null===(s=this._bitrateInfo)||void 0===s?void 0:s.start)||c}}}xe.EVENT_LOCAL_TRACK_END="local-track-end",xe.__INNER_EVENT_MUTED_CHANGE__="inner-muted-change",xe.__INNER_EVENT_DESTROY__="inner-destroy";class we extends xe{constructor(e,t,i){super(e,t,"audio",i),this._stopProcess=()=>{}}setRecommendBitrate(i){const r=Le.getLogger();if(!t.validate("audioBitrate",i,(t=>t in e.RCAudioBitrate)))return void(null==r||r.warn(o.L_RTC_SET_RECOMMEND_BITRATE_O,JSON.stringify({status:n.FAILED,msg:"params error -> params type is RCAudioBitrate"})));const s=be[i];this.setBitrate(s.max,s.min,s.start||.7*s.max)}setBitrate(e,...t){const[i=1,r=.7*e||1]=t;super.setBitrate(e,i,r)}__innerSetMediaStreamTrack(e){if(e)if(Me.isOpen){const t=new MediaStream([e]);Me.transformStreamTrack(t).then((({track:e,stop:t})=>{super.__innerSetMediaStreamTrack(e),this._stopProcess=t}))}else super.__innerSetMediaStreamTrack(e);else super.__innerSetMediaStreamTrack(e),this._stopProcess()}}class Be extends xe{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(i){const r=Le.getLogger();if(!t.validate("videoBitrate",i,(t=>t in e.RCVideoBitrate)))return void(null==r||r.warn(o.L_RTC_SET_RECOMMEND_BITRATE_O,JSON.stringify({status:n.FAILED,msg:"params error -> params type is RCVideoBitrate"})));const s=Pe[i];this.setBitrate(s.max,s.min,s.start||.7*s.max)}setBitrate(e,...t){const[i=1,r=.7*e||1]=t;super.setBitrate(e,i,r)}}class Ve extends xe{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 o=null===(i=this._mapping.get(t))||void 0===i?void 0:i.filter((t=>t!==e));o&&o.length>0?this._mapping.set(t,o):(this._mapping.delete(t),t.pause(),t.src="",null===(r=t.parentNode)||void 0===r||r.removeChild(t))}constructor(e,t,i,r,o){super(e,t,i,r),this._resource=o,Ve.__innerSetMapping(this.getTrackId(),o)}destroy(){this.isAudioTrack()&&this.mute(),Ve.__innerRemoveMapping(this.getTrackId(),this._resource),super.destroy()}}Ve._mapping=new Map;class Fe extends Ve{constructor(e,t,i,r){super(e,t,"video",i,r)}}class Je extends Ve{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 i(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:e.RCRTCCode.SUCCESS})}__innerSetMediaStreamTrack(e){if(e)if(Me.isOpen){const t=new MediaStream([e]);Me.transformStreamTrack(t).then((({track:e,stop:t})=>{super.__innerSetMediaStreamTrack(e),this._stopProcess=t}))}else super.__innerSetMediaStreamTrack(e);else super.__innerSetMediaStreamTrack(e),this._stopProcess()}}class He extends we{}class Ge extends Be{}class Ke extends Be{}class je extends we{}class $e extends De{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 We extends $e{constructor(e,t,i){super(e,t,"audio",i)}}class qe extends $e{constructor(e,t,i){super(e,t,"video",i),this._isSubTiny=!1}__innerSetIsTinyTrack(e){this._isSubTiny=e}isSubTiny(){return this._isSubTiny}}const Ye=(e,t)=>({name:e,content:JSON.stringify({uris:t,ignore:!0})}),ze=e=>JSON.stringify(e),Ze=e=>/^[a-zA-Z\d-=]+$/g.test(e),Qe="http:"!==location.protocol||["localhost","127.0.0.1"].includes(location.hostname),Xe=e=>{if(void 0===e)return 0;if(t.isNumber(e))return e;const i=e;return i.exact||i.ideal||i.max||0},et=e=>{const t=e.getSettings(),i=e.getConstraints();return{width:Xe(i.width)||t.width||0,height:Xe(i.height)||t.height||0,frameRate:t.frameRate||Xe(i.frameRate)}},tt=e=>{const{width:t,height:i,frameRate:r}=et(e),o=Se(t||1920,i||1080),n=Oe(r);return{min:o.minBitrate*n,max:o.maxBitrate*n}},it=e=>[e.msid,e.mediaType].join("_"),rt=e=>{const t=e.split("_");return{mediaType:parseInt(t.pop()),tag:t.pop(),userId:t.join("_")}},ot=(e,t)=>[e,t].join("_"),nt=e=>e.map((e=>Object.assign({},e))),st=(e,t,i=!1)=>{e=e.slice();const r=[],o=[],n=[];return t.forEach((t=>{const o=it(t);let s=e.findIndex((e=>it(e)===o));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&&n.push(t),e.splice(s,1)})),o.push(...e),{publishedList:r,unpublishedList:o,modifiedList:n}},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 o=[];do{const e=r%i;r=(r-e)/i,o.unshift(t[e])}while(r);return o.join("")})(e),e.length>22&&(e=e.slice(0,22)),e},dt=e=>{if(Ie[e]){const{width:t,height:i}=Ie[e];return{width:t,height:i}}const[t,i]=e.split("_").map((e=>parseInt(e.replace(/[^\d]/g,""))));return{width:t,height:i}},ct=t=>!!e.RCResolution[t],_t=t=>!!e.RCFrameRate[t],lt=e=>parseInt(e.replace("FPS_","")),ut=(()=>{const{browser:e,version:t,supportsUnifiedPlan:i}=pe.browserDetails;return{browser:e,version:t,supportsUnifiedPlan:!1!==i}})();function ht(){return"captureStream"in HTMLMediaElement.prototype||"mozCaptureStream"in HTMLMediaElement.prototype}function Rt(){return"mediaDevices"in navigator&&"getDisplayMedia"in navigator.mediaDevices}const vt=e=>"[object Null]"===Object.prototype.toString.call(e),Ct=e=>1===e.type,pt=(e,t,i)=>{const r={},n=Object.keys(e.users);return n.length&&n.forEach((n=>{const s=[],a=e.users[n];if(a.extra){const{roomId:e}=JSON.parse(a.extra);if(t!==e)return}if(a.uris)try{s.push(...JSON.parse(a.uris))}catch(e){const t=Le.getLogger();null==t||t.warn(o.L_PARSE_ROOMDATA_URIS_R,`invalid user data -> userId: ${n}, userData: ${a}`,i)}r[n]=s})),r},gt=(t,i)=>{const r=i.filter((e=>"RC_RTC_SESSIONID"===e.key))[0],o=r?r.value:"",n=i.filter((e=>"RC_ANCHOR_LIST"===e.key)).map((e=>JSON.parse(e.value||"[]")))[0],s=i.filter((e=>e.key.includes("RC_RES_"))).map((e=>JSON.parse(e.value||"{}"))),a=s.length?JSON.parse(s[0].mcu_uris||"[]"):[],d=[];a.forEach((i=>{const{mediaType:r,tag:o}=i,n=r===e.RCMediaType.AUDIO_ONLY?new We(o,"",t):new qe(o,"",t);d.push(n)}));const c=[],_=[];s.forEach((t=>{const i=JSON.parse(t.uris||"[]");c.push(...i),i.forEach((t=>{const{mediaType:i,tag:r,msid:o}=t,n=o.split("_")[0],s=i===e.RCMediaType.AUDIO_ONLY?new We(r,n):new qe(r,n);_.push(s)}))}));const l=i.filter((e=>"RC_CDN"===e.key)).map((e=>{const t=JSON.parse(e.value||"[]");return JSON.parse(t.cdn_uris)[0]}))[0];return{sessionId:o,remoteUserIds:n||[],remoteRTCUris:c,remoteMUCUris:a,remoteRTCTracks:_,remoteMCUTracks:d,remoteTracks:[..._,...d],CDNUris:l||{}}},mt=e=>e instanceof De?e.getTrackId():e.track.getTrackId(),Tt=e=>{if(!t.isObject(e)||void 0===e.low||void 0===e.high)return e;let{low:i}=e;i<0&&(i+=4294967296),i=i.toString(16);return parseInt(e.high.toString(16)+"00000000".replace(new RegExp(`0{${i.length}}$`),i),16)};var It,Et;!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"}(It||(It={})),e.RCRTCPingResult=void 0,(Et=e.RCRTCPingResult||(e.RCRTCPingResult={})).SUCCESS="Success",Et.FAIL="Fail";class St{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:o,roomMode:n}=this._store;this._roomId=o,this._roomMode=n,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(o.L_PINGER_START_O,JSON.stringify({interval:this._gap,offlineKickTime:this._offlineKickTime})),this._started=!0,this._checkAlive())}_sendPing(e){return new Promise((i=>{this._context.rtcPing(this._roomId,this._roomMode).then(i).catch((r=>{var s,a;null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_PINGER_SEND_RTCPING_R,JSON.stringify({status:n.FAILED,msg:r}),e),i({code:t.ErrorCode.UNKNOWN})})),setTimeout(i,5e3,t.ErrorCode.TIMEOUT)}))}_diffPullRTCRoomStatus(e){var t,i,r,n;if(e>this._store.getRoomStatusVersion()){const s=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(o.L_RTCPING_PULL_ROOM_STATUS_O,JSON.stringify({pingerVersion:e}),s),this._pullRTCRoomStatus(this._roomId,s,e)}}_checkAlive(){var r,s,a,d,c,_,l,u,h,R,v;return i(this,void 0,void 0,(function*(){const i=null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s?void 0:s.createTraceId();null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_PINGER_SEND_RTCPING_T,JSON.stringify({roomId:this._roomId}),i);const{code:C,data:p}=yield this._sendPing(i),g=Date.now();return C===t.ErrorCode.SUCCESS?(this._diffPullRTCRoomStatus(p.version),null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_PINGER_SEND_RTCPING_R,JSON.stringify({roomId:this._roomId,status:n.SUCCESSED}),i),this._latestTimestamp=g,null===(l=this.onPingResult)||void 0===l||l.call(this,e.RCRTCPingResult.SUCCESS),void(this._timer=setTimeout((()=>this._checkAlive()),this._gap))):(null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_PINGER_SEND_RTCPING_R,JSON.stringify({roomId:this._roomId,status:n.FAILED,code:C}),i),null===(R=this.onPingResult)||void 0===R||R.call(this,e.RCRTCPingResult.FAIL),40003===C||g-this._latestTimestamp>this._offlineKickTime?(this.stop(),void(null===(v=this.onFailed)||void 0===v||v.call(this,40003===C))):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(o.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 ft(e){let t=e.length;for(;--t>=0;)e[t]=0}const Ot=256,Lt=286,Nt=30,At=15,yt=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]),kt=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]),Dt=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),bt=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ut=new Array(576);ft(Ut);const Pt=new Array(60);ft(Pt);const Mt=new Array(512);ft(Mt);const xt=new Array(256);ft(xt);const wt=new Array(29);ft(wt);const Bt=new Array(Nt);function Vt(e,t,i,r,o){this.static_tree=e,this.extra_bits=t,this.extra_base=i,this.elems=r,this.max_length=o,this.has_stree=e&&e.length}let Ft,Jt,Ht;function Gt(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}ft(Bt);const Kt=e=>e<256?Mt[e]:Mt[256+(e>>>7)],jt=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},$t=(e,t,i)=>{e.bi_valid>16-i?(e.bi_buf|=t<<e.bi_valid&65535,jt(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)},Wt=(e,t,i)=>{$t(e,i[2*t],i[2*t+1])},qt=(e,t)=>{let i=0;do{i|=1&e,e>>>=1,i<<=1}while(--t>0);return i>>>1},Yt=(e,t,i)=>{const r=new Array(16);let o,n,s=0;for(o=1;o<=At;o++)r[o]=s=s+i[o-1]<<1;for(n=0;n<=t;n++){let t=e[2*n+1];0!==t&&(e[2*n]=qt(r[t]++,t))}},zt=e=>{let t;for(t=0;t<Lt;t++)e.dyn_ltree[2*t]=0;for(t=0;t<Nt;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},Zt=e=>{e.bi_valid>8?jt(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},Qt=(e,t,i,r)=>{const o=2*t,n=2*i;return e[o]<e[n]||e[o]===e[n]&&r[t]<=r[i]},Xt=(e,t,i)=>{const r=e.heap[i];let o=i<<1;for(;o<=e.heap_len&&(o<e.heap_len&&Qt(t,e.heap[o+1],e.heap[o],e.depth)&&o++,!Qt(t,r,e.heap[o],e.depth));)e.heap[i]=e.heap[o],i=o,o<<=1;e.heap[i]=r},ei=(e,t,i)=>{let r,o,n,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],o=e.pending_buf[e.l_buf+a],a++,0===r?Wt(e,o,t):(n=xt[o],Wt(e,n+Ot+1,t),s=yt[n],0!==s&&(o-=wt[n],$t(e,o,s)),r--,n=Kt(r),Wt(e,n,i),s=kt[n],0!==s&&(r-=Bt[n],$t(e,r,s)))}while(a<e.last_lit);Wt(e,256,t)},ti=(e,t)=>{const i=t.dyn_tree,r=t.stat_desc.static_tree,o=t.stat_desc.has_stree,n=t.stat_desc.elems;let s,a,d,c=-1;for(e.heap_len=0,e.heap_max=573,s=0;s<n;s++)0!==i[2*s]?(e.heap[++e.heap_len]=c=s,e.depth[s]=0):i[2*s+1]=0;for(;e.heap_len<2;)d=e.heap[++e.heap_len]=c<2?++c:0,i[2*d]=1,e.depth[d]=0,e.opt_len--,o&&(e.static_len-=r[2*d+1]);for(t.max_code=c,s=e.heap_len>>1;s>=1;s--)Xt(e,i,s);d=n;do{s=e.heap[1],e.heap[1]=e.heap[e.heap_len--],Xt(e,i,1),a=e.heap[1],e.heap[--e.heap_max]=s,e.heap[--e.heap_max]=a,i[2*d]=i[2*s]+i[2*a],e.depth[d]=(e.depth[s]>=e.depth[a]?e.depth[s]:e.depth[a])+1,i[2*s+1]=i[2*a+1]=d,e.heap[1]=d++,Xt(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,o=t.stat_desc.static_tree,n=t.stat_desc.has_stree,s=t.stat_desc.extra_bits,a=t.stat_desc.extra_base,d=t.stat_desc.max_length;let c,_,l,u,h,R,v=0;for(u=0;u<=At;u++)e.bl_count[u]=0;for(i[2*e.heap[e.heap_max]+1]=0,c=e.heap_max+1;c<573;c++)_=e.heap[c],u=i[2*i[2*_+1]+1]+1,u>d&&(u=d,v++),i[2*_+1]=u,_>r||(e.bl_count[u]++,h=0,_>=a&&(h=s[_-a]),R=i[2*_],e.opt_len+=R*(u+h),n&&(e.static_len+=R*(o[2*_+1]+h)));if(0!==v){do{for(u=d-1;0===e.bl_count[u];)u--;e.bl_count[u]--,e.bl_count[u+1]+=2,e.bl_count[d]--,v-=2}while(v>0);for(u=d;0!==u;u--)for(_=e.bl_count[u];0!==_;)l=e.heap[--c],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),Yt(i,c,e.bl_count)},ii=(e,t,i)=>{let r,o,n=-1,s=t[1],a=0,d=7,c=4;for(0===s&&(d=138,c=3),t[2*(i+1)+1]=65535,r=0;r<=i;r++)o=s,s=t[2*(r+1)+1],++a<d&&o===s||(a<c?e.bl_tree[2*o]+=a:0!==o?(o!==n&&e.bl_tree[2*o]++,e.bl_tree[32]++):a<=10?e.bl_tree[34]++:e.bl_tree[36]++,a=0,n=o,0===s?(d=138,c=3):o===s?(d=6,c=3):(d=7,c=4))},ri=(e,t,i)=>{let r,o,n=-1,s=t[1],a=0,d=7,c=4;for(0===s&&(d=138,c=3),r=0;r<=i;r++)if(o=s,s=t[2*(r+1)+1],!(++a<d&&o===s)){if(a<c)do{Wt(e,o,e.bl_tree)}while(0!=--a);else 0!==o?(o!==n&&(Wt(e,o,e.bl_tree),a--),Wt(e,16,e.bl_tree),$t(e,a-3,2)):a<=10?(Wt(e,17,e.bl_tree),$t(e,a-3,3)):(Wt(e,18,e.bl_tree),$t(e,a-11,7));a=0,n=o,0===s?(d=138,c=3):o===s?(d=6,c=3):(d=7,c=4)}};let oi=!1;const ni=(e,t,i,r)=>{$t(e,0+(r?1:0),3),((e,t,i,r)=>{Zt(e),r&&(jt(e,i),jt(e,~i)),e.pending_buf.set(e.window.subarray(t,t+i),e.pending),e.pending+=i})(e,t,i,!0)};var si=(e,t,i,r)=>{let o,n,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<Ot;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0})(e)),ti(e,e.l_desc),ti(e,e.d_desc),s=(e=>{let t;for(ii(e,e.dyn_ltree,e.l_desc.max_code),ii(e,e.dyn_dtree,e.d_desc.max_code),ti(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*bt[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),o=e.opt_len+3+7>>>3,n=e.static_len+3+7>>>3,n<=o&&(o=n)):o=n=i+5,i+4<=o&&-1!==t?ni(e,t,i,r):4===e.strategy||n===o?($t(e,2+(r?1:0),3),ei(e,Ut,Pt)):($t(e,4+(r?1:0),3),((e,t,i,r)=>{let o;for($t(e,t-257,5),$t(e,i-1,5),$t(e,r-4,4),o=0;o<r;o++)$t(e,e.bl_tree[2*bt[o]+1],3);ri(e,e.dyn_ltree,t-1),ri(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)),zt(e),r&&Zt(e)},ai={_tr_init:e=>{oi||((()=>{let e,t,i,r,o;const n=new Array(16);for(i=0,r=0;r<28;r++)for(wt[r]=i,e=0;e<1<<yt[r];e++)xt[i++]=r;for(xt[i-1]=r,o=0,r=0;r<16;r++)for(Bt[r]=o,e=0;e<1<<kt[r];e++)Mt[o++]=r;for(o>>=7;r<Nt;r++)for(Bt[r]=o<<7,e=0;e<1<<kt[r]-7;e++)Mt[256+o++]=r;for(t=0;t<=At;t++)n[t]=0;for(e=0;e<=143;)Ut[2*e+1]=8,e++,n[8]++;for(;e<=255;)Ut[2*e+1]=9,e++,n[9]++;for(;e<=279;)Ut[2*e+1]=7,e++,n[7]++;for(;e<=287;)Ut[2*e+1]=8,e++,n[8]++;for(Yt(Ut,287,n),e=0;e<Nt;e++)Pt[2*e+1]=5,Pt[2*e]=qt(e,5);Ft=new Vt(Ut,yt,257,Lt,At),Jt=new Vt(Pt,kt,0,Nt,At),Ht=new Vt(new Array(0),Dt,0,19,7)})(),oi=!0),e.l_desc=new Gt(e.dyn_ltree,Ft),e.d_desc=new Gt(e.dyn_dtree,Jt),e.bl_desc=new Gt(e.bl_tree,Ht),e.bi_buf=0,e.bi_valid=0,zt(e)},_tr_stored_block:ni,_tr_flush_block:si,_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*(xt[i]+Ot+1)]++,e.dyn_dtree[2*Kt(t)]++),e.last_lit===e.lit_bufsize-1),_tr_align:e=>{$t(e,2,3),Wt(e,256,Ut),(e=>{16===e.bi_valid?(jt(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 di=(e,t,i,r)=>{let o=65535&e|0,n=e>>>16&65535|0,s=0;for(;0!==i;){s=i>2e3?2e3:i,i-=s;do{o=o+t[r++]|0,n=n+o|0}while(--s);o%=65521,n%=65521}return o|n<<16|0};const ci=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 _i=(e,t,i,r)=>{const o=ci,n=r+i;e^=-1;for(let i=r;i<n;i++)e=e>>>8^o[255&(e^t[i])];return-1^e},li={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"},ui={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:hi,_tr_stored_block:Ri,_tr_flush_block:vi,_tr_tally:Ci,_tr_align:pi}=ai,{Z_NO_FLUSH:gi,Z_PARTIAL_FLUSH:mi,Z_FULL_FLUSH:Ti,Z_FINISH:Ii,Z_BLOCK:Ei,Z_OK:Si,Z_STREAM_END:fi,Z_STREAM_ERROR:Oi,Z_DATA_ERROR:Li,Z_BUF_ERROR:Ni,Z_DEFAULT_COMPRESSION:Ai,Z_FILTERED:yi,Z_HUFFMAN_ONLY:ki,Z_RLE:Di,Z_FIXED:bi,Z_DEFAULT_STRATEGY:Ui,Z_UNKNOWN:Pi,Z_DEFLATED:Mi}=ui,xi=258,wi=262,Bi=103,Vi=113,Fi=666,Ji=(e,t)=>(e.msg=li[t],t),Hi=e=>(e<<1)-(e>4?9:0),Gi=e=>{let t=e.length;for(;--t>=0;)e[t]=0};let Ki=(e,t,i)=>(t<<e.hash_shift^i)&e.hash_mask;const ji=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))},$i=(e,t)=>{vi(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,ji(e.strm)},Wi=(e,t)=>{e.pending_buf[e.pending++]=t},qi=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},Yi=(e,t,i,r)=>{let o=e.avail_in;return o>r&&(o=r),0===o?0:(e.avail_in-=o,t.set(e.input.subarray(e.next_in,e.next_in+o),i),1===e.state.wrap?e.adler=di(e.adler,t,o,i):2===e.state.wrap&&(e.adler=_i(e.adler,t,o,i)),e.next_in+=o,e.total_in+=o,o)},zi=(e,t)=>{let i,r,o=e.max_chain_length,n=e.strstart,s=e.prev_length,a=e.nice_match;const d=e.strstart>e.w_size-wi?e.strstart-(e.w_size-wi):0,c=e.window,_=e.w_mask,l=e.prev,u=e.strstart+xi;let h=c[n+s-1],R=c[n+s];e.prev_length>=e.good_match&&(o>>=2),a>e.lookahead&&(a=e.lookahead);do{if(i=t,c[i+s]===R&&c[i+s-1]===h&&c[i]===c[n]&&c[++i]===c[n+1]){n+=2,i++;do{}while(c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&n<u);if(r=xi-(u-n),n=u-xi,r>s){if(e.match_start=t,s=r,r>=a)break;h=c[n+s-1],R=c[n+s]}}}while((t=l[t&_])>d&&0!=--o);return s<=e.lookahead?s:e.lookahead},Zi=e=>{const t=e.w_size;let i,r,o,n,s;do{if(n=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-wi)){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{o=e.head[--i],e.head[i]=o>=t?o-t:0}while(--r);r=t,i=r;do{o=e.prev[--i],e.prev[i]=o>=t?o-t:0}while(--r);n+=t}if(0===e.strm.avail_in)break;if(r=Yi(e.strm,e.window,e.strstart+e.lookahead,n),e.lookahead+=r,e.lookahead+e.insert>=3)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=Ki(e,e.ins_h,e.window[s+1]);e.insert&&(e.ins_h=Ki(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<wi&&0!==e.strm.avail_in)},Qi=(e,t)=>{let i,r;for(;;){if(e.lookahead<wi){if(Zi(e),e.lookahead<wi&&t===gi)return 1;if(0===e.lookahead)break}if(i=0,e.lookahead>=3&&(e.ins_h=Ki(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-wi&&(e.match_length=zi(e,i)),e.match_length>=3)if(r=Ci(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=Ki(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=Ki(e,e.ins_h,e.window[e.strstart+1]);else r=Ci(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(r&&($i(e,!1),0===e.strm.avail_out))return 1}return e.insert=e.strstart<2?e.strstart:2,t===Ii?($i(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&($i(e,!1),0===e.strm.avail_out)?1:2},Xi=(e,t)=>{let i,r,o;for(;;){if(e.lookahead<wi){if(Zi(e),e.lookahead<wi&&t===gi)return 1;if(0===e.lookahead)break}if(i=0,e.lookahead>=3&&(e.ins_h=Ki(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-wi&&(e.match_length=zi(e,i),e.match_length<=5&&(e.strategy===yi||3===e.match_length&&e.strstart-e.match_start>4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){o=e.strstart+e.lookahead-3,r=Ci(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do{++e.strstart<=o&&(e.ins_h=Ki(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&&($i(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if(r=Ci(e,0,e.window[e.strstart-1]),r&&$i(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=Ci(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===Ii?($i(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&($i(e,!1),0===e.strm.avail_out)?1:2};function er(e,t,i,r,o){this.good_length=e,this.max_lazy=t,this.nice_length=i,this.max_chain=r,this.func=o}const tr=[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(Zi(e),0===e.lookahead&&t===gi)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,$i(e,!1),0===e.strm.avail_out))return 1;if(e.strstart-e.block_start>=e.w_size-wi&&($i(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ii?($i(e,!0),0===e.strm.avail_out?3:4):(e.strstart>e.block_start&&($i(e,!1),e.strm.avail_out),1)})),new er(4,4,8,4,Qi),new er(4,5,16,8,Qi),new er(4,6,32,32,Qi),new er(4,4,16,16,Xi),new er(8,16,32,32,Xi),new er(8,16,128,128,Xi),new er(8,32,128,256,Xi),new er(32,128,258,1024,Xi),new er(32,258,258,4096,Xi)];function ir(){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=Mi,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),Gi(this.dyn_ltree),Gi(this.dyn_dtree),Gi(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),Gi(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),Gi(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 rr=e=>{if(!e||!e.state)return Ji(e,Oi);e.total_in=e.total_out=0,e.data_type=Pi;const t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?42:Vi,e.adler=2===t.wrap?0:1,t.last_flush=gi,hi(t),Si},or=e=>{const t=rr(e);var i;return t===Si&&((i=e.state).window_size=2*i.w_size,Gi(i.head),i.max_lazy_match=tr[i.level].max_lazy,i.good_match=tr[i.level].good_length,i.nice_match=tr[i.level].nice_length,i.max_chain_length=tr[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},nr=(e,t,i,r,o,n)=>{if(!e)return Oi;let s=1;if(t===Ai&&(t=6),r<0?(s=0,r=-r):r>15&&(s=2,r-=16),o<1||o>9||i!==Mi||r<8||r>15||t<0||t>9||n<0||n>bi)return Ji(e,Oi);8===r&&(r=9);const a=new ir;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=o+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<<o+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=n,a.method=i,or(e)};var sr={deflateInit:(e,t)=>nr(e,t,Mi,15,8,Ui),deflateInit2:nr,deflateReset:or,deflateResetKeep:rr,deflateSetHeader:(e,t)=>e&&e.state?2!==e.state.wrap?Oi:(e.state.gzhead=t,Si):Oi,deflate:(e,t)=>{let i,r;if(!e||!e.state||t>Ei||t<0)return e?Ji(e,Oi):Oi;const o=e.state;if(!e.output||!e.input&&0!==e.avail_in||o.status===Fi&&t!==Ii)return Ji(e,0===e.avail_out?Ni:Oi);o.strm=e;const n=o.last_flush;if(o.last_flush=t,42===o.status)if(2===o.wrap)e.adler=0,Wi(o,31),Wi(o,139),Wi(o,8),o.gzhead?(Wi(o,(o.gzhead.text?1:0)+(o.gzhead.hcrc?2:0)+(o.gzhead.extra?4:0)+(o.gzhead.name?8:0)+(o.gzhead.comment?16:0)),Wi(o,255&o.gzhead.time),Wi(o,o.gzhead.time>>8&255),Wi(o,o.gzhead.time>>16&255),Wi(o,o.gzhead.time>>24&255),Wi(o,9===o.level?2:o.strategy>=ki||o.level<2?4:0),Wi(o,255&o.gzhead.os),o.gzhead.extra&&o.gzhead.extra.length&&(Wi(o,255&o.gzhead.extra.length),Wi(o,o.gzhead.extra.length>>8&255)),o.gzhead.hcrc&&(e.adler=_i(e.adler,o.pending_buf,o.pending,0)),o.gzindex=0,o.status=69):(Wi(o,0),Wi(o,0),Wi(o,0),Wi(o,0),Wi(o,0),Wi(o,9===o.level?2:o.strategy>=ki||o.level<2?4:0),Wi(o,3),o.status=Vi);else{let t=Mi+(o.w_bits-8<<4)<<8,i=-1;i=o.strategy>=ki||o.level<2?0:o.level<6?1:6===o.level?2:3,t|=i<<6,0!==o.strstart&&(t|=32),t+=31-t%31,o.status=Vi,qi(o,t),0!==o.strstart&&(qi(o,e.adler>>>16),qi(o,65535&e.adler)),e.adler=1}if(69===o.status)if(o.gzhead.extra){for(i=o.pending;o.gzindex<(65535&o.gzhead.extra.length)&&(o.pending!==o.pending_buf_size||(o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),ji(e),i=o.pending,o.pending!==o.pending_buf_size));)Wi(o,255&o.gzhead.extra[o.gzindex]),o.gzindex++;o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),o.gzindex===o.gzhead.extra.length&&(o.gzindex=0,o.status=73)}else o.status=73;if(73===o.status)if(o.gzhead.name){i=o.pending;do{if(o.pending===o.pending_buf_size&&(o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),ji(e),i=o.pending,o.pending===o.pending_buf_size)){r=1;break}r=o.gzindex<o.gzhead.name.length?255&o.gzhead.name.charCodeAt(o.gzindex++):0,Wi(o,r)}while(0!==r);o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),0===r&&(o.gzindex=0,o.status=91)}else o.status=91;if(91===o.status)if(o.gzhead.comment){i=o.pending;do{if(o.pending===o.pending_buf_size&&(o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),ji(e),i=o.pending,o.pending===o.pending_buf_size)){r=1;break}r=o.gzindex<o.gzhead.comment.length?255&o.gzhead.comment.charCodeAt(o.gzindex++):0,Wi(o,r)}while(0!==r);o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),0===r&&(o.status=Bi)}else o.status=Bi;if(o.status===Bi&&(o.gzhead.hcrc?(o.pending+2>o.pending_buf_size&&ji(e),o.pending+2<=o.pending_buf_size&&(Wi(o,255&e.adler),Wi(o,e.adler>>8&255),e.adler=0,o.status=Vi)):o.status=Vi),0!==o.pending){if(ji(e),0===e.avail_out)return o.last_flush=-1,Si}else if(0===e.avail_in&&Hi(t)<=Hi(n)&&t!==Ii)return Ji(e,Ni);if(o.status===Fi&&0!==e.avail_in)return Ji(e,Ni);if(0!==e.avail_in||0!==o.lookahead||t!==gi&&o.status!==Fi){let i=o.strategy===ki?((e,t)=>{let i;for(;;){if(0===e.lookahead&&(Zi(e),0===e.lookahead)){if(t===gi)return 1;break}if(e.match_length=0,i=Ci(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,i&&($i(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ii?($i(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&($i(e,!1),0===e.strm.avail_out)?1:2})(o,t):o.strategy===Di?((e,t)=>{let i,r,o,n;const s=e.window;for(;;){if(e.lookahead<=xi){if(Zi(e),e.lookahead<=xi&&t===gi)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(o=e.strstart-1,r=s[o],r===s[++o]&&r===s[++o]&&r===s[++o])){n=e.strstart+xi;do{}while(r===s[++o]&&r===s[++o]&&r===s[++o]&&r===s[++o]&&r===s[++o]&&r===s[++o]&&r===s[++o]&&r===s[++o]&&o<n);e.match_length=xi-(n-o),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(i=Ci(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(i=Ci(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),i&&($i(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ii?($i(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&($i(e,!1),0===e.strm.avail_out)?1:2})(o,t):tr[o.level].func(o,t);if(3!==i&&4!==i||(o.status=Fi),1===i||3===i)return 0===e.avail_out&&(o.last_flush=-1),Si;if(2===i&&(t===mi?pi(o):t!==Ei&&(Ri(o,0,0,!1),t===Ti&&(Gi(o.head),0===o.lookahead&&(o.strstart=0,o.block_start=0,o.insert=0))),ji(e),0===e.avail_out))return o.last_flush=-1,Si}return t!==Ii?Si:o.wrap<=0?fi:(2===o.wrap?(Wi(o,255&e.adler),Wi(o,e.adler>>8&255),Wi(o,e.adler>>16&255),Wi(o,e.adler>>24&255),Wi(o,255&e.total_in),Wi(o,e.total_in>>8&255),Wi(o,e.total_in>>16&255),Wi(o,e.total_in>>24&255)):(qi(o,e.adler>>>16),qi(o,65535&e.adler)),ji(e),o.wrap>0&&(o.wrap=-o.wrap),0!==o.pending?Si:fi)},deflateEnd:e=>{if(!e||!e.state)return Oi;const t=e.state.status;return 42!==t&&69!==t&&73!==t&&91!==t&&t!==Bi&&t!==Vi&&t!==Fi?Ji(e,Oi):(e.state=null,t===Vi?Ji(e,Li):Si)},deflateSetDictionary:(e,t)=>{let i=t.length;if(!e||!e.state)return Oi;const r=e.state,o=r.wrap;if(2===o||1===o&&42!==r.status||r.lookahead)return Oi;if(1===o&&(e.adler=di(e.adler,t,i,0)),r.wrap=0,i>=r.w_size){0===o&&(Gi(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 n=e.avail_in,s=e.next_in,a=e.input;for(e.avail_in=i,e.next_in=0,e.input=t,Zi(r);r.lookahead>=3;){let e=r.strstart,t=r.lookahead-2;do{r.ins_h=Ki(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,Zi(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=n,r.wrap=o,Si},deflateInfo:"pako deflate (from Nodeca project)"};const ar=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var dr=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)ar(i,t)&&(e[t]=i[t])}}return e},cr=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,o=e.length;t<o;t++){let o=e[t];i.set(o,r),r+=o.length}return i};let _r=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(e){_r=!1}const lr=new Uint8Array(256);for(let e=0;e<256;e++)lr[e]=e>=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;lr[254]=lr[254]=1;var ur=e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);let t,i,r,o,n,s=e.length,a=0;for(o=0;o<s;o++)i=e.charCodeAt(o),55296==(64512&i)&&o+1<s&&(r=e.charCodeAt(o+1),56320==(64512&r)&&(i=65536+(i-55296<<10)+(r-56320),o++)),a+=i<128?1:i<2048?2:i<65536?3:4;for(t=new Uint8Array(a),n=0,o=0;n<a;o++)i=e.charCodeAt(o),55296==(64512&i)&&o+1<s&&(r=e.charCodeAt(o+1),56320==(64512&r)&&(i=65536+(i-55296<<10)+(r-56320),o++)),i<128?t[n++]=i:i<2048?(t[n++]=192|i>>>6,t[n++]=128|63&i):i<65536?(t[n++]=224|i>>>12,t[n++]=128|i>>>6&63,t[n++]=128|63&i):(t[n++]=240|i>>>18,t[n++]=128|i>>>12&63,t[n++]=128|i>>>6&63,t[n++]=128|63&i);return t},hr=(e,t)=>{const i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));let r,o;const n=new Array(2*i);for(o=0,r=0;r<i;){let t=e[r++];if(t<128){n[o++]=t;continue}let s=lr[t];if(s>4)n[o++]=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?n[o++]=65533:t<65536?n[o++]=t:(t-=65536,n[o++]=55296|t>>10&1023,n[o++]=56320|1023&t)}}return((e,t)=>{if(t<65534&&e.subarray&&_r)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})(n,o)},Rr=(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+lr[e[i]]>t?i:t};var vr=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 Cr=Object.prototype.toString,{Z_NO_FLUSH:pr,Z_SYNC_FLUSH:gr,Z_FULL_FLUSH:mr,Z_FINISH:Tr,Z_OK:Ir,Z_STREAM_END:Er,Z_DEFAULT_COMPRESSION:Sr,Z_DEFAULT_STRATEGY:fr,Z_DEFLATED:Or}=ui;function Lr(e){this.options=dr({level:Sr,method:Or,chunkSize:16384,windowBits:15,memLevel:8,strategy:fr},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 vr,this.strm.avail_out=0;let i=sr.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(i!==Ir)throw new Error(li[i]);if(t.header&&sr.deflateSetHeader(this.strm,t.header),t.dictionary){let e;if(e="string"==typeof t.dictionary?ur(t.dictionary):"[object ArrayBuffer]"===Cr.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,i=sr.deflateSetDictionary(this.strm,e),i!==Ir)throw new Error(li[i]);this._dict_set=!0}}function Nr(e,t){const i=new Lr(t);if(i.push(e,!0),i.err)throw i.msg||li[i.err];return i.result}Lr.prototype.push=function(e,t){const i=this.strm,r=this.options.chunkSize;let o,n;if(this.ended)return!1;for(n=t===~~t?t:!0===t?Tr:pr,"string"==typeof e?i.input=ur(e):"[object ArrayBuffer]"===Cr.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),(n===gr||n===mr)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(o=sr.deflate(i,n),o===Er)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),o=sr.deflateEnd(this.strm),this.onEnd(o),this.ended=!0,o===Ir;if(0!==i.avail_out){if(n>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},Lr.prototype.onData=function(e){this.chunks.push(e)},Lr.prototype.onEnd=function(e){e===Ir&&(this.result=cr(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var Ar={Deflate:Lr,deflate:Nr,deflateRaw:function(e,t){return(t=t||{}).raw=!0,Nr(e,t)},gzip:function(e,t){return(t=t||{}).gzip=!0,Nr(e,t)},constants:ui};var yr=function(e,t){let i,r,o,n,s,a,d,c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f,O;const L=e.state;i=e.next_in,f=e.input,r=i+(e.avail_in-5),o=e.next_out,O=e.output,n=o-(t-e.avail_out),s=o+(e.avail_out-257),a=L.dmax,d=L.wsize,c=L.whave,_=L.wnext,l=L.window,u=L.hold,h=L.bits,R=L.lencode,v=L.distcode,C=(1<<L.lenbits)-1,p=(1<<L.distbits)-1;e:do{h<15&&(u+=f[i++]<<h,h+=8,u+=f[i++]<<h,h+=8),g=R[u&C];t:for(;;){if(m=g>>>24,u>>>=m,h-=m,m=g>>>16&255,0===m)O[o++]=65535&g;else{if(!(16&m)){if(0==(64&m)){g=R[(65535&g)+(u&(1<<m)-1)];continue t}if(32&m){L.mode=12;break e}e.msg="invalid literal/length code",L.mode=30;break e}T=65535&g,m&=15,m&&(h<m&&(u+=f[i++]<<h,h+=8),T+=u&(1<<m)-1,u>>>=m,h-=m),h<15&&(u+=f[i++]<<h,h+=8,u+=f[i++]<<h,h+=8),g=v[u&p];i:for(;;){if(m=g>>>24,u>>>=m,h-=m,m=g>>>16&255,!(16&m)){if(0==(64&m)){g=v[(65535&g)+(u&(1<<m)-1)];continue i}e.msg="invalid distance code",L.mode=30;break e}if(I=65535&g,m&=15,h<m&&(u+=f[i++]<<h,h+=8,h<m&&(u+=f[i++]<<h,h+=8)),I+=u&(1<<m)-1,I>a){e.msg="invalid distance too far back",L.mode=30;break e}if(u>>>=m,h-=m,m=o-n,I>m){if(m=I-m,m>c&&L.sane){e.msg="invalid distance too far back",L.mode=30;break e}if(E=0,S=l,0===_){if(E+=d-m,m<T){T-=m;do{O[o++]=l[E++]}while(--m);E=o-I,S=O}}else if(_<m){if(E+=d+_-m,m-=_,m<T){T-=m;do{O[o++]=l[E++]}while(--m);if(E=0,_<T){m=_,T-=m;do{O[o++]=l[E++]}while(--m);E=o-I,S=O}}}else if(E+=_-m,m<T){T-=m;do{O[o++]=l[E++]}while(--m);E=o-I,S=O}for(;T>2;)O[o++]=S[E++],O[o++]=S[E++],O[o++]=S[E++],T-=3;T&&(O[o++]=S[E++],T>1&&(O[o++]=S[E++]))}else{E=o-I;do{O[o++]=O[E++],O[o++]=O[E++],O[o++]=O[E++],T-=3}while(T>2);T&&(O[o++]=O[E++],T>1&&(O[o++]=O[E++]))}break}}break}}while(i<r&&o<s);T=h>>3,i-=T,h-=T<<3,u&=(1<<h)-1,e.next_in=i,e.next_out=o,e.avail_in=i<r?r-i+5:5-(i-r),e.avail_out=o<s?s-o+257:257-(o-s),L.hold=u,L.bits=h};const kr=15,Dr=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]),br=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]),Ur=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]),Pr=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 Mr=(e,t,i,r,o,n,s,a)=>{const d=a.bits;let c,_,l,u,h,R,v=0,C=0,p=0,g=0,m=0,T=0,I=0,E=0,S=0,f=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<=kr;v++)N[v]=0;for(C=0;C<r;C++)N[t[i+C]]++;for(m=d,g=kr;g>=1&&0===N[g];g--);if(m>g&&(m=g),0===g)return o[n++]=20971520,o[n++]=20971520,a.bits=1,0;for(p=1;p<g&&0===N[p];p++);for(m<p&&(m=p),E=1,v=1;v<=kr;v++)if(E<<=1,E-=N[v],E<0)return-1;if(E>0&&(0===e||1!==g))return-1;for(A[1]=0,v=1;v<kr;v++)A[v+1]=A[v]+N[v];for(C=0;C<r;C++)0!==t[i+C]&&(s[A[t[i+C]]++]=C);if(0===e?(O=b=s,R=19):1===e?(O=Dr,L-=257,b=br,U-=257,R=256):(O=Ur,b=Pr,R=-1),f=0,C=0,v=p,h=n,T=m,I=0,l=-1,S=1<<m,u=S-1,1===e&&S>852||2===e&&S>592)return 1;for(;;){y=v-I,s[C]<R?(k=0,D=s[C]):s[C]>R?(k=b[U+s[C]],D=O[L+s[C]]):(k=96,D=0),c=1<<v-I,_=1<<T,p=_;do{_-=c,o[h+(f>>I)+_]=y<<24|k<<16|D|0}while(0!==_);for(c=1<<v-1;f&c;)c>>=1;if(0!==c?(f&=c-1,f+=c):f=0,C++,0==--N[v]){if(v===g)break;v=t[i+s[C]]}if(v>m&&(f&u)!==l){for(0===I&&(I=m),h+=p,T=v-I,E=1<<T;T+I<g&&(E-=N[T+I],!(E<=0));)T++,E<<=1;if(S+=1<<T,1===e&&S>852||2===e&&S>592)return 1;l=f&u,o[l]=m<<24|T<<16|h-n|0}}return 0!==f&&(o[h+f]=v-I<<24|64<<16|0),a.bits=m,0};const{Z_FINISH:xr,Z_BLOCK:wr,Z_TREES:Br,Z_OK:Vr,Z_STREAM_END:Fr,Z_NEED_DICT:Jr,Z_STREAM_ERROR:Hr,Z_DATA_ERROR:Gr,Z_MEM_ERROR:Kr,Z_BUF_ERROR:jr,Z_DEFLATED:$r}=ui,Wr=12,qr=30,Yr=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function zr(){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 Zr=e=>{if(!e||!e.state)return Hr;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,Vr},Qr=e=>{if(!e||!e.state)return Hr;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,Zr(e)},Xr=(e,t)=>{let i;if(!e||!e.state)return Hr;const r=e.state;return t<0?(i=0,t=-t):(i=1+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?Hr:(null!==r.window&&r.wbits!==t&&(r.window=null),r.wrap=i,r.wbits=t,Qr(e))},eo=(e,t)=>{if(!e)return Hr;const i=new zr;e.state=i,i.window=null;const r=Xr(e,t);return r!==Vr&&(e.state=null),r};let to,io,ro=!0;const oo=e=>{if(ro){to=new Int32Array(512),io=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(Mr(1,e.lens,0,288,to,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;Mr(2,e.lens,0,32,io,0,e.work,{bits:5}),ro=!1}e.lencode=to,e.lenbits=9,e.distcode=io,e.distbits=5},no=(e,t,i,r)=>{let o;const n=e.state;return null===n.window&&(n.wsize=1<<n.wbits,n.wnext=0,n.whave=0,n.window=new Uint8Array(n.wsize)),r>=n.wsize?(n.window.set(t.subarray(i-n.wsize,i),0),n.wnext=0,n.whave=n.wsize):(o=n.wsize-n.wnext,o>r&&(o=r),n.window.set(t.subarray(i-r,i-r+o),n.wnext),(r-=o)?(n.window.set(t.subarray(i-r,i),0),n.wnext=r,n.whave=n.wsize):(n.wnext+=o,n.wnext===n.wsize&&(n.wnext=0),n.whave<n.wsize&&(n.whave+=o))),0};var so={inflateReset:Qr,inflateReset2:Xr,inflateResetKeep:Zr,inflateInit:e=>eo(e,15),inflateInit2:eo,inflate:(e,t)=>{let i,r,o,n,s,a,d,c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f=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 Hr;i=e.state,i.mode===Wr&&(i.mode=13),s=e.next_out,o=e.output,d=e.avail_out,n=e.next_in,r=e.input,a=e.avail_in,c=i.hold,_=i.bits,l=a,u=d,S=Vr;e:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;_<16;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(2&i.wrap&&35615===c){i.check=0,O[0]=255&c,O[1]=c>>>8&255,i.check=_i(i.check,O,2,0),c=0,_=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&c)<<8)+(c>>8))%31){e.msg="incorrect header check",i.mode=qr;break}if((15&c)!==$r){e.msg="unknown compression method",i.mode=qr;break}if(c>>>=4,_-=4,E=8+(15&c),0===i.wbits)i.wbits=E;else if(E>i.wbits){e.msg="invalid window size",i.mode=qr;break}i.dmax=1<<i.wbits,e.adler=i.check=1,i.mode=512&c?10:Wr,c=0,_=0;break;case 2:for(;_<16;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(i.flags=c,(255&i.flags)!==$r){e.msg="unknown compression method",i.mode=qr;break}if(57344&i.flags){e.msg="unknown header flags set",i.mode=qr;break}i.head&&(i.head.text=c>>8&1),512&i.flags&&(O[0]=255&c,O[1]=c>>>8&255,i.check=_i(i.check,O,2,0)),c=0,_=0,i.mode=3;case 3:for(;_<32;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.head&&(i.head.time=c),512&i.flags&&(O[0]=255&c,O[1]=c>>>8&255,O[2]=c>>>16&255,O[3]=c>>>24&255,i.check=_i(i.check,O,4,0)),c=0,_=0,i.mode=4;case 4:for(;_<16;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.head&&(i.head.xflags=255&c,i.head.os=c>>8),512&i.flags&&(O[0]=255&c,O[1]=c>>>8&255,i.check=_i(i.check,O,2,0)),c=0,_=0,i.mode=5;case 5:if(1024&i.flags){for(;_<16;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.length=c,i.head&&(i.head.extra_len=c),512&i.flags&&(O[0]=255&c,O[1]=c>>>8&255,i.check=_i(i.check,O,2,0)),c=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&&(E=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(r.subarray(n,n+h),E)),512&i.flags&&(i.check=_i(i.check,r,h,n)),a-=h,n+=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{E=r[n+h++],i.head&&E&&i.length<65536&&(i.head.name+=String.fromCharCode(E))}while(E&&h<a);if(512&i.flags&&(i.check=_i(i.check,r,h,n)),a-=h,n+=h,E)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{E=r[n+h++],i.head&&E&&i.length<65536&&(i.head.comment+=String.fromCharCode(E))}while(E&&h<a);if(512&i.flags&&(i.check=_i(i.check,r,h,n)),a-=h,n+=h,E)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--,c+=r[n++]<<_,_+=8}if(c!==(65535&i.check)){e.msg="header crc mismatch",i.mode=qr;break}c=0,_=0}i.head&&(i.head.hcrc=i.flags>>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=Wr;break;case 10:for(;_<32;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}e.adler=i.check=Yr(c),c=0,_=0,i.mode=11;case 11:if(0===i.havedict)return e.next_out=s,e.avail_out=d,e.next_in=n,e.avail_in=a,i.hold=c,i.bits=_,Jr;e.adler=i.check=1,i.mode=Wr;case Wr:if(t===wr||t===Br)break e;case 13:if(i.last){c>>>=7&_,_-=7&_,i.mode=27;break}for(;_<3;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}switch(i.last=1&c,c>>>=1,_-=1,3&c){case 0:i.mode=14;break;case 1:if(oo(i),i.mode=20,t===Br){c>>>=2,_-=2;break e}break;case 2:i.mode=17;break;case 3:e.msg="invalid block type",i.mode=qr}c>>>=2,_-=2;break;case 14:for(c>>>=7&_,_-=7&_;_<32;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if((65535&c)!=(c>>>16^65535)){e.msg="invalid stored block lengths",i.mode=qr;break}if(i.length=65535&c,c=0,_=0,i.mode=15,t===Br)break e;case 15:i.mode=16;case 16:if(h=i.length,h){if(h>a&&(h=a),h>d&&(h=d),0===h)break e;o.set(r.subarray(n,n+h),s),a-=h,n+=h,d-=h,s+=h,i.length-=h;break}i.mode=Wr;break;case 17:for(;_<14;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(i.nlen=257+(31&c),c>>>=5,_-=5,i.ndist=1+(31&c),c>>>=5,_-=5,i.ncode=4+(15&c),c>>>=4,_-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=qr;break}i.have=0,i.mode=18;case 18:for(;i.have<i.ncode;){for(;_<3;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.lens[A[i.have++]]=7&c,c>>>=3,_-=3}for(;i.have<19;)i.lens[A[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,L={bits:i.lenbits},S=Mr(0,i.lens,0,19,i.lencode,0,i.work,L),i.lenbits=L.bits,S){e.msg="invalid code lengths set",i.mode=qr;break}i.have=0,i.mode=19;case 19:for(;i.have<i.nlen+i.ndist;){for(;f=i.lencode[c&(1<<i.lenbits)-1],C=f>>>24,p=f>>>16&255,g=65535&f,!(C<=_);){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(g<16)c>>>=C,_-=C,i.lens[i.have++]=g;else{if(16===g){for(N=C+2;_<N;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(c>>>=C,_-=C,0===i.have){e.msg="invalid bit length repeat",i.mode=qr;break}E=i.lens[i.have-1],h=3+(3&c),c>>>=2,_-=2}else if(17===g){for(N=C+3;_<N;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}c>>>=C,_-=C,E=0,h=3+(7&c),c>>>=3,_-=3}else{for(N=C+7;_<N;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}c>>>=C,_-=C,E=0,h=11+(127&c),c>>>=7,_-=7}if(i.have+h>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=qr;break}for(;h--;)i.lens[i.have++]=E}}if(i.mode===qr)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=qr;break}if(i.lenbits=9,L={bits:i.lenbits},S=Mr(1,i.lens,0,i.nlen,i.lencode,0,i.work,L),i.lenbits=L.bits,S){e.msg="invalid literal/lengths set",i.mode=qr;break}if(i.distbits=6,i.distcode=i.distdyn,L={bits:i.distbits},S=Mr(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,L),i.distbits=L.bits,S){e.msg="invalid distances set",i.mode=qr;break}if(i.mode=20,t===Br)break e;case 20:i.mode=21;case 21:if(a>=6&&d>=258){e.next_out=s,e.avail_out=d,e.next_in=n,e.avail_in=a,i.hold=c,i.bits=_,yr(e,u),s=e.next_out,o=e.output,d=e.avail_out,n=e.next_in,r=e.input,a=e.avail_in,c=i.hold,_=i.bits,i.mode===Wr&&(i.back=-1);break}for(i.back=0;f=i.lencode[c&(1<<i.lenbits)-1],C=f>>>24,p=f>>>16&255,g=65535&f,!(C<=_);){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(p&&0==(240&p)){for(m=C,T=p,I=g;f=i.lencode[I+((c&(1<<m+T)-1)>>m)],C=f>>>24,p=f>>>16&255,g=65535&f,!(m+C<=_);){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}c>>>=m,_-=m,i.back+=m}if(c>>>=C,_-=C,i.back+=C,i.length=g,0===p){i.mode=26;break}if(32&p){i.back=-1,i.mode=Wr;break}if(64&p){e.msg="invalid literal/length code",i.mode=qr;break}i.extra=15&p,i.mode=22;case 22:if(i.extra){for(N=i.extra;_<N;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.length+=c&(1<<i.extra)-1,c>>>=i.extra,_-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;f=i.distcode[c&(1<<i.distbits)-1],C=f>>>24,p=f>>>16&255,g=65535&f,!(C<=_);){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(0==(240&p)){for(m=C,T=p,I=g;f=i.distcode[I+((c&(1<<m+T)-1)>>m)],C=f>>>24,p=f>>>16&255,g=65535&f,!(m+C<=_);){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}c>>>=m,_-=m,i.back+=m}if(c>>>=C,_-=C,i.back+=C,64&p){e.msg="invalid distance code",i.mode=qr;break}i.offset=g,i.extra=15&p,i.mode=24;case 24:if(i.extra){for(N=i.extra;_<N;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.offset+=c&(1<<i.extra)-1,c>>>=i.extra,_-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=qr;break}i.mode=25;case 25:if(0===d)break e;if(h=u-d,i.offset>h){if(h=i.offset-h,h>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=qr;break}h>i.wnext?(h-=i.wnext,R=i.wsize-h):R=i.wnext-h,h>i.length&&(h=i.length),v=i.window}else v=o,R=s-i.offset,h=i.length;h>d&&(h=d),d-=h,i.length-=h;do{o[s++]=v[R++]}while(--h);0===i.length&&(i.mode=21);break;case 26:if(0===d)break e;o[s++]=i.length,d--,i.mode=21;break;case 27:if(i.wrap){for(;_<32;){if(0===a)break e;a--,c|=r[n++]<<_,_+=8}if(u-=d,e.total_out+=u,i.total+=u,u&&(e.adler=i.check=i.flags?_i(i.check,o,u,s-u):di(i.check,o,u,s-u)),u=d,(i.flags?c:Yr(c))!==i.check){e.msg="incorrect data check",i.mode=qr;break}c=0,_=0}i.mode=28;case 28:if(i.wrap&&i.flags){for(;_<32;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(c!==(4294967295&i.total)){e.msg="incorrect length check",i.mode=qr;break}c=0,_=0}i.mode=29;case 29:S=Fr;break e;case qr:S=Gr;break e;case 31:return Kr;default:return Hr}return e.next_out=s,e.avail_out=d,e.next_in=n,e.avail_in=a,i.hold=c,i.bits=_,(i.wsize||u!==e.avail_out&&i.mode<qr&&(i.mode<27||t!==xr))&&no(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?_i(i.check,o,u,e.next_out-u):di(i.check,o,u,e.next_out-u)),e.data_type=i.bits+(i.last?64:0)+(i.mode===Wr?128:0)+(20===i.mode||15===i.mode?256:0),(0===l&&0===u||t===xr)&&S===Vr&&(S=jr),S},inflateEnd:e=>{if(!e||!e.state)return Hr;let t=e.state;return t.window&&(t.window=null),e.state=null,Vr},inflateGetHeader:(e,t)=>{if(!e||!e.state)return Hr;const i=e.state;return 0==(2&i.wrap)?Hr:(i.head=t,t.done=!1,Vr)},inflateSetDictionary:(e,t)=>{const i=t.length;let r,o,n;return e&&e.state?(r=e.state,0!==r.wrap&&11!==r.mode?Hr:11===r.mode&&(o=1,o=di(o,t,i,0),o!==r.check)?Gr:(n=no(e,t,i,i),n?(r.mode=31,Kr):(r.havedict=1,Vr))):Hr},inflateInfo:"pako inflate (from Nodeca project)"};var ao=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 co=Object.prototype.toString,{Z_NO_FLUSH:_o,Z_FINISH:lo,Z_OK:uo,Z_STREAM_END:ho,Z_NEED_DICT:Ro,Z_STREAM_ERROR:vo,Z_DATA_ERROR:Co,Z_MEM_ERROR:po}=ui;function go(e){this.options=dr({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 vr,this.strm.avail_out=0;let i=so.inflateInit2(this.strm,t.windowBits);if(i!==uo)throw new Error(li[i]);if(this.header=new ao,so.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=ur(t.dictionary):"[object ArrayBuffer]"===co.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=so.inflateSetDictionary(this.strm,t.dictionary),i!==uo)))throw new Error(li[i])}go.prototype.push=function(e,t){const i=this.strm,r=this.options.chunkSize,o=this.options.dictionary;let n,s,a;if(this.ended)return!1;for(s=t===~~t?t:!0===t?lo:_o,"[object ArrayBuffer]"===co.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),n=so.inflate(i,s),n===Ro&&o&&(n=so.inflateSetDictionary(i,o),n===uo?n=so.inflate(i,s):n===Co&&(n=Ro));i.avail_in>0&&n===ho&&i.state.wrap>0&&0!==e[i.next_in];)so.inflateReset(i),n=so.inflate(i,s);switch(n){case vo:case Co:case Ro:case po:return this.onEnd(n),this.ended=!0,!1}if(a=i.avail_out,i.next_out&&(0===i.avail_out||n===ho))if("string"===this.options.to){let e=Rr(i.output,i.next_out),t=i.next_out-e,o=hr(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(o)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(n!==uo||0!==a){if(n===ho)return n=so.inflateEnd(this.strm),this.onEnd(n),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},go.prototype.onData=function(e){this.chunks.push(e)},go.prototype.onEnd=function(e){e===uo&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=cr(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};const{Deflate:mo,deflate:To,deflateRaw:Io,gzip:Eo}=Ar;var So=Eo;const fo=-1,Oo=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})),Lo=(e,r,o)=>i(void 0,void 0,void 0,(function*(){const n=[];return yield Promise.any(e.map((e=>i(void 0,void 0,void 0,(function*(){const i=`${e.detectorAddr.replace(/^(https?:\/\/)?/,"https://")}/rtc/detector/ping?t=${s=1e3,a=9999,s+Math.floor(Math.random()*(a-s))}`;var s,a;const d={jwt:o};if(200!==(yield r.httpReq({url:i,body:JSON.stringify(d),timeout:5e3,method:t.HttpMethod.POST})).status)return Promise.reject();n.push(e.clusterId)}))))),n})),No=e=>{if(!e)return"";return e.jwt||""},Ao=(e,r)=>i(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=Le.getLogger();return null==i||i.warn(o.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:""})(r),n=No(r);let s=null,a=120,d=0;const c={jwt:n};if(i&&n){const r=yield e.httpReq({url:`${i}/rtc/detector/servers`,body:JSON.stringify(c),headers:{"Content-Type":"application/json;charset=UTF-8","Cache-Control":"no-cache",ClientType:`web|${ut.browser}|${ut.version}`,ClientVersion:"5.6.6","Client-Session-Id":Oo(),"Request-Id":Date.now().toString()},method:t.HttpMethod.POST}),o=r.data&&JSON.parse(r.data).detectorAddrs;a=r.data&&JSON.parse(r.data).clientDetectMinute,d=r.data&&JSON.parse(r.data).resultCode,o&&t.isArray(o)&&(s=yield Lo(o,e,n))}return{fastMediaUrl:s,clientDetectMinute:a,status:d}}));var yo;e.RCKickReason=void 0,(yo=e.RCKickReason||(e.RCKickReason={}))[yo.SERVER_KICK=1]="SERVER_KICK",yo[yo.OTHER_KICK=2]="OTHER_KICK";const ko={[String(e.RCKickReason.SERVER_KICK)]:1,[String(e.RCKickReason.OTHER_KICK)]:5};class Do{constructor(){}static getMemo(){return this._memo||(this._memo={}),window.__memo__=this._memo,this._memo}static destroy(){this._memo={}}}var bo;Do._memo={},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"}(bo||(bo={}));const Uo=(e,t,i)=>{var r;const o=Do.getMemo(),n={dur:0,cod:0,rid:e,csnid:t||(null===(r=o.clientData)||void 0===r?void 0:r.clientSessionId)||"",snid:i,rsid:"",msa:"",msas:[],time:0,resid:"",mtp:0,smct:1,cr:"unknown",net:"unknown",uid:"",stp:0};o.qualitySubscribeReportData=n,o.subscribeData={start:Date.now()}},Po=(e,t,i)=>{var r;const o=Do.getMemo(),n={dur:0,cod:0,rid:e,csnid:t||(null===(r=o.clientData)||void 0===r?void 0:r.clientSessionId)||"",snid:i,rsid:"",msa:"",msas:[],time:0,resid:"",mtp:0,smct:1,uid:"",stp:0};o.qualityUnsubscribeReportData=n,o.unsubscribeData={start:Date.now()}},Mo=e=>{const t=Do.getMemo();t.mediaService||(t.mediaService=[]),t.mediaService.push(e)},xo=()=>{Do.getMemo().mediaService=[]},wo=(e,t)=>{var i;const r=Do.getMemo();let n=[],s=Date.now();null===(i=r.mediaService)||void 0===i||i.forEach((e=>{n.push({rsid:e.reqId,rsdur:e.end-e.start,msa:e.url,rscod:e.status})})),r.subscribeCommand&&(r.subscribeCommand=!1,e.forEach((e=>{var i,a;const d=JSON.stringify(Object.assign(Object.assign({},r.qualitySubscribeReportData),{dur:s-((null===(i=r.subscribeData)||void 0===i?void 0:i.start)||0),cod:t,msas:n,time:s,resid:e.track.getTrackId(),mtp:rt(e.track.getTrackId()).mediaType,smct:e.track instanceof Be&&(null===(a=e.track)||void 0===a?void 0:a.__isTiny())?2:1}));Ne.__statistics(o.L_QS_SUBSCRIBE_S,d)}))),r.unsubscribeCommand&&(r.unsubscribeCommand=!1,e.forEach((e=>{var i,a;const d=JSON.stringify(Object.assign(Object.assign({},r.qualityUnsubscribeReportData),{dur:s-((null===(i=r.unsubscribeData)||void 0===i?void 0:i.start)||0),cod:t,time:s,msas:n,resid:e.track.getTrackId(),mtp:rt(e.track.getTrackId()).mediaType,smct:e.track instanceof Be&&(null===(a=e.track)||void 0===a?void 0:a.__isTiny())?2:1}));Ne.__statistics(o.L_QS_UNSUBSCRIBE_S,d)}))),xo()},Bo=e=>{var t,i,r,o,n;const s=Do.getMemo(),a=e.subscribe||(null===(t=s.iceStatusData)||void 0===t?void 0:t.subscribe),d=e.publish||(null===(i=s.iceStatusData)||void 0===i?void 0:i.publish),c=e.publishNotReport||(null===(r=s.iceStatusData)||void 0===r?void 0:r.publishNotReport),_=e.subscribeNotReport||(null===(o=s.iceStatusData)||void 0===o?void 0:o.subscribeNotReport),l=e.notFirst||(null===(n=s.iceStatusData)||void 0===n?void 0:n.notFirst);s.iceStatusData={publish:d,subscribe:a,publishNotReport:c,subscribeNotReport:_,notFirst:l},s.iceNewStatusData&&(s.iceOldStatusData=s.iceNewStatusData),e.iceNewStatusData&&(s.iceNewStatusData=e.iceNewStatusData)},Vo=(e,t,i,r)=>{var n,s;const a=Do.getMemo(),d=Date.now(),c=JSON.stringify(Object.assign(Object.assign({},a.qualityJoinRoomReportData),{dur:d-((null===(n=a.joinRoomData)||void 0===n?void 0:n.start)||0),cod:t,rid:e,csnid:null===(s=a.clientData)||void 0===s?void 0:s.clientSessionId,snid:i,time:d,uid:r}));Ne.__statistics(o.L_QS_JOIN_ROOM_S,c)},Fo=e=>{const t={dur:0,cod:0,rid:"",rtp:e,csnid:"",snid:"",time:0,cr:"unknown",net:"unknown",uid:""};Do.getMemo().qualityJoinRoomReportData=t},Jo=e=>{var t;const i=Do.getMemo(),r=(null===(t=i.joinRoomData)||void 0===t?void 0:t.start)||Date.now();i.joinRoomData={start:r,roomId:e}},Ho=(e,t)=>{var i;const r=Do.getMemo(),n=Date.now();let s=[];null===(i=r.mediaService)||void 0===i||i.forEach((e=>{s.push({rsid:e.reqId,rsdur:e.end-e.start,msa:e.url,rscod:e.status})})),e.forEach((e=>{var i;const a=JSON.stringify(Object.assign(Object.assign({},r.qualityPublishReportData),{dur:n-((null===(i=r.publish)||void 0===i?void 0:i.start)||0),cod:t,msas:s,time:n,resid:e.getTrackId(),mtp:rt(e.getTrackId()).mediaType,smct:e instanceof Be&&e.__isTiny()?2:1}));Ne.__statistics(o.L_QS_PUBLISH_S,a)})),xo()},Go=(e,t)=>{var i,r;const n=Do.getMemo(),s=Date.now();let a=[];null===(i=n.mediaService)||void 0===i||i.forEach((e=>{a.push({rsid:e.reqId,rsdur:e.end-e.start,msa:e.url,rscod:e.status})}));const d=[];d.push({dur:Date.now()-((null===(r=n.publishSignalTotal)||void 0===r?void 0:r.start)||0),cod:t}),e.forEach((e=>{var i;const r=JSON.stringify(Object.assign(Object.assign({},n.qualityPublishReportData),{dur:s-((null===(i=n.publish)||void 0===i?void 0:i.start)||0),cod:t,msas:a,sigs:d,time:s,resid:it(e),mtp:e.mediaType,smct:e.simulcast}));Ne.__statistics(o.L_QS_PUBLISH_S,r)})),xo()},Ko=(e,t)=>{var i,r;const n=Do.getMemo(),s=Date.now();let a=[];null===(i=n.mediaService)||void 0===i||i.forEach((e=>{a.push({rsid:e.reqId,rsdur:e.end-e.start,msa:e.url,rscod:e.status})}));const d=[];d.push({dur:Date.now()-((null===(r=n.unpublishSignalTotal)||void 0===r?void 0:r.start)||0),cod:t}),e.forEach((e=>{var i;const r=e.getTrackId(),c=JSON.stringify(Object.assign(Object.assign({},n.qualityUnpublishReportData),{dur:s-((null===(i=n.unpublish)||void 0===i?void 0:i.start)||0),cod:t,msas:a,sigs:d,time:s,resid:r,mtp:rt(r).mediaType,smct:e instanceof Be&&e.__isTiny()?2:1}));Ne.__statistics(o.L_QS_UNPUBLISH_S,c)})),xo()},jo=(e,t)=>{var i,r;const n=Do.getMemo(),s=Date.now();let a=[];null===(i=n.mediaService)||void 0===i||i.forEach((e=>{a.push({rsid:e.reqId,rsdur:e.end-e.start,msa:e.url,rscod:e.status})}));const d=[];d.push({dur:Date.now()-((null===(r=n.unpublishSignalTotal)||void 0===r?void 0:r.start)||0),cod:t}),e.forEach((e=>{var i;if(e){const r=JSON.stringify(Object.assign(Object.assign({},n.qualityUnpublishReportData),{dur:s-((null===(i=n.publish)||void 0===i?void 0:i.start)||0),cod:t,msas:a,sigs:d,time:s,resid:it(e),mtp:e.mediaType,smct:e.simulcast}));Ne.__statistics(o.L_QS_UNPUBLISH_S,r)}})),xo()},$o=()=>{var e,t,i,r;const n=Do.getMemo(),s=JSON.stringify(Object.assign(Object.assign({},n.qualityIceStatusReportData),{dur:((null===(e=n.iceNewStatusData)||void 0===e?void 0:e.start)||0)-((null===(t=n.iceOldStatusData)||void 0===t?void 0:t.start)||0),pices:bo[(null===(i=n.iceOldStatusData)||void 0===i?void 0:i.status)||0],ices:bo[(null===(r=n.iceNewStatusData)||void 0===r?void 0:r.status)||0],time:Date.now(),cncdts:[]}));Ne.__statistics(o.L_QS_ICE_STATUS_S,s)},Wo=e=>{Do.getMemo().subscribeCommand=e},qo=e=>{Do.getMemo().unsubscribeCommand=e},Yo=()=>({"Content-Type":"application/json;charset=UTF-8","Cache-Control":"no-cache",ClientType:`web|${ut.browser}|${ut.version}`,ClientVersion:"5.6.6","Client-Session-Id":Oo(),"Request-Id":Date.now().toString()});class zo{constructor(e,i,r,o=5e3){this._runtime=e,this._context=i,this._msUrl=r,this._timeout=o,this._msInNavi=[],this._failedMs=[],this._rtcFinger=void 0,this._clusterId="",this._configUrl="",this._msList=[],zo.isDetector||i.getConnectionStatus()!==t.ConnectionStatus.CONNECTED||this.detectorMediaSever()}detectorMediaSever(){const e=this._context.getNaviInfo();if(zo.jwtToken=(null==e?void 0:e.jwt)||"",this._msUrl)return;const i=Date.now(),r=zo.detectValidMinute+zo.detectorTime>i;zo.isDetector=r,!r&&e&&t.notEmptyObject(e)&&(this._msList=[],this._getDetectorUrls(e))}_getDetectorUrls(t){return i(this,void 0,void 0,(function*(){if(zo.isDetector)return;zo.isDetector=!0;const{fastMediaUrl:i,clientDetectMinute:r,status:o}=yield Ao(this._runtime,t);if(o===e.RCRTCCode.JWT_TIME_OUT){const e=this._context.getPluginContext();yield e.refetchNaviInfo(),this.detectorMediaSever()}zo.msInDetector=i||[],zo.detectorTime=Date.now(),zo.detectValidMinute=60*r*1e3}))}getNaviMS(){return this._msUrl?[this._msUrl]:(t.notEmptyArray(this._msList)&&!this._clusterId||(this._msList=this.setMediaServiceList()),this._msList)}setMediaServiceList(){var e,i;let r=[],n=[];return this._clusterId&&(this._clusterId=this._clusterId.replace(/^(https?:\/\/)?/,"https://"),this._msList.push(this._clusterId)),t.notEmptyArray(zo.msInDetector)&&(zo.msInDetector=zo.msInDetector.map((e=>e.replace(/^(https?:\/\/)?/,"https://"))),this._msList.push(zo.msInDetector[0]),r=zo.msInDetector.concat().splice(1,zo.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=Le.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 o=r[0],n=[];return o.mediaServer&&n.push(o.mediaServer.replace(/^(https?:\/\/)?/,"https://")),o.backupMediaServer&&o.backupMediaServer.forEach((e=>{n.push(e.replace(/^(https?:\/\/)?/,"https://"))})),n})(this._context.getNaviInfo())):(this._msInNavi.push(...this._failedMs),this._failedMs.length=0)),n=this._msInNavi.concat().splice(1,this._msInNavi.length-1),this._msList.push(this._msInNavi[0]),this._msList=[...this._msList,...r,...n],this._msList=[...new Set(this._msList)],null===(i=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===i||i.info(o.L_MEDIA_SERVICE_MSLIST_CHANGE_O,`MediaServiceList msList -> ${JSON.stringify(this._msList)}`),this._msList}_request(r,s,a,d,c){var _,l,u,h,R,v,C,p,g;return i(this,void 0,void 0,(function*(){if((null===(_=this._context.getNaviInfo())||void 0===_?void 0:_.openGzip)||!1){const e=JSON.stringify(a),t=e.length,r=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=e.charCodeAt(i);const o={"Content-Encoding":"gzip","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"};s=Object.assign(Object.assign({},s),o),a=So(r,i)}var i;const m=this.getNaviMS();if(0===m.length)return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"have no valid service address"}),d),{code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER};this._rtcFinger&&(a.rtcFinger=this._rtcFinger);for(let i=0;i<m.length;i+=1){const _=Date.now(),l=`${m[i]}${r}`,u=Yo(),T=Object.assign(Object.assign({},u),s),I=/x-www-form-urlencoded/.test(T["Content-Type"])?a:JSON.stringify(a),E=u["Request-Id"];null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_MEDIA_SERVICE_REQUEST_T,JSON.stringify({url:l,"Request-Id":E}),d);const{status:S,data:f}=yield this._runtime.httpReq({url:l,body:I,headers:T,method:t.HttpMethod.POST,timeout:this._timeout});if(c&&Mo({start:_,end:Date.now(),reqId:E,status:S,url:l}),200===S){const t=JSON.parse(f);return t.rtcFinger&&(this._rtcFinger=t.rtcFinger),t.clusterId&&(this._clusterId=t.clusterId),null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.info(o.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:n.SUCCESSED,url:l}),d),{code:e.RCRTCCode.SUCCESS,data:t}}this._failedMs.push(...this._msInNavi.splice(i,1)),null===(g=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===g||g.error(o.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:n.FAILED,msg:`request error -> Request-Id: ${E}, status: ${S}, url: ${l}`,timeout:this._timeout}),d)}return{code:e.RCRTCCode.REQUEST_FAILED}}))}exchange(t,r,o,n){var s;return i(this,void 0,void 0,(function*(){const i=yield this._request("/exchange",t,r,o,n);if(i.code===e.RCRTCCode.SUCCESS&&(null===(s=i.data)||void 0===s?void 0:s.resultCode)===e.RCRTCCode.SUCCESS){const{urls:e}=i.data;e&&(this._configUrl=e.configUrl)}return i}))}exit(e){var t,r;return i(this,void 0,void 0,(function*(){const i=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId(),{code:o}=yield this._request("/exit",e,{},i);return o}))}broadcastSubscribe(e,t){var i,r;const o=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,o)}broadcastExit(e){var t,r;return i(this,void 0,void 0,(function*(){const i=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId(),{code:o}=yield this._request("/broadcast/exit",e,{},i);return{code:o}}))}setMcuConfig(r,s){var a,d,c,_,l,u,h,R,v,C;return i(this,void 0,void 0,(function*(){const i=null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d?void 0:d.createTraceId();if(null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_MEDIA_SERVICE_SET_MCU_CONFIG_T,JSON.stringify({body:s}),i),!this._configUrl)return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.MCU_SERVER_NOT_FOUND,msg:"MCU server not found"}),i),{code:e.RCRTCCode.MCU_SERVER_NOT_FOUND};const p=`${this._configUrl.replace(/^(https?:\/\/)?/,"https://")}/server/mcu/config`,g=Yo(),m=Object.assign(Object.assign({},g),r),T=JSON.stringify(s),I=g["Request-Id"],{status:E,data:S}=yield this._runtime.httpReq({url:p,headers:m,body:T,method:t.HttpMethod.POST});if(200===E){const e=JSON.parse(S);return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:n.SUCCESSED,"Request-Id":I}),i),{code:e.resultCode,res:e}}return null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.error(o.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REQUEST_FAILED,msg:`request error -> Request-Id: ${I}, status: ${E}, url: ${p}`}),i),{code:e.RCRTCCode.REQUEST_FAILED}}))}getCDNResourceInfo(r,s,a){var d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const i=Yo(),R=Object.assign(Object.assign({},i),r),v=i["Request-Id"];null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_T,`Request-Id: ${v}, url: ${s}`,a);const{status:C,data:p}=yield this._runtime.httpReq({url:s,headers:R,method:t.HttpMethod.GET});if(200===C){const e=JSON.parse(p);return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_R,JSON.stringify({status:n.SUCCESSED,cdnPlayerUrl:null==e?void 0:e.data.pull_url}),a),{code:e.resultCode,res:e}}return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REQUEST_FAILED}),a),{code:e.RCRTCCode.REQUEST_FAILED}}))}}var Zo;zo.isDetector=!1,zo.msInDetector=[],zo.detectorTime=0,zo.detectValidMinute=72e5,zo.jwtToken="",function(e){e[e.NORMAL=1]="NORMAL",e[e.TINY=2]="TINY"}(Zo||(Zo={}));const Qo=(e,t)=>Math.round(8*t/e),Xo=(e,t=2)=>{const i=10**t;return Math.round(e*i)/i},en=(e,t=2)=>{e>1&&(e=1);const i=10**t;return Math.round(e*i)},tn=(e,t,i,r)=>{if(0===t)return 0;if(!i||!r)return Xo(e/t,3);const o=t-r;if(0===o)return 0;const n=e-i;return n<0||o<0?0:Xo(n/o,3)},rn=e=>{const{jitter:t,rtt:i,packetsLostRate:r}=e;return!vt(t)||!vt(i)||0!==r};class on{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 nn,sn,an,dn,cn,_n,ln,un,hn,Rn,vn,Cn,pn,gn,mn,Tn,In,En;on._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"}(nn||(nn={}));class Sn{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=Le.getLogger()}updateBytesSent(e,t,i){let r,o;if(this._latestBytesSent[e]&&t<this._latestBytesSent[e].bytesSent&&this.clearLatestpacketsSent([e]),this._latestBytesSent[e]){const{bytesSent:n,timestamp:s}=this._latestBytesSent[e];r=t-n,o=i-s,this._latestBytesSent[e]={bytesSent:t,timestamp:i}}else r=t,o=1e3,this._latestBytesSent[e]={bytesSent:t,timestamp:i};return Qo(o,r)}updateBytesRecv(e,t,i){let r,o;if(this._latestBytesRecv[e]&&t<this._latestBytesRecv[e].bytesRecv&&this.clearLatestPacketsRecv([e]),this._latestBytesRecv[e]){const{bytesRecv:n,timestamp:s}=this._latestBytesRecv[e];r=t-n,o=i-s,this._latestBytesRecv[e]={bytesRecv:t,timestamp:i}}else r=t,o=1e3,this._latestBytesRecv[e]={bytesRecv:t,timestamp:i};return Qo(o,r)}updateSenderPacketsLost(e,t,i){let r;if(Object.prototype.hasOwnProperty.call(this._latestPacketsSent[e],"packetsSent")){const{packetsLost:o,packetsSent:n}=this._latestPacketsSent[e];r=tn(t,i,o,n),this._latestPacketsSent[e].packetsLost=t,this._latestPacketsSent[e].packetsSent=o===t?n:i}else r=tn(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:o,packetsRecv:n}=this._latestPacketsRecv[e];r=tn(t,i+t,o,n+o)}else r=tn(t,i);return this._latestPacketsRecv[e]={packetsLost:t,packetsRecv:i},r}clearLatestpacketsSent(t){t.forEach((t=>{if(parseInt(t.split("_").pop())===e.RCMediaType.VIDEO_ONLY){const e=`${t}_tiny`;delete this._latestPacketsSent[e],delete this._latestBytesSent[e]}delete this._latestPacketsSent[t],delete this._latestBytesSent[t]}))}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(o.L_ABSTRACT_STAT_PARSER_FORMAT_RTC_STATE_REPORT_O,JSON.stringify({status:n.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===nn.REMOTEINBOUNDRTP?(e.remoteInbound.push(t),e):t.type===nn.INBOUNDRTP?(e.inbound.push(t),e):t.type===nn.OUTBOUNDRTP?(e.outbound.push(t),e):t.type===nn.TRANSPORT?(e.transport.push(t),e):t.type===nn.PEERCONNECTION?(e.connection.push(t),e):e),{outbound:[],remoteInbound:[],inbound:[],transport:[],connection:[]})}}Sn.formatSourceIdMapFromSdp=(e,t)=>{const i=on.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 fn extends Sn{formatRCRTCStateReport(e){const{outbound:t,remoteInbound:i,inbound:r,transport:o,connection:n}=this.formatStateData(e),s={senders:[],receivers:[]},a=Math.floor(n[0].timestamp);s.timestamp=a;let d=0,c=0;({totalPacketsLost:d,bitrateSend:c,senders:s.senders}=this.pickOutbound(t,e,d,a,c)),i.length>0&&s.senders.length>0&&this.pickRemoteInbound(i,s.senders,e);let _=0;if(({totalPacketsLost:d,bitrateRecv:_,receivers:s.receivers}=this.pickInbound(r,e,d,a,_)),o.length>0){const t=o[0];this.pickRtcTransport(t,e,s,_,c,d)}return s}pickRtcTransport(e,t,i,r,o,n){const{selectedCandidatePairId:s}=e;if(s){const e=t[s],{availableOutgoingBitrate:a,availableIncomingBitrate:d,currentRoundTripTime:c,localCandidateId:_,remoteCandidateId:l}=e,u=t[_],{ip:h,port:R,networkType:v}=u,C=t[l],{ip:p,port:g,protocol:m}=C;i.iceCandidatePair={IP:h,port:R,networkType:v,remoteIP:p,remotePort:g,protocol:m,bitrateRecv:r,bitrateSend:o,rtt:1e3*c,availableOutgoingBitrate:a,availableIncomingBitrate:d,totalPacketsLost:n},i.receivers.forEach((e=>{e.rtt=c}))}}pickRemoteInbound(e,t,i){e.forEach((e=>{var r;const{localId:o,jitter:n,roundTripTime:s,packetsLost:a}=e,d=t.filter((e=>e.id===o))[0];if(d&&!rn(d)){const e=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i[d.id].ssrc);d.jitter=Math.round(1e3*n),d.rtt=s;const t=this._latestPacketsSent[e].crtPacketsSent;d.packetsLostRate=this.updateSenderPacketsLost(e,a,t)}}))}pickOutbound(e,t,i,r,o){const n=[];return e.forEach((e=>{var s;if("unified-plan"===this._sdpSemantics&&!this.isValidSender(e))return;const{id:a,kind:d,transportId:c,mediaSourceId:_,remoteId:l,packetsSent:u,bytesSent:h,trackId:R,encoderImplementation:v,pliCount:C,nackCount:p,firCount:g}=e;if(!R)return;let{framesPerSecond:m,frameWidth:T,frameHeight:I}=e;"video"!==d||T||I||m||(T=t[R].frameWidth,I=t[R].frameHeight,m=_?t[_].framesPerSecond:null);const E=t[l];let S=null,f=null,O=0;E&&(S=E.jitter,f=E.roundTripTime,O=E.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[R].audioLevel;let A=null;!this._latestPacketsSent[L]&&(this._latestPacketsSent[L]={}),E?A=this.updateSenderPacketsLost(L,O,u):this._latestPacketsSent[L].crtPacketsSent=u;let y=this.updateBytesSent(L,h,r);y<0&&(y=0),o+=y,n.push({id:a,trackId:L,kind:d,packetsLostRate:A,remoteResource:!1,audioLevel:N||0===N?en(N):null,frameWidth:T,frameHeight:I,frameRate:m,bitrate:y,jitter:S?Math.round(1e3*S):S,rtt:f,encoderImplementation:v,pliCount:C,nackCount:p,googFirsSent:fo,samplingRate:fo,googRenderDelayMs:fo,trackState:fo})})),{totalPacketsLost:i,bitrateSend:o,senders:n}}pickInbound(e,t,i,r,o){let n=[];return e.forEach((e=>{var s;if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(e))return;const{trackId:a,packetsLost:d,packetsReceived:c,jitter:_,bytesReceived:l,framesPerSecond:u,kind:h,codecImplementationName:R,nackCount:v,pliCount:C}=e;if(!a)return;let{frameWidth:p,frameHeight:g,audioLevel:m}=e;"video"===h?p||g||(p=t[a].frameWidth,g=t[a].frameHeight):m||(m=t[a].audioLevel),i+=d;const T=null===(s=this._store)||void 0===s?void 0:s.getTrackIdBySSRC(e.ssrc),I=this.updateReceiverPacketsLost(T,d,c);let E=this.updateBytesRecv(T,l,r);E<0&&(E=0),o+=E,n.push({trackId:T,kind:h,packetsLostRate:I,remoteResource:!0,audioLevel:m||0===m?en(m):null,frameWidth:p,frameHeight:g,frameRate:u,bitrate:E,jitter:_?Math.round(1e3*_):0,codecImplementationName:R,nackCount:v,pliCount:C,rtt:null,samplingRate:fo,googFirsReceived:fo,googRenderDelayMs:fo,trackState:fo})})),{totalPacketsLost:i,bitrateRecv:o,receivers:n}}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,o;if("unified-plan"===this._sdpSemantics&&!this.isValidSender(i))return;const{mediaSourceId:n,trackId:s,kind:a}=i,d=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i.ssrc),c=n&&e[n]?e[n].audioLevel:(null===(o=e[s])||void 0===o?void 0:o.audioLevel)||null;d&&t.push({trackId:d,audioLevel:c||0===c?en(c):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:o}=i,n=i.audioLevel||e[o].audioLevel,s=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i.ssrc);s&&t.push({trackId:s,audioLevel:n||0===n?en(n):null})})),t}}class On extends Sn{formatRCRTCStateReport(e){var t,i,r;const o=+new Date,n={senders:[],receivers:[],timestamp:o};let s=0,a=0,d=0;for(const c in e){const _=e[c],{type:l}=_;if("outbound-rtp"===l){if("unified-plan"===this._sdpSemantics&&!this.isValidSender(_))continue;const{id:i,kind:r,bytesSent:d,packetsSent:c,bitrateMean:l,framerateMean:u,nackCount:h,pliCount:R,remoteId:v}=_,{jitter:C,roundTripTime:p,packetsLost:g}=v?e[v]:{jitter:null,roundTripTime:null,packetsLost:0},m=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(_.ssrc);s+=g;let T=null;!this._latestPacketsSent[m]&&(this._latestPacketsSent[m]={}),v?T=this.updateSenderPacketsLost(m,g,c):this._latestPacketsSent[m].crtPacketsSent=c;let I=0;"video"===r?l&&(I=Math.floor(l/1e3)):I=this.updateBytesSent(m,d,o),I<0&&(I=0),a+=I,n.senders.push({trackId:m,kind:r,packetsLostRate:T,remoteResource:!1,audioLevel:null,frameWidth:null,frameHeight:null,frameRate:Math.floor(u),bitrate:I,jitter:C?Math.round(1e3*C):null,rtt:p,encoderImplementation:null,pliCount:R,nackCount:h,googFirsSent:fo,samplingRate:fo,googRenderDelayMs:fo,trackState:fo})}if("remote-inbound-rtp"===l){const{localId:t}=_,r=null===(i=this._store)||void 0===i?void 0:i.getTrackIdBySSRC(e[t].ssrc),o=n.senders.filter((e=>e.trackId===r))[0];o&&rn(o)&&(o.jitter=Math.round(1e3*_.jitter),o.rtt=_.rtt,o.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:c,framerateMean:l,kind:u,bitrateMean:h,nackCount:R,pliCount:v}=_,C=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(_.ssrc);s+=t;const p=this.updateReceiverPacketsLost(C,t,a);let g=0;"video"===u?h&&(g=Math.floor(h/1e3)):g=this.updateBytesRecv(C,i,o),g<0&&(g=0),d+=g,n.receivers.push({trackId:C,kind:u,packetsLostRate:p,remoteResource:!0,audioLevel:null,frameWidth:null,frameHeight:null,frameRate:Math.floor(l),bitrate:g,jitter:c?Math.round(1e3*c):null,codecImplementationName:null,nackCount:R,pliCount:v,rtt:null,samplingRate:fo,googFirsReceived:fo,googRenderDelayMs:fo,trackState:fo})}if("candidate-pair"===l&&"succeeded"===_.state){const t=e[_.localCandidateId],{address:i,port:r}=t,o=e[_.remoteCandidateId],{address:c,port:l,protocol:u}=o;n.iceCandidatePair={IP:i,port:r,networkType:null,remoteIP:c,remotePort:l,protocol:u,bitrateRecv:d,bitrateSend:a,rtt:null,availableOutgoingBitrate:null,availableIncomingBitrate:null,totalPacketsLost:s}}}return n.iceCandidatePair&&(n.iceCandidatePair.bitrateSend=a),n.iceCandidatePair&&(n.iceCandidatePair.bitrateRecv=d),n}getAudioLevelList(e){var t,i;const r=[];for(const o in e){const n=e[o],{type:s}=n;if("outbound-rtp"===s){if("unified-plan"===this._sdpSemantics&&!this.isValidSender(n))continue;const{kind:e}=n;if("video"===e)continue;const i=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(n.ssrc);r.push({trackId:i,audioLevel:null})}if("inbound-rtp"===s){if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(n))continue;const{kind:e}=n;if("video"===e)continue;const t=null===(i=this._store)||void 0===i?void 0:i.getTrackIdBySSRC(n.ssrc);r.push({trackId:t,audioLevel:null})}}return r}}class Ln extends Sn{formatRCRTCStateReport(e){const t={senders:[],receivers:[]},i=Math.floor(e.RTCPeerConnection.timestamp);t.timestamp=i;const r=Object.keys(e);let o=0,n=0;r.filter((e=>/^RTCOutboundRTP(Video|Audio)Stream_/.test(e))).forEach((r=>{var o;const s=e[r];if("unified-plan"===this._sdpSemantics&&!this.isValidSender(s))return;const a=null===(o=this._store)||void 0===o?void 0:o.getTrackIdBySSRC(s.ssrc),{mediaType:d,transportId:c,remoteId:_,packetsSent:l,bytesSent:u,trackId:h,encoderImplementation:R,pliCount:v,nackCount:C,firCount:p}=s;if(!h)return;const{audioLevel:g,frameHeight:m,frameWidth:T}=e[h];let I=this.updateBytesSent(a,u,i);I<0&&(I=0),n+=I,t.senders.push({trackId:a,kind:d,packetsLostRate:null,remoteResource:!1,audioLevel:g||0===g?en(g):null,frameWidth:T,frameHeight:m,frameRate:null,bitrate:I,jitter:null,rtt:null,encoderImplementation:R,pliCount:v,nackCount:C,googFirsSent:fo,samplingRate:fo,googRenderDelayMs:fo,trackState:fo})}));let s=0;r.filter((e=>/^RTCInboundRTP(Video|Audio)Stream_/.test(e))).forEach((r=>{var n;const a=e[r];if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(a))return;const{trackId:d,packetsLost:c,packetsReceived:_,jitter:l,bytesReceived:u,mediaType:h,nackCount:R,pliCount:v}=a,C=null===(n=this._store)||void 0===n?void 0:n.getTrackIdBySSRC(a.ssrc);if(!d)return;const{frameHeight:p,frameWidth:g,audioLevel:m}=e[d];o+=c;const T=this.updateReceiverPacketsLost(C,c,_);let I=this.updateBytesRecv(C,u,i);I<0&&(I=0),s+=I,t.receivers.push({trackId:C,kind:h,packetsLostRate:T,remoteResource:!0,audioLevel:m||0===m?en(m):null,frameWidth:g,frameHeight:p,frameRate:null,bitrate:I,jitter:l,codecImplementationName:null,nackCount:R,pliCount:v,rtt:null,samplingRate:fo,googFirsReceived:fo,googRenderDelayMs:fo,trackState:fo})}));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:d,currentRoundTripTime:c,localCandidateId:_,remoteCandidateId:l}=i,u=e[_],{address:h,port:R}=u,v=e[l],{address:C,port:p,protocol:g}=v;t.iceCandidatePair={IP:h||null,port:R,networkType:null,remoteIP:C,remotePort:p,protocol:g,bitrateRecv:s,bitrateSend:n,rtt:1e3*c,availableOutgoingBitrate:a,availableIncomingBitrate:d,totalPacketsLost:o},t.receivers.forEach((e=>{e.rtt=c}))}}return t}getAudioLevelList(e){const t=[],i=Object.keys(e);i.filter((e=>/^RTCOutboundRTP(Video|Audio)Stream_/.test(e))).forEach((i=>{var r;const o=e[i];if("unified-plan"===this._sdpSemantics&&!this.isValidSender(o))return;const{trackId:n,mediaType:s}=o;if("video"===s)return;const a=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(o.ssrc),d=e[n];t.push({trackId:a,audioLevel:d||0===d?en(d):null})}));return i.filter((e=>/^RTCInboundRTP(Video|Audio)Stream_/.test(e))).forEach((i=>{var r;const o=e[i];if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(o))return;const{trackId:n,mediaType:s}=o;if(!n||"video"===s)return;const{audioLevel:a}=e[n],d=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(o.ssrc);t.push({trackId:d,audioLevel:a||0===a?en(a):null})})),t}}class Nn{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=Le.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*Nn.KBitrate}\r\nb=TIAS:${e*Nn.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*Nn.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*Nn.KBitrate}\r\nb=TIAS:${t.max*Nn.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*Nn.KBitrate,"x-google-min-bitrate="+t.min*Nn.KBitrate,`x-google-start-bitrate=${t.start||t.max*Nn.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*Nn.KBitrate}\r\nb=TIAS:${t.max*Nn.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===an.SENDONLY){if(/\ba=sendonly\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}if(t===an.RECVONLY){if(/\ba=recvonly\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}if(t===an.INACTIVE){if(/\ba=inactive\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}return e}}Nn.KBitrate=1,function(e){e.PLANB="plan-b",e.UNIFIEDPLAN="unified-plan"}(sn||(sn={})),function(e){e.SENDONLY="sendonly",e.RECVONLY="recvonly",e.INACTIVE="inactive"}(an||(an={}));class An{static setSdpSemantics(e){const t=Le.getLogger(),{browser:i,version:r,supportsUnifiedPlan:n}=ut;null==t||t.info(o.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 An._sdpSemantics}constructor(e){this._peer=e,this._outboundStreams={},this._logger=null,this._logger=Le.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:o,height:n}=et(i);e.push({trackId:i.id,simulcast:r?Zo.TINY:Zo.NORMAL,resolution:`${o}x${n}`})}return e}setRemoteAnswer(t){var r,s,a;return i(this,void 0,void 0,(function*(){if(t=Nn.trimBlankLine(t),"disconnected"===this._peer.connectionState||"closed"===this._peer.connectionState)return null===(r=this._logger)||void 0===r||r.info(o.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:n.FAILED,msg:`peer.connectionState is ${this._peer.connectionState}`})),e.RCRTCCode.SET_REMOTE_DESCRIPTION_FAILED;try{yield this._peer.setRemoteDescription({type:"answer",sdp:t})}catch(t){return null===(s=this._logger)||void 0===s||s.info(o.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:n.FAILED,msg:t})),e.RCRTCCode.SET_REMOTE_DESCRIPTION_FAILED}return null===(a=this._logger)||void 0===a||a.info(o.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:n.SUCCESSED,sdp:t})),e.RCRTCCode.SUCCESS}))}getStatParsr(e,t,i,r){return/chrome/i.test(ut.browser)?new fn(e,t,i,r):/Firefox/i.test(ut.browser)?new On(e,t,i,r):/Safari/i.test(ut.browser)?new Ln(e,t,i,r):null}resetSdp(e){return Nn.trimBlankLine(e)}}class yn extends Nn{constructor(e){super(e,sn.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=Nn.clearInactiveOrRecvonly(t);i&&i[1]===ye.AUDIO&&(e[1]=r),i&&i[1]===ye.VIDEO&&(e[2]=r)}));const t=e.join("");return Nn.trimBlankLine(t)}setAudioBitrateWithStreamId(e,t){var i;return null===(i=this._logger)||void 0===i||i.warn(o.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(o.L_FUNCTION_IS_UNAVAILABLE,"plan-b not support set Video Bitrate With Stream Id"),this}}class kn extends An{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 o=e.getTrackId(),n=this.senders[o];n?n.replaceTrack(i):(this.senders[o]=this._peer.addTrack(i,r),Object.defineProperty(i,"trackId",{value:o,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 i(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 yn(e),i={max:0,min:0},r={max:0,min:0};return this._localTracks.forEach((e=>{const{min:t,max:o,start:n}=e.getBitrate();e.isAudioTrack()&&(r.max=r.max<o?o:r.max,r.min=r.min>t?t:r.min,r.max===o?r.start=n:r.start=.7*r.max),e.isVideoTrack()&&(i.max=i.max<o?o:i.max,i.min=i.min>t?t:i.min,i.max===o?i.start=n:i.start=.7*i.max)})),t.setAudiosBitrate(r),t.setVideosBitrate(i),t.stringify()}}class Dn extends Nn{constructor(e){super(e,sn.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 Nn.trimBlankLine(t)}}class bn{static splitSections(e){return e.split("\nm=").map(((e,t)=>`${(t>0?`m=${e}`:e).trim()}\r\n`))}static getMediaSections(e){const t=bn.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=bn.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 bn.splitLines(e).filter((e=>0===e.indexOf(t)))}static parseMsid(e){let t;const i=bn.matchPrefix(e,"a=msid:");if(1===i.length)return t=i[0].substr(7).split(" "),{stream:t[0],track:t[1]};const r=bn.matchPrefix(e,"a=ssrc:").map((e=>bn.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=bn.matchPrefix(e,"a=mid:")[0];if(t)return t.substr(6)}}class Un{constructor(){this.__streams=new Map}static getInstance(){return Un.instance||(Un.instance=new Un),Un.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 Pn extends An{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(o.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(),o=e.__innerGetMediaStreamTrack();this._localTracks[i]=e;const n=this._outboundStreams[r]||(this._outboundStreams[r]=new MediaStream);n.getTracks().forEach((e=>{e.kind===o.kind&&n.removeTrack(e)})),n.addTrack(o);const s=this._sendTransceiver[i];s?(s.sender.replaceTrack(o),s.direction="sendonly"):this._sendTransceiver[i]=this._peer.addTransceiver(o,{direction:"sendonly",streams:[n]});Un.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 o=this._outboundStreams[i];(e.isAudioTrack()?o.getAudioTracks():o.getVideoTracks()).forEach((e=>o.removeTrack(e)));const n=this._sendTransceiver[`${t}_tiny`];if(n&&"inactive"!==n.direction&&"closed"!==this._peer.connectionState){n.direction="inactive";const{sender:e}=n,t=e.track;this._peer.removeTrack(e),e.replaceTrack(null);this._outboundStreams[`${i}_tiny`].removeTrack(t),t.stop()}}updateRecvTransceiverMap(t,i){const{mediaType:r}=rt(t);this._recvTransceiver[t]=i;const o=r===e.RCMediaType.AUDIO_ONLY?this._recvAudio:this._recvVideo,n=o.findIndex((e=>e===i));n>=0&&o.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],o=i.findIndex((e=>e===r));o>=0&&(t.splice(e,1),i.splice(o,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 i(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 Dn(e);for(const r in this._sendTransceiver){const o=this._sendTransceiver[r],n=null===(t=o.sender.track)||void 0===t?void 0:t.kind;let{direction:s,mid:a}=o;if(!a){bn.getMediaSections(e).forEach((e=>{bn.parseExtmap(e);const{kind:t}=bn.parseMLine(e);let{stream:i}=bn.parseMsid(e);const o=bn.getMid(e);"video"===n?/tiny$/.test(i)?i=i.replace(/tiny$/gi,"1_tiny"):i+="_1":i+="_0",i===r&&n===t&&o&&(a=o)}))}if(a){if(s===an.SENDONLY){const e=this._localTracks[r],t=null==e?void 0:e.getBitrate();n===ye.AUDIO&&t&&i.setAudioBitrateWithMid(t,a),n===ye.VIDEO&&t&&i.setVideoBitrateWithMid(t,a)}s===an.INACTIVE&&i.clearnSsrcWithMid(a,an.INACTIVE)}}for(const e in this._recvTransceiver){const t=this._recvTransceiver[e],{direction:r,mid:o}=t;o&&r===an.INACTIVE&&i.clearnSsrcWithMid(o,an.RECVONLY)}return i.stringify()}resetAnswerSdp(e){var t;const i=new Dn(e);for(const e in this._sendTransceiver){const r=this._sendTransceiver[e],{mid:o}=r;if(o){const n=this._localTracks[e],s=null==n?void 0:n.getBitrate(),a=null===(t=r.sender.track)||void 0===t?void 0:t.kind;a===ye.AUDIO&&s&&i.setAudioBitrateWithMid(s,o),a===ye.VIDEO&&s&&i.setVideoBitrateWithMid(s,o)}}return i.stringify()}}!function(e){e.VP8="VP8",e.VP9="VP9",e.H264="H264"}(dn||(dn={}));class Mn extends t.EventEmitter{constructor(e,t,i,r,o,n,s=!1,a){super(),this._pcName=e,this._reTryExchange=t,this._currentUserId=i,this._polarisReport=r,this.onTrackTrouble=o,this._store=n,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 d=An.getSdpSemantics(),c=this._rtcPeerConn=new RTCPeerConnection({sdpSemantics:d});this._sdpStrategy="plan-b"===d?new kn(c):new Pn(c),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,d,this._currentUserId,this._store),this._logger=Le.getLogger()}getName(){return this._pcName}getLocalTracks(){return Object.values(this.pubLocalTracks)}_onConnectionStateChange(){var e;null===(e=this._logger)||void 0===e||e.info(o.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;Bo({iceNewStatusData:{start:Date.now(),status:this._rtcPeerConn.iceConnectionState}}),(e=>{var t,i;const r=Do.getMemo(),o={dur:0,pices:0,ices:0,rid:(null===(t=r.joinRoomData)||void 0===t?void 0:t.roomId)||"",csnid:(null===(i=r.clientData)||void 0===i?void 0:i.clientSessionId)||"",snid:"",time:0,rcdts:[],lcdts:[],cncdts:void 0,cr:"unknown",net:"unknown",uid:e};r.qualityIceStatusReportData=o})(this._currentUserId),null===(e=this._logger)||void 0===e||e.info(o.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_S,JSON.stringify({connectionState:this._rtcPeerConn.connectionState,pcName:this._pcName})),"connected"===this._rtcPeerConn.iceConnectionState&&((()=>{var e,t,i,r,n,s,a,d,c,_,l,u,h,R;const v=Do.getMemo(),C=Date.now();if(!(null===(e=v.iceStatusData)||void 0===e?void 0:e.subscribeNotReport)&&(null===(t=v.iceStatusData)||void 0===t?void 0:t.subscribe)){Bo({subscribeNotReport:!0});const e=v.iceStatusData.notFirst?0:((null===(i=v.iceNewStatusData)||void 0===i?void 0:i.start)||0)-((null===(n=null===(r=v.iceStatusData)||void 0===r?void 0:r.subscribe)||void 0===n?void 0:n.time)||0),t=JSON.stringify(Object.assign(Object.assign({},v.qualityIceStatusReportData),{dur:e,pices:bo[(null===(s=v.iceOldStatusData)||void 0===s?void 0:s.status)||0],ices:bo[(null===(a=v.iceNewStatusData)||void 0===a?void 0:a.status)||0],rcdts:void 0,lcdts:void 0,cncdts:void 0,time:C}));Ne.__statistics(o.L_QS_SUB_ICE_STATUS_S,t)}if(!(null===(d=v.iceStatusData)||void 0===d?void 0:d.publishNotReport)&&(null===(c=v.iceStatusData)||void 0===c?void 0:c.publish)){Bo({publishNotReport:!0});const e=v.iceStatusData.notFirst?0:((null===(_=v.iceNewStatusData)||void 0===_?void 0:_.start)||0)-((null===(u=null===(l=v.iceStatusData)||void 0===l?void 0:l.publish)||void 0===u?void 0:u.time)||0),t=JSON.stringify(Object.assign(Object.assign({},v.qualityIceStatusReportData),{dur:e,pices:bo[(null===(h=v.iceOldStatusData)||void 0===h?void 0:h.status)||0],ices:bo[(null===(R=v.iceNewStatusData)||void 0===R?void 0:R.status)||0],rcdts:void 0,lcdts:void 0,cncdts:void 0,time:C}));Ne.__statistics(o.L_QS_PUB_ICE_STATUS_S,t)}Bo({notFirst:!0})})(),$o(),this.startAutoExecute(1e3)),"failed"!==this._rtcPeerConn.iceConnectionState&&"disconnected"!==this._rtcPeerConn.iceConnectionState||($o(),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,this._rtcPeerConn.iceConnectionState,this._pcName)}catch(e){null===(r=this._logger)||void 0===r||r.error(o.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_REPORT_R,JSON.stringify({status:n.FAILED,pcName:this._pcName,mag:e}))}}_onTrackReady(t){if(!t.streams.length)return;const i=t.streams[0].id,{track:r}=t.receiver,o=[i,"audio"===r.kind?e.RCMediaType.AUDIO_ONLY:e.RCMediaType.VIDEO_ONLY].join("_");Object.defineProperty(r,"trackId",{value:o,writable:!1,enumerable:!1,configurable:!1}),this._updateRecvTransceiverMap(o,t.transceiver),this.emit(Mn.__INNER_EVENT_TRACK_READY__,t)}setBitrate(e,t,r){var s;return i(this,void 0,void 0,(function*(){this._sdpStrategy.setBitrate(e,t,r),null===(s=this._logger)||void 0===s||s.info(o.L_RTC_PEER_CONNECTION_SET_BITRATE_O,JSON.stringify({status:n.SUCCESSED,max:e,min:t,start:r}))}))}createOffer(e){var t;return i(this,void 0,void 0,(function*(){const i=yield this._sdpStrategy.createOffer(e);return null===(t=this._logger)||void 0===t||t.info(o.L_RTC_PEER_CONNECTION_CREATE_OFFER_O,JSON.stringify({offerSDP:i.sdp,sdpDemantics:i.semantics})),i}))}setRemoteAnswer(e){return i(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(xe.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(xe.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),e.on(xe.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.on(xe.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),null===(t=this._logger)||void 0===t||t.info(o.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(o.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_BY_ID_O,JSON.stringify({status:n.SUCCESSED,trackId:e})),this.removeLocalTrack(r)):null===(t=this._logger)||void 0===t||t.warn(o.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_BY_ID_O,JSON.stringify({status:n.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(xe.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(xe.__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(o.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(xe.__INNER_EVENT_MUTED_CHANGE__,e,t)}_onLocalTrackDestroied(e){this.emit(xe.__INNER_EVENT_DESTROY__,e)}registerReportListener(e){this._reportListener=e}_createRCRTCStateReport(e){const{timestamp:t,iceCandidatePair:i,senders:r,receivers:o}=e;(null==i?void 0:i.totalPacketsLost)&&(null==i||delete i.totalPacketsLost);for(const e in i)vt(i[e])&&delete i[e];const n=[];r.forEach((e=>{const{trackId:t,kind:i,packetsLostRate:r,remoteResource:o,bitrate:s,jitter:a}=e,d={trackId:t,kind:i,packetsLostRate:r,remoteResource:o,bitrate:s,jitter:a};(e.audioLevel||0===e.audioLevel)&&(d.audioLevel=e.audioLevel),e.frameWidth&&(d.frameWidth=e.frameWidth),e.frameHeight&&(d.frameHeight=e.frameHeight),e.frameRate&&(d.frameRate=e.frameRate),e.trackId&&n.push(Object.assign({},d))}));const s=[];return o.forEach((e=>{const{trackId:t,kind:i,packetsLostRate:r,remoteResource:o,bitrate:n,jitter:a}=e,d={trackId:t,kind:i,packetsLostRate:r,remoteResource:o,bitrate:n,jitter:a};(e.audioLevel||0===e.audioLevel)&&(d.audioLevel=e.audioLevel),e.frameWidth&&(d.frameWidth=e.frameWidth),e.frameHeight&&(d.frameHeight=e.frameHeight),e.frameRate&&(d.frameRate=e.frameRate),e.trackId&&s.push(Object.assign({},d))})),{timestamp:t,iceCandidatePair:i,senders:n,receivers:s,pcName:this._pcName}}_getStatsData(){var e,t;return i(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 o=null===(t=this.reportParser)||void 0===t?void 0:t.formatRCRTCStateReport(i);return this._formatStatsData=o,o}))}_reportHandle(){var e,t,r,o;return i(this,void 0,void 0,(function*(){const i=yield this._getStatsData();if(!i)return;const n=this._createRCRTCStateReport(i);null===(t=null===(e=this._reportListener)||void 0===e?void 0:e.onStateReport)||void 0===t||t.call(e,n);const s=[...i.receivers,...i.senders].filter((e=>!("audio"!==e.kind))).map((e=>({trackId:e.trackId,audioLevel:e.audioLevel})));if(this.emit(Mn.__INNER_AUDIOLEVEL_CHANGE__,s),this._isRoomAudience){const e=this._getLiveAudioState();e.length&&(null===(o=null===(r=this._reportListener)||void 0===r?void 0:r.onReportLiveAudioStates)||void 0===o||o.call(r,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,o=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(i),{userId:n}=rt(o);return{audioLevel:en(r),userId:n,trackId:o}})).filter((e=>!!e.userId))}_sendR3R4Data(){var e,t;return i(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:o}=e;let n=0;"unknown"!==(null==t?void 0:t.toLowerCase())&&i&&r&&o||(n=1),this.setTroubleTrack(e.trackId,n)}})),e}return!0}))}__reportR3R4ToPolaris(){return i(this,void 0,void 0,(function*(){clearTimeout(this._reportR3R4ToPolarisTimer),this._reportR3R4ToPolarisTimer=setTimeout((()=>i(this,void 0,void 0,(function*(){this._sendR3R4Data().then((()=>{this.__reportR3R4ToPolaris()}))}))),2e3)}))}getRTCPeerConn(){return this._rtcPeerConn}getCapabilitiesCodes(e=dn.H264){var t;let i=null===(t=RTCRtpSender.getCapabilities("video"))||void 0===t?void 0:t.codecs,r=null;switch(e){case dn.VP8:case dn.VP9:r=i.find((t=>t.mimeType.match(e)));break;case dn.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 i(this,void 0,void 0,(function*(){const i=this.getRTCPeerConn(),r=this.getCapabilitiesCodes(e);null===(t=this._logger)||void 0===t||t.info(o.L_SET_ENCODER_PREFERENCES_S,JSON.stringify({status:n.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(o.L_RTC_PEER_CONNECTION_DESTROY_O,JSON.stringify({status:n.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)}}Mn.__INNER_EVENT_TRACK_READY__="inner-track-ready",Mn.__INNER_AUDIOLEVEL_CHANGE__="inner-audio-level-change",function(e){e[e.DISABLE=0]="DISABLE",e[e.ENABLE=1]="ENABLE"}(cn||(cn={})),function(e){e[e.MeetingOrAnchor=1]="MeetingOrAnchor",e[e.Audience=2]="Audience"}(_n||(_n={})),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"}(ln||(ln={})),function(e){e.R1="R1",e.R2="R2",e.R3="R3",e.R4="R4"}(un||(un={}));class xn{constructor(e,t,i,r,o=_n.MeetingOrAnchor){this._context=e,this._runtime=t,this._roomId=i,this._crtRTCRoom=r,this._userRole=o}_send(e){return i(this,void 0,void 0,(function*(){if(this._context.getConnectionStatus()!==t.ConnectionStatus.CONNECTED)return ln.NOT_REPORT;return(yield this._context.setRTCState(this._roomId,e))===t.ErrorCode.SUCCESS?ln.REPORT_SUCCESS:ln.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(t){let i="";const r=t.split("_");if(t.includes("_tiny")){const t=r.pop(),o=parseInt(r.pop())===e.RCMediaType.AUDIO_ONLY?"audio":"video",n=r.pop();i=[r.join("_"),n,t,o].join("_")}else{const t=parseInt(r.pop())===e.RCMediaType.AUDIO_ONLY?"audio":"video",o=r.pop();i=[r.join("_"),o,t].join("_")}return i}sendR3R4Data(e){return i(this,void 0,void 0,(function*(){const{iceCandidatePair:t,senders:i,receivers:r}=e,o=(null==t?void 0:t.bitrateSend)||fo,n=(null==t?void 0:t.bitrateRecv)||fo,s=(null==t?void 0:t.networkType)||"unknown",a=(null==t?void 0:t.rtt)||fo,d=`${(null==t?void 0:t.IP)||fo}:${null==t?void 0:t.port}`,c=(null==t||t.remoteIP,null==t||t.remotePort,(null==t?void 0:t.availableIncomingBitrate)||fo),_=(null==t?void 0:t.availableOutgoingBitrate)||fo,l=(null==t?void 0:t.totalPacketsLost)||fo,u=this._context.getCurrentId();let h=`R3\t${o}\t-1\t-1\t-1\t${s}\t${a}\t${d}\t${c}\t${_}\t${l}\t${u}\r`,R=`R4\t${n}\t-1\t-1\t-1\t${s}\t${a}\t${d}\t${c}\t${_}\t${l}\t${u}\r`;const v=i.map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:o,bitrate:n,packetsLostRate:s,frameRate:a,frameWidth:d,frameHeight:c,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:R,googFirsSent:v,encoderImplementation:C}=e,p=this._getPolarisTrackId(i),g=this._getRealResourceId(i);return{trackId:p,googCodecName:C||String(fo),audioLevel:r||0===r?r:fo,bitrate:n||0===n?n:fo,packetsLostRate:s||0===s?s:fo,frameRate:a||fo,resolution:d&&c?`${d} * ${c}`:"-1",jitter:l||fo,nackCount:u||0===u?u:fo,pliCount:h||0===h?h:fo,rtt:R||fo,googFirsSent:v,samplingRate:o,googRenderDelayMs:_,encoderImplementation:C||String(fo),trackState:(null===(t=this._crtRTCRoom.getLocalTrack(g))||void 0===t?void 0:t.isLocalMuted())?cn.DISABLE:cn.ENABLE}})),C=r.filter((e=>!!e.trackId)).map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:o,bitrate:n,packetsLostRate:s,frameRate:a,frameWidth:d,frameHeight:c,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:R,googFirsReceived:v,codecImplementationName:C}=e,p=this._getPolarisTrackId(i),g=this._getRealResourceId(i);return{trackId:p,googCodecName:C||String(fo),audioLevel:r||0===r?r:fo,bitrate:n||0===n?n:fo,packetsLostRate:s||0===s?s:fo,frameRate:a||fo,resolution:d&&c?`${d} * ${c}`:"-1",jitter:l||fo,nackCount:u||0===u?u:fo,pliCount:h||0===h?h:fo,rtt:R||fo,googFirsReceived:v,samplingRate:o,googRenderDelayMs:_,codecImplementationName:C||String(fo),trackState:(null===(t=this._crtRTCRoom.getRemoteTrack(g))||void 0===t?void 0:t.isLocalMuted())?cn.DISABLE:cn.ENABLE}}));let p=ln.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&&(p=yield this._send(`${h}\r${this._userRole}`));let g=ln.REPORT_FAIL;return R+=C.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&&(g=yield this._send(`${R}\r${this._userRole}`)),p!==ln.REPORT_SUCCESS&&g!==ln.REPORT_SUCCESS?ln.REPORT_FAIL:ln.REPORT_SUCCESS}))}sendR1(){const e=this._context.getCoreVersion(),t=navigator.platform,i=`R1\t5.6.6\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 wn{constructor(e,t,i,r,o=_n.MeetingOrAnchor){this._context=e,this._runtime=t,this._roomId=i,this._crtRTCRoom=r,this._userRole=o,this._useHttp=!0;const n=this._context.getNaviInfo();wn.logServer=null==n?void 0:n.logServer,wn.dc=null==n?void 0:n.dc,this._polarisSignalReporter=new xn(e,t,i,r,o)}_send(r,n){var s,a;return i(this,void 0,void 0,(function*(){if(this._context.getConnectionStatus()!==t.ConnectionStatus.CONNECTED)return ln.NOT_REPORT;const{logServer:i}=wn;if(!i||!this._useHttp||!zo.jwtToken)return ln.REPORT_FAIL;const d=yield this._context.setRTCStateByHttp(i,this._runtime,r,n);return d===ln.REPORT_SUCCESS?ln.REPORT_SUCCESS:d===e.RCRTCCode.JWT_TIME_OUT?(this._refetchNaviInfo(),ln.REPORT_FAIL):d===ln.REPORT_FAIL||d===ln.PB_ERROR?(null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_HTTP_POLARIS_REPORT_FAIL_O,`send data fail -> code: ${d}`),this._useHttp=!1,ln.REPORT_FAIL):ln.REPORT_FAIL}))}_refetchNaviInfo(){return i(this,void 0,void 0,(function*(){const{jwt:e,naviInfo:t}=yield(r=this._context,i(void 0,void 0,void 0,(function*(){const e=r.getPluginContext();yield e.refetchNaviInfo();const t=r.getNaviInfo();return{naviInfo:t,jwt:No(t)}})));var r;zo.jwtToken=e,wn.logServer=null==t?void 0:t.logServer,wn.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(t){let i="";const r=t.split("_");if(t.includes("_tiny")){const t=r.pop(),o=parseInt(r.pop())===e.RCMediaType.AUDIO_ONLY?"audio":"video",n=r.pop();i=[r.join("_"),n,t,o].join("_")}else{const t=parseInt(r.pop())===e.RCMediaType.AUDIO_ONLY?"audio":"video",o=r.pop();i=[r.join("_"),o,t].join("_")}return i}_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:wn.dc||""}}_formatReportData(e,t){let i=this._formatReportBaseData(e),r={};switch(e){case un.R1:r=this._formatR1Data();break;case un.R2:r=this._formatR2Data(t);break;case un.R3:case un.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.6",imVersion:this._context.getCoreVersion(),platform:"web",device:navigator.platform,os:String(fo),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:o}=t;let n=0,s=[];return e===un.R3?(n=(null==i?void 0:i.bitrateSend)||fo,s=r.map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:o,bitrate:n,packetsLostRate:s,frameRate:a,frameWidth:d,frameHeight:c,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:R,googFirsSent:v,encoderImplementation:C}=e,p=this._getPolarisTrackId(i),g=this._getRealResourceId(i);return{trackId:p,codeName:C||String(fo),volume:String(r||0===r?r:fo),samplingRate:o||fo,bitRate:n||0===n?n:fo,packetLossRate:s||0===s?s:fo,frameRate:a||fo,resolution:d&&c?`${d} * ${c}`:"-1",blockTime:_,jitterData:l||fo,nAckCount:String(u||0===u?u:fo),pliCount:String(h||0===h?h:fo),googleRTTTotalTime:R||fo,isReceiveFirstFrameRate:v,codeType:C||String(fo),isEnabled:(null===(t=this._crtRTCRoom.getLocalTrack(g))||void 0===t?void 0:t.isLocalMuted())?cn.DISABLE:cn.ENABLE}}))):e===un.R4&&(n=(null==i?void 0:i.bitrateRecv)||fo,s=o.filter((e=>!!e.trackId)).map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:o,bitrate:n,packetsLostRate:s,frameRate:a,frameWidth:d,frameHeight:c,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:R,googFirsReceived:v,codecImplementationName:C}=e,p=this._getPolarisTrackId(i),g=this._getRealResourceId(i);return{trackId:p,codeName:C||String(fo),volume:String(r||0===r?r:fo),samplingRate:o||fo,bitRate:n||0===n?n:fo,packetLossRate:s||0===s?s:fo,frameRate:a||fo,resolution:d&&c?`${d} * ${c}`:"-1",blockTime:_,jitterData:l||fo,nAckCount:String(u||0===u?u:fo),pliCount:String(h||0===h?h:fo),googleRTTTotalTime:R||fo,isReceiveFirstFrameRate:v,codeType:C||String(fo),isEnabled:(null===(t=this._crtRTCRoom.getRemoteTrack(g))||void 0===t?void 0:t.isLocalMuted())?cn.DISABLE:cn.ENABLE}}))),{info:{joinTime:this._context.userJoinTime||0,receiveTime:Date.now(),totalBitRate:n,appCPUUsage:-1,systemCPUUsage:-1,systemCPUFrequency:-1,networkStatus:(null==i?void 0:i.networkType)||"unknown",googleRTTNetwork:(null==i?void 0:i.rtt)||fo,ipAddress:`${(null==i?void 0:i.IP)||fo}:${null==i?void 0:i.port}`,useReceiveBroadBand:String((null==i?void 0:i.availableIncomingBitrate)||fo),useSendBroadBand:String((null==i?void 0:i.availableOutgoingBitrate)||fo),packetLossCount:String((null==i?void 0:i.totalPacketsLost)||fo),streams:s}}}sendR3R4Data(e){return i(this,void 0,void 0,(function*(){let t=ln.REPORT_FAIL;if(e.senders.length){const i=this._formatReportData(un.R3,e);t=yield this._send(i,un.R3),t===ln.REPORT_FAIL&&(t=yield this._polarisSignalReporter.sendR3R4Data(e))}let i=ln.REPORT_FAIL;if(e.receivers.length){const t=this._formatReportData(un.R4,e);i=yield this._send(t,un.R4),i===ln.REPORT_FAIL&&(i=yield this._polarisSignalReporter.sendR3R4Data(e))}return t!==ln.REPORT_SUCCESS&&i!==ln.REPORT_SUCCESS?ln.REPORT_FAIL:ln.REPORT_SUCCESS}))}sendR1(){var e;return i(this,void 0,void 0,(function*(){const t=this._formatReportData(un.R1);(yield this._send(t,un.R1))===ln.REPORT_FAIL&&(null===(e=this._polarisSignalReporter)||void 0===e||e.sendR1())}))}sendR2(e,t,r){var o;return i(this,void 0,void 0,(function*(){const i=this._formatReportData(un.R2,{action:e,status:t,trackIds:r});(yield this._send(i,un.R2))===ln.REPORT_FAIL&&(null===(o=this._polarisSignalReporter)||void 0===o||o.sendR2(e,t,r))}))}}class Bn{constructor(e){this._room=e,this._audioLevelChangeHandler=null}audioLevelReport(e){if(!this._audioLevelChangeHandler)return;const t=[];e.forEach((e=>{const{userId:i}=rt(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}}e.RCRTCLiveRole=void 0,(hn=e.RCRTCLiveRole||(e.RCRTCLiveRole={}))[hn.ANCHOR=1]="ANCHOR",hn[hn.AUDIENCE=2]="AUDIENCE";class Vn{constructor(e=!1,t,i,r,o,n,s,a){this._useMutilPeerC=e,this._roomId=t,this._reTryExchange=i,this._currentUserId=r,this._polarisReport=o,this._isRoomAudience=n,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 xe||e[0]instanceof $e?{track:e[0]}:e[0];return t.isLocalTrack()}_groupTracksByTag(e){const t={};return e.forEach((e=>{const{track:i}=e instanceof xe?{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 Mn(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 o=this._genPCName(i,e),n=r[e];t.push(this._createOnePeerCItem(o,n))}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}=rt(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"}(Rn||(Rn={})),function(e){e.NORMAL="normal",e.MIDDLE="middle",e.TAIL="tail"}(vn||(vn={})),function(e){e[e.LOW=0]="LOW",e[e.NORMAL=1]="NORMAL",e[e.HIGH=2]="HIGH"}(Cn||(Cn={})),function(e){e[e.Destroy=40400]="Destroy"}(pn||(pn={}));class Fn{get priority(){return Cn.LOW}get kind(){return Rn.UNKNOWN}}class Jn extends Fn{constructor(e=vn.NORMAL){super(),this.state=e}get kind(){return Rn.ASYNC_COMMAND}setState(e){this.state=e}pickoutSubscribed(e,t){const{unsubscribe:i,subscribe:r}=this.calcSubscribeList(e,t);return Jn.AsyncSubscribeTasks=[],Jn.AsyncUnsubscribeTasks=[],Jn.AsyncUpdateSubscribeTasks=[],{subscribe:r,unsubscribe:i}}calcSubscribeList(e,t){const i=[],r=new Set,o=[],n=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)||n.has(t)||(o.push(e),n.add(t))})),{unsubscribe:i,subscribe:o}}formateTrack(e){return e.map((e=>e instanceof $e?{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}}Jn.AsyncSubscribeTasks=[],Jn.AsyncUnsubscribeTasks=[],Jn.AsyncUpdateSubscribeTasks=[];class Hn{constructor(e,t,i,r,o,n,s,a,d){this.context=e,this.service=t,this.peerMgr=i,this.roomId=r,this.crtUserId=o,this.roomMode=n,this.polarisReport=s,this.isUpgrade=a,this.isMainRoom=d,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}=rt(e);return this._roomResources[t].find((t=>it(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 Gn extends Hn{_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 t in this._roomResources){const i=this._roomResources[t];t!==this.crtUserId&&0!==i.length&&i.forEach((t=>{const i=it(t),{tag:r,userId:o,mediaType:n}=rt(i),s=n===e.RCMediaType.AUDIO_ONLY?new We(r,o):new qe(r,o);s.__innerSetRemoteMuted(0===t.state),this._remoteTracks[i]=s}))}}initWithRoomData(e,t){this._sessionId=e.sessionId,this._token=e.token,this._roomStatusVersion=Tt(e.version),this.isUpgrade?this._roomResources={}:this._roomResources=pt(e,this.roomId,t),this._updateTrackIdSSRCMap(),this._initRemoteTracks(),this.setResourcesByUserId(this.crtUserId,this.getResourcesByUserId(this.crtUserId)||[]);const i=Le.getLogger();null==i||i.info(o.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=Tt(e)}}class Kn{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,r,s;return i(this,void 0,void 0,(function*(){if(this._isDestroyed||this._busy||0===this._queue.length)return;this._busy=!0;const{command:i,resolve:a,reject:d}=this._queue.shift();let c;const _=this._queue.map((e=>{var t;return null===(t=null==e?void 0:e.command)||void 0===t?void 0:t.kind})),l=null===(e=this.context.logger)||void 0===e?void 0:e.createTraceId();try{null===(t=this.context.logger)||void 0===t||t.info(o.L_INVOKER_EXECUTE_T,`commandKind: ${i.kind}, kinds:${_.join(",")}, length: ${this._queue.length}`,l),c=yield i.execute(this._store,this)}catch(e){return null===(r=this.context.logger)||void 0===r||r.error(o.L_INVOKER_EXECUTE_R,JSON.stringify({error:e,status:n.FAILED,commandKind:i.kind,kinds:_.join(",")}),l),d(e),void this._next()}null===(s=this.context.logger)||void 0===s||s.info(o.L_INVOKER_EXECUTE_R,`status: ${n.SUCCESSED}, commandKind: ${i.kind}`,l),a(c),this._next()}))}push(t){return new Promise(((i,r)=>{var n;if(null===(n=this.context.logger)||void 0===n||n.info(o.L_INVOKER_PUSH_O,JSON.stringify({isDestroyed:this._isDestroyed,commandKind:t.kind,length:this._queue.length})),this._isDestroyed)return void r({code:e.RCRTCCode.NOT_IN_ROOM});const{kind:s}=t;this._queue.length>0&&s===Rn.ASYNC_COMMAND&&({command:t,resolve:i,reject:r}=this.commandOffset(t,i,r));const{priority:a}=t;if(a===Cn.LOW)this._queue.push({command:t,resolve:i,reject:r});else{const e=this._queue.findIndex((e=>e.command.priority<a)),o=-1===e?this._queue.length-1:e;this._queue.splice(o,0,{command:t,resolve:i,reject:r})}Promise.resolve().then((()=>{this._execute()}))}))}commandOffset(e,t,r){const o=this._queue.length-1;if(!(this._queue[o].command.kind===Rn.ASYNC_COMMAND))return{command:e,resolve:t,reject:r};const[n]=this._queue.splice(o,1);n.command instanceof Jn&&(n.command.setState(vn.MIDDLE),e instanceof Jn&&e.setState(vn.TAIL));const s=e.execute;return e.execute=function(t,r){return i(this,void 0,void 0,(function*(){return n.command.execute.call(n.command,t,r),s.call(e,t,r)}))},{command:e,resolve:e=>{n.resolve.call(n,e),t(e)},reject:e=>{n.reject.call(n,e),r(e)}}}isDestroyed(){var e;return null===(e=this.context.logger)||void 0===e||e.info(o.L_INVOKER_DESTROY_O,JSON.stringify({isDestroyed:this._isDestroyed})),this._isDestroyed}destroy(){var e;null===(e=this.context.logger)||void 0===e||e.info(o.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 jn extends Kn{constructor(t,i,r,o,n,s,a,d,c){super(t,new Gn(t,i,r,o,n,s,a,d,c),e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED)}get store(){return this._store}destroy(){super.destroy(),this._store.removeRemoteTracks()}}class $n extends Fn{get kind(){return Rn.UNPUBLISH_PREV}execute(e){var r,s,a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){const i=e.getResourcesByUserId(e.crtUserId),h=i.slice();i.length=0;const R=null===(s=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===s?void 0:s.createTraceId();null===(d=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_UNPUBLISH_PREV_COMMAND_T,JSON.stringify({resource:h}),R);const v=yield e.context.setRTCTotalRes(e.roomId,[Ye(It.UNPUBLISH,h)],ze([]),It.TOTAL_CONTENT_RESOURCE,ze([]));v!==t.ErrorCode.SUCCESS?null===(_=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_UNPUBLISH_PREV_COMMAND_R,JSON.stringify({status:n.FAILED,code:v}),R):null===(u=null===(l=e.context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_UNPUBLISH_PREV_COMMAND_R,JSON.stringify({status:n.SUCCESSED}),R)}))}}!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"}(gn||(gn={}));class Wn extends Fn{constructor(e,t,i,r,o,n,s,a){super(),this.roomId=e,this.roomType=t,this.context=i,this.joinType=r,this.livingType=o,this.innerUserDatas=n,this.outerUserDatas=s,this.traceId=a}get kind(){return Rn.JOINROOM}execute(r,s){var a,d,c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f,O;return i(this,void 0,void 0,(function*(){Jo(),Fo(this.roomType);const{context:i,service:L}=r;let N=o.L_RTC_CLIENT_JOIN_RTC_ROOM_R;if(this.roomType===gn.LIVE?N=o.L_RTC_CLIENT_JOIN_LIVING_ROOM_R:this.roomType===gn.CROSS_MUTI&&(N=o.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_R),i.getConnectionStatus()!==t.ConnectionStatus.CONNECTED)return null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.SIGNAL_DISCONNECTED,msg:"im not connected"}),this.traceId),{code:e.RCRTCCode.SIGNAL_DISCONNECTED};if(L.detectorMediaSever(),Ct(i.getNaviInfo()))return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"}),this.traceId),{code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR};if(!t.validate("roomId",this.roomId,t.notEmptyString,!0))return null===(u=null===(l=r.context)||void 0===l?void 0:l.logger)||void 0===u||u.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> roomId"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};if(!t.validate("roomType",this.roomType,(e=>void 0!==gn[e])))return null===(R=null===(h=r.context)||void 0===h?void 0:h.logger)||void 0===R||R.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> roomType"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};if(!t.validate("outerUserDatas",this.outerUserDatas,t.isObject,!1))return null===(C=null===(v=r.context)||void 0===v?void 0:v.logger)||void 0===C||C.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> outerUserDatas"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};if(this.outerUserDatas){if(!Object.keys(this.outerUserDatas).every((e=>t.validate(`outerUserDatas.${e}`,this.outerUserDatas[e],t.isString,!0))))return null===(g=null===(p=r.context)||void 0===p?void 0:p.logger)||void 0===g||g.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> outerUserDatas"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR}}if(!L.getNaviMS().length)return null===(T=null===(m=r.context)||void 0===m?void 0:m.logger)||void 0===T||T.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"No audio / video server address available"}),this.traceId),{code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER};const{code:A,data:y}=yield i.joinRTCRoom(this.roomId,this.roomType,this.livingType,this.joinType,this.innerUserDatas,this.outerUserDatas);if(A!==t.ErrorCode.SUCCESS||!y){Vo(this.roomId,A,r.getSessionId(),r.crtUserId);const t=40032===A?e.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED:A;return null===(E=null===(I=r.context)||void 0===I?void 0:I.logger)||void 0===E||E.error(N,JSON.stringify({status:n.FAILED,code:t,msg:"joinRoom failed"}),this.traceId),{code:t}}Vo(this.roomId,A,r.getSessionId(),r.crtUserId),Jo(this.roomId),r.initWithRoomData(y,this.traceId);r.getResourcesByUserId(r.crtUserId).length>0&&s.push(new $n);const k=null===(S=y.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===S?void 0:S.value;return k&&r.setCDNUris(JSON.parse(k)[0]),null===(O=null===(f=r.context)||void 0===f?void 0:f.logger)||void 0===O||O.info(N,JSON.stringify({status:n.SUCCESSED,userId:r.crtUserId,roomId:this.roomId}),this.traceId),{code:e.RCRTCCode.SUCCESS,data:y}}))}}!function(e){e[e.ROOM=1]="ROOM",e[e.PERSON=2]="PERSON"}(mn||(mn={})),function(e){e.PUBLISH="publish",e.SUBSCRIBE="subscribe"}(Tn||(Tn={})),function(e){e.BEGIN="begin",e.END="end"}(In||(In={})),function(e){e[e.SPREAD=0]="SPREAD",e[e.NO_SPREAD=-1]="NO_SPREAD"}(En||(En={}));class qn extends Fn{constructor(e,t,i,r){super(),this.headers=e,this.reqBody=t,this.traceId=i,this.isNeedUpdateMsas=r}execute(t,r){var o,n;return i(this,void 0,void 0,(function*(){const i=yield t.service.exchange(this.headers,this.reqBody,this.traceId,this.isNeedUpdateMsas);if(t.roomMode!==gn.LIVE)return i;const r=null===(n=null===(o=i.data)||void 0===o?void 0:o.urls)||void 0===n?void 0:n.pull_url;if(i.code!==e.RCRTCCode.SUCCESS||!r)return i;const s=JSON.parse(r);if(t.setCDNUris(s),(null==s?void 0:s.broadcast)===En.SPREAD){t.setCDNEnabel(!0);const e=Object.assign(Object.assign({},s),{enableInnerCDN:!0});es(t.context,t.roomId,e)}return i}))}}class Yn extends Fn{constructor(e,t,i,r){super(),this.tracks=e,this.subhook=t,this.forceReq=i,this.traceId=r}get kind(){return Rn.UPDATE_SUBSCRIBE_LIST}execute(r,s){var a,d,c,_,l,u,h,R,v,C,p,g,m,T;return i(this,void 0,void 0,(function*(){const{tracks:i,forceReq:I}=this,{roomId:E}=r;if(null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_UPDATE_SUBSCRIBELIST_COMMAND_T,`roomId: ${E}, forceReq: ${I}, trackIds: ${i.map(mt)}`,this.traceId),!t.validate("tracks",i,(()=>t.isArray(i)&&i.every((e=>e instanceof $e||e.track instanceof $e))),!0))return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.warn(o.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"tracks is invalid"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};let S=i.map((e=>e instanceof $e?{track:e}:Object.assign({},e)));const f={};S=S.filter((e=>{var t,i;const n=e.track.getTrackId();return r.getRemoteTrack(n)?!f[n]&&(f[n]=!0,!0):(null===(i=null===(t=r.context)||void 0===t?void 0:t.logger)||void 0===i||i.warn(o.L_UPDATE_SUBSCRIBELIST_COMMAND_P,`track cannot found in room -> trackId: ${n}`,this.traceId),!1)})).map((e=>Object.assign({},e)));const O=r.getSubscribedList().map((e=>Object.assign({},e)));if(!I){let t=!1;if(S.forEach((e=>{const i=O.findIndex((t=>t.track===e.track));if(-1===i)return void(t=!0);O.splice(i,1)[0].subTiny!==e.subTiny&&(t=!0)})),O.length){t=!0;const e=O.map((e=>e.track));null===(u=null===(l=r.context)||void 0===l?void 0:l.logger)||void 0===u||u.warn(o.L_CLEAR_UNSUBSCRIBE_LIST_O,JSON.stringify({list:e.map((e=>e.getTrackId()))}),this.traceId);const i=r.getSubscribedList().filter((t=>!e.includes(t.track)));r.resetSubscribedList(i)}if(!t)return null===(R=null===(h=r.context)||void 0===h?void 0:h.logger)||void 0===R||R.warn(o.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:n.SUCCESSED,msg:"subscribe list unchanged"}),this.traceId),{code:e.RCRTCCode.SUCCESS}}const{pc:L,pushOtherRooms:N,headers:A}=this.subhook(i);L.updateSubRemoteTracks(S.map((e=>e.track))),Uo(r.roomId,"",r.getSessionId()),Po(r.roomId,"",r.getSessionId());const y=yield Qn(S,!1,L,r);N&&(y.pushOtherRooms=N);const k=yield new qn(A,y,this.traceId,!0).execute(r,s);if(S.map((e=>e.track.getTrackId())),k.code!==e.RCRTCCode.SUCCESS)return wo(S,k.code),null===(C=null===(v=r.context)||void 0===v?void 0:v.logger)||void 0===C||C.error(o.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:n.FAILED,code:k.code}),this.traceId),{code:k.code};const{sdp:D,resultCode:b,message:U,subscribedList:P}=k.data;if(b!==e.RCRTCCode.SUCCESS)return wo(S,b),null===(g=null===(p=r.context)||void 0===p?void 0:p.logger)||void 0===g||g.error(o.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:n.FAILED,code:b}),this.traceId),{code:b};const M=yield L.setRemoteAnswer(D.sdp);if(M!==e.RCRTCCode.SUCCESS)return wo(S,M),{code:M};Sn.formatSourceIdMapFromSdp(D.sdp,"subscribe"),wo(S,M),Bo({subscribe:{time:Date.now()}});const x=null==P?void 0:P.map((e=>`${e.msid}_${e.mediaType}`)),w=S.filter((e=>null==x?void 0:x.includes(e.track.getTrackId()))),B=S.filter((e=>!(null==x?void 0:x.includes(e.track.getTrackId()))));null===(T=null===(m=r.context)||void 0===m?void 0:m.logger)||void 0===T||T.info(o.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.SUCCESSED,subSuccessTrackIds:x,failedList:B}),this.traceId);const V=r.getRemoteTracks();for(const e in V){const t=w.some((t=>t.track.getTrackId()===e));V[e].__innerSetSubscribed(t);const i=w.some((t=>t.track.getTrackId()===e&&t.subTiny));V[e].isVideoTrack()&&V[e].__innerSetIsTinyTrack(i)}return r.resetSubscribedList(w),B.length?{code:e.RCRTCCode.SUCCESS,failedList:B}:{code:e.RCRTCCode.SUCCESS}}))}}class zn extends Fn{constructor(e,t,i){super(),this.tracks=e,this.subhook=t,this.traceId=i}get kind(){return Rn.UNSUBSCRIBE}execute(r,s){var a,d,c,_;return i(this,void 0,void 0,(function*(){const{tracks:i}=this;if(null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_UNSUBSCRIBE_T,JSON.stringify({unSubscribeTrackIds:i.map(mt)}),this.traceId),!t.validate("tracks",i,(()=>t.isArray(i)&&i.length>0&&i.every((e=>e instanceof $e))),!0))return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.warn(o.L_ABSTRACT_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};const l=r.getSubscribedList().map((e=>Object.assign({},e))).filter((e=>!i.includes(e.track)));return r.polarisReport.sendR2(Tn.SUBSCRIBE,In.END,i.map((e=>e.getTrackId()))),qo(!0),new Yn(l,this.subhook,!1,this.traceId).execute(r,s)}))}}class Zn extends Fn{constructor(e,t,i){super(),this.subhook=e,this.tracks=t,this.onTrackUnpublish=i}execute(e,t){var r,n;return i(this,void 0,void 0,(function*(){const{tracks:i}=this,s=null===(r=e.context.logger)||void 0===r?void 0:r.createTraceId();null===(n=e.context.logger)||void 0===n||n.info(o.L_USER_LEFT_UNSUBSCRIBE_O,void 0,s),yield new zn(i,this.subhook,s).execute(e,t),i.forEach((t=>{t.__innerDestroy(),e.removeRemoteTrack(t.getTrackId())})),this.onTrackUnpublish(i)}))}}function Qn(e,t,r,o){return i(this,void 0,void 0,(function*(){return{sdp:yield r.createOffer(t),extend:JSON.stringify({resolutionInfo:r.getOutboundVideoInfo()}),subscribeList:e.filter((e=>{const t=e.track.getTrackId(),{userId:i}=rt(t),r=o.getResourcesByUserId(i);if(!r)return!1;const n=r.filter((e=>t===`${e.msid}_${e.mediaType}`)).length;return n})).map((e=>({simulcast:e.subTiny?Zo.TINY:Zo.NORMAL,resolution:"",uri:o.getPublishedResourceByTrackId(e.track.getTrackId()).uri}))),switchstream:!1}}))}function Xn(r,s,a){var d,c,_,l;return i(this,void 0,void 0,(function*(){const i=null===(d=null==r?void 0:r.logger)||void 0===d?void 0:d.createTraceId();null===(c=null==r?void 0:r.logger)||void 0===c||c.info(o.L_LIVING_ROOM_SPREAD_CDN_INFO_T,JSON.stringify({CDNUris:a}),i);const u=yield r.setRTCCDNUris(s,It.TOTAL_CONTENT_RESOURCE,JSON.stringify([a]));return u!==t.ErrorCode.SUCCESS?(null===(_=null==r?void 0:r.logger)||void 0===_||_.error(o.L_LIVING_ROOM_SPREAD_CDN_INFO_R,`status: ${n.FAILED}, code: ${u}`,i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(l=null==r?void 0:r.logger)||void 0===l||l.info(o.L_LIVING_ROOM_SPREAD_CDN_INFO_R,`status: ${n.SUCCESSED}`,i),{code:e.RCRTCCode.SUCCESS})}))}function es(r,s,a){var d,c,_,l;return i(this,void 0,void 0,(function*(){const i=null===(d=null==r?void 0:r.logger)||void 0===d?void 0:d.createTraceId();null===(c=null==r?void 0:r.logger)||void 0===c||c.info(o.L_LIVING_ROOM_SET_ROOM_CDN_INFO_T,`CDNUris: ${a}`,i);const u=yield r.setRTCData(s,"cdn_uris",JSON.stringify([a]),!0,mn.ROOM);return u!==t.ErrorCode.SUCCESS?(null===(_=null==r?void 0:r.logger)||void 0===_||_.error(o.L_LIVING_ROOM_SET_ROOM_CDN_INFO_R,`status: ${n.FAILED}, code: ${u}`,i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(l=null==r?void 0:r.logger)||void 0===l||l.info(o.L_LIVING_ROOM_SET_ROOM_CDN_INFO_R,`status: ${n.SUCCESSED}`,i),{code:e.RCRTCCode.SUCCESS})}))}function ts(t){return i(this,void 0,void 0,(function*(){const{context:i}=t,{roomId:r}=t,o=Object.assign({},t.getCDNUris(),{enableInnerCDN:t.getCDNEnable()});return(yield Promise.all([Xn(i,r,o),es(i,r,o)])).every((t=>t.code===e.RCRTCCode.SUCCESS))?{code:e.RCRTCCode.SUCCESS}:{code:e.RCRTCCode.SIGNAL_ERROR}}))}function is(r,s,a,d,c,_,l){return i(this,void 0,void 0,(function*(){const{roomId:i,crtUserId:u,roomMode:h}=s,R=[],v={},C={},p={},g=pt(r,i,l),m=Object.keys(g),T=s.getAllUserIds();for(let e=m.length-1;e>=0;e-=1){const t=m[e],i=T.indexOf(t);if(-1===i){R.push(t),v[t]=nt(g[t]);continue}const r=s.getResourcesByUserId(t),o=g[t],{publishedList:n,modifiedList:a,unpublishedList:d}=st(r,o,!0);v[t]=nt(n),C[t]=nt(d),p[t]=nt(a),T.splice(i,1)}T.length&&T.forEach((e=>{s.removeResourcesByUserId(e)})),s.assignRoomData(g),T.length&&(yield rs(T,s,c,d,l),a.onUserLeave(T)),R.length&&a.onUserJoin(R);for(const e in C){if(e===u)continue;const t=C[e];if(t.length){const e=t.map((e=>s.getRemoteTrack(it(e))));yield new Zn(c,e,a.onTrackUnpublish).execute(s,d)}}Object.keys(v).forEach((t=>{const i=v[t];if(0===i.length)return;const r=i.map((t=>{const i=it(t),{userId:r,tag:o,mediaType:n}=rt(i),a=n===e.RCMediaType.AUDIO_ONLY?new We(o,r):new qe(o,r);return s.addRemoteTrack(a),a.__innerSetRemoteMuted(0===t.state),a}));a.onTrackPublish(r)})),Object.keys(p).forEach((e=>{p[e].forEach((e=>{const t=it(e),i=s.getRemoteTrack(t);i.__innerSetRemoteMuted(0===e.state),i.isAudioTrack()?a.onAudioMuteChange(i):a.onVideoMuteChange(i)}))})),h===t.RTCMode.LIVE&&function(e,t,i){var r,s,a;if(!i)return void(null===(s=null===(r=t.context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_LIVING_ROOM_RECONNECTED_R,JSON.stringify({status:n.FAILED,code:"",msg:"cdn_uris not found"})));const d=JSON.parse(i),c=(null===(a=t.getCDNUris())||void 0===a?void 0:a.enableInnerCDN)!==d.enableInnerCDN;t.setCDNUris(d),c&&e.onCDNEnableChange(d.enableInnerCDN)}(a,s,_)}))}function rs(e,t,r,n,s){var a;return i(this,void 0,void 0,(function*(){const i=[],d=[];e.forEach((e=>{i.push(...t.getRemoteTracksByUserId(e)),d.push(e)})),i.length&&(null===(a=t.context.logger)||void 0===a||a.info(o.L_RES_UNPUB_UNSUBSCRIBE_O,void 0,s),yield new zn(i,r,s).execute(t,n),i.forEach((e=>t.removeRemoteTrack(e.getTrackId())))),d.length&&d.forEach((e=>t.removeResourcesByUserId(e)))}))}function os(e){var t;const{userId:i,userData:r,event:o,switchRoleType:n}=e;return{users:[{userId:i,extra:null===(t=r.filter((e=>"extra"===e.key))[0])||void 0===t?void 0:t.value,state:o,switchRoleType:n}]}}function ns(e){var t,i;const{userId:r,userData:o}=e,n=(e=>e.some((e=>"uris"===e.key||"cdn_uris"===e.key)))(o);if(!n)return;const s=null===(t=o.filter((e=>"uris"===e.key))[0])||void 0===t?void 0:t.value,a=null===(i=o.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 ss=(t,i,r)=>{const o=t.split("\r\nm"),n=r===e.RCMediaType.AUDIO_ONLY?"audio":"video",s=o.filter((e=>e.includes(`=${n}`)&&e.includes(i)))[0];let a=new RegExp(`a=ssrc:(.*?) msid:${i}`);const d=s.match(a);return d?d[1]:""};class as extends Fn{constructor(e,t,i){super(),this.msgContent=e,this.subhook=t,this.traceId=i}get kind(){return Rn.PARSE_USERSTATE}get priority(){return Cn.NORMAL}execute(e,t){return i(this,void 0,void 0,(function*(){const i=[],r=[],n=[],s=[],a={joined:i,left:r,upgrade:n,downgrade:s},{users:d}=this.msgContent;if(0===d.length)return a;for(let t=0;t<d.length;t++){const i=d[t];if(i.extra&&i.extra.roomId!==e.roomId)return a;if(1===Number(i.state)&&!e.getRemoteUserIds().includes(i.userId))return a}d.forEach((t=>{var a,d,c,_;const{userId:l}=t;if(0===Number(t.state)){const r=e.getResourcesByUserId(l);r||(t.switchRoleType?n.push(l):i.push(l),null===(d=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_PARSE_USERSTATE_COMMAND_R,JSON.stringify({userId:l,msg:"user "+(t.switchRoleType?"upgrade":"joined")}),this.traceId)),e.setResourcesByUserId(l,r||[])}else null===(_=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_PARSE_USERSTATE_COMMAND_R,JSON.stringify({userId:l,msg:"user "+(t.switchRoleType?"downgrade":"left")}),this.traceId),t.switchRoleType?s.push(l):r.push(l)}));const c=[...r,...s];return c.length&&(yield rs(c,e,this.subhook,t,this.traceId)),a}))}}class ds extends Fn{constructor(e,t,i,r,o,n){super(),this.msgContent=e,this.messageType=t,this.senderId=i,this.subhook=r,this.callback=o,this.traceId=n}get kind(){return Rn.PARSE_REMOTERES}get priority(){return Cn.NORMAL}execute(t,r){var s,a,d,c;return i(this,void 0,void 0,(function*(){const{uris:i}=this.msgContent,_=[],l=[],u=[];let h;const R=this.senderId,{messageType:v}=this;if(!t.getRemoteUserIds().includes(R))return;const C=t.getResourcesByUserId(R)||[];switch(v){case It.MODIFY:u.push(...i);break;case It.PUBLISH:_.push(...i);break;case It.UNPUBLISH:l.push(...i);break;case It.TOTAL_CONTENT_RESOURCE:h=st(C,i),_.push(...h.publishedList),l.push(...h.unpublishedList),u.push(...h.modifiedList)}if(_.length>0){const i=C.map(it),d=[],c=[];if(_.forEach((r=>{const o=it(r),n=i.indexOf(o),{userId:s,tag:a,mediaType:_}=rt(o);n>-1?C[n]=r:C.push(r);let l=t.getRemoteTrack(o);l?l.isSubscribed()&&d.push(l):(l=_===e.RCMediaType.AUDIO_ONLY?new We(a,s):new qe(a,s),t.addRemoteTrack(l),c.push(l)),l.__innerSetRemoteMuted(0===r.state)})),d.length){const i=d.map((e=>e.getTrackId())),{code:c}=yield new Yn(d,this.subhook,!0,this.traceId).execute(t,r);c!==e.RCRTCCode.SUCCESS&&(null===(a=null===(s=t.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RESUB_REPUB_RES_R,JSON.stringify({status:n.FAILED,trackIds:i,code:c}),this.traceId))}this.callback.onTrackPublish(c)}if(l.length>0){const e=l.map(it);for(let t=C.length-1;t>=0;t-=1){const i=C[t];e.includes(it(i))&&C.splice(t,1)}const i=l.map((e=>{const i=it(e);return t.getRemoteTrack(i)}));yield new Zn(this.subhook,i,this.callback.onTrackUnpublish).execute(t,r)}if(u.length>0){const e=C.map(it);for(let i=0;i<u.length;i+=1){const r=u[i],o=it(r),n=e.indexOf(o);C[n].state=r.state;const s=t.getRemoteTrack(o);s.__innerSetRemoteMuted(0===r.state),s.isAudioTrack()?this.callback.onAudioMuteChange(s):this.callback.onVideoMuteChange(s)}}if(t.setResourcesByUserId(R,C),t.roomMode!==gn.LIVE)return;const p=this.msgContent;if(!p.cdn_uris)return;const g=(null===(d=t.getCDNUris())||void 0===d?void 0:d.enableInnerCDN)!==p.cdn_uris[0].enableInnerCDN;t.setCDNUris(p.cdn_uris[0]),g&&this.callback.onCDNEnableChange(!!(null===(c=t.getCDNUris())||void 0===c?void 0:c.enableInnerCDN))}))}}class cs extends Fn{constructor(e,t,i,r){super(),this.tracks=e,this.subhook=t,this.forceReq=i,this.traceId=r}get kind(){return Rn.SUBSCRIBE}execute(r,s){var a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){const{tracks:i,forceReq:h}=this;if(null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:i.map(mt),forceReq:h}),this.traceId),!t.validate("tracks",i,(()=>t.isArray(i)&&i.length>0&&i.every((e=>e instanceof $e||e.track instanceof $e))),!0))return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};const R=r.getSubscribedList().map((e=>Object.assign({},e))),v=i.map((e=>e instanceof $e?{track:e}:e));let C=!1;const p=[];return v.forEach((e=>{const t=e.track.getTrackId();p.push(t);const i=R.find((e=>e.track.getTrackId()===t));i&&i.subTiny===e.subTiny||(i?i.subTiny=e.subTiny:R.push(e),C=!0)})),C||h?(r.polarisReport.sendR2(Tn.SUBSCRIBE,In.BEGIN,p),Wo(!0),new Yn(R,this.subhook,!0,this.traceId).execute(r,s)):(null===(u=null===(l=r.context)||void 0===l?void 0:l.logger)||void 0===u||u.warn(o.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.SUCCESSED,msg:"repeat subscribe"}),this.traceId),{code:e.RCRTCCode.SUCCESS})}))}}class _s extends Fn{constructor(e,t,i=3e4){var r;super(),this.tracks=e,this.pubhook=t,this.signalRetryTime=i,this._logger=null,this._logger=Le.getLogger(),this._traceId=null===(r=this._logger)||void 0===r?void 0:r.createTraceId()}get kind(){return Rn.PUBLISH}_removePubFailedTracks(e,t){e.forEach((e=>{var i;const r=e instanceof xe?e:e.track;null===(i=this._logger)||void 0===i||i.debug(o.L_ABSTRACT_ROOM_PUBLISH_P,`remove pub failed track from peerconnection -> trackId: ${r.getTrackId()}`,this._traceId),t.removeLocalTrackById(r.getTrackId())}))}__publish(t,r,s,a,d){var c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const{pcName:i,pc:v,headers:C}=r,{roomId:p}=t,g=[];s.forEach((e=>{const{track:t}=e instanceof xe?{track:e}:e;g.push(t)})),s.sort(((e,t)=>{const{track:i}=e instanceof xe?{track:e}:e,{max:r}=i.getBitrate(),{track:o}=t instanceof xe?{track:t}:t,{max:n}=o.getBitrate();return r-n}));if(v.getLocalTracks().length+((e,t)=>{let i=0;return e.forEach((e=>{const r=e instanceof xe?e.getTrackId():e.track.getTrackId();t.getLocalTrack(r)||(e instanceof xe?i++:e.pubTiny&&e.track.isVideoTrack()&&(i+=2))})),i})(s,v)>10)return null===(c=this._logger)||void 0===c||c.error(o.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PUBLISH_TRACK_LIMIT_EXCEEDED,trackIds:s.map(mt),msg:`pcName: ${i} publish track limit exceeded`}),this._traceId),{code:e.RCRTCCode.PUBLISH_TRACK_LIMIT_EXCEEDED,tracks:g};null===(_=this._logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_PUBLISH_P,`publish tracks -> roomId: ${p}, tracks: ${s.map(mt)}`,this._traceId);const m=[];for(let t=0;t<s.length;t++){const i=s[t],{track:r,pubTiny:n}=i instanceof xe?{pubTiny:!1,track:i}:i;if(r.isVideoTrack()&&n){let t;try{t=r.__innerGetMediaStreamTrack().clone();const i=n.frameRate||e.RCFrameRate.FPS_15,o=n.resolution||e.RCResolution.W176_H144,{width:s,height:a}=dt(o),d=lt(i);yield t.applyConstraints({width:s,height:a,frameRate:d})}catch(e){null==t||t.stop(),null===(l=this._logger)||void 0===l||l.warn(o.L_ABSTRACT_ROOM_PUBLISH_P,`pubTiny failed -> id: ${r.getTrackId()}, msg: ${e.message}`,this._traceId);break}const i=new Be(r.getTag(),r.getUserId(),t,!0);m.push(i),v.addLocalTrack(i)}v.addLocalTrack(r)}v.clearReTryExchangeTimer();const T=t.useMutilPeerC?[]:t.getSubscribedList();((e,t,i)=>{var r;const o=Do.getMemo(),n={dur:0,cod:0,rid:e,csnid:(null===(r=o.clientData)||void 0===r?void 0:r.clientSessionId)||"",snid:t,rsid:"",msa:"",msas:[],sigs:[],time:0,resid:"",mtp:0,smct:1,cr:"unknown",net:"unknown",uid:i,stp:0};o.qualityPublishReportData=n,o.publish={start:Date.now()}})(t.roomId,t.getSessionId(),t.crtUserId);const I=yield Qn(T,!1,v,t);a&&(I.pushOtherRooms=a),Sn.formatSourceIdMapFromSdp(I.sdp.sdp,"publish");const E=yield new qn(C,I,this._traceId,!0).execute(t,d);if(E.code!==e.RCRTCCode.SUCCESS)return Ho(g,E.code),null===(u=this._logger)||void 0===u||u.error(o.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:n.FAILED,tracks:s.map(mt),code:E.code,msg:"exchange failed"}),this._traceId),this._removePubFailedTracks(s,v),{code:E.code,tracks:g};const{sdp:S,resultCode:f,message:O}=E.data;if(f!==e.RCRTCCode.SUCCESS)return Ho(g,f),null===(h=this._logger)||void 0===h||h.error(o.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:n.FAILED,trackIds:s.map(mt),code:f,msg:`exchange inner failed: ${O}`}),this._traceId),this._removePubFailedTracks(s,v),{code:f,tracks:g};const L=yield v.setRemoteAnswer(S.sdp);return L!==e.RCRTCCode.SUCCESS?(Ho(g,L),null===(R=this._logger)||void 0===R||R.error(o.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:n.FAILED,trackIds:s.map(mt),code:L,msg:"set remote answer error"}),this._traceId),{code:L,tracks:g}):(m.length&&this._updateTinyTrackIdSSRCMap(t,I.sdp.sdp,m),Object.assign(Object.assign({},E),{tracks:g}))}))}_updateTinyTrackIdSSRCMap(t,i,r){r.forEach((r=>{const o=ss(i,r.getStreamId(),e.RCMediaType.VIDEO_ONLY);t.setTrackIdSSRCMap(Number(o),r.getTrackId())}))}_mergePublishRes(r,s){var a,d;return i(this,void 0,void 0,(function*(){const i=s.crtUserId,{roomId:c}=s;let _="";const l=[],u=s.getResourcesByUserId(i),h=[...u];let R=[];r.forEach((t=>{if(t.code!==e.RCRTCCode.SUCCESS){const{tracks:e}=t;return void l.push({code:t.code,tracks:e})}const{publishList:i,urls:r,mcuPublishList:o}=t.data;_=null==r?void 0:r.liveUrl;i.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:s.getTrackState(it(e))},e))).forEach((e=>{const{isInclude:t,index:i}=((e,t)=>{let i=!1,r=0;for(let o=0;o<t.length;o++){const n=t[o];if(`${e.msid}_${e.mediaType}`==`${n.msid}_${n.mediaType}`){i=!0,r=o;break}}return{isInclude:i,index:r}})(e,h);t?h.splice(i,1,e):h.push(e)}));const n=(null==o?void 0:o.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:1},e))))||[];R=n}));const{publishedList:v}=st(u,h),C=Object.assign(Object.assign({},s.getCDNUris()),{enableInnerCDN:s.getCDNEnable()}),p=C&&C.broadcast===En.SPREAD?JSON.stringify([C]):"";Do.getMemo().publishSignalTotal={start:Date.now()};const g=yield s.context.setRTCTotalRes(c,[Ye(It.PUBLISH,v)],ze(h),It.TOTAL_CONTENT_RESOURCE,ze(R),p);if(g!==t.ErrorCode.SUCCESS)return Go(h,g),null===(a=this._logger)||void 0===a||a.error(o.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:n.FAILED,code:g,msg:"send publish streams notification failed"}),this._traceId),{code:e.RCRTCCode.SIGNAL_ERROR};Go(h,g),Bo({publish:{time:Date.now()}}),s.setResourcesByUserId(i,h);const m=v.map((e=>it(e)));s.polarisReport&&s.polarisReport.sendR2(Tn.PUBLISH,In.BEGIN,m),v.forEach((e=>{const t=s.useMutilPeerC?`${c}_${(e=>{const t=e.split("_");return{tag:t.pop(),userId:t.join("_")}})(e.msid).tag}`:`${c}_pub`,{pc:i}=s.peerMgr.getPCItemByPCName(t);i.getLocalTrack(`${e.msid}_${e.mediaType}`).__innerSetPublished(!0)})),null===(d=this._logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:n.SUCCESSED,code:l.length?e.RCRTCCode.SOME_TRACKS_PUBLISH_FAILED:e.RCRTCCode.SUCCESS,pubSuccessTrackIds:m}),this._traceId);const T={code:e.RCRTCCode.SUCCESS};return _&&(T.liveUrl=_),l.length&&(T.failedTracks=l,T.code=e.RCRTCCode.SOME_TRACKS_PUBLISH_FAILED),T}))}execute(r,s){var a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){let{tracks:i}=this;if(null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_PUBLISH_T,JSON.stringify({trackIds:i.map(mt)})),!t.validate("tracks",i,(()=>t.isArray(i)&&i.length>0&&i.every((e=>e instanceof xe||e.track instanceof xe))),!0))return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),this._traceId),{code:e.RCRTCCode.PARAMS_ERROR};if(i=i.filter((e=>{var t,i;const{track:n}=e instanceof xe?{track:e}:e,s=n.isDestroyed();return s&&(null===(i=null===(t=r.context)||void 0===t?void 0:t.logger)||void 0===i||i.warn(o.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({msg:`track -> ${n.getTrackId()} has beem destroyed`}),this._traceId)),!s})),!i.length)return null===(u=null===(l=r.context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PUBLISH_TRACKS_IS_INVALID,msg:"params tracks is invalid"}),this._traceId),{code:e.RCRTCCode.PUBLISH_TRACKS_IS_INVALID};const h=[],{plist:R,pushOtherRooms:v}=this.pubhook(i);for(let e=0;e<R.length;e++){const t=R[e];h.push(this.__publish(r,t,t.tracks,v,s))}const C=yield Promise.all(h);return yield this._mergePublishRes(C,r)}))}}class ls extends Fn{constructor(e,t){super(),this.tracks=e,this.unpubhook=t}get kind(){return Rn.UNPUBLISH}__unpublish(t,r,s,a){var d,c,_,l;return i(this,void 0,void 0,(function*(){const{pcName:i,pc:u}=s,h=a.map((e=>e.getTrackId()));if(0===h.map(t.getPublishedResourceByTrackId.bind(t)).filter((e=>!!e)).length)return{code:e.RCRTCCode.SUCCESS,tracks:a};h.forEach((e=>u.removeLocalTrackById(e))),t.polarisReport.sendR2(Tn.PUBLISH,In.END,h),u.clearReTryExchangeTimer();const R=t.useMutilPeerC?[]:t.getSubscribedList();((e,t,i)=>{var r;const o=Do.getMemo(),n={dur:0,cod:0,rid:e,csnid:(null===(r=o.clientData)||void 0===r?void 0:r.clientSessionId)||"",snid:t,rsid:"",msa:"",msas:[],sigs:[],time:0,resid:"",mtp:0,smct:1,uid:i,stp:0};o.qualityUnpublishReportData=n,o.unpublish={start:Date.now()}})(t.roomId,t.getSessionId(),t.crtUserId);const v=yield Qn(R,!1,u,t),{pushOtherRooms:C,headers:p}=this.unpubhook(a,i);C&&(v.pushOtherRooms=C);const g=yield new qn(p,v,this._traceId,!0).execute(t,r);if(g.code!==e.RCRTCCode.SUCCESS)return Ko(a,g.code),null===(c=null===(d=t.context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_ABSTRACT_ROOM_UNPUBLISH_P,JSON.stringify({status:n.FAILED,code:g.code,trackIds:a.map(mt),msg:"exchange failed"}),this._traceId),{code:g.code,tracks:a};const{resultCode:m,message:T}=g.data;return m!==e.RCRTCCode.SUCCESS?(Ko(a,g.data.resultCode),null===(l=null===(_=t.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_ABSTRACT_ROOM_UNPUBLISH_P,JSON.stringify({status:n.FAILED,code:m,trackIds:a.map(mt),msg:`exchange inner failed: ${T}`}),this._traceId),{code:m,tracks:a}):Object.assign(Object.assign({},g),{tracks:a})}))}_mergeUnpublishRes(r,s){var a,d,c,_;return i(this,void 0,void 0,(function*(){const l=r.context.getCurrentId(),{roomId:u}=r,h=[],R=[],v=[],C=[];let p=[];for(let t=0;t<s.length;t++){const i=s[t],{tracks:o}=i;if(i.code!==e.RCRTCCode.SUCCESS){R.push({code:i.code,tracks:o});continue}const{mcuPublishList:n}=i.data,a=i.tracks.map((e=>e.getTrackId()));C.push(...a);const d=a.map(r.getPublishedResourceByTrackId.bind(r)).filter((e=>!!e));v.push(...d),h.push(i);const c=n?n.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:1},e))):[];p=c}const g=r.getResourcesByUserId(l),m=g.filter((e=>!v.includes(e)));Do.getMemo().unpublishSignalTotal={start:Date.now()};const T=yield r.context.setRTCTotalRes(u,[Ye(It.UNPUBLISH,v)],ze(m),It.TOTAL_CONTENT_RESOURCE,ze(p));if(T!==t.ErrorCode.SUCCESS)return jo(g,T),null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:n.FAILED,code:T,msg:"send unpublish notification failed"}),this._traceId),{code:e.RCRTCCode.SIGNAL_ERROR};null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:n.SUCCESSED,code:R.length?e.RCRTCCode.SOME_TRACKS_PUBLISH_FAILED:e.RCRTCCode.SUCCESS,msg:"unpublish success",unPubResourceIds:C}),this._traceId),jo(g,T),h.forEach((e=>i(this,void 0,void 0,(function*(){const{sdp:t}=e.data,{tracks:i}=e,o=r.peerMgr.getPCByTrackId(i[0].getTrackId());yield o.setRemoteAnswer(t.sdp)})))),r.setResourcesByUserId(l,m);const I={code:e.RCRTCCode.SUCCESS};return R.length&&(I.failedTracks=R,I.code=e.RCRTCCode.SOME_TRACKS_PUBLISH_FAILED),I}))}execute(r,s){var a,d,c,_,l;return i(this,void 0,void 0,(function*(){const{crtUserId:i,roomId:u}=r,{tracks:h}=this;this._traceId=null===(a=r.context.logger)||void 0===a?void 0:a.createTraceId(),null===(c=null===(d=r.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_ABSTRACT_ROOM_UNPUBLISH_T,JSON.stringify({trackIds:h.map(mt)}));if(!t.validate("tracks",h,(()=>h.every((e=>e.getUserId()===i&&e instanceof xe))),!0))return null===(l=null===(_=r.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"})),{code:e.RCRTCCode.PARAMS_ERROR};const R=r.peerMgr.createPeerCList(h),v=[];for(let e=0;e<R.length;e++){const{tracks:t}=R[e];v.push(this.__unpublish(r,s,R[e],t))}const C=yield Promise.all(v);let p=C.length;if(C.forEach((t=>{t.code!==e.RCRTCCode.SUCCESS||t.data||(p-=1)})),0===p)return{code:e.RCRTCCode.SUCCESS};return yield this._mergeUnpublishRes(r,C)}))}}class us extends Fn{constructor(e,t){super(),this.localTrack=e,this._recvSignalResultFn=t}get kind(){return Rn.LOCAL_TRACK_MUTE}execute(e,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const{localTrack:i}=this,r=i.getTrackId(),{crtUserId:R,roomId:v}=e,C=!i.isLocalMuted(),p=null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();null===(c=null===(d=e.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_T,JSON.stringify({enabled:C,trackId:this.localTrack.getTrackId()}),p);const g=[{resourceId:r,enabled:C}],m=e.getResourcesByUserId(R),T=[];for(let e=0;e<m.length;e+=1){const t=m[e],i=it(t),r=g.findIndex((e=>e.resourceId===i));if(r>=0){const{enabled:e}=g[r];t.state=e?1:0,T.push(t);break}}const I=yield e.context.setRTCTotalRes(v,[Ye(It.MODIFY,T)],ze(m),It.TOTAL_CONTENT_RESOURCE);this._recvSignalResultFn(I),I!==t.ErrorCode.SUCCESS&&(null===(l=null===(_=e.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_R,JSON.stringify({status:n.FAILED,code:I,msg:"signal error"}),p)),null===(h=null===(u=e.context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_R,JSON.stringify({status:n.SUCCESSED}),p)}))}}class hs extends Fn{constructor(e,t,i){super(),this.pcName=e,this.isPub=t,this.retryHook=i}get kind(){return Rn.RETRY_EXCHANGE}get priority(){return Cn.HIGH}execute(t,r){var n,s,a,d,c;return i(this,void 0,void 0,(function*(){const i=null===(s=null===(n=t.context)||void 0===n?void 0:n.logger)||void 0===s?void 0:s.createTraceId();null===(d=null===(a=t.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_RETRY_EXCHANGE_COMMAND_T),this._store=t,this._userId=t.context.getCurrentId();const{pcName:_,isPub:l}=this,{useMutilPeerC:u}=t,{pc:h}=t.peerMgr.getPCItemByPCName(_),R=l&&u?[]:t.getSubscribedList(),v=yield Qn(R,!0,h,t),{pushOtherRooms:C,headers:p}=this.retryHook(_);C&&(v.pushOtherRooms=C);const g=yield new qn(p,v,i).execute(t,r);if(g.code!==e.RCRTCCode.SUCCESS)return;const{sdp:m,resultCode:T}=g.data;if(T!==e.RCRTCCode.SUCCESS)return;h.clearReTryExchangeTimer();if((yield h.setRemoteAnswer(m.sdp))!==e.RCRTCCode.SUCCESS)return;if(!this.isPub)return;const I=(null===(c=g.data)||void 0===c?void 0:c.publishList)||[],{plus:E,minus:S}=this._diffPublishListChange(I);(E.length||S.length)&&(yield this._spreadPublishListUri(E,S,i))}))}_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,o=r.findIndex((e=>{const{mediaType:r,msid:o}=e;return t===r&&i===o}));if(-1===o){const t=Object.assign({tag:i.split("_").pop(),state:this._store.getTrackState(it(e))},e);r.push(t)}else r[o].uri=e.uri})):r=e.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:this._store.getTrackState(it(e))},e)));const{publishedList:o,unpublishedList:n}=st(t,r,!0);return this._store.setResourcesByUserId(this._userId,r),{plus:o,minus:n}}_spreadPublishListUri(e,r,s){var a,d,c;return i(this,void 0,void 0,(function*(){const i=this._store.getResourcesByUserId(this._userId);null===(a=this._store.context.logger)||void 0===a||a.info(o.L_RETRY_EXCHANGE_SPREAD_T,JSON.stringify({plus:e,minus:r,allPublishList:i,pcName:this.pcName}),s);const _=[];r.length&&_.push(Ye(It.UNPUBLISH,r)),e.length&&_.push(Ye(It.PUBLISH,e));(yield this._store.context.setRTCTotalRes(this._store.roomId,_,ze(i),It.TOTAL_CONTENT_RESOURCE))===t.ErrorCode.SUCCESS?null===(d=this._store.context.logger)||void 0===d||d.info(o.L_RETRY_EXCHANGE_SPREAD_R,`status: ${n.SUCCESSED}`,s):null===(c=this._store.context.logger)||void 0===c||c.error(o.L_RETRY_EXCHANGE_SPREAD_R,`status: ${n.FAILED}`,s)}))}}class Rs extends Fn{constructor(e,t,i,r,o=3e4,n,s){super(),this.subhook=e,this.callbacks=t,this._retryHook=i,this._pubhook=r,this._signalRetryTime=o,this._pullRTCRoomStatus=n,this.livingType=s}get kind(){return Rn.ON_SIGNAL_RECONNECTED}get priority(){return Cn.HIGH}execute(e,r){var s,a,d,c,_,l;return i(this,void 0,void 0,(function*(){const{roomId:i,roomMode:u}=e;this._roomId=i,this._roomMode=u;const h=null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();null===(c=null===(d=e.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_ABSTRACT_ROOM_IM_RECONNECTED_T,void 0,h);if(e.peerMgr.getPCList().some((e=>"closed"===e.getRTCPeerConn().connectionState)))return null===(l=null===(_=e.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:n.FAILED,msg:"RTCPeerConnection closed. Please rejoin room to restore services"}),h),void(this.callbacks.onPeerClosed&&this.callbacks.onPeerClosed());const{code:R}=yield e.context.rtcPing(i,u);if(40001===R){(yield this._joinRoom(e,h,r))===t.ErrorCode.SUCCESS&&(yield this._restoreMediaServer(e,r))}else yield this._pullRTCRoomStatus(this._roomId,h).execute(e,r)}))}_joinRoom(e,r,s){var a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const{code:i,data:R}=yield e.context.joinRTCRoom(this._roomId,this._roomMode,this.livingType);if(i!==t.ErrorCode.SUCCESS)return void(null===(d=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:n.FAILED,code:i,msg:"im reconnect joinRTCRoom failed"}),r));if(!R)return void(null===(_=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:n.FAILED,msg:"im reconnect joinRTCRoom, roomData is empty"}),r));const v=null===(l=R.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===l?void 0:l.value;return yield is(R,e,this.callbacks,s,this.subhook,v,r),null===(h=null===(u=e.context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:n.SUCCESSED,roomData:R}),r),i}))}_restoreMediaServer(e,t){return i(this,void 0,void 0,(function*(){const{useMutilPeerC:i}=e.peerMgr,r=e.getLocalTracks(),o=Object.values(e.getRemoteTracks()).filter((e=>!!e.isSubscribed()));if(i)return o.length&&(yield new cs(o,this.subhook,!0).execute(e,t)),void(r.length&&(yield new _s(r,this._pubhook,this._signalRetryTime).execute(e,t)));r.length&&(yield new _s(r,this._pubhook,this._signalRetryTime).execute(e,t)),!r.length&&o.length&&(yield new cs(o,this.subhook,!0).execute(e,t))}))}}class vs extends Jn{constructor(e,t,i,r=vn.NORMAL,o){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=o,this._logger=null,this._logger=Le.getLogger()}get kind(){return Rn.ASYNC_COMMAND}execute(t,r){var o,n,s;return i(this,void 0,void 0,(function*(){const{tracks:i}=this;if(this.state===vn.NORMAL){const e=t.getSubscribedList().slice(),{code:n,failedList:s}=yield new Yn(i,this.subhook,!0,this.traceId).execute(t,r),a=t.getSubscribedList().slice(),{subscribe:d,unsubscribe:c}=this.pickoutSubscribed(a,e);return null===(o=this.callbacks)||void 0===o||o.onTaskCompleted({code:n,subscribe:d,unsubscribe:c,failedList:s}),{code:n,failedList:s}}if(this.state===vn.TAIL){const{code:i}=yield new vs(this.tracks,this.subhook,this.callbacks,vn.MIDDLE,this.traceId).execute(t,r);if(i===e.RCRTCCode.SUCCESS){const i=t.getCollectSubscribeList().slice(0),o=t.getSubscribedList().slice(),{code:a,failedList:d}=yield new Yn(i,this.subhook,!0).execute(t,r);if(a!==e.RCRTCCode.SUCCESS)return null===(n=this.callbacks)||void 0===n||n.onTaskCompleted({code:a,subscribe:[],unsubscribe:[],failedList:d}),{code:a,failedList:d};const c=t.getSubscribedList().slice(0),{subscribe:_,unsubscribe:l}=this.pickoutSubscribed(c,o);return null===(s=this.callbacks)||void 0===s||s.onTaskCompleted({code:a,subscribe:_,unsubscribe:l,failedList:d}),{code:a,failedList:d}}return{code:i}}return Jn.AsyncUpdateSubscribeTasks.splice(Jn.AsyncUpdateSubscribeTasks.length,0,...this.tracks),new Promise((r=>{const o=this.formateTrack(i);t.resetCollectSubscribeList(o),r({code:e.RCRTCCode.SUCCESS})}))}))}}class Cs extends Jn{constructor(e,t,i,r=vn.NORMAL,o){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=o}get kind(){return Rn.ASYNC_COMMAND}execute(r,s){var a,d,c,_,l;return i(this,void 0,void 0,(function*(){const{tracks:i}=this;if(this.state===vn.NORMAL){const e=r.getSubscribedList().slice(),{code:t,failedList:o}=yield new cs(i,this.subhook,!1,this.traceId).execute(r,s),n=r.getSubscribedList().slice(),{subscribe:d,unsubscribe:c}=this.pickoutSubscribed(n,e);return null===(a=this.callbacks)||void 0===a||a.onTaskCompleted({code:t,subscribe:d,unsubscribe:c,failedList:o}),{code:t,failedList:o}}if(null===(c=null===(d=r.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_ABSTRACT_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:i.map(mt)}),this.traceId),!t.validate("tracks",i,(()=>t.isArray(i)&&i.length>0&&i.every((e=>e instanceof $e||e.track instanceof $e))),!0))return null===(l=null===(_=r.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};const u=this.getSubscribedList(r).map((e=>Object.assign({},e))),h=i.map((e=>e instanceof $e?{track:e}:e)),R=[];if(h.forEach((e=>{const t=e.track.getTrackId();R.push(t);const i=u.find((e=>e.track.getTrackId()===t));if(i){if(i.subTiny===e.subTiny)return;i.subTiny=e.subTiny}else u.push(e)})),r.polarisReport.sendR2(Tn.SUBSCRIBE,In.BEGIN,R),this.state===vn.TAIL){const{code:t}=yield new Cs(this.tracks,this.subhook,this.callbacks,vn.MIDDLE,this.traceId).execute(r,s);if(t===e.RCRTCCode.SUCCESS){const e=r.getCollectSubscribeList().slice(0);return new vs(e,this.subhook,this.callbacks,vn.NORMAL,this.traceId).execute(r,s)}return{code:t}}return Jn.AsyncSubscribeTasks.splice(Jn.AsyncSubscribeTasks.length,0,...this.tracks),new Promise((t=>{r.resetCollectSubscribeList(u),t({code:e.RCRTCCode.SUCCESS})}))}))}getSubscribedList(e){return this.state===vn.MIDDLE?e.getCollectSubscribeList():e.getSubscribedList()}}class ps extends Jn{constructor(e,t,i,r=vn.NORMAL,o){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=o}get kind(){return Rn.ASYNC_COMMAND}execute(r,s){var a,d,c,_,l;return i(this,void 0,void 0,(function*(){const{tracks:i}=this;if(this.state===vn.NORMAL){const e=r.getSubscribedList().slice(),{code:t,failedList:o}=yield new zn(i,this.subhook,this.traceId).execute(r,s),n=r.getSubscribedList().slice(),{subscribe:d,unsubscribe:c}=this.pickoutSubscribed(n,e);return null===(a=this.callbacks)||void 0===a||a.onTaskCompleted({code:t,subscribe:d,unsubscribe:c,failedList:o}),{code:t,failedList:o}}if(null===(c=null===(d=r.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_ABSTRACT_ROOM_UNSUBSCRIBE_T,JSON.stringify({trackIds:i.map(mt)}),this.traceId),!t.validate("tracks",i,(()=>t.isArray(i)&&i.length>0&&i.every((e=>e instanceof $e))),!0))return null===(l=null===(_=r.context)||void 0===_?void 0:_.logger)||void 0===l||l.warn(o.L_ABSTRACT_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};const u=this.getSubscribedList(r).map((e=>Object.assign({},e))).filter((e=>!i.includes(e.track)));if(r.polarisReport.sendR2(Tn.SUBSCRIBE,In.END,i.map((e=>e.getTrackId()))),this.state===vn.TAIL){const{code:t}=yield new ps(this.tracks,this.subhook,this.callbacks,vn.MIDDLE,this.traceId).execute(r,s);if(t===e.RCRTCCode.SUCCESS){const e=r.getCollectSubscribeList().slice(0).map((e=>e.track));return new vs(e,this.subhook,this.callbacks,vn.NORMAL,this.traceId).execute(r,s)}return{code:t}}return Jn.AsyncUnsubscribeTasks.splice(Jn.AsyncUnsubscribeTasks.length,0,...this.tracks),new Promise((t=>{r.resetCollectSubscribeList(u),t({code:e.RCRTCCode.SUCCESS})}))}))}getSubscribedList(e){return this.state===vn.MIDDLE?e.getCollectSubscribeList():e.getSubscribedList()}}var gs;!function(e){e[e.JOIN=0]="JOIN",e[e.LEAVE=1]="LEAVE",e[e.OFFLINE=2]="OFFLINE",e[e.RESOURCECHANGE=3]="RESOURCECHANGE"}(gs||(gs={}));class ms extends Fn{constructor(e,t,i,r,o,n,s){super(),this._roomId=e,this._traceId=t,this._context=i,this._callbacks=r,this._subhook=o,this._dealUserAppListener=n,this._targetPullVersion=s}get kind(){return Rn.PULL_RTCROOM_STATUS}execute(e,r){var s,a,d,c;return i(this,void 0,void 0,(function*(){const i=e.getRoomStatusVersion();if(null===(s=this._context.logger)||void 0===s||s.info(o.L_PULL_ROOM_STATUS_T,JSON.stringify({roomId:this._roomId,localVersion:i}),this._traceId),this._targetPullVersion&&this._targetPullVersion<=i)return null===(a=this._context.logger)||void 0===a||a.info(o.L_PULL_ROOM_STATUS_R,JSON.stringify({status:n.SUCCESSED,msg:"the roomData has been pulled",localVersion:i,targetPullVersion:this._targetPullVersion}),this._traceId),{code:t.ErrorCode.SUCCESS};const{code:_,data:l}=yield this._context.pullRTCRoomStatus(this._roomId,i);if(_!==t.ErrorCode.SUCCESS)return null===(d=this._context.logger)||void 0===d||d.info(o.L_PULL_ROOM_STATUS_R,JSON.stringify({status:n.FAILED,code:_}),this._traceId),{code:_};const{bFullStatus:u,version:h,usersData:R,roomStatus:v}=l;if(null===(c=this._context.logger)||void 0===c||c.info(o.L_PULL_ROOM_STATUS_R,JSON.stringify({bFullStatus:u,version:Tt(h),usersData:R,roomStatus:v}),this._traceId),e.setRoomStatusVersion(h),u){const{urisData:t,CDNUris:i}=function(e){const t={users:{}};let i="";return e.forEach((e=>{var r,o;const{userId:n,userData:s}=e;t.users[n]={};const a=null===(r=s.filter((e=>"uris"===e.key))[0])||void 0===r?void 0:r.value,d=null===(o=s.filter((e=>"cdn_uris"===e.key))[0])||void 0===o?void 0:o.value;i=d||i,t.users[n]={uris:a}})),{urisData:t,CDNUris:i&&JSON.stringify(JSON.parse(i)[0])}}(R);return yield is(t,e,this._callbacks,r,this._subhook,i,this._traceId),{code:_}}for(let t=0;t<v.length;t++){const i=v[t];if(i.event===gs.RESOURCECHANGE){const t=ns(i);if(!t)continue;const{content:o,userId:n}=t;if(n===e.crtUserId)continue;yield new ds(o,It.TOTAL_CONTENT_RESOURCE,n,this._subhook.bind(this),this._callbacks,this._traceId).execute(e,r)}else{const t=os(i),o=yield new as(t,this._subhook.bind(this),this._traceId).execute(e,r);this._dealUserAppListener(o)}}return{code:_}}))}}const Ts="evt-leave";class Is extends t.EventEmitter{constructor(e,t,r,n,s,a,d,c,_,l=Oo(),u=3e4){super(),this._context=e,this._runtime=t,this._roomId=r,this._service=s,this._initOptions=a,this._useMutilPeerC=_,this._clientSessionId=l,this.signalRetryTime=u,this._appListener=null,this._reportListener=null,this._onRecvPKMsg=null,this._polarisReport=new wn(this._context,this._runtime,this._roomId,this),this._peerCManager=new Vn(this._useMutilPeerC,this._roomId,this._reTryExchange.bind(this),this._context.getCurrentId(),this._polarisReport,!1,a),this._invoker=new jn(this._context,this._service,this._peerCManager,r,this._context.getCurrentId(),n,this._polarisReport,d,c),this._store=this._invoker.store,this._peerCManager.setStore(this._store),this._context.registerRTCSignalListener((e=>i(this,void 0,void 0,(function*(){var t,i,r,n,s,a;const{time:d,type:c,roomId:_}=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(o.L_RTCNTF_PULL_ROOM_STATUS_O,JSON.stringify({isDestroyed:!0,type:c,time:d,roomId:_}));else if(2===c){if(_!==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===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_RTCNTF_PULL_ROOM_STATUS_O,null,e),this._startPullRTCRoomStatus(_,e,d)}}))))}_pullRTCRoomStatus(e,t,i){return new ms(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,r){return i(this,void 0,void 0,(function*(){yield this._invoker.push(this._pullRTCRoomStatus(e,t,r))}))}__innerInit(t,r,o,n,s,a){return i(this,void 0,void 0,(function*(){const{code:i,data:d}=yield this._invoker.push(new Wn(this._roomId,t,this._context,r,o,n,s,a));return i!==e.RCRTCCode.SUCCESS?{code:i}:(this._initWithRoomData(d.offlineKickTime),{code:i,data:d})}))}_initWithRoomData(e){var t;const i=this._invoker.store;this._pinger=new St(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,s,a,d;if(this._useMutilPeerC)return void(null===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.error(o.L_ABSTRACT_ROOM_SETBITRATE_O,"`RCAbstractRoom.setBitrate` is disabled, use `RCLocalTrack.setBitrate` instead."));null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.warn(o.L_ABSTRACT_ROOM_SETBITRATE_O,"`RCAbstractRoom.setBitrate` will be deprecated, use `RCLocalTrack.setBitrate` instead."),t.assert("max",e,(e=>t.isNumber(e)&&e>Math.max(i||1,200)),!0),t.assert("min",i,(i=>t.isNumber(i)&&i>=1&&(!t.isNumber(e)||i<e)),!0),t.assert("start",r,(r=>t.isNumber(r)&&r>i&&r<=e));this._peerCManager.getPCList().forEach((t=>{t.setBitrate(e,i,r)}))}_onTrackReady(t){var i,r,s,a;const d=t.streams[0].id,{track:c}=t.receiver,_=[d,"audio"===c.kind?e.RCMediaType.AUDIO_ONLY:e.RCMediaType.VIDEO_ONLY].join("_"),l=this._store.getRemoteTrack(_);l?(l.__innerSetMediaStreamTrack(c),null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onTrackReady",trackId:l.getTrackId()})),this._callAppListener("onTrackReady",l)):null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(o.L_ABSTRACT_ROOM_ONTRACKREADY_O,`cannot found remote track ${c.id}`)}_callAppListener(e,...t){var i,r,n;const s=null===(i=this._appListener)||void 0===i?void 0:i[e];if(s)try{s(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify(e))}}_onTrackUnpublish(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onTrackUnpublish",trackIds:null==e?void 0:e.map((e=>e.getTrackId()))})),this._callAppListener("onTrackUnpublish",e)}__parseInnerMessage(e,t){var i,r,s,a,d,c,_,l,u,h;const{targetId:R,conversationType:v}=e;if(R!==this._roomId)return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(o.L_ABSTRACT_ROOM_RECEIVE_MESSAGE_O,JSON.stringify({status:n.FAILED,message:`roomId is different, msg roomId-> ${R}, this._roomId-> ${this._roomId} `}),t),!0;null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_ABSTRACT_ROOM_RECEIVE_MESSAGE_O,`recv inner msg -> message: ${JSON.stringify(e)} | roomid: ${this._roomId}`,t);const{content:C}=e;switch(e.messageType){case It.KICK:this._kickoff(!0,C);break;case It.STATE:this._stateHandle(C,t);break;case It.MODIFY:case It.PUBLISH:case It.UNPUBLISH:case It.TOTAL_CONTENT_RESOURCE:((e,t,i,r,n)=>{var s;const a=Do.getMemo();if(!a.isReportRecvPubMsg){a.isReportRecvPubMsg=!0;const d=Date.now(),c={dur:d-r,puid:n,rid:e,csnid:(null===(s=a.clientData)||void 0===s?void 0:s.clientSessionId)||"",snid:t,time:d,cr:"unknown",net:"unknown",uid:i},_=JSON.stringify(c);Ne.__statistics(o.L_QS_RECV_PUB_MSG_S,_)}})(this._roomId,this.getSessionId(),this.getCrtUserId(),e.sentTime,e.senderUserId),this._resourceHandle(C,e.messageType,e.senderUserId,t);break;case It.ROOM_NOTIFY:null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onRoomAttributeChange",messageType:e.messageType,messageContent:e.content})),this._callAppListener("onRoomAttributeChange",e.messageType,e.content);break;case It.USER_NOTIFY:null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.warn(o.L_OLD_DAILY_RECORD_O,`TODO: ${It.USER_NOTIFY}`);break;case It.PK_INVITE:case It.PK_CANCEL_INVITE:case It.PK_INVITE_TIMEOUT:case It.PK_INVITE_ANSWER:case It.PK_END:this._onRecvPKMsg&&this._onRecvPKMsg(e);break;case It.OTHER_ROOM_OFFLINE:break;default:null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onMessageReceive",messageType:e.messageType,messageContent:e.content,senderUserId:e.senderUserId,messageUId:e.messageUId})),this._callAppListener("onMessageReceive",e.messageType,C,e.senderUserId,e.messageUId)}return!0}_kickoff(e,t){var r,s,a,d;return i(this,void 0,void 0,(function*(){if(this._invoker.isDestroyed())return;let i,c;null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s||s.warn(o.L_ABSTRACT_ROOM_ONKICKOFF_O,`onKickOff -> byServer: ${e}, kickContent: ${JSON.stringify(t)}`),this.emit(Ts),this._leaveHandle(!e),e&&(((null==t?void 0:t.users)||[]).forEach((e=>{e.userId===this._context.getCurrentId()&&(c=e.type,i=e.kickExtra)})),((e=1,t,i,r,n)=>{const s=Date.now(),a={cod:ko[String(e)],rid:t,csnid:i,snid:r,time:s,cr:"unknown",net:"unknown",uid:n},d=JSON.stringify(a);Ne.__statistics(o.L_QS_KICKED_S,d)})(c,this._roomId,this.getClientSessionId(),this.getSessionId(),this.getCrtUserId())),null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onKickOff",byServer:e,kickType:c,kickExtra:i})),this._callAppListener("onKickOff",e,c,i)}))}_rtcpeerClosed(){var e,t;this.emit(Ts),this._leaveHandle(!0),null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onRTCPeerConnectionCloseByException"})),this._callAppListener("onRTCPeerConnectionCloseByException")}_resourceHandle(e,t,r,o){return i(this,void 0,void 0,(function*(){const{uris:i,ignore:n}=e;!n&&i&&this._invoker.push(new ds(e,t,r,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")},o))}))}_onTrackPublish(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onTrackPublish",trackIds:null==e?void 0:e.map((e=>e.getTrackId()))})),this._callAppListener("onTrackPublish",e)}_stateHandle(e,t){return i(this,void 0,void 0,(function*(){const i=yield this._invoker.push(new as(e,this._subhook.bind(this),t));this._dealUserAppListener(i)}))}_dealUserAppListener(t){var i,r,s,a,d,c,_,l,u;const{left:h,joined:R,upgrade:v,downgrade:C}=t;if(null===(i=this._appListener)||void 0===i?void 0:i.onSwitchRole)return null==v||v.forEach((t=>{var i,r;null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onSwitchRole",userId:t,role:e.RCRTCLiveRole.ANCHOR})),this._callAppListener("onSwitchRole",t,e.RCRTCLiveRole.ANCHOR)})),null==C||C.forEach((t=>{var i,r;null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onSwitchRole",userId:t,role:e.RCRTCLiveRole.AUDIENCE})),this._callAppListener("onSwitchRole",t,e.RCRTCLiveRole.AUDIENCE)})),R.length>0&&(null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserJoin",joined:R})),this._callAppListener("onUserJoin",R)),void(h.length>0&&(null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserLeave",left:h})),this._callAppListener("onUserLeave",h)));const p=[...R,...v],g=[...h,...C];p.length>0&&(null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserJoin",allJoined:p})),this._callAppListener("onUserJoin",p)),g.length>0&&(g.length&&(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserLeave",allLeft:g}))),this._callAppListener("onUserLeave",g))}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(r,s){var a,d,c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d?void 0:d.createTraceId();null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_SEND_MESSAGE_T,JSON.stringify({name:r,content:s}),i);const{code:v}=yield this._context.sendMessage(t.ConversationType.RTC_ROOM,this._roomId,{messageType:r,content:s,isStatusMessage:!0});return v!==t.ErrorCode.SUCCESS?(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_ABSTRACT_ROOM_SEND_MESSAGE_R,JSON.stringify({status:n.FAILED,code:v}),i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_ABSTRACT_ROOM_SEND_MESSAGE_R,JSON.stringify({status:n.SUCCESSED,name:r,content:s}),i),{code:e.RCRTCCode.SUCCESS})}))}setRoomAttribute(r,s,a,d=!1){var c,_,l,u,h,R,v,C;return i(this,void 0,void 0,(function*(){const i=null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_?void 0:_.createTraceId();null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,key:r,value:s,message:a,isInner:d}),i);const p=yield this._context.setRTCData(this._roomId,r,s,d,mn.ROOM,a);return p!==t.ErrorCode.SUCCESS?(null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_R,JSON.stringify({status:n.FAILED,code:p}),i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.info(o.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_R,JSON.stringify({status:n.SUCCESSED,roomId:this._roomId,key:r,value:s,message:a,isInner:d}),i),{code:e.RCRTCCode.SUCCESS})}))}deleteRoomAttributes(r,s,a=!1){var d,c,_,l,u,h,R,v;return i(this,void 0,void 0,(function*(){const i=null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c?void 0:c.createTraceId();null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,keys:r,message:s,isInner:a}),i);const C=yield this._context.removeRTCData(this._roomId,r,a,mn.ROOM,s);return C!==t.ErrorCode.SUCCESS?(null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:n.FAILED,code:C}),i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.info(o.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:n.SUCCESSED,roomId:this._roomId,keys:r,message:s,isInner:a}),i),{code:e.RCRTCCode.SUCCESS})}))}getRoomAttributes(r=[],s=!1){var a,d,c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d?void 0:d.createTraceId();null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,keys:r,isInner:s}),i);const{code:v,data:C}=yield this._context.getRTCData(this._roomId,r,s,mn.ROOM);return v!==t.ErrorCode.SUCCESS?(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_R,`GetRoomAttributes Failed: ${v}`,i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:n.SUCCESSED,data:C}),i),{code:e.RCRTCCode.SUCCESS,data:C})}))}_setUserAttributeValue(e,t,i){return this._context.setRTCData(this._roomId,e,t,!1,mn.PERSON,i)}_deleteUserAttributes(e,t){return this._context.removeRTCData(this._roomId,e,!1,mn.PERSON,t)}_getUserAttributes(e){return this._context.getRTCData(this._roomId,e,!1,mn.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 i(this,void 0,void 0,(function*(){if(this._invoker.isDestroyed())return;Do.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(xe.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(xe.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this)})),this._peerCManager.clear(),this._peerCManager=null}_onLocalTrackDestroied(e){e instanceof Be&&e.__isTiny()||this.unpublish([e])}_onLocalTrackMuted(e,t){return i(this,void 0,void 0,(function*(){this._invoker.push(new us(e,t))}))}publish(e){return i(this,void 0,void 0,(function*(){return this._invoker.push(new _s(e,this._pubhook.bind(this),this.signalRetryTime))}))}_getPushOtherRoomsParams(){return[]}_reTryExchange(e,t){return i(this,void 0,void 0,(function*(){this._invoker.push(new hs(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 i(this,void 0,void 0,(function*(){return this._invoker.push(new ls(e,((e,t)=>({pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(t)}))))}))}_getResourceById(e){return this._store.getPublishedResourceByTrackId(e)}_isValidResourceId(e){var t;const{userId:i}=rt(e);return!!(null===(t=this._store.getResourcesByUserId(i))||void 0===t?void 0:t.find((t=>it(t)===e)))}_subhook(e){const{pc:t,pcName:i}=this._peerCManager.createPeerCList(e)[0];return t.on(Mn.__INNER_EVENT_TRACK_READY__,this._onTrackReady,this),this._audioLevelReport&&t.on(Mn.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport),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(xe.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),t.on(xe.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),this._audioLevelReport&&t.on(Mn.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport),t.registerReportListener(this._reportListener),t.__reportR3R4ToPolaris(),Object.assign(Object.assign({},e),{headers:this._getRTCReqestHeaders(i)})})),pushOtherRooms:this._getPushOtherRoomsParams()}}subscribe(e){return i(this,void 0,void 0,(function*(){return this._invoker.push(new cs(e,this._subhook.bind(this)))}))}addSubscribeTask(e){var t;const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();this._invoker.push(new Cs(e,this._subhook.bind(this),{onTaskCompleted:this._onTaskCompleted.bind(this)},vn.NORMAL,i))}unsubscribe(e){var t,r;return i(this,void 0,void 0,(function*(){const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();return null===(r=this._context.logger)||void 0===r||r.info(o.L_APP_CALL_UNSUBSCRIBE_O,void 0,i),this._invoker.push(new zn(e,this._subhook.bind(this),i))}))}addUnsubscribeTask(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)},vn.NORMAL,i))}updateSubList(e){var t,r;return i(this,void 0,void 0,(function*(){return this._invoker.push(new Yn(e,this._subhook.bind(this),!0,null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId()))}))}addUpdateSubscribeListTask(e){var t;const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();this._invoker.push(new vs(e,this._subhook.bind(this),{onTaskCompleted:this._onTaskCompleted.bind(this)},vn.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(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.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(o.L_ABSTRACT_ROOM_REGISTER_ROOM_EVENT_LISTENER_O,JSON.stringify({status:n.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(o.L_ABSTRACT_ROOM_REGISTER_REPORT_LISTENER_O,JSON.stringify({status:n.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(o.L_ABSTRACT_ROOM_AUDIO_LEVEL_O,JSON.stringify({status:n.SUCCESSED,handler:null==e?void 0:e.name,gap:t})),this._audioLevelReport=new Bn(this),this._audioLevelReport.onAudioLevelChange(e)}__onReconnected(e){return i(this,void 0,void 0,(function*(){return this._invoker.push(new Rs(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(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.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(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onVideoMuteChange",trackId:e.getTrackId()})),this._callAppListener("onVideoMuteChange",e)}_registerPKMsgListener(e){this._onRecvPKMsg=e}_quitAllPKRoom(){}getClientSessionId(){return this._clientSessionId}}class Es extends Fn{constructor(e,t){super(),this.data=e,this.cdnValues=t}get kind(){return Rn.MCUCONFIG_FLUSH}execute(t,r){var o,n,s,a;return i(this,void 0,void 0,(function*(){const i={"App-Key":t.context.getAppkey(),Token:t.getToken(),RoomId:t.roomId,UserId:t.context.getCurrentId(),SessionId:t.getSessionId()},{code:r,res:d}=yield t.service.setMcuConfig(i,this.data);if(r!==e.RCRTCCode.SUCCESS)return{code:r};d.pull_url&&t.setCDNUris(JSON.parse(d.pull_url));const c=this.cdnValues;return r===e.RCRTCCode.SUCCESS&&((null===(n=null===(o=c.output)||void 0===o?void 0:o.video.normal)||void 0===n?void 0:n.width)||(null===(a=null===(s=c.output)||void 0===s?void 0:s.video.normal)||void 0===a?void 0:a.fps))&&ts(t),{code:r,res:d}}))}}var Ss,fs,Os,Ls;e.BackgroundPictureFillMode=void 0,(Ss=e.BackgroundPictureFillMode||(e.BackgroundPictureFillMode={}))[Ss.CROP=1]="CROP",Ss[Ss.WHOLE=2]="WHOLE",e.MixLayoutMode=void 0,(fs=e.MixLayoutMode||(e.MixLayoutMode={}))[fs.CUSTOMIZE=1]="CUSTOMIZE",fs[fs.SUSPENSION=2]="SUSPENSION",fs[fs.ADAPTATION=3]="ADAPTATION",e.MixVideoRenderMode=void 0,(Os=e.MixVideoRenderMode||(e.MixVideoRenderMode={}))[Os.CROP=1]="CROP",Os[Os.WHOLE=2]="WHOLE",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"}(Ls||(Ls={}));const Ns=()=>({version:2,mode:e.MixLayoutMode.SUSPENSION});class As{constructor(e,t){this._invoker=e,this._isValidTrackId=t,this._values=Ns()}setHostVideoTrack(t){var i,r,s,a,d,c,_,l,u;if(!this._isValidTrackId(t))return null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,msg:`videoTrackId: ${t} is invalid`})),this;const{mediaType:h,tag:R,userId:v}=rt(t);return h!==e.RCMediaType.VIDEO_ONLY?(null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,msg:`kind of ${t} is not video`})),this):(this._values.host_stream_id=ot(v,R),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(o.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:n.SUCCESSED,videoTrackId:t})),this)}setMixLayoutMode(t){var i,r,s,a,d,c;return[e.MixLayoutMode.CUSTOMIZE,e.MixLayoutMode.SUSPENSION,e.MixLayoutMode.ADAPTATION].includes(t)?(this._values.mode=t,null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MCU_CONFIG_BUILDER_SET_MIX_LAYOUT_MODE_O,JSON.stringify({status:n.SUCCESSED,mode:t})),this):(null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_MIX_LAYOUT_MODE_O,JSON.stringify({status:n.SUCCESSED,msg:`mode: ${t} is invalid`})),this)}_addOutputValue(t,i,r="normal"){const o=this._values.output||(this._values.output={video:{normal:{width:640,height:480}}});if("cdn"===t)return void(o.cdn=i);if("audio"===t)return void(o.audio={bitrate:i});const{video:n}=o;if("normal"!==r&&"tiny"!==r)if("backgroundColor"!==r)if("exparams"!==r){if("backgroundPicture"===r){const t=n.backgroundPicture||(n.backgroundPicture={fillMode:e.BackgroundPictureFillMode.CROP,picture:[]});Object.assign(t,i)}}else n.exparams={renderMode:i};else n.backgroundColor=i;else{const e=n[r]||(n[r]={});Object.assign(e,i)}}setOutputVideoResolution(e){var t,i,r,s,a,d;if(!ct(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(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RESOLUTION_O,JSON.stringify({status:n.FAILED,msg:`params error -> resolution: ${e}`})),this;const{width:c,height:_}=dt(e);return this._addOutputValue("video",{width:c,height:_},"normal"),null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RESOLUTION_O,JSON.stringify({status:n.SUCCESSED,resolution:e})),this}setOutputVideoFPS(e){var t,i,r,s,a,d;if(!_t(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(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_FPS_O,JSON.stringify({status:n.FAILED,msg:`params error -> fps: ${e}`})),this;const c=lt(e);return this._addOutputValue("video",{fps:c},"normal"),null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_FPS_O,JSON.stringify({status:n.SUCCESSED,fps:e})),this}setOutputVideoBitrate(e){var i,r,s,a,d,c;return!t.isNumber(e)||e<=0?(null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_BITRATE_O,JSON.stringify({status:n.FAILED,msg:`params error -> bitrate: ${e}`})),this):(this._addOutputValue("video",{bitrate:e},"normal"),null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_BITRATE_O,JSON.stringify({status:n.SUCCESSED,bitrate:e})),this)}setOutputTinyVideoResolution(e){var t,i,r,s,a,d;if(!ct(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(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_RESOLUTION_O,JSON.stringify({status:n.FAILED,msg:`params error -> resolution: ${e}`})),this;const{width:c,height:_}=dt(e);return this._addOutputValue("video",{width:c,height:_},"tiny"),null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_RESOLUTION_O,JSON.stringify({status:n.SUCCESSED,resolution:e})),this}setOutputTinyVideoFPS(e){var t,i,r,s,a,d;if(!_t(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(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_FPS_O,JSON.stringify({status:n.FAILED,msg:`params error -> fps: ${e}`})),this;const c=lt(e);return this._addOutputValue("video",{fps:c},"tiny"),null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_FPS_O,JSON.stringify({status:n.SUCCESSED,fps:e})),this}setOutputTinyVideoBitrate(e){var i,r,s,a,d,c;return!t.isNumber(e)||e<=0?(null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_BITRATE_O,JSON.stringify({status:n.FAILED,msg:`params error -> bitrate: ${e}`})),this):(this._addOutputValue("video",{bitrate:e},"tiny"),null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_BITRATE_O,JSON.stringify({status:n.SUCCESSED,bitrate:e})),this)}setOutputVideoRenderMode(t){var i,r,s,a,d,c;return[e.MixVideoRenderMode.CROP,e.MixVideoRenderMode.WHOLE].includes(t)?(this._addOutputValue("video",t,"exparams"),null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RENDER_MODE_O,JSON.stringify({status:n.SUCCESSED,renderMode:t})),this):(null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RENDER_MODE_O,JSON.stringify({status:n.FAILED,msg:`params error -> renderMode: ${t}`})),this)}setOutputAudioBitrate(e){var i,r,s,a,d,c;return t.isNumber(e)&&e>0?(this._addOutputValue("audio",e),null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_AUDIO_BITRATE_O,JSON.stringify({status:n.SUCCESSED,bitrate:e})),this):(null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_AUDIO_BITRATE_O,JSON.stringify({status:n.FAILED,msg:`params error -> bitrate: ${e}`})),this)}setOutputBackgroundColor(e){var t,i,r,s,a,d;return/^0x[a-fA-F0-9]{6}$/.test(e)?(this._addOutputValue("video",e,"backgroundColor"),null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_COLOR_O,JSON.stringify({status:n.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(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_COLOR_O,JSON.stringify({status:n.FAILED,msg:`params error -> color: ${e}`})),this)}addOutputBackgroundPicture(e,i,r,s,a){var d,c,_,l,u,h,R,v,C,p,g,m;if(!t.isHttpUrl(e))return null===(_=null===(c=null===(d=this._invoker.store)||void 0===d?void 0:d.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.FAILED,msg:`params error -> uri: ${e}`})),this;if([i,r,s,a].some((e=>!t.isNumber(e)||e<0||e>1)))return null===(h=null===(u=null===(l=this._invoker.store)||void 0===l?void 0:l.context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.FAILED,msg:`params of (x, y, w, h) error -> x: ${i}, y: ${r}, w: ${s}, h: ${a}`})),this;const T=(null===(C=null===(v=null===(R=this._values.output)||void 0===R?void 0:R.video)||void 0===v?void 0:v.backgroundPicture)||void 0===C?void 0:C.picture)||[];return T.push({uri:e,w:s,h:a,x:i,y:r}),this._addOutputValue("video",{picture:T},"backgroundPicture"),null===(m=null===(g=null===(p=this._invoker.store)||void 0===p?void 0:p.context)||void 0===g?void 0:g.logger)||void 0===m||m.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.SUCCESSED,uri:e,x:i,y:r,w:s,h:a})),this}removeOutputBackgroundPicture(e){var i,r,s,a,d,c,_,l,u;if(!t.isHttpUrl(e))return null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_REMOVE_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.FAILED,msg:`params error -> uri: ${e}`})),this;let h=null===(c=null===(d=null===(a=this._values.output)||void 0===a?void 0:a.video)||void 0===d?void 0:d.backgroundPicture)||void 0===c?void 0:c.picture;return h&&(h=h.filter((t=>t.uri!==e)),this._addOutputValue("video",{pictures:h},"backgroundPicture")),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(o.L_MCU_CONFIG_BUILDER_REMOVE_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.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(o.L_MCU_CONFIG_BUILDER_CLEAR_OUTPUT_BACKGROUND_PICTURE_O),this}setOutputBackgroundPictureFillMode(t){var i,r,s,a,d,c;return[e.BackgroundPictureFillMode.CROP,e.BackgroundPictureFillMode.WHOLE].includes(t)?(this._addOutputValue("video",{fillMode:t},"backgroundPicture"),null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:n.SUCCESSED,fillMode:t})),this):(null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:n.FAILED,msg:`params error -> fillMode: ${t}`})),this)}addPublishStreamUrls(e){var i,r,s,a,d,c,_,l,u,h,R;const v=/^rtmp:\/\/.+/;if(!t.isArray(e)||0===e.length||e.some((e=>!v.test(e))))return null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:n.FAILED,msg:`params error -> urls: ${e.join(",")}`})),this;const C=(null===(d=null===(a=this._values.output)||void 0===a?void 0:a.cdn)||void 0===d?void 0:d.concat())||[];let p=!1;return e.forEach((e=>{C.some((t=>t.pushurl===e))||(p=!0,C.push({pushurl:e}))})),C.length>5?(null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:n.FAILED,msg:`params error -> publish stream urls no more than 5, length: ${e.length}`})),this):(p&&this._addOutputValue("cdn",C),null===(R=null===(h=null===(u=this._invoker.store)||void 0===u?void 0:u.context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_MCU_CONFIG_BUILDER_ADD_PUBLISH_STREAM_URLS_O,JSON.stringify({status:n.SUCCESSED,urls:e})),this)}removePublishStreamUrls(e){var i,r,s,a,d,c,_,l;const u=/^rtmp:\/\/.+/;if(!t.isArray(e)||0===e.length||e.some((e=>!u.test(e))))return null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_REMOVE_PUBLISH_STREAM_URLS_O,JSON.stringify({status:n.FAILED,msg:`params error -> urls: ${e.join(",")}`})),this;const h=(null===(d=null===(a=this._values.output)||void 0===a?void 0:a.cdn)||void 0===d?void 0:d.concat())||[];for(let t=h.length-1;t>=0;t-=1){const{pushurl:i}=h[t],r=e.indexOf(i);r>=0&&(e.splice(r,1),h.splice(t,1))}return this._addOutputValue("cdn",h),null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_MCU_CONFIG_BUILDER_REMOVE_PUBLISH_STREAM_URLS_O,JSON.stringify({status:n.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(o.L_MCU_CONFIG_BUILDER_CLEAR_PUBLISH_STREAM_URLS_O),this}addCustomizeLayoutVideo(i,r,s,a,d){var c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f,O,L;if(!t.notEmptyString(i)||!this._isValidTrackId(i))return null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${i}`})),this;if(!t.isNumber(r)||!t.isNumber(s))return null===(R=null===(h=null===(u=this._invoker.store)||void 0===u?void 0:u.context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`params x or y is error -> x: ${r}, y: ${s}`})),this;if([a,d].some((e=>!t.isNumber(e)||e<0)))return null===(p=null===(C=null===(v=this._invoker.store)||void 0===v?void 0:v.context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`params width or height error -> width: ${a}, height: ${d}`})),this;const{userId:N,tag:A,mediaType:y}=rt(i);if(y!==e.RCMediaType.VIDEO_ONLY)return null===(T=null===(m=null===(g=this._invoker.store)||void 0===g?void 0:g.context)||void 0===m?void 0:m.logger)||void 0===T||T.error(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`type of trackId: ${i} 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===d&&e.width===a&&e.stream_id===k&&e.user_id===N&&e.x===r&&e.y===s))?(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(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:"Duplicate configuration item place ignored"})),this):(b.push({user_id:N,stream_id:k,x:r,y:s,width:a,height:d}),null===(L=null===(O=null===(f=this._invoker.store)||void 0===f?void 0:f.context)||void 0===O?void 0:O.logger)||void 0===L||L.info(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.SUCCESSED,trackId:i,x:r,y:s,width:a,height:d})),this)}removeCustomizeLayoutVideo(t){var i,r,s,a,d,c,_,l,u;if(!this._isValidTrackId(t))return null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${t}`})),this;const{userId:h,tag:R,mediaType:v}=rt(t);if(v!==e.RCMediaType.VIDEO_ONLY)return null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`type of trackId: ${t} is not video`})),this;const C=ot(h,R),{input:p}=this._values;return(null==p?void 0:p.video)&&p.video.length>0&&(p.video=p.video.filter((e=>e.stream_id===C))),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(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.SUCCESSED,trackId:t})),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(o.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_LAYOUT_VIDEO_O),this}setCustomizeInputAudio(e){var t,i,r,s,a,d;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(o.L_MCU_CONFIG_BUILDER_SET_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.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}=rt(e);return{stream_id:ot(t,i),user_id:t}})),this._values.inputFilterMode=Ls.AUDIO_INPUT_VIDEO_ALL,null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.SUCCESSED,trackIds:e})),this}addCustomizeInputAudio(e){var t,i,r,s,a,d,c,_,l;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(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${e}`})),this;const u=this._values.input||(this._values.input={}),h=u.audio||(u.audio=[]),{userId:R,tag:v}=rt(e),C=ot(R,v);return h.some((e=>e.stream_id===C&&e.user_id===R))?(null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.warn(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.FAILED,msg:`trackId: ${e} is exist`})),this):(h.push({user_id:R,stream_id:C}),this._values.inputFilterMode=Ls.AUDIO_INPUT_VIDEO_ALL,null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.SUCCESSED,trackId:e})),this)}removeCustomizeInputAudio(e){var t,i,r,s,a,d,c,_,l;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(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${e}`})),this;const{input:u}=this._values;if(!(null==u?void 0:u.audio)||0===u.audio.length)return null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.FAILED,msg:`type of trackId: ${e} is not audio`})),this;const{userId:h,tag:R}=rt(e),v=ot(h,R);return u.audio=u.audio.filter((e=>h!==e.user_id||v!==e.stream_id)),null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.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=Ls.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(o.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_INPUT_AUDIO_O),this}addPictureWaterMark(e,i,r,s,a,d){var c,_,l,u,h,R,v,C,p,g,m,T;if(!this._isValidTrackId(e))return null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${e}`})),this;if(!t.isHttpUrl(i))return null===(R=null===(h=null===(u=this._invoker.store)||void 0===u?void 0:u.context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:n.FAILED,msg:`params error -> uri: ${i}`})),this;if([r,s,a,d].some((e=>!t.isNumber(e)||e<0||e>1)))return null===(p=null===(C=null===(v=this._invoker.store)||void 0===v?void 0:v.context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:n.FAILED,msg:`some attrs of (x, y, w, h) is invalid -> x: ${r}, y: ${s}, w: ${a}, h: ${d}`})),this;const{userId:I,tag:E}=rt(e),S=ot(I,E),f=this._values.waterMark||(this._values.waterMark={enable:"on",singleScreen:[]}),{singleScreen:O}=f,L=O.filter((e=>e.streamId===S))[0];return L?L.picture.push({uri:i,w:a,h:d,x:r,y:s}):O.push({streamId:S,picture:[{uri:i,w:a,h:d,x:r,y:s}]}),this._values.waterMark.singleScreen=O,null===(T=null===(m=null===(g=this._invoker.store)||void 0===g?void 0:g.context)||void 0===m?void 0:m.logger)||void 0===T||T.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.SUCCESSED,trackId:e,uri:i,x:r,y:s,w:a,h:d,singleScreen:O})),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(o.L_MCU_CONFIG_BUILDER_CLEAR_OUTPUT_BACKGROUND_PICTURE_O),this}removePictureWaterMark(e,i){var r,s,a,d,c,_;if(!t.notEmptyString(e)||!this._isValidTrackId(e))return null===(a=null===(s=null===(r=this._invoker.store)||void 0===r?void 0:r.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_MCU_CONFIG_BUILDER_REMOVE_SINGLE_WATER_MARK_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${e}`})),this;const{userId:l,tag:u}=rt(e),h=ot(l,u),R=this._values.waterMark||(this._values.waterMark={enable:"on",singleScreen:[]}),{singleScreen:v}=R;return v.forEach((e=>{e.streamId===h&&(e.picture=e.picture.filter((e=>e.uri!==i)))})),null===(_=null===(c=null===(d=this._invoker.store)||void 0===d?void 0:d.context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_MCU_CONFIG_BUILDER_REMOVE_SINGLE_WATER_MARK_O,JSON.stringify({status:n.SUCCESSED,trackId:e,uri:i})),this}reset(){var e,t,i;return this._values=Ns(),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(o.L_MCU_CONFIG_BUILDER_RESET_O),this}flush(e=!0){return i(this,void 0,void 0,(function*(){const t=JSON.parse(JSON.stringify(this._values)),{code:i}=yield this._invoker.push(new Es(t,this._values));return e&&(this._values=Ns()),{code:i}}))}__innerGetValues(){return JSON.parse(JSON.stringify(this._values))}}var ys,ks,Ds,bs;e.RCLivingType=void 0,(ys=e.RCLivingType||(e.RCLivingType={}))[ys.VIDEO=0]="VIDEO",ys[ys.AUDIO=1]="AUDIO",function(e){e[e.AUTOMATIC=0]="AUTOMATIC",e[e.MANUAL=1]="MANUAL"}(ks||(ks={}));class Us extends Fn{constructor(e,t,i,r){super(),this.roomId=e,this.hooks=t,this.roomPKHandler=i,this.traceId=r}_exchangeWithPushOtherRoom(t,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(!t.getLocalTracks().length)return void(null===(a=null===(s=t.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.SUCCESSED,msg:"have not published resource"}),this.traceId));const i=Object.values(t.peerMgr.getMutilPeerCData()),R=Object.keys(t.peerMgr.getMutilPeerCData());for(let s=0;s<i.length;s++){const{pc:a,isPub:v}=i[s],C=v&&t.useMutilPeerC?[]:t.getSubscribedList(),p=yield Qn(C,!1,a,t),{pushOtherRooms:g,headers:m}=this.hooks(R[s]);p.pushOtherRooms=g;const T=yield new qn(m,p,this.traceId,!0).execute(t,r);if(T.code!==e.RCRTCCode.SUCCESS)return void(null===(c=null===(d=t.context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.FAILED,code:T.code,pushOtherRooms:g}),this.traceId));const{sdp:I,resultCode:E}=T.data;if(E!==e.RCRTCCode.SUCCESS)return void(null===(l=null===(_=t.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.FAILED,code:E,pushOtherRooms:g}),this.traceId));null===(h=null===(u=t.context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.SUCCESSED,pushOtherRooms:g}),this.traceId),a.setRemoteAnswer(I.sdp)}}))}get kind(){return Rn.EXCHANGE_WITH_PUSH_OTHER_ROOM}execute(e,t){var r,s,a,d,c,_;return i(this,void 0,void 0,(function*(){const{roomId:i}=this;if(null===(s=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_EXCHANGE_WITH_PUSHOTHERROOM_T,JSON.stringify({roomId:i})),!this.roomPKHandler)return void(null===(d=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.FAILED,msg:"_roomPKHandler not exist"}),this.traceId));this.roomPKHandler.getPKInfo(i)?yield this._exchangeWithPushOtherRoom(e,t):null===(_=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.FAILED,msg:"PKInfo not exist"}),this.traceId)}))}}class Ps extends Fn{constructor(e,t,i,r,o,n,s){super(),this.pkHandler=e,this.room=t,this._PKInfo=i,this.hooks=r,this._joinedPKRooms=o,this.isQuitPK=n,this.traceId=s}get kind(){return Rn.LEAVE_OTHER_ROOM}quitRoomPK(r,s,a){var d,c,_,l,u,h,R,v;return i(this,void 0,void 0,(function*(){if(null===(c=null===(d=null==s?void 0:s.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_QUIT_PK_T,`roomId: ${r}`,a),!this._PKInfo[r])return void(null===(l=null===(_=null==s?void 0:s.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_QUIT_PK_R,`status: ${n.FAILED}, msg: pkinfo is empty`,a));const{inviterRoomId:i,inviteeRoomId:C,inviterUserId:p,inviteSessionId:g}=this._PKInfo[r],m={inviteeRoomId:C,inviterRoomId:i,userId:s.crtUserId},T={roomId:s.roomId,endRoomId:r,sessionId:g,content:JSON.stringify(m),keys:[`${i}|${p}`]},I=yield s.context.endRoomPK(T);return I!==t.ErrorCode.SUCCESS?(null===(h=null===(u=null==s?void 0:s.context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_QUIT_PK_R,`status: ${n.FAILED}, code: ${I}`,a),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(v=null===(R=null==s?void 0:s.context)||void 0===R?void 0:R.logger)||void 0===v||v.info(o.L_QUIT_PK_R,`status: ${n.SUCCESSED}`,a),delete this._PKInfo[r],{code:e.RCRTCCode.SUCCESS})}))}execute(t,r){var s,a,d,c;return i(this,void 0,void 0,(function*(){const{room:i,isQuitPK:_}=this,l=i.getRoomId();return null===(a=null===(s=t.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_LIVING_ROOM_LEAVE_PK_ROOM_T,JSON.stringify({roomId:l,isQuitPK:_}),this.traceId),yield i.__destroy(!0),delete this._joinedPKRooms[l],yield new Us(l,this.hooks,this.pkHandler,this.traceId).execute(t,r),_&&this.quitRoomPK(l,t,this.traceId),null===(c=null===(d=t.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_LIVING_ROOM_LEAVE_PK_ROOM_R,JSON.stringify({status:n.SUCCESSED}),this.traceId),{code:e.RCRTCCode.SUCCESS}}))}}class Ms{constructor(e,t,i,r,o,n,s,a,d,c,_){this._invoker=e,this._PKInfo=t,this._hooks=i,this._context=r,this._runtime=o,this._service=n,this._initOptions=s,this._mainLivingRoom=a,this._registerPKMsgListener=d,this._onJoinedPKRoom=c,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 s=null===(i=this._appListener)||void 0===i?void 0:i[e];if(s)try{s(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(o.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify(e))}}_onInvite(e){var t,i;const r=e.inviteInfo||{},{inviterRoomId:n,inviterUserId:s,extra:a}=r,d={inviterRoomId:n,inviterUserId:s,extra:a};this._PKInfo[n]=r,null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(o.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onRequestJoinOtherRoom",info:d})),this._callAppListener("onRequestJoinOtherRoom",d)}_onCancelInvite(e){var t,i;const{inviterRoomId:r,inviterUserId:n,extra:s}=e.inviteInfo||{},a={inviterRoomId:r,inviterUserId:n,extra:s};delete this._PKInfo[r],null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(o.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onCancelRequestOtherRoom",cancelInfo:a})),this._callAppListener("onCancelRequestOtherRoom",a)}_onInviteTimeout(e){}_onInviteAnswer(e){var t,i;const{answerCode:r,inviteContent:n}=e,{inviteSessionId:s,inviterUserId:a,inviterRoomId:d,inviteeUserId:c,inviterUserAutoMix:_,inviteeUserAutoMix:l,inviteeRoomId:u,extra:h}=n,R={agree:1===r,inviterRoomId:d,inviterUserId:a,inviteeRoomId:u,inviteeUserId:c,extra:h};this._PKInfo[u]=this._PKInfo[u]||{inviteSessionId:s,inviterRoomId:d,inviterUserId:a,inviterUserAutoMix:_,inviteeRoomId:u},this._PKInfo[u].inviteeUserAutoMix=l,null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(o.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onResponseJoinOtherRoom",answerInfo:R})),this._callAppListener("onResponseJoinOtherRoom",R)}createLeaveOtherRoomCommand(e,t,i){return new Ps(this,e,this._PKInfo,this._hooks,this._joinedPKRooms,t,i)}_onPKEnd(e){var t,r,n,s,a,d;return i(this,void 0,void 0,(function*(){const{inviteeRoomId:i,inviterRoomId:c,userId:_}=e.inviteInfo,l=c===this._mainRoomId?i:c,u={endRoomId:l,endUserId:_},h=this._joinedPKRooms[l],R=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.info(o.L_QUIT_PK_LEAVE_PK_ROOM_O,void 0,R),h&&(yield this._invoker.push(this.createLeaveOtherRoomCommand(h,!0,R))),delete this._PKInfo[l],null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onFinishOtherRoom",endInfo:u})),this._callAppListener("onFinishOtherRoom",u)}))}_onRecvPKMsg(e){const{targetId:t,content:i,messageType:r}=e;switch(r){case It.PK_INVITE:this._onInvite(i);break;case It.PK_CANCEL_INVITE:this._onCancelInvite(i);break;case It.PK_INVITE_TIMEOUT:this._onInviteTimeout(i);break;case It.PK_INVITE_ANSWER:this._onInviteAnswer(i);break;case It.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(o.L_LIVING_PK_HANDLER_REGISTER_ROOM_PK_EVENT_LISTENER_O,JSON.stringify({listener:e&&Object.keys(e)})),this._appListener=e}requestJoinOtherRoom(r,s,a){var d,c,_,l,u,h,R,v,C,p;return i(this,void 0,void 0,(function*(){const i=null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c?void 0:c.createTraceId();if(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_T,JSON.stringify({inviteeRoomId:r,inviteeUserId:s,options:a}),i),!t.validate("inviteeRoomId",r,t.notEmptyString,!0)||!t.validate("inviteeUserId",s,t.notEmptyString,!0))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> inviteeRoomId or inviteeUserId"}),i),{code:e.RCRTCCode.PARAMS_ERROR};const g=Oo(),m=!t.isBoolean(null==a?void 0:a.autoMix)||(null==a?void 0:a.autoMix),T={inviteSessionId:g,inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviterUserAutoMix:m,inviteeRoomId:r,inviteeUserId:s,inviteeTimeoutTime:this._inviteTimeout,extra:(null==a?void 0:a.extra)||""},I={roomId:this._mainRoomId,invitedRoomId:r,invitedUserId:s,inviteTimeout:this._inviteTimeout,inviteInfo:JSON.stringify(T),inviteSessionId:g},E=yield this._context.requestRoomPK(I);return E!==t.ErrorCode.SUCCESS?(null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:E}),i),{code:E}):(this._PKInfo[r]={inviteSessionId:g,inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviterUserAutoMix:m,inviteeRoomId:r},null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.info(o.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.SUCCESSED}),i),{code:e.RCRTCCode.SUCCESS})}))}cancelRequestJoinOtherRoom(r,s,a){var d,c,_,l,u,h,R,v,C,p,g,m;return i(this,void 0,void 0,(function*(){const i=null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c?void 0:c.createTraceId();if(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_T,JSON.stringify({inviteeRoomId:r,inviteeUserId:s,extra:a}),i),!t.validate("inviteeRoomId",r,t.notEmptyString,!0)||!t.validate("inviteeUserId",s,t.notEmptyString,!0))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> inviteeRoomId or inviteeUserId"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(!this._PKInfo[r])return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:`The request to connect with ${s} user in room ${r} is not initiated`}),i),{code:e.RCRTCCode.PARAMS_ERROR};const T={inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviteeRoomId:r,inviteeUserId:s,extra:a||""},I={roomId:this._mainRoomId,invitedRoomId:r,invitedUserId:s,inviteSessionId:this._PKInfo[r].inviteSessionId,inviteInfo:JSON.stringify(T)},E=yield this._context.cancelRoomPK(I);return E!==t.ErrorCode.SUCCESS?(null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:E}),i),{code:E}):(null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.info(o.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.SUCCESSED}),i),delete this._PKInfo[r],{code:e.RCRTCCode.SUCCESS})}))}responseJoinOtherRoom(r,s,a,d){var c,_,l,u,h,R,v,C,p,g,m,T;return i(this,void 0,void 0,(function*(){const i=null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_?void 0:_.createTraceId();if(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_T,JSON.stringify({inviterRoomId:r,inviterUserId:s,agree:a,options:d}),i),!t.validate("inviterRoomId",r,t.notEmptyString,!0)||!t.validate("inviterUserId",s,t.notEmptyString,!0))return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> inviterRoomId or inviterUserId"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(!this._PKInfo[r])return null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.error(o.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:`User ${s} in room ${r} did not send a request for connection`}),i),{code:e.RCRTCCode.PARAMS_ERROR};const{inviteSessionId:I,inviterUserAutoMix:E}=this._PKInfo[r],S=!t.isBoolean(null==d?void 0:d.autoMix)||(null==d?void 0:d.autoMix),f={inviteSessionId:I,inviterRoomId:r,inviterUserId:s,inviterUserAutoMix:E,inviteeRoomId:this._mainRoomId,inviteeUserId:this._context.getCurrentId(),inviteeUserAutoMix:S},O=Object.assign(f,{inviterUserAutoMix:E}),L=a?Object.assign(f,{MultiRoomKey:`${r}|${this._mainRoomId}`,MultiRoomValue:JSON.stringify(O)}):f;!t.isUndefined(null==d?void 0:d.extra)&&Object.assign(L,{extra:d.extra});const N={agree:a,roomId:this._mainRoomId,inviteSessionId:I,inviteRoomId:r,inviteUserId:s,content:JSON.stringify(L),key:`${r}|${this._mainRoomId}`,value:JSON.stringify(f)},A=yield this._context.responseRoomPK(N);return A!==t.ErrorCode.SUCCESS?(null===(g=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===g||g.error(o.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:A}),i),{code:A}):(null===(T=null===(m=this._context)||void 0===m?void 0:m.logger)||void 0===T||T.info(o.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.SUCCESSED}),i),this._PKInfo[r].inviteeUserAutoMix=S,{code:e.RCRTCCode.SUCCESS})}))}joinOtherRoom(r){var s,a,d,c,_,l,u,h,R,v,C,p,g,m;return i(this,void 0,void 0,(function*(){const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_T,JSON.stringify({roomId:r}),i),!t.validate("roomId",r,t.notEmptyString,!0))return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> roomId"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(this._context.getConnectionStatus()!==t.ConnectionStatus.CONNECTED)return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.SIGNAL_DISCONNECTED,msg:"IM disconnected"}),i),{code:e.RCRTCCode.SIGNAL_DISCONNECTED};if(this._joinedPKRooms[r])return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.warn(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const T=e.RCLivingType.VIDEO,I={extra:`{"roomId": "${this._mainRoomId}"}`},E=new Bs(this._context,this._runtime,r,this._service,this._initOptions,T,!1,!1,!1,this._clientSessionId),{code:S,data:f}=yield E.__innerInit(gn.LIVE,void 0,T,I);return S!==e.RCRTCCode.SUCCESS?(null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:S}),i),{code:S}):(this._joinedPKRooms[r]=E,yield this._onJoinedPKRoom(r,i),null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.info(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.SUCCESSED}),i),{room:E,code:e.RCRTCCode.SUCCESS,userIds:E.getRemoteUserIds(),tracks:E.getRemoteTracks()})}))}leaveOtherRoom(e,t){var r,n,s,a;return i(this,void 0,void 0,(function*(){const i=null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n?void 0:n.createTraceId();return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_APP_CALL_LEAVE_PK_ROOM_O,void 0,i),this._invoker.push(this.createLeaveOtherRoomCommand(e,t,i))}))}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"}(Ds||(Ds={}));class xs extends Fn{constructor(e,t){super(),this.cdnValues=e,this.enable=t}get kind(){return Rn.ENABLE_INNER_CDN}execute(r,s){var a,d,c,_,l,u,h,R,v,C,p,g,m,T;return i(this,void 0,void 0,(function*(){const{enable:i}=this;if(null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_LIVING_ROOM_ENABLE_INNER_CDN_T,JSON.stringify({roomId:r.roomId,enable:i})),!r.isMainRoom)return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM};if(!t.isBoolean(i))return null===(u=null===(l=r.context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> enable"})),{code:e.RCRTCCode.PARAMS_ERROR};r.setCDNEnabel(i);const I={version:2,output:{inCDNModel:i?Ds.OPEN:Ds.STOP}},{code:E}=yield new Es(I,this.cdnValues).execute(r,s);if(E!==e.RCRTCCode.SUCCESS)return null===(R=null===(h=r.context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.FAILED,code:E,msg:"signal error"})),{code:e.RCRTCCode.SIGNAL_ERROR};const S=r.getCDNUris();if(S&&S.broadcast!==En.SPREAD)return null===(C=null===(v=r.context)||void 0===v?void 0:v.logger)||void 0===C||C.info(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.SUCCESSED,enable:i})),{code:e.RCRTCCode.SUCCESS};const{code:f}=yield ts(r);return f===e.RCRTCCode.SUCCESS?(null===(g=null===(p=r.context)||void 0===p?void 0:p.logger)||void 0===g||g.info(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.SUCCESSED,enable:i})),{code:e.RCRTCCode.SUCCESS}):(null===(T=null===(m=r.context)||void 0===m?void 0:m.logger)||void 0===T||T.error(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.FAILED,code:f})),{code:f})}))}}!function(e){e[e.AnchorToViewer=1]="AnchorToViewer",e[e.ViewerToAnchor=2]="ViewerToAnchor"}(bs||(bs={}));class ws extends Fn{constructor(e,t){super(),this.livingType=e,this.traceId=t}get kind(){return Rn.RTC_IDENTITY_CHANGE}execute(e,r){var o;return i(this,void 0,void 0,(function*(){const{code:i,data:n}=yield e.context.rtcIdentityChange(e.roomId,bs.ViewerToAnchor,this.livingType);if(i!==t.ErrorCode.SUCCESS||!n)return{code:i};e.initWithRoomData(n,this.traceId);e.getResourcesByUserId(e.crtUserId).length>0&&r.push(new $n);const s=null===(o=n.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===o?void 0:o.value;return s&&e.setCDNUris(JSON.parse(s)[0]),{code:i,data:n}}))}}class Bs extends Is{constructor(e,t,i,r,o,n,s,a,d,c){super(e,t,i,gn.LIVE,r,o,s,a,d,c),this._livingType=n,this._mcuConfigBuilder=new As(this._invoker,this._isValidResourceId.bind(this))}_initAfterCatchRoomData(e,t){if(this._store.isUpgrade&&this._afterChangedRole(e,t),this._store.isMainRoom){const t=((e,t)=>{const i={};return t.forEach((t=>{const r=JSON.parse(t.value),{inviterRoomId:o,inviteeRoomId:n}=r;i[e===o?n:o]=JSON.parse(t.value)})),i})(this._roomId,e.roomInfo);this._roomPKHandler=new Ms(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(r,s,a,d,c,_){const l=Object.create(null,{__innerInit:{get:()=>super.__innerInit}});var u,h;return i(this,void 0,void 0,(function*(){if(!t.validate("livingType",a,(t=>t===e.RCLivingType.AUDIO||t===e.RCLivingType.VIDEO)))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> livingType"}),_),{code:e.RCRTCCode.PARAMS_ERROR};const{code:i,data:R}=yield l.__innerInit.call(this,r,s,a,d,c,_);return i===e.RCRTCCode.SUCCESS&&R&&this._initAfterCatchRoomData(R),{code:i,data:R}}))}__innerInitByIdentityChange(e){var r,s,a,d;return i(this,void 0,void 0,(function*(){const{code:i,data:c}=yield this._invoker.push(new ws(this._livingType,e));return i===t.ErrorCode.SUCCESS&&c?(this._initAfterCatchRoomData(c,e),this._initWithRoomData(c.offlineKickTime),null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:n.SUCCESSED,roomData:c}),e)):null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:n.FAILED,code:i}),e),i}))}publish(t){const r=Object.create(null,{publish:{get:()=>super.publish}});var s,a;return i(this,void 0,void 0,(function*(){return this._store.isMainRoom?r.publish.call(this,t):(null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}))}unpublish(t){const r=Object.create(null,{unpublish:{get:()=>super.unpublish}});var s,a;return i(this,void 0,void 0,(function*(){return this._store.isMainRoom?r.unpublish.call(this,t):(null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}))}_isValidResourceId(t){var i;const{userId:r}=rt(t),o=!!(null===(i=this._store.getResourcesByUserId(r))||void 0===i?void 0:i.find((e=>it(e)===t)));let n=!1;const{code:s,roomPKHandler:a}=this.getRoomPKHandler();if(s!==e.RCRTCCode.SUCCESS||!a)return o;const d=a.getJoinedPKRooms(),c=[];return Object.values(d).forEach((e=>{c.push(...e.getRemoteTracks())})),n=c.some((e=>t===e.getTrackId())),o||n}getLivingType(){return this._livingType}getMCUConfigBuilder(){var t,i;return this._store.isMainRoom?this._mcuConfigBuilder:(null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.error(o.L_LIVING_ROOM_GET_MCU_CONFIG_BUILDER_O,"the `getMCUConfigBuilder` is disabled in PK room"),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}enableInnerCDN(e){return i(this,void 0,void 0,(function*(){return this._invoker.push(new xs(this._mcuConfigBuilder.__innerGetValues(),e))}))}_resourceHandle(e,t,r,o){const n=Object.create(null,{_resourceHandle:{get:()=>super._resourceHandle}});return i(this,void 0,void 0,(function*(){n._resourceHandle.call(this,e,t,r,o)}))}_afterChangedRole(e,t){const i=pt(e,this._roomId,t),r=this._context.getCurrentId(),s=Object.keys(i);setTimeout((()=>{var a,d,c,_,l;const u=s.filter((e=>e!==r));u.length>0&&(null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserJoin",needNoticeUserIds:u})),this._callAppListener("onUserJoin",u));for(const e in i)e!==r&&this._resourceHandle({uris:i[e]},It.TOTAL_CONTENT_RESOURCE,e,t);if(!(null===(c=e.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===c?void 0:c.value))return;const h=this._store.getCDNUris();(null==h?void 0:h.push_mode)===ks.MANUAL&&(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserJoin",enableInnerCDN:null==h?void 0:h.enableInnerCDN})),this._callAppListener("onCDNEnableChange",null==h?void 0:h.enableInnerCDN))}))}__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 i(this,void 0,void 0,(function*(){this._invoker.push(new Us(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(),o=this._roomPKHandler.getPKInfo(i);if(!o)continue;const{inviterUserAutoMix:n,inviteeUserAutoMix:s,inviterUserId:a}=o,d=this._context.getCurrentId()===a;e.push({roomId:i,sessionId:r,autoMix:d?!!n:!!s})}return e}getRoomPKHandler(){var t,i,r,s;return this._store.isMainRoom?(null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_LIVING_ROOM_GET_ROOM_PK_HANDLER_O,JSON.stringify({status:n.SUCCESSED})),{code:e.RCRTCCode.SUCCESS,roomPKHandler:this._roomPKHandler}):(null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.error(o.L_LIVING_ROOM_GET_ROOM_PK_HANDLER_O,JSON.stringify({status:n.SUCCESSED,code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}_quitAllPKRoom(){var e,t;return i(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(o.L_LIVING_ROOM_QUIT_ALL_PK_ROOM_O,JSON.stringify({status:n.SUCCESSED,roomIds:Object.keys(i)}))}))}isMainRoom(){return this._store.isMainRoom}}class Vs extends Is{constructor(e,t,i,r,o,n,s,a,d,c=gn.RTC,_=3e4){super(e,t,i,c,r,o,n,s,a,d,_)}}const Fs=new class{constructor(){this.queue=[],this.locked=!1,this.taskCount=0}checkToStart(){return i(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}},Js=(e,t="")=>Fs.push(e,t);class Hs{constructor(e,t,i,r){this._context=e,this._useMutilPeerC=r,this._rtcToken="",this._liveUrl="",this._subTracks=[],this._subscribedList=[],this._clientSessionId=Oo(),this._livingType=null,this._mediaType=null,this._subTiny=!1,this._fromRetry=!1,this._appListener=null,this._crtUserId=this._context.getCurrentId(),this._service=new zo(t,e,i.mediaServer),this._peerCManager=new Vn(this._useMutilPeerC,this._crtUserId,this._reTryExchange.bind(this),this._crtUserId,void 0,!1,i,!0),this._store=new Gn(this._context,this._service,this._peerCManager,this._crtUserId,this._crtUserId),this._peerCManager.setStore(this._store)}_getReqHeaders(r){return i(this,void 0,void 0,(function*(){const i=this._crtUserId;if(!this._rtcToken){const{code:o,data:n}=yield this._context.getRTCToken(i,gn.LIVE,r);if(o!==t.ErrorCode.SUCCESS)return{code:e.RCRTCCode.SIGNAL_ERROR};this._rtcToken=n.rtcToken}const o=this._useMutilPeerC?{"Peer-Connection-Id":this._pcName}:{};return{code:e.RCRTCCode.SUCCESS,headers:Object.assign({"App-Key":this._context.getAppkey(),UserId:this._crtUserId,RoomId:i,RoomType:gn.LIVE,Token:this._rtcToken,"Client-Session-Id":this._clientSessionId},o)}}))}_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 t;return i(this,void 0,void 0,(function*(){this._fromRetry=!0;const{code:i}=yield this.subscribe(this._liveUrl,this._livingType,this._mediaType,this._subTiny);i===e.RCRTCCode.SUCCESS&&(null===(t=this._pc)||void 0===t||t.clearReTryExchangeTimer())}))}subscribe(e,t,r,o=!1){return i(this,void 0,void 0,(function*(){return Js((()=>this.__subscribe(e,t,r,o)),"audience-client-sub")}))}__subscribe(r,s,a,d=!1){var c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f,O,L,N,A,y,k,D;return i(this,void 0,void 0,(function*(){null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_AUDIENCE_CLIENT_SUBSCRIBE_T,JSON.stringify({liveUrl:r,livingType:s,mediaType:a,subTiny:d}));const i=[];if(Ct(this._context.getNaviInfo()))return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"})),{code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR,tracks:i};if(!this._fromRetry&&(null===(h=this._pc)||void 0===h||h.clearReTryExchangeTimer()),this._fromRetry=!1,!t.isString(r))return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:`params error -> liveUrl: ${r}`})),{code:e.RCRTCCode.PARAMS_ERROR,tracks:i};if(![e.RCLivingType.AUDIO,e.RCLivingType.VIDEO].includes(s))return null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(`livingType is invalid: ${s}`),null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:`params error -> livingType: ${s}`})),{code:e.RCRTCCode.PARAMS_ERROR,tracks:i};if(![e.RCMediaType.AUDIO_ONLY,e.RCMediaType.VIDEO_ONLY,e.RCMediaType.AUDIO_VIDEO].includes(a))return null===(I=null===(T=this._context)||void 0===T?void 0:T.logger)||void 0===I||I.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:`params error -> -> mediaType: ${a}`})),{code:e.RCRTCCode.PARAMS_ERROR,tracks:i};if(this._liveUrl&&this._liveUrl!==r)return null===(S=null===(E=this._context)||void 0===E?void 0:E.logger)||void 0===S||S.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.BROADCAST_SUB_LIST_NOT_EMPTY,msg:"repeat subscribe"})),{code:e.RCRTCCode.BROADCAST_SUB_LIST_NOT_EMPTY,tracks:i};if(!this._pc){const{pcName:e,pc:t}=this._peerCManager.createPeerCList(i)[0];this._pc=t,this._pcName=e,this._pc.on(Mn.__INNER_EVENT_TRACK_READY__,this._onTrackReady,this),this._pc.registerReportListener(this._reportListener),this._pc.__reportR3R4ToPolaris()}this._liveUrl=r;const{code:b,headers:U}=yield this._getReqHeaders(s);if(b!==e.RCRTCCode.SUCCESS)return null===(O=null===(f=this._context)||void 0===f?void 0:f.logger)||void 0===O||O.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:b,msg:"getRTCToken failed"})),{code:b,tracks:i};const P=`rc_mcu_${Date.now()}`,M="RongCloudRTC";0===this._subTracks.length&&(this._subTracks.push(new We(M,P),new qe(M,P)),this._pc.updateSubRemoteTracks(this._subTracks.slice()));const x={sdp:yield this._pc.createOffer(!0),liveUrl:r,mediaType:a,simulcast:d?Zo.TINY:Zo.NORMAL,switchstream:!1},w=yield this._service.broadcastSubscribe(U,x);if(w.code!==e.RCRTCCode.SUCCESS)return null===(N=null===(L=this._context)||void 0===L?void 0:L.logger)||void 0===N||N.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:w.code})),{code:w.code,tracks:i};const B=w.data;if(B.resultCode!==e.RCRTCCode.SUCCESS)return null===(y=null===(A=this._context)||void 0===A?void 0:A.logger)||void 0===y||y.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:B.resultCode,msg:B.message})),{code:B.resultCode,tracks:i};this._livingType=s,this._mediaType=a,this._subTiny=d;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(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.SUCCESSED,liveUrl:r})),{code:e.RCRTCCode.SUCCESS,tracks:J}}))}_updateTrackIdSSRCMap(e,t){t.forEach((t=>{const i=t.getTrackId(),{mediaType:r}=rt(i),{msid:o}=this._subscribedList.filter((e=>e.mediaType===r))[0],n=ss(e,o,r);this._store.setTrackIdSSRCMap(Number(n),i)}))}unsubscribe(){return i(this,void 0,void 0,(function*(){return Js((()=>this.__unsubscribe()),"audience-client-unsub")}))}__unsubscribe(){var t,r,s,a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){if(null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r||r.info(o.L_AUDIENCE_CLIENT_UNSUBSCRIBE_T,JSON.stringify({liveUrl:this._liveUrl})),null===(s=this._pc)||void 0===s||s.clearReTryExchangeTimer(),!this._rtcToken||!this._liveUrl)return null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.warn(o.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:"",msg:"Address does not exist, without unsubscribe"})),{code:e.RCRTCCode.SUCCESS};const{headers:i}=yield this._getReqHeaders(),{code:h}=yield this._service.broadcastExit(i);return h!==e.RCRTCCode.SUCCESS?null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:h})):(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:n.SUCCESSED,liveUrl:this._liveUrl})),this._subscribedList=[]),this._clearSubscribeInfo(),{code:h}}))}registerReportListener(e){this._reportListener=e}registerTrackEventListener(e){this._appListener=e}_onTrackReady(t){var i,r,n,s,a,d;const{track:c}=t.receiver,_="audio"===c.kind?e.RCMediaType.AUDIO_ONLY:e.RCMediaType.VIDEO_ONLY,l=this._subTracks[_];l.__innerSetMediaStreamTrack(c);try{null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(o.L_AUDIENCE_CLIENT_CALL_ONTRACKREADY_O,`trackId: ${l.getTrackId()}`),null===(s=null===(n=this._appListener)||void 0===n?void 0:n.onTrackReady)||void 0===s||s.call(n,l)}catch(e){null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_AUDIENCE_CLIENT_CALL_ONTRACKREADY_O,JSON.stringify(e))}}}var Gs,Ks;e.RCInnerCDNPullKind=void 0,(Gs=e.RCInnerCDNPullKind||(e.RCInnerCDNPullKind={})).RTMP="rtmp",Gs.FLV="flv",Gs.HLS="hls",e.RCInnerCDNPullIsHttps=void 0,(Ks=e.RCInnerCDNPullIsHttps||(e.RCInnerCDNPullIsHttps={}))[Ks.NOT_HTTPS=0]="NOT_HTTPS",Ks[Ks.HTTPS=1]="HTTPS";const js=Object.assign(Object.assign({},dt(e.RCResolution.W176_H144)),{frameRate:lt(e.RCFrameRate.FPS_15)});class $s{constructor(e,t,r,o,n,s,a,d=Oo()){this._context=e,this._runtime=t,this._initOptions=r,this._roomId=o,this._joinResData=n,this.livingType=s,this._useMutilPeerC=a,this._clientSessionId=d,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._reportListener=null,this._crtUserId=this._context.getCurrentId(),this._service=new zo(this._runtime,this._context,this._initOptions.mediaServer,this._initOptions.timeout),this._polarisReport=new wn(this._context,this._runtime,this._roomId,this,_n.Audience),this._polarisReport.sendR1(),this._peerCManager=new Vn(this._useMutilPeerC,this._roomId,this._reTryExchange.bind(this),this._crtUserId,this._polarisReport,!0,this._initOptions,!0),this._context.registerRTCSignalListener((e=>i(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 Gn(this._context,this._service,this._peerCManager,this._roomId,this._crtUserId,gn.LIVE,this._polarisReport),this._peerCManager.setStore(this._store),this._setInitData()}_startPull(e,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(this._isPulling)return;this._isPulling=!0;if(this._pullTime>r)return void(this._isPulling=!1);const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_T,`pullTime: ${this._pullTime}`,i);const{code:R,data:v}=yield this._context.pullRTCRoomEntry(e);if(R===t.ErrorCode.SUCCESS){this._isPulling=!1,this._pullTime=v.syncTime||0;const t=(null==v?void 0:v.kvEntries)||[];null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R,`status: ${n.SUCCESSED}, kvEntries: ${JSON.stringify(t)}`,i),this.singalDataChange(t,e,i)}null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R,`status: ${n.FAILED}, code: ${R}`,i)}))}_setInitData(){const{sessionId:e,remoteUserIds:t,remoteRTCUris:i,remoteMUCUris:r,remoteTracks:o,CDNUris:n}=gt(this._roomId,this._joinResData.kvEntries);this._sessionId=e,this._roomAnchorList=t,o.forEach((e=>{this._remoteTracks[e.getTrackId()]=e})),this._CDNUris=n,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:o}=JSON.parse(e.uri);this._store.setTrackIdSSRCMap(o,r)})),i.forEach((e=>{const t=it(e);this._roomRes[t]=e}))}_assertRoomDestroyed(){if(this._destroyed)return e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED}singalDataChange(e,t,i){var r,s,a;if(t!==this._roomId)return void(null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_AUDIENCE_LIVING_ROOM_SINGAL_DATA_CHANGE_P,JSON.stringify({status:n.FAILED,msg:`roomId inconsistency -> params roomId:${t}, current roomId:${this._roomId}`}),i));const d=[],c=null===(a=e.filter((e=>"RC_CDN"===e.key))[0])||void 0===a?void 0:a.value;c&&this._diffCDNUris(JSON.parse(JSON.parse(c).cdn_uris)[0],i),e.forEach((e=>{const{key:t,value:r,timestamp:o,uid:n}=e;if(-1!==t.indexOf("RC_RES_")){const e=JSON.parse(r||"{}"),t=JSON.parse(e.mcu_uris||"[]"),o=JSON.parse(e.uris||"[]");return d.push(...t),void this._diffAnchorResource(o,n,i)}if("RC_ANCHOR_LIST"===t){const e=JSON.parse(r||"[]"),{joinUserIds:t,leftUserIds:o}=this._diffAnchorList(e);t.length>0&&this._handleNewJoinedAnchor(t,i),o.length>0&&this._handleLeftedAnchor(o,i)}})),this._diffRoomResource(d,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(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorJoin",list:e}),t),this._callAppListener("onAnchorJoin",e)}_handleLeftedAnchor(e,t){var r,n;return i(this,void 0,void 0,(function*(){this._roomAnchorList=this._roomAnchorList.filter((t=>!(e.indexOf(t)>-1)));const i=[];e.forEach((e=>{i.push(...this.getRemoteTracksByUserId(e)),delete this._roomAnchorRes[e]})),i.length&&(yield this.unsubscribe(i),i.forEach((e=>delete this._remoteTracks[e.getTrackId()]))),null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorLeave",list:e}),t),this._callAppListener("onAnchorLeave",e)}))}_diffRoomResource(t,r){var n,s;return i(this,void 0,void 0,(function*(){const i=[],a=[],d=[];t.forEach((t=>{const r=it(t),{userId:o,tag:n,mediaType:s}=rt(r),a=[this._roomId,n,s].join("_"),{ssrc:c}=JSON.parse(t.uri);if(this._store.setTrackIdSSRCMap(c,a),!this._remoteTracks[a]){const r=s===e.RCMediaType.AUDIO_ONLY?new We(n,"",this._roomId):new qe(n,"",this._roomId);i.push(r),this._remoteTracks[a]=r,this._roomRes[r.getTrackId()]=t}d.push(a)})),Object.keys(this._remoteTracks).forEach((e=>{d.indexOf(e)<0&&this._remoteTracks[e].isMCUTrack()&&a.push(this._remoteTracks[e])})),i.length>0&&(null===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onTrackPublish",trackIds:i.map((e=>e.getTrackId()))}),r),this._callAppListener("onTrackPublish",i)),a.length>0&&this._onUserUnpublish(a,"onTrackUnpublish",r)}))}_diffAnchorResource(t,r,s){var a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){const i=this._roomAnchorRes[r]||(this._roomAnchorRes[r]=[]),{publishedList:h,unpublishedList:R,modifiedList:v}=st(i,t);if(h.length){const t=i.map(it),r=[],l=[];if(h.forEach((o=>{const n=it(o),s=t.indexOf(n),{userId:a,tag:d,mediaType:c}=rt(n);s>-1?i[s]=o:i.push(o);let _=this._remoteTracks[n];this._roomRes[n]=o,_?_.isSubscribed()&&r.push(_):(_=c===e.RCMediaType.AUDIO_ONLY?new We(d,a):new qe(d,a),this._remoteTracks[n]=_,l.push(_)),_.__innerSetRemoteMuted(0===o.state)})),r.length){const t=r.map((e=>e.getTrackId())),{code:i}=yield Js((()=>this._subscribeHandle(r,!0)));i!==e.RCRTCCode.SUCCESS&&(null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_RESUB_REPUB_RES_R,JSON.stringify({status:n.FAILED,trackIds:t,code:i})))}null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorTrackPublish",trackIds:l.map((e=>e.getTrackId()))}),s),this._callAppListener("onAnchorTrackPublish",l)}if(R.length){const e=R.map(it);for(let t=i.length-1;t>=0;t-=1){const r=i[t];e.includes(it(r))&&i.splice(t,1)}const t=R.map((e=>{const t=it(e);return this._remoteTracks[t]}));yield this._onUserUnpublish(t,"onAnchorTrackUnpublish",s)}if(v.length){const e=i.map(it);for(let t=0;t<v.length;t++){const r=v[t],n=it(r),a=e.indexOf(n);i[a].state=r.state;const d=this._remoteTracks[n];d.__innerSetRemoteMuted(0===r.state);const c=d.isAudioTrack()?"onAudioMuteChange":"onVideoMuteChange";null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:c,trackId:d.getTrackId()}),s),this._callAppListener(c,d)}}}))}_onUserUnpublish(e,t,r){var n,s;return i(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===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:t,trackIds:e.map((e=>e.getTrackId()))}),r),this._callAppListener(t,e)}))}_callAppListener(e,...t){var i,r,n;const s=null===(i=this._appListener)||void 0===i?void 0:i[e];if(s)try{s(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify(e))}}_reTryExchange(){return i(this,void 0,void 0,(function*(){Js((()=>i(this,void 0,void 0,(function*(){var t;const{reqBody:i}=yield this._createSubscribeParams(this._subscribedList,{},!0),r=yield this._exchangeHandle(i);if(r.code!==e.RCRTCCode.SUCCESS)return{code:r.code};const{sdp:o,resultCode:n}=r.data;if(n!==e.RCRTCCode.SUCCESS)return{code:n};this._pc.clearReTryExchangeTimer();const s=this._subscribedList.filter((e=>e.track.isMCUTrack()));if(s.length>0){const e=s[0].track.getTrackId(),i=null===(t=this._roomRes[e])||void 0===t?void 0:t.msid,r=[this._roomId,"RongCloudRTC"].join("_");o.sdp=o.sdp.replace(new RegExp(i,"g"),r)}const a=yield this._pc.setRemoteAnswer(o.sdp);return a!==e.RCRTCCode.SUCCESS?{code:a}:void 0}))),"audience-retry-exchange")}))}_createSubscribeParams(e,t,r){return i(this,void 0,void 0,(function*(){const i=yield this._pc.createOffer(r),o={resolutionInfo:[]},n={min:0,max:0};Object.keys(t).forEach((e=>{const{mediaStream:r,tinyStream:s}=t[e];[r,s].forEach(((t,r)=>{var s;const a=1===r?[e,"tiny"].join("_"):e;i.sdp=null===(s=i.sdp)||void 0===s?void 0:s.replace(new RegExp(t.id,"g"),a);const d=t.getVideoTracks()[0];if(!d)return;const c=0===r,{width:_,height:l,frameRate:u}=c?et(d):js;o.resolutionInfo.push({trackId:d.id,simulcast:c?Zo.NORMAL:Zo.TINY,resolution:`${_}x${l}`});const h=Se(_,l),R=Oe(u);n.min+=h.minBitrate*R,n.max+=h.maxBitrate*R}))}));return{reqBody:{sdp:i,switchstream:!1,newVersionFlag:!0,subscribeList:e.map((e=>({simulcast:e.subTiny?Zo.TINY:Zo.NORMAL,resolution:"",uri:this._roomRes[e.track.getTrackId()].uri})))},dynamicBitrate:n,offer:i}}))}_subscribeHandle(r,s=!1){var a,d,c,_,l,u,h,R,v,C,p;return i(this,void 0,void 0,(function*(){const i=null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d?void 0:d.createTraceId();null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:r.map(mt),forceReq:s}),i);if(this._assertRoomDestroyed())return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED,msg:"room destroyed"}),i),{code:e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED};if(!t.validate("tracks",r,(()=>t.isArray(r)&&r.length>0&&r.every((e=>e instanceof $e||e.track instanceof $e))),!0))return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),i),{code:e.RCRTCCode.PARAMS_ERROR};const{pc:g,pcName:m}=this._peerCManager.createPeerCList(r)[0];this._pc=g,this._pc.__reportR3R4ToPolaris(),this._pcName=m,this._pc.registerReportListener(this._reportListener),this._addPeerCEvent();const T=this._subscribedList.map((e=>Object.assign({},e))),I=r.map((e=>e instanceof $e?{track:e}:e));let E=!1;const S=[];return I.forEach((e=>{const t=e.track.getTrackId();S.push(t);const i=T.find((e=>e.track.getTrackId()===t));i&&i.subTiny===e.subTiny||(i?i.subTiny=e.subTiny:T.push(e),E=!0)})),E||s?(null===(p=this._polarisReport)||void 0===p||p.sendR2(Tn.SUBSCRIBE,In.BEGIN,S),this._updateSubListHandle(T,!0,i)):(null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.warn(o.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.SUCCESSED,msg:"repeat subscribe"}),i),{code:e.RCRTCCode.SUCCESS})}))}_addPeerCEvent(){this._pc.on(Mn.__INNER_EVENT_TRACK_READY__,(t=>{var i,r,n,s;const a=t.streams[0].id,{track:d}=t.receiver,c=[a,"audio"===d.kind?e.RCMediaType.AUDIO_ONLY:e.RCMediaType.VIDEO_ONLY].join("_"),_=this._remoteTracks[c];_?(_.__innerSetMediaStreamTrack(d),null===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onTrackReady",trackId:_.getTrackId()})),this._callAppListener("onTrackReady",_)):null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(o.L_AUDIENCE_LIVING_ROOM_ONTRACKREADY_O,`cannot found RCRemoteTrack: ${d.id}`)})),this._audioLevelReport&&this._pc.on(Mn.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport)}_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:gn.LIVE,UserId:e,"Session-Id":this._sessionId,"Client-Session-Id":this._clientSessionId},t)}_exchangeHandle(e){return this._service.broadcastSubscribe(this._getReqHeaders(),e)}_updateSubListHandle(t,r=!1,s){var a,d,c,_,l,u,h,R,v,C,p,g;return i(this,void 0,void 0,(function*(){null===(a=this._context.logger)||void 0===a||a.info(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_T,JSON.stringify({trackIds:t.map(mt),forceReq:r}),s);let i=t.map((e=>e instanceof $e?{track:e}:Object.assign({},e)));const m={};i=i.filter((e=>{const t=e.track.getTrackId();return!m[t]&&(m[t]=!0,!0)})).map((e=>Object.assign({},e)));const T=this._subscribedList.map((e=>Object.assign({},e)));if(!r){let t=!1;if(i.forEach((e=>{const i=T.findIndex((t=>t.track===e.track));if(-1===i)return void(t=!0);T.splice(i,1)[0].subTiny!==e.subTiny&&(t=!0)})),T.length&&(t=!0),!t)return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:n.SUCCESSED,msg:"repeat subscribe"}),s),{code:e.RCRTCCode.SUCCESS}}this._pc.clearReTryExchangeTimer(),this._pc.updateSubRemoteTracks(i.map((e=>e.track))),Uo(this._roomId,this._clientSessionId,this._sessionId),Po(this._roomId,this._clientSessionId,this._sessionId);const{reqBody:I}=yield this._createSubscribeParams(i,{},!1),E=yield this._exchangeHandle(I);if(T.length){const e=[];T.forEach((t=>{e.push(t.track.getTrackId())})),null===(_=this._pc.reportParser)||void 0===_||_.clearLatestPacketsRecv(e)}if(E.code!==e.RCRTCCode.SUCCESS)return wo(i,E.code),null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:n.FAILED,code:E.code}),s),{code:E.code};const{sdp:S,resultCode:f,message:O,subscribedList:L}=E.data;if(f!==e.RCRTCCode.SUCCESS)return wo(i,f),null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:n.FAILED,code:f,msg:O}),s),{code:f};i.forEach((e=>{const{track:t}=e;if(t.isMCUTrack()){const e=this._roomRes[t.getTrackId()].msid,{tag:i,userId:r}=rt(t.getTrackId()),o=[r,i].join("_");S.sdp=S.sdp.replace(new RegExp(e,"g"),o)}}));const N=yield this._pc.setRemoteAnswer(S.sdp);if(N!==e.RCRTCCode.SUCCESS)return wo(i,N),null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.error(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:n.FAILED,code:N,msg:"set remote answer error"}),s),{code:N};wo(i,N);const A=null==L?void 0:L.map((e=>`${e.msid}_${e.mediaType}`)),y=i.filter((e=>{if(e.track.isMCUTrack()){const t=this._roomRes[e.track.getTrackId()],i=`${t.msid}_${t.mediaType}`;return A.includes(i)}return null==A?void 0:A.includes(e.track.getTrackId())})),k=null==y?void 0:y.map((e=>`${e.track.getTrackId()}`)),D=i.filter((e=>!(null==k?void 0:k.includes(e.track.getTrackId()))));for(const e in this._remoteTracks){const t=y.some((t=>t.track.getTrackId()===e));this._remoteTracks[e].__innerSetSubscribed(t)}return this._subscribedList.splice(0,this._subscribedList.length,...y),null===(g=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===g||g.info(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:n.SUCCESSED,subSuccessTrackIds:A,failedList:D}),s),D.length?{code:e.RCRTCCode.SUCCESS,failedList:D}:{code:e.RCRTCCode.SUCCESS}}))}_diffCDNUris(e,t){var r,n,s,a,d,c;return i(this,void 0,void 0,(function*(){if(this._CDNUris.url&&!e.url)return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(o.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===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.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 i=this._CDNUris.w&&e.w&&this._CDNUris.w!==e.w,_=this._CDNUris.h&&e.h&&this._CDNUris.h!==e.h,l=this._CDNUris.fps&&e.fps&&this._CDNUris.fps!==e.fps;(i||_||l)&&(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.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(t,r){var s,a;return i(this,void 0,void 0,(function*(){const{w:i,h:d,fps:c}=t,_=this._initOptions.pullInnerCDNProtocol||e.RCInnerCDNPullKind.FLV,l=this._initOptions.pullInnerCDNUseHttps===e.RCInnerCDNPullIsHttps.NOT_HTTPS?e.RCInnerCDNPullIsHttps.NOT_HTTPS:e.RCInnerCDNPullIsHttps.HTTPS;if(!this._CDNUris.url)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.CDN_RESOURCE_IS_EMPTY,msg:"cdn_uris url is empty, the anchor need to open or push CDN"}),r),{code:e.RCRTCCode.CDN_RESOURCE_IS_EMPTY};const u={"App-Key":this._context.getAppkey(),Token:this._joinResData.token,RoomId:this.getRoomId(),UserId:this._crtUserId,SessionId:this.getSessionId()},h=[],{w:R=0,h:v=1}=this._CDNUris;R/v>1?(i&&h.push(`w=${i}`),d&&h.push(`h=${d}`)):(i&&h.push(`h=${i}`),d&&h.push(`w=${d}`)),c&&h.push(`fps=${c}`),h.push(`kind=${_}`),h.push(`is_https=${l}`);const C=h.join("&");let p=`${this._CDNUris.url}?`;C&&(p+=C);const{code:g,res:m}=yield this._service.getCDNResourceInfo(u,p,r);return g!==e.RCRTCCode.SUCCESS?{code:g}:{code:g,CDNPlayUrl:null==m?void 0:m.data.pull_url}}))}getCDNPlayUrl(t,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_T,JSON.stringify({resolution:t,fps:r}),i),t&&!ct(t))return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> resolution"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(r&&!_t(r))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> fps"}),i),{code:e.RCRTCCode.PARAMS_ERROR};const{width:R,height:v}=t?dt(t):{width:null,height:null},C=r?lt(r):null,p={};return R&&(p.w=R),v&&(p.h=v),C&&(p.fps=C),this._getCDNPlayUrl(p,i)}))}subscribe(e){return i(this,void 0,void 0,(function*(){return Wo(!0),Js((()=>this._subscribeHandle(e,!1)),"audience-sub")}))}addSubscribeTask(e){return i(this,void 0,void 0,(function*(){return Wo(!0),Js((()=>this._subscribeHandle(e,!1)),"audience-sub")}))}__unsubscribe(r){var s,a,d,c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_T,JSON.stringify({trackIds:r.map((e=>e.getTrackId()))}),i);if(this._assertRoomDestroyed())return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED,msg:"room destroyed"}),i),{code:e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED};if(!t.validate("tracks",r,(()=>t.isArray(r)&&r.length>0&&r.every((e=>e instanceof $e))),!0))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),i),{code:e.RCRTCCode.PARAMS_ERROR};const v=this._subscribedList.map((e=>Object.assign({},e))).filter((e=>!r.includes(e.track)));return null===(R=this._polarisReport)||void 0===R||R.sendR2(Tn.SUBSCRIBE,In.END,r.map((e=>e.getTrackId()))),qo(!0),this._updateSubListHandle(v,!1,i)}))}unsubscribe(e){return i(this,void 0,void 0,(function*(){return Js((()=>this.__unsubscribe(e)),"audience-unsub")}))}addUnsubscribeTask(e){return i(this,void 0,void 0,(function*(){return Js((()=>this.__unsubscribe(e)),"audience-unsub")}))}__destroy(e){var t;return i(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(),Do.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,r,s,a,d,c,_,l;return i(this,void 0,void 0,(function*(){const i=null===(r=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===r?void 0:r.createTraceId();null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_T,void 0,i);const{code:u}=yield this._context.joinLivingRoomAsAudience(this._roomId,gn.LIVE);u!==t.ErrorCode.SUCCESS&&(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_R,`status: ${n.FAILED}`,i)),null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_R,`status: ${n.SUCCESSED}`,i)}))}registerRoomEventListener(e){this._appListener=e}onAudioLevelChange(e,t){var i,r;this._audioLevelReport=new Bn(this),this._audioLevelReport.onAudioLevelChange(e),null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(o.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}}class Ws{constructor(e){this._context=e,this._isElectron=/Electron/.test(navigator.userAgent)}_getMediaStream(t,r="getUserMedia"){return i(this,void 0,void 0,(function*(){try{const i=this.setConstraintsConfig(t),o=yield navigator.mediaDevices[r](i);return{code:e.RCRTCCode.SUCCESS,stream:o}}catch(t){if("Permission denied"===t.message)return{code:e.RCRTCCode.BROWSER_PERMISSION_DENIED};if("Permission denied by system"===t.message)return{code:e.RCRTCCode.SYSTEM_PERMISSION_DENIED}}return{code:"getUserMedia"===r?e.RCRTCCode.GET_USER_MEDIA_FAILED:e.RCRTCCode.GET_DISPLAY_MEDIA_FAILED}}))}_getMediaStreamErrorReason(t){let i="";return t===e.RCRTCCode.BROWSER_PERMISSION_DENIED&&(i="Permission denied"),t===e.RCRTCCode.SYSTEM_PERMISSION_DENIED&&(i="Permission denied by system"),i}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(o.L_SET_AUDIO_CONSTRAINTS_O,`browser supported -> ${JSON.stringify(r)}`)}return e}createMicrophoneAudioTrack(t="RongCloudRTC",r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(!Ze(t))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS};const i=this._context.getCurrentId();if(!i)return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID};const{stream:R,code:v}=yield this._getMediaStream({audio:{deviceId:null==r?void 0:r.micphoneId,sampleRate:null==r?void 0:r.sampleRate}});if(v!==e.RCRTCCode.SUCCESS)return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:v,msg:this._getMediaStreamErrorReason(v)})),{code:v};const C=R.getAudioTracks()[0],p=new He(t,i,C);return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:n.SUCCESSED,trackId:p.getTrackId()})),{code:v,track:p}}))}createCameraVideoTrack(t="RongCloudRTC",r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(!Ze(t))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS};const i=this._context.getCurrentId();if(!i)return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID};const R=ct(null==r?void 0:r.resolution)?r.resolution:e.RCResolution.W640_H480,{width:v,height:C}=dt(R),{stream:p,code:g}=yield this._getMediaStream({video:{deviceId:null==r?void 0:r.cameraId,frameRate:lt((null==r?void 0:r.frameRate)||e.RCFrameRate.FPS_15),width:v,height:C,facingMode:null==r?void 0:r.faceMode}});if(g!==e.RCRTCCode.SUCCESS)return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:this._getMediaStreamErrorReason(g)})),{code:g};const m=p.getVideoTracks()[0],T=new Ge(t,i,m);return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:n.SUCCESSED,trackId:T.getTrackId()})),{code:g,track:T}}))}createMicrophoneAndCameraTracks(t="RongCloudRTC",r){var s,a,d,c,_,l,u,h,R,v,C,p,g,m;return i(this,void 0,void 0,(function*(){const i=[];if(!Ze(t))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS,tracks:i};const T=this._context.getCurrentId();if(!T)return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID,tracks:i};const I=ct(null===(_=null==r?void 0:r.video)||void 0===_?void 0:_.resolution)?r.video.resolution:e.RCResolution.W640_H480,{width:E,height:S}=dt(I),{stream:f,code:O}=yield this._getMediaStream({video:{deviceId:null===(l=null==r?void 0:r.video)||void 0===l?void 0:l.cameraId,frameRate:lt((null===(u=null==r?void 0:r.video)||void 0===u?void 0:u.frameRate)||e.RCFrameRate.FPS_15),width:E,height:S,facingMode:null===(h=null==r?void 0:r.video)||void 0===h?void 0:h.faceMode},audio:{deviceId:null===(R=null==r?void 0:r.audio)||void 0===R?void 0:R.micphoneId,sampleRate:null===(v=null==r?void 0:r.audio)||void 0===v?void 0:v.sampleRate}});return O!==e.RCRTCCode.SUCCESS?(null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:n.FAILED,code:O,msg:this._getMediaStreamErrorReason(O)})),{code:O,tracks:i}):(f.getTracks().forEach((e=>{"video"===e.kind?i.push(new Ge(t,T,e)):i.unshift(new He(t,T,e))})),null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.info(o.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:n.SUCCESSED,trackIds:i.map((e=>e.getTrackId()))})),{code:O,tracks:i})}))}createScreenVideoTrack(t="screenshare",r){return i(this,void 0,void 0,(function*(){const i=yield this._createScreenTracks(t,!1,o.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_TRACK_O,r);return i.code===e.RCRTCCode.SUCCESS?{code:i.code,track:i.tracks[0]}:i}))}createScreenWithAudioTracks(e="screenshare",t){return i(this,void 0,void 0,(function*(){return this._createScreenTracks(e,!0,o.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_AND_AUDIO_TRACKS_O,t)}))}_createScreenTracks(r,s,a,d){var c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f;return i(this,void 0,void 0,(function*(){if(!Ze(r))return null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.error(a,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS};const i=this._context.getCurrentId();if(!i)return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(a,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID};if(!Rt())return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.BROWSER_NOT_SUPPORT,msg:"browser not support"})),{code:e.RCRTCCode.BROWSER_NOT_SUPPORT};const O=/macintosh|mac os x/i.test(navigator.userAgent);this._isElectron&&O&&s&&(null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.warn(a,JSON.stringify({status:n.INFO,code:e.RCRTCCode.MAC_IN_ELECTRON_NOT_SUPPORT_SCREEN_SHARE_WITH_AUDIO,msg:"mac in electron not support screen share with audio"})));const L=(!this._isElectron||!O)&&s;if(this._isElectron&&!t.isUndefined(null==d?void 0:d.chromeMediaSourceId)&&!t.isString(null==d?void 0:d.chromeMediaSourceId))return null===(g=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===g||g.error(a,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> options.chromeMediaSourceId type is string"})),{code:e.RCRTCCode.PARAMS_ERROR};const N=ct(null==d?void 0:d.resolution)?d.resolution:e.RCResolution.W1280_H720,{width:A,height:y}=dt(N),k=this._isElectron?{mandatory:{chromeMediaSourceId:null==d?void 0:d.chromeMediaSourceId,chromeMediaSource:"desktop",minWidth:A,maxWidth:A,minHeight:y,maxHeight:y}}:{frameRate:lt((null==d?void 0:d.frameRate)||e.RCFrameRate.FPS_15),width:A,height:y};!(null==d?void 0:d.chromeMediaSourceId)&&this._isElectron&&(null===(m=k.mandatory)||void 0===m||delete m.chromeMediaSourceId);let D=null;L&&this._isElectron&&(null===(T=k.mandatory)||void 0===T||delete T.chromeMediaSourceId,D={mandatory:{chromeMediaSource:"desktop"}});const{stream:b,code:U}=yield this._getMediaStream({video:k,audio:D||L},this._isElectron?"getUserMedia":"getDisplayMedia");if(U!==e.RCRTCCode.SUCCESS)return null===(E=null===(I=this._context)||void 0===I?void 0:I.logger)||void 0===E||E.error(a,JSON.stringify({status:n.FAILED,code:U,msg:this._getMediaStreamErrorReason(U)})),{code:U};const P=b.getVideoTracks()[0],M=[new Ke(r,i,P)];if(L){const e=b.getAudioTracks()[0];e&&M.push(new je(r,i,e))}return null===(f=null===(S=this._context)||void 0===S?void 0:S.logger)||void 0===f||f.info(a,JSON.stringify({status:n.SUCCESSED,trackIds:M.map((e=>e.getTrackId()))})),{code:U,tracks:M}}))}createLocalAudioTrack(t,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(!Ze(t))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS};if(!r||"[object MediaStreamTrack]"!==r.toString()||"audio"!==r.kind)return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.CREATE_CUSTOM_TRACK_FAILED,msg:"params track is not MediaStreamTrack or kind is not audio"})),{code:e.RCRTCCode.CREATE_CUSTOM_TRACK_FAILED};const i=this._context.getCurrentId();if(!i)return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID};const R=new we(t,i,r);return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:n.SUCCESSED,trackId:R.getTrackId()})),{code:e.RCRTCCode.SUCCESS,track:R}}))}createLocalVideoTrack(t,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(!Ze(t))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS};if(!(r&&r instanceof MediaStreamTrack&&"video"===r.kind))return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.CREATE_CUSTOM_TRACK_FAILED,msg:"params track is not MediaStreamTrack or kind is not video"})),{code:e.RCRTCCode.CREATE_CUSTOM_TRACK_FAILED};const i=this._context.getCurrentId();if(!i)return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID};const R=new Be(t,i,r);return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:n.SUCCESSED,trackId:R.getTrackId()})),{code:e.RCRTCCode.SUCCESS,track:R}}))}createLocalFileTracks(r,s,a){var d,c,_,l,u,h,R,v;return i(this,void 0,void 0,(function*(){if(!Ze(r))return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS,tracks:[]};if(!ht())return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.BROWSER_NOT_SUPPORT,msg:"browser not support"})),{code:e.RCRTCCode.BROWSER_NOT_SUPPORT,tracks:[]};const i=s instanceof File?URL.createObjectURL(s):s;if(!t.isHttpUrl(i)&&!/^blob:/.test(i))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> file"})),{code:e.RCRTCCode.PARAMS_ERROR,tracks:[]};const C=this._context.getCurrentId();return C?new Promise((t=>{const s=document.createElement("video");(null==a?void 0:a.withoutAudio)&&(s.muted=!0),s.onloadedmetadata=()=>{var i,d,c,_;const l=[];let u;try{const e=s.mozCaptureStream?"mozCaptureStream":"captureStream";u=s[e]()}catch(r){null===(d=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===d||d.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.CREATE_FILE_TRACK_FAILED,msg:`captureSteam error -> ${JSON.stringify(r)}`})),t({code:e.RCRTCCode.CREATE_FILE_TRACK_FAILED,tracks:l})}const[h,R]=Ws.getTracksWithOptions(u,a);h&&l.push(new Je(r,C,h,s)),R&&l.push(new Fe(r,C,R,s)),0===l.length&&(s.pause(),s.src=""),s.onerror=null,null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.SUCCESSED,trackIds:l.map((e=>e.getTrackId()))})),t({code:e.RCRTCCode.SUCCESS,tracks:l})},s.onerror=()=>{var i,r;null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.CREATE_FILE_TRACK_FAILED,msg:"Failed to create file stream, video onerror"})),t({code:e.RCRTCCode.CREATE_FILE_TRACK_FAILED,tracks:[]})},s.src=i,s.loop=!0,s.play()})):(null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID,tracks:[]})}))}createLocalTracks(t,r,s){var a,d,c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=[];if(!Ze(t))return null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS,tracks:i};if(!(r instanceof MediaStream))return null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> stream"})),{code:e.RCRTCCode.PARAMS_ERROR,tracks:i};const v=this._context.getCurrentId();if(!v)return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID,tracks:i};const[C,p]=Ws.getTracksWithOptions(r,s);return C&&i.push(new we(t,v,C)),p&&i.push(new Be(t,v,p)),null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:n.SUCCESSED,trackIds:i.map((e=>e.getTrackId()))})),{code:e.RCRTCCode.SUCCESS,tracks:i}}))}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 qs{constructor(){this.tasks=[]}static handler(){return this.retryHandler||(this.retryHandler=new qs),this.retryHandler}execute(){for(const e of this.tasks)e();this.destroy()}task(e){return i(this,void 0,void 0,(function*(){return new Promise((t=>{this.tasks.push((()=>{t(e())}))}))}))}destroy(){this.tasks=[]}}class Ys extends Ws{constructor(e,t,i){super(e),this._context=e,this._runtime=t,this._options=i,this._crtRoom=null,this._audience=null,this._crtAudienceLivingRoom=null,An.setSdpSemantics(i.sdpSemantics||"plan-b"),this._service=new zo(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 i,r,s,a,d,c;if(e.conversationType!==t.ConversationType.RTC_ROOM)return!1;const _=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();if(this._crtRoom instanceof Bs){this._getJoinedPKRoomList().forEach((t=>{t.__parseInnerMessage(e,_)}))}return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_RTC_CLIENT_MESSAGE_O,JSON.stringify({status:n.SUCCESSED,message:e}),_),this._crtRoom?(this._crtRoom.__parseInnerMessage(e,_),!0):(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.warn(o.L_RTC_CLIENT_MESSAGE_O,JSON.stringify({status:n.FAILED,message:"the crtRoom is empty"}),_),!0)}naviDataChange(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(o.L_RTC_CLIENT_NAVI_CHANGE_O,`on navi change data => ${JSON.stringify(e)}`),this._service.detectorMediaSever(),wn.logServer=null==e?void 0:e.logServer,wn.dc=null==e?void 0:e.dc}_getJoinedPKRoomList(){const{code:t,roomPKHandler:i}=this._crtRoom.getRoomPKHandler();if(t===e.RCRTCCode.SUCCESS&&i){const e=i.getJoinedPKRooms()||{};return Object.values(e)}return[]}getCurrentId(){return this._context.getCurrentId()}joinRTCRoom(t,r,s,a,d=gn.RTC,c){var _,l,u,h,R,v;return i(this,void 0,void 0,(function*(){const i=null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l?void 0:l.createTraceId();if(null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_RTC_CLIENT_JOIN_RTC_ROOM_T,JSON.stringify({roomId:t,joinType:r,outerUserDatas:s,useMutilPeerC:a,roomType:d}),i),this._crtRoom)return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_RTC_CLIENT_JOIN_RTC_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const C=this._crtRoom=new Vs(this._context,this._runtime,t,this._service,this._options,!1,!1,a,Oo(),c),{code:p}=yield C.__innerInit(d,r,void 0,void 0,s,i);return p!==e.RCRTCCode.SUCCESS?(this._crtRoom=null,{code:p}):(C.once(Ts,(()=>{this._crtRoom=null})),{code:p,room:C,userIds:C.getRemoteUserIds(),tracks:C.getRemoteTracks()})}))}joinCrossRTCRoom(t,r,s,a,d=gn.CROSS_MUTI){var c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_?void 0:_.createTraceId();if(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_T,JSON.stringify({roomId:t,joinType:r,outerUserDatas:s,useMutilPeerC:a,roomType:d}),i),this._crtRoom)return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const v=this._crtRoom=new Vs(this._context,this._runtime,t,this._service,this._options,!1,!1,a,Oo(),d),{code:C}=yield v.__innerInit(d,r,void 0,void 0,s,i);return C!==e.RCRTCCode.SUCCESS?(this._crtRoom=null,{code:C}):(v.once(Ts,(()=>{this._crtRoom=null})),{code:C,room:v,userIds:v.getRemoteUserIds(),tracks:v.getRemoteTracks()})}))}joinLivingRoom(t,r,s,a,d){var c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_?void 0:_.createTraceId();if(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_T,JSON.stringify({roomId:t,livingType:r,joinType:s,outerUserDatas:a,useMutilPeerC:d}),i),this._crtRoom)return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:`Join the room repeatedly -> roomId: ${t}`}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const v=this._crtRoom=new Bs(this._context,this._runtime,t,this._service,this._options,r,!1,!0,d),{code:C}=yield v.__innerInit(gn.LIVE,s,r,void 0,a,i);if(C!==e.RCRTCCode.SUCCESS)return this._crtRoom=null,{code:C};v.once(Ts,(()=>{this._crtRoom=null}));const p={code:C,room:v,userIds:v.getRemoteUserIds(),tracks:v.getRemoteTracks()};return v.__getCDNPushMode()===ks.MANUAL&&Object.assign(p,{CDNEnable:v.__getCDNEnable()}),p}))}getAudienceClient(e){var t,i;return this._audience||(this._audience=new Hs(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(o.L_RTC_CLIENT_GET_AUDIENCE_CLIENT_O,JSON.stringify({useMutilPeerC:e})),this._audience}_onIMStatusChange(e){var i,r;if(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(o.L_RTC_CLIENT_IM_CONNECTION_STATE_S,JSON.stringify({status:e})),e===t.ConnectionStatus.CONNECTED){if(this._service.detectorMediaSever(),this._crtRoom instanceof Bs){this._getJoinedPKRoomList().forEach((e=>{e.__onReconnected()}))}this._crtRoom&&this._crtRoom.__onReconnected().then((e=>{if(e&&e.data&&e.data.sessionId){qs.handler().execute()}}))}}_onIMDisconnect(){var e,t;null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(o.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(o.L_RTC_CLIENT_DESTROY_S,JSON.stringify({msg:"TODO -> on IM client ondestroy"})),null===(i=this._crtRoom)||void 0===i||i.__destroy(!0)}leaveRoom(t){var r,s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const i=null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s?void 0:s.createTraceId();return null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_RTC_CLIENT_LEAVE_ROOM_T,JSON.stringify({roomId:t.getRoomId()}),i),this._crtRoom?(yield this._crtRoom.__destroy(!0),this._service.detectorMediaSever(),null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_RTC_CLIENT_LEAVE_ROOM_R,JSON.stringify({status:n.SUCCESSED,roomId:null===(h=this._crtRoom)||void 0===h?void 0:h.getRoomId()}),i),this._crtRoom=null,{code:e.RCRTCCode.SUCCESS}):(null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.warn(o.L_RTC_CLIENT_LEAVE_ROOM_R,JSON.stringify({status:n.FAILED,msg:"Room does not exist, without leave"}),i),{code:e.RCRTCCode.SUCCESS})}))}joinLivingRoomAsAudience(r,s,a){var d,c,_,l,u,h,R,v,C,p,g,m,T,I,E,S;return i(this,void 0,void 0,(function*(){const i=null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c?void 0:c.createTraceId();if(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_T,JSON.stringify({roomId:r,livingType:s,useMutilPeerC:a}),i),this._service.detectorMediaSever(),Ct(this._context.getNaviInfo()))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"}),i),{code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR};if(!t.validate("roomId",r,t.notEmptyString,!0)||!t.validate("livingType",s,(t=>t===e.RCLivingType.AUDIO||t===e.RCLivingType.VIDEO)))return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> roomId or livingType"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(this._crtAudienceLivingRoom)return null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};if(!this._service.getNaviMS().length)return null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"No audio / video server address available"}),i),{code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER};const{code:f,data:O}=yield this._context.joinLivingRoomAsAudience(r,gn.LIVE,s);if(f!==t.ErrorCode.SUCCESS)return null===(I=null===(T=this._context)||void 0===T?void 0:T.logger)||void 0===I||I.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:f,msg:"signal error -> audience join room"}),i),{code:e.RCRTCCode.SIGNAL_AUDIENCE_JOIN_ROOM_FAILED};const L=Oo();(e=>{Do.getMemo().clientData={clientSessionId:e}})(L);const N=new $s(this._context,this._runtime,this._options,r,O,s,a,L);return this._crtAudienceLivingRoom=N,null===(S=null===(E=this._context)||void 0===E?void 0:E.logger)||void 0===S||S.info(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.SUCCESSED,roomData:O}),i),{room:N,code:e.RCRTCCode.SUCCESS,userIds:N.getRemoteUserIds(),RTCTracks:N.getRemoteRTCTracks(),MCUTracks:N.getRemoteMCUTracks(),CDNUris:N.getCDNInfo()}}))}leaveLivingRoomAsAudience(t){var r,s,a,d,c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s?void 0:s.createTraceId();return null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_T,JSON.stringify({roomId:t.getRoomId(),userId:this._context.getCurrentId()}),i),this._crtAudienceLivingRoom?this._crtAudienceLivingRoom!==t?(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> room"}),i),{code:e.RCRTCCode.PARAMS_ERROR}):(yield this._crtAudienceLivingRoom.__destroy(!0),this._crtAudienceLivingRoom=null,null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.SUCCESSED}),i),{code:e.RCRTCCode.SUCCESS}):(null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.warn(o.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,msg:"Room does not exist, without leave"}),i),{code:e.RCRTCCode.SUCCESS})}))}upgradeToAnchorRoom(r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_T,void 0,i),!t.validate("room",r,(()=>r instanceof $s),!0))return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> room"}),i),{code:e.RCRTCCode.PARAMS_ERROR};const R=r.getRoomId();if(this._crtRoom)return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly",roomId:R}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const v=this._crtRoom=new Bs(this._context,this._runtime,R,this._service,this._options,r.livingType,!0,!0,!1,r.getClientSessionId());return(yield v.__innerInitByIdentityChange(i))!==t.ErrorCode.SUCCESS?(this._crtRoom=null,{code:e.RCRTCCode.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED}):(v.once(Ts,(()=>{this._crtRoom=null})),yield this._crtAudienceLivingRoom.__destroy(!1),this._crtAudienceLivingRoom=null,{room:v,code:e.RCRTCCode.SUCCESS,userIds:v.getRemoteUserIds(),tracks:v.getRemoteTracks()})}))}downgradeToAudienceRoom(r){var s,a,d,c,_,l,u,h,R,v,C,p,g,m;return i(this,void 0,void 0,(function*(){const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_T,JSON.stringify({roomId:r._roomId,userId:this._context.getCurrentId()}),i),!r.isMainRoom())return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"the `downgradeToAudienceRoom` is disabled in PK room"}),i),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM};if(!t.validate("room",r,(()=>r instanceof Bs),!0))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> room"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(this._crtAudienceLivingRoom)return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const{code:T,data:I}=yield this._context.rtcIdentityChange(r._roomId,bs.AnchorToViewer,r.getLivingType());if(T!==t.ErrorCode.SUCCESS)return null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED}),i),{code:e.RCRTCCode.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED};null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.info(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:n.SUCCESSED,roomData:I}),i);const E=r.getClientSessionId(),S=new $s(this._context,this._runtime,this._options,r._roomId,I,r.getLivingType(),!1,E);return this._crtAudienceLivingRoom=S,this._crtRoom.__destroy(!1),this._crtRoom=null,{room:S,code:e.RCRTCCode.SUCCESS,userIds:S.getRemoteUserIds(),RTCTracks:S.getRemoteRTCTracks(),MCUTracks:S.getRemoteMCUTracks(),CDNUris:S.getCDNInfo()}}))}getJoinedRoomInfo(){var r,s,a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){const i=null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s?void 0:s.createTraceId(),h=this._context.getCurrentId();null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_T,JSON.stringify({userId:h}),i);const{code:R,data:v}=yield this._context.getRTCJoinedUserInfo(h);return R!==t.ErrorCode.SUCCESS?(null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_R,JSON.stringify({status:n.FAILED,code:R}),i),{code:R}):(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_R,JSON.stringify({status:n.SUCCESSED,roomInfo:v}),i),{code:e.RCRTCCode.SUCCESS,data:v})}))}reportSDKInfo(){this._context.reportSDKInfo({"plugin-rtc":"5.6.6"})}}var zs;e.RTCJoinType=void 0,(zs=e.RTCJoinType||(e.RTCJoinType={}))[zs.KICK=0]="KICK",zs[zs.REFUSE=1]="REFUSE",zs[zs.COEXIST=2]="COEXIST";const Zs="rtcRJoin_data",Qs="rtcRExit",Xs="rtcRInfo",ea="rtcUData",ta="rtcUDel",ia="rtcSetData",ra="userSetData",oa="rtcQryData",na="rtcDelData",sa="rtcToken",aa="rtcUserState",da="rtcUList",ca="viewerJoinR",_a="viewerExitR",la="rtcPullKv",ua="rtcIdentityChange",ha="rtcInvite",Ra="rtcCancelInvite",va="rtcInviteAnswer",Ca="rtcEndInvite",pa="rtcQueryJoined",ga="rtcPullRoomStatus",ma="reportsdk",Ta="rtcPing";var Ia;!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"}(Ia||(Ia={}));const Ea={[Ia.RtcInput]:["roomType","broadcastType","extraInnerData","needSysChatroom","identityChangeType","joinType","innerDatas","outerDatas","supportNtf"],[Ia.RtcOutput]:["version"],[Ia.RtcUserListOutput]:["users","token","sessionId","roomInfo","version"],[Ia.SetUserStatusInput]:["status"],[Ia.RtcSetDataInput]:["interior","target","key","value","objectName","content"],[Ia.RtcUserSetDataInput]:["valueInfo","objectName","content"],[Ia.RtcDataInput]:["interior","target","key","objectName","content"],[Ia.RtcSetOutDataInput]:["target","valueInfo","objectName","content"],[Ia.MCFollowInput]:["state"],[Ia.RtcTokenOutput]:["rtcToken"],[Ia.RtcQryOutput]:["outInfo"],[Ia.RtcQryUserOutDataInput]:["userId"],[Ia.RtcUserOutDataOutput]:["user"],[Ia.RtcQueryListInput]:["order"],[Ia.RtcRoomInfoOutput]:["roomId","roomData","userCount","list"],[Ia.RtcValueInfo]:["key","value"],[Ia.RtcKeyDeleteInput]:["key"],[Ia.RtcNotifyMsg]:["type","time","roomId"],[Ia.RtcPullKV]:["timestamp","roomId"],[Ia.RtcKVOutput]:["entries","bFullUpdate","syncTime"],[Ia.RtcQueryUserJoinedInput]:["userId"],[Ia.RtcQueryUserJoinedOutput]:["info"],[Ia.RtcInviteInput]:["invitedUserId","timeoutTime","invitedRoomId","inviteInfo","inviteSessionId"],[Ia.RtcCancelInviteInput]:["invitedUserId","invitedRoomId","inviteInfo","inviteSessionId"],[Ia.RtcInviteAnswerInput]:["inviteUserId","answerCode","inviteRoomId","inviteSessionId","content","key","value"],[Ia.RtcEndInviteInput]:["inviteRoomId","inviteSessionId","inviteContent","inviteRoomKeys"],[Ia.RtcRoomStatusInput]:["version"],[Ia.RtcRoomStatusOutput]:["bFullStatus","version","usersData","roomStatus"],[Ia.RtcReportSDKInput]:["sdkInfo"],[Ia.RtcPBPolaris]:["type","appKey","sessionId","roomId","roomCreateTime","userId","userRole","joinTime","signalDataCenter","r1Info","r2Info","r3Info","r4Info"],[Ia.RtcPBR1Info]:["joinTime","rtcVersion","imVersion","platform","device","os","browserName","browserVersion"],[Ia.RtcPBR2Info]:["joinTime","sendTime","rtcActionType","rtcActionStatus","trackId"],[Ia.RtcPBR3Info]:["info"],[Ia.RtcPBR4Info]:["info"],[Ia.RtcPBStatusInfo]:["joinTime","receiveTime","totalBitRate","appCPUUsage","systemCPUUsage","systemCPUFrequency","networkStatus","googleRTTNetwork","ipAddress","useReceiveBroadBand","useSendBroadBand","packetLossCount","streams"],[Ia.RtcPBStreamInfo]:["trackId","codeName","volume","samplingRate","bitRate","packetLossRate","frameRate","resolution","blockTime","jitterData","nAckCount","pliCount","googleRTTTotalTime","isReceiveFirstFrameRate","codeType","isEnabled"]},Sa=`\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 ${Ia.SetUserStatusInput}\n {\n optional int32 status=1;\n }\n message ${Ia.MCFollowInput}\n {\n required string state = 1;\n }\n message ${Ia.RtcQueryListInput}{\n optional int32 order=1;\n }\n message ${Ia.RtcKeyDeleteInput}{\n repeated string key=1;\n }\n message ${Ia.RtcValueInfo}{\n required string key=1;\n required string value=2;\n }\n message RtcUserInfo{\n required string userId=1;\n repeated ${Ia.RtcValueInfo} userData=2; //用户资源信息\n }\n message ${Ia.RtcRoomStatusInput}{ // rtc 和 living room 拉房间资源状态使用的参数\n required int64 version =1; //当前客户端最大的房间状态的version\n }\n message ${Ia.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 ${Ia.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 ${Ia.RtcValueInfo} roomData = 2;\n optional int32 userCount = 3;\n repeated RtcUserInfo list=4;\n }\n message ${Ia.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 ${Ia.RtcValueInfo} innerDatas = 7; //用户内部inner数据,角色或者连麦信息等\n repeated ${Ia.RtcValueInfo} outerDatas = 8; //用户内部outer数据,自定义数据结构RtcInput。\n optional bool supportNtf = 9; //是否支持房间状态的变更通过通知拉取的方式获取\n }\n message ${Ia.RtcQryOutput}{\n repeated ${Ia.RtcValueInfo} outInfo=1;\n }\n message ${Ia.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 ${Ia.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 ${Ia.RtcUserSetDataInput} {\n repeated ${Ia.RtcValueInfo} valueInfo = 1;\n required string objectName = 2;\n repeated ${Ia.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 ${Ia.RtcTokenOutput}{\n required string rtcToken=1;\n }\n message ${Ia.RtcSetOutDataInput}{\n required targetType target=1;\n repeated ${Ia.RtcValueInfo} valueInfo=2;\n optional string objectName=3;\n optional string content=4;\n }\n message ${Ia.RtcQryUserOutDataInput}{\n repeated string userId = 1;\n }\n message ${Ia.RtcUserOutDataOutput}{\n repeated RtcUserInfo user = 1;\n }\n message ${Ia.RtcNotifyMsg} \n {\n required int32 type= 1; //(通知类型 1:rtc房间状态KV变更通知)\n optional int64 time= 2; //消息产生时间\n optional string roomId=3; //主播房间id\n }\n message ${Ia.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 ${Ia.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 ${Ia.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 ${Ia.RtcQueryUserJoinedOutput}\n {\n repeated RtcJoinedInfo info = 1;\n }\n message ${Ia.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 ${Ia.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 ${Ia.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 ${Ia.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 ${Ia.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 ${Ia.RtcReportSDKInput} {\n required string sdkInfo=1; // 用户集成的 sdk 信息,json 格式 {"web-rtc": "4.0.3.7"}\n }\n // ---- 北极星数据上报 -------\n message ${Ia.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 ${Ia.RtcPBR1Info} r1Info = 10;\n optional ${Ia.RtcPBR2Info} r2Info = 11;\n optional ${Ia.RtcPBR3Info} r3Info = 12;\n optional ${Ia.RtcPBR4Info} r4Info = 13;\n }\n message ${Ia.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 ${Ia.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 ${Ia.RtcPBR3Info} {\n required ${Ia.RtcPBStatusInfo} info = 1;\n }\n message ${Ia.RtcPBR4Info} {\n required ${Ia.RtcPBStatusInfo} info = 1;\n }\n message ${Ia.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 ${Ia.RtcPBStreamInfo} streams = 13;\n }\n message ${Ia.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`,fa=(e,t,i,r,o,n,s)=>{const a=o?Object.keys(o).map((t=>e.encode(Ia.RtcValueInfo,{key:t,value:o[t]},!0))):void 0,d=n?Object.keys(n).map((t=>e.encode(Ia.RtcValueInfo,{key:t,value:n[t]},!0))):void 0;return e.encode(Ia.RtcInput,{roomType:t,broadcastType:i,joinType:r,innerDatas:a,outerDatas:d,supportNtf:s})},Oa=(e,i)=>{const r=e.decode(Ia.RtcUserListOutput,i),{users:o,token:n,sessionId:s,roomInfo:a,entries:d,offlineKickTime:c=60,codeFormat:_,roomCreateTime:l,userJoinTime:u,version:h}=r,R={};return t.forEach(o,(e=>{const{userId:i,userData:r}=e,o={};t.forEach(r,(e=>{const{key:t,value:i}=e;o[t]=i})),R[i]=o})),{users:R,token:n,sessionId:s,roomInfo:a,kvEntries:d,offlineKickTime:c,codeFormat:_,roomCreateTime:Tt(l),userJoinTime:Tt(u),version:h}};class La{constructor(e,t){this.context=e,this.codec=t,this.roomCreateTime=0,this.userJoinTime=0,this.logger=null,this.logger=Le.getLogger()}joinRTCRoom(e,r,o,n,s,a){return i(this,void 0,void 0,(function*(){const i=fa(this.codec,r,o,n,s,a,!0),{code:d,buffer:c}=yield this.context.rtcSignaling(e,Zs,!0,i);let _;if(d===t.ErrorCode.SUCCESS&&c){_=Oa(this.codec,c);const{users:e,token:t,sessionId:i,roomInfo:r,kvEntries:o,offlineKickTime:n,roomCreateTime:s,userJoinTime:a,version:l}=_;return this.roomCreateTime=s,this.userJoinTime=a,{code:d,data:{users:e,token:t,sessionId:i,roomInfo:r,kvEntries:o,offlineKickTime:n,version:l}}}return{code:d,data:_}}))}quitRTCRoom(e){return i(this,void 0,void 0,(function*(){const t=this.codec.encode(Ia.SetUserStatusInput,{status:0}),{code:i}=yield this.context.rtcSignaling(e,Qs,!0,t);return i}))}getRTCRoomInfo(e){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcQueryListInput,{order:2}),{code:r,buffer:o}=yield this.context.rtcSignaling(e,Xs,!0,i);let n;return r===t.ErrorCode.SUCCESS&&o&&(n=this.codec.decode(Ia.RtcRoomInfoOutput,o)),{code:r,data:n}}))}getRTCUserInfoList(e){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcQueryListInput,{order:2}),{code:r,buffer:o}=yield this.context.rtcSignaling(e,ea,!0,i);let n;if(r===t.ErrorCode.SUCCESS&&o){n={users:Oa(this.codec,o).users}}return{code:r,data:n}}))}getRTCUserInfo(e){throw new Error("Method not implemented.")}removeRTCUserInfo(e,t){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcKeyDeleteInput,{key:t}),{code:r}=yield this.context.rtcSignaling(e,ta,!1,i);return r}))}setRTCData(e,t,r,o,n,s){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcSetDataInput,{interior:o,target:n,key:t,value:r,objectName:null==s?void 0:s.name,content:null==s?void 0:s.content}),{code:a}=yield this.context.rtcSignaling(e,ia,!1,i);return a}))}setRTCTotalRes(e,t,r,o,n,s){return i(this,void 0,void 0,(function*(){const i={objectName:o,content:[],valueInfo:[this.codec.encode(Ia.RtcValueInfo,{key:"uris",value:r},!0)]};t.forEach((e=>{const t=this.codec.encode(Ia.RtcValueInfo,{key:e.name,value:e.content},!0);i.content.push(t)})),n&&i.valueInfo.push(this.codec.encode(Ia.RtcValueInfo,{key:"mcu_uris",value:n},!0)),s&&i.valueInfo.push(this.codec.encode(Ia.RtcValueInfo,{key:"cdn_uris",value:s},!0));const a=this.codec.encode(Ia.RtcUserSetDataInput,i),{code:d}=yield this.context.rtcSignaling(e,ra,!0,a);return d}))}setRTCCDNUris(e,t,r){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcUserSetDataInput,{objectName:t,valueInfo:this.codec.encode(Ia.RtcValueInfo,{key:"cdn_uris",value:r},!0)}),{code:o}=yield this.context.rtcSignaling(e,ra,!0,i);return o}))}getRTCData(e,r,o,n){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcDataInput,{interior:o,target:n,key:r}),{code:s,buffer:a}=yield this.context.rtcSignaling(e,oa,!0,i);if(s!==t.ErrorCode.SUCCESS||!a)return{code:s};const{outInfo:d}=this.codec.decode(Ia.RtcQryOutput,a),c={};return d.forEach((e=>{c[e.key]=e.value})),{code:s,data:c}}))}removeRTCData(e,t,r,o,n){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcDataInput,{interior:r,target:o,key:t,objectName:(null==n?void 0:n.name)||"",content:(null==n?void 0:n.content)||""}),{code:s}=yield this.context.rtcSignaling(e,na,!1,i);return s}))}setRTCOutData(e,t,r,o){return i(this,void 0,void 0,(function*(){throw new Error("JSEngine's method not implemented.")}))}getRTCOutData(e,t){return i(this,void 0,void 0,(function*(){throw new Error("JSEngine's method not implemented.")}))}getRTCToken(e,r,o){return i(this,void 0,void 0,(function*(){const i=fa(this.codec,r,o),{code:n,buffer:s}=yield this.context.rtcSignaling(e,sa,!0,i);if(n!==t.ErrorCode.SUCCESS||!s)return{code:n};const{rtcToken:a}=this.codec.decode(Ia.RtcTokenOutput,s);return{code:n,data:{rtcToken:a}}}))}setRTCState(e,t){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.MCFollowInput,{state:t}),{code:r}=yield this.context.rtcSignaling(e,aa,!0,i);return r}))}setRTCStateByHttp(e,r,o,n){return i(this,void 0,void 0,(function*(){const i=((e,t,i)=>{const{type:r,appKey:o,sessionId:n,roomId:s,roomCreateTime:a,userId:d,userRole:c,joinTime:_,signalDataCenter:l,r1Info:u,r2Info:h,r3Info:R,r4Info:v}=t,C={type:r,appKey:o,sessionId:n,roomId:s,roomCreateTime:a,userId:d,userRole:c,joinTime:_,signalDataCenter:l};if(i===un.R1&&u){const t=e.encode(Ia.RtcPBR1Info,u,!0);return e.encode(Ia.RtcPBPolaris,Object.assign(Object.assign({},C),{r1Info:t}))}if(i===un.R2&&h){const t=e.encode(Ia.RtcPBR2Info,h,!0);return e.encode(Ia.RtcPBPolaris,Object.assign(Object.assign({},C),{r2Info:t}))}if(i===un.R3&&R){const{info:t}=R,{streams:i}=t;let r=Array.isArray(i)&&i.map((t=>t&&e.encode(Ia.RtcPBStreamInfo,t,!0))),o=e.encode(Ia.RtcPBStatusInfo,Object.assign(Object.assign({},t),{streams:r}),!0),n=e.encode(Ia.RtcPBR3Info,{info:o},!0);return e.encode(Ia.RtcPBPolaris,Object.assign(Object.assign({},C),{r3Info:n}))}if(i===un.R4&&v){const{info:t}=v,{streams:i}=t;let r=Array.isArray(i)&&i.map((t=>t&&e.encode(Ia.RtcPBStreamInfo,t,!0))),o=e.encode(Ia.RtcPBStatusInfo,Object.assign(Object.assign({},t),{streams:r}),!0),n=e.encode(Ia.RtcPBR4Info,{info:o},!0);return e.encode(Ia.RtcPBPolaris,Object.assign(Object.assign({},C),{r4Info:n}))}return{}})(this.codec,o,n);let s=e;/^https:\/\//.test(e)||(s=`https://${e}`);try{const e=yield r.httpReq({url:`${s}/rtc/logserver/polaris`,body:i,method:t.HttpMethod.POST,headers:{jwt:zo.jwtToken},timeout:2e3});if(!e.data)throw new Error("http request fail");return JSON.parse(e.data).resultCode}catch(e){return ln.REPORT_FAIL}}))}getRTCUserList(e){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcQueryListInput,{order:2}),{code:r,buffer:o}=yield this.context.rtcSignaling(e,da,!0,i);if(r!==t.ErrorCode.SUCCESS||!o)return{code:r};return{code:r,data:Oa(this.codec,o)}}))}joinLivingRoomAsAudience(e,r,o){return i(this,void 0,void 0,(function*(){const i=fa(this.codec,r,o);Jo(),Fo(r);const{code:n,buffer:s}=yield this.context.rtcSignaling(e,ca,!0,i);if(n!==t.ErrorCode.SUCCESS||!s)return{code:n};const{rtcToken:a,entries:d,roomCreateTime:c,userJoinTime:_}=this.codec.decode(Ia.RtcViewerJoinedOutput,s);return Vo(e,n,gt(e,d).sessionId,this.context.getCurrentId()),this.roomCreateTime=Tt(c),this.userJoinTime=Tt(_),{code:n,data:{token:a,kvEntries:d}}}))}quitLivingRoomAsAudience(e){return i(this,void 0,void 0,(function*(){const t=this.codec.encode(Ia.SetUserStatusInput,{status:0}),{code:i}=yield this.context.rtcSignaling(e,_a,!0,t);return i}))}rtcIdentityChange(e,r,o){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcInput,{roomType:gn.LIVE,broadcastType:o,identityChangeType:r,needSysChatroom:!1}),{code:n,buffer:s}=yield this.context.rtcSignaling(e,ua,!0,i);if(n!==t.ErrorCode.SUCCESS||!s)return{code:n};return{code:n,data:Oa(this.codec,s)}}))}requestRoomPK(e){return i(this,void 0,void 0,(function*(){const{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteTimeout:o,inviteInfo:n,roomId:s}=e,a=this.codec.encode(Ia.RtcInviteInput,{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,timeoutTime:o,inviteInfo:n}),{code:d}=yield this.context.rtcSignaling(s,ha,!0,a);return d}))}cancelRoomPK(e){return i(this,void 0,void 0,(function*(){const{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteInfo:o,roomId:n}=e,s=this.codec.encode(Ia.RtcCancelInviteInput,{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteInfo:o}),{code:a}=yield this.context.rtcSignaling(n,Ra,!0,s);return a}))}responseRoomPK(e){return i(this,void 0,void 0,(function*(){const{inviteUserId:t,inviteRoomId:i,inviteSessionId:r,content:o,key:n,value:s,agree:a,roomId:d}=e,c=this.codec.encode(Ia.RtcInviteAnswerInput,{inviteUserId:t,inviteRoomId:i,inviteSessionId:r,content:o,key:n,value:s,answerCode:a?1:0}),{code:_}=yield this.context.rtcSignaling(d,va,!0,c);return _}))}endRoomPK(e){return i(this,void 0,void 0,(function*(){const{endRoomId:t,sessionId:i,content:r,keys:o,roomId:n}=e,s=this.codec.encode(Ia.RtcEndInviteInput,{inviteRoomId:t,inviteSessionId:i,inviteContent:r,inviteRoomKeys:o}),{code:a}=yield this.context.rtcSignaling(n,Ca,!0,s);return a}))}getRTCJoinedUserInfo(e){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcQueryUserJoinedInput,{userId:e}),{code:r,buffer:o}=yield this.context.rtcSignaling("",pa,!0,i);if(r!==t.ErrorCode.SUCCESS||!o)return{code:r};return{code:r,data:(this.codec.decode(Ia.RtcQueryUserJoinedOutput,o).info||[]).map((e=>({deviceId:e.deviceId,roomId:e.roomId,joinTime:Tt(e.joinTime)})))}}))}pullRTCRoomEntry(e){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcPullKV,{timestamp:0,roomId:e}),{code:r,buffer:o}=yield this.context.rtcSignaling(e,la,!0,i);if(r!==t.ErrorCode.SUCCESS)return{code:r};const n=this.codec.decode(Ia.RtcKVOutput,o);let{entries:s,syncTime:a}=n;return s=(s||[]).map((e=>Object.assign(Object.assign({},e),{timestamp:Tt(e.timestamp)}))),{code:r,data:{kvEntries:s,syncTime:Tt(a)}}}))}pullRTCRoomStatus(e,r){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcRoomStatusInput,{version:r}),{code:o,buffer:n}=yield this.context.rtcSignaling(e,ga,!0,i);if(o!==t.ErrorCode.SUCCESS)return{code:o};return{code:o,data:this.codec.decode(Ia.RtcRoomStatusOutput,n)}}))}decodeRtcNotify(e){const{time:t,type:i,roomId:r}=this.codec.decode(Ia.RtcNotifyMsg,e);return{time:Tt(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,r,o){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcInput,{roomType:r,broadcastType:o}),{code:n,buffer:s}=yield this.context.rtcSignaling(e,Ta,!0,i);if(n!==t.ErrorCode.SUCCESS)return{code:n};const a=this.codec.decode(Ia.RtcOutput,s);return a.version=Tt(a.version),{code:n,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(Ia.RtcReportSDKInput,{sdkInfo:JSON.stringify(e)});this.context.rtcSignaling("",ma,!0,t)}}var Na;!function(e){e.RTC="RTC"}(Na||(Na={}));const Aa={tag:"RCRTC",verify:e=>"browser"!==e.tag?(console.error(`RCRTC Plugin is not support the runtime '${e.tag}'`),!1):Qe?(t.VersionManage.add("plugin-rtc","5.6.6"),!!t.VersionManage.validEngine("^5.6.0")||(console.error(`The current engine version '${t.VersionManage.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,s,a,d,c,_,l,u;const h=e.createLogger("RCRTC",Na.RTC);return h.setOutputLevel(r.logLevel||t.LogL.DEBUG),Le.setLogger(h),Ne.setLogger(h),h.warn(o.L_INDEX_INSTALL_RTC_PLUGIN_O,JSON.stringify({"RCRTC Version":"5.6.6",Commit:"fc1865a049a26e89d0eb7e4cc4c2cbed81c19a38","browserInfo.browser":ut.browser,"browserInfo.supportsUnifiedPlan":ut.supportsUnifiedPlan,"browserInfo.version":ut.version})),t.assert("options.mediaServer",r.mediaServer,(e=>!(!t.isHttpUrl(e)||"https:"===location.protocol&&!/^https/.test(e)))),t.assert("options.timeout",r.timeout,(e=>t.isNumber(e)&&e>=5e3&&e<=3e4)),t.assert("options.pingGap",r.pingGap,(e=>t.isNumber(e)&&e>=3e3&&e<=1e4)),(null==r?void 0:r.audio)&&((null===(n=r.audio)||void 0===n?void 0:n.workletModule)&&(Me.workletModule=null===(s=r.audio)||void 0===s?void 0:s.workletModule),(null===(a=r.audio)||void 0===a?void 0:a.workletWasm)&&(Me.workletWasm=null===(d=r.audio)||void 0===d?void 0:d.workletWasm),(null===(c=r.audio)||void 0===c?void 0:c.workletModule)&&(null===(_=r.audio)||void 0===_?void 0:_.workletWasm)&&(Me.isOpen=!0),void 0!==(null===(l=r.audio)||void 0===l?void 0:l.isOpen)&&(Me.isOpen=null===(u=r.audio)||void 0===u?void 0:u.isOpen)),new Ys(new La(e,e.createCodec(Ea,Sa)),i,r)}},ya={transResolution:dt,transFrameRate:lt,parseTrackId:rt,ifSupportLocalFileTrack:ht,ifSupportScreenShare:Rt};e.RCAbstractRoom=Is,e.RCAudienceClient=Hs,e.RCAudienceLivingRoom=$s,e.RCCameraVideoTrack=Ge,e.RCLivingRoom=Bs,e.RCLocalAudioTrack=we,e.RCLocalFileAudioTrack=Je,e.RCLocalFileTrack=Ve,e.RCLocalFileVideoTrack=Fe,e.RCLocalTrack=xe,e.RCLocalVideoTrack=Be,e.RCMCUConfigBuilder=As,e.RCMediaStreamCapture=Ws,e.RCMicphoneAudioTrack=He,e.RCRTCClient=Ys,e.RCRTCRoom=Vs,e.RCRemoteAudioTrack=We,e.RCRemoteTrack=$e,e.RCRemoteVideoTrack=qe,e.RCScreenAudioTrack=je,e.RCScreenVideoTrack=Ke,e.RCTag={DEFAULT:"RongCloudRTC"},e.RCTrack=De,e.device=Ae,e.helper=ya,e.installer=Aa,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
16
|
+
/*! pako 2.0.4 https://github.com/nodeca/pako @license (MIT AND Zlib) */function ft(e){let t=e.length;for(;--t>=0;)e[t]=0}const Ot=256,Lt=286,Nt=30,At=15,yt=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]),kt=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]),Dt=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),bt=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ut=new Array(576);ft(Ut);const Pt=new Array(60);ft(Pt);const Mt=new Array(512);ft(Mt);const xt=new Array(256);ft(xt);const wt=new Array(29);ft(wt);const Bt=new Array(Nt);function Vt(e,t,i,r,o){this.static_tree=e,this.extra_bits=t,this.extra_base=i,this.elems=r,this.max_length=o,this.has_stree=e&&e.length}let Ft,Jt,Ht;function Gt(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}ft(Bt);const Kt=e=>e<256?Mt[e]:Mt[256+(e>>>7)],jt=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},$t=(e,t,i)=>{e.bi_valid>16-i?(e.bi_buf|=t<<e.bi_valid&65535,jt(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)},Wt=(e,t,i)=>{$t(e,i[2*t],i[2*t+1])},qt=(e,t)=>{let i=0;do{i|=1&e,e>>>=1,i<<=1}while(--t>0);return i>>>1},Yt=(e,t,i)=>{const r=new Array(16);let o,n,s=0;for(o=1;o<=At;o++)r[o]=s=s+i[o-1]<<1;for(n=0;n<=t;n++){let t=e[2*n+1];0!==t&&(e[2*n]=qt(r[t]++,t))}},zt=e=>{let t;for(t=0;t<Lt;t++)e.dyn_ltree[2*t]=0;for(t=0;t<Nt;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},Zt=e=>{e.bi_valid>8?jt(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},Qt=(e,t,i,r)=>{const o=2*t,n=2*i;return e[o]<e[n]||e[o]===e[n]&&r[t]<=r[i]},Xt=(e,t,i)=>{const r=e.heap[i];let o=i<<1;for(;o<=e.heap_len&&(o<e.heap_len&&Qt(t,e.heap[o+1],e.heap[o],e.depth)&&o++,!Qt(t,r,e.heap[o],e.depth));)e.heap[i]=e.heap[o],i=o,o<<=1;e.heap[i]=r},ei=(e,t,i)=>{let r,o,n,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],o=e.pending_buf[e.l_buf+a],a++,0===r?Wt(e,o,t):(n=xt[o],Wt(e,n+Ot+1,t),s=yt[n],0!==s&&(o-=wt[n],$t(e,o,s)),r--,n=Kt(r),Wt(e,n,i),s=kt[n],0!==s&&(r-=Bt[n],$t(e,r,s)))}while(a<e.last_lit);Wt(e,256,t)},ti=(e,t)=>{const i=t.dyn_tree,r=t.stat_desc.static_tree,o=t.stat_desc.has_stree,n=t.stat_desc.elems;let s,a,d,c=-1;for(e.heap_len=0,e.heap_max=573,s=0;s<n;s++)0!==i[2*s]?(e.heap[++e.heap_len]=c=s,e.depth[s]=0):i[2*s+1]=0;for(;e.heap_len<2;)d=e.heap[++e.heap_len]=c<2?++c:0,i[2*d]=1,e.depth[d]=0,e.opt_len--,o&&(e.static_len-=r[2*d+1]);for(t.max_code=c,s=e.heap_len>>1;s>=1;s--)Xt(e,i,s);d=n;do{s=e.heap[1],e.heap[1]=e.heap[e.heap_len--],Xt(e,i,1),a=e.heap[1],e.heap[--e.heap_max]=s,e.heap[--e.heap_max]=a,i[2*d]=i[2*s]+i[2*a],e.depth[d]=(e.depth[s]>=e.depth[a]?e.depth[s]:e.depth[a])+1,i[2*s+1]=i[2*a+1]=d,e.heap[1]=d++,Xt(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,o=t.stat_desc.static_tree,n=t.stat_desc.has_stree,s=t.stat_desc.extra_bits,a=t.stat_desc.extra_base,d=t.stat_desc.max_length;let c,_,l,u,h,R,v=0;for(u=0;u<=At;u++)e.bl_count[u]=0;for(i[2*e.heap[e.heap_max]+1]=0,c=e.heap_max+1;c<573;c++)_=e.heap[c],u=i[2*i[2*_+1]+1]+1,u>d&&(u=d,v++),i[2*_+1]=u,_>r||(e.bl_count[u]++,h=0,_>=a&&(h=s[_-a]),R=i[2*_],e.opt_len+=R*(u+h),n&&(e.static_len+=R*(o[2*_+1]+h)));if(0!==v){do{for(u=d-1;0===e.bl_count[u];)u--;e.bl_count[u]--,e.bl_count[u+1]+=2,e.bl_count[d]--,v-=2}while(v>0);for(u=d;0!==u;u--)for(_=e.bl_count[u];0!==_;)l=e.heap[--c],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),Yt(i,c,e.bl_count)},ii=(e,t,i)=>{let r,o,n=-1,s=t[1],a=0,d=7,c=4;for(0===s&&(d=138,c=3),t[2*(i+1)+1]=65535,r=0;r<=i;r++)o=s,s=t[2*(r+1)+1],++a<d&&o===s||(a<c?e.bl_tree[2*o]+=a:0!==o?(o!==n&&e.bl_tree[2*o]++,e.bl_tree[32]++):a<=10?e.bl_tree[34]++:e.bl_tree[36]++,a=0,n=o,0===s?(d=138,c=3):o===s?(d=6,c=3):(d=7,c=4))},ri=(e,t,i)=>{let r,o,n=-1,s=t[1],a=0,d=7,c=4;for(0===s&&(d=138,c=3),r=0;r<=i;r++)if(o=s,s=t[2*(r+1)+1],!(++a<d&&o===s)){if(a<c)do{Wt(e,o,e.bl_tree)}while(0!=--a);else 0!==o?(o!==n&&(Wt(e,o,e.bl_tree),a--),Wt(e,16,e.bl_tree),$t(e,a-3,2)):a<=10?(Wt(e,17,e.bl_tree),$t(e,a-3,3)):(Wt(e,18,e.bl_tree),$t(e,a-11,7));a=0,n=o,0===s?(d=138,c=3):o===s?(d=6,c=3):(d=7,c=4)}};let oi=!1;const ni=(e,t,i,r)=>{$t(e,0+(r?1:0),3),((e,t,i,r)=>{Zt(e),r&&(jt(e,i),jt(e,~i)),e.pending_buf.set(e.window.subarray(t,t+i),e.pending),e.pending+=i})(e,t,i,!0)};var si=(e,t,i,r)=>{let o,n,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<Ot;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0})(e)),ti(e,e.l_desc),ti(e,e.d_desc),s=(e=>{let t;for(ii(e,e.dyn_ltree,e.l_desc.max_code),ii(e,e.dyn_dtree,e.d_desc.max_code),ti(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*bt[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),o=e.opt_len+3+7>>>3,n=e.static_len+3+7>>>3,n<=o&&(o=n)):o=n=i+5,i+4<=o&&-1!==t?ni(e,t,i,r):4===e.strategy||n===o?($t(e,2+(r?1:0),3),ei(e,Ut,Pt)):($t(e,4+(r?1:0),3),((e,t,i,r)=>{let o;for($t(e,t-257,5),$t(e,i-1,5),$t(e,r-4,4),o=0;o<r;o++)$t(e,e.bl_tree[2*bt[o]+1],3);ri(e,e.dyn_ltree,t-1),ri(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)),zt(e),r&&Zt(e)},ai={_tr_init:e=>{oi||((()=>{let e,t,i,r,o;const n=new Array(16);for(i=0,r=0;r<28;r++)for(wt[r]=i,e=0;e<1<<yt[r];e++)xt[i++]=r;for(xt[i-1]=r,o=0,r=0;r<16;r++)for(Bt[r]=o,e=0;e<1<<kt[r];e++)Mt[o++]=r;for(o>>=7;r<Nt;r++)for(Bt[r]=o<<7,e=0;e<1<<kt[r]-7;e++)Mt[256+o++]=r;for(t=0;t<=At;t++)n[t]=0;for(e=0;e<=143;)Ut[2*e+1]=8,e++,n[8]++;for(;e<=255;)Ut[2*e+1]=9,e++,n[9]++;for(;e<=279;)Ut[2*e+1]=7,e++,n[7]++;for(;e<=287;)Ut[2*e+1]=8,e++,n[8]++;for(Yt(Ut,287,n),e=0;e<Nt;e++)Pt[2*e+1]=5,Pt[2*e]=qt(e,5);Ft=new Vt(Ut,yt,257,Lt,At),Jt=new Vt(Pt,kt,0,Nt,At),Ht=new Vt(new Array(0),Dt,0,19,7)})(),oi=!0),e.l_desc=new Gt(e.dyn_ltree,Ft),e.d_desc=new Gt(e.dyn_dtree,Jt),e.bl_desc=new Gt(e.bl_tree,Ht),e.bi_buf=0,e.bi_valid=0,zt(e)},_tr_stored_block:ni,_tr_flush_block:si,_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*(xt[i]+Ot+1)]++,e.dyn_dtree[2*Kt(t)]++),e.last_lit===e.lit_bufsize-1),_tr_align:e=>{$t(e,2,3),Wt(e,256,Ut),(e=>{16===e.bi_valid?(jt(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 di=(e,t,i,r)=>{let o=65535&e|0,n=e>>>16&65535|0,s=0;for(;0!==i;){s=i>2e3?2e3:i,i-=s;do{o=o+t[r++]|0,n=n+o|0}while(--s);o%=65521,n%=65521}return o|n<<16|0};const ci=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 _i=(e,t,i,r)=>{const o=ci,n=r+i;e^=-1;for(let i=r;i<n;i++)e=e>>>8^o[255&(e^t[i])];return-1^e},li={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"},ui={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:hi,_tr_stored_block:Ri,_tr_flush_block:vi,_tr_tally:Ci,_tr_align:pi}=ai,{Z_NO_FLUSH:gi,Z_PARTIAL_FLUSH:mi,Z_FULL_FLUSH:Ti,Z_FINISH:Ii,Z_BLOCK:Ei,Z_OK:Si,Z_STREAM_END:fi,Z_STREAM_ERROR:Oi,Z_DATA_ERROR:Li,Z_BUF_ERROR:Ni,Z_DEFAULT_COMPRESSION:Ai,Z_FILTERED:yi,Z_HUFFMAN_ONLY:ki,Z_RLE:Di,Z_FIXED:bi,Z_DEFAULT_STRATEGY:Ui,Z_UNKNOWN:Pi,Z_DEFLATED:Mi}=ui,xi=258,wi=262,Bi=103,Vi=113,Fi=666,Ji=(e,t)=>(e.msg=li[t],t),Hi=e=>(e<<1)-(e>4?9:0),Gi=e=>{let t=e.length;for(;--t>=0;)e[t]=0};let Ki=(e,t,i)=>(t<<e.hash_shift^i)&e.hash_mask;const ji=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))},$i=(e,t)=>{vi(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,ji(e.strm)},Wi=(e,t)=>{e.pending_buf[e.pending++]=t},qi=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},Yi=(e,t,i,r)=>{let o=e.avail_in;return o>r&&(o=r),0===o?0:(e.avail_in-=o,t.set(e.input.subarray(e.next_in,e.next_in+o),i),1===e.state.wrap?e.adler=di(e.adler,t,o,i):2===e.state.wrap&&(e.adler=_i(e.adler,t,o,i)),e.next_in+=o,e.total_in+=o,o)},zi=(e,t)=>{let i,r,o=e.max_chain_length,n=e.strstart,s=e.prev_length,a=e.nice_match;const d=e.strstart>e.w_size-wi?e.strstart-(e.w_size-wi):0,c=e.window,_=e.w_mask,l=e.prev,u=e.strstart+xi;let h=c[n+s-1],R=c[n+s];e.prev_length>=e.good_match&&(o>>=2),a>e.lookahead&&(a=e.lookahead);do{if(i=t,c[i+s]===R&&c[i+s-1]===h&&c[i]===c[n]&&c[++i]===c[n+1]){n+=2,i++;do{}while(c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&n<u);if(r=xi-(u-n),n=u-xi,r>s){if(e.match_start=t,s=r,r>=a)break;h=c[n+s-1],R=c[n+s]}}}while((t=l[t&_])>d&&0!=--o);return s<=e.lookahead?s:e.lookahead},Zi=e=>{const t=e.w_size;let i,r,o,n,s;do{if(n=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-wi)){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{o=e.head[--i],e.head[i]=o>=t?o-t:0}while(--r);r=t,i=r;do{o=e.prev[--i],e.prev[i]=o>=t?o-t:0}while(--r);n+=t}if(0===e.strm.avail_in)break;if(r=Yi(e.strm,e.window,e.strstart+e.lookahead,n),e.lookahead+=r,e.lookahead+e.insert>=3)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=Ki(e,e.ins_h,e.window[s+1]);e.insert&&(e.ins_h=Ki(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<wi&&0!==e.strm.avail_in)},Qi=(e,t)=>{let i,r;for(;;){if(e.lookahead<wi){if(Zi(e),e.lookahead<wi&&t===gi)return 1;if(0===e.lookahead)break}if(i=0,e.lookahead>=3&&(e.ins_h=Ki(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-wi&&(e.match_length=zi(e,i)),e.match_length>=3)if(r=Ci(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=Ki(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=Ki(e,e.ins_h,e.window[e.strstart+1]);else r=Ci(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(r&&($i(e,!1),0===e.strm.avail_out))return 1}return e.insert=e.strstart<2?e.strstart:2,t===Ii?($i(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&($i(e,!1),0===e.strm.avail_out)?1:2},Xi=(e,t)=>{let i,r,o;for(;;){if(e.lookahead<wi){if(Zi(e),e.lookahead<wi&&t===gi)return 1;if(0===e.lookahead)break}if(i=0,e.lookahead>=3&&(e.ins_h=Ki(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-wi&&(e.match_length=zi(e,i),e.match_length<=5&&(e.strategy===yi||3===e.match_length&&e.strstart-e.match_start>4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){o=e.strstart+e.lookahead-3,r=Ci(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do{++e.strstart<=o&&(e.ins_h=Ki(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&&($i(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if(r=Ci(e,0,e.window[e.strstart-1]),r&&$i(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=Ci(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===Ii?($i(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&($i(e,!1),0===e.strm.avail_out)?1:2};function er(e,t,i,r,o){this.good_length=e,this.max_lazy=t,this.nice_length=i,this.max_chain=r,this.func=o}const tr=[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(Zi(e),0===e.lookahead&&t===gi)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,$i(e,!1),0===e.strm.avail_out))return 1;if(e.strstart-e.block_start>=e.w_size-wi&&($i(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ii?($i(e,!0),0===e.strm.avail_out?3:4):(e.strstart>e.block_start&&($i(e,!1),e.strm.avail_out),1)})),new er(4,4,8,4,Qi),new er(4,5,16,8,Qi),new er(4,6,32,32,Qi),new er(4,4,16,16,Xi),new er(8,16,32,32,Xi),new er(8,16,128,128,Xi),new er(8,32,128,256,Xi),new er(32,128,258,1024,Xi),new er(32,258,258,4096,Xi)];function ir(){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=Mi,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),Gi(this.dyn_ltree),Gi(this.dyn_dtree),Gi(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),Gi(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),Gi(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 rr=e=>{if(!e||!e.state)return Ji(e,Oi);e.total_in=e.total_out=0,e.data_type=Pi;const t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?42:Vi,e.adler=2===t.wrap?0:1,t.last_flush=gi,hi(t),Si},or=e=>{const t=rr(e);var i;return t===Si&&((i=e.state).window_size=2*i.w_size,Gi(i.head),i.max_lazy_match=tr[i.level].max_lazy,i.good_match=tr[i.level].good_length,i.nice_match=tr[i.level].nice_length,i.max_chain_length=tr[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},nr=(e,t,i,r,o,n)=>{if(!e)return Oi;let s=1;if(t===Ai&&(t=6),r<0?(s=0,r=-r):r>15&&(s=2,r-=16),o<1||o>9||i!==Mi||r<8||r>15||t<0||t>9||n<0||n>bi)return Ji(e,Oi);8===r&&(r=9);const a=new ir;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=o+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<<o+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=n,a.method=i,or(e)};var sr={deflateInit:(e,t)=>nr(e,t,Mi,15,8,Ui),deflateInit2:nr,deflateReset:or,deflateResetKeep:rr,deflateSetHeader:(e,t)=>e&&e.state?2!==e.state.wrap?Oi:(e.state.gzhead=t,Si):Oi,deflate:(e,t)=>{let i,r;if(!e||!e.state||t>Ei||t<0)return e?Ji(e,Oi):Oi;const o=e.state;if(!e.output||!e.input&&0!==e.avail_in||o.status===Fi&&t!==Ii)return Ji(e,0===e.avail_out?Ni:Oi);o.strm=e;const n=o.last_flush;if(o.last_flush=t,42===o.status)if(2===o.wrap)e.adler=0,Wi(o,31),Wi(o,139),Wi(o,8),o.gzhead?(Wi(o,(o.gzhead.text?1:0)+(o.gzhead.hcrc?2:0)+(o.gzhead.extra?4:0)+(o.gzhead.name?8:0)+(o.gzhead.comment?16:0)),Wi(o,255&o.gzhead.time),Wi(o,o.gzhead.time>>8&255),Wi(o,o.gzhead.time>>16&255),Wi(o,o.gzhead.time>>24&255),Wi(o,9===o.level?2:o.strategy>=ki||o.level<2?4:0),Wi(o,255&o.gzhead.os),o.gzhead.extra&&o.gzhead.extra.length&&(Wi(o,255&o.gzhead.extra.length),Wi(o,o.gzhead.extra.length>>8&255)),o.gzhead.hcrc&&(e.adler=_i(e.adler,o.pending_buf,o.pending,0)),o.gzindex=0,o.status=69):(Wi(o,0),Wi(o,0),Wi(o,0),Wi(o,0),Wi(o,0),Wi(o,9===o.level?2:o.strategy>=ki||o.level<2?4:0),Wi(o,3),o.status=Vi);else{let t=Mi+(o.w_bits-8<<4)<<8,i=-1;i=o.strategy>=ki||o.level<2?0:o.level<6?1:6===o.level?2:3,t|=i<<6,0!==o.strstart&&(t|=32),t+=31-t%31,o.status=Vi,qi(o,t),0!==o.strstart&&(qi(o,e.adler>>>16),qi(o,65535&e.adler)),e.adler=1}if(69===o.status)if(o.gzhead.extra){for(i=o.pending;o.gzindex<(65535&o.gzhead.extra.length)&&(o.pending!==o.pending_buf_size||(o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),ji(e),i=o.pending,o.pending!==o.pending_buf_size));)Wi(o,255&o.gzhead.extra[o.gzindex]),o.gzindex++;o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),o.gzindex===o.gzhead.extra.length&&(o.gzindex=0,o.status=73)}else o.status=73;if(73===o.status)if(o.gzhead.name){i=o.pending;do{if(o.pending===o.pending_buf_size&&(o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),ji(e),i=o.pending,o.pending===o.pending_buf_size)){r=1;break}r=o.gzindex<o.gzhead.name.length?255&o.gzhead.name.charCodeAt(o.gzindex++):0,Wi(o,r)}while(0!==r);o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),0===r&&(o.gzindex=0,o.status=91)}else o.status=91;if(91===o.status)if(o.gzhead.comment){i=o.pending;do{if(o.pending===o.pending_buf_size&&(o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),ji(e),i=o.pending,o.pending===o.pending_buf_size)){r=1;break}r=o.gzindex<o.gzhead.comment.length?255&o.gzhead.comment.charCodeAt(o.gzindex++):0,Wi(o,r)}while(0!==r);o.gzhead.hcrc&&o.pending>i&&(e.adler=_i(e.adler,o.pending_buf,o.pending-i,i)),0===r&&(o.status=Bi)}else o.status=Bi;if(o.status===Bi&&(o.gzhead.hcrc?(o.pending+2>o.pending_buf_size&&ji(e),o.pending+2<=o.pending_buf_size&&(Wi(o,255&e.adler),Wi(o,e.adler>>8&255),e.adler=0,o.status=Vi)):o.status=Vi),0!==o.pending){if(ji(e),0===e.avail_out)return o.last_flush=-1,Si}else if(0===e.avail_in&&Hi(t)<=Hi(n)&&t!==Ii)return Ji(e,Ni);if(o.status===Fi&&0!==e.avail_in)return Ji(e,Ni);if(0!==e.avail_in||0!==o.lookahead||t!==gi&&o.status!==Fi){let i=o.strategy===ki?((e,t)=>{let i;for(;;){if(0===e.lookahead&&(Zi(e),0===e.lookahead)){if(t===gi)return 1;break}if(e.match_length=0,i=Ci(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,i&&($i(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ii?($i(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&($i(e,!1),0===e.strm.avail_out)?1:2})(o,t):o.strategy===Di?((e,t)=>{let i,r,o,n;const s=e.window;for(;;){if(e.lookahead<=xi){if(Zi(e),e.lookahead<=xi&&t===gi)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(o=e.strstart-1,r=s[o],r===s[++o]&&r===s[++o]&&r===s[++o])){n=e.strstart+xi;do{}while(r===s[++o]&&r===s[++o]&&r===s[++o]&&r===s[++o]&&r===s[++o]&&r===s[++o]&&r===s[++o]&&r===s[++o]&&o<n);e.match_length=xi-(n-o),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(i=Ci(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(i=Ci(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),i&&($i(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ii?($i(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&($i(e,!1),0===e.strm.avail_out)?1:2})(o,t):tr[o.level].func(o,t);if(3!==i&&4!==i||(o.status=Fi),1===i||3===i)return 0===e.avail_out&&(o.last_flush=-1),Si;if(2===i&&(t===mi?pi(o):t!==Ei&&(Ri(o,0,0,!1),t===Ti&&(Gi(o.head),0===o.lookahead&&(o.strstart=0,o.block_start=0,o.insert=0))),ji(e),0===e.avail_out))return o.last_flush=-1,Si}return t!==Ii?Si:o.wrap<=0?fi:(2===o.wrap?(Wi(o,255&e.adler),Wi(o,e.adler>>8&255),Wi(o,e.adler>>16&255),Wi(o,e.adler>>24&255),Wi(o,255&e.total_in),Wi(o,e.total_in>>8&255),Wi(o,e.total_in>>16&255),Wi(o,e.total_in>>24&255)):(qi(o,e.adler>>>16),qi(o,65535&e.adler)),ji(e),o.wrap>0&&(o.wrap=-o.wrap),0!==o.pending?Si:fi)},deflateEnd:e=>{if(!e||!e.state)return Oi;const t=e.state.status;return 42!==t&&69!==t&&73!==t&&91!==t&&t!==Bi&&t!==Vi&&t!==Fi?Ji(e,Oi):(e.state=null,t===Vi?Ji(e,Li):Si)},deflateSetDictionary:(e,t)=>{let i=t.length;if(!e||!e.state)return Oi;const r=e.state,o=r.wrap;if(2===o||1===o&&42!==r.status||r.lookahead)return Oi;if(1===o&&(e.adler=di(e.adler,t,i,0)),r.wrap=0,i>=r.w_size){0===o&&(Gi(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 n=e.avail_in,s=e.next_in,a=e.input;for(e.avail_in=i,e.next_in=0,e.input=t,Zi(r);r.lookahead>=3;){let e=r.strstart,t=r.lookahead-2;do{r.ins_h=Ki(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,Zi(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=n,r.wrap=o,Si},deflateInfo:"pako deflate (from Nodeca project)"};const ar=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var dr=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)ar(i,t)&&(e[t]=i[t])}}return e},cr=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,o=e.length;t<o;t++){let o=e[t];i.set(o,r),r+=o.length}return i};let _r=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(e){_r=!1}const lr=new Uint8Array(256);for(let e=0;e<256;e++)lr[e]=e>=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;lr[254]=lr[254]=1;var ur=e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);let t,i,r,o,n,s=e.length,a=0;for(o=0;o<s;o++)i=e.charCodeAt(o),55296==(64512&i)&&o+1<s&&(r=e.charCodeAt(o+1),56320==(64512&r)&&(i=65536+(i-55296<<10)+(r-56320),o++)),a+=i<128?1:i<2048?2:i<65536?3:4;for(t=new Uint8Array(a),n=0,o=0;n<a;o++)i=e.charCodeAt(o),55296==(64512&i)&&o+1<s&&(r=e.charCodeAt(o+1),56320==(64512&r)&&(i=65536+(i-55296<<10)+(r-56320),o++)),i<128?t[n++]=i:i<2048?(t[n++]=192|i>>>6,t[n++]=128|63&i):i<65536?(t[n++]=224|i>>>12,t[n++]=128|i>>>6&63,t[n++]=128|63&i):(t[n++]=240|i>>>18,t[n++]=128|i>>>12&63,t[n++]=128|i>>>6&63,t[n++]=128|63&i);return t},hr=(e,t)=>{const i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));let r,o;const n=new Array(2*i);for(o=0,r=0;r<i;){let t=e[r++];if(t<128){n[o++]=t;continue}let s=lr[t];if(s>4)n[o++]=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?n[o++]=65533:t<65536?n[o++]=t:(t-=65536,n[o++]=55296|t>>10&1023,n[o++]=56320|1023&t)}}return((e,t)=>{if(t<65534&&e.subarray&&_r)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})(n,o)},Rr=(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+lr[e[i]]>t?i:t};var vr=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 Cr=Object.prototype.toString,{Z_NO_FLUSH:pr,Z_SYNC_FLUSH:gr,Z_FULL_FLUSH:mr,Z_FINISH:Tr,Z_OK:Ir,Z_STREAM_END:Er,Z_DEFAULT_COMPRESSION:Sr,Z_DEFAULT_STRATEGY:fr,Z_DEFLATED:Or}=ui;function Lr(e){this.options=dr({level:Sr,method:Or,chunkSize:16384,windowBits:15,memLevel:8,strategy:fr},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 vr,this.strm.avail_out=0;let i=sr.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(i!==Ir)throw new Error(li[i]);if(t.header&&sr.deflateSetHeader(this.strm,t.header),t.dictionary){let e;if(e="string"==typeof t.dictionary?ur(t.dictionary):"[object ArrayBuffer]"===Cr.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,i=sr.deflateSetDictionary(this.strm,e),i!==Ir)throw new Error(li[i]);this._dict_set=!0}}function Nr(e,t){const i=new Lr(t);if(i.push(e,!0),i.err)throw i.msg||li[i.err];return i.result}Lr.prototype.push=function(e,t){const i=this.strm,r=this.options.chunkSize;let o,n;if(this.ended)return!1;for(n=t===~~t?t:!0===t?Tr:pr,"string"==typeof e?i.input=ur(e):"[object ArrayBuffer]"===Cr.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),(n===gr||n===mr)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(o=sr.deflate(i,n),o===Er)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),o=sr.deflateEnd(this.strm),this.onEnd(o),this.ended=!0,o===Ir;if(0!==i.avail_out){if(n>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},Lr.prototype.onData=function(e){this.chunks.push(e)},Lr.prototype.onEnd=function(e){e===Ir&&(this.result=cr(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var Ar={Deflate:Lr,deflate:Nr,deflateRaw:function(e,t){return(t=t||{}).raw=!0,Nr(e,t)},gzip:function(e,t){return(t=t||{}).gzip=!0,Nr(e,t)},constants:ui};var yr=function(e,t){let i,r,o,n,s,a,d,c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f,O;const L=e.state;i=e.next_in,f=e.input,r=i+(e.avail_in-5),o=e.next_out,O=e.output,n=o-(t-e.avail_out),s=o+(e.avail_out-257),a=L.dmax,d=L.wsize,c=L.whave,_=L.wnext,l=L.window,u=L.hold,h=L.bits,R=L.lencode,v=L.distcode,C=(1<<L.lenbits)-1,p=(1<<L.distbits)-1;e:do{h<15&&(u+=f[i++]<<h,h+=8,u+=f[i++]<<h,h+=8),g=R[u&C];t:for(;;){if(m=g>>>24,u>>>=m,h-=m,m=g>>>16&255,0===m)O[o++]=65535&g;else{if(!(16&m)){if(0==(64&m)){g=R[(65535&g)+(u&(1<<m)-1)];continue t}if(32&m){L.mode=12;break e}e.msg="invalid literal/length code",L.mode=30;break e}T=65535&g,m&=15,m&&(h<m&&(u+=f[i++]<<h,h+=8),T+=u&(1<<m)-1,u>>>=m,h-=m),h<15&&(u+=f[i++]<<h,h+=8,u+=f[i++]<<h,h+=8),g=v[u&p];i:for(;;){if(m=g>>>24,u>>>=m,h-=m,m=g>>>16&255,!(16&m)){if(0==(64&m)){g=v[(65535&g)+(u&(1<<m)-1)];continue i}e.msg="invalid distance code",L.mode=30;break e}if(I=65535&g,m&=15,h<m&&(u+=f[i++]<<h,h+=8,h<m&&(u+=f[i++]<<h,h+=8)),I+=u&(1<<m)-1,I>a){e.msg="invalid distance too far back",L.mode=30;break e}if(u>>>=m,h-=m,m=o-n,I>m){if(m=I-m,m>c&&L.sane){e.msg="invalid distance too far back",L.mode=30;break e}if(E=0,S=l,0===_){if(E+=d-m,m<T){T-=m;do{O[o++]=l[E++]}while(--m);E=o-I,S=O}}else if(_<m){if(E+=d+_-m,m-=_,m<T){T-=m;do{O[o++]=l[E++]}while(--m);if(E=0,_<T){m=_,T-=m;do{O[o++]=l[E++]}while(--m);E=o-I,S=O}}}else if(E+=_-m,m<T){T-=m;do{O[o++]=l[E++]}while(--m);E=o-I,S=O}for(;T>2;)O[o++]=S[E++],O[o++]=S[E++],O[o++]=S[E++],T-=3;T&&(O[o++]=S[E++],T>1&&(O[o++]=S[E++]))}else{E=o-I;do{O[o++]=O[E++],O[o++]=O[E++],O[o++]=O[E++],T-=3}while(T>2);T&&(O[o++]=O[E++],T>1&&(O[o++]=O[E++]))}break}}break}}while(i<r&&o<s);T=h>>3,i-=T,h-=T<<3,u&=(1<<h)-1,e.next_in=i,e.next_out=o,e.avail_in=i<r?r-i+5:5-(i-r),e.avail_out=o<s?s-o+257:257-(o-s),L.hold=u,L.bits=h};const kr=15,Dr=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]),br=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]),Ur=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]),Pr=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 Mr=(e,t,i,r,o,n,s,a)=>{const d=a.bits;let c,_,l,u,h,R,v=0,C=0,p=0,g=0,m=0,T=0,I=0,E=0,S=0,f=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<=kr;v++)N[v]=0;for(C=0;C<r;C++)N[t[i+C]]++;for(m=d,g=kr;g>=1&&0===N[g];g--);if(m>g&&(m=g),0===g)return o[n++]=20971520,o[n++]=20971520,a.bits=1,0;for(p=1;p<g&&0===N[p];p++);for(m<p&&(m=p),E=1,v=1;v<=kr;v++)if(E<<=1,E-=N[v],E<0)return-1;if(E>0&&(0===e||1!==g))return-1;for(A[1]=0,v=1;v<kr;v++)A[v+1]=A[v]+N[v];for(C=0;C<r;C++)0!==t[i+C]&&(s[A[t[i+C]]++]=C);if(0===e?(O=b=s,R=19):1===e?(O=Dr,L-=257,b=br,U-=257,R=256):(O=Ur,b=Pr,R=-1),f=0,C=0,v=p,h=n,T=m,I=0,l=-1,S=1<<m,u=S-1,1===e&&S>852||2===e&&S>592)return 1;for(;;){y=v-I,s[C]<R?(k=0,D=s[C]):s[C]>R?(k=b[U+s[C]],D=O[L+s[C]]):(k=96,D=0),c=1<<v-I,_=1<<T,p=_;do{_-=c,o[h+(f>>I)+_]=y<<24|k<<16|D|0}while(0!==_);for(c=1<<v-1;f&c;)c>>=1;if(0!==c?(f&=c-1,f+=c):f=0,C++,0==--N[v]){if(v===g)break;v=t[i+s[C]]}if(v>m&&(f&u)!==l){for(0===I&&(I=m),h+=p,T=v-I,E=1<<T;T+I<g&&(E-=N[T+I],!(E<=0));)T++,E<<=1;if(S+=1<<T,1===e&&S>852||2===e&&S>592)return 1;l=f&u,o[l]=m<<24|T<<16|h-n|0}}return 0!==f&&(o[h+f]=v-I<<24|64<<16|0),a.bits=m,0};const{Z_FINISH:xr,Z_BLOCK:wr,Z_TREES:Br,Z_OK:Vr,Z_STREAM_END:Fr,Z_NEED_DICT:Jr,Z_STREAM_ERROR:Hr,Z_DATA_ERROR:Gr,Z_MEM_ERROR:Kr,Z_BUF_ERROR:jr,Z_DEFLATED:$r}=ui,Wr=12,qr=30,Yr=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function zr(){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 Zr=e=>{if(!e||!e.state)return Hr;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,Vr},Qr=e=>{if(!e||!e.state)return Hr;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,Zr(e)},Xr=(e,t)=>{let i;if(!e||!e.state)return Hr;const r=e.state;return t<0?(i=0,t=-t):(i=1+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?Hr:(null!==r.window&&r.wbits!==t&&(r.window=null),r.wrap=i,r.wbits=t,Qr(e))},eo=(e,t)=>{if(!e)return Hr;const i=new zr;e.state=i,i.window=null;const r=Xr(e,t);return r!==Vr&&(e.state=null),r};let to,io,ro=!0;const oo=e=>{if(ro){to=new Int32Array(512),io=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(Mr(1,e.lens,0,288,to,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;Mr(2,e.lens,0,32,io,0,e.work,{bits:5}),ro=!1}e.lencode=to,e.lenbits=9,e.distcode=io,e.distbits=5},no=(e,t,i,r)=>{let o;const n=e.state;return null===n.window&&(n.wsize=1<<n.wbits,n.wnext=0,n.whave=0,n.window=new Uint8Array(n.wsize)),r>=n.wsize?(n.window.set(t.subarray(i-n.wsize,i),0),n.wnext=0,n.whave=n.wsize):(o=n.wsize-n.wnext,o>r&&(o=r),n.window.set(t.subarray(i-r,i-r+o),n.wnext),(r-=o)?(n.window.set(t.subarray(i-r,i),0),n.wnext=r,n.whave=n.wsize):(n.wnext+=o,n.wnext===n.wsize&&(n.wnext=0),n.whave<n.wsize&&(n.whave+=o))),0};var so={inflateReset:Qr,inflateReset2:Xr,inflateResetKeep:Zr,inflateInit:e=>eo(e,15),inflateInit2:eo,inflate:(e,t)=>{let i,r,o,n,s,a,d,c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f=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 Hr;i=e.state,i.mode===Wr&&(i.mode=13),s=e.next_out,o=e.output,d=e.avail_out,n=e.next_in,r=e.input,a=e.avail_in,c=i.hold,_=i.bits,l=a,u=d,S=Vr;e:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;_<16;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(2&i.wrap&&35615===c){i.check=0,O[0]=255&c,O[1]=c>>>8&255,i.check=_i(i.check,O,2,0),c=0,_=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&c)<<8)+(c>>8))%31){e.msg="incorrect header check",i.mode=qr;break}if((15&c)!==$r){e.msg="unknown compression method",i.mode=qr;break}if(c>>>=4,_-=4,E=8+(15&c),0===i.wbits)i.wbits=E;else if(E>i.wbits){e.msg="invalid window size",i.mode=qr;break}i.dmax=1<<i.wbits,e.adler=i.check=1,i.mode=512&c?10:Wr,c=0,_=0;break;case 2:for(;_<16;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(i.flags=c,(255&i.flags)!==$r){e.msg="unknown compression method",i.mode=qr;break}if(57344&i.flags){e.msg="unknown header flags set",i.mode=qr;break}i.head&&(i.head.text=c>>8&1),512&i.flags&&(O[0]=255&c,O[1]=c>>>8&255,i.check=_i(i.check,O,2,0)),c=0,_=0,i.mode=3;case 3:for(;_<32;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.head&&(i.head.time=c),512&i.flags&&(O[0]=255&c,O[1]=c>>>8&255,O[2]=c>>>16&255,O[3]=c>>>24&255,i.check=_i(i.check,O,4,0)),c=0,_=0,i.mode=4;case 4:for(;_<16;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.head&&(i.head.xflags=255&c,i.head.os=c>>8),512&i.flags&&(O[0]=255&c,O[1]=c>>>8&255,i.check=_i(i.check,O,2,0)),c=0,_=0,i.mode=5;case 5:if(1024&i.flags){for(;_<16;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.length=c,i.head&&(i.head.extra_len=c),512&i.flags&&(O[0]=255&c,O[1]=c>>>8&255,i.check=_i(i.check,O,2,0)),c=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&&(E=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(r.subarray(n,n+h),E)),512&i.flags&&(i.check=_i(i.check,r,h,n)),a-=h,n+=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{E=r[n+h++],i.head&&E&&i.length<65536&&(i.head.name+=String.fromCharCode(E))}while(E&&h<a);if(512&i.flags&&(i.check=_i(i.check,r,h,n)),a-=h,n+=h,E)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{E=r[n+h++],i.head&&E&&i.length<65536&&(i.head.comment+=String.fromCharCode(E))}while(E&&h<a);if(512&i.flags&&(i.check=_i(i.check,r,h,n)),a-=h,n+=h,E)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--,c+=r[n++]<<_,_+=8}if(c!==(65535&i.check)){e.msg="header crc mismatch",i.mode=qr;break}c=0,_=0}i.head&&(i.head.hcrc=i.flags>>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=Wr;break;case 10:for(;_<32;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}e.adler=i.check=Yr(c),c=0,_=0,i.mode=11;case 11:if(0===i.havedict)return e.next_out=s,e.avail_out=d,e.next_in=n,e.avail_in=a,i.hold=c,i.bits=_,Jr;e.adler=i.check=1,i.mode=Wr;case Wr:if(t===wr||t===Br)break e;case 13:if(i.last){c>>>=7&_,_-=7&_,i.mode=27;break}for(;_<3;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}switch(i.last=1&c,c>>>=1,_-=1,3&c){case 0:i.mode=14;break;case 1:if(oo(i),i.mode=20,t===Br){c>>>=2,_-=2;break e}break;case 2:i.mode=17;break;case 3:e.msg="invalid block type",i.mode=qr}c>>>=2,_-=2;break;case 14:for(c>>>=7&_,_-=7&_;_<32;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if((65535&c)!=(c>>>16^65535)){e.msg="invalid stored block lengths",i.mode=qr;break}if(i.length=65535&c,c=0,_=0,i.mode=15,t===Br)break e;case 15:i.mode=16;case 16:if(h=i.length,h){if(h>a&&(h=a),h>d&&(h=d),0===h)break e;o.set(r.subarray(n,n+h),s),a-=h,n+=h,d-=h,s+=h,i.length-=h;break}i.mode=Wr;break;case 17:for(;_<14;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(i.nlen=257+(31&c),c>>>=5,_-=5,i.ndist=1+(31&c),c>>>=5,_-=5,i.ncode=4+(15&c),c>>>=4,_-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=qr;break}i.have=0,i.mode=18;case 18:for(;i.have<i.ncode;){for(;_<3;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.lens[A[i.have++]]=7&c,c>>>=3,_-=3}for(;i.have<19;)i.lens[A[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,L={bits:i.lenbits},S=Mr(0,i.lens,0,19,i.lencode,0,i.work,L),i.lenbits=L.bits,S){e.msg="invalid code lengths set",i.mode=qr;break}i.have=0,i.mode=19;case 19:for(;i.have<i.nlen+i.ndist;){for(;f=i.lencode[c&(1<<i.lenbits)-1],C=f>>>24,p=f>>>16&255,g=65535&f,!(C<=_);){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(g<16)c>>>=C,_-=C,i.lens[i.have++]=g;else{if(16===g){for(N=C+2;_<N;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(c>>>=C,_-=C,0===i.have){e.msg="invalid bit length repeat",i.mode=qr;break}E=i.lens[i.have-1],h=3+(3&c),c>>>=2,_-=2}else if(17===g){for(N=C+3;_<N;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}c>>>=C,_-=C,E=0,h=3+(7&c),c>>>=3,_-=3}else{for(N=C+7;_<N;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}c>>>=C,_-=C,E=0,h=11+(127&c),c>>>=7,_-=7}if(i.have+h>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=qr;break}for(;h--;)i.lens[i.have++]=E}}if(i.mode===qr)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=qr;break}if(i.lenbits=9,L={bits:i.lenbits},S=Mr(1,i.lens,0,i.nlen,i.lencode,0,i.work,L),i.lenbits=L.bits,S){e.msg="invalid literal/lengths set",i.mode=qr;break}if(i.distbits=6,i.distcode=i.distdyn,L={bits:i.distbits},S=Mr(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,L),i.distbits=L.bits,S){e.msg="invalid distances set",i.mode=qr;break}if(i.mode=20,t===Br)break e;case 20:i.mode=21;case 21:if(a>=6&&d>=258){e.next_out=s,e.avail_out=d,e.next_in=n,e.avail_in=a,i.hold=c,i.bits=_,yr(e,u),s=e.next_out,o=e.output,d=e.avail_out,n=e.next_in,r=e.input,a=e.avail_in,c=i.hold,_=i.bits,i.mode===Wr&&(i.back=-1);break}for(i.back=0;f=i.lencode[c&(1<<i.lenbits)-1],C=f>>>24,p=f>>>16&255,g=65535&f,!(C<=_);){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(p&&0==(240&p)){for(m=C,T=p,I=g;f=i.lencode[I+((c&(1<<m+T)-1)>>m)],C=f>>>24,p=f>>>16&255,g=65535&f,!(m+C<=_);){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}c>>>=m,_-=m,i.back+=m}if(c>>>=C,_-=C,i.back+=C,i.length=g,0===p){i.mode=26;break}if(32&p){i.back=-1,i.mode=Wr;break}if(64&p){e.msg="invalid literal/length code",i.mode=qr;break}i.extra=15&p,i.mode=22;case 22:if(i.extra){for(N=i.extra;_<N;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.length+=c&(1<<i.extra)-1,c>>>=i.extra,_-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;f=i.distcode[c&(1<<i.distbits)-1],C=f>>>24,p=f>>>16&255,g=65535&f,!(C<=_);){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(0==(240&p)){for(m=C,T=p,I=g;f=i.distcode[I+((c&(1<<m+T)-1)>>m)],C=f>>>24,p=f>>>16&255,g=65535&f,!(m+C<=_);){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}c>>>=m,_-=m,i.back+=m}if(c>>>=C,_-=C,i.back+=C,64&p){e.msg="invalid distance code",i.mode=qr;break}i.offset=g,i.extra=15&p,i.mode=24;case 24:if(i.extra){for(N=i.extra;_<N;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}i.offset+=c&(1<<i.extra)-1,c>>>=i.extra,_-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=qr;break}i.mode=25;case 25:if(0===d)break e;if(h=u-d,i.offset>h){if(h=i.offset-h,h>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=qr;break}h>i.wnext?(h-=i.wnext,R=i.wsize-h):R=i.wnext-h,h>i.length&&(h=i.length),v=i.window}else v=o,R=s-i.offset,h=i.length;h>d&&(h=d),d-=h,i.length-=h;do{o[s++]=v[R++]}while(--h);0===i.length&&(i.mode=21);break;case 26:if(0===d)break e;o[s++]=i.length,d--,i.mode=21;break;case 27:if(i.wrap){for(;_<32;){if(0===a)break e;a--,c|=r[n++]<<_,_+=8}if(u-=d,e.total_out+=u,i.total+=u,u&&(e.adler=i.check=i.flags?_i(i.check,o,u,s-u):di(i.check,o,u,s-u)),u=d,(i.flags?c:Yr(c))!==i.check){e.msg="incorrect data check",i.mode=qr;break}c=0,_=0}i.mode=28;case 28:if(i.wrap&&i.flags){for(;_<32;){if(0===a)break e;a--,c+=r[n++]<<_,_+=8}if(c!==(4294967295&i.total)){e.msg="incorrect length check",i.mode=qr;break}c=0,_=0}i.mode=29;case 29:S=Fr;break e;case qr:S=Gr;break e;case 31:return Kr;default:return Hr}return e.next_out=s,e.avail_out=d,e.next_in=n,e.avail_in=a,i.hold=c,i.bits=_,(i.wsize||u!==e.avail_out&&i.mode<qr&&(i.mode<27||t!==xr))&&no(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?_i(i.check,o,u,e.next_out-u):di(i.check,o,u,e.next_out-u)),e.data_type=i.bits+(i.last?64:0)+(i.mode===Wr?128:0)+(20===i.mode||15===i.mode?256:0),(0===l&&0===u||t===xr)&&S===Vr&&(S=jr),S},inflateEnd:e=>{if(!e||!e.state)return Hr;let t=e.state;return t.window&&(t.window=null),e.state=null,Vr},inflateGetHeader:(e,t)=>{if(!e||!e.state)return Hr;const i=e.state;return 0==(2&i.wrap)?Hr:(i.head=t,t.done=!1,Vr)},inflateSetDictionary:(e,t)=>{const i=t.length;let r,o,n;return e&&e.state?(r=e.state,0!==r.wrap&&11!==r.mode?Hr:11===r.mode&&(o=1,o=di(o,t,i,0),o!==r.check)?Gr:(n=no(e,t,i,i),n?(r.mode=31,Kr):(r.havedict=1,Vr))):Hr},inflateInfo:"pako inflate (from Nodeca project)"};var ao=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 co=Object.prototype.toString,{Z_NO_FLUSH:_o,Z_FINISH:lo,Z_OK:uo,Z_STREAM_END:ho,Z_NEED_DICT:Ro,Z_STREAM_ERROR:vo,Z_DATA_ERROR:Co,Z_MEM_ERROR:po}=ui;function go(e){this.options=dr({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 vr,this.strm.avail_out=0;let i=so.inflateInit2(this.strm,t.windowBits);if(i!==uo)throw new Error(li[i]);if(this.header=new ao,so.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=ur(t.dictionary):"[object ArrayBuffer]"===co.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=so.inflateSetDictionary(this.strm,t.dictionary),i!==uo)))throw new Error(li[i])}go.prototype.push=function(e,t){const i=this.strm,r=this.options.chunkSize,o=this.options.dictionary;let n,s,a;if(this.ended)return!1;for(s=t===~~t?t:!0===t?lo:_o,"[object ArrayBuffer]"===co.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),n=so.inflate(i,s),n===Ro&&o&&(n=so.inflateSetDictionary(i,o),n===uo?n=so.inflate(i,s):n===Co&&(n=Ro));i.avail_in>0&&n===ho&&i.state.wrap>0&&0!==e[i.next_in];)so.inflateReset(i),n=so.inflate(i,s);switch(n){case vo:case Co:case Ro:case po:return this.onEnd(n),this.ended=!0,!1}if(a=i.avail_out,i.next_out&&(0===i.avail_out||n===ho))if("string"===this.options.to){let e=Rr(i.output,i.next_out),t=i.next_out-e,o=hr(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(o)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(n!==uo||0!==a){if(n===ho)return n=so.inflateEnd(this.strm),this.onEnd(n),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},go.prototype.onData=function(e){this.chunks.push(e)},go.prototype.onEnd=function(e){e===uo&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=cr(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};const{Deflate:mo,deflate:To,deflateRaw:Io,gzip:Eo}=Ar;var So=Eo;const fo=-1,Oo=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})),Lo=(e,r,o)=>i(void 0,void 0,void 0,(function*(){const n=[];return yield Promise.any(e.map((e=>i(void 0,void 0,void 0,(function*(){const i=`${e.detectorAddr.replace(/^(https?:\/\/)?/,"https://")}/rtc/detector/ping?t=${s=1e3,a=9999,s+Math.floor(Math.random()*(a-s))}`;var s,a;const d={jwt:o};if(200!==(yield r.httpReq({url:i,body:JSON.stringify(d),timeout:5e3,method:t.HttpMethod.POST})).status)return Promise.reject();n.push(e.clusterId)}))))),n})),No=e=>{if(!e)return"";return e.jwt||""},Ao=(e,r)=>i(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=Le.getLogger();return null==i||i.warn(o.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:""})(r),n=No(r);let s=null,a=120,d=0;const c={jwt:n};if(i&&n){const r=yield e.httpReq({url:`${i}/rtc/detector/servers`,body:JSON.stringify(c),headers:{"Content-Type":"application/json;charset=UTF-8","Cache-Control":"no-cache",ClientType:`web|${ut.browser}|${ut.version}`,ClientVersion:"5.6.7","Client-Session-Id":Oo(),"Request-Id":Date.now().toString()},method:t.HttpMethod.POST}),o=r.data&&JSON.parse(r.data).detectorAddrs;a=r.data&&JSON.parse(r.data).clientDetectMinute,d=r.data&&JSON.parse(r.data).resultCode,o&&t.isArray(o)&&(s=yield Lo(o,e,n))}return{fastMediaUrl:s,clientDetectMinute:a,status:d}}));var yo;e.RCKickReason=void 0,(yo=e.RCKickReason||(e.RCKickReason={}))[yo.SERVER_KICK=1]="SERVER_KICK",yo[yo.OTHER_KICK=2]="OTHER_KICK";const ko={[String(e.RCKickReason.SERVER_KICK)]:1,[String(e.RCKickReason.OTHER_KICK)]:5};class Do{constructor(){}static getMemo(){return this._memo||(this._memo={}),window.__memo__=this._memo,this._memo}static destroy(){this._memo={}}}var bo;Do._memo={},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"}(bo||(bo={}));const Uo=(e,t,i)=>{var r;const o=Do.getMemo(),n={dur:0,cod:0,rid:e,csnid:t||(null===(r=o.clientData)||void 0===r?void 0:r.clientSessionId)||"",snid:i,rsid:"",msa:"",msas:[],time:0,resid:"",mtp:0,smct:1,cr:"unknown",net:"unknown",uid:"",stp:0};o.qualitySubscribeReportData=n,o.subscribeData={start:Date.now()}},Po=(e,t,i)=>{var r;const o=Do.getMemo(),n={dur:0,cod:0,rid:e,csnid:t||(null===(r=o.clientData)||void 0===r?void 0:r.clientSessionId)||"",snid:i,rsid:"",msa:"",msas:[],time:0,resid:"",mtp:0,smct:1,uid:"",stp:0};o.qualityUnsubscribeReportData=n,o.unsubscribeData={start:Date.now()}},Mo=e=>{const t=Do.getMemo();t.mediaService||(t.mediaService=[]),t.mediaService.push(e)},xo=()=>{Do.getMemo().mediaService=[]},wo=(e,t)=>{var i;const r=Do.getMemo();let n=[],s=Date.now();null===(i=r.mediaService)||void 0===i||i.forEach((e=>{n.push({rsid:e.reqId,rsdur:e.end-e.start,msa:e.url,rscod:e.status})})),r.subscribeCommand&&(r.subscribeCommand=!1,e.forEach((e=>{var i,a;const d=JSON.stringify(Object.assign(Object.assign({},r.qualitySubscribeReportData),{dur:s-((null===(i=r.subscribeData)||void 0===i?void 0:i.start)||0),cod:t,msas:n,time:s,resid:e.track.getTrackId(),mtp:rt(e.track.getTrackId()).mediaType,smct:e.track instanceof Be&&(null===(a=e.track)||void 0===a?void 0:a.__isTiny())?2:1}));Ne.__statistics(o.L_QS_SUBSCRIBE_S,d)}))),r.unsubscribeCommand&&(r.unsubscribeCommand=!1,e.forEach((e=>{var i,a;const d=JSON.stringify(Object.assign(Object.assign({},r.qualityUnsubscribeReportData),{dur:s-((null===(i=r.unsubscribeData)||void 0===i?void 0:i.start)||0),cod:t,time:s,msas:n,resid:e.track.getTrackId(),mtp:rt(e.track.getTrackId()).mediaType,smct:e.track instanceof Be&&(null===(a=e.track)||void 0===a?void 0:a.__isTiny())?2:1}));Ne.__statistics(o.L_QS_UNSUBSCRIBE_S,d)}))),xo()},Bo=e=>{var t,i,r,o,n;const s=Do.getMemo(),a=e.subscribe||(null===(t=s.iceStatusData)||void 0===t?void 0:t.subscribe),d=e.publish||(null===(i=s.iceStatusData)||void 0===i?void 0:i.publish),c=e.publishNotReport||(null===(r=s.iceStatusData)||void 0===r?void 0:r.publishNotReport),_=e.subscribeNotReport||(null===(o=s.iceStatusData)||void 0===o?void 0:o.subscribeNotReport),l=e.notFirst||(null===(n=s.iceStatusData)||void 0===n?void 0:n.notFirst);s.iceStatusData={publish:d,subscribe:a,publishNotReport:c,subscribeNotReport:_,notFirst:l},s.iceNewStatusData&&(s.iceOldStatusData=s.iceNewStatusData),e.iceNewStatusData&&(s.iceNewStatusData=e.iceNewStatusData)},Vo=(e,t,i,r)=>{var n,s;const a=Do.getMemo(),d=Date.now(),c=JSON.stringify(Object.assign(Object.assign({},a.qualityJoinRoomReportData),{dur:d-((null===(n=a.joinRoomData)||void 0===n?void 0:n.start)||0),cod:t,rid:e,csnid:null===(s=a.clientData)||void 0===s?void 0:s.clientSessionId,snid:i,time:d,uid:r}));Ne.__statistics(o.L_QS_JOIN_ROOM_S,c)},Fo=e=>{const t={dur:0,cod:0,rid:"",rtp:e,csnid:"",snid:"",time:0,cr:"unknown",net:"unknown",uid:""};Do.getMemo().qualityJoinRoomReportData=t},Jo=e=>{var t;const i=Do.getMemo(),r=(null===(t=i.joinRoomData)||void 0===t?void 0:t.start)||Date.now();i.joinRoomData={start:r,roomId:e}},Ho=(e,t)=>{var i;const r=Do.getMemo(),n=Date.now();let s=[];null===(i=r.mediaService)||void 0===i||i.forEach((e=>{s.push({rsid:e.reqId,rsdur:e.end-e.start,msa:e.url,rscod:e.status})})),e.forEach((e=>{var i;const a=JSON.stringify(Object.assign(Object.assign({},r.qualityPublishReportData),{dur:n-((null===(i=r.publish)||void 0===i?void 0:i.start)||0),cod:t,msas:s,time:n,resid:e.getTrackId(),mtp:rt(e.getTrackId()).mediaType,smct:e instanceof Be&&e.__isTiny()?2:1}));Ne.__statistics(o.L_QS_PUBLISH_S,a)})),xo()},Go=(e,t)=>{var i,r;const n=Do.getMemo(),s=Date.now();let a=[];null===(i=n.mediaService)||void 0===i||i.forEach((e=>{a.push({rsid:e.reqId,rsdur:e.end-e.start,msa:e.url,rscod:e.status})}));const d=[];d.push({dur:Date.now()-((null===(r=n.publishSignalTotal)||void 0===r?void 0:r.start)||0),cod:t}),e.forEach((e=>{var i;const r=JSON.stringify(Object.assign(Object.assign({},n.qualityPublishReportData),{dur:s-((null===(i=n.publish)||void 0===i?void 0:i.start)||0),cod:t,msas:a,sigs:d,time:s,resid:it(e),mtp:e.mediaType,smct:e.simulcast}));Ne.__statistics(o.L_QS_PUBLISH_S,r)})),xo()},Ko=(e,t)=>{var i,r;const n=Do.getMemo(),s=Date.now();let a=[];null===(i=n.mediaService)||void 0===i||i.forEach((e=>{a.push({rsid:e.reqId,rsdur:e.end-e.start,msa:e.url,rscod:e.status})}));const d=[];d.push({dur:Date.now()-((null===(r=n.unpublishSignalTotal)||void 0===r?void 0:r.start)||0),cod:t}),e.forEach((e=>{var i;const r=e.getTrackId(),c=JSON.stringify(Object.assign(Object.assign({},n.qualityUnpublishReportData),{dur:s-((null===(i=n.unpublish)||void 0===i?void 0:i.start)||0),cod:t,msas:a,sigs:d,time:s,resid:r,mtp:rt(r).mediaType,smct:e instanceof Be&&e.__isTiny()?2:1}));Ne.__statistics(o.L_QS_UNPUBLISH_S,c)})),xo()},jo=(e,t)=>{var i,r;const n=Do.getMemo(),s=Date.now();let a=[];null===(i=n.mediaService)||void 0===i||i.forEach((e=>{a.push({rsid:e.reqId,rsdur:e.end-e.start,msa:e.url,rscod:e.status})}));const d=[];d.push({dur:Date.now()-((null===(r=n.unpublishSignalTotal)||void 0===r?void 0:r.start)||0),cod:t}),e.forEach((e=>{var i;if(e){const r=JSON.stringify(Object.assign(Object.assign({},n.qualityUnpublishReportData),{dur:s-((null===(i=n.publish)||void 0===i?void 0:i.start)||0),cod:t,msas:a,sigs:d,time:s,resid:it(e),mtp:e.mediaType,smct:e.simulcast}));Ne.__statistics(o.L_QS_UNPUBLISH_S,r)}})),xo()},$o=()=>{var e,t,i,r;const n=Do.getMemo(),s=JSON.stringify(Object.assign(Object.assign({},n.qualityIceStatusReportData),{dur:((null===(e=n.iceNewStatusData)||void 0===e?void 0:e.start)||0)-((null===(t=n.iceOldStatusData)||void 0===t?void 0:t.start)||0),pices:bo[(null===(i=n.iceOldStatusData)||void 0===i?void 0:i.status)||0],ices:bo[(null===(r=n.iceNewStatusData)||void 0===r?void 0:r.status)||0],time:Date.now(),cncdts:[]}));Ne.__statistics(o.L_QS_ICE_STATUS_S,s)},Wo=e=>{Do.getMemo().subscribeCommand=e},qo=e=>{Do.getMemo().unsubscribeCommand=e},Yo=()=>({"Content-Type":"application/json;charset=UTF-8","Cache-Control":"no-cache",ClientType:`web|${ut.browser}|${ut.version}`,ClientVersion:"5.6.7","Client-Session-Id":Oo(),"Request-Id":Date.now().toString()});class zo{constructor(e,i,r,o=5e3){this._runtime=e,this._context=i,this._msUrl=r,this._timeout=o,this._msInNavi=[],this._failedMs=[],this._rtcFinger=void 0,this._clusterId="",this._configUrl="",this._msList=[],zo.isDetector||i.getConnectionStatus()!==t.ConnectionStatus.CONNECTED||this.detectorMediaSever()}detectorMediaSever(){const e=this._context.getNaviInfo();if(zo.jwtToken=(null==e?void 0:e.jwt)||"",this._msUrl)return;const i=Date.now(),r=zo.detectValidMinute+zo.detectorTime>i;zo.isDetector=r,!r&&e&&t.notEmptyObject(e)&&(this._msList=[],this._getDetectorUrls(e))}_getDetectorUrls(t){return i(this,void 0,void 0,(function*(){if(zo.isDetector)return;zo.isDetector=!0;const{fastMediaUrl:i,clientDetectMinute:r,status:o}=yield Ao(this._runtime,t);if(o===e.RCRTCCode.JWT_TIME_OUT){const e=this._context.getPluginContext();yield e.refetchNaviInfo(),this.detectorMediaSever()}zo.msInDetector=i||[],zo.detectorTime=Date.now(),zo.detectValidMinute=60*r*1e3}))}getNaviMS(){return this._msUrl?[this._msUrl]:(t.notEmptyArray(this._msList)&&!this._clusterId||(this._msList=this.setMediaServiceList()),this._msList)}setMediaServiceList(){var e,i;let r=[],n=[];return this._clusterId&&(this._clusterId=this._clusterId.replace(/^(https?:\/\/)?/,"https://"),this._msList.push(this._clusterId)),t.notEmptyArray(zo.msInDetector)&&(zo.msInDetector=zo.msInDetector.map((e=>e.replace(/^(https?:\/\/)?/,"https://"))),this._msList.push(zo.msInDetector[0]),r=zo.msInDetector.concat().splice(1,zo.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=Le.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 o=r[0],n=[];return o.mediaServer&&n.push(o.mediaServer.replace(/^(https?:\/\/)?/,"https://")),o.backupMediaServer&&o.backupMediaServer.forEach((e=>{n.push(e.replace(/^(https?:\/\/)?/,"https://"))})),n})(this._context.getNaviInfo())):(this._msInNavi.push(...this._failedMs),this._failedMs.length=0)),n=this._msInNavi.concat().splice(1,this._msInNavi.length-1),this._msList.push(this._msInNavi[0]),this._msList=[...this._msList,...r,...n],this._msList=[...new Set(this._msList)],null===(i=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===i||i.info(o.L_MEDIA_SERVICE_MSLIST_CHANGE_O,`MediaServiceList msList -> ${JSON.stringify(this._msList)}`),this._msList}_request(r,s,a,d,c){var _,l,u,h,R,v,C,p,g;return i(this,void 0,void 0,(function*(){if((null===(_=this._context.getNaviInfo())||void 0===_?void 0:_.openGzip)||!1){const e=JSON.stringify(a),t=e.length,r=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=e.charCodeAt(i);const o={"Content-Encoding":"gzip","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"};s=Object.assign(Object.assign({},s),o),a=So(r,i)}var i;const m=this.getNaviMS();if(0===m.length)return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"have no valid service address"}),d),{code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER};this._rtcFinger&&(a.rtcFinger=this._rtcFinger);for(let i=0;i<m.length;i+=1){const _=Date.now(),l=`${m[i]}${r}`,u=Yo(),T=Object.assign(Object.assign({},u),s),I=/x-www-form-urlencoded/.test(T["Content-Type"])?a:JSON.stringify(a),E=u["Request-Id"];null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_MEDIA_SERVICE_REQUEST_T,JSON.stringify({url:l,"Request-Id":E}),d);const{status:S,data:f}=yield this._runtime.httpReq({url:l,body:I,headers:T,method:t.HttpMethod.POST,timeout:this._timeout});if(c&&Mo({start:_,end:Date.now(),reqId:E,status:S,url:l}),200===S){const t=JSON.parse(f);return t.rtcFinger&&(this._rtcFinger=t.rtcFinger),t.clusterId&&(this._clusterId=t.clusterId),null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.info(o.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:n.SUCCESSED,url:l}),d),{code:e.RCRTCCode.SUCCESS,data:t}}this._failedMs.push(...this._msInNavi.splice(i,1)),null===(g=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===g||g.error(o.L_MEDIA_SERVICE_REQUEST_R,JSON.stringify({status:n.FAILED,msg:`request error -> Request-Id: ${E}, status: ${S}, url: ${l}`,timeout:this._timeout}),d)}return{code:e.RCRTCCode.REQUEST_FAILED}}))}exchange(t,r,o,n){var s;return i(this,void 0,void 0,(function*(){const i=yield this._request("/exchange",t,r,o,n);if(i.code===e.RCRTCCode.SUCCESS&&(null===(s=i.data)||void 0===s?void 0:s.resultCode)===e.RCRTCCode.SUCCESS){const{urls:e}=i.data;e&&(this._configUrl=e.configUrl)}return i}))}exit(e){var t,r;return i(this,void 0,void 0,(function*(){const i=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId(),{code:o}=yield this._request("/exit",e,{},i);return o}))}broadcastSubscribe(e,t){var i,r;const o=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,o)}broadcastExit(e){var t,r;return i(this,void 0,void 0,(function*(){const i=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId(),{code:o}=yield this._request("/broadcast/exit",e,{},i);return{code:o}}))}setMcuConfig(r,s){var a,d,c,_,l,u,h,R,v,C;return i(this,void 0,void 0,(function*(){const i=null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d?void 0:d.createTraceId();if(null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_MEDIA_SERVICE_SET_MCU_CONFIG_T,JSON.stringify({body:s}),i),!this._configUrl)return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.MCU_SERVER_NOT_FOUND,msg:"MCU server not found"}),i),{code:e.RCRTCCode.MCU_SERVER_NOT_FOUND};const p=`${this._configUrl.replace(/^(https?:\/\/)?/,"https://")}/server/mcu/config`,g=Yo(),m=Object.assign(Object.assign({},g),r),T=JSON.stringify(s),I=g["Request-Id"],{status:E,data:S}=yield this._runtime.httpReq({url:p,headers:m,body:T,method:t.HttpMethod.POST});if(200===E){const e=JSON.parse(S);return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:n.SUCCESSED,"Request-Id":I}),i),{code:e.resultCode,res:e}}return null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.error(o.L_MEDIA_SERVICE_SET_MCU_CONFIG_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REQUEST_FAILED,msg:`request error -> Request-Id: ${I}, status: ${E}, url: ${p}`}),i),{code:e.RCRTCCode.REQUEST_FAILED}}))}getCDNResourceInfo(r,s,a){var d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const i=Yo(),R=Object.assign(Object.assign({},i),r),v=i["Request-Id"];null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_T,`Request-Id: ${v}, url: ${s}`,a);const{status:C,data:p}=yield this._runtime.httpReq({url:s,headers:R,method:t.HttpMethod.GET});if(200===C){const e=JSON.parse(p);return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_R,JSON.stringify({status:n.SUCCESSED,cdnPlayerUrl:null==e?void 0:e.data.pull_url}),a),{code:e.resultCode,res:e}}return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_MEDIA_SERVICE_GET_CDN_RESOURCE_INFO_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REQUEST_FAILED}),a),{code:e.RCRTCCode.REQUEST_FAILED}}))}}var Zo;zo.isDetector=!1,zo.msInDetector=[],zo.detectorTime=0,zo.detectValidMinute=72e5,zo.jwtToken="",function(e){e[e.NORMAL=1]="NORMAL",e[e.TINY=2]="TINY"}(Zo||(Zo={}));const Qo=(e,t)=>Math.round(8*t/e),Xo=(e,t=2)=>{const i=10**t;return Math.round(e*i)/i},en=(e,t=2)=>{e>1&&(e=1);const i=10**t;return Math.round(e*i)},tn=(e,t,i,r)=>{if(0===t)return 0;if(!i||!r)return Xo(e/t,3);const o=t-r;if(0===o)return 0;const n=e-i;return n<0||o<0?0:Xo(n/o,3)},rn=e=>{const{jitter:t,rtt:i,packetsLostRate:r}=e;return!vt(t)||!vt(i)||0!==r};class on{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 nn,sn,an,dn,cn,_n,ln,un,hn,Rn,vn,Cn,pn,gn,mn,Tn,In,En;on._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"}(nn||(nn={}));class Sn{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=Le.getLogger()}updateBytesSent(e,t,i){let r,o;if(this._latestBytesSent[e]&&t<this._latestBytesSent[e].bytesSent&&this.clearLatestpacketsSent([e]),this._latestBytesSent[e]){const{bytesSent:n,timestamp:s}=this._latestBytesSent[e];r=t-n,o=i-s,this._latestBytesSent[e]={bytesSent:t,timestamp:i}}else r=t,o=1e3,this._latestBytesSent[e]={bytesSent:t,timestamp:i};return Qo(o,r)}updateBytesRecv(e,t,i){let r,o;if(this._latestBytesRecv[e]&&t<this._latestBytesRecv[e].bytesRecv&&this.clearLatestPacketsRecv([e]),this._latestBytesRecv[e]){const{bytesRecv:n,timestamp:s}=this._latestBytesRecv[e];r=t-n,o=i-s,this._latestBytesRecv[e]={bytesRecv:t,timestamp:i}}else r=t,o=1e3,this._latestBytesRecv[e]={bytesRecv:t,timestamp:i};return Qo(o,r)}updateSenderPacketsLost(e,t,i){let r;if(Object.prototype.hasOwnProperty.call(this._latestPacketsSent[e],"packetsSent")){const{packetsLost:o,packetsSent:n}=this._latestPacketsSent[e];r=tn(t,i,o,n),this._latestPacketsSent[e].packetsLost=t,this._latestPacketsSent[e].packetsSent=o===t?n:i}else r=tn(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:o,packetsRecv:n}=this._latestPacketsRecv[e];r=tn(t,i+t,o,n+o)}else r=tn(t,i);return this._latestPacketsRecv[e]={packetsLost:t,packetsRecv:i},r}clearLatestpacketsSent(t){t.forEach((t=>{if(parseInt(t.split("_").pop())===e.RCMediaType.VIDEO_ONLY){const e=`${t}_tiny`;delete this._latestPacketsSent[e],delete this._latestBytesSent[e]}delete this._latestPacketsSent[t],delete this._latestBytesSent[t]}))}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(o.L_ABSTRACT_STAT_PARSER_FORMAT_RTC_STATE_REPORT_O,JSON.stringify({status:n.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===nn.REMOTEINBOUNDRTP?(e.remoteInbound.push(t),e):t.type===nn.INBOUNDRTP?(e.inbound.push(t),e):t.type===nn.OUTBOUNDRTP?(e.outbound.push(t),e):t.type===nn.TRANSPORT?(e.transport.push(t),e):t.type===nn.PEERCONNECTION?(e.connection.push(t),e):e),{outbound:[],remoteInbound:[],inbound:[],transport:[],connection:[]})}}Sn.formatSourceIdMapFromSdp=(e,t)=>{const i=on.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 fn extends Sn{formatRCRTCStateReport(e){const{outbound:t,remoteInbound:i,inbound:r,transport:o,connection:n}=this.formatStateData(e),s={senders:[],receivers:[]},a=Math.floor(n[0].timestamp);s.timestamp=a;let d=0,c=0;({totalPacketsLost:d,bitrateSend:c,senders:s.senders}=this.pickOutbound(t,e,d,a,c)),i.length>0&&s.senders.length>0&&this.pickRemoteInbound(i,s.senders,e);let _=0;if(({totalPacketsLost:d,bitrateRecv:_,receivers:s.receivers}=this.pickInbound(r,e,d,a,_)),o.length>0){const t=o[0];this.pickRtcTransport(t,e,s,_,c,d)}return s}pickRtcTransport(e,t,i,r,o,n){const{selectedCandidatePairId:s}=e;if(s){const e=t[s],{availableOutgoingBitrate:a,availableIncomingBitrate:d,currentRoundTripTime:c,localCandidateId:_,remoteCandidateId:l}=e,u=t[_],{ip:h,port:R,networkType:v}=u,C=t[l],{ip:p,port:g,protocol:m}=C;i.iceCandidatePair={IP:h,port:R,networkType:v,remoteIP:p,remotePort:g,protocol:m,bitrateRecv:r,bitrateSend:o,rtt:1e3*c,availableOutgoingBitrate:a,availableIncomingBitrate:d,totalPacketsLost:n},i.receivers.forEach((e=>{e.rtt=c}))}}pickRemoteInbound(e,t,i){e.forEach((e=>{var r;const{localId:o,jitter:n,roundTripTime:s,packetsLost:a}=e,d=t.filter((e=>e.id===o))[0];if(d&&!rn(d)){const e=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i[d.id].ssrc);d.jitter=Math.round(1e3*n),d.rtt=s;const t=this._latestPacketsSent[e].crtPacketsSent;d.packetsLostRate=this.updateSenderPacketsLost(e,a,t)}}))}pickOutbound(e,t,i,r,o){const n=[];return e.forEach((e=>{var s;if("unified-plan"===this._sdpSemantics&&!this.isValidSender(e))return;const{id:a,kind:d,transportId:c,mediaSourceId:_,remoteId:l,packetsSent:u,bytesSent:h,trackId:R,encoderImplementation:v,pliCount:C,nackCount:p,firCount:g}=e;if(!R)return;let{framesPerSecond:m,frameWidth:T,frameHeight:I}=e;"video"!==d||T||I||m||(T=t[R].frameWidth,I=t[R].frameHeight,m=_?t[_].framesPerSecond:null);const E=t[l];let S=null,f=null,O=0;E&&(S=E.jitter,f=E.roundTripTime,O=E.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[R].audioLevel;let A=null;!this._latestPacketsSent[L]&&(this._latestPacketsSent[L]={}),E?A=this.updateSenderPacketsLost(L,O,u):this._latestPacketsSent[L].crtPacketsSent=u;let y=this.updateBytesSent(L,h,r);y<0&&(y=0),o+=y,n.push({id:a,trackId:L,kind:d,packetsLostRate:A,remoteResource:!1,audioLevel:N||0===N?en(N):null,frameWidth:T,frameHeight:I,frameRate:m,bitrate:y,jitter:S?Math.round(1e3*S):S,rtt:f,encoderImplementation:v,pliCount:C,nackCount:p,googFirsSent:fo,samplingRate:fo,googRenderDelayMs:fo,trackState:fo})})),{totalPacketsLost:i,bitrateSend:o,senders:n}}pickInbound(e,t,i,r,o){let n=[];return e.forEach((e=>{var s;if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(e))return;const{trackId:a,packetsLost:d,packetsReceived:c,jitter:_,bytesReceived:l,framesPerSecond:u,kind:h,codecImplementationName:R,nackCount:v,pliCount:C}=e;if(!a)return;let{frameWidth:p,frameHeight:g,audioLevel:m}=e;"video"===h?p||g||(p=t[a].frameWidth,g=t[a].frameHeight):m||(m=t[a].audioLevel),i+=d;const T=null===(s=this._store)||void 0===s?void 0:s.getTrackIdBySSRC(e.ssrc),I=this.updateReceiverPacketsLost(T,d,c);let E=this.updateBytesRecv(T,l,r);E<0&&(E=0),o+=E,n.push({trackId:T,kind:h,packetsLostRate:I,remoteResource:!0,audioLevel:m||0===m?en(m):null,frameWidth:p,frameHeight:g,frameRate:u,bitrate:E,jitter:_?Math.round(1e3*_):0,codecImplementationName:R,nackCount:v,pliCount:C,rtt:null,samplingRate:fo,googFirsReceived:fo,googRenderDelayMs:fo,trackState:fo})})),{totalPacketsLost:i,bitrateRecv:o,receivers:n}}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,o;if("unified-plan"===this._sdpSemantics&&!this.isValidSender(i))return;const{mediaSourceId:n,trackId:s,kind:a}=i,d=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i.ssrc),c=n&&e[n]?e[n].audioLevel:(null===(o=e[s])||void 0===o?void 0:o.audioLevel)||null;d&&t.push({trackId:d,audioLevel:c||0===c?en(c):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:o}=i,n=i.audioLevel||e[o].audioLevel,s=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(i.ssrc);s&&t.push({trackId:s,audioLevel:n||0===n?en(n):null})})),t}}class On extends Sn{formatRCRTCStateReport(e){var t,i,r;const o=+new Date,n={senders:[],receivers:[],timestamp:o};let s=0,a=0,d=0;for(const c in e){const _=e[c],{type:l}=_;if("outbound-rtp"===l){if("unified-plan"===this._sdpSemantics&&!this.isValidSender(_))continue;const{id:i,kind:r,bytesSent:d,packetsSent:c,bitrateMean:l,framerateMean:u,nackCount:h,pliCount:R,remoteId:v}=_,{jitter:C,roundTripTime:p,packetsLost:g}=v?e[v]:{jitter:null,roundTripTime:null,packetsLost:0},m=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(_.ssrc);s+=g;let T=null;!this._latestPacketsSent[m]&&(this._latestPacketsSent[m]={}),v?T=this.updateSenderPacketsLost(m,g,c):this._latestPacketsSent[m].crtPacketsSent=c;let I=0;"video"===r?l&&(I=Math.floor(l/1e3)):I=this.updateBytesSent(m,d,o),I<0&&(I=0),a+=I,n.senders.push({trackId:m,kind:r,packetsLostRate:T,remoteResource:!1,audioLevel:null,frameWidth:null,frameHeight:null,frameRate:Math.floor(u),bitrate:I,jitter:C?Math.round(1e3*C):null,rtt:p,encoderImplementation:null,pliCount:R,nackCount:h,googFirsSent:fo,samplingRate:fo,googRenderDelayMs:fo,trackState:fo})}if("remote-inbound-rtp"===l){const{localId:t}=_,r=null===(i=this._store)||void 0===i?void 0:i.getTrackIdBySSRC(e[t].ssrc),o=n.senders.filter((e=>e.trackId===r))[0];o&&rn(o)&&(o.jitter=Math.round(1e3*_.jitter),o.rtt=_.rtt,o.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:c,framerateMean:l,kind:u,bitrateMean:h,nackCount:R,pliCount:v}=_,C=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(_.ssrc);s+=t;const p=this.updateReceiverPacketsLost(C,t,a);let g=0;"video"===u?h&&(g=Math.floor(h/1e3)):g=this.updateBytesRecv(C,i,o),g<0&&(g=0),d+=g,n.receivers.push({trackId:C,kind:u,packetsLostRate:p,remoteResource:!0,audioLevel:null,frameWidth:null,frameHeight:null,frameRate:Math.floor(l),bitrate:g,jitter:c?Math.round(1e3*c):null,codecImplementationName:null,nackCount:R,pliCount:v,rtt:null,samplingRate:fo,googFirsReceived:fo,googRenderDelayMs:fo,trackState:fo})}if("candidate-pair"===l&&"succeeded"===_.state){const t=e[_.localCandidateId],{address:i,port:r}=t,o=e[_.remoteCandidateId],{address:c,port:l,protocol:u}=o;n.iceCandidatePair={IP:i,port:r,networkType:null,remoteIP:c,remotePort:l,protocol:u,bitrateRecv:d,bitrateSend:a,rtt:null,availableOutgoingBitrate:null,availableIncomingBitrate:null,totalPacketsLost:s}}}return n.iceCandidatePair&&(n.iceCandidatePair.bitrateSend=a),n.iceCandidatePair&&(n.iceCandidatePair.bitrateRecv=d),n}getAudioLevelList(e){var t,i;const r=[];for(const o in e){const n=e[o],{type:s}=n;if("outbound-rtp"===s){if("unified-plan"===this._sdpSemantics&&!this.isValidSender(n))continue;const{kind:e}=n;if("video"===e)continue;const i=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(n.ssrc);r.push({trackId:i,audioLevel:null})}if("inbound-rtp"===s){if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(n))continue;const{kind:e}=n;if("video"===e)continue;const t=null===(i=this._store)||void 0===i?void 0:i.getTrackIdBySSRC(n.ssrc);r.push({trackId:t,audioLevel:null})}}return r}}class Ln extends Sn{formatRCRTCStateReport(e){const t={senders:[],receivers:[]},i=Math.floor(e.RTCPeerConnection.timestamp);t.timestamp=i;const r=Object.keys(e);let o=0,n=0;r.filter((e=>/^RTCOutboundRTP(Video|Audio)Stream_/.test(e))).forEach((r=>{var o;const s=e[r];if("unified-plan"===this._sdpSemantics&&!this.isValidSender(s))return;const a=null===(o=this._store)||void 0===o?void 0:o.getTrackIdBySSRC(s.ssrc),{mediaType:d,transportId:c,remoteId:_,packetsSent:l,bytesSent:u,trackId:h,encoderImplementation:R,pliCount:v,nackCount:C,firCount:p}=s;if(!h)return;const{audioLevel:g,frameHeight:m,frameWidth:T}=e[h];let I=this.updateBytesSent(a,u,i);I<0&&(I=0),n+=I,t.senders.push({trackId:a,kind:d,packetsLostRate:null,remoteResource:!1,audioLevel:g||0===g?en(g):null,frameWidth:T,frameHeight:m,frameRate:null,bitrate:I,jitter:null,rtt:null,encoderImplementation:R,pliCount:v,nackCount:C,googFirsSent:fo,samplingRate:fo,googRenderDelayMs:fo,trackState:fo})}));let s=0;r.filter((e=>/^RTCInboundRTP(Video|Audio)Stream_/.test(e))).forEach((r=>{var n;const a=e[r];if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(a))return;const{trackId:d,packetsLost:c,packetsReceived:_,jitter:l,bytesReceived:u,mediaType:h,nackCount:R,pliCount:v}=a,C=null===(n=this._store)||void 0===n?void 0:n.getTrackIdBySSRC(a.ssrc);if(!d)return;const{frameHeight:p,frameWidth:g,audioLevel:m}=e[d];o+=c;const T=this.updateReceiverPacketsLost(C,c,_);let I=this.updateBytesRecv(C,u,i);I<0&&(I=0),s+=I,t.receivers.push({trackId:C,kind:h,packetsLostRate:T,remoteResource:!0,audioLevel:m||0===m?en(m):null,frameWidth:g,frameHeight:p,frameRate:null,bitrate:I,jitter:l,codecImplementationName:null,nackCount:R,pliCount:v,rtt:null,samplingRate:fo,googFirsReceived:fo,googRenderDelayMs:fo,trackState:fo})}));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:d,currentRoundTripTime:c,localCandidateId:_,remoteCandidateId:l}=i,u=e[_],{address:h,port:R}=u,v=e[l],{address:C,port:p,protocol:g}=v;t.iceCandidatePair={IP:h||null,port:R,networkType:null,remoteIP:C,remotePort:p,protocol:g,bitrateRecv:s,bitrateSend:n,rtt:1e3*c,availableOutgoingBitrate:a,availableIncomingBitrate:d,totalPacketsLost:o},t.receivers.forEach((e=>{e.rtt=c}))}}return t}getAudioLevelList(e){const t=[],i=Object.keys(e);i.filter((e=>/^RTCOutboundRTP(Video|Audio)Stream_/.test(e))).forEach((i=>{var r;const o=e[i];if("unified-plan"===this._sdpSemantics&&!this.isValidSender(o))return;const{trackId:n,mediaType:s}=o;if("video"===s)return;const a=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(o.ssrc),d=e[n];t.push({trackId:a,audioLevel:d||0===d?en(d):null})}));return i.filter((e=>/^RTCInboundRTP(Video|Audio)Stream_/.test(e))).forEach((i=>{var r;const o=e[i];if("unified-plan"===this._sdpSemantics&&!this.isValidReceiver(o))return;const{trackId:n,mediaType:s}=o;if(!n||"video"===s)return;const{audioLevel:a}=e[n],d=null===(r=this._store)||void 0===r?void 0:r.getTrackIdBySSRC(o.ssrc);t.push({trackId:d,audioLevel:a||0===a?en(a):null})})),t}}class Nn{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=Le.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*Nn.KBitrate}\r\nb=TIAS:${e*Nn.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*Nn.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*Nn.KBitrate}\r\nb=TIAS:${t.max*Nn.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*Nn.KBitrate,"x-google-min-bitrate="+t.min*Nn.KBitrate,`x-google-start-bitrate=${t.start||t.max*Nn.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*Nn.KBitrate}\r\nb=TIAS:${t.max*Nn.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===an.SENDONLY){if(/\ba=sendonly\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}if(t===an.RECVONLY){if(/\ba=recvonly\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}if(t===an.INACTIVE){if(/\ba=inactive\b/.test(e))return e.replace(/\r\na=(ssrc|msid)[^\r\n]+/gi,"")}return e}}Nn.KBitrate=1,function(e){e.PLANB="plan-b",e.UNIFIEDPLAN="unified-plan"}(sn||(sn={})),function(e){e.SENDONLY="sendonly",e.RECVONLY="recvonly",e.INACTIVE="inactive"}(an||(an={}));class An{static setSdpSemantics(e){const t=Le.getLogger(),{browser:i,version:r,supportsUnifiedPlan:n}=ut;null==t||t.info(o.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 An._sdpSemantics}constructor(e){this._peer=e,this._outboundStreams={},this._logger=null,this._logger=Le.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:o,height:n}=et(i);e.push({trackId:i.id,simulcast:r?Zo.TINY:Zo.NORMAL,resolution:`${o}x${n}`})}return e}setRemoteAnswer(t){var r,s,a;return i(this,void 0,void 0,(function*(){if(t=Nn.trimBlankLine(t),"disconnected"===this._peer.connectionState||"closed"===this._peer.connectionState)return null===(r=this._logger)||void 0===r||r.info(o.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:n.FAILED,msg:`peer.connectionState is ${this._peer.connectionState}`})),e.RCRTCCode.SET_REMOTE_DESCRIPTION_FAILED;try{yield this._peer.setRemoteDescription({type:"answer",sdp:t})}catch(t){return null===(s=this._logger)||void 0===s||s.info(o.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:n.FAILED,msg:t})),e.RCRTCCode.SET_REMOTE_DESCRIPTION_FAILED}return null===(a=this._logger)||void 0===a||a.info(o.L_A_SDP_STRATEGY_SET_REMOTE_ANSWER_O,JSON.stringify({status:n.SUCCESSED,sdp:t})),e.RCRTCCode.SUCCESS}))}getStatParsr(e,t,i,r){return/chrome/i.test(ut.browser)?new fn(e,t,i,r):/Firefox/i.test(ut.browser)?new On(e,t,i,r):/Safari/i.test(ut.browser)?new Ln(e,t,i,r):null}resetSdp(e){return Nn.trimBlankLine(e)}}class yn extends Nn{constructor(e){super(e,sn.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=Nn.clearInactiveOrRecvonly(t);i&&i[1]===ye.AUDIO&&(e[1]=r),i&&i[1]===ye.VIDEO&&(e[2]=r)}));const t=e.join("");return Nn.trimBlankLine(t)}setAudioBitrateWithStreamId(e,t){var i;return null===(i=this._logger)||void 0===i||i.warn(o.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(o.L_FUNCTION_IS_UNAVAILABLE,"plan-b not support set Video Bitrate With Stream Id"),this}}class kn extends An{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 o=e.getTrackId(),n=this.senders[o];n?n.replaceTrack(i):(this.senders[o]=this._peer.addTrack(i,r),Object.defineProperty(i,"trackId",{value:o,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 i(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 yn(e),i={max:0,min:0},r={max:0,min:0};return this._localTracks.forEach((e=>{const{min:t,max:o,start:n}=e.getBitrate();e.isAudioTrack()&&(r.max=r.max<o?o:r.max,r.min=r.min>t?t:r.min,r.max===o?r.start=n:r.start=.7*r.max),e.isVideoTrack()&&(i.max=i.max<o?o:i.max,i.min=i.min>t?t:i.min,i.max===o?i.start=n:i.start=.7*i.max)})),t.setAudiosBitrate(r),t.setVideosBitrate(i),t.stringify()}}class Dn extends Nn{constructor(e){super(e,sn.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 Nn.trimBlankLine(t)}}class bn{static splitSections(e){return e.split("\nm=").map(((e,t)=>`${(t>0?`m=${e}`:e).trim()}\r\n`))}static getMediaSections(e){const t=bn.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=bn.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 bn.splitLines(e).filter((e=>0===e.indexOf(t)))}static parseMsid(e){let t;const i=bn.matchPrefix(e,"a=msid:");if(1===i.length)return t=i[0].substr(7).split(" "),{stream:t[0],track:t[1]};const r=bn.matchPrefix(e,"a=ssrc:").map((e=>bn.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=bn.matchPrefix(e,"a=mid:")[0];if(t)return t.substr(6)}}class Un{constructor(){this.__streams=new Map}static getInstance(){return Un.instance||(Un.instance=new Un),Un.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 Pn extends An{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(o.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(),o=e.__innerGetMediaStreamTrack();this._localTracks[i]=e;const n=this._outboundStreams[r]||(this._outboundStreams[r]=new MediaStream);n.getTracks().forEach((e=>{e.kind===o.kind&&n.removeTrack(e)})),n.addTrack(o);const s=this._sendTransceiver[i];s?(s.sender.replaceTrack(o),s.direction="sendonly"):this._sendTransceiver[i]=this._peer.addTransceiver(o,{direction:"sendonly",streams:[n]});Un.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 o=this._outboundStreams[i];(e.isAudioTrack()?o.getAudioTracks():o.getVideoTracks()).forEach((e=>o.removeTrack(e)));const n=this._sendTransceiver[`${t}_tiny`];if(n&&"inactive"!==n.direction&&"closed"!==this._peer.connectionState){n.direction="inactive";const{sender:e}=n,t=e.track;this._peer.removeTrack(e),e.replaceTrack(null);this._outboundStreams[`${i}_tiny`].removeTrack(t),t.stop()}}updateRecvTransceiverMap(t,i){const{mediaType:r}=rt(t);this._recvTransceiver[t]=i;const o=r===e.RCMediaType.AUDIO_ONLY?this._recvAudio:this._recvVideo,n=o.findIndex((e=>e===i));n>=0&&o.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],o=i.findIndex((e=>e===r));o>=0&&(t.splice(e,1),i.splice(o,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 i(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 Dn(e);for(const r in this._sendTransceiver){const o=this._sendTransceiver[r],n=null===(t=o.sender.track)||void 0===t?void 0:t.kind;let{direction:s,mid:a}=o;if(!a){bn.getMediaSections(e).forEach((e=>{bn.parseExtmap(e);const{kind:t}=bn.parseMLine(e);let{stream:i}=bn.parseMsid(e);const o=bn.getMid(e);"video"===n?/tiny$/.test(i)?i=i.replace(/tiny$/gi,"1_tiny"):i+="_1":i+="_0",i===r&&n===t&&o&&(a=o)}))}if(a){if(s===an.SENDONLY){const e=this._localTracks[r],t=null==e?void 0:e.getBitrate();n===ye.AUDIO&&t&&i.setAudioBitrateWithMid(t,a),n===ye.VIDEO&&t&&i.setVideoBitrateWithMid(t,a)}s===an.INACTIVE&&i.clearnSsrcWithMid(a,an.INACTIVE)}}for(const e in this._recvTransceiver){const t=this._recvTransceiver[e],{direction:r,mid:o}=t;o&&r===an.INACTIVE&&i.clearnSsrcWithMid(o,an.RECVONLY)}return i.stringify()}resetAnswerSdp(e){var t;const i=new Dn(e);for(const e in this._sendTransceiver){const r=this._sendTransceiver[e],{mid:o}=r;if(o){const n=this._localTracks[e],s=null==n?void 0:n.getBitrate(),a=null===(t=r.sender.track)||void 0===t?void 0:t.kind;a===ye.AUDIO&&s&&i.setAudioBitrateWithMid(s,o),a===ye.VIDEO&&s&&i.setVideoBitrateWithMid(s,o)}}return i.stringify()}}!function(e){e.VP8="VP8",e.VP9="VP9",e.H264="H264"}(dn||(dn={}));class Mn extends t.EventEmitter{constructor(e,t,i,r,o,n,s=!1,a){super(),this._pcName=e,this._reTryExchange=t,this._currentUserId=i,this._polarisReport=r,this.onTrackTrouble=o,this._store=n,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 d=An.getSdpSemantics(),c=this._rtcPeerConn=new RTCPeerConnection({sdpSemantics:d});this._sdpStrategy="plan-b"===d?new kn(c):new Pn(c),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,d,this._currentUserId,this._store),this._logger=Le.getLogger()}getName(){return this._pcName}getLocalTracks(){return Object.values(this.pubLocalTracks)}_onConnectionStateChange(){var e;null===(e=this._logger)||void 0===e||e.info(o.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;Bo({iceNewStatusData:{start:Date.now(),status:this._rtcPeerConn.iceConnectionState}}),(e=>{var t,i;const r=Do.getMemo(),o={dur:0,pices:0,ices:0,rid:(null===(t=r.joinRoomData)||void 0===t?void 0:t.roomId)||"",csnid:(null===(i=r.clientData)||void 0===i?void 0:i.clientSessionId)||"",snid:"",time:0,rcdts:[],lcdts:[],cncdts:void 0,cr:"unknown",net:"unknown",uid:e};r.qualityIceStatusReportData=o})(this._currentUserId),null===(e=this._logger)||void 0===e||e.info(o.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_S,JSON.stringify({connectionState:this._rtcPeerConn.connectionState,pcName:this._pcName})),"connected"===this._rtcPeerConn.iceConnectionState&&((()=>{var e,t,i,r,n,s,a,d,c,_,l,u,h,R;const v=Do.getMemo(),C=Date.now();if(!(null===(e=v.iceStatusData)||void 0===e?void 0:e.subscribeNotReport)&&(null===(t=v.iceStatusData)||void 0===t?void 0:t.subscribe)){Bo({subscribeNotReport:!0});const e=v.iceStatusData.notFirst?0:((null===(i=v.iceNewStatusData)||void 0===i?void 0:i.start)||0)-((null===(n=null===(r=v.iceStatusData)||void 0===r?void 0:r.subscribe)||void 0===n?void 0:n.time)||0),t=JSON.stringify(Object.assign(Object.assign({},v.qualityIceStatusReportData),{dur:e,pices:bo[(null===(s=v.iceOldStatusData)||void 0===s?void 0:s.status)||0],ices:bo[(null===(a=v.iceNewStatusData)||void 0===a?void 0:a.status)||0],rcdts:void 0,lcdts:void 0,cncdts:void 0,time:C}));Ne.__statistics(o.L_QS_SUB_ICE_STATUS_S,t)}if(!(null===(d=v.iceStatusData)||void 0===d?void 0:d.publishNotReport)&&(null===(c=v.iceStatusData)||void 0===c?void 0:c.publish)){Bo({publishNotReport:!0});const e=v.iceStatusData.notFirst?0:((null===(_=v.iceNewStatusData)||void 0===_?void 0:_.start)||0)-((null===(u=null===(l=v.iceStatusData)||void 0===l?void 0:l.publish)||void 0===u?void 0:u.time)||0),t=JSON.stringify(Object.assign(Object.assign({},v.qualityIceStatusReportData),{dur:e,pices:bo[(null===(h=v.iceOldStatusData)||void 0===h?void 0:h.status)||0],ices:bo[(null===(R=v.iceNewStatusData)||void 0===R?void 0:R.status)||0],rcdts:void 0,lcdts:void 0,cncdts:void 0,time:C}));Ne.__statistics(o.L_QS_PUB_ICE_STATUS_S,t)}Bo({notFirst:!0})})(),$o(),this.startAutoExecute(1e3)),"failed"!==this._rtcPeerConn.iceConnectionState&&"disconnected"!==this._rtcPeerConn.iceConnectionState||($o(),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,this._rtcPeerConn.iceConnectionState,this._pcName)}catch(e){null===(r=this._logger)||void 0===r||r.error(o.L_RTC_PEER_CONNECTION_ICE_CONNECTION_STATE_REPORT_R,JSON.stringify({status:n.FAILED,pcName:this._pcName,mag:e}))}}_onTrackReady(t){if(!t.streams.length)return;const i=t.streams[0].id,{track:r}=t.receiver,o=[i,"audio"===r.kind?e.RCMediaType.AUDIO_ONLY:e.RCMediaType.VIDEO_ONLY].join("_");Object.defineProperty(r,"trackId",{value:o,writable:!1,enumerable:!1,configurable:!1}),this._updateRecvTransceiverMap(o,t.transceiver),this.emit(Mn.__INNER_EVENT_TRACK_READY__,t)}setBitrate(e,t,r){var s;return i(this,void 0,void 0,(function*(){this._sdpStrategy.setBitrate(e,t,r),null===(s=this._logger)||void 0===s||s.info(o.L_RTC_PEER_CONNECTION_SET_BITRATE_O,JSON.stringify({status:n.SUCCESSED,max:e,min:t,start:r}))}))}createOffer(e){var t;return i(this,void 0,void 0,(function*(){const i=yield this._sdpStrategy.createOffer(e);return null===(t=this._logger)||void 0===t||t.info(o.L_RTC_PEER_CONNECTION_CREATE_OFFER_O,JSON.stringify({offerSDP:i.sdp,sdpDemantics:i.semantics})),i}))}setRemoteAnswer(e){return i(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(xe.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(xe.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),e.on(xe.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.on(xe.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),null===(t=this._logger)||void 0===t||t.info(o.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(o.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_BY_ID_O,JSON.stringify({status:n.SUCCESSED,trackId:e})),this.removeLocalTrack(r)):null===(t=this._logger)||void 0===t||t.warn(o.L_RTC_PEER_CONNECTION_REMOVE_LOCAL_TRACK_BY_ID_O,JSON.stringify({status:n.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(xe.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(xe.__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(o.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(xe.__INNER_EVENT_MUTED_CHANGE__,e,t)}_onLocalTrackDestroied(e){this.emit(xe.__INNER_EVENT_DESTROY__,e)}registerReportListener(e){this._reportListener=e}_createRCRTCStateReport(e){const{timestamp:t,iceCandidatePair:i,senders:r,receivers:o}=e;(null==i?void 0:i.totalPacketsLost)&&(null==i||delete i.totalPacketsLost);for(const e in i)vt(i[e])&&delete i[e];const n=[];r.forEach((e=>{const{trackId:t,kind:i,packetsLostRate:r,remoteResource:o,bitrate:s,jitter:a}=e,d={trackId:t,kind:i,packetsLostRate:r,remoteResource:o,bitrate:s,jitter:a};(e.audioLevel||0===e.audioLevel)&&(d.audioLevel=e.audioLevel),e.frameWidth&&(d.frameWidth=e.frameWidth),e.frameHeight&&(d.frameHeight=e.frameHeight),e.frameRate&&(d.frameRate=e.frameRate),e.trackId&&n.push(Object.assign({},d))}));const s=[];return o.forEach((e=>{const{trackId:t,kind:i,packetsLostRate:r,remoteResource:o,bitrate:n,jitter:a}=e,d={trackId:t,kind:i,packetsLostRate:r,remoteResource:o,bitrate:n,jitter:a};(e.audioLevel||0===e.audioLevel)&&(d.audioLevel=e.audioLevel),e.frameWidth&&(d.frameWidth=e.frameWidth),e.frameHeight&&(d.frameHeight=e.frameHeight),e.frameRate&&(d.frameRate=e.frameRate),e.trackId&&s.push(Object.assign({},d))})),{timestamp:t,iceCandidatePair:i,senders:n,receivers:s,pcName:this._pcName}}_getStatsData(){var e,t;return i(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 o=null===(t=this.reportParser)||void 0===t?void 0:t.formatRCRTCStateReport(i);return this._formatStatsData=o,o}))}_reportHandle(){var e,t,r,o;return i(this,void 0,void 0,(function*(){const i=yield this._getStatsData();if(!i)return;const n=this._createRCRTCStateReport(i);null===(t=null===(e=this._reportListener)||void 0===e?void 0:e.onStateReport)||void 0===t||t.call(e,n);const s=[...i.receivers,...i.senders].filter((e=>!("audio"!==e.kind))).map((e=>({trackId:e.trackId,audioLevel:e.audioLevel})));if(this.emit(Mn.__INNER_AUDIOLEVEL_CHANGE__,s),this._isRoomAudience){const e=this._getLiveAudioState();e.length&&(null===(o=null===(r=this._reportListener)||void 0===r?void 0:r.onReportLiveAudioStates)||void 0===o||o.call(r,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,o=null===(t=this._store)||void 0===t?void 0:t.getTrackIdBySSRC(i),{userId:n}=rt(o);return{audioLevel:en(r),userId:n,trackId:o}})).filter((e=>!!e.userId))}_sendR3R4Data(){var e,t;return i(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:o}=e;let n=0;"unknown"!==(null==t?void 0:t.toLowerCase())&&i&&r&&o||(n=1),this.setTroubleTrack(e.trackId,n)}})),e}return!0}))}__reportR3R4ToPolaris(){return i(this,void 0,void 0,(function*(){clearTimeout(this._reportR3R4ToPolarisTimer),this._reportR3R4ToPolarisTimer=setTimeout((()=>i(this,void 0,void 0,(function*(){this._sendR3R4Data().then((()=>{this.__reportR3R4ToPolaris()}))}))),2e3)}))}getRTCPeerConn(){return this._rtcPeerConn}getCapabilitiesCodes(e=dn.H264){var t;let i=null===(t=RTCRtpSender.getCapabilities("video"))||void 0===t?void 0:t.codecs,r=null;switch(e){case dn.VP8:case dn.VP9:r=i.find((t=>t.mimeType.match(e)));break;case dn.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 i(this,void 0,void 0,(function*(){const i=this.getRTCPeerConn(),r=this.getCapabilitiesCodes(e);null===(t=this._logger)||void 0===t||t.info(o.L_SET_ENCODER_PREFERENCES_S,JSON.stringify({status:n.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(o.L_RTC_PEER_CONNECTION_DESTROY_O,JSON.stringify({status:n.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)}}Mn.__INNER_EVENT_TRACK_READY__="inner-track-ready",Mn.__INNER_AUDIOLEVEL_CHANGE__="inner-audio-level-change",function(e){e[e.DISABLE=0]="DISABLE",e[e.ENABLE=1]="ENABLE"}(cn||(cn={})),function(e){e[e.MeetingOrAnchor=1]="MeetingOrAnchor",e[e.Audience=2]="Audience"}(_n||(_n={})),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"}(ln||(ln={})),function(e){e.R1="R1",e.R2="R2",e.R3="R3",e.R4="R4"}(un||(un={}));class xn{constructor(e,t,i,r,o=_n.MeetingOrAnchor){this._context=e,this._runtime=t,this._roomId=i,this._crtRTCRoom=r,this._userRole=o}_send(e){return i(this,void 0,void 0,(function*(){if(this._context.getConnectionStatus()!==t.ConnectionStatus.CONNECTED)return ln.NOT_REPORT;return(yield this._context.setRTCState(this._roomId,e))===t.ErrorCode.SUCCESS?ln.REPORT_SUCCESS:ln.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(t){let i="";const r=t.split("_");if(t.includes("_tiny")){const t=r.pop(),o=parseInt(r.pop())===e.RCMediaType.AUDIO_ONLY?"audio":"video",n=r.pop();i=[r.join("_"),n,t,o].join("_")}else{const t=parseInt(r.pop())===e.RCMediaType.AUDIO_ONLY?"audio":"video",o=r.pop();i=[r.join("_"),o,t].join("_")}return i}sendR3R4Data(e){return i(this,void 0,void 0,(function*(){const{iceCandidatePair:t,senders:i,receivers:r}=e,o=(null==t?void 0:t.bitrateSend)||fo,n=(null==t?void 0:t.bitrateRecv)||fo,s=(null==t?void 0:t.networkType)||"unknown",a=(null==t?void 0:t.rtt)||fo,d=`${(null==t?void 0:t.IP)||fo}:${null==t?void 0:t.port}`,c=(null==t||t.remoteIP,null==t||t.remotePort,(null==t?void 0:t.availableIncomingBitrate)||fo),_=(null==t?void 0:t.availableOutgoingBitrate)||fo,l=(null==t?void 0:t.totalPacketsLost)||fo,u=this._context.getCurrentId();let h=`R3\t${o}\t-1\t-1\t-1\t${s}\t${a}\t${d}\t${c}\t${_}\t${l}\t${u}\r`,R=`R4\t${n}\t-1\t-1\t-1\t${s}\t${a}\t${d}\t${c}\t${_}\t${l}\t${u}\r`;const v=i.map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:o,bitrate:n,packetsLostRate:s,frameRate:a,frameWidth:d,frameHeight:c,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:R,googFirsSent:v,encoderImplementation:C}=e,p=this._getPolarisTrackId(i),g=this._getRealResourceId(i);return{trackId:p,googCodecName:C||String(fo),audioLevel:r||0===r?r:fo,bitrate:n||0===n?n:fo,packetsLostRate:s||0===s?s:fo,frameRate:a||fo,resolution:d&&c?`${d} * ${c}`:"-1",jitter:l||fo,nackCount:u||0===u?u:fo,pliCount:h||0===h?h:fo,rtt:R||fo,googFirsSent:v,samplingRate:o,googRenderDelayMs:_,encoderImplementation:C||String(fo),trackState:(null===(t=this._crtRTCRoom.getLocalTrack(g))||void 0===t?void 0:t.isLocalMuted())?cn.DISABLE:cn.ENABLE}})),C=r.filter((e=>!!e.trackId)).map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:o,bitrate:n,packetsLostRate:s,frameRate:a,frameWidth:d,frameHeight:c,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:R,googFirsReceived:v,codecImplementationName:C}=e,p=this._getPolarisTrackId(i),g=this._getRealResourceId(i);return{trackId:p,googCodecName:C||String(fo),audioLevel:r||0===r?r:fo,bitrate:n||0===n?n:fo,packetsLostRate:s||0===s?s:fo,frameRate:a||fo,resolution:d&&c?`${d} * ${c}`:"-1",jitter:l||fo,nackCount:u||0===u?u:fo,pliCount:h||0===h?h:fo,rtt:R||fo,googFirsReceived:v,samplingRate:o,googRenderDelayMs:_,codecImplementationName:C||String(fo),trackState:(null===(t=this._crtRTCRoom.getRemoteTrack(g))||void 0===t?void 0:t.isLocalMuted())?cn.DISABLE:cn.ENABLE}}));let p=ln.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&&(p=yield this._send(`${h}\r${this._userRole}`));let g=ln.REPORT_FAIL;return R+=C.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&&(g=yield this._send(`${R}\r${this._userRole}`)),p!==ln.REPORT_SUCCESS&&g!==ln.REPORT_SUCCESS?ln.REPORT_FAIL:ln.REPORT_SUCCESS}))}sendR1(){const e=this._context.getCoreVersion(),t=navigator.platform,i=`R1\t5.6.7\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 wn{constructor(e,t,i,r,o=_n.MeetingOrAnchor){this._context=e,this._runtime=t,this._roomId=i,this._crtRTCRoom=r,this._userRole=o,this._useHttp=!0;const n=this._context.getNaviInfo();wn.logServer=null==n?void 0:n.logServer,wn.dc=null==n?void 0:n.dc,this._polarisSignalReporter=new xn(e,t,i,r,o)}_send(r,n){var s,a;return i(this,void 0,void 0,(function*(){if(this._context.getConnectionStatus()!==t.ConnectionStatus.CONNECTED)return ln.NOT_REPORT;const{logServer:i}=wn;if(!i||!this._useHttp||!zo.jwtToken)return ln.REPORT_FAIL;const d=yield this._context.setRTCStateByHttp(i,this._runtime,r,n);return d===ln.REPORT_SUCCESS?ln.REPORT_SUCCESS:d===e.RCRTCCode.JWT_TIME_OUT?(this._refetchNaviInfo(),ln.REPORT_FAIL):d===ln.REPORT_FAIL||d===ln.PB_ERROR?(null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_HTTP_POLARIS_REPORT_FAIL_O,`send data fail -> code: ${d}`),this._useHttp=!1,ln.REPORT_FAIL):ln.REPORT_FAIL}))}_refetchNaviInfo(){return i(this,void 0,void 0,(function*(){const{jwt:e,naviInfo:t}=yield(r=this._context,i(void 0,void 0,void 0,(function*(){const e=r.getPluginContext();yield e.refetchNaviInfo();const t=r.getNaviInfo();return{naviInfo:t,jwt:No(t)}})));var r;zo.jwtToken=e,wn.logServer=null==t?void 0:t.logServer,wn.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(t){let i="";const r=t.split("_");if(t.includes("_tiny")){const t=r.pop(),o=parseInt(r.pop())===e.RCMediaType.AUDIO_ONLY?"audio":"video",n=r.pop();i=[r.join("_"),n,t,o].join("_")}else{const t=parseInt(r.pop())===e.RCMediaType.AUDIO_ONLY?"audio":"video",o=r.pop();i=[r.join("_"),o,t].join("_")}return i}_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:wn.dc||""}}_formatReportData(e,t){let i=this._formatReportBaseData(e),r={};switch(e){case un.R1:r=this._formatR1Data();break;case un.R2:r=this._formatR2Data(t);break;case un.R3:case un.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.7",imVersion:this._context.getCoreVersion(),platform:"web",device:navigator.platform,os:String(fo),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:o}=t;let n=0,s=[];return e===un.R3?(n=(null==i?void 0:i.bitrateSend)||fo,s=r.map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:o,bitrate:n,packetsLostRate:s,frameRate:a,frameWidth:d,frameHeight:c,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:R,googFirsSent:v,encoderImplementation:C}=e,p=this._getPolarisTrackId(i),g=this._getRealResourceId(i);return{trackId:p,codeName:C||String(fo),volume:String(r||0===r?r:fo),samplingRate:o||fo,bitRate:n||0===n?n:fo,packetLossRate:s||0===s?s:fo,frameRate:a||fo,resolution:d&&c?`${d} * ${c}`:"-1",blockTime:_,jitterData:l||fo,nAckCount:String(u||0===u?u:fo),pliCount:String(h||0===h?h:fo),googleRTTTotalTime:R||fo,isReceiveFirstFrameRate:v,codeType:C||String(fo),isEnabled:(null===(t=this._crtRTCRoom.getLocalTrack(g))||void 0===t?void 0:t.isLocalMuted())?cn.DISABLE:cn.ENABLE}}))):e===un.R4&&(n=(null==i?void 0:i.bitrateRecv)||fo,s=o.filter((e=>!!e.trackId)).map((e=>{var t;const{trackId:i,audioLevel:r,samplingRate:o,bitrate:n,packetsLostRate:s,frameRate:a,frameWidth:d,frameHeight:c,googRenderDelayMs:_,jitter:l,nackCount:u,pliCount:h,rtt:R,googFirsReceived:v,codecImplementationName:C}=e,p=this._getPolarisTrackId(i),g=this._getRealResourceId(i);return{trackId:p,codeName:C||String(fo),volume:String(r||0===r?r:fo),samplingRate:o||fo,bitRate:n||0===n?n:fo,packetLossRate:s||0===s?s:fo,frameRate:a||fo,resolution:d&&c?`${d} * ${c}`:"-1",blockTime:_,jitterData:l||fo,nAckCount:String(u||0===u?u:fo),pliCount:String(h||0===h?h:fo),googleRTTTotalTime:R||fo,isReceiveFirstFrameRate:v,codeType:C||String(fo),isEnabled:(null===(t=this._crtRTCRoom.getRemoteTrack(g))||void 0===t?void 0:t.isLocalMuted())?cn.DISABLE:cn.ENABLE}}))),{info:{joinTime:this._context.userJoinTime||0,receiveTime:Date.now(),totalBitRate:n,appCPUUsage:-1,systemCPUUsage:-1,systemCPUFrequency:-1,networkStatus:(null==i?void 0:i.networkType)||"unknown",googleRTTNetwork:(null==i?void 0:i.rtt)||fo,ipAddress:`${(null==i?void 0:i.IP)||fo}:${null==i?void 0:i.port}`,useReceiveBroadBand:String((null==i?void 0:i.availableIncomingBitrate)||fo),useSendBroadBand:String((null==i?void 0:i.availableOutgoingBitrate)||fo),packetLossCount:String((null==i?void 0:i.totalPacketsLost)||fo),streams:s}}}sendR3R4Data(e){return i(this,void 0,void 0,(function*(){let t=ln.REPORT_FAIL;if(e.senders.length){const i=this._formatReportData(un.R3,e);t=yield this._send(i,un.R3),t===ln.REPORT_FAIL&&(t=yield this._polarisSignalReporter.sendR3R4Data(e))}let i=ln.REPORT_FAIL;if(e.receivers.length){const t=this._formatReportData(un.R4,e);i=yield this._send(t,un.R4),i===ln.REPORT_FAIL&&(i=yield this._polarisSignalReporter.sendR3R4Data(e))}return t!==ln.REPORT_SUCCESS&&i!==ln.REPORT_SUCCESS?ln.REPORT_FAIL:ln.REPORT_SUCCESS}))}sendR1(){var e;return i(this,void 0,void 0,(function*(){const t=this._formatReportData(un.R1);(yield this._send(t,un.R1))===ln.REPORT_FAIL&&(null===(e=this._polarisSignalReporter)||void 0===e||e.sendR1())}))}sendR2(e,t,r){var o;return i(this,void 0,void 0,(function*(){const i=this._formatReportData(un.R2,{action:e,status:t,trackIds:r});(yield this._send(i,un.R2))===ln.REPORT_FAIL&&(null===(o=this._polarisSignalReporter)||void 0===o||o.sendR2(e,t,r))}))}}class Bn{constructor(e){this._room=e,this._audioLevelChangeHandler=null}audioLevelReport(e){if(!this._audioLevelChangeHandler)return;const t=[];e.forEach((e=>{const{userId:i}=rt(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}}e.RCRTCLiveRole=void 0,(hn=e.RCRTCLiveRole||(e.RCRTCLiveRole={}))[hn.ANCHOR=1]="ANCHOR",hn[hn.AUDIENCE=2]="AUDIENCE";class Vn{constructor(e=!1,t,i,r,o,n,s,a){this._useMutilPeerC=e,this._roomId=t,this._reTryExchange=i,this._currentUserId=r,this._polarisReport=o,this._isRoomAudience=n,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 xe||e[0]instanceof $e?{track:e[0]}:e[0];return t.isLocalTrack()}_groupTracksByTag(e){const t={};return e.forEach((e=>{const{track:i}=e instanceof xe?{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 Mn(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 o=this._genPCName(i,e),n=r[e];t.push(this._createOnePeerCItem(o,n))}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}=rt(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"}(Rn||(Rn={})),function(e){e.NORMAL="normal",e.MIDDLE="middle",e.TAIL="tail"}(vn||(vn={})),function(e){e[e.LOW=0]="LOW",e[e.NORMAL=1]="NORMAL",e[e.HIGH=2]="HIGH"}(Cn||(Cn={})),function(e){e[e.Destroy=40400]="Destroy"}(pn||(pn={}));class Fn{get priority(){return Cn.LOW}get kind(){return Rn.UNKNOWN}}class Jn extends Fn{constructor(e=vn.NORMAL){super(),this.state=e}get kind(){return Rn.ASYNC_COMMAND}setState(e){this.state=e}pickoutSubscribed(e,t){const{unsubscribe:i,subscribe:r}=this.calcSubscribeList(e,t);return Jn.AsyncSubscribeTasks=[],Jn.AsyncUnsubscribeTasks=[],Jn.AsyncUpdateSubscribeTasks=[],{subscribe:r,unsubscribe:i}}calcSubscribeList(e,t){const i=[],r=new Set,o=[],n=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)||n.has(t)||(o.push(e),n.add(t))})),{unsubscribe:i,subscribe:o}}formateTrack(e){return e.map((e=>e instanceof $e?{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}}Jn.AsyncSubscribeTasks=[],Jn.AsyncUnsubscribeTasks=[],Jn.AsyncUpdateSubscribeTasks=[];class Hn{constructor(e,t,i,r,o,n,s,a,d){this.context=e,this.service=t,this.peerMgr=i,this.roomId=r,this.crtUserId=o,this.roomMode=n,this.polarisReport=s,this.isUpgrade=a,this.isMainRoom=d,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}=rt(e);return this._roomResources[t].find((t=>it(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 Gn extends Hn{_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 t in this._roomResources){const i=this._roomResources[t];t!==this.crtUserId&&0!==i.length&&i.forEach((t=>{const i=it(t),{tag:r,userId:o,mediaType:n}=rt(i),s=n===e.RCMediaType.AUDIO_ONLY?new We(r,o):new qe(r,o);s.__innerSetRemoteMuted(0===t.state),this._remoteTracks[i]=s}))}}initWithRoomData(e,t){this._sessionId=e.sessionId,this._token=e.token,this._roomStatusVersion=Tt(e.version),this.isUpgrade?this._roomResources={}:this._roomResources=pt(e,this.roomId,t),this._updateTrackIdSSRCMap(),this._initRemoteTracks(),this.setResourcesByUserId(this.crtUserId,this.getResourcesByUserId(this.crtUserId)||[]);const i=Le.getLogger();null==i||i.info(o.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=Tt(e)}}class Kn{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,r,s;return i(this,void 0,void 0,(function*(){if(this._isDestroyed||this._busy||0===this._queue.length)return;this._busy=!0;const{command:i,resolve:a,reject:d}=this._queue.shift();let c;const _=this._queue.map((e=>{var t;return null===(t=null==e?void 0:e.command)||void 0===t?void 0:t.kind})),l=null===(e=this.context.logger)||void 0===e?void 0:e.createTraceId();try{null===(t=this.context.logger)||void 0===t||t.info(o.L_INVOKER_EXECUTE_T,`commandKind: ${i.kind}, kinds:${_.join(",")}, length: ${this._queue.length}`,l),c=yield i.execute(this._store,this)}catch(e){return null===(r=this.context.logger)||void 0===r||r.error(o.L_INVOKER_EXECUTE_R,JSON.stringify({error:e,status:n.FAILED,commandKind:i.kind,kinds:_.join(",")}),l),d(e),void this._next()}null===(s=this.context.logger)||void 0===s||s.info(o.L_INVOKER_EXECUTE_R,`status: ${n.SUCCESSED}, commandKind: ${i.kind}`,l),a(c),this._next()}))}push(t){return new Promise(((i,r)=>{var n;if(null===(n=this.context.logger)||void 0===n||n.info(o.L_INVOKER_PUSH_O,JSON.stringify({isDestroyed:this._isDestroyed,commandKind:t.kind,length:this._queue.length})),this._isDestroyed)return void r({code:e.RCRTCCode.NOT_IN_ROOM});const{kind:s}=t;this._queue.length>0&&s===Rn.ASYNC_COMMAND&&({command:t,resolve:i,reject:r}=this.commandOffset(t,i,r));const{priority:a}=t;if(a===Cn.LOW)this._queue.push({command:t,resolve:i,reject:r});else{const e=this._queue.findIndex((e=>e.command.priority<a)),o=-1===e?this._queue.length-1:e;this._queue.splice(o,0,{command:t,resolve:i,reject:r})}Promise.resolve().then((()=>{this._execute()}))}))}commandOffset(e,t,r){const o=this._queue.length-1;if(!(this._queue[o].command.kind===Rn.ASYNC_COMMAND))return{command:e,resolve:t,reject:r};const[n]=this._queue.splice(o,1);n.command instanceof Jn&&(n.command.setState(vn.MIDDLE),e instanceof Jn&&e.setState(vn.TAIL));const s=e.execute;return e.execute=function(t,r){return i(this,void 0,void 0,(function*(){return n.command.execute.call(n.command,t,r),s.call(e,t,r)}))},{command:e,resolve:e=>{n.resolve.call(n,e),t(e)},reject:e=>{n.reject.call(n,e),r(e)}}}isDestroyed(){var e;return null===(e=this.context.logger)||void 0===e||e.info(o.L_INVOKER_DESTROY_O,JSON.stringify({isDestroyed:this._isDestroyed})),this._isDestroyed}destroy(){var e;null===(e=this.context.logger)||void 0===e||e.info(o.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 jn extends Kn{constructor(t,i,r,o,n,s,a,d,c){super(t,new Gn(t,i,r,o,n,s,a,d,c),e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED)}get store(){return this._store}destroy(){super.destroy(),this._store.removeRemoteTracks()}}class $n extends Fn{get kind(){return Rn.UNPUBLISH_PREV}execute(e){var r,s,a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){const i=e.getResourcesByUserId(e.crtUserId),h=i.slice();i.length=0;const R=null===(s=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===s?void 0:s.createTraceId();null===(d=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_UNPUBLISH_PREV_COMMAND_T,JSON.stringify({resource:h}),R);const v=yield e.context.setRTCTotalRes(e.roomId,[Ye(It.UNPUBLISH,h)],ze([]),It.TOTAL_CONTENT_RESOURCE,ze([]));v!==t.ErrorCode.SUCCESS?null===(_=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_UNPUBLISH_PREV_COMMAND_R,JSON.stringify({status:n.FAILED,code:v}),R):null===(u=null===(l=e.context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_UNPUBLISH_PREV_COMMAND_R,JSON.stringify({status:n.SUCCESSED}),R)}))}}!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"}(gn||(gn={}));class Wn extends Fn{constructor(e,t,i,r,o,n,s,a){super(),this.roomId=e,this.roomType=t,this.context=i,this.joinType=r,this.livingType=o,this.innerUserDatas=n,this.outerUserDatas=s,this.traceId=a}get kind(){return Rn.JOINROOM}execute(r,s){var a,d,c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f,O;return i(this,void 0,void 0,(function*(){Jo(),Fo(this.roomType);const{context:i,service:L}=r;let N=o.L_RTC_CLIENT_JOIN_RTC_ROOM_R;if(this.roomType===gn.LIVE?N=o.L_RTC_CLIENT_JOIN_LIVING_ROOM_R:this.roomType===gn.CROSS_MUTI&&(N=o.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_R),i.getConnectionStatus()!==t.ConnectionStatus.CONNECTED)return null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.SIGNAL_DISCONNECTED,msg:"im not connected"}),this.traceId),{code:e.RCRTCCode.SIGNAL_DISCONNECTED};if(L.detectorMediaSever(),Ct(i.getNaviInfo()))return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"}),this.traceId),{code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR};if(!t.validate("roomId",this.roomId,t.notEmptyString,!0))return null===(u=null===(l=r.context)||void 0===l?void 0:l.logger)||void 0===u||u.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> roomId"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};if(!t.validate("roomType",this.roomType,(e=>void 0!==gn[e])))return null===(R=null===(h=r.context)||void 0===h?void 0:h.logger)||void 0===R||R.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> roomType"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};if(!t.validate("outerUserDatas",this.outerUserDatas,t.isObject,!1))return null===(C=null===(v=r.context)||void 0===v?void 0:v.logger)||void 0===C||C.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> outerUserDatas"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};if(this.outerUserDatas){if(!Object.keys(this.outerUserDatas).every((e=>t.validate(`outerUserDatas.${e}`,this.outerUserDatas[e],t.isString,!0))))return null===(g=null===(p=r.context)||void 0===p?void 0:p.logger)||void 0===g||g.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> outerUserDatas"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR}}if(!L.getNaviMS().length)return null===(T=null===(m=r.context)||void 0===m?void 0:m.logger)||void 0===T||T.error(N,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"No audio / video server address available"}),this.traceId),{code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER};const{code:A,data:y}=yield i.joinRTCRoom(this.roomId,this.roomType,this.livingType,this.joinType,this.innerUserDatas,this.outerUserDatas);if(A!==t.ErrorCode.SUCCESS||!y){Vo(this.roomId,A,r.getSessionId(),r.crtUserId);const t=40032===A?e.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED:A;return null===(E=null===(I=r.context)||void 0===I?void 0:I.logger)||void 0===E||E.error(N,JSON.stringify({status:n.FAILED,code:t,msg:"joinRoom failed"}),this.traceId),{code:t}}Vo(this.roomId,A,r.getSessionId(),r.crtUserId),Jo(this.roomId),r.initWithRoomData(y,this.traceId);r.getResourcesByUserId(r.crtUserId).length>0&&s.push(new $n);const k=null===(S=y.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===S?void 0:S.value;return k&&r.setCDNUris(JSON.parse(k)[0]),null===(O=null===(f=r.context)||void 0===f?void 0:f.logger)||void 0===O||O.info(N,JSON.stringify({status:n.SUCCESSED,userId:r.crtUserId,roomId:this.roomId}),this.traceId),{code:e.RCRTCCode.SUCCESS,data:y}}))}}!function(e){e[e.ROOM=1]="ROOM",e[e.PERSON=2]="PERSON"}(mn||(mn={})),function(e){e.PUBLISH="publish",e.SUBSCRIBE="subscribe"}(Tn||(Tn={})),function(e){e.BEGIN="begin",e.END="end"}(In||(In={})),function(e){e[e.SPREAD=0]="SPREAD",e[e.NO_SPREAD=-1]="NO_SPREAD"}(En||(En={}));class qn extends Fn{constructor(e,t,i,r){super(),this.headers=e,this.reqBody=t,this.traceId=i,this.isNeedUpdateMsas=r}execute(t,r){var o,n;return i(this,void 0,void 0,(function*(){const i=yield t.service.exchange(this.headers,this.reqBody,this.traceId,this.isNeedUpdateMsas);if(t.roomMode!==gn.LIVE)return i;const r=null===(n=null===(o=i.data)||void 0===o?void 0:o.urls)||void 0===n?void 0:n.pull_url;if(i.code!==e.RCRTCCode.SUCCESS||!r)return i;const s=JSON.parse(r);if(t.setCDNUris(s),(null==s?void 0:s.broadcast)===En.SPREAD){t.setCDNEnabel(!0);const e=Object.assign(Object.assign({},s),{enableInnerCDN:!0});es(t.context,t.roomId,e)}return i}))}}class Yn extends Fn{constructor(e,t,i,r){super(),this.tracks=e,this.subhook=t,this.forceReq=i,this.traceId=r}get kind(){return Rn.UPDATE_SUBSCRIBE_LIST}execute(r,s){var a,d,c,_,l,u,h,R,v,C,p,g,m,T;return i(this,void 0,void 0,(function*(){const{tracks:i,forceReq:I}=this,{roomId:E}=r;if(null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_UPDATE_SUBSCRIBELIST_COMMAND_T,`roomId: ${E}, forceReq: ${I}, trackIds: ${i.map(mt)}`,this.traceId),!t.validate("tracks",i,(()=>t.isArray(i)&&i.every((e=>e instanceof $e||e.track instanceof $e))),!0))return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.warn(o.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"tracks is invalid"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};let S=i.map((e=>e instanceof $e?{track:e}:Object.assign({},e)));const f={};S=S.filter((e=>{var t,i;const n=e.track.getTrackId();return r.getRemoteTrack(n)?!f[n]&&(f[n]=!0,!0):(null===(i=null===(t=r.context)||void 0===t?void 0:t.logger)||void 0===i||i.warn(o.L_UPDATE_SUBSCRIBELIST_COMMAND_P,`track cannot found in room -> trackId: ${n}`,this.traceId),!1)})).map((e=>Object.assign({},e)));const O=r.getSubscribedList().map((e=>Object.assign({},e)));if(!I){let t=!1;if(S.forEach((e=>{const i=O.findIndex((t=>t.track===e.track));if(-1===i)return void(t=!0);O.splice(i,1)[0].subTiny!==e.subTiny&&(t=!0)})),O.length){t=!0;const e=O.map((e=>e.track));null===(u=null===(l=r.context)||void 0===l?void 0:l.logger)||void 0===u||u.warn(o.L_CLEAR_UNSUBSCRIBE_LIST_O,JSON.stringify({list:e.map((e=>e.getTrackId()))}),this.traceId);const i=r.getSubscribedList().filter((t=>!e.includes(t.track)));r.resetSubscribedList(i)}if(!t)return null===(R=null===(h=r.context)||void 0===h?void 0:h.logger)||void 0===R||R.warn(o.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:n.SUCCESSED,msg:"subscribe list unchanged"}),this.traceId),{code:e.RCRTCCode.SUCCESS}}const{pc:L,pushOtherRooms:N,headers:A}=this.subhook(i);L.updateSubRemoteTracks(S.map((e=>e.track))),Uo(r.roomId,"",r.getSessionId()),Po(r.roomId,"",r.getSessionId());const y=yield Qn(S,!1,L,r);N&&(y.pushOtherRooms=N);const k=yield new qn(A,y,this.traceId,!0).execute(r,s);if(S.map((e=>e.track.getTrackId())),k.code!==e.RCRTCCode.SUCCESS)return wo(S,k.code),null===(C=null===(v=r.context)||void 0===v?void 0:v.logger)||void 0===C||C.error(o.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:n.FAILED,code:k.code}),this.traceId),{code:k.code};const{sdp:D,resultCode:b,message:U,subscribedList:P}=k.data;if(b!==e.RCRTCCode.SUCCESS)return wo(S,b),null===(g=null===(p=r.context)||void 0===p?void 0:p.logger)||void 0===g||g.error(o.L_UPDATE_SUBSCRIBELIST_COMMAND_R,JSON.stringify({status:n.FAILED,code:b}),this.traceId),{code:b};const M=yield L.setRemoteAnswer(D.sdp);if(M!==e.RCRTCCode.SUCCESS)return wo(S,M),{code:M};Sn.formatSourceIdMapFromSdp(D.sdp,"subscribe"),wo(S,M),Bo({subscribe:{time:Date.now()}});const x=null==P?void 0:P.map((e=>`${e.msid}_${e.mediaType}`)),w=S.filter((e=>null==x?void 0:x.includes(e.track.getTrackId()))),B=S.filter((e=>!(null==x?void 0:x.includes(e.track.getTrackId()))));null===(T=null===(m=r.context)||void 0===m?void 0:m.logger)||void 0===T||T.info(o.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.SUCCESSED,subSuccessTrackIds:x,failedList:B}),this.traceId);const V=r.getRemoteTracks();for(const e in V){const t=w.some((t=>t.track.getTrackId()===e));V[e].__innerSetSubscribed(t);const i=w.some((t=>t.track.getTrackId()===e&&t.subTiny));V[e].isVideoTrack()&&V[e].__innerSetIsTinyTrack(i)}return r.resetSubscribedList(w),B.length?{code:e.RCRTCCode.SUCCESS,failedList:B}:{code:e.RCRTCCode.SUCCESS}}))}}class zn extends Fn{constructor(e,t,i){super(),this.tracks=e,this.subhook=t,this.traceId=i}get kind(){return Rn.UNSUBSCRIBE}execute(r,s){var a,d,c,_;return i(this,void 0,void 0,(function*(){const{tracks:i}=this;if(null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_UNSUBSCRIBE_T,JSON.stringify({unSubscribeTrackIds:i.map(mt)}),this.traceId),!t.validate("tracks",i,(()=>t.isArray(i)&&i.length>0&&i.every((e=>e instanceof $e))),!0))return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.warn(o.L_ABSTRACT_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};const l=r.getSubscribedList().map((e=>Object.assign({},e))).filter((e=>!i.includes(e.track)));return r.polarisReport.sendR2(Tn.SUBSCRIBE,In.END,i.map((e=>e.getTrackId()))),qo(!0),new Yn(l,this.subhook,!1,this.traceId).execute(r,s)}))}}class Zn extends Fn{constructor(e,t,i){super(),this.subhook=e,this.tracks=t,this.onTrackUnpublish=i}execute(e,t){var r,n;return i(this,void 0,void 0,(function*(){const{tracks:i}=this,s=null===(r=e.context.logger)||void 0===r?void 0:r.createTraceId();null===(n=e.context.logger)||void 0===n||n.info(o.L_USER_LEFT_UNSUBSCRIBE_O,void 0,s),yield new zn(i,this.subhook,s).execute(e,t),i.forEach((t=>{t.__innerDestroy(),e.removeRemoteTrack(t.getTrackId())})),this.onTrackUnpublish(i)}))}}function Qn(e,t,r,o){return i(this,void 0,void 0,(function*(){return{sdp:yield r.createOffer(t),extend:JSON.stringify({resolutionInfo:r.getOutboundVideoInfo()}),subscribeList:e.filter((e=>{const t=e.track.getTrackId(),{userId:i}=rt(t),r=o.getResourcesByUserId(i);if(!r)return!1;const n=r.filter((e=>t===`${e.msid}_${e.mediaType}`)).length;return n})).map((e=>({simulcast:e.subTiny?Zo.TINY:Zo.NORMAL,resolution:"",uri:o.getPublishedResourceByTrackId(e.track.getTrackId()).uri}))),switchstream:!1}}))}function Xn(r,s,a){var d,c,_,l;return i(this,void 0,void 0,(function*(){const i=null===(d=null==r?void 0:r.logger)||void 0===d?void 0:d.createTraceId();null===(c=null==r?void 0:r.logger)||void 0===c||c.info(o.L_LIVING_ROOM_SPREAD_CDN_INFO_T,JSON.stringify({CDNUris:a}),i);const u=yield r.setRTCCDNUris(s,It.TOTAL_CONTENT_RESOURCE,JSON.stringify([a]));return u!==t.ErrorCode.SUCCESS?(null===(_=null==r?void 0:r.logger)||void 0===_||_.error(o.L_LIVING_ROOM_SPREAD_CDN_INFO_R,`status: ${n.FAILED}, code: ${u}`,i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(l=null==r?void 0:r.logger)||void 0===l||l.info(o.L_LIVING_ROOM_SPREAD_CDN_INFO_R,`status: ${n.SUCCESSED}`,i),{code:e.RCRTCCode.SUCCESS})}))}function es(r,s,a){var d,c,_,l;return i(this,void 0,void 0,(function*(){const i=null===(d=null==r?void 0:r.logger)||void 0===d?void 0:d.createTraceId();null===(c=null==r?void 0:r.logger)||void 0===c||c.info(o.L_LIVING_ROOM_SET_ROOM_CDN_INFO_T,`CDNUris: ${a}`,i);const u=yield r.setRTCData(s,"cdn_uris",JSON.stringify([a]),!0,mn.ROOM);return u!==t.ErrorCode.SUCCESS?(null===(_=null==r?void 0:r.logger)||void 0===_||_.error(o.L_LIVING_ROOM_SET_ROOM_CDN_INFO_R,`status: ${n.FAILED}, code: ${u}`,i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(l=null==r?void 0:r.logger)||void 0===l||l.info(o.L_LIVING_ROOM_SET_ROOM_CDN_INFO_R,`status: ${n.SUCCESSED}`,i),{code:e.RCRTCCode.SUCCESS})}))}function ts(t){return i(this,void 0,void 0,(function*(){const{context:i}=t,{roomId:r}=t,o=Object.assign({},t.getCDNUris(),{enableInnerCDN:t.getCDNEnable()});return(yield Promise.all([Xn(i,r,o),es(i,r,o)])).every((t=>t.code===e.RCRTCCode.SUCCESS))?{code:e.RCRTCCode.SUCCESS}:{code:e.RCRTCCode.SIGNAL_ERROR}}))}function is(r,s,a,d,c,_,l){return i(this,void 0,void 0,(function*(){const{roomId:i,crtUserId:u,roomMode:h}=s,R=[],v={},C={},p={},g=pt(r,i,l),m=Object.keys(g),T=s.getAllUserIds();for(let e=m.length-1;e>=0;e-=1){const t=m[e],i=T.indexOf(t);if(-1===i){R.push(t),v[t]=nt(g[t]);continue}const r=s.getResourcesByUserId(t),o=g[t],{publishedList:n,modifiedList:a,unpublishedList:d}=st(r,o,!0);v[t]=nt(n),C[t]=nt(d),p[t]=nt(a),T.splice(i,1)}T.length&&T.forEach((e=>{s.removeResourcesByUserId(e)})),s.assignRoomData(g),T.length&&(yield rs(T,s,c,d,l),a.onUserLeave(T)),R.length&&a.onUserJoin(R);for(const e in C){if(e===u)continue;const t=C[e];if(t.length){const e=t.map((e=>s.getRemoteTrack(it(e))));yield new Zn(c,e,a.onTrackUnpublish).execute(s,d)}}Object.keys(v).forEach((t=>{const i=v[t];if(0===i.length)return;const r=i.map((t=>{const i=it(t),{userId:r,tag:o,mediaType:n}=rt(i),a=n===e.RCMediaType.AUDIO_ONLY?new We(o,r):new qe(o,r);return s.addRemoteTrack(a),a.__innerSetRemoteMuted(0===t.state),a}));a.onTrackPublish(r)})),Object.keys(p).forEach((e=>{p[e].forEach((e=>{const t=it(e),i=s.getRemoteTrack(t);i.__innerSetRemoteMuted(0===e.state),i.isAudioTrack()?a.onAudioMuteChange(i):a.onVideoMuteChange(i)}))})),h===t.RTCMode.LIVE&&function(e,t,i){var r,s,a;if(!i)return void(null===(s=null===(r=t.context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_LIVING_ROOM_RECONNECTED_R,JSON.stringify({status:n.FAILED,code:"",msg:"cdn_uris not found"})));const d=JSON.parse(i),c=(null===(a=t.getCDNUris())||void 0===a?void 0:a.enableInnerCDN)!==d.enableInnerCDN;t.setCDNUris(d),c&&e.onCDNEnableChange(d.enableInnerCDN)}(a,s,_)}))}function rs(e,t,r,n,s){var a;return i(this,void 0,void 0,(function*(){const i=[],d=[];e.forEach((e=>{i.push(...t.getRemoteTracksByUserId(e)),d.push(e)})),i.length&&(null===(a=t.context.logger)||void 0===a||a.info(o.L_RES_UNPUB_UNSUBSCRIBE_O,void 0,s),yield new zn(i,r,s).execute(t,n),i.forEach((e=>t.removeRemoteTrack(e.getTrackId())))),d.length&&d.forEach((e=>t.removeResourcesByUserId(e)))}))}function os(e){var t;const{userId:i,userData:r,event:o,switchRoleType:n}=e;return{users:[{userId:i,extra:null===(t=r.filter((e=>"extra"===e.key))[0])||void 0===t?void 0:t.value,state:o,switchRoleType:n}]}}function ns(e){var t,i;const{userId:r,userData:o}=e,n=(e=>e.some((e=>"uris"===e.key||"cdn_uris"===e.key)))(o);if(!n)return;const s=null===(t=o.filter((e=>"uris"===e.key))[0])||void 0===t?void 0:t.value,a=null===(i=o.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 ss=(t,i,r)=>{const o=t.split("\r\nm"),n=r===e.RCMediaType.AUDIO_ONLY?"audio":"video",s=o.filter((e=>e.includes(`=${n}`)&&e.includes(i)))[0];let a=new RegExp(`a=ssrc:(.*?) msid:${i}`);const d=s.match(a);return d?d[1]:""};class as extends Fn{constructor(e,t,i){super(),this.msgContent=e,this.subhook=t,this.traceId=i}get kind(){return Rn.PARSE_USERSTATE}get priority(){return Cn.NORMAL}execute(e,t){return i(this,void 0,void 0,(function*(){const i=[],r=[],n=[],s=[],a={joined:i,left:r,upgrade:n,downgrade:s},{users:d}=this.msgContent;if(0===d.length)return a;for(let t=0;t<d.length;t++){const i=d[t];if(i.extra&&i.extra.roomId!==e.roomId)return a;if(1===Number(i.state)&&!e.getRemoteUserIds().includes(i.userId))return a}d.forEach((t=>{var a,d,c,_;const{userId:l}=t;if(0===Number(t.state)){const r=e.getResourcesByUserId(l);r||(t.switchRoleType?n.push(l):i.push(l),null===(d=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_PARSE_USERSTATE_COMMAND_R,JSON.stringify({userId:l,msg:"user "+(t.switchRoleType?"upgrade":"joined")}),this.traceId)),e.setResourcesByUserId(l,r||[])}else null===(_=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_PARSE_USERSTATE_COMMAND_R,JSON.stringify({userId:l,msg:"user "+(t.switchRoleType?"downgrade":"left")}),this.traceId),t.switchRoleType?s.push(l):r.push(l)}));const c=[...r,...s];return c.length&&(yield rs(c,e,this.subhook,t,this.traceId)),a}))}}class ds extends Fn{constructor(e,t,i,r,o,n){super(),this.msgContent=e,this.messageType=t,this.senderId=i,this.subhook=r,this.callback=o,this.traceId=n}get kind(){return Rn.PARSE_REMOTERES}get priority(){return Cn.NORMAL}execute(t,r){var s,a,d,c;return i(this,void 0,void 0,(function*(){const{uris:i}=this.msgContent,_=[],l=[],u=[];let h;const R=this.senderId,{messageType:v}=this;if(!t.getRemoteUserIds().includes(R))return;const C=t.getResourcesByUserId(R)||[];switch(v){case It.MODIFY:u.push(...i);break;case It.PUBLISH:_.push(...i);break;case It.UNPUBLISH:l.push(...i);break;case It.TOTAL_CONTENT_RESOURCE:h=st(C,i),_.push(...h.publishedList),l.push(...h.unpublishedList),u.push(...h.modifiedList)}if(_.length>0){const i=C.map(it),d=[],c=[];if(_.forEach((r=>{const o=it(r),n=i.indexOf(o),{userId:s,tag:a,mediaType:_}=rt(o);n>-1?C[n]=r:C.push(r);let l=t.getRemoteTrack(o);l?l.isSubscribed()&&d.push(l):(l=_===e.RCMediaType.AUDIO_ONLY?new We(a,s):new qe(a,s),t.addRemoteTrack(l),c.push(l)),l.__innerSetRemoteMuted(0===r.state)})),d.length){const i=d.map((e=>e.getTrackId())),{code:c}=yield new Yn(d,this.subhook,!0,this.traceId).execute(t,r);c!==e.RCRTCCode.SUCCESS&&(null===(a=null===(s=t.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RESUB_REPUB_RES_R,JSON.stringify({status:n.FAILED,trackIds:i,code:c}),this.traceId))}this.callback.onTrackPublish(c)}if(l.length>0){const e=l.map(it);for(let t=C.length-1;t>=0;t-=1){const i=C[t];e.includes(it(i))&&C.splice(t,1)}const i=l.map((e=>{const i=it(e);return t.getRemoteTrack(i)}));yield new Zn(this.subhook,i,this.callback.onTrackUnpublish).execute(t,r)}if(u.length>0){const e=C.map(it);for(let i=0;i<u.length;i+=1){const r=u[i],o=it(r),n=e.indexOf(o);C[n].state=r.state;const s=t.getRemoteTrack(o);s.__innerSetRemoteMuted(0===r.state),s.isAudioTrack()?this.callback.onAudioMuteChange(s):this.callback.onVideoMuteChange(s)}}if(t.setResourcesByUserId(R,C),t.roomMode!==gn.LIVE)return;const p=this.msgContent;if(!p.cdn_uris)return;const g=(null===(d=t.getCDNUris())||void 0===d?void 0:d.enableInnerCDN)!==p.cdn_uris[0].enableInnerCDN;t.setCDNUris(p.cdn_uris[0]),g&&this.callback.onCDNEnableChange(!!(null===(c=t.getCDNUris())||void 0===c?void 0:c.enableInnerCDN))}))}}class cs extends Fn{constructor(e,t,i,r){super(),this.tracks=e,this.subhook=t,this.forceReq=i,this.traceId=r}get kind(){return Rn.SUBSCRIBE}execute(r,s){var a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){const{tracks:i,forceReq:h}=this;if(null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:i.map(mt),forceReq:h}),this.traceId),!t.validate("tracks",i,(()=>t.isArray(i)&&i.length>0&&i.every((e=>e instanceof $e||e.track instanceof $e))),!0))return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};const R=r.getSubscribedList().map((e=>Object.assign({},e))),v=i.map((e=>e instanceof $e?{track:e}:e));let C=!1;const p=[];return v.forEach((e=>{const t=e.track.getTrackId();p.push(t);const i=R.find((e=>e.track.getTrackId()===t));i&&i.subTiny===e.subTiny||(i?i.subTiny=e.subTiny:R.push(e),C=!0)})),C||h?(r.polarisReport.sendR2(Tn.SUBSCRIBE,In.BEGIN,p),Wo(!0),new Yn(R,this.subhook,!0,this.traceId).execute(r,s)):(null===(u=null===(l=r.context)||void 0===l?void 0:l.logger)||void 0===u||u.warn(o.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.SUCCESSED,msg:"repeat subscribe"}),this.traceId),{code:e.RCRTCCode.SUCCESS})}))}}class _s extends Fn{constructor(e,t,i=3e4){var r;super(),this.tracks=e,this.pubhook=t,this.signalRetryTime=i,this._logger=null,this._logger=Le.getLogger(),this._traceId=null===(r=this._logger)||void 0===r?void 0:r.createTraceId()}get kind(){return Rn.PUBLISH}_removePubFailedTracks(e,t){e.forEach((e=>{var i;const r=e instanceof xe?e:e.track;null===(i=this._logger)||void 0===i||i.debug(o.L_ABSTRACT_ROOM_PUBLISH_P,`remove pub failed track from peerconnection -> trackId: ${r.getTrackId()}`,this._traceId),t.removeLocalTrackById(r.getTrackId())}))}__publish(t,r,s,a,d){var c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const{pcName:i,pc:v,headers:C}=r,{roomId:p}=t,g=[];s.forEach((e=>{const{track:t}=e instanceof xe?{track:e}:e;g.push(t)})),s.sort(((e,t)=>{const{track:i}=e instanceof xe?{track:e}:e,{max:r}=i.getBitrate(),{track:o}=t instanceof xe?{track:t}:t,{max:n}=o.getBitrate();return r-n}));if(v.getLocalTracks().length+((e,t)=>{let i=0;return e.forEach((e=>{const r=e instanceof xe?e.getTrackId():e.track.getTrackId();t.getLocalTrack(r)||(e instanceof xe?i++:e.pubTiny&&e.track.isVideoTrack()&&(i+=2))})),i})(s,v)>10)return null===(c=this._logger)||void 0===c||c.error(o.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PUBLISH_TRACK_LIMIT_EXCEEDED,trackIds:s.map(mt),msg:`pcName: ${i} publish track limit exceeded`}),this._traceId),{code:e.RCRTCCode.PUBLISH_TRACK_LIMIT_EXCEEDED,tracks:g};null===(_=this._logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_PUBLISH_P,`publish tracks -> roomId: ${p}, tracks: ${s.map(mt)}`,this._traceId);const m=[];for(let t=0;t<s.length;t++){const i=s[t],{track:r,pubTiny:n}=i instanceof xe?{pubTiny:!1,track:i}:i;if(r.isVideoTrack()&&n){let t;try{t=r.__innerGetMediaStreamTrack().clone();const i=n.frameRate||e.RCFrameRate.FPS_15,o=n.resolution||e.RCResolution.W176_H144,{width:s,height:a}=dt(o),d=lt(i);yield t.applyConstraints({width:s,height:a,frameRate:d})}catch(e){null==t||t.stop(),null===(l=this._logger)||void 0===l||l.warn(o.L_ABSTRACT_ROOM_PUBLISH_P,`pubTiny failed -> id: ${r.getTrackId()}, msg: ${e.message}`,this._traceId);break}const i=new Be(r.getTag(),r.getUserId(),t,!0);m.push(i),v.addLocalTrack(i)}v.addLocalTrack(r)}v.clearReTryExchangeTimer();const T=t.useMutilPeerC?[]:t.getSubscribedList();((e,t,i)=>{var r;const o=Do.getMemo(),n={dur:0,cod:0,rid:e,csnid:(null===(r=o.clientData)||void 0===r?void 0:r.clientSessionId)||"",snid:t,rsid:"",msa:"",msas:[],sigs:[],time:0,resid:"",mtp:0,smct:1,cr:"unknown",net:"unknown",uid:i,stp:0};o.qualityPublishReportData=n,o.publish={start:Date.now()}})(t.roomId,t.getSessionId(),t.crtUserId);const I=yield Qn(T,!1,v,t);a&&(I.pushOtherRooms=a),Sn.formatSourceIdMapFromSdp(I.sdp.sdp,"publish");const E=yield new qn(C,I,this._traceId,!0).execute(t,d);if(E.code!==e.RCRTCCode.SUCCESS)return Ho(g,E.code),null===(u=this._logger)||void 0===u||u.error(o.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:n.FAILED,tracks:s.map(mt),code:E.code,msg:"exchange failed"}),this._traceId),this._removePubFailedTracks(s,v),{code:E.code,tracks:g};const{sdp:S,resultCode:f,message:O}=E.data;if(f!==e.RCRTCCode.SUCCESS)return Ho(g,f),null===(h=this._logger)||void 0===h||h.error(o.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:n.FAILED,trackIds:s.map(mt),code:f,msg:`exchange inner failed: ${O}`}),this._traceId),this._removePubFailedTracks(s,v),{code:f,tracks:g};const L=yield v.setRemoteAnswer(S.sdp);return L!==e.RCRTCCode.SUCCESS?(Ho(g,L),null===(R=this._logger)||void 0===R||R.error(o.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({status:n.FAILED,trackIds:s.map(mt),code:L,msg:"set remote answer error"}),this._traceId),{code:L,tracks:g}):(m.length&&this._updateTinyTrackIdSSRCMap(t,I.sdp.sdp,m),Object.assign(Object.assign({},E),{tracks:g}))}))}_updateTinyTrackIdSSRCMap(t,i,r){r.forEach((r=>{const o=ss(i,r.getStreamId(),e.RCMediaType.VIDEO_ONLY);t.setTrackIdSSRCMap(Number(o),r.getTrackId())}))}_mergePublishRes(r,s){var a,d;return i(this,void 0,void 0,(function*(){const i=s.crtUserId,{roomId:c}=s;let _="";const l=[],u=s.getResourcesByUserId(i),h=[...u];let R=[];r.forEach((t=>{if(t.code!==e.RCRTCCode.SUCCESS){const{tracks:e}=t;return void l.push({code:t.code,tracks:e})}const{publishList:i,urls:r,mcuPublishList:o}=t.data;_=null==r?void 0:r.liveUrl;i.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:s.getTrackState(it(e))},e))).forEach((e=>{const{isInclude:t,index:i}=((e,t)=>{let i=!1,r=0;for(let o=0;o<t.length;o++){const n=t[o];if(`${e.msid}_${e.mediaType}`==`${n.msid}_${n.mediaType}`){i=!0,r=o;break}}return{isInclude:i,index:r}})(e,h);t?h.splice(i,1,e):h.push(e)}));const n=(null==o?void 0:o.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:1},e))))||[];R=n}));const{publishedList:v}=st(u,h),C=Object.assign(Object.assign({},s.getCDNUris()),{enableInnerCDN:s.getCDNEnable()}),p=C&&C.broadcast===En.SPREAD?JSON.stringify([C]):"";Do.getMemo().publishSignalTotal={start:Date.now()};const g=yield s.context.setRTCTotalRes(c,[Ye(It.PUBLISH,v)],ze(h),It.TOTAL_CONTENT_RESOURCE,ze(R),p);if(g!==t.ErrorCode.SUCCESS)return Go(h,g),null===(a=this._logger)||void 0===a||a.error(o.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:n.FAILED,code:g,msg:"send publish streams notification failed"}),this._traceId),{code:e.RCRTCCode.SIGNAL_ERROR};Go(h,g),Bo({publish:{time:Date.now()}}),s.setResourcesByUserId(i,h);const m=v.map((e=>it(e)));s.polarisReport&&s.polarisReport.sendR2(Tn.PUBLISH,In.BEGIN,m),v.forEach((e=>{const t=s.useMutilPeerC?`${c}_${(e=>{const t=e.split("_");return{tag:t.pop(),userId:t.join("_")}})(e.msid).tag}`:`${c}_pub`,{pc:i}=s.peerMgr.getPCItemByPCName(t);i.getLocalTrack(`${e.msid}_${e.mediaType}`).__innerSetPublished(!0)})),null===(d=this._logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:n.SUCCESSED,code:l.length?e.RCRTCCode.SOME_TRACKS_PUBLISH_FAILED:e.RCRTCCode.SUCCESS,pubSuccessTrackIds:m}),this._traceId);const T={code:e.RCRTCCode.SUCCESS};return _&&(T.liveUrl=_),l.length&&(T.failedTracks=l,T.code=e.RCRTCCode.SOME_TRACKS_PUBLISH_FAILED),T}))}execute(r,s){var a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){let{tracks:i}=this;if(null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_PUBLISH_T,JSON.stringify({trackIds:i.map(mt)})),!t.validate("tracks",i,(()=>t.isArray(i)&&i.length>0&&i.every((e=>e instanceof xe||e.track instanceof xe))),!0))return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),this._traceId),{code:e.RCRTCCode.PARAMS_ERROR};if(i=i.filter((e=>{var t,i;const{track:n}=e instanceof xe?{track:e}:e,s=n.isDestroyed();return s&&(null===(i=null===(t=r.context)||void 0===t?void 0:t.logger)||void 0===i||i.warn(o.L_ABSTRACT_ROOM_PUBLISH_P,JSON.stringify({msg:`track -> ${n.getTrackId()} has beem destroyed`}),this._traceId)),!s})),!i.length)return null===(u=null===(l=r.context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PUBLISH_TRACKS_IS_INVALID,msg:"params tracks is invalid"}),this._traceId),{code:e.RCRTCCode.PUBLISH_TRACKS_IS_INVALID};const h=[],{plist:R,pushOtherRooms:v}=this.pubhook(i);for(let e=0;e<R.length;e++){const t=R[e];h.push(this.__publish(r,t,t.tracks,v,s))}const C=yield Promise.all(h);return yield this._mergePublishRes(C,r)}))}}class ls extends Fn{constructor(e,t){super(),this.tracks=e,this.unpubhook=t}get kind(){return Rn.UNPUBLISH}__unpublish(t,r,s,a){var d,c,_,l;return i(this,void 0,void 0,(function*(){const{pcName:i,pc:u}=s,h=a.map((e=>e.getTrackId()));if(0===h.map(t.getPublishedResourceByTrackId.bind(t)).filter((e=>!!e)).length)return{code:e.RCRTCCode.SUCCESS,tracks:a};h.forEach((e=>u.removeLocalTrackById(e))),t.polarisReport.sendR2(Tn.PUBLISH,In.END,h),u.clearReTryExchangeTimer();const R=t.useMutilPeerC?[]:t.getSubscribedList();((e,t,i)=>{var r;const o=Do.getMemo(),n={dur:0,cod:0,rid:e,csnid:(null===(r=o.clientData)||void 0===r?void 0:r.clientSessionId)||"",snid:t,rsid:"",msa:"",msas:[],sigs:[],time:0,resid:"",mtp:0,smct:1,uid:i,stp:0};o.qualityUnpublishReportData=n,o.unpublish={start:Date.now()}})(t.roomId,t.getSessionId(),t.crtUserId);const v=yield Qn(R,!1,u,t),{pushOtherRooms:C,headers:p}=this.unpubhook(a,i);C&&(v.pushOtherRooms=C);const g=yield new qn(p,v,this._traceId,!0).execute(t,r);if(g.code!==e.RCRTCCode.SUCCESS)return Ko(a,g.code),null===(c=null===(d=t.context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_ABSTRACT_ROOM_UNPUBLISH_P,JSON.stringify({status:n.FAILED,code:g.code,trackIds:a.map(mt),msg:"exchange failed"}),this._traceId),{code:g.code,tracks:a};const{resultCode:m,message:T}=g.data;return m!==e.RCRTCCode.SUCCESS?(Ko(a,g.data.resultCode),null===(l=null===(_=t.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_ABSTRACT_ROOM_UNPUBLISH_P,JSON.stringify({status:n.FAILED,code:m,trackIds:a.map(mt),msg:`exchange inner failed: ${T}`}),this._traceId),{code:m,tracks:a}):Object.assign(Object.assign({},g),{tracks:a})}))}_mergeUnpublishRes(r,s){var a,d,c,_;return i(this,void 0,void 0,(function*(){const l=r.context.getCurrentId(),{roomId:u}=r,h=[],R=[],v=[],C=[];let p=[];for(let t=0;t<s.length;t++){const i=s[t],{tracks:o}=i;if(i.code!==e.RCRTCCode.SUCCESS){R.push({code:i.code,tracks:o});continue}const{mcuPublishList:n}=i.data,a=i.tracks.map((e=>e.getTrackId()));C.push(...a);const d=a.map(r.getPublishedResourceByTrackId.bind(r)).filter((e=>!!e));v.push(...d),h.push(i);const c=n?n.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:1},e))):[];p=c}const g=r.getResourcesByUserId(l),m=g.filter((e=>!v.includes(e)));Do.getMemo().unpublishSignalTotal={start:Date.now()};const T=yield r.context.setRTCTotalRes(u,[Ye(It.UNPUBLISH,v)],ze(m),It.TOTAL_CONTENT_RESOURCE,ze(p));if(T!==t.ErrorCode.SUCCESS)return jo(g,T),null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:n.FAILED,code:T,msg:"send unpublish notification failed"}),this._traceId),{code:e.RCRTCCode.SIGNAL_ERROR};null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:n.SUCCESSED,code:R.length?e.RCRTCCode.SOME_TRACKS_PUBLISH_FAILED:e.RCRTCCode.SUCCESS,msg:"unpublish success",unPubResourceIds:C}),this._traceId),jo(g,T),h.forEach((e=>i(this,void 0,void 0,(function*(){const{sdp:t}=e.data,{tracks:i}=e,o=r.peerMgr.getPCByTrackId(i[0].getTrackId());yield o.setRemoteAnswer(t.sdp)})))),r.setResourcesByUserId(l,m);const I={code:e.RCRTCCode.SUCCESS};return R.length&&(I.failedTracks=R,I.code=e.RCRTCCode.SOME_TRACKS_PUBLISH_FAILED),I}))}execute(r,s){var a,d,c,_,l;return i(this,void 0,void 0,(function*(){const{crtUserId:i,roomId:u}=r,{tracks:h}=this;this._traceId=null===(a=r.context.logger)||void 0===a?void 0:a.createTraceId(),null===(c=null===(d=r.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_ABSTRACT_ROOM_UNPUBLISH_T,JSON.stringify({trackIds:h.map(mt)}));if(!t.validate("tracks",h,(()=>h.every((e=>e.getUserId()===i&&e instanceof xe))),!0))return null===(l=null===(_=r.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"})),{code:e.RCRTCCode.PARAMS_ERROR};const R=r.peerMgr.createPeerCList(h),v=[];for(let e=0;e<R.length;e++){const{tracks:t}=R[e];v.push(this.__unpublish(r,s,R[e],t))}const C=yield Promise.all(v);let p=C.length;if(C.forEach((t=>{t.code!==e.RCRTCCode.SUCCESS||t.data||(p-=1)})),0===p)return{code:e.RCRTCCode.SUCCESS};return yield this._mergeUnpublishRes(r,C)}))}}class us extends Fn{constructor(e,t){super(),this.localTrack=e,this._recvSignalResultFn=t}get kind(){return Rn.LOCAL_TRACK_MUTE}execute(e,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const{localTrack:i}=this,r=i.getTrackId(),{crtUserId:R,roomId:v}=e,C=!i.isLocalMuted(),p=null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();null===(c=null===(d=e.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_T,JSON.stringify({enabled:C,trackId:this.localTrack.getTrackId()}),p);const g=[{resourceId:r,enabled:C}],m=e.getResourcesByUserId(R),T=[];for(let e=0;e<m.length;e+=1){const t=m[e],i=it(t),r=g.findIndex((e=>e.resourceId===i));if(r>=0){const{enabled:e}=g[r];t.state=e?1:0,T.push(t);break}}const I=yield e.context.setRTCTotalRes(v,[Ye(It.MODIFY,T)],ze(m),It.TOTAL_CONTENT_RESOURCE);this._recvSignalResultFn(I),I!==t.ErrorCode.SUCCESS&&(null===(l=null===(_=e.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_R,JSON.stringify({status:n.FAILED,code:I,msg:"signal error"}),p)),null===(h=null===(u=e.context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_LOCAL_TRACK_SET_LOCAL_MUTED_SPREAD_R,JSON.stringify({status:n.SUCCESSED}),p)}))}}class hs extends Fn{constructor(e,t,i){super(),this.pcName=e,this.isPub=t,this.retryHook=i}get kind(){return Rn.RETRY_EXCHANGE}get priority(){return Cn.HIGH}execute(t,r){var n,s,a,d,c;return i(this,void 0,void 0,(function*(){const i=null===(s=null===(n=t.context)||void 0===n?void 0:n.logger)||void 0===s?void 0:s.createTraceId();null===(d=null===(a=t.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_RETRY_EXCHANGE_COMMAND_T),this._store=t,this._userId=t.context.getCurrentId();const{pcName:_,isPub:l}=this,{useMutilPeerC:u}=t,{pc:h}=t.peerMgr.getPCItemByPCName(_),R=l&&u?[]:t.getSubscribedList(),v=yield Qn(R,!0,h,t),{pushOtherRooms:C,headers:p}=this.retryHook(_);C&&(v.pushOtherRooms=C);const g=yield new qn(p,v,i).execute(t,r);if(g.code!==e.RCRTCCode.SUCCESS)return;const{sdp:m,resultCode:T}=g.data;if(T!==e.RCRTCCode.SUCCESS)return;h.clearReTryExchangeTimer();if((yield h.setRemoteAnswer(m.sdp))!==e.RCRTCCode.SUCCESS)return;if(!this.isPub)return;const I=(null===(c=g.data)||void 0===c?void 0:c.publishList)||[],{plus:E,minus:S}=this._diffPublishListChange(I);(E.length||S.length)&&(yield this._spreadPublishListUri(E,S,i))}))}_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,o=r.findIndex((e=>{const{mediaType:r,msid:o}=e;return t===r&&i===o}));if(-1===o){const t=Object.assign({tag:i.split("_").pop(),state:this._store.getTrackState(it(e))},e);r.push(t)}else r[o].uri=e.uri})):r=e.map((e=>Object.assign({tag:e.msid.split("_").pop(),state:this._store.getTrackState(it(e))},e)));const{publishedList:o,unpublishedList:n}=st(t,r,!0);return this._store.setResourcesByUserId(this._userId,r),{plus:o,minus:n}}_spreadPublishListUri(e,r,s){var a,d,c;return i(this,void 0,void 0,(function*(){const i=this._store.getResourcesByUserId(this._userId);null===(a=this._store.context.logger)||void 0===a||a.info(o.L_RETRY_EXCHANGE_SPREAD_T,JSON.stringify({plus:e,minus:r,allPublishList:i,pcName:this.pcName}),s);const _=[];r.length&&_.push(Ye(It.UNPUBLISH,r)),e.length&&_.push(Ye(It.PUBLISH,e));(yield this._store.context.setRTCTotalRes(this._store.roomId,_,ze(i),It.TOTAL_CONTENT_RESOURCE))===t.ErrorCode.SUCCESS?null===(d=this._store.context.logger)||void 0===d||d.info(o.L_RETRY_EXCHANGE_SPREAD_R,`status: ${n.SUCCESSED}`,s):null===(c=this._store.context.logger)||void 0===c||c.error(o.L_RETRY_EXCHANGE_SPREAD_R,`status: ${n.FAILED}`,s)}))}}class Rs extends Fn{constructor(e,t,i,r,o=3e4,n,s){super(),this.subhook=e,this.callbacks=t,this._retryHook=i,this._pubhook=r,this._signalRetryTime=o,this._pullRTCRoomStatus=n,this.livingType=s}get kind(){return Rn.ON_SIGNAL_RECONNECTED}get priority(){return Cn.HIGH}execute(e,r){var s,a,d,c,_,l;return i(this,void 0,void 0,(function*(){const{roomId:i,roomMode:u}=e;this._roomId=i,this._roomMode=u;const h=null===(a=null===(s=e.context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();null===(c=null===(d=e.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_ABSTRACT_ROOM_IM_RECONNECTED_T,void 0,h);if(e.peerMgr.getPCList().some((e=>"closed"===e.getRTCPeerConn().connectionState)))return null===(l=null===(_=e.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:n.FAILED,msg:"RTCPeerConnection closed. Please rejoin room to restore services"}),h),void(this.callbacks.onPeerClosed&&this.callbacks.onPeerClosed());const{code:R}=yield e.context.rtcPing(i,u);if(40001===R){(yield this._joinRoom(e,h,r))===t.ErrorCode.SUCCESS&&(yield this._restoreMediaServer(e,r))}else yield this._pullRTCRoomStatus(this._roomId,h).execute(e,r)}))}_joinRoom(e,r,s){var a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const{code:i,data:R}=yield e.context.joinRTCRoom(this._roomId,this._roomMode,this.livingType);if(i!==t.ErrorCode.SUCCESS)return void(null===(d=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:n.FAILED,code:i,msg:"im reconnect joinRTCRoom failed"}),r));if(!R)return void(null===(_=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:n.FAILED,msg:"im reconnect joinRTCRoom, roomData is empty"}),r));const v=null===(l=R.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===l?void 0:l.value;return yield is(R,e,this.callbacks,s,this.subhook,v,r),null===(h=null===(u=e.context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_ABSTRACT_ROOM_IM_RECONNECTED_R,JSON.stringify({status:n.SUCCESSED,roomData:R}),r),i}))}_restoreMediaServer(e,t){return i(this,void 0,void 0,(function*(){const{useMutilPeerC:i}=e.peerMgr,r=e.getLocalTracks(),o=Object.values(e.getRemoteTracks()).filter((e=>!!e.isSubscribed()));if(i)return o.length&&(yield new cs(o,this.subhook,!0).execute(e,t)),void(r.length&&(yield new _s(r,this._pubhook,this._signalRetryTime).execute(e,t)));r.length&&(yield new _s(r,this._pubhook,this._signalRetryTime).execute(e,t)),!r.length&&o.length&&(yield new cs(o,this.subhook,!0).execute(e,t))}))}}class vs extends Jn{constructor(e,t,i,r=vn.NORMAL,o){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=o,this._logger=null,this._logger=Le.getLogger()}get kind(){return Rn.ASYNC_COMMAND}execute(t,r){var o,n,s;return i(this,void 0,void 0,(function*(){const{tracks:i}=this;if(this.state===vn.NORMAL){const e=t.getSubscribedList().slice(),{code:n,failedList:s}=yield new Yn(i,this.subhook,!0,this.traceId).execute(t,r),a=t.getSubscribedList().slice(),{subscribe:d,unsubscribe:c}=this.pickoutSubscribed(a,e);return null===(o=this.callbacks)||void 0===o||o.onTaskCompleted({code:n,subscribe:d,unsubscribe:c,failedList:s}),{code:n,failedList:s}}if(this.state===vn.TAIL){const{code:i}=yield new vs(this.tracks,this.subhook,this.callbacks,vn.MIDDLE,this.traceId).execute(t,r);if(i===e.RCRTCCode.SUCCESS){const i=t.getCollectSubscribeList().slice(0),o=t.getSubscribedList().slice(),{code:a,failedList:d}=yield new Yn(i,this.subhook,!0).execute(t,r);if(a!==e.RCRTCCode.SUCCESS)return null===(n=this.callbacks)||void 0===n||n.onTaskCompleted({code:a,subscribe:[],unsubscribe:[],failedList:d}),{code:a,failedList:d};const c=t.getSubscribedList().slice(0),{subscribe:_,unsubscribe:l}=this.pickoutSubscribed(c,o);return null===(s=this.callbacks)||void 0===s||s.onTaskCompleted({code:a,subscribe:_,unsubscribe:l,failedList:d}),{code:a,failedList:d}}return{code:i}}return Jn.AsyncUpdateSubscribeTasks.splice(Jn.AsyncUpdateSubscribeTasks.length,0,...this.tracks),new Promise((r=>{const o=this.formateTrack(i);t.resetCollectSubscribeList(o),r({code:e.RCRTCCode.SUCCESS})}))}))}}class Cs extends Jn{constructor(e,t,i,r=vn.NORMAL,o){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=o}get kind(){return Rn.ASYNC_COMMAND}execute(r,s){var a,d,c,_,l;return i(this,void 0,void 0,(function*(){const{tracks:i}=this;if(this.state===vn.NORMAL){const e=r.getSubscribedList().slice(),{code:t,failedList:o}=yield new cs(i,this.subhook,!1,this.traceId).execute(r,s),n=r.getSubscribedList().slice(),{subscribe:d,unsubscribe:c}=this.pickoutSubscribed(n,e);return null===(a=this.callbacks)||void 0===a||a.onTaskCompleted({code:t,subscribe:d,unsubscribe:c,failedList:o}),{code:t,failedList:o}}if(null===(c=null===(d=r.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_ABSTRACT_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:i.map(mt)}),this.traceId),!t.validate("tracks",i,(()=>t.isArray(i)&&i.length>0&&i.every((e=>e instanceof $e||e.track instanceof $e))),!0))return null===(l=null===(_=r.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_ABSTRACT_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};const u=this.getSubscribedList(r).map((e=>Object.assign({},e))),h=i.map((e=>e instanceof $e?{track:e}:e)),R=[];if(h.forEach((e=>{const t=e.track.getTrackId();R.push(t);const i=u.find((e=>e.track.getTrackId()===t));if(i){if(i.subTiny===e.subTiny)return;i.subTiny=e.subTiny}else u.push(e)})),r.polarisReport.sendR2(Tn.SUBSCRIBE,In.BEGIN,R),this.state===vn.TAIL){const{code:t}=yield new Cs(this.tracks,this.subhook,this.callbacks,vn.MIDDLE,this.traceId).execute(r,s);if(t===e.RCRTCCode.SUCCESS){const e=r.getCollectSubscribeList().slice(0);return new vs(e,this.subhook,this.callbacks,vn.NORMAL,this.traceId).execute(r,s)}return{code:t}}return Jn.AsyncSubscribeTasks.splice(Jn.AsyncSubscribeTasks.length,0,...this.tracks),new Promise((t=>{r.resetCollectSubscribeList(u),t({code:e.RCRTCCode.SUCCESS})}))}))}getSubscribedList(e){return this.state===vn.MIDDLE?e.getCollectSubscribeList():e.getSubscribedList()}}class ps extends Jn{constructor(e,t,i,r=vn.NORMAL,o){super(r),this.tracks=e,this.subhook=t,this.callbacks=i,this.traceId=o}get kind(){return Rn.ASYNC_COMMAND}execute(r,s){var a,d,c,_,l;return i(this,void 0,void 0,(function*(){const{tracks:i}=this;if(this.state===vn.NORMAL){const e=r.getSubscribedList().slice(),{code:t,failedList:o}=yield new zn(i,this.subhook,this.traceId).execute(r,s),n=r.getSubscribedList().slice(),{subscribe:d,unsubscribe:c}=this.pickoutSubscribed(n,e);return null===(a=this.callbacks)||void 0===a||a.onTaskCompleted({code:t,subscribe:d,unsubscribe:c,failedList:o}),{code:t,failedList:o}}if(null===(c=null===(d=r.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_ABSTRACT_ROOM_UNSUBSCRIBE_T,JSON.stringify({trackIds:i.map(mt)}),this.traceId),!t.validate("tracks",i,(()=>t.isArray(i)&&i.length>0&&i.every((e=>e instanceof $e))),!0))return null===(l=null===(_=r.context)||void 0===_?void 0:_.logger)||void 0===l||l.warn(o.L_ABSTRACT_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),this.traceId),{code:e.RCRTCCode.PARAMS_ERROR};const u=this.getSubscribedList(r).map((e=>Object.assign({},e))).filter((e=>!i.includes(e.track)));if(r.polarisReport.sendR2(Tn.SUBSCRIBE,In.END,i.map((e=>e.getTrackId()))),this.state===vn.TAIL){const{code:t}=yield new ps(this.tracks,this.subhook,this.callbacks,vn.MIDDLE,this.traceId).execute(r,s);if(t===e.RCRTCCode.SUCCESS){const e=r.getCollectSubscribeList().slice(0).map((e=>e.track));return new vs(e,this.subhook,this.callbacks,vn.NORMAL,this.traceId).execute(r,s)}return{code:t}}return Jn.AsyncUnsubscribeTasks.splice(Jn.AsyncUnsubscribeTasks.length,0,...this.tracks),new Promise((t=>{r.resetCollectSubscribeList(u),t({code:e.RCRTCCode.SUCCESS})}))}))}getSubscribedList(e){return this.state===vn.MIDDLE?e.getCollectSubscribeList():e.getSubscribedList()}}var gs;!function(e){e[e.JOIN=0]="JOIN",e[e.LEAVE=1]="LEAVE",e[e.OFFLINE=2]="OFFLINE",e[e.RESOURCECHANGE=3]="RESOURCECHANGE"}(gs||(gs={}));class ms extends Fn{constructor(e,t,i,r,o,n,s){super(),this._roomId=e,this._traceId=t,this._context=i,this._callbacks=r,this._subhook=o,this._dealUserAppListener=n,this._targetPullVersion=s}get kind(){return Rn.PULL_RTCROOM_STATUS}execute(e,r){var s,a,d,c;return i(this,void 0,void 0,(function*(){const i=e.getRoomStatusVersion();if(null===(s=this._context.logger)||void 0===s||s.info(o.L_PULL_ROOM_STATUS_T,JSON.stringify({roomId:this._roomId,localVersion:i}),this._traceId),this._targetPullVersion&&this._targetPullVersion<=i)return null===(a=this._context.logger)||void 0===a||a.info(o.L_PULL_ROOM_STATUS_R,JSON.stringify({status:n.SUCCESSED,msg:"the roomData has been pulled",localVersion:i,targetPullVersion:this._targetPullVersion}),this._traceId),{code:t.ErrorCode.SUCCESS};const{code:_,data:l}=yield this._context.pullRTCRoomStatus(this._roomId,i);if(_!==t.ErrorCode.SUCCESS)return null===(d=this._context.logger)||void 0===d||d.info(o.L_PULL_ROOM_STATUS_R,JSON.stringify({status:n.FAILED,code:_}),this._traceId),{code:_};const{bFullStatus:u,version:h,usersData:R,roomStatus:v}=l;if(null===(c=this._context.logger)||void 0===c||c.info(o.L_PULL_ROOM_STATUS_R,JSON.stringify({bFullStatus:u,version:Tt(h),usersData:R,roomStatus:v}),this._traceId),e.setRoomStatusVersion(h),u){const{urisData:t,CDNUris:i}=function(e){const t={users:{}};let i="";return e.forEach((e=>{var r,o;const{userId:n,userData:s}=e;t.users[n]={};const a=null===(r=s.filter((e=>"uris"===e.key))[0])||void 0===r?void 0:r.value,d=null===(o=s.filter((e=>"cdn_uris"===e.key))[0])||void 0===o?void 0:o.value;i=d||i,t.users[n]={uris:a}})),{urisData:t,CDNUris:i&&JSON.stringify(JSON.parse(i)[0])}}(R);return yield is(t,e,this._callbacks,r,this._subhook,i,this._traceId),{code:_}}for(let t=0;t<v.length;t++){const i=v[t];if(i.event===gs.RESOURCECHANGE){const t=ns(i);if(!t)continue;const{content:o,userId:n}=t;if(n===e.crtUserId)continue;yield new ds(o,It.TOTAL_CONTENT_RESOURCE,n,this._subhook.bind(this),this._callbacks,this._traceId).execute(e,r)}else{const t=os(i),o=yield new as(t,this._subhook.bind(this),this._traceId).execute(e,r);this._dealUserAppListener(o)}}return{code:_}}))}}const Ts="evt-leave";class Is extends t.EventEmitter{constructor(e,t,r,n,s,a,d,c,_,l=Oo(),u=3e4){super(),this._context=e,this._runtime=t,this._roomId=r,this._service=s,this._initOptions=a,this._useMutilPeerC=_,this._clientSessionId=l,this.signalRetryTime=u,this._appListener=null,this._reportListener=null,this._onRecvPKMsg=null,this._polarisReport=new wn(this._context,this._runtime,this._roomId,this),this._peerCManager=new Vn(this._useMutilPeerC,this._roomId,this._reTryExchange.bind(this),this._context.getCurrentId(),this._polarisReport,!1,a),this._invoker=new jn(this._context,this._service,this._peerCManager,r,this._context.getCurrentId(),n,this._polarisReport,d,c),this._store=this._invoker.store,this._peerCManager.setStore(this._store),this._context.registerRTCSignalListener((e=>i(this,void 0,void 0,(function*(){var t,i,r,n,s,a;const{time:d,type:c,roomId:_}=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(o.L_RTCNTF_PULL_ROOM_STATUS_O,JSON.stringify({isDestroyed:!0,type:c,time:d,roomId:_}));else if(2===c){if(_!==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===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_RTCNTF_PULL_ROOM_STATUS_O,null,e),this._startPullRTCRoomStatus(_,e,d)}}))))}_pullRTCRoomStatus(e,t,i){return new ms(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,r){return i(this,void 0,void 0,(function*(){yield this._invoker.push(this._pullRTCRoomStatus(e,t,r))}))}__innerInit(t,r,o,n,s,a){return i(this,void 0,void 0,(function*(){const{code:i,data:d}=yield this._invoker.push(new Wn(this._roomId,t,this._context,r,o,n,s,a));return i!==e.RCRTCCode.SUCCESS?{code:i}:(this._initWithRoomData(d.offlineKickTime),{code:i,data:d})}))}_initWithRoomData(e){var t;const i=this._invoker.store;this._pinger=new St(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,s,a,d;if(this._useMutilPeerC)return void(null===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.error(o.L_ABSTRACT_ROOM_SETBITRATE_O,"`RCAbstractRoom.setBitrate` is disabled, use `RCLocalTrack.setBitrate` instead."));null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.warn(o.L_ABSTRACT_ROOM_SETBITRATE_O,"`RCAbstractRoom.setBitrate` will be deprecated, use `RCLocalTrack.setBitrate` instead."),t.assert("max",e,(e=>t.isNumber(e)&&e>Math.max(i||1,200)),!0),t.assert("min",i,(i=>t.isNumber(i)&&i>=1&&(!t.isNumber(e)||i<e)),!0),t.assert("start",r,(r=>t.isNumber(r)&&r>i&&r<=e));this._peerCManager.getPCList().forEach((t=>{t.setBitrate(e,i,r)}))}_onTrackReady(t){var i,r,s,a;const d=t.streams[0].id,{track:c}=t.receiver,_=[d,"audio"===c.kind?e.RCMediaType.AUDIO_ONLY:e.RCMediaType.VIDEO_ONLY].join("_"),l=this._store.getRemoteTrack(_);l?(l.__innerSetMediaStreamTrack(c),null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onTrackReady",trackId:l.getTrackId()})),this._callAppListener("onTrackReady",l)):null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(o.L_ABSTRACT_ROOM_ONTRACKREADY_O,`cannot found remote track ${c.id}`)}_callAppListener(e,...t){var i,r,n;const s=null===(i=this._appListener)||void 0===i?void 0:i[e];if(s)try{s(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(o.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(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onTrackUnpublish",trackIds:null==e?void 0:e.map((e=>e.getTrackId()))})),this._callAppListener("onTrackUnpublish",e)}__parseInnerMessage(e,t){var i,r,s,a,d,c,_,l,u,h;const{targetId:R,conversationType:v}=e;if(R!==this._roomId)return null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(o.L_ABSTRACT_ROOM_RECEIVE_MESSAGE_O,JSON.stringify({status:n.FAILED,message:`roomId is different, msg roomId-> ${R}, this._roomId-> ${this._roomId} `}),t),!0;null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_ABSTRACT_ROOM_RECEIVE_MESSAGE_O,`recv inner msg -> message: ${JSON.stringify(e)} | roomid: ${this._roomId}`,t);const{content:C}=e;switch(e.messageType){case It.KICK:this._kickoff(!0,C);break;case It.STATE:this._stateHandle(C,t);break;case It.MODIFY:case It.PUBLISH:case It.UNPUBLISH:case It.TOTAL_CONTENT_RESOURCE:((e,t,i,r,n)=>{var s;const a=Do.getMemo();if(!a.isReportRecvPubMsg){a.isReportRecvPubMsg=!0;const d=Date.now(),c={dur:d-r,puid:n,rid:e,csnid:(null===(s=a.clientData)||void 0===s?void 0:s.clientSessionId)||"",snid:t,time:d,cr:"unknown",net:"unknown",uid:i},_=JSON.stringify(c);Ne.__statistics(o.L_QS_RECV_PUB_MSG_S,_)}})(this._roomId,this.getSessionId(),this.getCrtUserId(),e.sentTime,e.senderUserId),this._resourceHandle(C,e.messageType,e.senderUserId,t);break;case It.ROOM_NOTIFY:null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onRoomAttributeChange",messageType:e.messageType,messageContent:e.content})),this._callAppListener("onRoomAttributeChange",e.messageType,e.content);break;case It.USER_NOTIFY:null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.warn(o.L_OLD_DAILY_RECORD_O,`TODO: ${It.USER_NOTIFY}`);break;case It.PK_INVITE:case It.PK_CANCEL_INVITE:case It.PK_INVITE_TIMEOUT:case It.PK_INVITE_ANSWER:case It.PK_END:this._onRecvPKMsg&&this._onRecvPKMsg(e);break;case It.OTHER_ROOM_OFFLINE:break;default:null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onMessageReceive",messageType:e.messageType,messageContent:e.content,senderUserId:e.senderUserId,messageUId:e.messageUId})),this._callAppListener("onMessageReceive",e.messageType,C,e.senderUserId,e.messageUId)}return!0}_kickoff(e,t){var r,s,a,d;return i(this,void 0,void 0,(function*(){if(this._invoker.isDestroyed())return;let i,c;null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s||s.warn(o.L_ABSTRACT_ROOM_ONKICKOFF_O,`onKickOff -> byServer: ${e}, kickContent: ${JSON.stringify(t)}`),this.emit(Ts),this._leaveHandle(!e),e&&(((null==t?void 0:t.users)||[]).forEach((e=>{e.userId===this._context.getCurrentId()&&(c=e.type,i=e.kickExtra)})),((e=1,t,i,r,n)=>{const s=Date.now(),a={cod:ko[String(e)],rid:t,csnid:i,snid:r,time:s,cr:"unknown",net:"unknown",uid:n},d=JSON.stringify(a);Ne.__statistics(o.L_QS_KICKED_S,d)})(c,this._roomId,this.getClientSessionId(),this.getSessionId(),this.getCrtUserId())),null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onKickOff",byServer:e,kickType:c,kickExtra:i})),this._callAppListener("onKickOff",e,c,i)}))}_rtcpeerClosed(){var e,t;this.emit(Ts),this._leaveHandle(!0),null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onRTCPeerConnectionCloseByException"})),this._callAppListener("onRTCPeerConnectionCloseByException")}_resourceHandle(e,t,r,o){return i(this,void 0,void 0,(function*(){const{uris:i,ignore:n}=e;!n&&i&&this._invoker.push(new ds(e,t,r,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")},o))}))}_onTrackPublish(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onTrackPublish",trackIds:null==e?void 0:e.map((e=>e.getTrackId()))})),this._callAppListener("onTrackPublish",e)}_stateHandle(e,t){return i(this,void 0,void 0,(function*(){const i=yield this._invoker.push(new as(e,this._subhook.bind(this),t));this._dealUserAppListener(i)}))}_dealUserAppListener(t){var i,r,s,a,d,c,_,l,u;const{left:h,joined:R,upgrade:v,downgrade:C}=t;if(null===(i=this._appListener)||void 0===i?void 0:i.onSwitchRole)return null==v||v.forEach((t=>{var i,r;null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onSwitchRole",userId:t,role:e.RCRTCLiveRole.ANCHOR})),this._callAppListener("onSwitchRole",t,e.RCRTCLiveRole.ANCHOR)})),null==C||C.forEach((t=>{var i,r;null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onSwitchRole",userId:t,role:e.RCRTCLiveRole.AUDIENCE})),this._callAppListener("onSwitchRole",t,e.RCRTCLiveRole.AUDIENCE)})),R.length>0&&(null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserJoin",joined:R})),this._callAppListener("onUserJoin",R)),void(h.length>0&&(null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserLeave",left:h})),this._callAppListener("onUserLeave",h)));const p=[...R,...v],g=[...h,...C];p.length>0&&(null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserJoin",allJoined:p})),this._callAppListener("onUserJoin",p)),g.length>0&&(g.length&&(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserLeave",allLeft:g}))),this._callAppListener("onUserLeave",g))}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(r,s){var a,d,c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d?void 0:d.createTraceId();null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_SEND_MESSAGE_T,JSON.stringify({name:r,content:s}),i);const{code:v}=yield this._context.sendMessage(t.ConversationType.RTC_ROOM,this._roomId,{messageType:r,content:s,isStatusMessage:!0});return v!==t.ErrorCode.SUCCESS?(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_ABSTRACT_ROOM_SEND_MESSAGE_R,JSON.stringify({status:n.FAILED,code:v}),i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_ABSTRACT_ROOM_SEND_MESSAGE_R,JSON.stringify({status:n.SUCCESSED,name:r,content:s}),i),{code:e.RCRTCCode.SUCCESS})}))}setRoomAttribute(r,s,a,d=!1){var c,_,l,u,h,R,v,C;return i(this,void 0,void 0,(function*(){const i=null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_?void 0:_.createTraceId();null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,key:r,value:s,message:a,isInner:d}),i);const p=yield this._context.setRTCData(this._roomId,r,s,d,mn.ROOM,a);return p!==t.ErrorCode.SUCCESS?(null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_R,JSON.stringify({status:n.FAILED,code:p}),i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.info(o.L_ABSTRACT_ROOM_SET_ROOM_ATTRIBUTE_R,JSON.stringify({status:n.SUCCESSED,roomId:this._roomId,key:r,value:s,message:a,isInner:d}),i),{code:e.RCRTCCode.SUCCESS})}))}deleteRoomAttributes(r,s,a=!1){var d,c,_,l,u,h,R,v;return i(this,void 0,void 0,(function*(){const i=null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c?void 0:c.createTraceId();null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,keys:r,message:s,isInner:a}),i);const C=yield this._context.removeRTCData(this._roomId,r,a,mn.ROOM,s);return C!==t.ErrorCode.SUCCESS?(null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:n.FAILED,code:C}),i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.info(o.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:n.SUCCESSED,roomId:this._roomId,keys:r,message:s,isInner:a}),i),{code:e.RCRTCCode.SUCCESS})}))}getRoomAttributes(r=[],s=!1){var a,d,c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d?void 0:d.createTraceId();null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_T,JSON.stringify({roomId:this._roomId,keys:r,isInner:s}),i);const{code:v,data:C}=yield this._context.getRTCData(this._roomId,r,s,mn.ROOM);return v!==t.ErrorCode.SUCCESS?(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_ABSTRACT_ROOM_GET_ROOM_ATTRIBUTE_R,`GetRoomAttributes Failed: ${v}`,i),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_ABSTRACT_ROOM_DELETE_ROOM_ATTRIBUTE_R,JSON.stringify({status:n.SUCCESSED,data:C}),i),{code:e.RCRTCCode.SUCCESS,data:C})}))}_setUserAttributeValue(e,t,i){return this._context.setRTCData(this._roomId,e,t,!1,mn.PERSON,i)}_deleteUserAttributes(e,t){return this._context.removeRTCData(this._roomId,e,!1,mn.PERSON,t)}_getUserAttributes(e){return this._context.getRTCData(this._roomId,e,!1,mn.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 i(this,void 0,void 0,(function*(){if(this._invoker.isDestroyed())return;Do.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(xe.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),e.off(xe.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this)})),this._peerCManager.clear(),this._peerCManager=null}_onLocalTrackDestroied(e){e instanceof Be&&e.__isTiny()||this.unpublish([e])}_onLocalTrackMuted(e,t){return i(this,void 0,void 0,(function*(){this._invoker.push(new us(e,t))}))}publish(e){return i(this,void 0,void 0,(function*(){return this._invoker.push(new _s(e,this._pubhook.bind(this),this.signalRetryTime))}))}_getPushOtherRoomsParams(){return[]}_reTryExchange(e,t){return i(this,void 0,void 0,(function*(){this._invoker.push(new hs(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 i(this,void 0,void 0,(function*(){return this._invoker.push(new ls(e,((e,t)=>({pushOtherRooms:this._getPushOtherRoomsParams(),headers:this._getRTCReqestHeaders(t)}))))}))}_getResourceById(e){return this._store.getPublishedResourceByTrackId(e)}_isValidResourceId(e){var t;const{userId:i}=rt(e);return!!(null===(t=this._store.getResourcesByUserId(i))||void 0===t?void 0:t.find((t=>it(t)===e)))}_subhook(e){const{pc:t,pcName:i}=this._peerCManager.createPeerCList(e)[0];return t.on(Mn.__INNER_EVENT_TRACK_READY__,this._onTrackReady,this),this._audioLevelReport&&t.on(Mn.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport),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(xe.__INNER_EVENT_MUTED_CHANGE__,this._onLocalTrackMuted,this),t.on(xe.__INNER_EVENT_DESTROY__,this._onLocalTrackDestroied,this),this._audioLevelReport&&t.on(Mn.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport),t.registerReportListener(this._reportListener),t.__reportR3R4ToPolaris(),Object.assign(Object.assign({},e),{headers:this._getRTCReqestHeaders(i)})})),pushOtherRooms:this._getPushOtherRoomsParams()}}subscribe(e){return i(this,void 0,void 0,(function*(){return this._invoker.push(new cs(e,this._subhook.bind(this)))}))}addSubscribeTask(e){var t;const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();this._invoker.push(new Cs(e,this._subhook.bind(this),{onTaskCompleted:this._onTaskCompleted.bind(this)},vn.NORMAL,i))}unsubscribe(e){var t,r;return i(this,void 0,void 0,(function*(){const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();return null===(r=this._context.logger)||void 0===r||r.info(o.L_APP_CALL_UNSUBSCRIBE_O,void 0,i),this._invoker.push(new zn(e,this._subhook.bind(this),i))}))}addUnsubscribeTask(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)},vn.NORMAL,i))}updateSubList(e){var t,r;return i(this,void 0,void 0,(function*(){return this._invoker.push(new Yn(e,this._subhook.bind(this),!0,null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId()))}))}addUpdateSubscribeListTask(e){var t;const i=null===(t=this._context.logger)||void 0===t?void 0:t.createTraceId();this._invoker.push(new vs(e,this._subhook.bind(this),{onTaskCompleted:this._onTaskCompleted.bind(this)},vn.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(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.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(o.L_ABSTRACT_ROOM_REGISTER_ROOM_EVENT_LISTENER_O,JSON.stringify({status:n.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(o.L_ABSTRACT_ROOM_REGISTER_REPORT_LISTENER_O,JSON.stringify({status:n.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(o.L_ABSTRACT_ROOM_AUDIO_LEVEL_O,JSON.stringify({status:n.SUCCESSED,handler:null==e?void 0:e.name,gap:t})),this._audioLevelReport=new Bn(this),this._audioLevelReport.onAudioLevelChange(e)}__onReconnected(e){return i(this,void 0,void 0,(function*(){return this._invoker.push(new Rs(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(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.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(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onVideoMuteChange",trackId:e.getTrackId()})),this._callAppListener("onVideoMuteChange",e)}_registerPKMsgListener(e){this._onRecvPKMsg=e}_quitAllPKRoom(){}getClientSessionId(){return this._clientSessionId}}class Es extends Fn{constructor(e,t){super(),this.data=e,this.cdnValues=t}get kind(){return Rn.MCUCONFIG_FLUSH}execute(t,r){var o,n,s,a;return i(this,void 0,void 0,(function*(){const i={"App-Key":t.context.getAppkey(),Token:t.getToken(),RoomId:t.roomId,UserId:t.context.getCurrentId(),SessionId:t.getSessionId()},{code:r,res:d}=yield t.service.setMcuConfig(i,this.data);if(r!==e.RCRTCCode.SUCCESS)return{code:r};d.pull_url&&t.setCDNUris(JSON.parse(d.pull_url));const c=this.cdnValues;return r===e.RCRTCCode.SUCCESS&&((null===(n=null===(o=c.output)||void 0===o?void 0:o.video.normal)||void 0===n?void 0:n.width)||(null===(a=null===(s=c.output)||void 0===s?void 0:s.video.normal)||void 0===a?void 0:a.fps))&&ts(t),{code:r,res:d}}))}}var Ss,fs,Os,Ls;e.BackgroundPictureFillMode=void 0,(Ss=e.BackgroundPictureFillMode||(e.BackgroundPictureFillMode={}))[Ss.CROP=1]="CROP",Ss[Ss.WHOLE=2]="WHOLE",e.MixLayoutMode=void 0,(fs=e.MixLayoutMode||(e.MixLayoutMode={}))[fs.CUSTOMIZE=1]="CUSTOMIZE",fs[fs.SUSPENSION=2]="SUSPENSION",fs[fs.ADAPTATION=3]="ADAPTATION",e.MixVideoRenderMode=void 0,(Os=e.MixVideoRenderMode||(e.MixVideoRenderMode={}))[Os.CROP=1]="CROP",Os[Os.WHOLE=2]="WHOLE",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"}(Ls||(Ls={}));const Ns=()=>({version:2,mode:e.MixLayoutMode.SUSPENSION});class As{constructor(e,t){this._invoker=e,this._isValidTrackId=t,this._values=Ns()}setHostVideoTrack(t){var i,r,s,a,d,c,_,l,u;if(!this._isValidTrackId(t))return null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,msg:`videoTrackId: ${t} is invalid`})),this;const{mediaType:h,tag:R,userId:v}=rt(t);return h!==e.RCMediaType.VIDEO_ONLY?(null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,msg:`kind of ${t} is not video`})),this):(this._values.host_stream_id=ot(v,R),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(o.L_MCU_CONFIG_BUILDER_SET_HOST_VIDEO_TRACK_O,JSON.stringify({status:n.SUCCESSED,videoTrackId:t})),this)}setMixLayoutMode(t){var i,r,s,a,d,c;return[e.MixLayoutMode.CUSTOMIZE,e.MixLayoutMode.SUSPENSION,e.MixLayoutMode.ADAPTATION].includes(t)?(this._values.mode=t,null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MCU_CONFIG_BUILDER_SET_MIX_LAYOUT_MODE_O,JSON.stringify({status:n.SUCCESSED,mode:t})),this):(null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_MIX_LAYOUT_MODE_O,JSON.stringify({status:n.SUCCESSED,msg:`mode: ${t} is invalid`})),this)}_addOutputValue(t,i,r="normal"){const o=this._values.output||(this._values.output={video:{normal:{width:640,height:480}}});if("cdn"===t)return void(o.cdn=i);if("audio"===t)return void(o.audio={bitrate:i});const{video:n}=o;if("normal"!==r&&"tiny"!==r)if("backgroundColor"!==r)if("exparams"!==r){if("backgroundPicture"===r){const t=n.backgroundPicture||(n.backgroundPicture={fillMode:e.BackgroundPictureFillMode.CROP,picture:[]});Object.assign(t,i)}}else n.exparams={renderMode:i};else n.backgroundColor=i;else{const e=n[r]||(n[r]={});Object.assign(e,i)}}setOutputVideoResolution(e){var t,i,r,s,a,d;if(!ct(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(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RESOLUTION_O,JSON.stringify({status:n.FAILED,msg:`params error -> resolution: ${e}`})),this;const{width:c,height:_}=dt(e);return this._addOutputValue("video",{width:c,height:_},"normal"),null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RESOLUTION_O,JSON.stringify({status:n.SUCCESSED,resolution:e})),this}setOutputVideoFPS(e){var t,i,r,s,a,d;if(!_t(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(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_FPS_O,JSON.stringify({status:n.FAILED,msg:`params error -> fps: ${e}`})),this;const c=lt(e);return this._addOutputValue("video",{fps:c},"normal"),null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_FPS_O,JSON.stringify({status:n.SUCCESSED,fps:e})),this}setOutputVideoBitrate(e){var i,r,s,a,d,c;return!t.isNumber(e)||e<=0?(null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_BITRATE_O,JSON.stringify({status:n.FAILED,msg:`params error -> bitrate: ${e}`})),this):(this._addOutputValue("video",{bitrate:e},"normal"),null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_BITRATE_O,JSON.stringify({status:n.SUCCESSED,bitrate:e})),this)}setOutputTinyVideoResolution(e){var t,i,r,s,a,d;if(!ct(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(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_RESOLUTION_O,JSON.stringify({status:n.FAILED,msg:`params error -> resolution: ${e}`})),this;const{width:c,height:_}=dt(e);return this._addOutputValue("video",{width:c,height:_},"tiny"),null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_RESOLUTION_O,JSON.stringify({status:n.SUCCESSED,resolution:e})),this}setOutputTinyVideoFPS(e){var t,i,r,s,a,d;if(!_t(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(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_FPS_O,JSON.stringify({status:n.FAILED,msg:`params error -> fps: ${e}`})),this;const c=lt(e);return this._addOutputValue("video",{fps:c},"tiny"),null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_FPS_O,JSON.stringify({status:n.SUCCESSED,fps:e})),this}setOutputTinyVideoBitrate(e){var i,r,s,a,d,c;return!t.isNumber(e)||e<=0?(null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_BITRATE_O,JSON.stringify({status:n.FAILED,msg:`params error -> bitrate: ${e}`})),this):(this._addOutputValue("video",{bitrate:e},"tiny"),null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_TINY_VIDEO_BITRATE_O,JSON.stringify({status:n.SUCCESSED,bitrate:e})),this)}setOutputVideoRenderMode(t){var i,r,s,a,d,c;return[e.MixVideoRenderMode.CROP,e.MixVideoRenderMode.WHOLE].includes(t)?(this._addOutputValue("video",t,"exparams"),null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RENDER_MODE_O,JSON.stringify({status:n.SUCCESSED,renderMode:t})),this):(null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_VIDEO_RENDER_MODE_O,JSON.stringify({status:n.FAILED,msg:`params error -> renderMode: ${t}`})),this)}setOutputAudioBitrate(e){var i,r,s,a,d,c;return t.isNumber(e)&&e>0?(this._addOutputValue("audio",e),null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_AUDIO_BITRATE_O,JSON.stringify({status:n.SUCCESSED,bitrate:e})),this):(null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_AUDIO_BITRATE_O,JSON.stringify({status:n.FAILED,msg:`params error -> bitrate: ${e}`})),this)}setOutputBackgroundColor(e){var t,i,r,s,a,d;return/^0x[a-fA-F0-9]{6}$/.test(e)?(this._addOutputValue("video",e,"backgroundColor"),null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_COLOR_O,JSON.stringify({status:n.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(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_COLOR_O,JSON.stringify({status:n.FAILED,msg:`params error -> color: ${e}`})),this)}addOutputBackgroundPicture(e,i,r,s,a){var d,c,_,l,u,h,R,v,C,p,g,m;if(!t.isHttpUrl(e))return null===(_=null===(c=null===(d=this._invoker.store)||void 0===d?void 0:d.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.FAILED,msg:`params error -> uri: ${e}`})),this;if([i,r,s,a].some((e=>!t.isNumber(e)||e<0||e>1)))return null===(h=null===(u=null===(l=this._invoker.store)||void 0===l?void 0:l.context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.FAILED,msg:`params of (x, y, w, h) error -> x: ${i}, y: ${r}, w: ${s}, h: ${a}`})),this;const T=(null===(C=null===(v=null===(R=this._values.output)||void 0===R?void 0:R.video)||void 0===v?void 0:v.backgroundPicture)||void 0===C?void 0:C.picture)||[];return T.push({uri:e,w:s,h:a,x:i,y:r}),this._addOutputValue("video",{picture:T},"backgroundPicture"),null===(m=null===(g=null===(p=this._invoker.store)||void 0===p?void 0:p.context)||void 0===g?void 0:g.logger)||void 0===m||m.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.SUCCESSED,uri:e,x:i,y:r,w:s,h:a})),this}removeOutputBackgroundPicture(e){var i,r,s,a,d,c,_,l,u;if(!t.isHttpUrl(e))return null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_REMOVE_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.FAILED,msg:`params error -> uri: ${e}`})),this;let h=null===(c=null===(d=null===(a=this._values.output)||void 0===a?void 0:a.video)||void 0===d?void 0:d.backgroundPicture)||void 0===c?void 0:c.picture;return h&&(h=h.filter((t=>t.uri!==e)),this._addOutputValue("video",{pictures:h},"backgroundPicture")),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(o.L_MCU_CONFIG_BUILDER_REMOVE_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.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(o.L_MCU_CONFIG_BUILDER_CLEAR_OUTPUT_BACKGROUND_PICTURE_O),this}setOutputBackgroundPictureFillMode(t){var i,r,s,a,d,c;return[e.BackgroundPictureFillMode.CROP,e.BackgroundPictureFillMode.WHOLE].includes(t)?(this._addOutputValue("video",{fillMode:t},"backgroundPicture"),null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:n.SUCCESSED,fillMode:t})),this):(null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:n.FAILED,msg:`params error -> fillMode: ${t}`})),this)}addPublishStreamUrls(e){var i,r,s,a,d,c,_,l,u,h,R;const v=/^rtmp:\/\/.+/;if(!t.isArray(e)||0===e.length||e.some((e=>!v.test(e))))return null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:n.FAILED,msg:`params error -> urls: ${e.join(",")}`})),this;const C=(null===(d=null===(a=this._values.output)||void 0===a?void 0:a.cdn)||void 0===d?void 0:d.concat())||[];let p=!1;return e.forEach((e=>{C.some((t=>t.pushurl===e))||(p=!0,C.push({pushurl:e}))})),C.length>5?(null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_FILL_MODE_O,JSON.stringify({status:n.FAILED,msg:`params error -> publish stream urls no more than 5, length: ${e.length}`})),this):(p&&this._addOutputValue("cdn",C),null===(R=null===(h=null===(u=this._invoker.store)||void 0===u?void 0:u.context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_MCU_CONFIG_BUILDER_ADD_PUBLISH_STREAM_URLS_O,JSON.stringify({status:n.SUCCESSED,urls:e})),this)}removePublishStreamUrls(e){var i,r,s,a,d,c,_,l;const u=/^rtmp:\/\/.+/;if(!t.isArray(e)||0===e.length||e.some((e=>!u.test(e))))return null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_REMOVE_PUBLISH_STREAM_URLS_O,JSON.stringify({status:n.FAILED,msg:`params error -> urls: ${e.join(",")}`})),this;const h=(null===(d=null===(a=this._values.output)||void 0===a?void 0:a.cdn)||void 0===d?void 0:d.concat())||[];for(let t=h.length-1;t>=0;t-=1){const{pushurl:i}=h[t],r=e.indexOf(i);r>=0&&(e.splice(r,1),h.splice(t,1))}return this._addOutputValue("cdn",h),null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_MCU_CONFIG_BUILDER_REMOVE_PUBLISH_STREAM_URLS_O,JSON.stringify({status:n.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(o.L_MCU_CONFIG_BUILDER_CLEAR_PUBLISH_STREAM_URLS_O),this}addCustomizeLayoutVideo(i,r,s,a,d){var c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f,O,L;if(!t.notEmptyString(i)||!this._isValidTrackId(i))return null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${i}`})),this;if(!t.isNumber(r)||!t.isNumber(s))return null===(R=null===(h=null===(u=this._invoker.store)||void 0===u?void 0:u.context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`params x or y is error -> x: ${r}, y: ${s}`})),this;if([a,d].some((e=>!t.isNumber(e)||e<0)))return null===(p=null===(C=null===(v=this._invoker.store)||void 0===v?void 0:v.context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`params width or height error -> width: ${a}, height: ${d}`})),this;const{userId:N,tag:A,mediaType:y}=rt(i);if(y!==e.RCMediaType.VIDEO_ONLY)return null===(T=null===(m=null===(g=this._invoker.store)||void 0===g?void 0:g.context)||void 0===m?void 0:m.logger)||void 0===T||T.error(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`type of trackId: ${i} 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===d&&e.width===a&&e.stream_id===k&&e.user_id===N&&e.x===r&&e.y===s))?(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(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:"Duplicate configuration item place ignored"})),this):(b.push({user_id:N,stream_id:k,x:r,y:s,width:a,height:d}),null===(L=null===(O=null===(f=this._invoker.store)||void 0===f?void 0:f.context)||void 0===O?void 0:O.logger)||void 0===L||L.info(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.SUCCESSED,trackId:i,x:r,y:s,width:a,height:d})),this)}removeCustomizeLayoutVideo(t){var i,r,s,a,d,c,_,l,u;if(!this._isValidTrackId(t))return null===(s=null===(r=null===(i=this._invoker.store)||void 0===i?void 0:i.context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${t}`})),this;const{userId:h,tag:R,mediaType:v}=rt(t);if(v!==e.RCMediaType.VIDEO_ONLY)return null===(c=null===(d=null===(a=this._invoker.store)||void 0===a?void 0:a.context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.FAILED,msg:`type of trackId: ${t} is not video`})),this;const C=ot(h,R),{input:p}=this._values;return(null==p?void 0:p.video)&&p.video.length>0&&(p.video=p.video.filter((e=>e.stream_id===C))),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(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_LAYOUT_VIDEO_O,JSON.stringify({status:n.SUCCESSED,trackId:t})),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(o.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_LAYOUT_VIDEO_O),this}setCustomizeInputAudio(e){var t,i,r,s,a,d;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(o.L_MCU_CONFIG_BUILDER_SET_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.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}=rt(e);return{stream_id:ot(t,i),user_id:t}})),this._values.inputFilterMode=Ls.AUDIO_INPUT_VIDEO_ALL,null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_MCU_CONFIG_BUILDER_SET_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.SUCCESSED,trackIds:e})),this}addCustomizeInputAudio(e){var t,i,r,s,a,d,c,_,l;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(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${e}`})),this;const u=this._values.input||(this._values.input={}),h=u.audio||(u.audio=[]),{userId:R,tag:v}=rt(e),C=ot(R,v);return h.some((e=>e.stream_id===C&&e.user_id===R))?(null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.warn(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.FAILED,msg:`trackId: ${e} is exist`})),this):(h.push({user_id:R,stream_id:C}),this._values.inputFilterMode=Ls.AUDIO_INPUT_VIDEO_ALL,null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_MCU_CONFIG_BUILDER_ADD_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.SUCCESSED,trackId:e})),this)}removeCustomizeInputAudio(e){var t,i,r,s,a,d,c,_,l;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(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${e}`})),this;const{input:u}=this._values;if(!(null==u?void 0:u.audio)||0===u.audio.length)return null===(d=null===(a=null===(s=this._invoker.store)||void 0===s?void 0:s.context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.FAILED,msg:`type of trackId: ${e} is not audio`})),this;const{userId:h,tag:R}=rt(e),v=ot(h,R);return u.audio=u.audio.filter((e=>h!==e.user_id||v!==e.stream_id)),null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_MCU_CONFIG_BUILDER_REMOVE_CUSTOMIZE_INPUT_AUDIO_O,JSON.stringify({status:n.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=Ls.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(o.L_MCU_CONFIG_BUILDER_CLEAR_CUSTOMIZE_INPUT_AUDIO_O),this}addPictureWaterMark(e,i,r,s,a,d){var c,_,l,u,h,R,v,C,p,g,m,T;if(!this._isValidTrackId(e))return null===(l=null===(_=null===(c=this._invoker.store)||void 0===c?void 0:c.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${e}`})),this;if(!t.isHttpUrl(i))return null===(R=null===(h=null===(u=this._invoker.store)||void 0===u?void 0:u.context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:n.FAILED,msg:`params error -> uri: ${i}`})),this;if([r,s,a,d].some((e=>!t.isNumber(e)||e<0||e>1)))return null===(p=null===(C=null===(v=this._invoker.store)||void 0===v?void 0:v.context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_MCU_CONFIG_BUILDER_ADD_SINGLE_WATER_MARK_O,JSON.stringify({status:n.FAILED,msg:`some attrs of (x, y, w, h) is invalid -> x: ${r}, y: ${s}, w: ${a}, h: ${d}`})),this;const{userId:I,tag:E}=rt(e),S=ot(I,E),f=this._values.waterMark||(this._values.waterMark={enable:"on",singleScreen:[]}),{singleScreen:O}=f,L=O.filter((e=>e.streamId===S))[0];return L?L.picture.push({uri:i,w:a,h:d,x:r,y:s}):O.push({streamId:S,picture:[{uri:i,w:a,h:d,x:r,y:s}]}),this._values.waterMark.singleScreen=O,null===(T=null===(m=null===(g=this._invoker.store)||void 0===g?void 0:g.context)||void 0===m?void 0:m.logger)||void 0===T||T.info(o.L_MCU_CONFIG_BUILDER_SET_OUTPUT_BACKGROUND_PICTURE_O,JSON.stringify({status:n.SUCCESSED,trackId:e,uri:i,x:r,y:s,w:a,h:d,singleScreen:O})),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(o.L_MCU_CONFIG_BUILDER_CLEAR_OUTPUT_BACKGROUND_PICTURE_O),this}removePictureWaterMark(e,i){var r,s,a,d,c,_;if(!t.notEmptyString(e)||!this._isValidTrackId(e))return null===(a=null===(s=null===(r=this._invoker.store)||void 0===r?void 0:r.context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_MCU_CONFIG_BUILDER_REMOVE_SINGLE_WATER_MARK_O,JSON.stringify({status:n.FAILED,msg:`params error -> trackId: ${e}`})),this;const{userId:l,tag:u}=rt(e),h=ot(l,u),R=this._values.waterMark||(this._values.waterMark={enable:"on",singleScreen:[]}),{singleScreen:v}=R;return v.forEach((e=>{e.streamId===h&&(e.picture=e.picture.filter((e=>e.uri!==i)))})),null===(_=null===(c=null===(d=this._invoker.store)||void 0===d?void 0:d.context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_MCU_CONFIG_BUILDER_REMOVE_SINGLE_WATER_MARK_O,JSON.stringify({status:n.SUCCESSED,trackId:e,uri:i})),this}reset(){var e,t,i;return this._values=Ns(),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(o.L_MCU_CONFIG_BUILDER_RESET_O),this}flush(e=!0){return i(this,void 0,void 0,(function*(){const t=JSON.parse(JSON.stringify(this._values)),{code:i}=yield this._invoker.push(new Es(t,this._values));return e&&(this._values=Ns()),{code:i}}))}__innerGetValues(){return JSON.parse(JSON.stringify(this._values))}}var ys,ks,Ds,bs;e.RCLivingType=void 0,(ys=e.RCLivingType||(e.RCLivingType={}))[ys.VIDEO=0]="VIDEO",ys[ys.AUDIO=1]="AUDIO",function(e){e[e.AUTOMATIC=0]="AUTOMATIC",e[e.MANUAL=1]="MANUAL"}(ks||(ks={}));class Us extends Fn{constructor(e,t,i,r){super(),this.roomId=e,this.hooks=t,this.roomPKHandler=i,this.traceId=r}_exchangeWithPushOtherRoom(t,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(!t.getLocalTracks().length)return void(null===(a=null===(s=t.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.SUCCESSED,msg:"have not published resource"}),this.traceId));const i=Object.values(t.peerMgr.getMutilPeerCData()),R=Object.keys(t.peerMgr.getMutilPeerCData());for(let s=0;s<i.length;s++){const{pc:a,isPub:v}=i[s],C=v&&t.useMutilPeerC?[]:t.getSubscribedList(),p=yield Qn(C,!1,a,t),{pushOtherRooms:g,headers:m}=this.hooks(R[s]);p.pushOtherRooms=g;const T=yield new qn(m,p,this.traceId,!0).execute(t,r);if(T.code!==e.RCRTCCode.SUCCESS)return void(null===(c=null===(d=t.context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.FAILED,code:T.code,pushOtherRooms:g}),this.traceId));const{sdp:I,resultCode:E}=T.data;if(E!==e.RCRTCCode.SUCCESS)return void(null===(l=null===(_=t.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.FAILED,code:E,pushOtherRooms:g}),this.traceId));null===(h=null===(u=t.context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.SUCCESSED,pushOtherRooms:g}),this.traceId),a.setRemoteAnswer(I.sdp)}}))}get kind(){return Rn.EXCHANGE_WITH_PUSH_OTHER_ROOM}execute(e,t){var r,s,a,d,c,_;return i(this,void 0,void 0,(function*(){const{roomId:i}=this;if(null===(s=null===(r=e.context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_EXCHANGE_WITH_PUSHOTHERROOM_T,JSON.stringify({roomId:i})),!this.roomPKHandler)return void(null===(d=null===(a=e.context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.FAILED,msg:"_roomPKHandler not exist"}),this.traceId));this.roomPKHandler.getPKInfo(i)?yield this._exchangeWithPushOtherRoom(e,t):null===(_=null===(c=e.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_EXCHANGE_WITH_PUSHOTHERROOM_R,JSON.stringify({status:n.FAILED,msg:"PKInfo not exist"}),this.traceId)}))}}class Ps extends Fn{constructor(e,t,i,r,o,n,s){super(),this.pkHandler=e,this.room=t,this._PKInfo=i,this.hooks=r,this._joinedPKRooms=o,this.isQuitPK=n,this.traceId=s}get kind(){return Rn.LEAVE_OTHER_ROOM}quitRoomPK(r,s,a){var d,c,_,l,u,h,R,v;return i(this,void 0,void 0,(function*(){if(null===(c=null===(d=null==s?void 0:s.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_QUIT_PK_T,`roomId: ${r}`,a),!this._PKInfo[r])return void(null===(l=null===(_=null==s?void 0:s.context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_QUIT_PK_R,`status: ${n.FAILED}, msg: pkinfo is empty`,a));const{inviterRoomId:i,inviteeRoomId:C,inviterUserId:p,inviteSessionId:g}=this._PKInfo[r],m={inviteeRoomId:C,inviterRoomId:i,userId:s.crtUserId},T={roomId:s.roomId,endRoomId:r,sessionId:g,content:JSON.stringify(m),keys:[`${i}|${p}`]},I=yield s.context.endRoomPK(T);return I!==t.ErrorCode.SUCCESS?(null===(h=null===(u=null==s?void 0:s.context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_QUIT_PK_R,`status: ${n.FAILED}, code: ${I}`,a),{code:e.RCRTCCode.SIGNAL_ERROR}):(null===(v=null===(R=null==s?void 0:s.context)||void 0===R?void 0:R.logger)||void 0===v||v.info(o.L_QUIT_PK_R,`status: ${n.SUCCESSED}`,a),delete this._PKInfo[r],{code:e.RCRTCCode.SUCCESS})}))}execute(t,r){var s,a,d,c;return i(this,void 0,void 0,(function*(){const{room:i,isQuitPK:_}=this,l=i.getRoomId();return null===(a=null===(s=t.context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_LIVING_ROOM_LEAVE_PK_ROOM_T,JSON.stringify({roomId:l,isQuitPK:_}),this.traceId),yield i.__destroy(!0),delete this._joinedPKRooms[l],yield new Us(l,this.hooks,this.pkHandler,this.traceId).execute(t,r),_&&this.quitRoomPK(l,t,this.traceId),null===(c=null===(d=t.context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_LIVING_ROOM_LEAVE_PK_ROOM_R,JSON.stringify({status:n.SUCCESSED}),this.traceId),{code:e.RCRTCCode.SUCCESS}}))}}class Ms{constructor(e,t,i,r,o,n,s,a,d,c,_){this._invoker=e,this._PKInfo=t,this._hooks=i,this._context=r,this._runtime=o,this._service=n,this._initOptions=s,this._mainLivingRoom=a,this._registerPKMsgListener=d,this._onJoinedPKRoom=c,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 s=null===(i=this._appListener)||void 0===i?void 0:i[e];if(s)try{s(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(o.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify(e))}}_onInvite(e){var t,i;const r=e.inviteInfo||{},{inviterRoomId:n,inviterUserId:s,extra:a}=r,d={inviterRoomId:n,inviterUserId:s,extra:a};this._PKInfo[n]=r,null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(o.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onRequestJoinOtherRoom",info:d})),this._callAppListener("onRequestJoinOtherRoom",d)}_onCancelInvite(e){var t,i;const{inviterRoomId:r,inviterUserId:n,extra:s}=e.inviteInfo||{},a={inviterRoomId:r,inviterUserId:n,extra:s};delete this._PKInfo[r],null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(o.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onCancelRequestOtherRoom",cancelInfo:a})),this._callAppListener("onCancelRequestOtherRoom",a)}_onInviteTimeout(e){}_onInviteAnswer(e){var t,i;const{answerCode:r,inviteContent:n}=e,{inviteSessionId:s,inviterUserId:a,inviterRoomId:d,inviteeUserId:c,inviterUserAutoMix:_,inviteeUserAutoMix:l,inviteeRoomId:u,extra:h}=n,R={agree:1===r,inviterRoomId:d,inviterUserId:a,inviteeRoomId:u,inviteeUserId:c,extra:h};this._PKInfo[u]=this._PKInfo[u]||{inviteSessionId:s,inviterRoomId:d,inviterUserId:a,inviterUserAutoMix:_,inviteeRoomId:u},this._PKInfo[u].inviteeUserAutoMix=l,null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(o.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onResponseJoinOtherRoom",answerInfo:R})),this._callAppListener("onResponseJoinOtherRoom",R)}createLeaveOtherRoomCommand(e,t,i){return new Ps(this,e,this._PKInfo,this._hooks,this._joinedPKRooms,t,i)}_onPKEnd(e){var t,r,n,s,a,d;return i(this,void 0,void 0,(function*(){const{inviteeRoomId:i,inviterRoomId:c,userId:_}=e.inviteInfo,l=c===this._mainRoomId?i:c,u={endRoomId:l,endUserId:_},h=this._joinedPKRooms[l],R=null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r?void 0:r.createTraceId();null===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.info(o.L_QUIT_PK_LEAVE_PK_ROOM_O,void 0,R),h&&(yield this._invoker.push(this.createLeaveOtherRoomCommand(h,!0,R))),delete this._PKInfo[l],null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_LIVING_PK_HANDLER_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onFinishOtherRoom",endInfo:u})),this._callAppListener("onFinishOtherRoom",u)}))}_onRecvPKMsg(e){const{targetId:t,content:i,messageType:r}=e;switch(r){case It.PK_INVITE:this._onInvite(i);break;case It.PK_CANCEL_INVITE:this._onCancelInvite(i);break;case It.PK_INVITE_TIMEOUT:this._onInviteTimeout(i);break;case It.PK_INVITE_ANSWER:this._onInviteAnswer(i);break;case It.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(o.L_LIVING_PK_HANDLER_REGISTER_ROOM_PK_EVENT_LISTENER_O,JSON.stringify({listener:e&&Object.keys(e)})),this._appListener=e}requestJoinOtherRoom(r,s,a){var d,c,_,l,u,h,R,v,C,p;return i(this,void 0,void 0,(function*(){const i=null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c?void 0:c.createTraceId();if(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_T,JSON.stringify({inviteeRoomId:r,inviteeUserId:s,options:a}),i),!t.validate("inviteeRoomId",r,t.notEmptyString,!0)||!t.validate("inviteeUserId",s,t.notEmptyString,!0))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> inviteeRoomId or inviteeUserId"}),i),{code:e.RCRTCCode.PARAMS_ERROR};const g=Oo(),m=!t.isBoolean(null==a?void 0:a.autoMix)||(null==a?void 0:a.autoMix),T={inviteSessionId:g,inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviterUserAutoMix:m,inviteeRoomId:r,inviteeUserId:s,inviteeTimeoutTime:this._inviteTimeout,extra:(null==a?void 0:a.extra)||""},I={roomId:this._mainRoomId,invitedRoomId:r,invitedUserId:s,inviteTimeout:this._inviteTimeout,inviteInfo:JSON.stringify(T),inviteSessionId:g},E=yield this._context.requestRoomPK(I);return E!==t.ErrorCode.SUCCESS?(null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:E}),i),{code:E}):(this._PKInfo[r]={inviteSessionId:g,inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviterUserAutoMix:m,inviteeRoomId:r},null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.info(o.L_LIVING_PK_HANDLER_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.SUCCESSED}),i),{code:e.RCRTCCode.SUCCESS})}))}cancelRequestJoinOtherRoom(r,s,a){var d,c,_,l,u,h,R,v,C,p,g,m;return i(this,void 0,void 0,(function*(){const i=null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c?void 0:c.createTraceId();if(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_T,JSON.stringify({inviteeRoomId:r,inviteeUserId:s,extra:a}),i),!t.validate("inviteeRoomId",r,t.notEmptyString,!0)||!t.validate("inviteeUserId",s,t.notEmptyString,!0))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> inviteeRoomId or inviteeUserId"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(!this._PKInfo[r])return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:`The request to connect with ${s} user in room ${r} is not initiated`}),i),{code:e.RCRTCCode.PARAMS_ERROR};const T={inviterRoomId:this._mainRoomId,inviterUserId:this._context.getCurrentId(),inviteeRoomId:r,inviteeUserId:s,extra:a||""},I={roomId:this._mainRoomId,invitedRoomId:r,invitedUserId:s,inviteSessionId:this._PKInfo[r].inviteSessionId,inviteInfo:JSON.stringify(T)},E=yield this._context.cancelRoomPK(I);return E!==t.ErrorCode.SUCCESS?(null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:E}),i),{code:E}):(null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.info(o.L_LIVING_PK_HANDLER_CANCEL_REQUEST_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.SUCCESSED}),i),delete this._PKInfo[r],{code:e.RCRTCCode.SUCCESS})}))}responseJoinOtherRoom(r,s,a,d){var c,_,l,u,h,R,v,C,p,g,m,T;return i(this,void 0,void 0,(function*(){const i=null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_?void 0:_.createTraceId();if(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_T,JSON.stringify({inviterRoomId:r,inviterUserId:s,agree:a,options:d}),i),!t.validate("inviterRoomId",r,t.notEmptyString,!0)||!t.validate("inviterUserId",s,t.notEmptyString,!0))return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> inviterRoomId or inviterUserId"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(!this._PKInfo[r])return null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.error(o.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:`User ${s} in room ${r} did not send a request for connection`}),i),{code:e.RCRTCCode.PARAMS_ERROR};const{inviteSessionId:I,inviterUserAutoMix:E}=this._PKInfo[r],S=!t.isBoolean(null==d?void 0:d.autoMix)||(null==d?void 0:d.autoMix),f={inviteSessionId:I,inviterRoomId:r,inviterUserId:s,inviterUserAutoMix:E,inviteeRoomId:this._mainRoomId,inviteeUserId:this._context.getCurrentId(),inviteeUserAutoMix:S},O=Object.assign(f,{inviterUserAutoMix:E}),L=a?Object.assign(f,{MultiRoomKey:`${r}|${this._mainRoomId}`,MultiRoomValue:JSON.stringify(O)}):f;!t.isUndefined(null==d?void 0:d.extra)&&Object.assign(L,{extra:d.extra});const N={agree:a,roomId:this._mainRoomId,inviteSessionId:I,inviteRoomId:r,inviteUserId:s,content:JSON.stringify(L),key:`${r}|${this._mainRoomId}`,value:JSON.stringify(f)},A=yield this._context.responseRoomPK(N);return A!==t.ErrorCode.SUCCESS?(null===(g=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===g||g.error(o.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:A}),i),{code:A}):(null===(T=null===(m=this._context)||void 0===m?void 0:m.logger)||void 0===T||T.info(o.L_LIVING_PK_HANDLER_RESPONSE_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.SUCCESSED}),i),this._PKInfo[r].inviteeUserAutoMix=S,{code:e.RCRTCCode.SUCCESS})}))}joinOtherRoom(r){var s,a,d,c,_,l,u,h,R,v,C,p,g,m;return i(this,void 0,void 0,(function*(){const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_T,JSON.stringify({roomId:r}),i),!t.validate("roomId",r,t.notEmptyString,!0))return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> roomId"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(this._context.getConnectionStatus()!==t.ConnectionStatus.CONNECTED)return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.SIGNAL_DISCONNECTED,msg:"IM disconnected"}),i),{code:e.RCRTCCode.SIGNAL_DISCONNECTED};if(this._joinedPKRooms[r])return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.warn(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const T=e.RCLivingType.VIDEO,I={extra:`{"roomId": "${this._mainRoomId}"}`},E=new Bs(this._context,this._runtime,r,this._service,this._initOptions,T,!1,!1,!1,this._clientSessionId),{code:S,data:f}=yield E.__innerInit(gn.LIVE,void 0,T,I);return S!==e.RCRTCCode.SUCCESS?(null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.FAILED,code:S}),i),{code:S}):(this._joinedPKRooms[r]=E,yield this._onJoinedPKRoom(r,i),null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.info(o.L_LIVING_PK_HANDLER_JOIN_OTHER_ROOM_R,JSON.stringify({status:n.SUCCESSED}),i),{room:E,code:e.RCRTCCode.SUCCESS,userIds:E.getRemoteUserIds(),tracks:E.getRemoteTracks()})}))}leaveOtherRoom(e,t){var r,n,s,a;return i(this,void 0,void 0,(function*(){const i=null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n?void 0:n.createTraceId();return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_APP_CALL_LEAVE_PK_ROOM_O,void 0,i),this._invoker.push(this.createLeaveOtherRoomCommand(e,t,i))}))}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"}(Ds||(Ds={}));class xs extends Fn{constructor(e,t){super(),this.cdnValues=e,this.enable=t}get kind(){return Rn.ENABLE_INNER_CDN}execute(r,s){var a,d,c,_,l,u,h,R,v,C,p,g,m,T;return i(this,void 0,void 0,(function*(){const{enable:i}=this;if(null===(d=null===(a=r.context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_LIVING_ROOM_ENABLE_INNER_CDN_T,JSON.stringify({roomId:r.roomId,enable:i})),!r.isMainRoom)return null===(_=null===(c=r.context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM};if(!t.isBoolean(i))return null===(u=null===(l=r.context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> enable"})),{code:e.RCRTCCode.PARAMS_ERROR};r.setCDNEnabel(i);const I={version:2,output:{inCDNModel:i?Ds.OPEN:Ds.STOP}},{code:E}=yield new Es(I,this.cdnValues).execute(r,s);if(E!==e.RCRTCCode.SUCCESS)return null===(R=null===(h=r.context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.FAILED,code:E,msg:"signal error"})),{code:e.RCRTCCode.SIGNAL_ERROR};const S=r.getCDNUris();if(S&&S.broadcast!==En.SPREAD)return null===(C=null===(v=r.context)||void 0===v?void 0:v.logger)||void 0===C||C.info(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.SUCCESSED,enable:i})),{code:e.RCRTCCode.SUCCESS};const{code:f}=yield ts(r);return f===e.RCRTCCode.SUCCESS?(null===(g=null===(p=r.context)||void 0===p?void 0:p.logger)||void 0===g||g.info(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.SUCCESSED,enable:i})),{code:e.RCRTCCode.SUCCESS}):(null===(T=null===(m=r.context)||void 0===m?void 0:m.logger)||void 0===T||T.error(o.L_LIVING_ROOM_ENABLE_INNER_CDN_R,JSON.stringify({status:n.FAILED,code:f})),{code:f})}))}}!function(e){e[e.AnchorToViewer=1]="AnchorToViewer",e[e.ViewerToAnchor=2]="ViewerToAnchor"}(bs||(bs={}));class ws extends Fn{constructor(e,t){super(),this.livingType=e,this.traceId=t}get kind(){return Rn.RTC_IDENTITY_CHANGE}execute(e,r){var o;return i(this,void 0,void 0,(function*(){const{code:i,data:n}=yield e.context.rtcIdentityChange(e.roomId,bs.ViewerToAnchor,this.livingType);if(i!==t.ErrorCode.SUCCESS||!n)return{code:i};e.initWithRoomData(n,this.traceId);e.getResourcesByUserId(e.crtUserId).length>0&&r.push(new $n);const s=null===(o=n.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===o?void 0:o.value;return s&&e.setCDNUris(JSON.parse(s)[0]),{code:i,data:n}}))}}class Bs extends Is{constructor(e,t,i,r,o,n,s,a,d,c){super(e,t,i,gn.LIVE,r,o,s,a,d,c),this._livingType=n,this._mcuConfigBuilder=new As(this._invoker,this._isValidResourceId.bind(this))}_initAfterCatchRoomData(e,t){if(this._store.isUpgrade&&this._afterChangedRole(e,t),this._store.isMainRoom){const t=((e,t)=>{const i={};return t.forEach((t=>{const r=JSON.parse(t.value),{inviterRoomId:o,inviteeRoomId:n}=r;i[e===o?n:o]=JSON.parse(t.value)})),i})(this._roomId,e.roomInfo);this._roomPKHandler=new Ms(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(r,s,a,d,c,_){const l=Object.create(null,{__innerInit:{get:()=>super.__innerInit}});var u,h;return i(this,void 0,void 0,(function*(){if(!t.validate("livingType",a,(t=>t===e.RCLivingType.AUDIO||t===e.RCLivingType.VIDEO)))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> livingType"}),_),{code:e.RCRTCCode.PARAMS_ERROR};const{code:i,data:R}=yield l.__innerInit.call(this,r,s,a,d,c,_);return i===e.RCRTCCode.SUCCESS&&R&&this._initAfterCatchRoomData(R),{code:i,data:R}}))}__innerInitByIdentityChange(e){var r,s,a,d;return i(this,void 0,void 0,(function*(){const{code:i,data:c}=yield this._invoker.push(new ws(this._livingType,e));return i===t.ErrorCode.SUCCESS&&c?(this._initAfterCatchRoomData(c,e),this._initWithRoomData(c.offlineKickTime),null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:n.SUCCESSED,roomData:c}),e)):null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:n.FAILED,code:i}),e),i}))}publish(t){const r=Object.create(null,{publish:{get:()=>super.publish}});var s,a;return i(this,void 0,void 0,(function*(){return this._store.isMainRoom?r.publish.call(this,t):(null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_ABSTRACT_ROOM_PUBLISH_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}))}unpublish(t){const r=Object.create(null,{unpublish:{get:()=>super.unpublish}});var s,a;return i(this,void 0,void 0,(function*(){return this._store.isMainRoom?r.unpublish.call(this,t):(null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_ABSTRACT_ROOM_UNPUBLISH_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}))}_isValidResourceId(t){var i;const{userId:r}=rt(t),o=!!(null===(i=this._store.getResourcesByUserId(r))||void 0===i?void 0:i.find((e=>it(e)===t)));let n=!1;const{code:s,roomPKHandler:a}=this.getRoomPKHandler();if(s!==e.RCRTCCode.SUCCESS||!a)return o;const d=a.getJoinedPKRooms(),c=[];return Object.values(d).forEach((e=>{c.push(...e.getRemoteTracks())})),n=c.some((e=>t===e.getTrackId())),o||n}getLivingType(){return this._livingType}getMCUConfigBuilder(){var t,i;return this._store.isMainRoom?this._mcuConfigBuilder:(null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.error(o.L_LIVING_ROOM_GET_MCU_CONFIG_BUILDER_O,"the `getMCUConfigBuilder` is disabled in PK room"),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}enableInnerCDN(e){return i(this,void 0,void 0,(function*(){return this._invoker.push(new xs(this._mcuConfigBuilder.__innerGetValues(),e))}))}_resourceHandle(e,t,r,o){const n=Object.create(null,{_resourceHandle:{get:()=>super._resourceHandle}});return i(this,void 0,void 0,(function*(){n._resourceHandle.call(this,e,t,r,o)}))}_afterChangedRole(e,t){const i=pt(e,this._roomId,t),r=this._context.getCurrentId(),s=Object.keys(i);setTimeout((()=>{var a,d,c,_,l;const u=s.filter((e=>e!==r));u.length>0&&(null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserJoin",needNoticeUserIds:u})),this._callAppListener("onUserJoin",u));for(const e in i)e!==r&&this._resourceHandle({uris:i[e]},It.TOTAL_CONTENT_RESOURCE,e,t);if(!(null===(c=e.roomInfo.filter((e=>"cdn_uris"===e.key))[0])||void 0===c?void 0:c.value))return;const h=this._store.getCDNUris();(null==h?void 0:h.push_mode)===ks.MANUAL&&(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_ABSTRACT_ROOM_CALL_APP_LISTENER_O,JSON.stringify({status:n.SUCCESSED,eventType:"onUserJoin",enableInnerCDN:null==h?void 0:h.enableInnerCDN})),this._callAppListener("onCDNEnableChange",null==h?void 0:h.enableInnerCDN))}))}__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 i(this,void 0,void 0,(function*(){this._invoker.push(new Us(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(),o=this._roomPKHandler.getPKInfo(i);if(!o)continue;const{inviterUserAutoMix:n,inviteeUserAutoMix:s,inviterUserId:a}=o,d=this._context.getCurrentId()===a;e.push({roomId:i,sessionId:r,autoMix:d?!!n:!!s})}return e}getRoomPKHandler(){var t,i,r,s;return this._store.isMainRoom?(null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s||s.info(o.L_LIVING_ROOM_GET_ROOM_PK_HANDLER_O,JSON.stringify({status:n.SUCCESSED})),{code:e.RCRTCCode.SUCCESS,roomPKHandler:this._roomPKHandler}):(null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.error(o.L_LIVING_ROOM_GET_ROOM_PK_HANDLER_O,JSON.stringify({status:n.SUCCESSED,code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"method not available in PK room"})),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM})}_quitAllPKRoom(){var e,t;return i(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(o.L_LIVING_ROOM_QUIT_ALL_PK_ROOM_O,JSON.stringify({status:n.SUCCESSED,roomIds:Object.keys(i)}))}))}isMainRoom(){return this._store.isMainRoom}}class Vs extends Is{constructor(e,t,i,r,o,n,s,a,d,c=gn.RTC,_=3e4){super(e,t,i,c,r,o,n,s,a,d,_)}}const Fs=new class{constructor(){this.queue=[],this.locked=!1,this.taskCount=0}checkToStart(){return i(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}},Js=(e,t="")=>Fs.push(e,t);class Hs{constructor(e,t,i,r){this._context=e,this._useMutilPeerC=r,this._rtcToken="",this._liveUrl="",this._subTracks=[],this._subscribedList=[],this._clientSessionId=Oo(),this._livingType=null,this._mediaType=null,this._subTiny=!1,this._fromRetry=!1,this._appListener=null,this._crtUserId=this._context.getCurrentId(),this._service=new zo(t,e,i.mediaServer),this._peerCManager=new Vn(this._useMutilPeerC,this._crtUserId,this._reTryExchange.bind(this),this._crtUserId,void 0,!1,i,!0),this._store=new Gn(this._context,this._service,this._peerCManager,this._crtUserId,this._crtUserId),this._peerCManager.setStore(this._store)}_getReqHeaders(r){return i(this,void 0,void 0,(function*(){const i=this._crtUserId;if(!this._rtcToken){const{code:o,data:n}=yield this._context.getRTCToken(i,gn.LIVE,r);if(o!==t.ErrorCode.SUCCESS)return{code:e.RCRTCCode.SIGNAL_ERROR};this._rtcToken=n.rtcToken}const o=this._useMutilPeerC?{"Peer-Connection-Id":this._pcName}:{};return{code:e.RCRTCCode.SUCCESS,headers:Object.assign({"App-Key":this._context.getAppkey(),UserId:this._crtUserId,RoomId:i,RoomType:gn.LIVE,Token:this._rtcToken,"Client-Session-Id":this._clientSessionId},o)}}))}_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 t;return i(this,void 0,void 0,(function*(){this._fromRetry=!0;const{code:i}=yield this.subscribe(this._liveUrl,this._livingType,this._mediaType,this._subTiny);i===e.RCRTCCode.SUCCESS&&(null===(t=this._pc)||void 0===t||t.clearReTryExchangeTimer())}))}subscribe(e,t,r,o=!1){return i(this,void 0,void 0,(function*(){return Js((()=>this.__subscribe(e,t,r,o)),"audience-client-sub")}))}__subscribe(r,s,a,d=!1){var c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f,O,L,N,A,y,k,D;return i(this,void 0,void 0,(function*(){null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_AUDIENCE_CLIENT_SUBSCRIBE_T,JSON.stringify({liveUrl:r,livingType:s,mediaType:a,subTiny:d}));const i=[];if(Ct(this._context.getNaviInfo()))return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"})),{code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR,tracks:i};if(!this._fromRetry&&(null===(h=this._pc)||void 0===h||h.clearReTryExchangeTimer()),this._fromRetry=!1,!t.isString(r))return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:`params error -> liveUrl: ${r}`})),{code:e.RCRTCCode.PARAMS_ERROR,tracks:i};if(![e.RCLivingType.AUDIO,e.RCLivingType.VIDEO].includes(s))return null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(`livingType is invalid: ${s}`),null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:`params error -> livingType: ${s}`})),{code:e.RCRTCCode.PARAMS_ERROR,tracks:i};if(![e.RCMediaType.AUDIO_ONLY,e.RCMediaType.VIDEO_ONLY,e.RCMediaType.AUDIO_VIDEO].includes(a))return null===(I=null===(T=this._context)||void 0===T?void 0:T.logger)||void 0===I||I.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:`params error -> -> mediaType: ${a}`})),{code:e.RCRTCCode.PARAMS_ERROR,tracks:i};if(this._liveUrl&&this._liveUrl!==r)return null===(S=null===(E=this._context)||void 0===E?void 0:E.logger)||void 0===S||S.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.BROADCAST_SUB_LIST_NOT_EMPTY,msg:"repeat subscribe"})),{code:e.RCRTCCode.BROADCAST_SUB_LIST_NOT_EMPTY,tracks:i};if(!this._pc){const{pcName:e,pc:t}=this._peerCManager.createPeerCList(i)[0];this._pc=t,this._pcName=e,this._pc.on(Mn.__INNER_EVENT_TRACK_READY__,this._onTrackReady,this),this._pc.registerReportListener(this._reportListener),this._pc.__reportR3R4ToPolaris()}this._liveUrl=r;const{code:b,headers:U}=yield this._getReqHeaders(s);if(b!==e.RCRTCCode.SUCCESS)return null===(O=null===(f=this._context)||void 0===f?void 0:f.logger)||void 0===O||O.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:b,msg:"getRTCToken failed"})),{code:b,tracks:i};const P=`rc_mcu_${Date.now()}`,M="RongCloudRTC";0===this._subTracks.length&&(this._subTracks.push(new We(M,P),new qe(M,P)),this._pc.updateSubRemoteTracks(this._subTracks.slice()));const x={sdp:yield this._pc.createOffer(!0),liveUrl:r,mediaType:a,simulcast:d?Zo.TINY:Zo.NORMAL,switchstream:!1},w=yield this._service.broadcastSubscribe(U,x);if(w.code!==e.RCRTCCode.SUCCESS)return null===(N=null===(L=this._context)||void 0===L?void 0:L.logger)||void 0===N||N.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:w.code})),{code:w.code,tracks:i};const B=w.data;if(B.resultCode!==e.RCRTCCode.SUCCESS)return null===(y=null===(A=this._context)||void 0===A?void 0:A.logger)||void 0===y||y.error(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:B.resultCode,msg:B.message})),{code:B.resultCode,tracks:i};this._livingType=s,this._mediaType=a,this._subTiny=d;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(o.L_AUDIENCE_CLIENT_SUBSCRIBE_R,JSON.stringify({status:n.SUCCESSED,liveUrl:r})),{code:e.RCRTCCode.SUCCESS,tracks:J}}))}_updateTrackIdSSRCMap(e,t){t.forEach((t=>{const i=t.getTrackId(),{mediaType:r}=rt(i),{msid:o}=this._subscribedList.filter((e=>e.mediaType===r))[0],n=ss(e,o,r);this._store.setTrackIdSSRCMap(Number(n),i)}))}unsubscribe(){return i(this,void 0,void 0,(function*(){return Js((()=>this.__unsubscribe()),"audience-client-unsub")}))}__unsubscribe(){var t,r,s,a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){if(null===(r=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===r||r.info(o.L_AUDIENCE_CLIENT_UNSUBSCRIBE_T,JSON.stringify({liveUrl:this._liveUrl})),null===(s=this._pc)||void 0===s||s.clearReTryExchangeTimer(),!this._rtcToken||!this._liveUrl)return null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.warn(o.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:"",msg:"Address does not exist, without unsubscribe"})),{code:e.RCRTCCode.SUCCESS};const{headers:i}=yield this._getReqHeaders(),{code:h}=yield this._service.broadcastExit(i);return h!==e.RCRTCCode.SUCCESS?null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:h})):(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_AUDIENCE_CLIENT_UNSUBSCRIBE_R,JSON.stringify({status:n.SUCCESSED,liveUrl:this._liveUrl})),this._subscribedList=[]),this._clearSubscribeInfo(),{code:h}}))}registerReportListener(e){this._reportListener=e}registerTrackEventListener(e){this._appListener=e}_onTrackReady(t){var i,r,n,s,a,d;const{track:c}=t.receiver,_="audio"===c.kind?e.RCMediaType.AUDIO_ONLY:e.RCMediaType.VIDEO_ONLY,l=this._subTracks[_];l.__innerSetMediaStreamTrack(c);try{null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(o.L_AUDIENCE_CLIENT_CALL_ONTRACKREADY_O,`trackId: ${l.getTrackId()}`),null===(s=null===(n=this._appListener)||void 0===n?void 0:n.onTrackReady)||void 0===s||s.call(n,l)}catch(e){null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_AUDIENCE_CLIENT_CALL_ONTRACKREADY_O,JSON.stringify(e))}}}var Gs,Ks;e.RCInnerCDNPullKind=void 0,(Gs=e.RCInnerCDNPullKind||(e.RCInnerCDNPullKind={})).RTMP="rtmp",Gs.FLV="flv",Gs.HLS="hls",e.RCInnerCDNPullIsHttps=void 0,(Ks=e.RCInnerCDNPullIsHttps||(e.RCInnerCDNPullIsHttps={}))[Ks.NOT_HTTPS=0]="NOT_HTTPS",Ks[Ks.HTTPS=1]="HTTPS";const js=Object.assign(Object.assign({},dt(e.RCResolution.W176_H144)),{frameRate:lt(e.RCFrameRate.FPS_15)});class $s{constructor(e,t,r,o,n,s,a,d=Oo()){this._context=e,this._runtime=t,this._initOptions=r,this._roomId=o,this._joinResData=n,this.livingType=s,this._useMutilPeerC=a,this._clientSessionId=d,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._reportListener=null,this._crtUserId=this._context.getCurrentId(),this._service=new zo(this._runtime,this._context,this._initOptions.mediaServer,this._initOptions.timeout),this._polarisReport=new wn(this._context,this._runtime,this._roomId,this,_n.Audience),this._polarisReport.sendR1(),this._peerCManager=new Vn(this._useMutilPeerC,this._roomId,this._reTryExchange.bind(this),this._crtUserId,this._polarisReport,!0,this._initOptions,!0),this._context.registerRTCSignalListener((e=>i(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 Gn(this._context,this._service,this._peerCManager,this._roomId,this._crtUserId,gn.LIVE,this._polarisReport),this._peerCManager.setStore(this._store),this._setInitData()}_startPull(e,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(this._isPulling)return;this._isPulling=!0;if(this._pullTime>r)return void(this._isPulling=!1);const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_T,`pullTime: ${this._pullTime}`,i);const{code:R,data:v}=yield this._context.pullRTCRoomEntry(e);if(R===t.ErrorCode.SUCCESS){this._isPulling=!1,this._pullTime=v.syncTime||0;const t=(null==v?void 0:v.kvEntries)||[];null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R,`status: ${n.SUCCESSED}, kvEntries: ${JSON.stringify(t)}`,i),this.singalDataChange(t,e,i)}null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_AUDIENCE_LIVING_ROOM_PULL_KVENTRIES_R,`status: ${n.FAILED}, code: ${R}`,i)}))}_setInitData(){const{sessionId:e,remoteUserIds:t,remoteRTCUris:i,remoteMUCUris:r,remoteTracks:o,CDNUris:n}=gt(this._roomId,this._joinResData.kvEntries);this._sessionId=e,this._roomAnchorList=t,o.forEach((e=>{this._remoteTracks[e.getTrackId()]=e})),this._CDNUris=n,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:o}=JSON.parse(e.uri);this._store.setTrackIdSSRCMap(o,r)})),i.forEach((e=>{const t=it(e);this._roomRes[t]=e}))}_assertRoomDestroyed(){if(this._destroyed)return e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED}singalDataChange(e,t,i){var r,s,a;if(t!==this._roomId)return void(null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s||s.error(o.L_AUDIENCE_LIVING_ROOM_SINGAL_DATA_CHANGE_P,JSON.stringify({status:n.FAILED,msg:`roomId inconsistency -> params roomId:${t}, current roomId:${this._roomId}`}),i));const d=[],c=null===(a=e.filter((e=>"RC_CDN"===e.key))[0])||void 0===a?void 0:a.value;c&&this._diffCDNUris(JSON.parse(JSON.parse(c).cdn_uris)[0],i),e.forEach((e=>{const{key:t,value:r,timestamp:o,uid:n}=e;if(-1!==t.indexOf("RC_RES_")){const e=JSON.parse(r||"{}"),t=JSON.parse(e.mcu_uris||"[]"),o=JSON.parse(e.uris||"[]");return d.push(...t),void this._diffAnchorResource(o,n,i)}if("RC_ANCHOR_LIST"===t){const e=JSON.parse(r||"[]"),{joinUserIds:t,leftUserIds:o}=this._diffAnchorList(e);t.length>0&&this._handleNewJoinedAnchor(t,i),o.length>0&&this._handleLeftedAnchor(o,i)}})),this._diffRoomResource(d,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(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorJoin",list:e}),t),this._callAppListener("onAnchorJoin",e)}_handleLeftedAnchor(e,t){var r,n;return i(this,void 0,void 0,(function*(){this._roomAnchorList=this._roomAnchorList.filter((t=>!(e.indexOf(t)>-1)));const i=[];e.forEach((e=>{i.push(...this.getRemoteTracksByUserId(e)),delete this._roomAnchorRes[e]})),i.length&&(yield this.unsubscribe(i),i.forEach((e=>delete this._remoteTracks[e.getTrackId()]))),null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorLeave",list:e}),t),this._callAppListener("onAnchorLeave",e)}))}_diffRoomResource(t,r){var n,s;return i(this,void 0,void 0,(function*(){const i=[],a=[],d=[];t.forEach((t=>{const r=it(t),{userId:o,tag:n,mediaType:s}=rt(r),a=[this._roomId,n,s].join("_"),{ssrc:c}=JSON.parse(t.uri);if(this._store.setTrackIdSSRCMap(c,a),!this._remoteTracks[a]){const r=s===e.RCMediaType.AUDIO_ONLY?new We(n,"",this._roomId):new qe(n,"",this._roomId);i.push(r),this._remoteTracks[a]=r,this._roomRes[r.getTrackId()]=t}d.push(a)})),Object.keys(this._remoteTracks).forEach((e=>{d.indexOf(e)<0&&this._remoteTracks[e].isMCUTrack()&&a.push(this._remoteTracks[e])})),i.length>0&&(null===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onTrackPublish",trackIds:i.map((e=>e.getTrackId()))}),r),this._callAppListener("onTrackPublish",i)),a.length>0&&this._onUserUnpublish(a,"onTrackUnpublish",r)}))}_diffAnchorResource(t,r,s){var a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){const i=this._roomAnchorRes[r]||(this._roomAnchorRes[r]=[]),{publishedList:h,unpublishedList:R,modifiedList:v}=st(i,t);if(h.length){const t=i.map(it),r=[],l=[];if(h.forEach((o=>{const n=it(o),s=t.indexOf(n),{userId:a,tag:d,mediaType:c}=rt(n);s>-1?i[s]=o:i.push(o);let _=this._remoteTracks[n];this._roomRes[n]=o,_?_.isSubscribed()&&r.push(_):(_=c===e.RCMediaType.AUDIO_ONLY?new We(d,a):new qe(d,a),this._remoteTracks[n]=_,l.push(_)),_.__innerSetRemoteMuted(0===o.state)})),r.length){const t=r.map((e=>e.getTrackId())),{code:i}=yield Js((()=>this._subscribeHandle(r,!0)));i!==e.RCRTCCode.SUCCESS&&(null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_RESUB_REPUB_RES_R,JSON.stringify({status:n.FAILED,trackIds:t,code:i})))}null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onAnchorTrackPublish",trackIds:l.map((e=>e.getTrackId()))}),s),this._callAppListener("onAnchorTrackPublish",l)}if(R.length){const e=R.map(it);for(let t=i.length-1;t>=0;t-=1){const r=i[t];e.includes(it(r))&&i.splice(t,1)}const t=R.map((e=>{const t=it(e);return this._remoteTracks[t]}));yield this._onUserUnpublish(t,"onAnchorTrackUnpublish",s)}if(v.length){const e=i.map(it);for(let t=0;t<v.length;t++){const r=v[t],n=it(r),a=e.indexOf(n);i[a].state=r.state;const d=this._remoteTracks[n];d.__innerSetRemoteMuted(0===r.state);const c=d.isAudioTrack()?"onAudioMuteChange":"onVideoMuteChange";null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:c,trackId:d.getTrackId()}),s),this._callAppListener(c,d)}}}))}_onUserUnpublish(e,t,r){var n,s;return i(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===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:t,trackIds:e.map((e=>e.getTrackId()))}),r),this._callAppListener(t,e)}))}_callAppListener(e,...t){var i,r,n;const s=null===(i=this._appListener)||void 0===i?void 0:i[e];if(s)try{s(...t)}catch(e){null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.error(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify(e))}}_reTryExchange(){return i(this,void 0,void 0,(function*(){Js((()=>i(this,void 0,void 0,(function*(){var t;const{reqBody:i}=yield this._createSubscribeParams(this._subscribedList,{},!0),r=yield this._exchangeHandle(i);if(r.code!==e.RCRTCCode.SUCCESS)return{code:r.code};const{sdp:o,resultCode:n}=r.data;if(n!==e.RCRTCCode.SUCCESS)return{code:n};this._pc.clearReTryExchangeTimer();const s=this._subscribedList.filter((e=>e.track.isMCUTrack()));if(s.length>0){const e=s[0].track.getTrackId(),i=null===(t=this._roomRes[e])||void 0===t?void 0:t.msid,r=[this._roomId,"RongCloudRTC"].join("_");o.sdp=o.sdp.replace(new RegExp(i,"g"),r)}const a=yield this._pc.setRemoteAnswer(o.sdp);return a!==e.RCRTCCode.SUCCESS?{code:a}:void 0}))),"audience-retry-exchange")}))}_createSubscribeParams(e,t,r){return i(this,void 0,void 0,(function*(){const i=yield this._pc.createOffer(r),o={resolutionInfo:[]},n={min:0,max:0};Object.keys(t).forEach((e=>{const{mediaStream:r,tinyStream:s}=t[e];[r,s].forEach(((t,r)=>{var s;const a=1===r?[e,"tiny"].join("_"):e;i.sdp=null===(s=i.sdp)||void 0===s?void 0:s.replace(new RegExp(t.id,"g"),a);const d=t.getVideoTracks()[0];if(!d)return;const c=0===r,{width:_,height:l,frameRate:u}=c?et(d):js;o.resolutionInfo.push({trackId:d.id,simulcast:c?Zo.NORMAL:Zo.TINY,resolution:`${_}x${l}`});const h=Se(_,l),R=Oe(u);n.min+=h.minBitrate*R,n.max+=h.maxBitrate*R}))}));return{reqBody:{sdp:i,switchstream:!1,newVersionFlag:!0,subscribeList:e.map((e=>({simulcast:e.subTiny?Zo.TINY:Zo.NORMAL,resolution:"",uri:this._roomRes[e.track.getTrackId()].uri})))},dynamicBitrate:n,offer:i}}))}_subscribeHandle(r,s=!1){var a,d,c,_,l,u,h,R,v,C,p;return i(this,void 0,void 0,(function*(){const i=null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d?void 0:d.createTraceId();null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_T,JSON.stringify({trackIds:r.map(mt),forceReq:s}),i);if(this._assertRoomDestroyed())return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED,msg:"room destroyed"}),i),{code:e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED};if(!t.validate("tracks",r,(()=>t.isArray(r)&&r.length>0&&r.every((e=>e instanceof $e||e.track instanceof $e))),!0))return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),i),{code:e.RCRTCCode.PARAMS_ERROR};const{pc:g,pcName:m}=this._peerCManager.createPeerCList(r)[0];this._pc=g,this._pc.__reportR3R4ToPolaris(),this._pcName=m,this._pc.registerReportListener(this._reportListener),this._addPeerCEvent();const T=this._subscribedList.map((e=>Object.assign({},e))),I=r.map((e=>e instanceof $e?{track:e}:e));let E=!1;const S=[];return I.forEach((e=>{const t=e.track.getTrackId();S.push(t);const i=T.find((e=>e.track.getTrackId()===t));i&&i.subTiny===e.subTiny||(i?i.subTiny=e.subTiny:T.push(e),E=!0)})),E||s?(null===(p=this._polarisReport)||void 0===p||p.sendR2(Tn.SUBSCRIBE,In.BEGIN,S),this._updateSubListHandle(T,!0,i)):(null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.warn(o.L_AUDIENCE_LIVING_ROOM_SUBSCRIBE_R,JSON.stringify({status:n.SUCCESSED,msg:"repeat subscribe"}),i),{code:e.RCRTCCode.SUCCESS})}))}_addPeerCEvent(){this._pc.on(Mn.__INNER_EVENT_TRACK_READY__,(t=>{var i,r,n,s;const a=t.streams[0].id,{track:d}=t.receiver,c=[a,"audio"===d.kind?e.RCMediaType.AUDIO_ONLY:e.RCMediaType.VIDEO_ONLY].join("_"),_=this._remoteTracks[c];_?(_.__innerSetMediaStreamTrack(d),null===(s=null===(n=this._context)||void 0===n?void 0:n.logger)||void 0===s||s.info(o.L_AUDIENCE_LIVING_ROOM_CALL_APP_LISTENER_O,JSON.stringify({eventType:"onTrackReady",trackId:_.getTrackId()})),this._callAppListener("onTrackReady",_)):null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.warn(o.L_AUDIENCE_LIVING_ROOM_ONTRACKREADY_O,`cannot found RCRemoteTrack: ${d.id}`)})),this._audioLevelReport&&this._pc.on(Mn.__INNER_AUDIOLEVEL_CHANGE__,this._audioLevelReport.audioLevelReport,this._audioLevelReport)}_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:gn.LIVE,UserId:e,"Session-Id":this._sessionId,"Client-Session-Id":this._clientSessionId},t)}_exchangeHandle(e){return this._service.broadcastSubscribe(this._getReqHeaders(),e)}_updateSubListHandle(t,r=!1,s){var a,d,c,_,l,u,h,R,v,C,p,g;return i(this,void 0,void 0,(function*(){null===(a=this._context.logger)||void 0===a||a.info(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_T,JSON.stringify({trackIds:t.map(mt),forceReq:r}),s);let i=t.map((e=>e instanceof $e?{track:e}:Object.assign({},e)));const m={};i=i.filter((e=>{const t=e.track.getTrackId();return!m[t]&&(m[t]=!0,!0)})).map((e=>Object.assign({},e)));const T=this._subscribedList.map((e=>Object.assign({},e)));if(!r){let t=!1;if(i.forEach((e=>{const i=T.findIndex((t=>t.track===e.track));if(-1===i)return void(t=!0);T.splice(i,1)[0].subTiny!==e.subTiny&&(t=!0)})),T.length&&(t=!0),!t)return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:n.SUCCESSED,msg:"repeat subscribe"}),s),{code:e.RCRTCCode.SUCCESS}}this._pc.clearReTryExchangeTimer(),this._pc.updateSubRemoteTracks(i.map((e=>e.track))),Uo(this._roomId,this._clientSessionId,this._sessionId),Po(this._roomId,this._clientSessionId,this._sessionId);const{reqBody:I}=yield this._createSubscribeParams(i,{},!1),E=yield this._exchangeHandle(I);if(T.length){const e=[];T.forEach((t=>{e.push(t.track.getTrackId())})),null===(_=this._pc.reportParser)||void 0===_||_.clearLatestPacketsRecv(e)}if(E.code!==e.RCRTCCode.SUCCESS)return wo(i,E.code),null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:n.FAILED,code:E.code}),s),{code:E.code};const{sdp:S,resultCode:f,message:O,subscribedList:L}=E.data;if(f!==e.RCRTCCode.SUCCESS)return wo(i,f),null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:n.FAILED,code:f,msg:O}),s),{code:f};i.forEach((e=>{const{track:t}=e;if(t.isMCUTrack()){const e=this._roomRes[t.getTrackId()].msid,{tag:i,userId:r}=rt(t.getTrackId()),o=[r,i].join("_");S.sdp=S.sdp.replace(new RegExp(e,"g"),o)}}));const N=yield this._pc.setRemoteAnswer(S.sdp);if(N!==e.RCRTCCode.SUCCESS)return wo(i,N),null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.error(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:n.FAILED,code:N,msg:"set remote answer error"}),s),{code:N};wo(i,N);const A=null==L?void 0:L.map((e=>`${e.msid}_${e.mediaType}`)),y=i.filter((e=>{if(e.track.isMCUTrack()){const t=this._roomRes[e.track.getTrackId()],i=`${t.msid}_${t.mediaType}`;return A.includes(i)}return null==A?void 0:A.includes(e.track.getTrackId())})),k=null==y?void 0:y.map((e=>`${e.track.getTrackId()}`)),D=i.filter((e=>!(null==k?void 0:k.includes(e.track.getTrackId()))));for(const e in this._remoteTracks){const t=y.some((t=>t.track.getTrackId()===e));this._remoteTracks[e].__innerSetSubscribed(t)}return this._subscribedList.splice(0,this._subscribedList.length,...y),null===(g=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===g||g.info(o.L_AUDIENCE_LIVING_ROOM_UPDATE_SUBSCRIBELIST_R,JSON.stringify({status:n.SUCCESSED,subSuccessTrackIds:A,failedList:D}),s),D.length?{code:e.RCRTCCode.SUCCESS,failedList:D}:{code:e.RCRTCCode.SUCCESS}}))}_diffCDNUris(e,t){var r,n,s,a,d,c;return i(this,void 0,void 0,(function*(){if(this._CDNUris.url&&!e.url)return null===(n=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===n||n.info(o.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===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.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 i=this._CDNUris.w&&e.w&&this._CDNUris.w!==e.w,_=this._CDNUris.h&&e.h&&this._CDNUris.h!==e.h,l=this._CDNUris.fps&&e.fps&&this._CDNUris.fps!==e.fps;(i||_||l)&&(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.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(t,r){var s,a;return i(this,void 0,void 0,(function*(){const{w:i,h:d,fps:c}=t,_=this._initOptions.pullInnerCDNProtocol||e.RCInnerCDNPullKind.FLV,l=this._initOptions.pullInnerCDNUseHttps===e.RCInnerCDNPullIsHttps.NOT_HTTPS?e.RCInnerCDNPullIsHttps.NOT_HTTPS:e.RCInnerCDNPullIsHttps.HTTPS;if(!this._CDNUris.url)return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.CDN_RESOURCE_IS_EMPTY,msg:"cdn_uris url is empty, the anchor need to open or push CDN"}),r),{code:e.RCRTCCode.CDN_RESOURCE_IS_EMPTY};const u={"App-Key":this._context.getAppkey(),Token:this._joinResData.token,RoomId:this.getRoomId(),UserId:this._crtUserId,SessionId:this.getSessionId()},h=[],{w:R=0,h:v=1}=this._CDNUris;R/v>1?(i&&h.push(`w=${i}`),d&&h.push(`h=${d}`)):(i&&h.push(`h=${i}`),d&&h.push(`w=${d}`)),c&&h.push(`fps=${c}`),h.push(`kind=${_}`),h.push(`is_https=${l}`);const C=h.join("&");let p=`${this._CDNUris.url}?`;C&&(p+=C);const{code:g,res:m}=yield this._service.getCDNResourceInfo(u,p,r);return g!==e.RCRTCCode.SUCCESS?{code:g}:{code:g,CDNPlayUrl:null==m?void 0:m.data.pull_url}}))}getCDNPlayUrl(t,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_T,JSON.stringify({resolution:t,fps:r}),i),t&&!ct(t))return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> resolution"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(r&&!_t(r))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_AUDIENCE_LIVING_ROOM_GET_CDN_PLAY_URL_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> fps"}),i),{code:e.RCRTCCode.PARAMS_ERROR};const{width:R,height:v}=t?dt(t):{width:null,height:null},C=r?lt(r):null,p={};return R&&(p.w=R),v&&(p.h=v),C&&(p.fps=C),this._getCDNPlayUrl(p,i)}))}subscribe(e){return i(this,void 0,void 0,(function*(){return Wo(!0),Js((()=>this._subscribeHandle(e,!1)),"audience-sub")}))}addSubscribeTask(e){return i(this,void 0,void 0,(function*(){return Wo(!0),Js((()=>this._subscribeHandle(e,!1)),"audience-sub")}))}__unsubscribe(r){var s,a,d,c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_T,JSON.stringify({trackIds:r.map((e=>e.getTrackId()))}),i);if(this._assertRoomDestroyed())return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED,msg:"room destroyed"}),i),{code:e.RCRTCCode.ROOM_HAS_BEEN_DESTROYED};if(!t.validate("tracks",r,(()=>t.isArray(r)&&r.length>0&&r.every((e=>e instanceof $e))),!0))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_AUDIENCE_LIVING_ROOM_UNSUBSCRIBE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> tracks"}),i),{code:e.RCRTCCode.PARAMS_ERROR};const v=this._subscribedList.map((e=>Object.assign({},e))).filter((e=>!r.includes(e.track)));return null===(R=this._polarisReport)||void 0===R||R.sendR2(Tn.SUBSCRIBE,In.END,r.map((e=>e.getTrackId()))),qo(!0),this._updateSubListHandle(v,!1,i)}))}unsubscribe(e){return i(this,void 0,void 0,(function*(){return Js((()=>this.__unsubscribe(e)),"audience-unsub")}))}addUnsubscribeTask(e){return i(this,void 0,void 0,(function*(){return Js((()=>this.__unsubscribe(e)),"audience-unsub")}))}__destroy(e){var t;return i(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(),Do.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,r,s,a,d,c,_,l;return i(this,void 0,void 0,(function*(){const i=null===(r=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===r?void 0:r.createTraceId();null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_T,void 0,i);const{code:u}=yield this._context.joinLivingRoomAsAudience(this._roomId,gn.LIVE);u!==t.ErrorCode.SUCCESS&&(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_R,`status: ${n.FAILED}`,i)),null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_AUDIENCE_LIVING_ROOM_IM_RECONNECTED_R,`status: ${n.SUCCESSED}`,i)}))}registerRoomEventListener(e){this._appListener=e}onAudioLevelChange(e,t){var i,r;this._audioLevelReport=new Bn(this),this._audioLevelReport.onAudioLevelChange(e),null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(o.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}}class Ws{constructor(e){this._context=e,this._isElectron=/Electron/.test(navigator.userAgent)}_getMediaStream(t,r="getUserMedia"){return i(this,void 0,void 0,(function*(){try{const i=this.setConstraintsConfig(t),o=yield navigator.mediaDevices[r](i);return{code:e.RCRTCCode.SUCCESS,stream:o}}catch(t){if("Permission denied"===t.message)return{code:e.RCRTCCode.BROWSER_PERMISSION_DENIED};if("Permission denied by system"===t.message)return{code:e.RCRTCCode.SYSTEM_PERMISSION_DENIED}}return{code:"getUserMedia"===r?e.RCRTCCode.GET_USER_MEDIA_FAILED:e.RCRTCCode.GET_DISPLAY_MEDIA_FAILED}}))}_getMediaStreamErrorReason(t){let i="";return t===e.RCRTCCode.BROWSER_PERMISSION_DENIED&&(i="Permission denied"),t===e.RCRTCCode.SYSTEM_PERMISSION_DENIED&&(i="Permission denied by system"),i}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(o.L_SET_AUDIO_CONSTRAINTS_O,`browser supported -> ${JSON.stringify(r)}`)}return e}createMicrophoneAudioTrack(t="RongCloudRTC",r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(!Ze(t))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS};const i=this._context.getCurrentId();if(!i)return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID};const{stream:R,code:v}=yield this._getMediaStream({audio:{deviceId:null==r?void 0:r.micphoneId,sampleRate:null==r?void 0:r.sampleRate}});if(v!==e.RCRTCCode.SUCCESS)return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:v,msg:this._getMediaStreamErrorReason(v)})),{code:v};const C=R.getAudioTracks()[0],p=new He(t,i,C);return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_RTC_CLIENT_CREATE_MICROPHONE_AUDIO_TRACK_O,JSON.stringify({status:n.SUCCESSED,trackId:p.getTrackId()})),{code:v,track:p}}))}createCameraVideoTrack(t="RongCloudRTC",r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(!Ze(t))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS};const i=this._context.getCurrentId();if(!i)return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID};const R=ct(null==r?void 0:r.resolution)?r.resolution:e.RCResolution.W640_H480,{width:v,height:C}=dt(R),{stream:p,code:g}=yield this._getMediaStream({video:{deviceId:null==r?void 0:r.cameraId,frameRate:lt((null==r?void 0:r.frameRate)||e.RCFrameRate.FPS_15),width:v,height:C,facingMode:null==r?void 0:r.faceMode}});if(g!==e.RCRTCCode.SUCCESS)return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:this._getMediaStreamErrorReason(g)})),{code:g};const m=p.getVideoTracks()[0],T=new Ge(t,i,m);return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_RTC_CLIENT_CREATE_CAMERA_VIDEO_TRACK_O,JSON.stringify({status:n.SUCCESSED,trackId:T.getTrackId()})),{code:g,track:T}}))}createMicrophoneAndCameraTracks(t="RongCloudRTC",r){var s,a,d,c,_,l,u,h,R,v,C,p,g,m;return i(this,void 0,void 0,(function*(){const i=[];if(!Ze(t))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS,tracks:i};const T=this._context.getCurrentId();if(!T)return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID,tracks:i};const I=ct(null===(_=null==r?void 0:r.video)||void 0===_?void 0:_.resolution)?r.video.resolution:e.RCResolution.W640_H480,{width:E,height:S}=dt(I),{stream:f,code:O}=yield this._getMediaStream({video:{deviceId:null===(l=null==r?void 0:r.video)||void 0===l?void 0:l.cameraId,frameRate:lt((null===(u=null==r?void 0:r.video)||void 0===u?void 0:u.frameRate)||e.RCFrameRate.FPS_15),width:E,height:S,facingMode:null===(h=null==r?void 0:r.video)||void 0===h?void 0:h.faceMode},audio:{deviceId:null===(R=null==r?void 0:r.audio)||void 0===R?void 0:R.micphoneId,sampleRate:null===(v=null==r?void 0:r.audio)||void 0===v?void 0:v.sampleRate}});return O!==e.RCRTCCode.SUCCESS?(null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:n.FAILED,code:O,msg:this._getMediaStreamErrorReason(O)})),{code:O,tracks:i}):(f.getTracks().forEach((e=>{"video"===e.kind?i.push(new Ge(t,T,e)):i.unshift(new He(t,T,e))})),null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.info(o.L_RTC_CLIENT_CREATE_MICROPHONE_AND_CAMERA_TRACKS_O,JSON.stringify({status:n.SUCCESSED,trackIds:i.map((e=>e.getTrackId()))})),{code:O,tracks:i})}))}createScreenVideoTrack(t="screenshare",r){return i(this,void 0,void 0,(function*(){const i=yield this._createScreenTracks(t,!1,o.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_TRACK_O,r);return i.code===e.RCRTCCode.SUCCESS?{code:i.code,track:i.tracks[0]}:i}))}createScreenWithAudioTracks(e="screenshare",t){return i(this,void 0,void 0,(function*(){return this._createScreenTracks(e,!0,o.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_AND_AUDIO_TRACKS_O,t)}))}_createScreenTracks(r,s,a,d){var c,_,l,u,h,R,v,C,p,g,m,T,I,E,S,f;return i(this,void 0,void 0,(function*(){if(!Ze(r))return null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.error(a,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS};const i=this._context.getCurrentId();if(!i)return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(a,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID};if(!Rt())return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_RTC_CLIENT_CREATE_SCREEN_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.BROWSER_NOT_SUPPORT,msg:"browser not support"})),{code:e.RCRTCCode.BROWSER_NOT_SUPPORT};const O=/macintosh|mac os x/i.test(navigator.userAgent);this._isElectron&&O&&s&&(null===(C=null===(v=this._context)||void 0===v?void 0:v.logger)||void 0===C||C.warn(a,JSON.stringify({status:n.INFO,code:e.RCRTCCode.MAC_IN_ELECTRON_NOT_SUPPORT_SCREEN_SHARE_WITH_AUDIO,msg:"mac in electron not support screen share with audio"})));const L=(!this._isElectron||!O)&&s;if(this._isElectron&&!t.isUndefined(null==d?void 0:d.chromeMediaSourceId)&&!t.isString(null==d?void 0:d.chromeMediaSourceId))return null===(g=null===(p=this._context)||void 0===p?void 0:p.logger)||void 0===g||g.error(a,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> options.chromeMediaSourceId type is string"})),{code:e.RCRTCCode.PARAMS_ERROR};const N=ct(null==d?void 0:d.resolution)?d.resolution:e.RCResolution.W1280_H720,{width:A,height:y}=dt(N),k=this._isElectron?{mandatory:{chromeMediaSourceId:null==d?void 0:d.chromeMediaSourceId,chromeMediaSource:"desktop",minWidth:A,maxWidth:A,minHeight:y,maxHeight:y}}:{frameRate:lt((null==d?void 0:d.frameRate)||e.RCFrameRate.FPS_15),width:A,height:y};!(null==d?void 0:d.chromeMediaSourceId)&&this._isElectron&&(null===(m=k.mandatory)||void 0===m||delete m.chromeMediaSourceId);let D=null;L&&this._isElectron&&(null===(T=k.mandatory)||void 0===T||delete T.chromeMediaSourceId,D={mandatory:{chromeMediaSource:"desktop"}});const{stream:b,code:U}=yield this._getMediaStream({video:k,audio:D||L},this._isElectron?"getUserMedia":"getDisplayMedia");if(U!==e.RCRTCCode.SUCCESS)return null===(E=null===(I=this._context)||void 0===I?void 0:I.logger)||void 0===E||E.error(a,JSON.stringify({status:n.FAILED,code:U,msg:this._getMediaStreamErrorReason(U)})),{code:U};const P=b.getVideoTracks()[0],M=[new Ke(r,i,P)];if(L){const e=b.getAudioTracks()[0];e&&M.push(new je(r,i,e))}return null===(f=null===(S=this._context)||void 0===S?void 0:S.logger)||void 0===f||f.info(a,JSON.stringify({status:n.SUCCESSED,trackIds:M.map((e=>e.getTrackId()))})),{code:U,tracks:M}}))}createLocalAudioTrack(t,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(!Ze(t))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS};if(!r||"[object MediaStreamTrack]"!==r.toString()||"audio"!==r.kind)return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.CREATE_CUSTOM_TRACK_FAILED,msg:"params track is not MediaStreamTrack or kind is not audio"})),{code:e.RCRTCCode.CREATE_CUSTOM_TRACK_FAILED};const i=this._context.getCurrentId();if(!i)return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID};const R=new we(t,i,r);return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_RTC_CLIENT_CREATE_LOCAL_AUDIO_TRACK_O,JSON.stringify({status:n.SUCCESSED,trackId:R.getTrackId()})),{code:e.RCRTCCode.SUCCESS,track:R}}))}createLocalVideoTrack(t,r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){if(!Ze(t))return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.error(o.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS};if(!(r&&r instanceof MediaStreamTrack&&"video"===r.kind))return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.CREATE_CUSTOM_TRACK_FAILED,msg:"params track is not MediaStreamTrack or kind is not video"})),{code:e.RCRTCCode.CREATE_CUSTOM_TRACK_FAILED};const i=this._context.getCurrentId();if(!i)return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID};const R=new Be(t,i,r);return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_RTC_CLIENT_CREATE_LOCAL_VIDEO_TRACK_O,JSON.stringify({status:n.SUCCESSED,trackId:R.getTrackId()})),{code:e.RCRTCCode.SUCCESS,track:R}}))}createLocalFileTracks(r,s,a){var d,c,_,l,u,h,R,v;return i(this,void 0,void 0,(function*(){if(!Ze(r))return null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS,tracks:[]};if(!ht())return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.BROWSER_NOT_SUPPORT,msg:"browser not support"})),{code:e.RCRTCCode.BROWSER_NOT_SUPPORT,tracks:[]};const i=s instanceof File?URL.createObjectURL(s):s;if(!t.isHttpUrl(i)&&!/^blob:/.test(i))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> file"})),{code:e.RCRTCCode.PARAMS_ERROR,tracks:[]};const C=this._context.getCurrentId();return C?new Promise((t=>{const s=document.createElement("video");(null==a?void 0:a.withoutAudio)&&(s.muted=!0),s.onloadedmetadata=()=>{var i,d,c,_;const l=[];let u;try{const e=s.mozCaptureStream?"mozCaptureStream":"captureStream";u=s[e]()}catch(r){null===(d=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===d||d.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.CREATE_FILE_TRACK_FAILED,msg:`captureSteam error -> ${JSON.stringify(r)}`})),t({code:e.RCRTCCode.CREATE_FILE_TRACK_FAILED,tracks:l})}const[h,R]=Ws.getTracksWithOptions(u,a);h&&l.push(new Je(r,C,h,s)),R&&l.push(new Fe(r,C,R,s)),0===l.length&&(s.pause(),s.src=""),s.onerror=null,null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.info(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.SUCCESSED,trackIds:l.map((e=>e.getTrackId()))})),t({code:e.RCRTCCode.SUCCESS,tracks:l})},s.onerror=()=>{var i,r;null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.CREATE_FILE_TRACK_FAILED,msg:"Failed to create file stream, video onerror"})),t({code:e.RCRTCCode.CREATE_FILE_TRACK_FAILED,tracks:[]})},s.src=i,s.loop=!0,s.play()})):(null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_RTC_CLIENT_CREATE_LOCAL_FILE_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID,tracks:[]})}))}createLocalTracks(t,r,s){var a,d,c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=[];if(!Ze(t))return null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_TAGS,msg:"invalid tag"})),{code:e.RCRTCCode.INVALID_TAGS,tracks:i};if(!(r instanceof MediaStream))return null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> stream"})),{code:e.RCRTCCode.PARAMS_ERROR,tracks:i};const v=this._context.getCurrentId();if(!v)return null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.INVALID_USER_ID,msg:"invalid IM connection,invalid userId"})),{code:e.RCRTCCode.INVALID_USER_ID,tracks:i};const[C,p]=Ws.getTracksWithOptions(r,s);return C&&i.push(new we(t,v,C)),p&&i.push(new Be(t,v,p)),null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_RTC_CLIENT_CREATE_LOCAL_TRACKS_O,JSON.stringify({status:n.SUCCESSED,trackIds:i.map((e=>e.getTrackId()))})),{code:e.RCRTCCode.SUCCESS,tracks:i}}))}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 qs{constructor(){this.tasks=[]}static handler(){return this.retryHandler||(this.retryHandler=new qs),this.retryHandler}execute(){for(const e of this.tasks)e();this.destroy()}task(e){return i(this,void 0,void 0,(function*(){return new Promise((t=>{this.tasks.push((()=>{t(e())}))}))}))}destroy(){this.tasks=[]}}class Ys extends Ws{constructor(e,t,i){super(e),this._context=e,this._runtime=t,this._options=i,this._crtRoom=null,this._audience=null,this._crtAudienceLivingRoom=null,An.setSdpSemantics(i.sdpSemantics||"plan-b"),this._service=new zo(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 i,r,s,a,d,c;if(e.conversationType!==t.ConversationType.RTC_ROOM)return!1;const _=null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r?void 0:r.createTraceId();if(this._crtRoom instanceof Bs){this._getJoinedPKRoomList().forEach((t=>{t.__parseInnerMessage(e,_)}))}return null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a||a.info(o.L_RTC_CLIENT_MESSAGE_O,JSON.stringify({status:n.SUCCESSED,message:e}),_),this._crtRoom?(this._crtRoom.__parseInnerMessage(e,_),!0):(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.warn(o.L_RTC_CLIENT_MESSAGE_O,JSON.stringify({status:n.FAILED,message:"the crtRoom is empty"}),_),!0)}naviDataChange(e){var t,i;null===(i=null===(t=this._context)||void 0===t?void 0:t.logger)||void 0===i||i.info(o.L_RTC_CLIENT_NAVI_CHANGE_O,`on navi change data => ${JSON.stringify(e)}`),this._service.detectorMediaSever(),wn.logServer=null==e?void 0:e.logServer,wn.dc=null==e?void 0:e.dc}_getJoinedPKRoomList(){const{code:t,roomPKHandler:i}=this._crtRoom.getRoomPKHandler();if(t===e.RCRTCCode.SUCCESS&&i){const e=i.getJoinedPKRooms()||{};return Object.values(e)}return[]}getCurrentId(){return this._context.getCurrentId()}joinRTCRoom(t,r,s,a,d=gn.RTC,c){var _,l,u,h,R,v;return i(this,void 0,void 0,(function*(){const i=null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l?void 0:l.createTraceId();if(null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.info(o.L_RTC_CLIENT_JOIN_RTC_ROOM_T,JSON.stringify({roomId:t,joinType:r,outerUserDatas:s,useMutilPeerC:a,roomType:d}),i),this._crtRoom)return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_RTC_CLIENT_JOIN_RTC_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const C=this._crtRoom=new Vs(this._context,this._runtime,t,this._service,this._options,!1,!1,a,Oo(),c),{code:p}=yield C.__innerInit(d,r,void 0,void 0,s,i);return p!==e.RCRTCCode.SUCCESS?(this._crtRoom=null,{code:p}):(C.once(Ts,(()=>{this._crtRoom=null})),{code:p,room:C,userIds:C.getRemoteUserIds(),tracks:C.getRemoteTracks()})}))}joinCrossRTCRoom(t,r,s,a,d=gn.CROSS_MUTI){var c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_?void 0:_.createTraceId();if(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_T,JSON.stringify({roomId:t,joinType:r,outerUserDatas:s,useMutilPeerC:a,roomType:d}),i),this._crtRoom)return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_RTC_CLIENT_JOIN_CROSS_RTC_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const v=this._crtRoom=new Vs(this._context,this._runtime,t,this._service,this._options,!1,!1,a,Oo(),d),{code:C}=yield v.__innerInit(d,r,void 0,void 0,s,i);return C!==e.RCRTCCode.SUCCESS?(this._crtRoom=null,{code:C}):(v.once(Ts,(()=>{this._crtRoom=null})),{code:C,room:v,userIds:v.getRemoteUserIds(),tracks:v.getRemoteTracks()})}))}joinLivingRoom(t,r,s,a,d){var c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_?void 0:_.createTraceId();if(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_T,JSON.stringify({roomId:t,livingType:r,joinType:s,outerUserDatas:a,useMutilPeerC:d}),i),this._crtRoom)return null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:`Join the room repeatedly -> roomId: ${t}`}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const v=this._crtRoom=new Bs(this._context,this._runtime,t,this._service,this._options,r,!1,!0,d),{code:C}=yield v.__innerInit(gn.LIVE,s,r,void 0,a,i);if(C!==e.RCRTCCode.SUCCESS)return this._crtRoom=null,{code:C};v.once(Ts,(()=>{this._crtRoom=null}));const p={code:C,room:v,userIds:v.getRemoteUserIds(),tracks:v.getRemoteTracks()};return v.__getCDNPushMode()===ks.MANUAL&&Object.assign(p,{CDNEnable:v.__getCDNEnable()}),p}))}getAudienceClient(e){var t,i;return this._audience||(this._audience=new Hs(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(o.L_RTC_CLIENT_GET_AUDIENCE_CLIENT_O,JSON.stringify({useMutilPeerC:e})),this._audience}_onIMStatusChange(e){var i,r;if(null===(r=null===(i=this._context)||void 0===i?void 0:i.logger)||void 0===r||r.info(o.L_RTC_CLIENT_IM_CONNECTION_STATE_S,JSON.stringify({status:e})),e===t.ConnectionStatus.CONNECTED){if(this._service.detectorMediaSever(),this._crtRoom instanceof Bs){this._getJoinedPKRoomList().forEach((e=>{e.__onReconnected()}))}this._crtRoom&&this._crtRoom.__onReconnected().then((e=>{if(e&&e.data&&e.data.sessionId){qs.handler().execute()}}))}}_onIMDisconnect(){var e,t;null===(t=null===(e=this._context)||void 0===e?void 0:e.logger)||void 0===t||t.info(o.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(o.L_RTC_CLIENT_DESTROY_S,JSON.stringify({msg:"TODO -> on IM client ondestroy"})),null===(i=this._crtRoom)||void 0===i||i.__destroy(!0)}leaveRoom(t){var r,s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const i=null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s?void 0:s.createTraceId();return null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_RTC_CLIENT_LEAVE_ROOM_T,JSON.stringify({roomId:t.getRoomId()}),i),this._crtRoom?(yield this._crtRoom.__destroy(!0),this._service.detectorMediaSever(),null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_RTC_CLIENT_LEAVE_ROOM_R,JSON.stringify({status:n.SUCCESSED,roomId:null===(h=this._crtRoom)||void 0===h?void 0:h.getRoomId()}),i),this._crtRoom=null,{code:e.RCRTCCode.SUCCESS}):(null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.warn(o.L_RTC_CLIENT_LEAVE_ROOM_R,JSON.stringify({status:n.FAILED,msg:"Room does not exist, without leave"}),i),{code:e.RCRTCCode.SUCCESS})}))}joinLivingRoomAsAudience(r,s,a){var d,c,_,l,u,h,R,v,C,p,g,m,T,I,E,S;return i(this,void 0,void 0,(function*(){const i=null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c?void 0:c.createTraceId();if(null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.info(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_T,JSON.stringify({roomId:r,livingType:s,useMutilPeerC:a}),i),this._service.detectorMediaSever(),Ct(this._context.getNaviInfo()))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR,msg:"package environment error"}),i),{code:e.RCRTCCode.PACKAGE_ENVIRONMENT_ERROR};if(!t.validate("roomId",r,t.notEmptyString,!0)||!t.validate("livingType",s,(t=>t===e.RCLivingType.AUDIO||t===e.RCLivingType.VIDEO)))return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> roomId or livingType"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(this._crtAudienceLivingRoom)return null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};if(!this._service.getNaviMS().length)return null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER,msg:"No audio / video server address available"}),i),{code:e.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER};const{code:f,data:O}=yield this._context.joinLivingRoomAsAudience(r,gn.LIVE,s);if(f!==t.ErrorCode.SUCCESS)return null===(I=null===(T=this._context)||void 0===T?void 0:T.logger)||void 0===I||I.error(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:f,msg:"signal error -> audience join room"}),i),{code:e.RCRTCCode.SIGNAL_AUDIENCE_JOIN_ROOM_FAILED};const L=Oo();(e=>{Do.getMemo().clientData={clientSessionId:e}})(L);const N=new $s(this._context,this._runtime,this._options,r,O,s,a,L);return this._crtAudienceLivingRoom=N,null===(S=null===(E=this._context)||void 0===E?void 0:E.logger)||void 0===S||S.info(o.L_RTC_CLIENT_JOIN_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.SUCCESSED,roomData:O}),i),{room:N,code:e.RCRTCCode.SUCCESS,userIds:N.getRemoteUserIds(),RTCTracks:N.getRemoteRTCTracks(),MCUTracks:N.getRemoteMCUTracks(),CDNUris:N.getCDNInfo()}}))}leaveLivingRoomAsAudience(t){var r,s,a,d,c,_,l,u,h,R;return i(this,void 0,void 0,(function*(){const i=null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s?void 0:s.createTraceId();return null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.info(o.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_T,JSON.stringify({roomId:t.getRoomId(),userId:this._context.getCurrentId()}),i),this._crtAudienceLivingRoom?this._crtAudienceLivingRoom!==t?(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.error(o.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> room"}),i),{code:e.RCRTCCode.PARAMS_ERROR}):(yield this._crtAudienceLivingRoom.__destroy(!0),this._crtAudienceLivingRoom=null,null===(R=null===(h=this._context)||void 0===h?void 0:h.logger)||void 0===R||R.info(o.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.SUCCESSED}),i),{code:e.RCRTCCode.SUCCESS}):(null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.warn(o.L_RTC_CLIENT_LEAVE_LIVING_ROOM_AS_AUDIENCE_R,JSON.stringify({status:n.FAILED,msg:"Room does not exist, without leave"}),i),{code:e.RCRTCCode.SUCCESS})}))}upgradeToAnchorRoom(r){var s,a,d,c,_,l,u,h;return i(this,void 0,void 0,(function*(){const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_T,void 0,i),!t.validate("room",r,(()=>r instanceof $s),!0))return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> room"}),i),{code:e.RCRTCCode.PARAMS_ERROR};const R=r.getRoomId();if(this._crtRoom)return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_RTC_CLIENT_UPGRADE_TO_ANCHOR_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly",roomId:R}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const v=this._crtRoom=new Bs(this._context,this._runtime,R,this._service,this._options,r.livingType,!0,!0,!1,r.getClientSessionId());return(yield v.__innerInitByIdentityChange(i))!==t.ErrorCode.SUCCESS?(this._crtRoom=null,{code:e.RCRTCCode.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED}):(v.once(Ts,(()=>{this._crtRoom=null})),yield this._crtAudienceLivingRoom.__destroy(!1),this._crtAudienceLivingRoom=null,{room:v,code:e.RCRTCCode.SUCCESS,userIds:v.getRemoteUserIds(),tracks:v.getRemoteTracks()})}))}downgradeToAudienceRoom(r){var s,a,d,c,_,l,u,h,R,v,C,p,g,m;return i(this,void 0,void 0,(function*(){const i=null===(a=null===(s=this._context)||void 0===s?void 0:s.logger)||void 0===a?void 0:a.createTraceId();if(null===(c=null===(d=this._context)||void 0===d?void 0:d.logger)||void 0===c||c.info(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_T,JSON.stringify({roomId:r._roomId,userId:this._context.getCurrentId()}),i),!r.isMainRoom())return null===(l=null===(_=this._context)||void 0===_?void 0:_.logger)||void 0===l||l.error(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM,msg:"the `downgradeToAudienceRoom` is disabled in PK room"}),i),{code:e.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM};if(!t.validate("room",r,(()=>r instanceof Bs),!0))return null===(h=null===(u=this._context)||void 0===u?void 0:u.logger)||void 0===h||h.error(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.PARAMS_ERROR,msg:"params error -> room"}),i),{code:e.RCRTCCode.PARAMS_ERROR};if(this._crtAudienceLivingRoom)return null===(v=null===(R=this._context)||void 0===R?void 0:R.logger)||void 0===v||v.error(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.REPERT_JOIN_ROOM,msg:"Join the room repeatedly"}),i),{code:e.RCRTCCode.REPERT_JOIN_ROOM};const{code:T,data:I}=yield this._context.rtcIdentityChange(r._roomId,bs.AnchorToViewer,r.getLivingType());if(T!==t.ErrorCode.SUCCESS)return null===(p=null===(C=this._context)||void 0===C?void 0:C.logger)||void 0===p||p.error(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:n.FAILED,code:e.RCRTCCode.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED}),i),{code:e.RCRTCCode.SIGNAL_ROOM_CHANGE_IDENTITY_FAILED};null===(m=null===(g=this._context)||void 0===g?void 0:g.logger)||void 0===m||m.info(o.L_RTC_CLIENT_DOWNGRADE_TO_AUDIENCE_ROOM_R,JSON.stringify({status:n.SUCCESSED,roomData:I}),i);const E=r.getClientSessionId(),S=new $s(this._context,this._runtime,this._options,r._roomId,I,r.getLivingType(),!1,E);return this._crtAudienceLivingRoom=S,this._crtRoom.__destroy(!1),this._crtRoom=null,{room:S,code:e.RCRTCCode.SUCCESS,userIds:S.getRemoteUserIds(),RTCTracks:S.getRemoteRTCTracks(),MCUTracks:S.getRemoteMCUTracks(),CDNUris:S.getCDNInfo()}}))}getJoinedRoomInfo(){var r,s,a,d,c,_,l,u;return i(this,void 0,void 0,(function*(){const i=null===(s=null===(r=this._context)||void 0===r?void 0:r.logger)||void 0===s?void 0:s.createTraceId(),h=this._context.getCurrentId();null===(d=null===(a=this._context)||void 0===a?void 0:a.logger)||void 0===d||d.error(o.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_T,JSON.stringify({userId:h}),i);const{code:R,data:v}=yield this._context.getRTCJoinedUserInfo(h);return R!==t.ErrorCode.SUCCESS?(null===(_=null===(c=this._context)||void 0===c?void 0:c.logger)||void 0===_||_.error(o.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_R,JSON.stringify({status:n.FAILED,code:R}),i),{code:R}):(null===(u=null===(l=this._context)||void 0===l?void 0:l.logger)||void 0===u||u.info(o.L_RTC_CLIENT_GET_JOINED_ROOM_INFO_R,JSON.stringify({status:n.SUCCESSED,roomInfo:v}),i),{code:e.RCRTCCode.SUCCESS,data:v})}))}reportSDKInfo(){this._context.reportSDKInfo({"plugin-rtc":"5.6.7"})}}var zs;e.RTCJoinType=void 0,(zs=e.RTCJoinType||(e.RTCJoinType={}))[zs.KICK=0]="KICK",zs[zs.REFUSE=1]="REFUSE",zs[zs.COEXIST=2]="COEXIST";const Zs="rtcRJoin_data",Qs="rtcRExit",Xs="rtcRInfo",ea="rtcUData",ta="rtcUDel",ia="rtcSetData",ra="userSetData",oa="rtcQryData",na="rtcDelData",sa="rtcToken",aa="rtcUserState",da="rtcUList",ca="viewerJoinR",_a="viewerExitR",la="rtcPullKv",ua="rtcIdentityChange",ha="rtcInvite",Ra="rtcCancelInvite",va="rtcInviteAnswer",Ca="rtcEndInvite",pa="rtcQueryJoined",ga="rtcPullRoomStatus",ma="reportsdk",Ta="rtcPing";var Ia;!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"}(Ia||(Ia={}));const Ea={[Ia.RtcInput]:["roomType","broadcastType","extraInnerData","needSysChatroom","identityChangeType","joinType","innerDatas","outerDatas","supportNtf"],[Ia.RtcOutput]:["version"],[Ia.RtcUserListOutput]:["users","token","sessionId","roomInfo","version"],[Ia.SetUserStatusInput]:["status"],[Ia.RtcSetDataInput]:["interior","target","key","value","objectName","content"],[Ia.RtcUserSetDataInput]:["valueInfo","objectName","content"],[Ia.RtcDataInput]:["interior","target","key","objectName","content"],[Ia.RtcSetOutDataInput]:["target","valueInfo","objectName","content"],[Ia.MCFollowInput]:["state"],[Ia.RtcTokenOutput]:["rtcToken"],[Ia.RtcQryOutput]:["outInfo"],[Ia.RtcQryUserOutDataInput]:["userId"],[Ia.RtcUserOutDataOutput]:["user"],[Ia.RtcQueryListInput]:["order"],[Ia.RtcRoomInfoOutput]:["roomId","roomData","userCount","list"],[Ia.RtcValueInfo]:["key","value"],[Ia.RtcKeyDeleteInput]:["key"],[Ia.RtcNotifyMsg]:["type","time","roomId"],[Ia.RtcPullKV]:["timestamp","roomId"],[Ia.RtcKVOutput]:["entries","bFullUpdate","syncTime"],[Ia.RtcQueryUserJoinedInput]:["userId"],[Ia.RtcQueryUserJoinedOutput]:["info"],[Ia.RtcInviteInput]:["invitedUserId","timeoutTime","invitedRoomId","inviteInfo","inviteSessionId"],[Ia.RtcCancelInviteInput]:["invitedUserId","invitedRoomId","inviteInfo","inviteSessionId"],[Ia.RtcInviteAnswerInput]:["inviteUserId","answerCode","inviteRoomId","inviteSessionId","content","key","value"],[Ia.RtcEndInviteInput]:["inviteRoomId","inviteSessionId","inviteContent","inviteRoomKeys"],[Ia.RtcRoomStatusInput]:["version"],[Ia.RtcRoomStatusOutput]:["bFullStatus","version","usersData","roomStatus"],[Ia.RtcReportSDKInput]:["sdkInfo"],[Ia.RtcPBPolaris]:["type","appKey","sessionId","roomId","roomCreateTime","userId","userRole","joinTime","signalDataCenter","r1Info","r2Info","r3Info","r4Info"],[Ia.RtcPBR1Info]:["joinTime","rtcVersion","imVersion","platform","device","os","browserName","browserVersion"],[Ia.RtcPBR2Info]:["joinTime","sendTime","rtcActionType","rtcActionStatus","trackId"],[Ia.RtcPBR3Info]:["info"],[Ia.RtcPBR4Info]:["info"],[Ia.RtcPBStatusInfo]:["joinTime","receiveTime","totalBitRate","appCPUUsage","systemCPUUsage","systemCPUFrequency","networkStatus","googleRTTNetwork","ipAddress","useReceiveBroadBand","useSendBroadBand","packetLossCount","streams"],[Ia.RtcPBStreamInfo]:["trackId","codeName","volume","samplingRate","bitRate","packetLossRate","frameRate","resolution","blockTime","jitterData","nAckCount","pliCount","googleRTTTotalTime","isReceiveFirstFrameRate","codeType","isEnabled"]},Sa=`\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 ${Ia.SetUserStatusInput}\n {\n optional int32 status=1;\n }\n message ${Ia.MCFollowInput}\n {\n required string state = 1;\n }\n message ${Ia.RtcQueryListInput}{\n optional int32 order=1;\n }\n message ${Ia.RtcKeyDeleteInput}{\n repeated string key=1;\n }\n message ${Ia.RtcValueInfo}{\n required string key=1;\n required string value=2;\n }\n message RtcUserInfo{\n required string userId=1;\n repeated ${Ia.RtcValueInfo} userData=2; //用户资源信息\n }\n message ${Ia.RtcRoomStatusInput}{ // rtc 和 living room 拉房间资源状态使用的参数\n required int64 version =1; //当前客户端最大的房间状态的version\n }\n message ${Ia.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 ${Ia.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 ${Ia.RtcValueInfo} roomData = 2;\n optional int32 userCount = 3;\n repeated RtcUserInfo list=4;\n }\n message ${Ia.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 ${Ia.RtcValueInfo} innerDatas = 7; //用户内部inner数据,角色或者连麦信息等\n repeated ${Ia.RtcValueInfo} outerDatas = 8; //用户内部outer数据,自定义数据结构RtcInput。\n optional bool supportNtf = 9; //是否支持房间状态的变更通过通知拉取的方式获取\n }\n message ${Ia.RtcQryOutput}{\n repeated ${Ia.RtcValueInfo} outInfo=1;\n }\n message ${Ia.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 ${Ia.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 ${Ia.RtcUserSetDataInput} {\n repeated ${Ia.RtcValueInfo} valueInfo = 1;\n required string objectName = 2;\n repeated ${Ia.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 ${Ia.RtcTokenOutput}{\n required string rtcToken=1;\n }\n message ${Ia.RtcSetOutDataInput}{\n required targetType target=1;\n repeated ${Ia.RtcValueInfo} valueInfo=2;\n optional string objectName=3;\n optional string content=4;\n }\n message ${Ia.RtcQryUserOutDataInput}{\n repeated string userId = 1;\n }\n message ${Ia.RtcUserOutDataOutput}{\n repeated RtcUserInfo user = 1;\n }\n message ${Ia.RtcNotifyMsg} \n {\n required int32 type= 1; //(通知类型 1:rtc房间状态KV变更通知)\n optional int64 time= 2; //消息产生时间\n optional string roomId=3; //主播房间id\n }\n message ${Ia.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 ${Ia.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 ${Ia.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 ${Ia.RtcQueryUserJoinedOutput}\n {\n repeated RtcJoinedInfo info = 1;\n }\n message ${Ia.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 ${Ia.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 ${Ia.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 ${Ia.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 ${Ia.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 ${Ia.RtcReportSDKInput} {\n required string sdkInfo=1; // 用户集成的 sdk 信息,json 格式 {"web-rtc": "4.0.3.7"}\n }\n // ---- 北极星数据上报 -------\n message ${Ia.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 ${Ia.RtcPBR1Info} r1Info = 10;\n optional ${Ia.RtcPBR2Info} r2Info = 11;\n optional ${Ia.RtcPBR3Info} r3Info = 12;\n optional ${Ia.RtcPBR4Info} r4Info = 13;\n }\n message ${Ia.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 ${Ia.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 ${Ia.RtcPBR3Info} {\n required ${Ia.RtcPBStatusInfo} info = 1;\n }\n message ${Ia.RtcPBR4Info} {\n required ${Ia.RtcPBStatusInfo} info = 1;\n }\n message ${Ia.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 ${Ia.RtcPBStreamInfo} streams = 13;\n }\n message ${Ia.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`,fa=(e,t,i,r,o,n,s)=>{const a=o?Object.keys(o).map((t=>e.encode(Ia.RtcValueInfo,{key:t,value:o[t]},!0))):void 0,d=n?Object.keys(n).map((t=>e.encode(Ia.RtcValueInfo,{key:t,value:n[t]},!0))):void 0;return e.encode(Ia.RtcInput,{roomType:t,broadcastType:i,joinType:r,innerDatas:a,outerDatas:d,supportNtf:s})},Oa=(e,i)=>{const r=e.decode(Ia.RtcUserListOutput,i),{users:o,token:n,sessionId:s,roomInfo:a,entries:d,offlineKickTime:c=60,codeFormat:_,roomCreateTime:l,userJoinTime:u,version:h}=r,R={};return t.forEach(o,(e=>{const{userId:i,userData:r}=e,o={};t.forEach(r,(e=>{const{key:t,value:i}=e;o[t]=i})),R[i]=o})),{users:R,token:n,sessionId:s,roomInfo:a,kvEntries:d,offlineKickTime:c,codeFormat:_,roomCreateTime:Tt(l),userJoinTime:Tt(u),version:h}};class La{constructor(e,t){this.context=e,this.codec=t,this.roomCreateTime=0,this.userJoinTime=0,this.logger=null,this.logger=Le.getLogger()}joinRTCRoom(e,r,o,n,s,a){return i(this,void 0,void 0,(function*(){const i=fa(this.codec,r,o,n,s,a,!0),{code:d,buffer:c}=yield this.context.rtcSignaling(e,Zs,!0,i);let _;if(d===t.ErrorCode.SUCCESS&&c){_=Oa(this.codec,c);const{users:e,token:t,sessionId:i,roomInfo:r,kvEntries:o,offlineKickTime:n,roomCreateTime:s,userJoinTime:a,version:l}=_;return this.roomCreateTime=s,this.userJoinTime=a,{code:d,data:{users:e,token:t,sessionId:i,roomInfo:r,kvEntries:o,offlineKickTime:n,version:l}}}return{code:d,data:_}}))}quitRTCRoom(e){return i(this,void 0,void 0,(function*(){const t=this.codec.encode(Ia.SetUserStatusInput,{status:0}),{code:i}=yield this.context.rtcSignaling(e,Qs,!0,t);return i}))}getRTCRoomInfo(e){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcQueryListInput,{order:2}),{code:r,buffer:o}=yield this.context.rtcSignaling(e,Xs,!0,i);let n;return r===t.ErrorCode.SUCCESS&&o&&(n=this.codec.decode(Ia.RtcRoomInfoOutput,o)),{code:r,data:n}}))}getRTCUserInfoList(e){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcQueryListInput,{order:2}),{code:r,buffer:o}=yield this.context.rtcSignaling(e,ea,!0,i);let n;if(r===t.ErrorCode.SUCCESS&&o){n={users:Oa(this.codec,o).users}}return{code:r,data:n}}))}getRTCUserInfo(e){throw new Error("Method not implemented.")}removeRTCUserInfo(e,t){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcKeyDeleteInput,{key:t}),{code:r}=yield this.context.rtcSignaling(e,ta,!1,i);return r}))}setRTCData(e,t,r,o,n,s){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcSetDataInput,{interior:o,target:n,key:t,value:r,objectName:null==s?void 0:s.name,content:null==s?void 0:s.content}),{code:a}=yield this.context.rtcSignaling(e,ia,!1,i);return a}))}setRTCTotalRes(e,t,r,o,n,s){return i(this,void 0,void 0,(function*(){const i={objectName:o,content:[],valueInfo:[this.codec.encode(Ia.RtcValueInfo,{key:"uris",value:r},!0)]};t.forEach((e=>{const t=this.codec.encode(Ia.RtcValueInfo,{key:e.name,value:e.content},!0);i.content.push(t)})),n&&i.valueInfo.push(this.codec.encode(Ia.RtcValueInfo,{key:"mcu_uris",value:n},!0)),s&&i.valueInfo.push(this.codec.encode(Ia.RtcValueInfo,{key:"cdn_uris",value:s},!0));const a=this.codec.encode(Ia.RtcUserSetDataInput,i),{code:d}=yield this.context.rtcSignaling(e,ra,!0,a);return d}))}setRTCCDNUris(e,t,r){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcUserSetDataInput,{objectName:t,valueInfo:this.codec.encode(Ia.RtcValueInfo,{key:"cdn_uris",value:r},!0)}),{code:o}=yield this.context.rtcSignaling(e,ra,!0,i);return o}))}getRTCData(e,r,o,n){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcDataInput,{interior:o,target:n,key:r}),{code:s,buffer:a}=yield this.context.rtcSignaling(e,oa,!0,i);if(s!==t.ErrorCode.SUCCESS||!a)return{code:s};const{outInfo:d}=this.codec.decode(Ia.RtcQryOutput,a),c={};return d.forEach((e=>{c[e.key]=e.value})),{code:s,data:c}}))}removeRTCData(e,t,r,o,n){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcDataInput,{interior:r,target:o,key:t,objectName:(null==n?void 0:n.name)||"",content:(null==n?void 0:n.content)||""}),{code:s}=yield this.context.rtcSignaling(e,na,!1,i);return s}))}setRTCOutData(e,t,r,o){return i(this,void 0,void 0,(function*(){throw new Error("JSEngine's method not implemented.")}))}getRTCOutData(e,t){return i(this,void 0,void 0,(function*(){throw new Error("JSEngine's method not implemented.")}))}getRTCToken(e,r,o){return i(this,void 0,void 0,(function*(){const i=fa(this.codec,r,o),{code:n,buffer:s}=yield this.context.rtcSignaling(e,sa,!0,i);if(n!==t.ErrorCode.SUCCESS||!s)return{code:n};const{rtcToken:a}=this.codec.decode(Ia.RtcTokenOutput,s);return{code:n,data:{rtcToken:a}}}))}setRTCState(e,t){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.MCFollowInput,{state:t}),{code:r}=yield this.context.rtcSignaling(e,aa,!0,i);return r}))}setRTCStateByHttp(e,r,o,n){return i(this,void 0,void 0,(function*(){const i=((e,t,i)=>{const{type:r,appKey:o,sessionId:n,roomId:s,roomCreateTime:a,userId:d,userRole:c,joinTime:_,signalDataCenter:l,r1Info:u,r2Info:h,r3Info:R,r4Info:v}=t,C={type:r,appKey:o,sessionId:n,roomId:s,roomCreateTime:a,userId:d,userRole:c,joinTime:_,signalDataCenter:l};if(i===un.R1&&u){const t=e.encode(Ia.RtcPBR1Info,u,!0);return e.encode(Ia.RtcPBPolaris,Object.assign(Object.assign({},C),{r1Info:t}))}if(i===un.R2&&h){const t=e.encode(Ia.RtcPBR2Info,h,!0);return e.encode(Ia.RtcPBPolaris,Object.assign(Object.assign({},C),{r2Info:t}))}if(i===un.R3&&R){const{info:t}=R,{streams:i}=t;let r=Array.isArray(i)&&i.map((t=>t&&e.encode(Ia.RtcPBStreamInfo,t,!0))),o=e.encode(Ia.RtcPBStatusInfo,Object.assign(Object.assign({},t),{streams:r}),!0),n=e.encode(Ia.RtcPBR3Info,{info:o},!0);return e.encode(Ia.RtcPBPolaris,Object.assign(Object.assign({},C),{r3Info:n}))}if(i===un.R4&&v){const{info:t}=v,{streams:i}=t;let r=Array.isArray(i)&&i.map((t=>t&&e.encode(Ia.RtcPBStreamInfo,t,!0))),o=e.encode(Ia.RtcPBStatusInfo,Object.assign(Object.assign({},t),{streams:r}),!0),n=e.encode(Ia.RtcPBR4Info,{info:o},!0);return e.encode(Ia.RtcPBPolaris,Object.assign(Object.assign({},C),{r4Info:n}))}return{}})(this.codec,o,n);let s=e;/^https:\/\//.test(e)||(s=`https://${e}`);try{const e=yield r.httpReq({url:`${s}/rtc/logserver/polaris`,body:i,method:t.HttpMethod.POST,headers:{jwt:zo.jwtToken},timeout:2e3});if(!e.data)throw new Error("http request fail");return JSON.parse(e.data).resultCode}catch(e){return ln.REPORT_FAIL}}))}getRTCUserList(e){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcQueryListInput,{order:2}),{code:r,buffer:o}=yield this.context.rtcSignaling(e,da,!0,i);if(r!==t.ErrorCode.SUCCESS||!o)return{code:r};return{code:r,data:Oa(this.codec,o)}}))}joinLivingRoomAsAudience(e,r,o){return i(this,void 0,void 0,(function*(){const i=fa(this.codec,r,o);Jo(),Fo(r);const{code:n,buffer:s}=yield this.context.rtcSignaling(e,ca,!0,i);if(n!==t.ErrorCode.SUCCESS||!s)return{code:n};const{rtcToken:a,entries:d,roomCreateTime:c,userJoinTime:_}=this.codec.decode(Ia.RtcViewerJoinedOutput,s);return Vo(e,n,gt(e,d).sessionId,this.context.getCurrentId()),this.roomCreateTime=Tt(c),this.userJoinTime=Tt(_),{code:n,data:{token:a,kvEntries:d}}}))}quitLivingRoomAsAudience(e){return i(this,void 0,void 0,(function*(){const t=this.codec.encode(Ia.SetUserStatusInput,{status:0}),{code:i}=yield this.context.rtcSignaling(e,_a,!0,t);return i}))}rtcIdentityChange(e,r,o){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcInput,{roomType:gn.LIVE,broadcastType:o,identityChangeType:r,needSysChatroom:!1}),{code:n,buffer:s}=yield this.context.rtcSignaling(e,ua,!0,i);if(n!==t.ErrorCode.SUCCESS||!s)return{code:n};return{code:n,data:Oa(this.codec,s)}}))}requestRoomPK(e){return i(this,void 0,void 0,(function*(){const{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteTimeout:o,inviteInfo:n,roomId:s}=e,a=this.codec.encode(Ia.RtcInviteInput,{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,timeoutTime:o,inviteInfo:n}),{code:d}=yield this.context.rtcSignaling(s,ha,!0,a);return d}))}cancelRoomPK(e){return i(this,void 0,void 0,(function*(){const{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteInfo:o,roomId:n}=e,s=this.codec.encode(Ia.RtcCancelInviteInput,{invitedRoomId:t,invitedUserId:i,inviteSessionId:r,inviteInfo:o}),{code:a}=yield this.context.rtcSignaling(n,Ra,!0,s);return a}))}responseRoomPK(e){return i(this,void 0,void 0,(function*(){const{inviteUserId:t,inviteRoomId:i,inviteSessionId:r,content:o,key:n,value:s,agree:a,roomId:d}=e,c=this.codec.encode(Ia.RtcInviteAnswerInput,{inviteUserId:t,inviteRoomId:i,inviteSessionId:r,content:o,key:n,value:s,answerCode:a?1:0}),{code:_}=yield this.context.rtcSignaling(d,va,!0,c);return _}))}endRoomPK(e){return i(this,void 0,void 0,(function*(){const{endRoomId:t,sessionId:i,content:r,keys:o,roomId:n}=e,s=this.codec.encode(Ia.RtcEndInviteInput,{inviteRoomId:t,inviteSessionId:i,inviteContent:r,inviteRoomKeys:o}),{code:a}=yield this.context.rtcSignaling(n,Ca,!0,s);return a}))}getRTCJoinedUserInfo(e){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcQueryUserJoinedInput,{userId:e}),{code:r,buffer:o}=yield this.context.rtcSignaling("",pa,!0,i);if(r!==t.ErrorCode.SUCCESS||!o)return{code:r};return{code:r,data:(this.codec.decode(Ia.RtcQueryUserJoinedOutput,o).info||[]).map((e=>({deviceId:e.deviceId,roomId:e.roomId,joinTime:Tt(e.joinTime)})))}}))}pullRTCRoomEntry(e){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcPullKV,{timestamp:0,roomId:e}),{code:r,buffer:o}=yield this.context.rtcSignaling(e,la,!0,i);if(r!==t.ErrorCode.SUCCESS)return{code:r};const n=this.codec.decode(Ia.RtcKVOutput,o);let{entries:s,syncTime:a}=n;return s=(s||[]).map((e=>Object.assign(Object.assign({},e),{timestamp:Tt(e.timestamp)}))),{code:r,data:{kvEntries:s,syncTime:Tt(a)}}}))}pullRTCRoomStatus(e,r){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcRoomStatusInput,{version:r}),{code:o,buffer:n}=yield this.context.rtcSignaling(e,ga,!0,i);if(o!==t.ErrorCode.SUCCESS)return{code:o};return{code:o,data:this.codec.decode(Ia.RtcRoomStatusOutput,n)}}))}decodeRtcNotify(e){const{time:t,type:i,roomId:r}=this.codec.decode(Ia.RtcNotifyMsg,e);return{time:Tt(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,r,o){return i(this,void 0,void 0,(function*(){const i=this.codec.encode(Ia.RtcInput,{roomType:r,broadcastType:o}),{code:n,buffer:s}=yield this.context.rtcSignaling(e,Ta,!0,i);if(n!==t.ErrorCode.SUCCESS)return{code:n};const a=this.codec.decode(Ia.RtcOutput,s);return a.version=Tt(a.version),{code:n,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(Ia.RtcReportSDKInput,{sdkInfo:JSON.stringify(e)});this.context.rtcSignaling("",ma,!0,t)}}var Na;!function(e){e.RTC="RTC"}(Na||(Na={}));const Aa={tag:"RCRTC",verify:e=>"browser"!==e.tag?(console.error(`RCRTC Plugin is not support the runtime '${e.tag}'`),!1):Qe?(t.VersionManage.add("plugin-rtc","5.6.7"),!!t.VersionManage.validEngine("^5.6.0")||(console.error(`The current engine version '${t.VersionManage.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,s,a,d,c,_,l,u;const h=e.createLogger("RCRTC",Na.RTC);return h.setOutputLevel(r.logLevel||t.LogL.DEBUG),Le.setLogger(h),Ne.setLogger(h),h.warn(o.L_INDEX_INSTALL_RTC_PLUGIN_O,JSON.stringify({"RCRTC Version":"5.6.7",Commit:"175673bde55fc97dc1448f9912d7d45c88b7ba2d","browserInfo.browser":ut.browser,"browserInfo.supportsUnifiedPlan":ut.supportsUnifiedPlan,"browserInfo.version":ut.version})),t.assert("options.mediaServer",r.mediaServer,(e=>!(!t.isHttpUrl(e)||"https:"===location.protocol&&!/^https/.test(e)))),t.assert("options.timeout",r.timeout,(e=>t.isNumber(e)&&e>=5e3&&e<=3e4)),t.assert("options.pingGap",r.pingGap,(e=>t.isNumber(e)&&e>=3e3&&e<=1e4)),(null==r?void 0:r.audio)&&((null===(n=r.audio)||void 0===n?void 0:n.workletModule)&&(Me.workletModule=null===(s=r.audio)||void 0===s?void 0:s.workletModule),(null===(a=r.audio)||void 0===a?void 0:a.workletWasm)&&(Me.workletWasm=null===(d=r.audio)||void 0===d?void 0:d.workletWasm),(null===(c=r.audio)||void 0===c?void 0:c.workletModule)&&(null===(_=r.audio)||void 0===_?void 0:_.workletWasm)&&(Me.isOpen=!0),void 0!==(null===(l=r.audio)||void 0===l?void 0:l.isOpen)&&(Me.isOpen=null===(u=r.audio)||void 0===u?void 0:u.isOpen)),new Ys(new La(e,e.createCodec(Ea,Sa)),i,r)}},ya={transResolution:dt,transFrameRate:lt,parseTrackId:rt,ifSupportLocalFileTrack:ht,ifSupportScreenShare:Rt};e.RCAbstractRoom=Is,e.RCAudienceClient=Hs,e.RCAudienceLivingRoom=$s,e.RCCameraVideoTrack=Ge,e.RCLivingRoom=Bs,e.RCLocalAudioTrack=we,e.RCLocalFileAudioTrack=Je,e.RCLocalFileTrack=Ve,e.RCLocalFileVideoTrack=Fe,e.RCLocalTrack=xe,e.RCLocalVideoTrack=Be,e.RCMCUConfigBuilder=As,e.RCMediaStreamCapture=Ws,e.RCMicphoneAudioTrack=He,e.RCRTCClient=Ys,e.RCRTCRoom=Vs,e.RCRemoteAudioTrack=We,e.RCRemoteTrack=$e,e.RCRemoteVideoTrack=qe,e.RCScreenAudioTrack=je,e.RCScreenVideoTrack=Ke,e.RCTag={DEFAULT:"RongCloudRTC"},e.RCTrack=De,e.device=Ae,e.helper=ya,e.installer=Aa,Object.defineProperty(e,"__esModule",{value:!0})}));
|