このイベントは、セッションが別のセッションに切り替わったときにクライアントによって呼び出されます。 このイベントにより、クライアント側のハンドラーはセッションの切り替えに反応し、必要に応じてユーザーインターフェイスまたは内部状態を更新できます。 ON_SESSION_SWITCHイベントは、次のeventDataを受け取ります。
| eventData | Description |
|---|---|
| previousSessionId | 前のセッションのセッション ID。 |
| 新しいセッション ID | フォーカスされているセッションの ID。 |
Example
// Define a handler function that's triggered when the session is switched
let sessionSwitchedHandlerFunction = function(eventInput) {
// Log the previous and new session IDs to the console
console.log("Previous session: " + eventInput.data.previousSessionId +
" - Current session: " + eventInput.data.newSessionId);
};
// Retrieve the event topic specific to session switching from the API
let sessionSwitchTopic = Microsoft.Apm.getEventPublisherTopic("ON_SESSION_SWITCH");
// Create a new broadcast channel to subscribe to session switch events
let sessionSwitchSubscriber = new BroadcastChannel(sessionSwitchTopic);
// Attach the session switched handler function to the message event of the subscriber
sessionSwitchSubscriber.onmessage = sessionSwitchedHandlerFunction;
注
このコード サンプルでは、 ブロードキャスト チャネル API - Web API を使用して、同じオリジンのページや iframe などの異なるドキュメント間で通信します。 この API のサポートは異なる場合があるため、カスタマイズと互換性があることを確認してください。