Skip to content

Commit

Permalink
Merge pull request #51 from humhub/fix/update-firebase-version
Browse files Browse the repository at this point in the history
Update firebase to v10.6.0
  • Loading branch information
luke- authored Oct 18, 2024
2 parents 95ec401 + f5f8b5c commit accd1e1
Show file tree
Hide file tree
Showing 15 changed files with 782 additions and 211 deletions.
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
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',
];

}
16 changes: 8 additions & 8 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.14.1"
},
"replace": {
"npm-asset/firebase--app": "*",
Expand All @@ -21,14 +21,14 @@
"npm-asset/firebase--performance": "*",
"npm-asset/firebase--util": "*"
},



"provide": {
"npm-asset/undici": "*"
},
"config": {
"process-timeout": 1800,
"platform": {
"php": "8.1"
}
"platform": {
"php": "8.1"
}
},
"repositories": [
{
Expand Down
Loading

0 comments on commit accd1e1

Please sign in to comment.