Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FEC-13719): [Transcript Plugins]: Add Events (used by kava analytics) #180

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/transcript/transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {TranscriptMenu} from '../transcript-menu';
import {SmallScreenSlate} from '../small-screen-slate';
import {Button, ButtonType, ButtonSize} from '@playkit-js/common/dist/components/button';
import {OnClickEvent, OnClick} from '@playkit-js/common/dist/hoc/a11y-wrapper';
import { TranscriptEvents } from "../../events";

const {ENTER, SPACE, TAB} = ui.utils.KeyMap;
const {withText, Text} = ui.preacti18n;
Expand Down Expand Up @@ -52,6 +53,7 @@ export interface TranscriptProps {
onPrint: () => void;
smallScreen?: boolean;
expandMode?: string;
dispatcher: (name: string, payload?: any) => void;
}

interface TranscriptState {
Expand Down Expand Up @@ -168,6 +170,7 @@ export class Transcript extends Component<TranscriptProps, TranscriptState> {
searchMap[caption.id] = {...searchMap[caption.id], [index]: i};
});
});
this.props.dispatcher(TranscriptEvents.TRANSCRIPT_SEARCH, {search: state.search});
return {
searchMap,
totalSearchResults: index,
Expand All @@ -183,6 +186,7 @@ export class Transcript extends Component<TranscriptProps, TranscriptState> {
activeSearchIndex: index,
isAutoScrollEnabled: false
});
this.props.dispatcher(TranscriptEvents.TRANSCRIPT_NAVIGATE_RESULT, {index});
};

private _getHeaderStyles = (): string => {
Expand Down
9 changes: 9 additions & 0 deletions src/events/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

export const TranscriptEvents = {
TRANSCRIPT_OPEN: 'transcript_open',
TRANSCRIPT_CLOSE: 'transcript_close',
TRANSCRIPT_DOWNLOAD: 'transcript_download',
TRANSCRIPT_PRINT: 'transcript_print',
TRANSCRIPT_SEARCH: 'transcript_search',
TRANSCRIPT_NAVIGATE_RESULT: 'transcript_navigate_result',
};
1 change: 1 addition & 0 deletions src/events/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {TranscriptEvents} from './events';
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare var __NAME__: string;
const VERSION = __VERSION__;
const NAME = __NAME__;

export { TranscriptEvents} from './events'
export {TranscriptPlugin as Plugin};
export {VERSION, NAME};

Expand Down
6 changes: 6 additions & 0 deletions src/transcript-plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {PluginButton} from './components/plugin-button/plugin-button';
import {Transcript} from './components/transcript';
import {getConfigValue, isBoolean, makePlainText, prepareCuePoint} from './utils';
import {TranscriptConfig, PluginStates, HighlightedMap, CuePointData, ItemTypes, CuePoint} from './types';
import { TranscriptEvents } from "./events";

export const pluginName: string = 'playkit-js-transcript';

Expand Down Expand Up @@ -177,13 +178,15 @@ export class TranscriptPlugin extends KalturaPlayer.core.BasePlugin {
this.sidePanelsManager?.activateItem(this._transcriptPanel);
this._pluginState = PluginStates.OPENED;
this.upperBarManager?.update(this._transcriptIcon);
this.dispatchEvent(TranscriptEvents.TRANSCRIPT_OPEN, {auto: this.config.expandOnFirstPlay});
});
};

private _deactivatePlugin = () => {
this.ready.then(() => {
this.sidePanelsManager?.deactivateItem(this._transcriptPanel);
this.upperBarManager?.update(this._transcriptIcon);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we deactivated the plugin, should we not set the state to this._pluginState = PluginStates.CLOSED ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that you are right, i guess @semarche-kaltura is most familiar with this plugin
anyway from experience... we rather not touch things unrelated directly to the original ticket

this.dispatchEvent(TranscriptEvents.TRANSCRIPT_CLOSE);
});
};

Expand Down Expand Up @@ -257,6 +260,7 @@ export class TranscriptPlugin extends KalturaPlayer.core.BasePlugin {
onDownload={this._handleDownload}
printDisabled={getConfigValue(printDisabled, isBoolean, false)}
onPrint={this._handlePrint}
dispatcher={(eventType, payload) => this.dispatchEvent(eventType, payload)}
/> as any
);
},
Expand Down Expand Up @@ -316,13 +320,15 @@ export class TranscriptPlugin extends KalturaPlayer.core.BasePlugin {

downloadContent(makePlainText(captions), `${language}${entryMetadata.name ? `-${entryMetadata.name}` : ''}.txt`);
}
this.dispatchEvent(TranscriptEvents.TRANSCRIPT_DOWNLOAD, {videoPosition: this.player.currentTime});
};

private _handlePrint = () => {
const captions = this._sanitizeCaptions(this._captionMap.get(this._activeCaptionMapId) || []);
if (captions) {
printContent(makePlainText(captions));
}
this.dispatchEvent(TranscriptEvents.TRANSCRIPT_PRINT, {videoPosition: this.player.currentTime});
};

private _handleClose = (e: OnClickEvent, byKeyboard: boolean) => {
Expand Down
Loading