[英]How to know that web app is access on browser or from teams custom app
My web application is created in angular.我的 web 应用程序是在 angular 中创建的。 Can I check whether web application is accessed from browser or Teams custom apps.我可以检查是否从浏览器或团队自定义应用程序访问 web 应用程序。
As I know this features is available for app which are created in react.据我所知,此功能可用于在 react 中创建的应用程序。 example:- import { useTeams } from "msteams-react-base-component";示例:- 从“msteams-react-base-component”导入 { useTeams }; const [{ inTeams, theme, context }] = useTeams(); const [{ inTeams, 主题, 上下文}] = useTeams();
Above inTeams return boolean, which tells whether app is accessed from browser or custom app.上面的 inTeams 返回 boolean,它告诉应用程序是从浏览器还是自定义应用程序访问。
So I get this in angular as well?所以我也在 angular 中得到这个?
You can take the function from msteams-react-base-component, it's very simple:您可以从 msteams-react-base-component 获取 function,非常简单:
import * as microsoftTeams from "@microsoft/teams-js";
export const checkInTeams = (): boolean => {
// eslint-disable-next-line dot-notation
const microsoftTeamsLib = microsoftTeams || window["microsoftTeams"];
if (!microsoftTeamsLib) {
return false; // the Microsoft Teams library is for some reason not loaded
}
if ((window.parent === window.self && (window as any).nativeInterface) ||
window.name === "embedded-page-container" ||
window.name === "extension-tab-frame") {
return true;
}
return false;
};
There is a property on the Teams Context object called hostClientType
, which I think is/was meant to deal with this. Teams Context object 上有一个名为hostClientType
的属性,我认为它是/应该处理这个问题。 It contains values like 'web' and 'desktop', and it used to be documented here but this doc has been updated to remove this property (amongst others).它包含诸如“web”和“desktop”之类的值,它曾经在此处记录,但此文档已更新以删除此属性(以及其他属性)。 Here is an older version of the same doc which contains more info.这是同一文档的旧版本,其中包含更多信息。 The property still exists, and it holds this info, but I'm not sure why it was removed from the documents (perhaps the property has been deprecated).该属性仍然存在,并且包含此信息,但我不确定为什么将其从文档中删除(也许该属性已被弃用)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.