OfficeDev / microsoft-teams-library-js

JavaScript library for use by Microsoft Teams apps
https://docs.microsoft.com/microsoftteams/platform/
Other
419 stars 192 forks source link

Add support for geolocation in New Teams #2393

Open Nerconer opened 2 weeks ago

Nerconer commented 2 weeks ago

Hello,

With new Teams client, it is expected to use navigator.permissions.query({ name: "geolocation" }) method to retrieve user location instead of microsoftTeams.location.getLocation(locationProps, (err, location) as we could using Classic Teams client.

Example:

https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/app-checkin-location/nodejs/views/CheckIn.ejs

This new alternative has been proven for us to not be reliable since most of the times, we don't get any response even when result.state is equal to granted. It behaves different across browsers, mobile devices and the desktop client.

It seems for us that navigator.permissions.query({ name: "geolocation" }) has been getting worse over time.

We didn't had any issues in the past using the Classic Teams method and now it feels that this feature is broken. For some users works and for others don't (at the same time). However, most of the time, it doesn't.

It would be great if you could add support again to this feature.

Thanks in advance

Prasad-MSFT commented 2 weeks ago

Thanks for raising your issue. Team will check this at our end and will update you accordingly.

Nivedipa-MSFT commented 1 week ago

@Nerconer - It seems there might be a misunderstanding regarding the navigator.permissions.query({ name: "geolocation" }) method. This method is a standard web API for checking the permission status of a given permission name, such as "geolocation". However, in the context of the Microsoft TeamsJS library, as of version 2.1.0, you should use the following functions for geolocation purposes:

geoLocation.getCurrentLocation(): Promise : to get the current location. geoLocation.map.chooseLocation(): Promise : to choose location on map.

These API is in Beta and provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

If you are looking for the navigator.permissions.query({ name: "geolocation" }) method within the TeamsJS library documentation, it might not be listed as it is not a part of the TeamsJS library but a standard web API. For geolocation functionalities within Teams applications, you should use the TeamsJS library's geolocation APIs as mentioned above.

Ref Doc: https://learn.microsoft.com/en-us/javascript/api/@microsoft/teams-js/location?view=msteams-client-js-latest#@microsoft-teams-js-location-getlocation

If you have any further query, feel free to ask!

Nerconer commented 1 week ago

Hello @Nivedipa-MSFT,

Thanks for your reply. I will check that API and update you.

One question that still is not clear for me. What API should be used in production environment then?

Thanks!

Nerconer commented 1 week ago

The following code produces the next output using New Teams client.

console.log(`Teams SDK version: ${microsoftTeams.version}`)
console.log(`Is GeoLocation supported: ${microsoftTeams.geoLocation.isSupported()}`)

// Classic Teams client
if (microsoftTeams.geoLocation.isSupported()) {
  console.log("Getting location using microsoftTeams");
  microsoftTeams.geoLocation.map.chooseLocation().then((result) => {
    document.getElementById("text").innerHTML = "Your location has been shared.";
    microsoftTeams.tasks.submitTask(result);
  }).catch((error) => {
    displayErrorScreen()
  });
} else {
  // Teams V2 client
  console.log("Getting location using navigator");
  getLocationUsingNavigator();
}
image

As you can see, microsoftTeams.geoLocation.isSupported()returns false.

Using Classic Teams, returns true.

Nivedipa-MSFT commented 1 week ago

@Nerconer - We are checking this with engineering team, we will inform you once we get any updates from them.

Nerconer commented 6 days ago

Hi @Nivedipa-MSFT - Thanks for the reply. Do you have any updates?

Nivedipa-MSFT commented 5 days ago

@Nerconer - The teams-js geolocation APIs aren't supported in the New Teams Client. Ref Doc: https://learn.microsoft.com/en-us/microsoftteams/platform/resources/teams-updates#limitations

image

You can use the standard HTML5 Geolocation API whenever the geoLocation.isSupported API returns false: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API

Please share if you have any further query here?

Nerconer commented 5 days ago

@Nivedipa-MSFT - As mentioned at the beginning, we are already using HTML Geolocation in New Teams and because it's a broken functionality at this time (most of the times doesn't work), my original request was if it was possible to add support using teams-js library again since when we were using it in Classic, we never had any issues.

Please, let me know what can we do.

Thanks!

Nivedipa-MSFT commented 3 days ago

@Nerconer - We received a response from the engineering team indicating that there are no immediate plans to implement support for the geoLocation APIs in the New Teams Client. Although the task is recorded in our backlog, it is not a priority at the moment.