UNPKG

@aigamo/nostalgic-diva

Version:

React function components for imperatively controlling embedded players (audio, Niconico, SoundCloud and YouTube) using refs.

1 lines 2.36 kB
{"version":3,"file":"SoundCloudPlayer-CyoHSGVd.cjs","sources":["../src/components/SoundCloudPlayer.tsx"],"sourcesContent":["import React, { ReactElement, memo, useCallback } from 'react';\n\nimport { LogLevel } from '../controllers/Logger';\nimport { SoundCloudPlayerController } from '../controllers/SoundCloudPlayerController';\nimport { ensureScriptLoaded } from '../controllers/ensureScriptLoaded';\nimport { PlayerContainer, PlayerProps } from './PlayerContainer';\n\nconst SoundCloudPlayer = memo(({ ...props }: PlayerProps): ReactElement => {\n\tconst { logger } = props;\n\n\tlogger.log(LogLevel.Debug, 'SoundCloudPlayer');\n\n\tconst loadScript = useCallback(async () => {\n\t\tawait ensureScriptLoaded(\n\t\t\t'https://w.soundcloud.com/player/api.js',\n\t\t\tlogger,\n\t\t);\n\t}, [logger]);\n\n\tconst playerFactory = useCallback(\n\t\t(element: HTMLIFrameElement): Promise<SC.SoundCloudWidget> => {\n\t\t\treturn Promise.resolve(SC.Widget(element));\n\t\t},\n\t\t[],\n\t);\n\n\treturn (\n\t\t<PlayerContainer\n\t\t\t{...props}\n\t\t\tloadScript={loadScript}\n\t\t\tplayerFactory={playerFactory}\n\t\t\tcontrollerFactory={SoundCloudPlayerController}\n\t\t>\n\t\t\t{(elementRef, videoId): ReactElement => (\n\t\t\t\t// eslint-disable-next-line jsx-a11y/iframe-has-title\n\t\t\t\t<iframe\n\t\t\t\t\tref={elementRef}\n\t\t\t\t\tsrc={`https://w.soundcloud.com/player/?url=${videoId}`}\n\t\t\t\t\tframeBorder={0}\n\t\t\t\t\tallow=\"autoplay\"\n\t\t\t\t\tstyle={{ width: '100%', height: '100%' }}\n\t\t\t\t/>\n\t\t\t)}\n\t\t</PlayerContainer>\n\t);\n});\n\nexport default SoundCloudPlayer;\n"],"names":["SoundCloudPlayer","memo","props","logger","LogLevel","loadScript","useCallback","ensureScriptLoaded","playerFactory","element","React","PlayerContainer","SoundCloudPlayerController","elementRef","videoId"],"mappings":"sOAOMA,EAAmBC,EAAAA,KAAK,CAAC,CAAE,GAAGC,KAAuC,CAC1E,KAAM,CAAE,OAAAC,GAAWD,EAEnBC,EAAO,IAAIC,WAAS,MAAO,kBAAkB,EAE7C,MAAMC,EAAaC,EAAAA,YAAY,SAAY,CAC1C,MAAMC,EAAAA,mBACL,yCACAJ,CAAA,CAEF,EAAG,CAACA,CAAM,CAAC,EAELK,EAAgBF,EAAAA,YACpBG,GACO,QAAQ,QAAQ,GAAG,OAAOA,CAAO,CAAC,EAE1C,CAAA,CAAC,EAGF,OACCC,EAAA,cAACC,EAAAA,gBAAA,CACC,GAAGT,EACJ,WAAAG,EACA,cAAAG,EACA,kBAAmBI,EAAAA,0BAAA,EAElB,CAACC,EAAYC,IAEbJ,EAAA,cAAC,SAAA,CACA,IAAKG,EACL,IAAK,wCAAwCC,CAAO,GACpD,YAAa,EACb,MAAM,WACN,MAAO,CAAE,MAAO,OAAQ,OAAQ,MAAA,CAAO,CAAA,CACxC,CAIJ,CAAC"}