This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
BlazoradeTeamsInteropModule.cs
96 lines (86 loc) · 3.84 KB
/
BlazoradeTeamsInteropModule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using Blazorade.Core.Interop;
using Blazorade.Teams.Components;
using Blazorade.Teams.Configuration;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
namespace Blazorade.Teams.Interop
{
/// <summary>
/// The root module for facilitating communications with the Teams JavaScript SDK.
/// </summary>
public class BlazoradeTeamsInteropModule : InteropModuleBase
{
/// <summary>
/// Creates a new instance of the module class.
/// </summary>
/// <remarks>
/// This class should not be initialized in code. It will be created automatically through Dependency Injection
/// and provided through the <see cref="TeamsApplication.TeamsInterop"/> property.
/// </remarks>
public BlazoradeTeamsInteropModule(BlazoradeTeamsOptions appOptions, IJSRuntime jsRuntime, ApplicationInitializationModule appInitModule, SettingsModule settingsModule, AuthenticationModule authModule) : base(appOptions, jsRuntime)
{
this.Authentication = authModule ?? throw new ArgumentNullException(nameof(authModule));
this.AppInitialization = appInitModule ?? throw new ArgumentNullException(nameof(appInitModule));
this.Settings = settingsModule ?? throw new ArgumentNullException(nameof(settingsModule));
}
/// <summary>
/// Returns a module that is used for authentication.
/// </summary>
public AuthenticationModule Authentication { get; protected set; }
/// <summary>
/// A module that represents the <c>appInitialization</c> module in the Teams SDK.
/// </summary>
public ApplicationInitializationModule AppInitialization { get; protected set; }
/// <summary>
/// A module that represents the <c>settings</c> module in the Teams SDK.
/// </summary>
public SettingsModule Settings { get; protected set; }
/// <summary>
/// Returns the context information loaded from Teams.
/// </summary>
/// <remarks>
/// This method is called for you when you use the <see cref="TeamsApplication"/> component.
/// </remarks>
public async Task<Context> GetContextAsync()
{
return await new DotNetInstanceCallbackHandler<Context>(await this.GetBlazoradeTeamsJSModuleAsync(), "getContext")
.GetResultAsync();
}
/// <summary>
/// Initializes your application with Teams.
/// </summary>
/// <remarks>
/// This method is invoked for you when you use the <see cref="TeamsApplication"/> component.
/// </remarks>
public async Task InitializeAsync()
{
await new DotNetInstanceCallbackHandler(await this.GetBlazoradeTeamsJSModuleAsync(), "initialize")
.GetResultAsync();
}
/// <summary>
/// Determines whether the application has been loaded inside of Teams.
/// </summary>
/// <remarks>
/// <para>
/// If this method returns <c>false</c>, all the other methods on this module an its child modules
/// will also very likely fail.
/// </para>
/// <para>
/// You don't have to worry about this when using the <see cref="TeamsApplication"/> component as the
/// root component on your pages, and putting your application content in the
/// <see cref="TeamsApplication.ApplicationTemplate"/> template.
/// </para>
/// </remarks>
public async ValueTask<bool> IsTeamsHostAvailableAsync()
{
var module = await this.GetBlazoradeTeamsJSModuleAsync();
return await module.InvokeAsync<bool>("isTeamsHostAvailable");
}
}
}