import{R as n,P as e,L as S,T as b}from"./livekit-client-ca552de3.js";import{l as C}from"./loglevel-e40a507a.js";import{m as h,s as d,O as P}from"./rxjs-2154ddb2.js";var y="lk";function v(a){return typeof a>"u"?!1:E(a)||w(a)}function E(a){var r;return a?a.hasOwnProperty("participant")&&a.hasOwnProperty("source")&&a.hasOwnProperty("track")&&typeof((r=a.publication)==null?void 0:r.track)<"u":!1}function w(a){return a?a.hasOwnProperty("participant")&&a.hasOwnProperty("source")&&a.hasOwnProperty("publication")&&typeof a.publication<"u":!1}function M(a){return a?a.hasOwnProperty("participant")&&a.hasOwnProperty("source")&&typeof a.publication>"u":!1}function j(a){if(typeof a=="string"||typeof a=="number")return`${a}`;if(M(a))return`${a.participant.identity}_${a.source}_placeholder`;if(v(a))return`${a.participant.identity}_${a.publication.source}_${a.publication.trackSid}`;throw new Error(`Can't generate a id for the given track reference: ${a}`)}function B(a){return a instanceof S}var O=[n.ConnectionStateChanged,n.RoomMetadataChanged,n.ActiveSpeakersChanged,n.ConnectionQualityChanged,n.ParticipantConnected,n.ParticipantDisconnected,n.ParticipantPermissionsChanged,n.ParticipantMetadataChanged,n.TrackMuted,n.TrackUnmuted,n.TrackPublished,n.TrackUnpublished,n.TrackStreamStateChanged,n.TrackSubscriptionFailed,n.TrackSubscriptionPermissionChanged,n.TrackSubscriptionStatusChanged],L=[...O,n.LocalTrackPublished,n.LocalTrackUnpublished],U=[e.ConnectionQualityChanged,e.IsSpeakingChanged,e.ParticipantMetadataChanged,e.ParticipantPermissionsChanged,e.TrackMuted,e.TrackUnmuted,e.TrackPublished,e.TrackUnpublished,e.TrackStreamStateChanged,e.TrackSubscriptionFailed,e.TrackSubscriptionPermissionChanged,e.TrackSubscriptionStatusChanged];[...U,e.LocalTrackPublished,e.LocalTrackUnpublished];var g=C.getLogger("lk-components-js");g.setDefaultLevel("WARN");function _(a){return typeof a=="object"}function F(a){return Array.isArray(a)&&a.filter(_).length>0}function $(a,...r){return new P(o=>{const i=()=>{o.next(a)};return r.forEach(s=>{a.on(s,i)}),()=>{r.forEach(s=>{a.off(s,i)})}}).pipe(d(a))}function A(a){return`${y}-${a}`}function Q(a){const r=f(a),t=x(a.participant).pipe(h(()=>f(a)),d(r));return{className:A(a.source===b.Source.Camera||a.source===b.Source.ScreenShare?"participant-media-video":"participant-media-audio"),trackObserver:t}}function f(a){if(v(a))return a.publication;{const{source:r,name:t,participant:o}=a;if(r&&t)return o.getTracks().find(i=>i.source===r&&i.trackName===t);if(t)return o.getTrackByName(t);if(r)return o.getTrack(r);throw new Error("At least one of source and name needs to be defined")}}function k(a,...r){return new P(o=>{const i=()=>{o.next(a)};return r.forEach(s=>{a.on(s,i)}),()=>{r.forEach(s=>{a.off(s,i)})}}).pipe(d(a))}function x(a){return k(a,e.TrackMuted,e.TrackUnmuted,e.ParticipantPermissionsChanged,e.TrackPublished,e.TrackUnpublished,e.LocalTrackPublished,e.LocalTrackUnpublished,e.MediaDevicesError,e.TrackSubscriptionStatusChanged).pipe(h(t=>{const{isMicrophoneEnabled:o,isCameraEnabled:i,isScreenShareEnabled:c}=t,s=t.getTrack(b.Source.Microphone),u=t.getTrack(b.Source.Camera);return{isCameraEnabled:i,isMicrophoneEnabled:o,isScreenShareEnabled:c,cameraTrack:u,microphoneTrack:s,participant:t}}))}function K(a){var r,t,o,i;return k(a.participant,e.TrackMuted,e.TrackUnmuted,e.TrackSubscribed,e.TrackUnsubscribed,e.LocalTrackPublished,e.LocalTrackUnpublished).pipe(h(c=>{var s,u;const p=(s=a.publication)!=null?s:c.getTrack(a.source);return(u=p==null?void 0:p.isMuted)!=null?u:!0}),d((i=(o=(r=a.publication)==null?void 0:r.isMuted)!=null?o:(t=a.participant.getTrack(a.source))==null?void 0:t.isMuted)!=null?i:!0))}new TextEncoder;new TextDecoder;function q(){return{className:"lk-room-container"}}function m(a,r,t=!0){const i=[a.localParticipant,...Array.from(a.participants.values())],c=[];return i.forEach(s=>{r.forEach(u=>{const p=Array.from(s.tracks.values()).filter(l=>l.source===u&&(!t||l.track)).map(l=>({participant:s,publication:l,source:l.source}));c.push(...p)})}),{trackReferences:c,participants:i}}function z(a,r,t){var o,i;const c=(o=t.additionalRoomEvents)!=null?o:L,s=(i=t.onlySubscribed)!=null?i:!0,u=Array.from(new Set([n.ParticipantConnected,n.ParticipantDisconnected,n.ConnectionStateChanged,n.LocalTrackPublished,n.LocalTrackUnpublished,n.TrackPublished,n.TrackUnpublished,n.TrackSubscriptionStatusChanged,...c]).values());return $(a,...u).pipe(h(l=>{const T=m(l,r,s);return g.debug(`TrackReference[] was updated. (length ${T.trackReferences.length})`,T),T}),d(m(a,r,s)))}export{j as a,q as b,_ as c,F as d,f as g,B as i,g as l,K as m,x as o,Q as s,z as t};
