Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update firebase to v10.6.0 #51

Merged
merged 14 commits into from
Oct 18, 2024
Merged
31 changes: 11 additions & 20 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,18 @@ public static function onServiceWorkerControllerInit($event): void
// Service Worker Addons
$controller->additionalJs .= <<<JS
// Give the service worker access to Firebase Messaging.
importScripts('{$bundle->baseUrl}/firebase-app.js');
importScripts('{$bundle->baseUrl}/firebase-messaging.js');
//importScripts('https://www.gstatic.com/firebasejs/6.3.3/firebase-app.js');
//importScripts('https://www.gstatic.com/firebasejs/6.3.3/firebase-messaging.js');

firebase.initializeApp({messagingSenderId: "{$pushDriver->getSenderId()}"});

const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
const notificationTitle = payload.data.title;
const notificationOptions = {
body: payload.data.body,
icon: payload.data.icon
};
return self.registration.showNotification(notificationTitle, notificationOptions);
importScripts('{$bundle->baseUrl}/firebase-app-compat.js');
importScripts('{$bundle->baseUrl}/firebase-messaging-compat.js');

firebase.initializeApp({
messagingSenderId: "{$pushDriver->getSenderId()}",
projectId: "{$module->getConfigureForm()->getJsonParam('project_id')}",
appId: "{$module->getConfigureForm()->firebaseAppId}",
apiKey: "{$module->getConfigureForm()->firebaseApiKey}",
});

// Initialize Firebase Cloud Messaging and get a reference to the service
const messaging = firebase.messaging();
JS;
}

Expand All @@ -88,7 +84,6 @@ public static function onNotificationInfoWidget($event)
$baseStack = $event->sender;

$baseStack->addWidget(PushNotificationInfoWidget::class);

}

public static function onLayoutAddonInit($event)
Expand Down Expand Up @@ -118,7 +113,6 @@ public static function onLayoutAddonInit($event)

FcmPushAsset::register(Yii::$app->view);
FirebaseAsset::register(Yii::$app->view);

}

public static function onAfterLogout()
Expand All @@ -142,8 +136,5 @@ public static function onAuthChoiceBeforeRun(Event $event)
if (MobileAppHelper::isIosApp() && $module->getConfigureForm()->disableAuthChoicesIos) {
$sender->setClients([]);
}


}

}
28 changes: 19 additions & 9 deletions assets/FcmPushAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,51 @@

namespace humhub\modules\fcmPush\assets;

use humhub\components\assets\AssetBundle;
use humhub\modules\fcmPush\Module;
use humhub\modules\fcmPush\services\DriverService;
use Yii;
use yii\helpers\Url;
use yii\web\AssetBundle;

class FcmPushAsset extends AssetBundle
{
/**
* @inheritdoc
*/
public $defer = false;

public $publishOptions = [
'forceCopy' => true,
];

/**
* @inheritdoc
*/
public $sourcePath = '@fcm-push/resources/js';

/**
* @inheritdoc
*/
public $js = [
'humhub.firebase.js',
];

/**
* @inheritdoc
*/
public static function register($view)
{
/** @var Module $module */
/* @var Module $module */
$module = Yii::$app->getModule('fcm-push');

$pushDriver = (new DriverService($module->getConfigureForm()))->getWebDriver();
if ($pushDriver !== null) {
Yii::$app->view->registerJsConfig('firebase', [
'tokenUpdateUrl' => Url::to(['/fcm-push/token/update']),
'senderId' => $pushDriver->getSenderId(),
'projectId' => $module->getConfigureForm()->getJsonParam('project_id'),
'apiKey' => $module->getConfigureForm()->firebaseApiKey,
'appId' => $module->getConfigureForm()->firebaseAppId,
'vapidKey' => $module->getConfigureForm()->firebaseVapidKey,
]);

return parent::register($view);
}


return parent::register($view);
}
}
24 changes: 12 additions & 12 deletions assets/FirebaseAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@

namespace humhub\modules\fcmPush\assets;

use humhub\modules\ui\view\components\View;
use yii\web\AssetBundle;
use humhub\components\assets\AssetBundle;

class FirebaseAsset extends AssetBundle
{
/**
* @inheritdoc
*/
public $defer = false;

public $publishOptions = [
'forceCopy' => false,

];

/**
* @inheritdoc
*/
public $sourcePath = '@fcm-push/vendor/npm-asset/firebase';

/**
* @inheritdoc
*/
public $js = [
'firebase-app.js',
'firebase-messaging.js',
//'https://www.gstatic.com/firebasejs/6.3.3/firebase-app.js',
//'https://www.gstatic.com/firebasejs/6.3.3/firebase-messaging.js'
'firebase-app-compat.js',
'firebase-messaging-compat.js',
];

}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"type": "library",
"require": {
"php": ">=8.0",
"kreait/firebase-php": "^7.13.1",
"npm-asset/firebase": "6.3.3"
"kreait/firebase-php": "7.15.x",
"npm-asset/firebase": "10.6.x"
},
"replace": {
"npm-asset/firebase--app": "*",
Expand Down
Loading
Loading