1.30.0 • Published 1 year ago

griffith-message v1.30.0

Weekly downloads
57
License
MIT
Repository
-
Last release
1 year ago

griffith-message

English | 简体中文

Griffith message communication plugin

Usage

import {EVENTS, ACTIONS, createMessageHelper} from 'griffith-message'

const helper = createMessageHelper()
// register event listener
helper.subscribeMessage(EVENTS.PLAY, (r) => {
  r.currentTime
})
helper.subscribeMessage(EVENTS.QUALITY_CHANGE, (r) => {
  r.quality
})
// dispatch action to player
helper.dispatchMessage(window, ACTIONS.SET_VOLUME, {volume: 0.5})
// dispose all event listeners
helper.dispose()

createMessageHelper

Cross-window communication

createMessageHelper(id?, targetOrigin?, shouldValidateId?)
NameTypeDescription
idstring \| numberUnique identifier, each message will contain this id, the receiver can be used to verify.
targetOriginobjectThe targetOrigin parameter when sending a message. If it is not empty, it will check if the origin of the sent message is the same.
shouldValidateIdbooleanWill check if the id of the incoming message is the same as the id of the first parameter.

subscribeMessage

subscribeMessage(name: EVENTS, (data?: object, source?: MessageEventSource) => void): () => void
NameTypeDescription
nameEVENTSMessage Name
dataobjectMessage attached data
sourceMessageEventSourceMessage Event Source

dispatchMessage

dispatchMessage(target: Window, name: ACTIONS, data?: object): void
NameTypeDescription
targetWindowTarget Window
nameACTIONSMessage Name
dataobjectMessage attached data

EVENTS

Events received from the player

messageNameDescriptiondata
EVENTS.CANPLAYcanplaysee DOM type data table
EVENTS.PLAYPlaysee DOM type data table
EVENTS.PLAYINGResume playback from pause or buffersee DOM type data table
EVENTS.PAUSEPausesee DOM type data table
EVENTS.ENDEDEndedsee DOM type data table
EVENTS.TIMEUPDATETimeupdatesee DOM type data table
EVENTS.ERRORErrorsee DOM type data table
EVENTS.WAITINGBuffersee DOM type data table
EVENTS.REQUEST_PLAYUser starts playbacknull
EVENTS.QUALITY_CHANGEPlay quality switching{quality: string, prevQuality: string}
EVENTS.PLAY_COUNTPlaybacknull
EVENTS.PLAY_FAILEDPlay failed{currentTime: number}
EVENTS.ENTER_FULLSCREENEnter Fullscreennull
EVENTS.EXIT_FULLSCREENExit Fullscreennull
EVENTS.ENTER_PIPEnter Picture in Picturenull
EVENTS.EXIT_PIPExit Picture in Picturenull
EVENTS.SHOW_CONTROLLERShow Controllernull
EVENTS.HIDE_CONTROLLERHide Controllernull
EVENTS.HOVER_PROGRESS_DOTMouse hover progress dot{startTime: number, left: number, top: number}
EVENTS.LEAVE_PROGRESS_DOTMouse leave progress dotnull
EVENTS.SUBSCRIPTION_READYAction subscription readyvoid

DOM type data

NameTypeDescription
currentTimenumberCurrent time
durationnumberTotal video duration
videoWidthnumberVideo Width
videoHeightnumberVideo Height
error{code: number, message: string, name: stirng} or nullHTMLMediaElement.error

ACTIONS

Actions sent to the player

messageNameDescriptiondata
ACTIONS.PLAYPlayvoid
ACTIONS.PAUSEPause{dontApplyOnFullScreen: boolean} Whether to apply to full screen video
ACTIONS.SET_VOLUMESet the volume{volume: number} Volume value from 0 to 1
ACTIONS.ENTER_FULLSCREENEnter fullScreenvoid
ACTIONS.EXIT_FULLSCREENExit fullscreenvoid
ACTIONS.TIME_UPDATESet current time{currentTime: number} Set the current playback time
ACTIONS.SHOW_CONTROLLERShow Controllervoid
1.30.0

1 year ago

1.27.1

2 years ago

1.25.0

2 years ago

1.21.0

3 years ago

1.18.0

3 years ago

1.17.0

3 years ago

1.16.0

3 years ago

1.15.0

3 years ago

1.14.0

3 years ago

1.11.0

3 years ago

1.10.0

3 years ago

1.9.0

4 years ago

1.6.0

4 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.2.1

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.2.0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.0.0

5 years ago

1.1.0

5 years ago