createListener Method

Create a listener for long polling events from an EventSubscription. When event is received from the subscription, every registered listener callback is called. This continuously waits for events until all created listeners for that subscriptionId are deleted. EventSAS token expirations are handled automatically, AccessToken expiration is handled by calling authenticationCallback to get a new token.

createListener<T extends IModelHubEvent<T>>(requestContext: ClientRequestContext, authenticationCallback: () => Promise<AccessToken>, subscriptionId: string, iModelId: string, listener: (event: T) => void): () => void

throws IModelHubClientError with IModelHubStatus.UndefinedArgumentError or IModelHubStatus.InvalidArgumentError if one of the arguments is undefined or has an invalid value.

Parameter Type Description
requestContext ClientRequestContext The client request context
authenticationCallback () => Promise<AccessToken> Callback used to get AccessToken. Only the first registered authenticationCallback for this subscriptionId will be used.
subscriptionId string Id of EventSubscription.
iModelId string Id of the iModel. See HubIModel.
listener (event: T) => void Callback that is called when an IModelHubEvent is received.

Returns - () => void

Function that deletes the created listener.

Defined in

Last Updated: 12 June, 2024