Skip to content

Commit

Permalink
only mark connected once snapshot is received
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusLongmuir committed Jan 20, 2025
1 parent 886d735 commit 0a2acf5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/networked-dom-web/src/NetworkedDOMWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,21 @@ export class NetworkedDOMWebsocket {
websocketAdapter = new NetworkedDOMWebsocketV02Adapter(
websocket,
this.parentElement,
() => {
this.backoffTime = startingBackoffTimeMilliseconds;
this.setStatus(NetworkedDOMWebsocketStatus.Connected);
},
this.timeCallback,
this.options,
);
} else {
websocketAdapter = new NetworkedDOMWebsocketV01Adapter(
websocket,
this.parentElement,
() => {
this.backoffTime = startingBackoffTimeMilliseconds;
this.setStatus(NetworkedDOMWebsocketStatus.Connected);
},
this.timeCallback,
this.options,
);
Expand All @@ -126,9 +134,7 @@ export class NetworkedDOMWebsocket {
websocket.close();
return;
}
this.backoffTime = startingBackoffTimeMilliseconds;
websocketAdapter.receiveMessage(event);
this.setStatus(NetworkedDOMWebsocketStatus.Connected);
});

const onWebsocketClose = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class NetworkedDOMWebsocketV01Adapter implements NetworkedDOMWebsocketAda
constructor(
private websocket: WebSocket,
private parentElement: HTMLElement,
private connectedCallback: () => void,
private timeCallback?: (time: number) => void,
private options: NetworkedDOMWebsocketOptions = {},
) {
Expand Down Expand Up @@ -87,6 +88,7 @@ export class NetworkedDOMWebsocketV01Adapter implements NetworkedDOMWebsocketAda
switch (message.type) {
case "snapshot":
this.handleSnapshot(message);
this.connectedCallback();
break;
case "attributeChange":
this.handleAttributeChange(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class NetworkedDOMWebsocketV02Adapter implements NetworkedDOMWebsocketAda
constructor(
private websocket: WebSocket,
private parentElement: HTMLElement,
private connectedCallback: () => void,
private timeCallback?: (time: number) => void,
private options: NetworkedDOMWebsocketOptions = {},
) {
Expand Down Expand Up @@ -129,6 +130,7 @@ export class NetworkedDOMWebsocketV02Adapter implements NetworkedDOMWebsocketAda
break;
case "snapshot":
this.handleSnapshot(message);
this.connectedCallback();
break;
case "attributesChanged":
this.handleAttributeChange(message);
Expand Down

0 comments on commit 0a2acf5

Please sign in to comment.