|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2025 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
1 | 17 |
|
2 | 18 | import { ConfigUpdateObserver } from "../public_types"; |
3 | | -export class RealtimeHandler { |
4 | | - constructor() { |
| 19 | +const MAX_HTTP_RETRIES = 8; |
5 | 20 |
|
6 | | - } |
| 21 | +export class RealtimeHandler{ |
| 22 | + constructor () |
| 23 | + { } |
| 24 | + |
7 | 25 | private observers: Set<ConfigUpdateObserver> = new Set<ConfigUpdateObserver>(); |
8 | | - begineRealtime(){ |
9 | | - //if observers are present, start the realtime updates |
10 | | - if (this.observers.size > 0) { |
11 | | - |
12 | | - } |
13 | | - } |
| 26 | + |
14 | 27 | /** |
15 | | - * Adds an observer to the realtime updates. |
16 | | - * @param observer The observer to add. |
17 | | - */ |
18 | | - addObserver(observer: ConfigUpdateObserver) { |
| 28 | + * Adds an observer to the realtime updates. |
| 29 | + * @param observer The observer to add. |
| 30 | + */ |
| 31 | + public addObserver(observer: ConfigUpdateObserver) { |
19 | 32 | this.observers.add(observer); |
20 | | - console.log("observer added:", this.observers); |
21 | | - |
22 | | - this.begineRealtime(); |
| 33 | + this.beginRealtime(); |
23 | 34 | } |
24 | 35 | /** |
25 | 36 | * Removes an observer from the realtime updates. |
26 | 37 | * @param observer The observer to remove. |
27 | | - * @returns true if the observer was removed, false if it was not found. |
28 | 38 | */ |
29 | | - removeObserver(observer: ConfigUpdateObserver) { |
| 39 | + public removeObserver(observer: ConfigUpdateObserver): void { |
30 | 40 | if (this.observers.has(observer)) { |
31 | | - console.log("observer remove:", this.observers); |
32 | | - return this.observers.delete(observer); |
| 41 | + this.observers.delete(observer); |
33 | 42 | } |
34 | 43 | } |
| 44 | + |
| 45 | + private beginRealtime(): void { |
| 46 | + if (this.observers.size > 0) { |
| 47 | + this.makeRealtimeHttpConnection(0); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + private makeRealtimeHttpConnection(retryMilliseconds: number): void { |
| 52 | + |
| 53 | + } |
| 54 | + |
35 | 55 | } |
0 commit comments