Skip to content

Commit 1c449f8

Browse files
committed
refactor(ServerProvider): drop Meteor.absoluteUrl and combine Meteor + DDPSDK status
- absoluteUrl(path) now uses new URL(path, __meteor_runtime_config__.ROOT_URL). Same pattern we applied to roomCoordinator and AudioEncoder in the other migration branch, and prepares this file for the Meteor.absoluteUrl helper going away with the Meteor bundler. - getStatus() rolls up Meteor's DDP status with the DDPSDK connection status. If either socket is disconnected or still connecting, the UI reflects the worst state so the ConnectionStatusBar warns the user and useIdleConnection does not assume liveness. A dedicated Tracker.Dependency bridges DDPSDK's connection events into the same useReactiveValue autorun that reads Meteor.status(), so transitions on either transport invalidate the computation.
1 parent 4e236dd commit 1c449f8

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

apps/meteor/client/providers/ServerProvider.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { Method, PathFor, OperationParams, OperationResult, UrlParams, Path
1111
import type { UploadResult, ServerContextValue } from '@rocket.chat/ui-contexts';
1212
import { ServerContext } from '@rocket.chat/ui-contexts';
1313
import { Meteor } from 'meteor/meteor';
14+
import { Tracker } from 'meteor/tracker';
1415
import { compile } from 'path-to-regexp';
1516
import { useMemo, type ReactNode } from 'react';
1617

@@ -19,7 +20,7 @@ import { Info as info } from '../../app/utils/rocketchat.info';
1920
import { useReactiveValue } from '../hooks/useReactiveValue';
2021
import { ensureConnectedAndAuthenticated, getDdpSdk } from '../lib/sdk/ddpSdk';
2122

22-
const absoluteUrl = (path: string): string => Meteor.absoluteUrl(path);
23+
const absoluteUrl = (path: string): string => new URL(path, __meteor_runtime_config__.ROOT_URL).toString();
2324

2425
const callMethod = <MethodName extends ServerMethodName>(
2526
methodName: MethodName,
@@ -92,7 +93,39 @@ const reconnect = () => {
9293
void ensureConnectedAndAuthenticated();
9394
};
9495

95-
const getStatus = () => ({ ...Meteor.status() });
96+
// Combine Meteor's DDP status with our DDPSDK's connection status so the
97+
// ConnectionStatusBar / idle-connection hooks reflect the worst-case of both
98+
// transports: if either socket is down, UI shows disconnected. Meteor.status()
99+
// is Tracker-reactive; bridge DDPSDK's connection events into a local
100+
// Tracker.Dependency so the same useReactiveValue autorun re-fires on either
101+
// transport's transitions.
102+
const ddpSdkStatusDep = new Tracker.Dependency();
103+
getDdpSdk().connection.on('connection', () => ddpSdkStatusDep.changed());
104+
105+
type CombinedStatus = ReturnType<typeof Meteor.status>;
106+
107+
const mergeStatus = (meteor: CombinedStatus, sdkStatus: string): CombinedStatus => {
108+
if (sdkStatus === 'connected') {
109+
return { ...meteor };
110+
}
111+
112+
const sdkConnecting = sdkStatus === 'connecting' || sdkStatus === 'reconnecting';
113+
114+
if (meteor.connected && sdkConnecting) {
115+
return { ...meteor, connected: false, status: 'connecting' };
116+
}
117+
118+
if (meteor.connected) {
119+
return { ...meteor, connected: false, status: 'waiting' };
120+
}
121+
122+
return meteor;
123+
};
124+
125+
const getStatus = () => {
126+
ddpSdkStatusDep.depend();
127+
return mergeStatus(Meteor.status(), getDdpSdk().connection.status);
128+
};
96129

97130
type ServerProviderProps = { children?: ReactNode };
98131

0 commit comments

Comments
 (0)