MCPcopy Create free account
hub / github.com/dailydotdev/apps / loadExcoPlayer

Function loadExcoPlayer

packages/shared/src/features/monetization/exco.ts:145–182  ·  view source on GitHub ↗
(
  playerId: string,
)

Source from the content-addressed store, hash-verified

143};
144
145export const loadExcoPlayer = (
146 playerId: string,
147): Promise<ExcoPlayerRegistry> => {
148 const cached = registries.get(playerId);
149
150 if (cached) {
151 return cached;
152 }
153
154 const registry = new Promise<void>((resolve, reject) => {
155 const script = document.createElement('script');
156 script.className = 'exco-player';
157 script.src = getExcoPlayerScriptSrc(playerId);
158 script.async = true;
159 script.setAttribute('programmatic', 'true');
160 script.setAttribute('multiple', 'true');
161 script.addEventListener('load', () => resolve());
162 script.addEventListener('error', () =>
163 reject(new Error('Failed to load the EX.CO player')),
164 );
165 document.head.appendChild(script);
166 })
167 .then(() => {
168 if (!window.ExCoPlayer) {
169 throw new Error('The EX.CO player script defined no API');
170 }
171
172 return window.ExCoPlayer.connect(playerId);
173 })
174 .catch((error) => {
175 setExcoPlayerBlocked(playerId);
176 throw error;
177 });
178
179 registries.set(playerId, registry);
180
181 return registry;
182};

Callers 1

setupFunction · 0.90

Calls 3

getExcoPlayerScriptSrcFunction · 0.85
setExcoPlayerBlockedFunction · 0.85
connectMethod · 0.80

Tested by

no test coverage detected