22// TODO: figure out member access types and remove the line above
33
44import { captureException } from '@sentry/core' ;
5- import type { ReplayRecordingData } from '@sentry/types' ;
65import { logger } from '@sentry/utils' ;
76
8- import type { EventBuffer , RecordingEvent , WorkerRequest , WorkerResponse } from './types' ;
7+ import type { AddEventResult , EventBuffer , RecordingEvent , WorkerRequest } from './types' ;
98import workerString from './worker/worker.js' ;
109
1110interface CreateEventBufferParams {
@@ -54,13 +53,14 @@ class EventBufferArray implements EventBuffer {
5453 this . _events = [ ] ;
5554 }
5655
57- public addEvent ( event : RecordingEvent , isCheckout ?: boolean ) : void {
56+ public async addEvent ( event : RecordingEvent , isCheckout ?: boolean ) : Promise < AddEventResult > {
5857 if ( isCheckout ) {
5958 this . _events = [ event ] ;
6059 return ;
6160 }
6261
6362 this . _events . push ( event ) ;
63+ return ;
6464 }
6565
6666 public finish ( ) : Promise < string > {
@@ -107,8 +107,10 @@ export class EventBufferCompressionWorker implements EventBuffer {
107107
108108 /**
109109 * Add an event to the event buffer.
110+ *
111+ * Returns true if event was successfuly received and processed by worker.
110112 */
111- public async addEvent ( event : RecordingEvent , isCheckout ?: boolean ) : Promise < ReplayRecordingData > {
113+ public async addEvent ( event : RecordingEvent , isCheckout ?: boolean ) : Promise < AddEventResult > {
112114 if ( isCheckout ) {
113115 // This event is a checkout, make sure worker buffer is cleared before
114116 // proceeding.
@@ -132,7 +134,7 @@ export class EventBufferCompressionWorker implements EventBuffer {
132134 /**
133135 * Post message to worker and wait for response before resolving promise.
134136 */
135- private _postMessage ( { id, method, args } : WorkerRequest ) : Promise < WorkerResponse [ 'response' ] > {
137+ private _postMessage < T > ( { id, method, args } : WorkerRequest ) : Promise < T > {
136138 return new Promise ( ( resolve , reject ) => {
137139 // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
138140 const listener = ( { data } : MessageEvent ) => {
@@ -178,8 +180,8 @@ export class EventBufferCompressionWorker implements EventBuffer {
178180 /**
179181 * Send the event to the worker.
180182 */
181- private _sendEventToWorker ( event : RecordingEvent ) : Promise < ReplayRecordingData > {
182- const promise = this . _postMessage ( {
183+ private async _sendEventToWorker ( event : RecordingEvent ) : Promise < AddEventResult > {
184+ const promise = this . _postMessage < void > ( {
183185 id : this . _getAndIncrementId ( ) ,
184186 method : 'addEvent' ,
185187 args : [ event ] ,
@@ -195,12 +197,12 @@ export class EventBufferCompressionWorker implements EventBuffer {
195197 * Finish the request and return the compressed data from the worker.
196198 */
197199 private async _finishRequest ( id : number ) : Promise < Uint8Array > {
198- const promise = this . _postMessage ( { id, method : 'finish' , args : [ ] } ) ;
200+ const promise = this . _postMessage < Uint8Array > ( { id, method : 'finish' , args : [ ] } ) ;
199201
200202 // XXX: See note in `get length()`
201203 this . _eventBufferItemLength = 0 ;
202204
203- return promise as Promise < Uint8Array > ;
205+ return promise ;
204206 }
205207
206208 /** Get the current ID and increment it for the next call. */
0 commit comments