Skip to content

Commit

Permalink
feat: add video size for events payload (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuJianghao authored Mar 27, 2023
1 parent 6936fc9 commit 93506b9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/griffith-message/README-zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ dispatchMessage(target: Window, name: ACTIONS, data?: object): void
| ------------- | --------------------------------------------------------- | -------------------------------------------------- |
| `currentTime` | `number` | 当前时间 |
| `duration` | `number` | 视频总时长 |
| `videoWidth` | `number` | 视频宽度 |
| `videoHeight` | `number` | 视频高度 |
| `error` | `{code: number, message: string, name: stirng}``null` | [`HTMLMediaElement.error`][htmlmediaelement-error] |
[htmlmediaelement-error]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/error 'HTMLMediaElement.error'
Expand Down
2 changes: 2 additions & 0 deletions packages/griffith-message/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Events received from the player
| ------------- | --------------------------------------------------------- | -------------------------------------------------- |
| `currentTime` | `number` | Current time |
| `duration` | `number` | Total video duration |
| `videoWidth` | `number` | Video Width |
| `videoHeight` | `number` | Video Height |
| `error` | `{code: number, message: string, name: stirng}` or `null` | [`HTMLMediaElement.error`][htmlmediaelement-error] |
[htmlmediaelement-error]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/error 'HTMLMediaElement.error'
Expand Down
4 changes: 3 additions & 1 deletion packages/griffith-message/src/constants/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ export const EVENTS = {

export type EVENTS = DOM | PLAYER

type DOMEventParams = {
export type DOMEventParams = {
currentTime: number
duration: number
videoWidth: number
videoHeight: number
error: {code: number; message: string; name: string} | null
}

Expand Down
8 changes: 6 additions & 2 deletions packages/griffith/src/components/VideoWithMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {useCallback, useContext, useEffect, useMemo, useRef} from 'react'
import {EVENTS} from 'griffith-message'
import type {DOMEventParams} from 'griffith-message'
import {InternalMessageContext} from '../contexts/MessageContext'
import ObjectFitContext from '../contexts/ObjectFitContext'
import PositionContext from '../contexts/PositionContext'
Expand Down Expand Up @@ -28,11 +29,14 @@ function serializeDOMException(exception?: MediaError | null) {
return {code, message, name: (exception as any).name}
}

function getMediaEventPayload(event: VideoEvent) {
const {currentTime, duration, error} = event.currentTarget as HTMLVideoElement
function getMediaEventPayload(event: VideoEvent): DOMEventParams {
const {currentTime, duration, error, videoWidth, videoHeight} =
event.currentTarget as HTMLVideoElement
return {
currentTime,
duration,
videoWidth,
videoHeight,
error: serializeDOMException(error),
}
}
Expand Down

0 comments on commit 93506b9

Please sign in to comment.