@aigamo/nostalgic-diva 1.3.0
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/LICENSE +22 -0
- package/README.md +125 -0
- package/dist/components/AudioPlayer.d.ts +3 -0
- package/dist/components/NiconicoPlayer.d.ts +3 -0
- package/dist/components/NostalgicDiva.d.ts +9 -0
- package/dist/components/NostalgicDivaProvider.d.ts +11 -0
- package/dist/components/PlayerContainer.d.ts +16 -0
- package/dist/components/SoundCloudPlayer.d.ts +3 -0
- package/dist/components/VimeoPlayer.d.ts +3 -0
- package/dist/components/YouTubePlayer.d.ts +3 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/useFirstMountState.d.ts +1 -0
- package/dist/components/usePreviousDistinct.d.ts +2 -0
- package/dist/global.d.ts +757 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +802 -0
- package/dist/index.es.js.map +1 -0
- package/dist/players/AudioPlayerApi.d.ts +17 -0
- package/dist/players/NiconicoPlayerApi.d.ts +27 -0
- package/dist/players/PlayerApi.d.ts +58 -0
- package/dist/players/PlayerApiImpl.d.ts +18 -0
- package/dist/players/PlayerConsole.d.ts +8 -0
- package/dist/players/SoundCloudPlayerApi.d.ts +20 -0
- package/dist/players/VimeoPlayerApi.d.ts +17 -0
- package/dist/players/YouTubePlayerApi.d.ts +28 -0
- package/dist/players/ensureScriptLoaded.d.ts +1 -0
- package/dist/players/getScript.d.ts +1 -0
- package/dist/players/index.d.ts +6 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 VocaDB Devgroup
|
|
4
|
+
Copyright (c) 2023 Aigamo
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Nostalgic Diva
|
|
2
|
+
|
|
3
|
+
React function components for imperatively controlling embedded players (audio, [Niconico](https://www.nicovideo.jp/), [SoundCloud](https://soundcloud.com/), [Vimeo](https://vimeo.com/) and [YouTube](https://www.youtube.com/)) using refs.
|
|
4
|
+
|
|
5
|
+
This was originally developed in [VocaDB/vocadb#1101](https://github.com/VocaDB/vocadb/pull/1101) as a part of VocaDB.
|
|
6
|
+
|
|
7
|
+
NOTE: This is an independent fork of VocaDB/route-sphere.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
`yarn add @aigamo/nostalgic-diva` or `npm i @aigamo/nostalgic-diva`
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import {
|
|
17
|
+
NostalgicDiva,
|
|
18
|
+
NostalgicDivaProvider,
|
|
19
|
+
PlayerOptions,
|
|
20
|
+
} from '@aigamo/nostalgic-diva';
|
|
21
|
+
|
|
22
|
+
// Callbacks
|
|
23
|
+
const handleError = React.useCallback(() => {}, []);
|
|
24
|
+
const handlePlay = React.useCallback(() => {}, []);
|
|
25
|
+
const handlePause = React.useCallback(() => {}, []);
|
|
26
|
+
const handleEnded = React.useCallback(() => {}, []);
|
|
27
|
+
const handleTimeUpdate = React.useCallback(() => {}, []);
|
|
28
|
+
|
|
29
|
+
// Options
|
|
30
|
+
const options = React.useMemo(
|
|
31
|
+
(): PlayerOptions => ({
|
|
32
|
+
onError: handleError,
|
|
33
|
+
onPlay: handlePlay,
|
|
34
|
+
onPause: handlePause,
|
|
35
|
+
onEnded: handleEnded,
|
|
36
|
+
onTimeUpdate: handleTimeUpdate,
|
|
37
|
+
}),
|
|
38
|
+
[handleError, handlePlay, handlePause, handleEnded, handleTimeUpdate],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
<NostalgicDivaProvider>
|
|
42
|
+
<NostalgicDiva
|
|
43
|
+
// Supported media types:
|
|
44
|
+
// - "Audio"
|
|
45
|
+
// - "Niconico"
|
|
46
|
+
// - "SoundCloud"
|
|
47
|
+
// - "Vimeo"
|
|
48
|
+
// - "YouTube"
|
|
49
|
+
type="Audio"
|
|
50
|
+
videoId={videoId}
|
|
51
|
+
options={options}
|
|
52
|
+
/>
|
|
53
|
+
;
|
|
54
|
+
</NostalgicDivaProvider>;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { useNostalgicDiva } from '@aigamo/nostalgic-diva';
|
|
59
|
+
|
|
60
|
+
const diva = useNostalgicDiva();
|
|
61
|
+
|
|
62
|
+
// Play
|
|
63
|
+
await diva.play();
|
|
64
|
+
|
|
65
|
+
// Pause
|
|
66
|
+
await diva.pause();
|
|
67
|
+
|
|
68
|
+
// Mute
|
|
69
|
+
await diva.setMuted(true);
|
|
70
|
+
|
|
71
|
+
// Unmute
|
|
72
|
+
await diva.setMuted(false);
|
|
73
|
+
|
|
74
|
+
// Seek
|
|
75
|
+
await diva.setCurrentTime(seconds);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Imperative functions
|
|
79
|
+
|
|
80
|
+
| Function | Description |
|
|
81
|
+
| ------------------------------------------------ | ------------------------------------------------------------------- |
|
|
82
|
+
| `loadVideo(id: string): Promise<void>` | Loads a new video into an existing player. |
|
|
83
|
+
| `play(): Promise<void>` | Plays a video. |
|
|
84
|
+
| `pause(): Promise<void>` | Pauses the playback of a video. |
|
|
85
|
+
| `setCurrentTime(seconds: number): Promise<void>` | Sets the current playback position in seconds. |
|
|
86
|
+
| `setVolume(volume: number): Promise<void>` | Sets the volume level of the player on a scale from 0 to 1. |
|
|
87
|
+
| `setMuted(muted: boolean): Promise<void>` | Sets the muted state of the player. |
|
|
88
|
+
| `getDuration(): Promise<number \| undefined>` | Gets the duration of the video in seconds. |
|
|
89
|
+
| `getCurrentTime(): Promise<number \| undefined>` | Gets the current playback position of a video, measured in seconds. |
|
|
90
|
+
|
|
91
|
+
## Events
|
|
92
|
+
|
|
93
|
+
| Event | Description |
|
|
94
|
+
| -------------------------------------- | ------------------------------------------------------ |
|
|
95
|
+
| `onError(event: any): void` | Fired when the player experiences some sort of error. |
|
|
96
|
+
| `onPlay(): void` | Fired when the video plays. |
|
|
97
|
+
| `onPause(): void` | Fired when the video is paused. |
|
|
98
|
+
| `onEnded(): void` | Fired when playback reaches the end of a video. |
|
|
99
|
+
| `onTimeUpdate(event: TimeEvent): void` | Fired when the playback position of the video changes. |
|
|
100
|
+
|
|
101
|
+
## Lifecycle
|
|
102
|
+
|
|
103
|
+
1. [PlayerApi.attach](https://github.com/ycanardeau/nostalgic-diva/blob/5cc35c68cf71230f9459804a9dd9e9265cfa2297/src/players/PlayerApi.ts#L84)
|
|
104
|
+
1. [IPlayerApi.loadVideo](https://github.com/ycanardeau/nostalgic-diva/blob/5cc35c68cf71230f9459804a9dd9e9265cfa2297/src/players/PlayerApi.ts#L33)
|
|
105
|
+
1. [PlayerOptions.onLoaded](https://github.com/ycanardeau/nostalgic-diva/blob/5cc35c68cf71230f9459804a9dd9e9265cfa2297/src/players/PlayerApi.ts#L25)
|
|
106
|
+
1. [IPlayerApi.play](https://github.com/ycanardeau/nostalgic-diva/blob/5cc35c68cf71230f9459804a9dd9e9265cfa2297/src/players/PlayerApi.ts#L34)
|
|
107
|
+
1. [PlayerOptions.onPlay](https://github.com/ycanardeau/nostalgic-diva/blob/5cc35c68cf71230f9459804a9dd9e9265cfa2297/src/players/PlayerApi.ts#L26)
|
|
108
|
+
1. [PlayerOptions.onTimeUpdate](https://github.com/ycanardeau/nostalgic-diva/blob/5cc35c68cf71230f9459804a9dd9e9265cfa2297/src/players/PlayerApi.ts#L29)
|
|
109
|
+
1. [IPlayerApi.pause](https://github.com/ycanardeau/nostalgic-diva/blob/5cc35c68cf71230f9459804a9dd9e9265cfa2297/src/players/PlayerApi.ts#L35)
|
|
110
|
+
1. [PlayerOptions.onPause](https://github.com/ycanardeau/nostalgic-diva/blob/5cc35c68cf71230f9459804a9dd9e9265cfa2297/src/players/PlayerApi.ts#L27)
|
|
111
|
+
1. [PlayerOptions.onEnded](https://github.com/ycanardeau/nostalgic-diva/blob/5cc35c68cf71230f9459804a9dd9e9265cfa2297/src/players/PlayerApi.ts#L28)
|
|
112
|
+
1. [PlayerApi.detach](https://github.com/ycanardeau/nostalgic-diva/blob/5cc35c68cf71230f9459804a9dd9e9265cfa2297/src/players/PlayerApi.ts#L111)
|
|
113
|
+
|
|
114
|
+
The `attach` function is called when switching from another player (Audio, Niconico, SoundCloud and YouTube), and the `detach` function is called when switching to another player. After the `detach` function is called, you cannot use any imperative functions like `loadVideo`, `play`, `pause` and etc.
|
|
115
|
+
|
|
116
|
+
## References
|
|
117
|
+
|
|
118
|
+
- [vocadb/VocaDbWeb/Scripts/ViewModels/PVs/](https://github.com/VocaDB/vocadb/tree/5304e764cf423f07b424e94266e415db40d11f28/VocaDbWeb/Scripts/ViewModels/PVs)
|
|
119
|
+
- [React Player](https://github.com/cookpete/react-player)
|
|
120
|
+
- [ニコニコ動画の HTML5 外部プレイヤーを JavaScript で操作する](https://blog.hayu.io/web/create/nicovideo-embed-player-api/)
|
|
121
|
+
- [Widget API - SoundCloud Developers](https://developers.soundcloud.com/docs/api/html5-widget)
|
|
122
|
+
- [Player SDK: Reference - Vimeo Developer](https://developer.vimeo.com/player/sdk/reference)
|
|
123
|
+
- [YouTube Player API Reference for iframe Embeds | YouTube IFrame Player API | Google Developers](https://developers.google.com/youtube/iframe_api_reference)
|
|
124
|
+
- [How to support Reusable State in Effects · Discussion #18 · reactwg/react-18](https://github.com/reactwg/react-18/discussions/18)
|
|
125
|
+
- [Synchronizing with Effects](https://beta.reactjs.org/learn/synchronizing-with-effects#how-to-handle-the-effect-firing-twice-in-development)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PlayerOptions, PlayerType } from '../players/PlayerApi';
|
|
3
|
+
interface NostalgicDivaProps {
|
|
4
|
+
type: PlayerType;
|
|
5
|
+
videoId: string;
|
|
6
|
+
options?: PlayerOptions;
|
|
7
|
+
}
|
|
8
|
+
export declare const NostalgicDiva: React.MemoExoticComponent<({ type, videoId, options }: NostalgicDivaProps) => React.ReactElement>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IPlayerApi } from '../players';
|
|
3
|
+
interface NostalgicDivaContextProps extends IPlayerApi {
|
|
4
|
+
playerApiRef: React.MutableRefObject<IPlayerApi | undefined>;
|
|
5
|
+
}
|
|
6
|
+
interface NostalgicDivaProviderProps {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare const NostalgicDivaProvider: ({ children, }: NostalgicDivaProviderProps) => React.ReactElement;
|
|
10
|
+
export declare const useNostalgicDiva: () => NostalgicDivaContextProps;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IPlayerApi, Logger, PlayerOptions, PlayerType } from '../players/PlayerApi';
|
|
3
|
+
import { PlayerApiImpl } from '../players/PlayerApiImpl';
|
|
4
|
+
export interface PlayerProps {
|
|
5
|
+
type: PlayerType;
|
|
6
|
+
playerApiRef: React.MutableRefObject<IPlayerApi | undefined> | undefined;
|
|
7
|
+
videoId: string;
|
|
8
|
+
options: PlayerOptions | undefined;
|
|
9
|
+
}
|
|
10
|
+
interface PlayerContainerProps<TElement extends HTMLElement, TPlayer extends PlayerApiImpl<TElement>> extends PlayerProps {
|
|
11
|
+
loadScript: (() => Promise<void>) | undefined;
|
|
12
|
+
playerApiFactory: new (logger: Logger, playerElementRef: React.MutableRefObject<TElement>, options: PlayerOptions | undefined) => TPlayer;
|
|
13
|
+
children: (playerElementRef: React.MutableRefObject<TElement>, videoId: string) => React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
export declare const PlayerContainer: <TElement extends HTMLElement, TPlayer extends PlayerApiImpl<TElement>>({ type, playerApiRef, videoId, options, loadScript, playerApiFactory, children, }: PlayerContainerProps<TElement, TPlayer>) => React.ReactElement<PlayerContainerProps<TElement, TPlayer>, string | React.JSXElementConstructor<any>>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useFirstMountState(): boolean;
|