Sự kiện ON_SESSION_CLOSED (Trình quản lý hồ sơ ứng dụng)

Sự kiện này được máy khách gọi khi một phiên được đóng. Sự kiện này cung cấp cơ hội để thực hiện các tác vụ dọn dẹp hoặc cập nhật trạng thái ứng dụng để phản hồi khi đóng phiên. Sự kiện ON_SESSION_CLOSED nhận eventData sau:

dữ liệu sự kiện Nội dung mô tả
sessionId ID phiên của phiên đã đóng.

Ví dụ:


// Define a handler function that's triggered when a session is closed
let sessionClosedHandlerFunction = function(eventInput) {
    // Log the ID of the closed session to the console
    console.log("Session closed: " + eventInput.data.sessionId);
};
// Retrieve the event topic specific to session closing from the API
let sessionCloseTopic = Microsoft.Apm.getEventPublisherTopic("ON_SESSION_CLOSED");
// Create a new broadcast channel to subscribe to session close events
let sessionCloseSubscriber = new BroadcastChannel(sessionCloseTopic);
// Attach the session closed handler function to the message event of the subscriber
sessionCloseSubscriber.onmessage = sessionClosedHandlerFunction;

Lưu ý

Mẫu mã sử dụng API kênh phát sóng - API web, để giao tiếp giữa các tài liệu khác nhau như các trang hoặc iframe có cùng nguồn gốc. Đảm bảo nó tương thích với tùy chỉnh của bạn vì hỗ trợ cho API này có thể khác nhau.