import { PlayerApiClient, PlayerInfo } from '../../clients/player'; import { ApiEndpoints, Env, HostEnv, BundleEndpoints } from '../../types'; import '@pie-framework/pie-player-components'; import { EventEmitter } from '../../stencil-public-runtime'; import { NewRelicInstrumentationService } from '../../clients/new-relic'; export declare class PieApiPlayer { playerClient: PlayerApiClient; playerInfo: PlayerInfo; player: HTMLPiePlayerElement; initialized: boolean; newRelic: NewRelicInstrumentationService; private debouncedSaveSession; private releasePageLifecycleCommit; private persistedSessionSignature; private inFlightSessionSignature; el: HTMLElement; /** * Override element versions. * Requires the 'overrides' scope in the token in pie-api * matches the key against the element names and if matching uses the overridden version * if a string it's parsed as a json string */ overrides: string | { [key: string]: string; }; /** * Use the beta controllers for pie-elements */ optimize: boolean; /** * If `recordUserSession` property is set to true, detailed user session data will be sent to New Relic * for troubleshooting purposes. */ recordingStarted: EventEmitter; /** * The player will auto-save response session data when the response is changed by the user. * If it encounters an error saving this response to the item session, this event will be emitted. * The event detail will contain the exception thrown by the attempted save. */ saveSessionError: EventEmitter; /** * pie-api-player listens for `session-changed`events from pie-player and auto-saves the response to pie-api. * This event will be emitted when that request completes successfully. If not a `saveSessionError`event will be emitted. * The event detail will contain the session id of the session that was saved. */ sessionSaved: EventEmitter; /** * Emitted when the model was reloaded, content item query was called with the new content version. */ modelReload: EventEmitter; /** * Emitted when the `pie-api-player` encounters an error in the following cases: * - Loading the item or session. * - Updating the item, session, or token. * - Environment configuration issues. * - Saving session data fails. * * Event detail contains: * - `message`: A high-level description of the error. * - `details`: Detailed error information or stack trace. * * Example usage: * ```javascript * player.addEventListener("api-player-error", (event) => { * console.error("Error from API Player:", event.detail); * }); * ``` */ playerError: EventEmitter; /** * Enable screen recording with New Relic. * Note: not to be used in production unless for temporary use to track down a specific user problem. * Defaults to false */ recordScreen: boolean; /** * If screen recording enabled for debug purposes, use this property to provide a unique identifer for * the user whose session is being recorded. */ recordScreenIdentity: string; /** * Enable exception tracking with New Relic. */ exceptions: boolean; /** * Enable tracking page actions/events with New Relic. * Note: Setting this to true increases data sent to New Relic, which may affect costs. */ trackPageActions: boolean; /** * In evaluate mode, add a bottom border to visually separate each item in the case of a multi-item */ showBottomBorder: boolean; /** * The mode to be used when player is initialized */ initialMode: string; /** * The role to be used when player is initialized */ initialRole: string; /** * A JWT token to authorize requests on behalf of the player. * This token for accessing pie-api can be generated with a valid Api Client Id and Secret. */ token: string; /** * The identifier for the related assignment. * This is only used when loading by itemId. */ assignmentId: string; /** * The identifier for the content to load. * The player will immediately load the content when this property is set. */ itemId: string; /** * If provided, will load the assessment session identified by the id. * An assessment session is the record of a student's interaction with the item. * The player will immediately load the assessment session when this property is set. */ sessionId?: string; /** * The current environment context in which to render the player. See notes. */ env?: Env; /** * If the item contains a passage, the player will render it by default. * Set this property to false to not render passage. */ renderStimulus: boolean; /** * It will allow to resize passage and item width for items with stimulus */ allowedResize?: boolean; /** * Provide custom endpoints for the player components. Can be proxy or direct. */ bundleEndpoints?: BundleEndpoints; /** * Choose 'dev' , 'stage' or 'prod' environments for back end. */ host?: HostEnv; _apiConfig: ApiEndpoints; /** * used to automatically re-fetch the bundle (in case we get a 503); defaults to false */ reFetchBundle?: boolean; /** * Maximum number of retry attempts for failed requests. * Does not include the initial request attempt. * Default: 2 */ maxRetryAttempts?: number; /** * Maximum time in milliseconds to wait for a response before aborting the request. * Used to prevent requests from hanging indefinitely in poor network conditions. * Default: 10000 (10 seconds) */ requestTimeoutMs?: number; /** * Initial delay in milliseconds before the first retry attempt. * This value is used as the base for exponential backoff calculation. * Default: 500 (0.5 seconds) */ initialRetryDelayMs?: number; /** * Maximum delay in milliseconds between retry attempts. * Caps the exponential backoff to prevent excessively long waits. * Default: 2000 (2 seconds) */ maxRetryDelayMs?: number; /** * Support styling with external stylesheet urls (comma separated urls) * Target the pie-player component using the class provided in the class property * Parse the css file and add the class to the stylesheet to scope the styles * The last stylesheet url takes priority if the selectors have the same specificity. */ externalStyleUrls: string; customClassname?: string; watchHostEnvironment(newVal: any): void; /** * Customize any of the api endpoint fields. */ customConfig: ApiEndpoints; onCustomConfigChange(newValue: any): void; /** * Customize model. */ customModels?: any[]; /** * Customize passage models. */ customPassageModels?: any[]; /** * Customize markup. */ customMarkup?: string; onCustomModelsChange(newValue: any): void; onCustomPassageModelsChange(newValue: any): void; onCustomMarkupChange(newValue: any): void; private get safeConfig(); /** * If this property is set the item will be rendered in a `preview` state by the player. * This means no server-side calls will be made and no reponse-session will be created/stored in pie-api. */ preview: boolean; errorMessage: string; /** * Emitted when an item has loaded with a sessionId that was not specified on load. * The event detail contains the generated session id and data. * * `event.detail === {id: session_id, data:[session_data]}` */ sessionCreated: EventEmitter; /** * Get the retry configuration from component properties */ private getRetryConfig; initPlayerClient(): void; watchToken(): Promise; watchItemId(newValue: any, oldValue: any): Promise; watchRetryConfig(): Promise; watchEnv(newEnv: any): Promise; watchRecordScreen(newVal: any, oldVal: any): void; /** * Return the evaluated score for the current response. * The api token must provide permission to authorize the use of this method. * * Note: Score does not (yet) work when in preview mode - will resolve to null if `preview` is `true` * * @param disablePartialScoring - if true all interactions will be scored as either correct or incorrect */ score(disablePartialScoring?: boolean): Promise; saveSession(): Promise; private currentSessionSignature; private noteSessionPersisted; /** * Save, unless the backend already has this session or is being sent it. * * Every commit seam decides through here. A sweep dispatches once per * delivery element, and each of those events bypasses the debounce, so an * item with two elements used to issue two concurrent saves of the same * whole-item session - the debounce is what used to coalesce them. The * comparison also absorbs a re-commit of a response the host has already * been told about, which an element whose session moves during its own * commit would otherwise produce at every later seam. */ private saveSessionIfChanged; /** * Runs after the sweep has committed, when the page is going away. * * Issued in the lifecycle handler's own task, which is what a hidden * document performs dependably - but this stack's client sends an ordinary * request, so the browser may still drop it when the page goes away. * `keepalive` would need threading through `callApi` and the retry loop's * abort timeout, which is a change for its own PR. Until then the commit is * reliable and the save on that path is best-effort; the next load re-reads * whatever did land. * * The save is decided here as well as flushed, for the same reason teardown * decides rather than waits: a commit's event is not a dependable way to * reach this component. blocks `session-changed` for 150ms * around every model set, and an erasure of a response the element never * announced is not dispatched by the sweep at all - `flush()` covers * neither, because in both cases nothing is pending. */ private onPageHidden; /** * Listens for session changed events and saves updated data for session */ handleSessionChange(ev: CustomEvent): void; handlePlayerError(ev: CustomEvent): void; /** * Helper method to track errors with New Relic * This is a utility method that centralizes our error reporting logic and ensures * we capture comprehensive error information including stack traces. */ private trackError; updateItemOrSession(): Promise; readyToLoad(): string; getOverrides(): { [key: string]: string; } | undefined; componentDidRender(): void; load(): Promise; connectedCallback(): void; componentWillLoad(): Promise; disconnectedCallback(): void; overrideModels(models: any, customModels: any): any; getConfigParsed(item: any, models?: any, passageModels?: any): any; render(): any; }