File
Index
Properties
|
|
Methods
|
|
Accessors
|
|
Methods
currentPlatform
|
Please use BriPlatformService.platform that returns BriPlatform
|
currentPlatform()
|
|
Please use BriPlatformService.platform that returns BriPlatform
Returns : "ios" | "android" | "web"
|
isBrowser
|
Type : boolean
|
Default value : false
|
|
import { Platform } from '@angular/cdk/platform';
import { Injectable } from '@angular/core';
import { BriPlatform } from '@davita/bridge-library/shared';
@Injectable({
providedIn: 'root',
})
export class BriPlatformService {
isBrowser: boolean = false;
constructor() {}
/**
* @deprecated
* Please use BriPlatformService.platform that returns BriPlatform
*/
currentPlatform() {
var _platform: Platform = new Platform('browser');
this.isBrowser = _platform.isBrowser;
if (_platform.IOS) {
return 'ios';
} else if (_platform.ANDROID) {
return 'android';
} else {
return 'web';
}
}
get platform(): BriPlatform {
const userAgent = navigator.userAgent || navigator.vendor || (window as any).opera;
const platform = navigator.platform || 'unknown';
const maxTouchPoints = navigator.maxTouchPoints || 0;
// Detect if it's an iPad
const isIPad = /iPad/.test(userAgent) || (/Mac/.test(platform) && maxTouchPoints >= 1);
// Detect if it's an iPhone
const isIPhone = /iPhone/.test(userAgent);
// Detect if it's an iOS device
const isIOS = isIPad || isIPhone;
// Detect if it's an Android device
const isAndroid = /Android/.test(userAgent);
// Detect if it's Chrome on iOS
const isCriOS = /CriOS/.test(userAgent);
// Detect if it's Safari
const isSafari = /Version/.test(userAgent);
// iPhone detection
if (isIPhone) {
if (isSafari) {
return BriPlatform.iPhoneSafari;
}
return BriPlatform.iPhoneWebView;
}
// Android detection
if (isAndroid) {
if (isSafari) {
return BriPlatform.androidBrowser;
}
return BriPlatform.androidWebView;
}
// iPhone/iPad browser (Chrome)
if (isIOS && isCriOS) {
if (isIPad) {
return BriPlatform.iPadBrowser;
}
return BriPlatform.iPhoneBrowser;
}
// iPad detection
if (isIPad) {
if (isSafari) {
return BriPlatform.iPadSafari;
}
return BriPlatform.iPadWebView;
}
// Default to computer
return BriPlatform.computer;
}
}