Skip to content

Commit

Permalink
fix: Only import necessary teams modules
Browse files Browse the repository at this point in the history
  • Loading branch information
biharygergo committed Dec 26, 2024
1 parent 78489ca commit e136b94
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2>What is this?</h2>
target="_blank"
>strongly against this conversion</a
>. This story point calculator helps the former teams estimate
project delivery timelines by converting story points a
project delivery timelines by converting story points into a
measurement of time. It considers various parameters such as team
members, velocity, days off, and buffer days to provide a somewhat
accurate project burndown. By inputting these details, teams can
Expand Down
64 changes: 28 additions & 36 deletions src/app/services/teams.service.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import * as microsoftTeams from '@microsoft/teams-js';
import { app, authentication, meeting, teamsCore } from '@microsoft/teams-js';
import { Theme, ThemeService } from './theme.service';
import { PaymentService } from './payment.service';

@Injectable({
providedIn: 'root',
})
@Injectable()
export class TeamsService {
isInitialized = false;

constructor(
private readonly router: Router,
private readonly themeService: ThemeService,
private readonly paymentService: PaymentService
) {}

async configureApp() {
if (!this.isInitialized) {
await microsoftTeams.app.initialize();
const frameContext = microsoftTeams.app.getFrameContext();
const appContext = await microsoftTeams.app.getContext();
await app.initialize();
const frameContext = app.getFrameContext();
const appContext = await app.getContext();

if (
['android', 'ios', 'ipados'].includes(appContext.app.host.clientType)
Expand All @@ -33,24 +29,22 @@ export class TeamsService {
}

try {
microsoftTeams.teamsCore.registerOnLoadHandler((data) => {
teamsCore.registerOnLoadHandler((data) => {
try {
microsoftTeams.app.notifySuccess();
app.notifySuccess();
} catch {
console.error('Could not notify success');
}
});

microsoftTeams.teamsCore.registerBeforeUnloadHandler(
(readyToUnload) => {
try {
readyToUnload();
} catch {
console.error('Could not notify unload');
}
return true;
teamsCore.registerBeforeUnloadHandler((readyToUnload) => {
try {
readyToUnload();
} catch {
console.error('Could not notify unload');
}
);
return true;
});
} catch {
console.error('Could not register for cache');
}
Expand All @@ -69,7 +63,7 @@ export class TeamsService {
}

const roomUrl = `${window.location.origin}/room/${roomId}?s=teams`;
microsoftTeams.meeting.shareAppContentToStage((err, result) => {
meeting.shareAppContentToStage((err, result) => {
if (result) {
resolve(true);
}
Expand All @@ -84,7 +78,7 @@ export class TeamsService {

async canShareToStage() {
return new Promise((resolve) => {
const frameContext = microsoftTeams.app.getFrameContext();
const frameContext = app.getFrameContext();
const isInMeeting =
frameContext === 'sidePanel' || frameContext === 'meetingStage';

Expand All @@ -93,23 +87,21 @@ export class TeamsService {
return;
}

microsoftTeams.meeting.getAppContentStageSharingCapabilities(
(err, result) => {
if (result?.doesAppHaveSharePermission) {
resolve(true);
return;
}

resolve(false);
meeting.getAppContentStageSharingCapabilities((err, result) => {
if (result?.doesAppHaveSharePermission) {
resolve(true);
return;
}
);

resolve(false);
return;
});
});
}

async getDeepLink(roomId: string) {
const joinUrl = `${window.location.origin}/join?s=teams&roomId=${roomId}`;
const context = await microsoftTeams.app.getContext();
const context = await app.getContext();
const isRunningInMeeting = !!context.meeting?.id;
const linkContext = {
subEntityId: roomId,
Expand All @@ -128,7 +120,7 @@ export class TeamsService {
}

async getLinkedRoomId(): Promise<string | undefined> {
const context = await microsoftTeams.app.getContext();
const context = await app.getContext();
return context.page.subPageId;
}

Expand All @@ -140,7 +132,7 @@ export class TeamsService {
}/api/startOAuth?oauthRedirectMethod={oauthRedirectMethod}&authId={authId}&redirectTo=${encodeURIComponent(
returnTo
)}&platform=teams&provider=google`;
const token = await microsoftTeams.authentication.authenticate({
const token = await authentication.authenticate({
url: apiUrl,
isExternal: true,
});
Expand All @@ -149,7 +141,7 @@ export class TeamsService {
}

notifySuccess(token: string) {
microsoftTeams.authentication.notifySuccess(token);
authentication.notifySuccess(token);
}

async getMicrosoftAuthToken(returnTo: string): Promise<string> {
Expand All @@ -160,7 +152,7 @@ export class TeamsService {
}/api/startOAuth?oauthRedirectMethod={oauthRedirectMethod}&authId={authId}&redirectTo=${encodeURIComponent(
returnTo
)}&platform=teams&provider=microsoft`;
const token = await microsoftTeams.authentication.authenticate({
const token = await authentication.authenticate({
url: apiUrl,
isExternal: true,
});
Expand Down

0 comments on commit e136b94

Please sign in to comment.