55 * -------------------------------------------------------------------------------------------
66 */
77
8- import { BetaGraph , IGraph , Providers , error , log } from '@microsoft/mgt-element' ;
8+ import { BetaGraph , IGraph , Providers , createFromProvider , error , log } from '@microsoft/mgt-element' ;
99import { HubConnection , HubConnectionBuilder , IHttpConnectionOptions , LogLevel } from '@microsoft/signalr' ;
1010import { ThreadEventEmitter } from './ThreadEventEmitter' ;
1111import type {
@@ -45,8 +45,6 @@ const isMessageNotification = (o: Notification<Entity>): o is Notification<ChatM
4545const isMembershipNotification = ( o : Notification < Entity > ) : o is Notification < AadUserConversationMember > =>
4646 o . resource . includes ( '/members' ) ;
4747
48- const stripWssScheme = ( notificationUrl : string ) : string => notificationUrl . replace ( 'websockets:' , '' ) ;
49-
5048export class GraphNotificationClient {
5149 private connection ?: HubConnection = undefined ;
5250 private renewalInterval = - 1 ;
@@ -60,6 +58,11 @@ export class GraphNotificationClient {
6058 private get beta ( ) {
6159 return BetaGraph . fromGraph ( this . _graph ) ;
6260 }
61+ private get subscriptionGraph ( ) {
62+ return GraphConfig . useCanary
63+ ? createFromProvider ( Providers . globalProvider , GraphConfig . canarySubscriptionVersion , 'mgt-chat' )
64+ : this . beta ;
65+ }
6366
6467 /**
6568 *
@@ -168,21 +171,21 @@ export class GraphNotificationClient {
168171 ) . toISOString ( ) ;
169172 const subscriptionDefinition : Subscription = {
170173 changeType : changeTypes . join ( ',' ) ,
171- notificationUrl : 'websockets:' ,
174+ notificationUrl : GraphConfig . webSocketsPrefix ,
172175 resource : resourcePath ,
173176 expirationDateTime,
174177 includeResourceData : true ,
175178 clientState : 'wsssecret'
176179 } ;
177180
178181 log ( 'subscribing to changes for ' + resourcePath ) ;
182+ const subscriptionEndpoint = GraphConfig . subscriptionEndpoint ;
179183 // send subscription POST to Graph
180- const subscription : Subscription = ( await this . beta
181- . api ( GraphConfig . subscriptionEndpoint )
184+ const subscription : Subscription = ( await this . subscriptionGraph
185+ . api ( subscriptionEndpoint )
182186 . post ( subscriptionDefinition ) ) as Subscription ;
183187 if ( ! subscription ?. notificationUrl ) throw new Error ( 'Subscription not created' ) ;
184188 log ( subscription ) ;
185- // subscription.notificationUrl = GraphConfig.adjustNotificationUrl(subscription.notificationUrl);
186189
187190 const awaits : Promise < void > [ ] = [ ] ;
188191 // Cache the subscription in storage for re-hydration on page refreshes
@@ -262,7 +265,7 @@ export class GraphNotificationClient {
262265 withCredentials : false
263266 } ;
264267 const connection = new HubConnectionBuilder ( )
265- . withUrl ( stripWssScheme ( notificationUrl ) , connectionOptions )
268+ . withUrl ( GraphConfig . adjustNotificationUrl ( notificationUrl ) , connectionOptions )
266269 . withAutomaticReconnect ( )
267270 . configureLogging ( LogLevel . Information )
268271 . build ( ) ;
0 commit comments