How do I close the window after leaveUrl?

at the end of the meeting and click on the exit button after 3 seconds I would like the window to close automatically

Hey @dario.mendoza,

Thank you for reaching out to the Zoom Developer Forum. There are a couple of options when it comes to this.

  1. You can add an event listener for the click event on the Leave button and close the tab when the user confirms they want to leave the meeting.

  2. You can add an event listener to the beforeUnload or unload events so that you can close the child window when the page is redirected

  3. You can set your leaveURL to a page you’ve created that automatically closes the child window when it’s opened

I hope that helps! Let me know if you have any questions.

Thanks,
Max

Hi Max, I would like to apply option 1, could you help me with an example of how to close the window once the participant leaves the meeting or leaves the meeting.
regards
Dario

Hey @dario.mendoza ,

You can use the close window javascript function:

https://developer.mozilla.org/en-US/docs/Web/API/Window/close

You can listen to the onUserLeave event via In Meeting Service Listener:

https://marketplacefront.zoom.us/sdk/meeting/web/ZoomMtg.html#inMeetingServiceListener

Let me know if that helps.

Thanks,
Tommy

Hi Tommy, I did the exercise with window.close () but in automatic it closes the window (it doesn’t let anything load)

I don’t understand the other exercise (onUserLeave event), could you explain it to me more clearly?
regards
Darius
saludos Tommy

Hey @dario.mendoza,

Thank you for your questions.

You won’t be able to add a JavaScript function to the leaveUrl property as this expects a string containing the URL to redirect to. Instead, you’ll want to call the window.close() function from the onUserLeave inMeetingEventListener event. Alternatively, you can use the leaveUrl to redirect to a page that closes the browser window after the page loads.

The onUserLeave event will fire when a user leaves the meeting. We have an example of how to use this in our Sample Web App and more information can be found in the reference documentation:

I hope that helps! Let me know if you have any questions.

Thanks,
Max

Hi MaxM,

in 1.9.0

ZoomMtg.inMeetingServiceListener(“onUserLeave”, () => {
window.close();
});

does not work, it still redirects and does not close the window

Edit: When the meeting has 2 people in it this does work, but it closes the window for all participants when any one participant leaves. So this is not the correct solution.

1 Like

thanks, jake2 in effect does not work and does not close the window

I was able to test this with Jake, using 2 computers on different networks in different buildings. I joined as the host, Jake joined after me, Jake left the meeting, and when he did my browser window also closed. So, the onUserLeave event gets fired for every user in the meeting, not just the user who left, and it looks like the event handler gets passed 3 objects, but I don’t see information about the user who left that we could use to determine if the current user left and close only their window. The first parameter to the event handler is an object that contains an exports property, which is an object with a Meeting object, then there’s a numeric id property, and a “loaded” property set to true.

If we can’t catch the current user leaving, then maybe another alternative would be another option like leaveUrl that accepts a function to run when the current user leaves.

already solved

in the leaveUrl I directed it to a new example page [leaveUrl: “/endmeeting.html”] and on that page I put what is seen in the image and with that when the user leaves the meeting the window automatically closes.


thanks: Adrian Ponce

1 Like

Hey @jake2, @tcsteve and @dario.mendoza,

Thank you for the update.

That is correct, you can’t directly call the window.close() function unless you want the window to close for all users. You will need to add custom logic to fit your use case.

If you initialize an inMeetingServiceListener on the page, the user that has that page opened will receive the event but it will only fire for the single user that left the meeting. You can always add an inMeetingServiceListener conditionally.

You should be able to use the data argument as shown in the example above to get information about the user leaving the meeting. Here is an example of what I saw when running the code from the Sample Web App:

image

That userId, in conjunction with the getCurrentUser() function should be all you need to close the window for a specific user.

Great! I’m glad to hear that method worked for you.

Thanks,
Max

2 Likes

Hi Max,

I saw my problem before, we had the event handler set up as an arrow function and I tried to use arguments to see what was being passed to it.

We’re trying to call getCurrentUser, and it’s returning undefined. It looks like the documentation says it expects an empty object as a parameter. We’ve called it with and without a parameter and it’s still showing undefined. Do you know where we’re going wrong?

Hey @tcsteve ,

Can you share the code snippet of how you are calling the getCurrentUser function? Make sure you are calling it in the ZoomMtg.join success callback function. :slight_smile:

More details will allow us to better assist.

Thanks,
Tommy

We’re actually calling it in the onUserLeave event handler, using ZoomMtg.getCurrentUser. The purpose is to figure out if the current user is the user who just left, and close their window if so. We’re registering the event listener right after calling init, not in the success callback for either init or join.

			// ZoomMtg.inMeetingServiceListener("onUserLeave", (data) => {
			// 	console.log("close window");
			// 	console.log("inMeetingServiceListener onUserLeave", data);
			// 	const user = ZoomMtg.getCurrentUser({});
			// 	console.log("ZoomMtg.getCurrentUser({})", user);
			// 	if(data.userId === user.id) {
			// 		window.close();
			// 	}
			// });

Hey @tcsteve,

Thank you for the update. I tested this on my end and saw that the user leaving does not receive the onUserLeave event because this event fires after the page is redirected. That’s my mistake for advising you incorrectly.

Instead, you should employ the same method as @dario.mendoza where you redirect to a page that closes the window.

As part of my testing, I found a couple additional tips related to the code snippet:

  1. Instead of using getCurrentUser to obtain the User ID, you can use the onUserJoin event to capture the userId
  ZoomMtg.inMeetingServiceListener('onUserJoin',  (data) => {
    console.log('inMeetingServiceListener onUserJoin', data.userId);
  });
  1. When using getCurrentUser make sure that you are accessing the user information from the success callback.

Along those same lines, in order to ensure you get all the information available from that function, it will need to be called from the success callback of the join() function or via another method that ensures it is called after the user is done joining the meeting.

We have an example of this can be done on the git repo for our Sample Web App:

Sorry for the confusion there, I hope this is helpful!

Thanks,
Max

We have been suffering from this a lot. I guess it’s will be much better if control is given to the developer so that we have can have control what our app should behave rather than just a hack.

I find zoom dev are unhelpful most of the time, its on our end to find a workaround. I find really demotivated working with zoom sdk.

Hi Max, that is the solution I suggest for the moment, let me know if it has worked for someone else.
regards
Darius

Hey @ankur.sharma,

Thank you for your feedback. I’m really sorry to hear that we haven’t been helpful. It’s our goal to make sure that using Zoom SDKs is as frictionless as possible.

If you have any issues, please do submit a forum topic going over any ongoing problems that you face and I’m happy to do whatever is necessary to help out. This might mean resolving the issue, working with our engineering team to add feature requests or to confirming if any of the changes are on our roadmap.

Thanks,
Max

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.