Integrate the Rutube Iframe player into your Vue 3 app
Here's a README document based on the provided TypeScript types for the Rutube player messaging system. This document includes sections on the usage of each message type, along with examples:
The following types represent the different message types that can be sent to and from the player:
export type PlayerMessageType =
| "init"
| "buffering"
| "ready"
| "changeState"
| "currentTime"
| "play"
| "pause"
| "stop"
| "mute"
| "unMute"
| "setVolume"
| "setCurrentTime"
| "relativelySeek"
| "changeVideo"
| "setSkinColor"
| "remove"
| "error"
| "changeFullscreen"
| "rollState"
| "playComplete"
| "durationChange"
| null;
Each message follows the same base structure defined by the PlayerMessageFabric
interface. Here's the structure:
interface PlayerMessageFabric<T = any, M extends PlayerMessageType = null> {
type: PlayerMessageTypeBuilder<M>;
data: T;
}
- Type:
init
- Data: An empty object.
type InitMessage = PlayerMessageFabric<{}, "init">;
- Type:
ready
- Data: An empty object.
type ReadyMessage = PlayerMessageFabric<{}, "ready">;
- Type:
play
- Data: An empty object.
type PlayMessage = PlayerMessageFabric<{}, "play">;
- Type:
pause
- Data: An empty object.
type PauseMessage = PlayerMessageFabric<{}, "pause">;
- Type:
stop
- Data: An empty object.
type StopMessage = PlayerMessageFabric<{}, "stop">;
- Type:
mute
- Data: An empty object.
type MuteMessage = PlayerMessageFabric<{}, "mute">;
- Type:
unMute
- Data: An empty object.
type UnmuteMessage = PlayerMessageFabric<{}, "unMute">;
- Type:
setVolume
- Data: Contains a
volume
field (0 to 1).
interface VolumeChangeData {
volume: number; // 0 to 1
}
type VolumeChangeMessage = PlayerMessageFabric<VolumeChangeData, "setVolume">;
- Type:
currentTime
- Data: Contains a
time
field in seconds.
interface CurrentTimeData {
time: number; // time in seconds to set
}
type CurrentTimeMessage = PlayerMessageFabric<CurrentTimeData, "currentTime">;
- Type:
changeVideo
- Data: Includes
id
and optional parameters such ashash
,p
(private key), andquality
.
interface ChangeVideoData {
id: string;
params?: {
hash?: string;
p?: string; // private key
quality?: number; // 1 for highest, -2 for lowest
};
}
type ChangeVideoMessage = PlayerMessageFabric<ChangeVideoData, "changeVideo">;
- Type:
relativelySeek
- Data: Contains
time
in seconds to seek.
interface RelativelySeekData {
time: number; // seconds to seek
}
type RelativelySeekMessage = PlayerMessageFabric<RelativelySeekData, "relativelySeek">;
- Type:
changeFullscreen
- Data: Contains
isFullscreen
(true or false).
interface ChangeFullscreenData {
isFullscreen: boolean; // true or false
}
type ChangeFullscreenMessage = PlayerMessageFabric<ChangeFullscreenData, "changeFullscreen">;
- Type:
error
- Data: Contains an error code and text.
interface ErrorData {
code: string; // error code
text: string; // error message
}
type ErrorMessage = PlayerMessageFabric<ErrorData, "error">;
- Type:
rollState
- Data: Contains
rollState
,state
, andguid
.
interface RollStateData {
rollState: "preRoll" | "pauseBanner" | "postRoll" | "midRoll" | "pauseRoll" | "overlay";
state: "play" | "complete";
guid: string;
}
type RollStateMessage = PlayerMessageFabric<RollStateData, "rollState">;
- Type:
durationChange
- Data: Contains the duration of the video in seconds.
interface DurationChangeData {
duration: number; // duration in seconds
}
type DurationChangeMessage = PlayerMessageFabric<DurationChangeData, "durationChange">;
- Type:
changeState
- Data: Contains the new state and whether it's licensed.
export type ChangeState = "playing" | "paused" | "stopped" | "lockScreenOn" | "lockScreenOff";
interface ChangeStateData {
state: ChangeState;
isLicensed: boolean;
}
type ChangeStateMessage = PlayerMessageFabric<ChangeStateData, "changeState">;
These message types are meant to facilitate communication with the Rutube player. When sending a message, ensure that you format the data
field according to the specific type you've chosen. Here's an example of sending a play message:
const playMessage: PlayMessage = {
type: "player:play",
data: {}
};
// Send the message to the player
player.postMessage(JSON.stringify(playMessage), '*');
Customize the implementation according to your project's requirements, ensuring that you handle responses appropriately.
Feel free to adjust any sections to better match your project's style or details!