nativescript-plugin-firebase
Advanced tools
Comparing version 9.0.1 to 9.0.2
@@ -5,3 +5,2 @@ "use strict"; | ||
var enums_1 = require("tns-core-modules/ui/enums/enums"); | ||
var utils_1 = require("tns-core-modules/utils/utils"); | ||
var firebase_common_1 = require("../firebase-common"); | ||
@@ -23,3 +22,3 @@ var admob_common_1 = require("./admob-common"); | ||
} | ||
admob_common_1.BANNER_DEFAULTS.view = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController.view; | ||
admob_common_1.BANNER_DEFAULTS.view = UIApplication.sharedApplication.keyWindow.rootViewController.view; | ||
var settings = firebase_common_1.firebase.merge(arg, admob_common_1.BANNER_DEFAULTS); | ||
@@ -52,3 +51,3 @@ _bannerOptions = settings; | ||
} | ||
firebase_common_1.firebase.admob.adView.rootViewController = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController; | ||
firebase_common_1.firebase.admob.adView.rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController; | ||
firebase_common_1.firebase.admob.adView.loadRequest(adRequest); | ||
@@ -119,3 +118,3 @@ view.addSubview(firebase_common_1.firebase.admob.adView); | ||
if (firebase_common_1.firebase.admob.interstitialView) { | ||
firebase_common_1.firebase.admob.interstitialView.presentFromRootViewController(utils_1.ios.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController); | ||
firebase_common_1.firebase.admob.interstitialView.presentFromRootViewController(UIApplication.sharedApplication.keyWindow.rootViewController); | ||
resolve(); | ||
@@ -135,3 +134,3 @@ } | ||
else { | ||
firebase_common_1.firebase.admob.interstitialView.presentFromRootViewController(utils_1.ios.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController); | ||
firebase_common_1.firebase.admob.interstitialView.presentFromRootViewController(UIApplication.sharedApplication.keyWindow.rootViewController); | ||
resolve(); | ||
@@ -231,3 +230,3 @@ } | ||
} | ||
firebase_common_1.firebase.admob.rewardedAdVideoView.presentFromRootViewController(utils_1.ios.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController); | ||
firebase_common_1.firebase.admob.rewardedAdVideoView.presentFromRootViewController(UIApplication.sharedApplication.keyWindow.rootViewController); | ||
resolve(); | ||
@@ -278,3 +277,3 @@ } | ||
else if (size === admob_common_1.AD_SIZE.SMART_BANNER || size === admob_common_1.AD_SIZE.FLUID) { | ||
var orientation_1 = utils_1.ios.getter(UIDevice, UIDevice.currentDevice).orientation; | ||
var orientation_1 = UIDevice.currentDevice.orientation; | ||
var isIPad = platform_1.device.deviceType === enums_1.DeviceType.Tablet; | ||
@@ -281,0 +280,0 @@ if (orientation_1 === 1 || orientation_1 === 2) { |
@@ -236,2 +236,3 @@ /** | ||
id: string; | ||
token?: string; | ||
} | ||
@@ -238,0 +239,0 @@ |
@@ -123,6 +123,20 @@ "use strict"; | ||
try { | ||
var tokenReturned_1 = false; | ||
org.nativescript.plugins.firebase.FirebasePlugin.setOnPushTokenReceivedCallback(new org.nativescript.plugins.firebase.FirebasePluginListener({ | ||
success: function (token) { return callback(token); }, | ||
success: function (token) { | ||
tokenReturned_1 = true; | ||
callback(token); | ||
}, | ||
error: function (err) { return console.log("addOnPushTokenReceivedCallback error: " + err); } | ||
})); | ||
setTimeout(function () { | ||
if (!tokenReturned_1) { | ||
getSenderId().then(function (senderId) { | ||
org.nativescript.plugins.firebase.FirebasePlugin.getCurrentPushToken(senderId, new org.nativescript.plugins.firebase.FirebasePluginListener({ | ||
success: function (token) { return callback(token); }, | ||
error: function (err) { return console.log(err); } | ||
})); | ||
}); | ||
} | ||
}, 2000); | ||
resolve(); | ||
@@ -129,0 +143,0 @@ } |
@@ -0,3 +1,3 @@ | ||
import { MessagingOptions } from "../firebase"; | ||
import { IosInteractiveNotificationAction, IosInteractiveNotificationCategory } from "./messaging"; | ||
import { MessagingOptions } from "../firebase"; | ||
export declare function initFirebaseMessaging(options: any): void; | ||
@@ -4,0 +4,0 @@ export declare function addOnMessageReceivedCallback(callback: Function): Promise<{}>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var applicationSettings = require("tns-core-modules/application-settings"); | ||
var application = require("tns-core-modules/application/application"); | ||
var applicationSettings = require("tns-core-modules/application-settings"); | ||
var utils_1 = require("tns-core-modules/utils/utils"); | ||
var platform_1 = require("tns-core-modules/platform/platform"); | ||
var utils_2 = require("../utils"); | ||
var firebase_common_1 = require("../firebase-common"); | ||
var utils_1 = require("../utils"); | ||
var _notificationActionTakenCallback; | ||
@@ -100,3 +99,3 @@ var _pendingNotifications = []; | ||
function handleRemoteNotification(app, userInfo) { | ||
var userInfoJSON = utils_2.firebaseUtils.toJsObject(userInfo); | ||
var userInfoJSON = utils_1.firebaseUtils.toJsObject(userInfo); | ||
var aps = userInfo.objectForKey("aps"); | ||
@@ -199,5 +198,4 @@ if (aps !== null) { | ||
}); | ||
var center = utils_1.ios.getter(UNUserNotificationCenter, UNUserNotificationCenter.currentNotificationCenter); | ||
var nsSetCategories = new NSSet(nativeCategories); | ||
center.setNotificationCategories(nsSetCategories); | ||
UNUserNotificationCenter.currentNotificationCenter().setNotificationCategories(nsSetCategories); | ||
if (model.onNotificationActionTakenCallback) { | ||
@@ -296,4 +294,3 @@ _addOnNotificationActionTakenCallback(model.onNotificationActionTakenCallback); | ||
function areNotificationsEnabled() { | ||
var app = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication); | ||
return app.currentUserNotificationSettings.types > 0; | ||
return UIApplication.sharedApplication.currentUserNotificationSettings.types > 0; | ||
} | ||
@@ -316,3 +313,3 @@ exports.areNotificationsEnabled = areNotificationsEnabled; | ||
function _registerForRemoteNotifications(resolve, reject) { | ||
var app = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication); | ||
var app = UIApplication.sharedApplication; | ||
if (!app) { | ||
@@ -331,10 +328,9 @@ application.on("launch", function () { return _registerForRemoteNotifications(resolve, reject); }); | ||
var authorizationOptions = 4 | 2 | 1; | ||
var curNotCenter = utils_1.ios.getter(UNUserNotificationCenter, UNUserNotificationCenter.currentNotificationCenter); | ||
curNotCenter.requestAuthorizationWithOptionsCompletionHandler(authorizationOptions, function (granted, error) { | ||
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptionsCompletionHandler(authorizationOptions, function (granted, error) { | ||
if (!error) { | ||
if (app === null) { | ||
app = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication); | ||
app = UIApplication.sharedApplication; | ||
} | ||
if (app !== null) { | ||
utils_2.firebaseUtils.invokeOnRunLoop(function () { return app.registerForRemoteNotifications(); }); | ||
utils_1.firebaseUtils.invokeOnRunLoop(function () { return app.registerForRemoteNotifications(); }); | ||
} | ||
@@ -350,3 +346,3 @@ } | ||
var userInfo = unnotification.request.content.userInfo; | ||
var userInfoJSON = utils_2.firebaseUtils.toJsObject(userInfo); | ||
var userInfoJSON = utils_1.firebaseUtils.toJsObject(userInfo); | ||
updateUserInfo(userInfoJSON); | ||
@@ -363,3 +359,3 @@ if (actionIdentifier) { | ||
} | ||
userInfoJSON.foreground = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication).applicationState === 0; | ||
userInfoJSON.foreground = UIApplication.sharedApplication.applicationState === 0; | ||
_pendingNotifications.push(userInfoJSON); | ||
@@ -370,10 +366,10 @@ if (_receivedNotificationCallback) { | ||
}); | ||
curNotCenter.delegate = _userNotificationCenterDelegate; | ||
UNUserNotificationCenter.currentNotificationCenter().delegate = _userNotificationCenterDelegate; | ||
} | ||
if (typeof (FIRMessaging) !== "undefined") { | ||
_firebaseRemoteMessageDelegate = FIRMessagingDelegateImpl.new().initWithCallback(function (appDataDictionary) { | ||
var userInfoJSON = utils_2.firebaseUtils.toJsObject(appDataDictionary); | ||
var userInfoJSON = utils_1.firebaseUtils.toJsObject(appDataDictionary); | ||
updateUserInfo(userInfoJSON); | ||
_pendingNotifications.push(userInfoJSON); | ||
var asJs = utils_2.firebaseUtils.toJsObject(appDataDictionary.objectForKey("notification")); | ||
var asJs = utils_1.firebaseUtils.toJsObject(appDataDictionary.objectForKey("notification")); | ||
if (asJs) { | ||
@@ -383,3 +379,3 @@ userInfoJSON.title = asJs.title; | ||
} | ||
var app = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication); | ||
var app = UIApplication.sharedApplication; | ||
if (app.applicationState === 0) { | ||
@@ -401,3 +397,3 @@ userInfoJSON.foreground = true; | ||
var notificationSettings = UIUserNotificationSettings.settingsForTypesCategories(notificationTypes, null); | ||
utils_2.firebaseUtils.invokeOnRunLoop(function () { | ||
utils_1.firebaseUtils.invokeOnRunLoop(function () { | ||
app.registerForRemoteNotifications(); | ||
@@ -422,3 +418,3 @@ }); | ||
function _processPendingNotifications() { | ||
var app = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication); | ||
var app = UIApplication.sharedApplication; | ||
if (!app) { | ||
@@ -439,3 +435,3 @@ application.on("launch", function () { return _processPendingNotifications(); }); | ||
function _processPendingActionTakenNotifications() { | ||
var app = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication); | ||
var app = UIApplication.sharedApplication; | ||
if (!app) { | ||
@@ -475,3 +471,3 @@ application.on("launch", function () { return _processPendingNotifications(); }); | ||
var userInfo = notification.request.content.userInfo; | ||
var userInfoJSON = utils_2.firebaseUtils.toJsObject(userInfo); | ||
var userInfoJSON = utils_1.firebaseUtils.toJsObject(userInfo); | ||
if (_showNotificationsWhenInForeground || | ||
@@ -478,0 +474,0 @@ userInfoJSON["gcm.notification.showWhenInForeground"] === "true" || |
@@ -98,91 +98,96 @@ "use strict"; | ||
} | ||
var surfaceHolder = _this.surfaceView.getHolder(); | ||
var cameraFacingRequested = _this.preferFrontCamera ? android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT : android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK; | ||
var cameraInfo = new android.hardware.Camera.CameraInfo(); | ||
var requestedCameraId = android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK; | ||
for (var i = 0; i < android.hardware.Camera.getNumberOfCameras(); ++i) { | ||
android.hardware.Camera.getCameraInfo(i, cameraInfo); | ||
if (cameraInfo.facing === cameraFacingRequested) { | ||
requestedCameraId = i; | ||
break; | ||
try { | ||
var surfaceHolder = _this.surfaceView.getHolder(); | ||
var cameraFacingRequested = _this.preferFrontCamera ? android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT : android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK; | ||
var cameraInfo = new android.hardware.Camera.CameraInfo(); | ||
var requestedCameraId = android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK; | ||
for (var i = 0; i < android.hardware.Camera.getNumberOfCameras(); ++i) { | ||
android.hardware.Camera.getCameraInfo(i, cameraInfo); | ||
if (cameraInfo.facing === cameraFacingRequested) { | ||
requestedCameraId = i; | ||
break; | ||
} | ||
} | ||
} | ||
_this.camera = android.hardware.Camera.open(requestedCameraId); | ||
var sizePair = _this.selectSizePair(_this.camera, 1400, 1200); | ||
if (!sizePair) { | ||
console.log("Could not find suitable preview size."); | ||
return; | ||
} | ||
var pictureSize = sizePair.pictureSize; | ||
var previewSize = sizePair.previewSize; | ||
console.log("sizePair.pictureSize: " + pictureSize.width + "x" + pictureSize.height); | ||
console.log("sizePair.previewSize: " + previewSize.width + "x" + previewSize.height); | ||
var parameters = _this.camera.getParameters(); | ||
if (pictureSize) { | ||
parameters.setPictureSize(pictureSize.width, pictureSize.height); | ||
} | ||
parameters.setPreviewSize(previewSize.width, previewSize.height); | ||
parameters.setPreviewFormat(android.graphics.ImageFormat.NV21); | ||
_this.setRotation(_this.camera, parameters, requestedCameraId); | ||
if (parameters.getSupportedFocusModes().contains(android.hardware.Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) { | ||
parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); | ||
} | ||
if (_this.torchOn) { | ||
if (parameters.getSupportedFlashModes() && parameters.getSupportedFlashModes().contains(android.hardware.Camera.Parameters.FLASH_MODE_TORCH)) { | ||
parameters.setFlashMode(android.hardware.Camera.Parameters.FLASH_MODE_TORCH); | ||
_this.camera = android.hardware.Camera.open(requestedCameraId); | ||
var sizePair = _this.selectSizePair(_this.camera, 1400, 1200); | ||
if (!sizePair) { | ||
console.log("Could not find suitable preview size."); | ||
return; | ||
} | ||
} | ||
_this.camera.setParameters(parameters); | ||
_this.detector = _this.createDetector(); | ||
var onSuccessListener = _this.createSuccessListener(); | ||
var onFailureListener = _this.createFailureListener(); | ||
var metadata = new com.google.firebase.ml.vision.common.FirebaseVisionImageMetadata.Builder() | ||
.setFormat(com.google.firebase.ml.vision.common.FirebaseVisionImageMetadata.IMAGE_FORMAT_NV21) | ||
.setWidth(previewSize.width) | ||
.setHeight(previewSize.height) | ||
.setRotation(_this.rotation) | ||
.build(); | ||
var throttle = 0; | ||
_this.camera.setPreviewCallbackWithBuffer(new android.hardware.Camera.PreviewCallback({ | ||
onPreviewFrame: function (byteArray, camera) { | ||
if (_this.pendingFrameData !== null) { | ||
camera.addCallbackBuffer(_this.pendingFrameData.array()); | ||
_this.pendingFrameData = null; | ||
var pictureSize = sizePair.pictureSize; | ||
var previewSize_1 = sizePair.previewSize; | ||
console.log("sizePair.pictureSize: " + pictureSize.width + "x" + pictureSize.height); | ||
console.log("sizePair.previewSize: " + previewSize_1.width + "x" + previewSize_1.height); | ||
var parameters = _this.camera.getParameters(); | ||
if (pictureSize) { | ||
parameters.setPictureSize(pictureSize.width, pictureSize.height); | ||
} | ||
parameters.setPreviewSize(previewSize_1.width, previewSize_1.height); | ||
parameters.setPreviewFormat(android.graphics.ImageFormat.NV21); | ||
_this.setRotation(_this.camera, parameters, requestedCameraId); | ||
if (parameters.getSupportedFocusModes().contains(android.hardware.Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) { | ||
parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); | ||
} | ||
if (_this.torchOn) { | ||
if (parameters.getSupportedFlashModes() && parameters.getSupportedFlashModes().contains(android.hardware.Camera.Parameters.FLASH_MODE_TORCH)) { | ||
parameters.setFlashMode(android.hardware.Camera.Parameters.FLASH_MODE_TORCH); | ||
} | ||
if (!_this.bytesToByteBuffer.has(byteArray)) { | ||
console.log("Skipping frame"); | ||
return; | ||
} | ||
_this.camera.setParameters(parameters); | ||
_this.detector = _this.createDetector(); | ||
var onSuccessListener_1 = _this.createSuccessListener(); | ||
var onFailureListener_1 = _this.createFailureListener(); | ||
var metadata_1 = new com.google.firebase.ml.vision.common.FirebaseVisionImageMetadata.Builder() | ||
.setFormat(com.google.firebase.ml.vision.common.FirebaseVisionImageMetadata.IMAGE_FORMAT_NV21) | ||
.setWidth(previewSize_1.width) | ||
.setHeight(previewSize_1.height) | ||
.setRotation(_this.rotation) | ||
.build(); | ||
var throttle_1 = 0; | ||
_this.camera.setPreviewCallbackWithBuffer(new android.hardware.Camera.PreviewCallback({ | ||
onPreviewFrame: function (byteArray, camera) { | ||
if (_this.pendingFrameData !== null) { | ||
camera.addCallbackBuffer(_this.pendingFrameData.array()); | ||
_this.pendingFrameData = null; | ||
} | ||
if (!_this.bytesToByteBuffer.has(byteArray)) { | ||
console.log("Skipping frame"); | ||
return; | ||
} | ||
_this.pendingFrameData = _this.bytesToByteBuffer.get(byteArray); | ||
if (throttle_1++ % _this.processEveryNthFrame !== 0) { | ||
return; | ||
} | ||
var data = _this.pendingFrameData; | ||
if (_this.detector.processImage) { | ||
_this.lastVisionImage = com.google.firebase.ml.vision.common.FirebaseVisionImage.fromByteBuffer(data, metadata_1); | ||
_this.detector | ||
.processImage(_this.lastVisionImage) | ||
.addOnSuccessListener(onSuccessListener_1) | ||
.addOnFailureListener(onFailureListener_1); | ||
} | ||
else if (_this.detector.detectInImage) { | ||
_this.lastVisionImage = com.google.firebase.ml.vision.common.FirebaseVisionImage.fromByteBuffer(data, metadata_1); | ||
_this.detector | ||
.detectInImage(_this.lastVisionImage) | ||
.addOnSuccessListener(onSuccessListener_1) | ||
.addOnFailureListener(onFailureListener_1); | ||
} | ||
else { | ||
_this.runDetector(data, previewSize_1.width, previewSize_1.height); | ||
} | ||
} | ||
_this.pendingFrameData = _this.bytesToByteBuffer.get(byteArray); | ||
if (throttle++ % _this.processEveryNthFrame !== 0) { | ||
return; | ||
} | ||
var data = _this.pendingFrameData; | ||
if (_this.detector.processImage) { | ||
_this.lastVisionImage = com.google.firebase.ml.vision.common.FirebaseVisionImage.fromByteBuffer(data, metadata); | ||
_this.detector | ||
.processImage(_this.lastVisionImage) | ||
.addOnSuccessListener(onSuccessListener) | ||
.addOnFailureListener(onFailureListener); | ||
} | ||
else if (_this.detector.detectInImage) { | ||
_this.lastVisionImage = com.google.firebase.ml.vision.common.FirebaseVisionImage.fromByteBuffer(data, metadata); | ||
_this.detector | ||
.detectInImage(_this.lastVisionImage) | ||
.addOnSuccessListener(onSuccessListener) | ||
.addOnFailureListener(onFailureListener); | ||
} | ||
else { | ||
_this.runDetector(data, previewSize.width, previewSize.height); | ||
} | ||
})); | ||
_this.camera.addCallbackBuffer(_this.createPreviewBuffer(previewSize_1)); | ||
_this.camera.addCallbackBuffer(_this.createPreviewBuffer(previewSize_1)); | ||
_this.camera.addCallbackBuffer(_this.createPreviewBuffer(previewSize_1)); | ||
_this.camera.addCallbackBuffer(_this.createPreviewBuffer(previewSize_1)); | ||
_this.camera.setPreviewDisplay(surfaceHolder); | ||
if (!_this.pause) { | ||
_this.camera.startPreview(); | ||
} | ||
})); | ||
_this.camera.addCallbackBuffer(_this.createPreviewBuffer(previewSize)); | ||
_this.camera.addCallbackBuffer(_this.createPreviewBuffer(previewSize)); | ||
_this.camera.addCallbackBuffer(_this.createPreviewBuffer(previewSize)); | ||
_this.camera.addCallbackBuffer(_this.createPreviewBuffer(previewSize)); | ||
_this.camera.setPreviewDisplay(surfaceHolder); | ||
if (!_this.pause) { | ||
_this.camera.startPreview(); | ||
} | ||
catch (e) { | ||
console.log("Error in Firebase MLKit's runCamera function: " + e); | ||
} | ||
}, 500); | ||
@@ -189,0 +194,0 @@ }; |
{ | ||
"name": "nativescript-plugin-firebase", | ||
"version": "9.0.1", | ||
"version": "9.0.2", | ||
"description": "Fire. Base. Firebase!", | ||
@@ -5,0 +5,0 @@ "main": "firebase", |
Sorry, the diff of this file is too big to display
4043556
17433