{"id":19935047,"url":"https://github.com/nickersoft/push-fcm-plugin","last_synced_at":"2025-05-03T12:30:56.161Z","repository":{"id":58242354,"uuid":"94400712","full_name":"Nickersoft/push-fcm-plugin","owner":"Nickersoft","description":"Official Firebase Cloud Messaging plugin for Push.js v1.0 :fire: ","archived":false,"fork":false,"pushed_at":"2023-12-15T17:39:15.000Z","size":20,"stargazers_count":42,"open_issues_count":13,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T12:35:18.947Z","etag":null,"topics":["fcm","firebase","framework","javascript","js","notifications","plugin","push","pushjs"],"latest_commit_sha":null,"homepage":"https://pushjs.org","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nickersoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-15T04:47:12.000Z","updated_at":"2024-01-30T01:11:02.000Z","dependencies_parsed_at":"2024-11-19T20:46:39.862Z","dependency_job_id":null,"html_url":"https://github.com/Nickersoft/push-fcm-plugin","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"7220bd1d65d9f994795738e003077aaefd60ece1"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nickersoft%2Fpush-fcm-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nickersoft%2Fpush-fcm-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nickersoft%2Fpush-fcm-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nickersoft%2Fpush-fcm-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nickersoft","download_url":"https://codeload.github.com/Nickersoft/push-fcm-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252190631,"owners_count":21708914,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fcm","firebase","framework","javascript","js","notifications","plugin","push","pushjs"],"created_at":"2024-11-12T23:18:36.823Z","updated_at":"2025-05-03T12:30:55.728Z","avatar_url":"https://github.com/Nickersoft.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Push.js FCM Plugin\n\n## What is FCM?\nFCM, otherwise known as Firebase Cloud Messaging, is a free feature of the Google Firebase Platform, a collection of services for building scalable, effective web services. FCM allows web servers to send direct messages to a group of subscribers using ServiceWorkers. This means that by using this plugin, Push.js can now send targeted push notifications to a user's desktop without your website being open! Finally! :tada::tada::tada:\n\nThough, keep in mind this is the first plugin for Push.js, ever. Expect a few bumps and potholes.\n\n## Installing\nJust like Push itself, this module is easily installable via NPM or Bower:\n\n```bash\n$ npm install push-fcm-plugin --save\n$ bower install push-fcm-plugin --save \n```\n\n## How to Use\n### Configuring\nWith Push.js, managing FCM on your site becomes incredibly easy. To begin, you need to configure FCM Push's SafeConfig: Head on over to your [Firebase console](https://console.firebase.google.com/) and add a new project. Once the project is created, click on it and then click \"Add Firebase to your web app\". Select the configuration map from the generated code in the popup window and add it to your JavaScript file. Then, add the map to Push's FCM configuration using the `config()` method. Your finally code should look something like this:\n\n```javascript\nvar config = {\n    apiKey: \"\u003cYOUR_API_KEY\u003e\",\n    authDomain: \"\u003cYOUR_AUTH_DOMAIN\u003e\",\n    databaseURL: \"\u003cYOUR_DATABASE_URL\u003e\",\n    projectId: \"\u003cYOUR_PROJECT_ID\u003e\",\n    storageBucket: \"\u003cYOUR_STORAGE_BUCKET\u003e\",\n    messagingSenderId: \"\u003cYOUR_MESSAGE_SENDER_ID\u003e\"\n};\n\nPush.config({\n    FCM: config\n});\n```\n\nLastly, add a `manifest.json` file to the root of your web server with the following contents:\n  \n```json\n{\n    \"//\": \"Some browsers will use this to enable push notifications.\",\n    \"//\": \"It is the same for all projects, this is not your project's sender ID\",\n    \"gcm_sender_id\": \"103953800507\"\n}\n```\n\nthen import it into your HTML:\n\n```html\n\u003clink rel=\"manifest\" href=\"/manifest.json\"\u003e\n```\n\nThis sender ID is required in order to tell Firebase your website allows messages to be pushed to it. **Do not change the above ID.** It is the same for all Firebase projects, regardless of who you are or what you've built. \n\n### Using with AMD or CommonJS\nIf you use AMD or CommonJS to load Push, you'll have to manually install the plugin. \n\nFor AMD:\n\n```javascript\ndefine(['push', 'pushjs-fcm'], function (Push, PushFCM) {\n    Push.extend(PushFCM);\n});\n```\n\nFor CommonJS:\n\n```javascript\nconst Push = require('pushjs');\nconst PushFCM = require('pushjs-fcm');\n\nPush.extend(PushFCM);\n```\n\n### Initializing\nTo initialize FCM, just call:\n\n```javascript\nPush.FCM();\n```\n\nAnd that's it! You can then use the returned promise to run additional functions:\n\n```javascript\nPush.FCM().then(function(FCM) {\n    FCM.getToken().then(function(token) {\n        console.log(\"Initialized with token \" + token);\n    }).catch(function(tokenError) {\n       throw tokenError; \n    });\n}).catch(function(initError) {\n   throw initError; \n});\n```\n\nThe available functions are as follows:\n\n\n| Function                | Description                                                                                                         | Returns                      |\n|-------------------------|---------------------------------------------------------------------------------------------------------------------|------------------------------|\n| `getToken()`            | generates a new Instance ID token or retrieves the current one if it already exists                                 | Promise(token, error)        |\n| `deleteToken()`         | deletes the current token                                                                                           | Promise(deletedToken, error) |\n| `isTokenSentToServer()` | denotes whether the current token has been sent to the server via `sendTokenToServer()`  (see \"Additional Options\") | Boolean                      |\n\n### Additional Options\nThe FCM SafeConfig has a few additional options you can pass to it:\n\n- `serviceWorkerLocation`: Specifies directory containing the `firebase-messaging-sw` ServiceWorker script. May need to\nchange if Push has been installed via NPM or Bower. The default is `./`.\n- `onTokenFetched(token)`: Called when a new Instance ID token is retrieved\n- `onTokenFetchedError(error)`: Called if an error occurs while retrieving a new Instance ID token\n- `onPermissionRequired()` Called when permission is required to retrieve an Instance ID\n- `onPermissionGranted()`: Called when said permission is granted\n- `onPermissionDenied()`: Called when said permission is denied\n- `onMessage(payload)`: Called when a new message is received\n- `sendTokenToServer(token)`: Function that sends the given token to your server for future use \n- `onTokenDeleted(deletedToken)`: Called when the current token is deleted\n- `onTokenDeletedError(error)`: Called if an error occurs while deleting the current token\n\n### Sending Server-side Notifications\nTo send a notification to a given Instance ID from your server, simply make a POST request to `https://fcm.googleapis.com/fcm/send` with the following data:\n\nHeader\n```text\nAuthorization: key=\u003cYOUR_SERVER_KEY\u003e\nContent-Type: application/json\n```\n\nBody\n```json\n{ \n  \"notification\": {\n    \"title\": \"Notification Title\",\n    \"body\": \"Notification Body\",\n    \"click_action\" : \"http://example.com\"\n  },\n  \"to\" : \"\u003cINSTANCE_ID_TOKEN\u003e\"\n}\n```\n\nYou can find your server key by going to your project console on Firebase, clicking the gear icon on the right sidebar, selecting \"Project Settings\" and going to the \"Cloud Messaging\" tab. For more information on messaging types, read Google's [documentation on the topic](https://firebase.google.com/docs/cloud-messaging/concept-options#notifications).\n\n### Writing Your Own Plugin\nDocumentation on writing plugins will be coming the official Push.js docs soon!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickersoft%2Fpush-fcm-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnickersoft%2Fpush-fcm-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickersoft%2Fpush-fcm-plugin/lists"}