blob: 197890f6ac6b0859f1fa8a3afeed1645f4c5516c [file] [log] [blame]
import { ProtobufObject } from '../../common/protojs.types';
import {
Interceptor,
InterceptorFilter,
InterceptorHandlerPort,
} from './InterceptorHandler.port';
export default class InterceptorHandlerAdapter
implements InterceptorHandlerPort
{
constructor(private interceptors: Interceptor[]) {}
matchInterceptors(filter: InterceptorFilter, url: string): Interceptor[] {
return this.interceptors.filter((interceptor) => {
return interceptor.intercepts == filter && interceptor.urlRegex.test(url);
});
}
triggerEvent(eventName: string, body: ProtobufObject, id: number): void {
const e = new CustomEvent('TWPT_' + eventName, {
detail: {
body,
id,
},
});
window.dispatchEvent(e);
}
}