diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index 8663947b7b..713879e463 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/packages/mgt-chat/src/statefulClient/GraphConfig.ts b/packages/mgt-chat/src/statefulClient/GraphConfig.ts index c52f013889..057382f399 100644 --- a/packages/mgt-chat/src/statefulClient/GraphConfig.ts +++ b/packages/mgt-chat/src/statefulClient/GraphConfig.ts @@ -5,24 +5,27 @@ export class GraphConfig { public static version = 'v1.0'; - // public static subscriptionConnectionVersion = 'testprodv1.0e2ewebsockets'; + public static canarySubscriptionVersion = 'testprodv1.0e2ewebsockets'; + + public static webSocketsPrefix = 'websockets:'; public static get graphEndpoint(): GraphEndpoint { - // return GraphConfig.useCanary ? 'https://canary.graph.microsoft.com' : - return 'https://graph.microsoft.com'; + return GraphConfig.useCanary ? 'https://canary.graph.microsoft.com' : 'https://graph.microsoft.com'; + } + + public static get baseCanaryUrl(): string { + return `${GraphConfig.graphEndpoint}/${this.canarySubscriptionVersion}`; } public static get subscriptionEndpoint(): string { - return '/subscriptions'; + return GraphConfig.useCanary ? `${GraphConfig.baseCanaryUrl}/subscriptions` : '/subscriptions'; } - // public static adjustNotificationUrl(url: string): string { - // let temp = url; - // if (GraphConfig.useCanary && url) { - // temp = url.replace('https://graph.microsoft.com/1.0', GraphConfig.baseCanaryUrl); - // temp = temp.replace('https://graph.microsoft.com/beta', GraphConfig.baseCanaryUrl); - // } - // temp = temp.replace(GraphConfig.version, GraphConfig.subscriptionConnectionVersion); - // return temp.replace('wss:', ''); - // } + public static adjustNotificationUrl(url: string): string { + if (GraphConfig.useCanary && url) { + url = url.replace('https://graph.microsoft.com/1.0', GraphConfig.baseCanaryUrl); + url = url.replace('https://graph.microsoft.com/beta', GraphConfig.baseCanaryUrl); + } + return url.replace(GraphConfig.webSocketsPrefix, ''); + } } diff --git a/packages/mgt-chat/src/statefulClient/GraphNotificationClient.ts b/packages/mgt-chat/src/statefulClient/GraphNotificationClient.ts index 652492dfc9..fdc8d01580 100644 --- a/packages/mgt-chat/src/statefulClient/GraphNotificationClient.ts +++ b/packages/mgt-chat/src/statefulClient/GraphNotificationClient.ts @@ -5,7 +5,7 @@ * ------------------------------------------------------------------------------------------- */ -import { BetaGraph, IGraph, Providers, error, log } from '@microsoft/mgt-element'; +import { BetaGraph, IGraph, Providers, createFromProvider, error, log } from '@microsoft/mgt-element'; import { HubConnection, HubConnectionBuilder, IHttpConnectionOptions, LogLevel } from '@microsoft/signalr'; import { ThreadEventEmitter } from './ThreadEventEmitter'; import type { @@ -45,8 +45,6 @@ const isMessageNotification = (o: Notification): o is Notification): o is Notification => o.resource.includes('/members'); -const stripWssScheme = (notificationUrl: string): string => notificationUrl.replace('websockets:', ''); - export class GraphNotificationClient { private connection?: HubConnection = undefined; private renewalInterval = -1; @@ -60,6 +58,11 @@ export class GraphNotificationClient { private get beta() { return BetaGraph.fromGraph(this._graph); } + private get subscriptionGraph() { + return GraphConfig.useCanary + ? createFromProvider(Providers.globalProvider, GraphConfig.canarySubscriptionVersion, 'mgt-chat') + : this.beta; + } /** * @@ -168,7 +171,7 @@ export class GraphNotificationClient { ).toISOString(); const subscriptionDefinition: Subscription = { changeType: changeTypes.join(','), - notificationUrl: 'websockets:', + notificationUrl: GraphConfig.webSocketsPrefix, resource: resourcePath, expirationDateTime, includeResourceData: true, @@ -176,13 +179,13 @@ export class GraphNotificationClient { }; log('subscribing to changes for ' + resourcePath); + const subscriptionEndpoint = GraphConfig.subscriptionEndpoint; // send subscription POST to Graph - const subscription: Subscription = (await this.beta - .api(GraphConfig.subscriptionEndpoint) + const subscription: Subscription = (await this.subscriptionGraph + .api(subscriptionEndpoint) .post(subscriptionDefinition)) as Subscription; if (!subscription?.notificationUrl) throw new Error('Subscription not created'); log(subscription); - // subscription.notificationUrl = GraphConfig.adjustNotificationUrl(subscription.notificationUrl); const awaits: Promise[] = []; // Cache the subscription in storage for re-hydration on page refreshes @@ -262,7 +265,7 @@ export class GraphNotificationClient { withCredentials: false }; const connection = new HubConnectionBuilder() - .withUrl(stripWssScheme(notificationUrl), connectionOptions) + .withUrl(GraphConfig.adjustNotificationUrl(notificationUrl), connectionOptions) .withAutomaticReconnect() .configureLogging(LogLevel.Information) .build(); diff --git a/packages/mgt-element/src/Graph.ts b/packages/mgt-element/src/Graph.ts index 21f653f794..b3ce0895f0 100644 --- a/packages/mgt-element/src/Graph.ts +++ b/packages/mgt-element/src/Graph.ts @@ -147,7 +147,7 @@ export class Graph implements IGraph { * @returns {Graph} * @memberof Graph */ -export const createFromProvider = (provider: IProvider, version?: string, component?: Element): Graph => { +export const createFromProvider = (provider: IProvider, version?: string, component?: Element | string): Graph => { const middleware: Middleware[] = [ new AuthenticationHandler(provider), new RetryHandler(new RetryHandlerOptions()),