Adrià Vilanova MartÃnez | 9c418ab | 2024-12-05 15:34:40 +0100 | [diff] [blame] | 1 | import { ProtobufObject } from '../../common/protojs.types'; |
| 2 | import { |
| 3 | Interceptor, |
| 4 | InterceptorFilter, |
| 5 | InterceptorHandlerPort, |
| 6 | } from './InterceptorHandler.port'; |
| 7 | |
| 8 | export default class InterceptorHandlerAdapter |
| 9 | implements InterceptorHandlerPort |
| 10 | { |
| 11 | constructor(private interceptors: Interceptor[]) {} |
| 12 | |
| 13 | matchInterceptors(filter: InterceptorFilter, url: string): Interceptor[] { |
| 14 | return this.interceptors.filter((interceptor) => { |
| 15 | return interceptor.intercepts == filter && interceptor.urlRegex.test(url); |
| 16 | }); |
| 17 | } |
| 18 | triggerEvent(eventName: string, body: ProtobufObject, id: number): void { |
| 19 | const e = new CustomEvent('TWPT_' + eventName, { |
| 20 | detail: { |
| 21 | body, |
| 22 | id, |
| 23 | }, |
| 24 | }); |
| 25 | window.dispatchEvent(e); |
| 26 | } |
| 27 | } |