<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Swarup Das</title>
    <description>The latest articles on DEV Community by Swarup Das (@dasswarup).</description>
    <link>https://dev.to/dasswarup</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F752699%2Fcd5e3a5e-0bf7-41cc-89c6-88db0aeb7295.jpg</url>
      <title>DEV Community: Swarup Das</title>
      <link>https://dev.to/dasswarup</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dasswarup"/>
    <language>en</language>
    <item>
      <title>The magic behind video upload process in social media</title>
      <dc:creator>Swarup Das</dc:creator>
      <pubDate>Wed, 05 Feb 2025 08:29:31 +0000</pubDate>
      <link>https://dev.to/dasswarup/the-magic-behind-video-upload-process-in-social-media-2dl</link>
      <guid>https://dev.to/dasswarup/the-magic-behind-video-upload-process-in-social-media-2dl</guid>
      <description>&lt;p&gt;This is the era of social media. We see uncountable short form content these days, also known as reels or shorts or maybe stories and statuses. But have you ever wondered what happens when you press that upload or post button? &lt;br&gt;
It might seem just a simple upload to the database and then distribution of that to the bigger mass - NO! not just it. A bunch of logic goes behind the whole process and let's decode it ☕&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq2lguq3kzjg8cybz4n4v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq2lguq3kzjg8cybz4n4v.png" alt="Coffee with code" width="800" height="556"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  The journey
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The user creates a content, edits it and then goes to upload.&lt;/li&gt;
&lt;li&gt;When the user uploads the reel, it goes through a pipeline which has some set of compression processes. &lt;/li&gt;
&lt;li&gt;The backend handles the video and compress it down to a desired bitrate for which the size of the reel is now reduced from the originally uploaded content. This size difference is massive!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For reference let's say you upload a video of 90 MB, and it is going through the pipeline. Now after the process is finished the video is now about 25-30 MB, incredible isn't it!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The average percentage compression from the above example comes down as-

                   90-25
 % compression =   ------ x 100 % = 72.222%
                    90
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;After the compression it simply follows the same method of uploading to the database and then comes to our feed.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: This is a simple overview but the market leading social medias are designed in such a way that it stores different version on top of compression (and their compression method can differ than mine) and shows us the best version according to our internet speed! &lt;br&gt;
&lt;em&gt;We will save that part for another blog 😉&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Breakdown of compression
&lt;/h3&gt;

&lt;p&gt;I will be explaining just the compression part with two packages called &lt;em&gt;ffmpeg-static&lt;/em&gt; and &lt;em&gt;fluent-ffmpeg&lt;/em&gt; you can easily find it in the &lt;a href="https://www.npmjs.com/package/ffmpeg-static" rel="noopener noreferrer"&gt;npm&lt;/a&gt; library. Again, it's just an overview and you can definitely implement this method for video compression or any tool, it is not necessarily what Instagram or YouTube uses. Atleast it gets the job done 👀&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgp1frbb9vm0br0h4oj80.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgp1frbb9vm0br0h4oj80.png" alt="It gets the job done gif" width="356" height="200"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Now let's get going to some technical stuff ☕&lt;/p&gt;

&lt;p&gt;This part is based on pure backend, and I am using NodeJs and ExpressJs for the backend server. Before going to raw code let's just analyze the process a bit more in depth.&lt;/p&gt;

&lt;p&gt;My method is used for compression and as well as storing the video in a dedicated database after compression and returns with the compressed video URL. The database part can vary since I have used a simple approach using firebase for demonstration.&lt;/p&gt;

&lt;h2&gt;
  
  
  What goes inside the function
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We accept the video from the request body.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const inputFilePath = req.file.path;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The function is configured to accept both the video and the firebase endpoint where to store the compressed video.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function compressAndUploadVideo(inputFilePath, firebaseStoragePath){
//function body
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;There is a package &lt;a href="https://www.npmjs.com/package/multer" rel="noopener noreferrer"&gt;"multer"&lt;/a&gt;, which is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files. This will create a temporary folder where the file from request body gets stored for processing.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const upload = multer({ dest: 'uploads/' }); //dest: destination, refer package documentation
.
.
.
app.post('/endpoint', upload.single('video'), async (req, res) =&amp;gt; {
//function body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; Before the compression begins the ffmpeg path has to be specified and this is done by the &lt;em&gt;ffmpeg-static&lt;/em&gt; package.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ffmpegPath = require('ffmpeg-static');
const ffmpeg = require('fluent-ffmpeg');

// Set the FFmpeg path from ffmpeg-static
ffmpeg.setFfmpegPath(ffmpegPath);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; Now the major compression is done by the &lt;em&gt;&lt;a href="https://www.npmjs.com/package/fluent-ffmpeg" rel="noopener noreferrer"&gt;fluent-ffmpeg&lt;/a&gt;&lt;/em&gt; package, which has it's own set of rules to modify the &lt;a href="https://en.wikipedia.org/wiki/Codec" rel="noopener noreferrer"&gt;codec&lt;/a&gt; and &lt;a href="https://www.adobe.com/creativecloud/video/discover/bit-rate.html#:~:text=%E2%80%9CBitrate%20refers%20to%20depth%20of,%2C%20resolution%2C%20or%20video%20format." rel="noopener noreferrer"&gt;bitrate&lt;/a&gt; of the video. By lowering down the bitrate the size of the video decreases which turns out to be video compression and makes it suitable to be uploaded to the database and won't cause trouble in playing in any device.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await new Promise((resolve, reject) =&amp;gt; {
  ffmpeg(inputFilePath)
    .output(outputFilePath)
    .videoCodec('libx264')
    .audioCodec('aac')
    .on('end', () =&amp;gt; resolve())
    .on('error', (err) =&amp;gt; reject(new Error(`Error compressing video: ${err.message}`)))
    .run();
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The &lt;a href="https://www.npmjs.com/package/fs" rel="noopener noreferrer"&gt;"fs"&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/path" rel="noopener noreferrer"&gt;"path"&lt;/a&gt; modules play a crucial role to take the video from the response and process it in the API with some file based operations like reading and writing and stores it in a temporary location for uploading to firebase or any other database
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const outputFilePath = path.join(__dirname, 'filename.mp4');
.
.
.
// Upload to Firebase Storage
  const storageFile = bucket.file(firebaseStoragePath);
  await storageFile.save(fs.readFileSync(outputFilePath), {
   contentType: 'video/mp4'
  });
.
.
.
 // Clean up temporary file
  if (fs.existsSync(outputFilePath)) {
    fs.unlinkSync(outputFilePath);
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The entire function
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = require('fs');
const path = require('path');
const ffmpegPath = require('ffmpeg-static');
const ffmpeg = require('fluent-ffmpeg');
const admin = require('firebase-admin');

// Set the FFmpeg path from ffmpeg-static
ffmpeg.setFfmpegPath(ffmpegPath);

const bucket = admin.storage().bucket();

/**
 * Compresses a video file using FFmpeg, uploads it to Firebase Storage, and updates a Firestore document.
 * @param {string} inputFilePath - Path to the input video file.
 * @param {string} firebaseStoragePath - Path in Firebase Storage where the video will be uploaded.
 * @returns {Promise&amp;lt;string&amp;gt;} - The download URL of the uploaded video.
 */
async function compressAndUploadVideo(inputFilePath, firebaseStoragePath) {
    const outputFilePath = path.join(__dirname, 'compressed_video.mp4');

    try {
        // Compress the video using FFmpeg (fluent-ffmpeg)
        await new Promise((resolve, reject) =&amp;gt; {
            ffmpeg(inputFilePath)
                .output(outputFilePath)
                .videoCodec('libx264')
                .audioCodec('aac')
                .on('end', () =&amp;gt; resolve())
                .on('error', (err) =&amp;gt; reject(new Error(`Error compressing video: ${err.message}`)))
                .run();
        });

        // Upload to Firebase Storage
        const storageFile = bucket.file(firebaseStoragePath);
        await storageFile.save(fs.readFileSync(outputFilePath), {
            contentType: 'video/mp4'
        });

        // Get the download URL
        const downloadURL = await storageFile.getSignedUrl({
            action: 'read',
            expires: '03-01-2500' // Set a long expiration date
        });

        return downloadURL[0];
    } catch (error) {
        console.error('Error compressing and uploading video:', error);
        throw error;
    } finally {
        // Clean up temporary file
        if (fs.existsSync(outputFilePath)) {
            fs.unlinkSync(outputFilePath);
        }
    }
}

module.exports = compressAndUploadVideo;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Now you can import the &lt;em&gt;compressAndUploadVideo&lt;/em&gt; function and use it in the root as explained earlier and the compressed video will be ready at your provided output location.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you have came across till here make sure to follow me and you can also check my &lt;a href="https://github.com/Das-Swarup" rel="noopener noreferrer"&gt;github&lt;/a&gt;. I will be sharing more unique ideas with ☕. Comment down anything you feel to share, I am open to suggestions. Till then see ya'll ✌️&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>backend</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to implement push notifications in React Native (Android)</title>
      <dc:creator>Swarup Das</dc:creator>
      <pubDate>Thu, 19 Sep 2024 09:15:11 +0000</pubDate>
      <link>https://dev.to/dasswarup/how-to-implement-push-notifications-in-react-native-android-lll</link>
      <guid>https://dev.to/dasswarup/how-to-implement-push-notifications-in-react-native-android-lll</guid>
      <description>&lt;p&gt;Ever thought about the notifications we receive from the apps we installed? or How is Swiggy or Zomato provoking us to order food at 3 AM with their creative notifications? 🤔&lt;/p&gt;

&lt;p&gt;Let's dive deep into the concept of notifications!&lt;/p&gt;

&lt;h2&gt;
  
  
  What are notifications?
&lt;/h2&gt;

&lt;p&gt;A &lt;em&gt;notification&lt;/em&gt; is a message or alert sent by an app to inform users about updates, events, or actions, typically delivered outside the app's interface.&lt;/p&gt;

&lt;p&gt;Now there can be two types of notifications as shown below -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyirt0y9mxnxw5x9wbb5y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyirt0y9mxnxw5x9wbb5y.png" alt="Types of notifications" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Push Notification
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Push notifications are messages or alerts sent from a server to an app when the app is not actively running in the foreground. They are primarily used to keep users engaged by sending updates, reminders, or personalized content. Push notifications are delivered through operating system services like Apple Push Notification Service (APNs) for iOS or Firebase Cloud Messaging (FCM) for Android.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  How push notification works:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Registration: When the app is installed or first opened, the app requests a unique device token from the OS's push notification service (APNs or FCM).&lt;/li&gt;
&lt;li&gt;Server Communication: The app sends this token to the app's backend server, which stores it for future use.&lt;/li&gt;
&lt;li&gt;Sending Notifications: The server sends a notification payload (containing title, message, action buttons, etc.) to the push notification service (APNs/FCM) with the device token.&lt;/li&gt;
&lt;li&gt;Delivery: The push notification service delivers the message to the respective device, even if the app is not running.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  In-App Notification
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;In-app notifications are messages or alerts displayed to users while they are actively using the app. Unlike push notifications, these do not require server intervention and are triggered within the app itself, usually as a result of user actions or app events.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  How in-app notification works:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Event Trigger: When a specific event occurs inside the app (like a user reaching a milestone or a feature needing attention), the app can trigger an in-app notification.&lt;/li&gt;
&lt;li&gt;Display: The notification is shown as a banner, modal, or pop-up within the app's UI, guiding the user or informing them about the event.&lt;/li&gt;
&lt;li&gt;Custom Logic: In-app notifications are handled directly by the app’s code and can be shown dynamically based on the app’s internal state or logic.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Implementation in React Native android app:
&lt;/h2&gt;

&lt;p&gt;Now that we know about notifications and their types, it's time to implement the feature in your very own react native app. This guide is for implementing only push notification in React native android app only, if you want for iOS or in-app notification, write down a comment and I will post that for sure!&lt;/p&gt;

&lt;p&gt;To get started we will be using a third-party service called &lt;em&gt;OneSignal&lt;/em&gt;. I recently came across this platform and was shocked by the services they offer. &lt;/p&gt;

&lt;h4&gt;
  
  
  About OneSignal:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2mj47y4ywifwkpeykp3x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2mj47y4ywifwkpeykp3x.png" alt="OneSignal Logo" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;OneSignal&lt;/strong&gt; is a push notification service that enables app developers to send targeted notifications to users across various platforms, including mobile apps, websites, and email. It supports push, in-app, and web notifications, providing features like segmentation, automation, A/B testing, and real-time analytics. OneSignal is widely used for improving user engagement and retention by offering an easy-to-integrate solution for sending personalized messages. Their free tier consists of 10,000/month Free Email Sends, Unlimited Mobile Push Sends, Journeys Workflows, GDPR Compliant, A/B Testing&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Going back to the guide, since we already know that push notifications require server-side handling via FCM (Firebase Cloud Messaging) hence there are a few steps to follow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Set up firebase project (ignore first two steps if you already have firebase project):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to &lt;a href="https://console.firebase.google.com/" rel="noopener noreferrer"&gt;firebase console&lt;/a&gt; and log in to your account.&lt;/li&gt;
&lt;li&gt;Create a project from here and follow the steps
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxavzulugywnesdozxgj6.png" alt="create project card firebase" width="332" height="236"&gt;
&lt;/li&gt;
&lt;li&gt;Once your project is created go to project settings from the sidebar 
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpqtgi1vwsjd1rsy2dhdh.png" alt="project settings button" width="445" height="146"&gt;
&lt;/li&gt;
&lt;li&gt;Navigate to service accounts from the bar and it should look like this
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F26hqhwvnn7d7rr2ux797.png" alt="firebase service accounts" width="800" height="519"&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;strong&gt;&lt;em&gt;Generate new private key&lt;/em&gt;&lt;/strong&gt; and this will download a json file, carefully store it somewhere safe, we will be needing this while setting up OneSignal.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set up OneSignal&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to &lt;a href="https://dashboard.onesignal.com/signup" rel="noopener noreferrer"&gt;OneSignal&lt;/a&gt; and create an account.&lt;/li&gt;
&lt;li&gt;After creating an account go through the setup steps and create an organization and now, you'll see a page for adding apps.&lt;/li&gt;
&lt;li&gt;In this page give your app name and select &lt;em&gt;Google Android (FCM)&lt;/em&gt; for our case.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj4fh69sevpgd70v6bgol.png" alt="OneSignal app add page" width="800" height="603"&gt;
and click on &lt;strong&gt;&lt;em&gt;Configure Your Platform&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Now you will be redirected to this page where we'll be using the service account json file downloaded during firebase configuration
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy3fgcq970660btau8ena.png" alt="Add service account json OneSignal" width="800" height="324"&gt;
Upload the json and then &lt;em&gt;Save &amp;amp; Continue&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;On the next page select React Native/Expo as target SDK and then &lt;em&gt;Save &amp;amp; Continue&lt;/em&gt; again&lt;/li&gt;
&lt;li&gt;In the next screen you'll get your &lt;strong&gt;App ID&lt;/strong&gt;, this is a confidential id and using this id anyone can trigger notification in your app, so be careful with this secret.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;We are done with the setup in firebase and OneSignal, now the only task left is some &lt;em&gt;Coffee with Code&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Add OneSignal to your app and configure it
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Step 1: Add OneSignal to your app by running this command first
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i react-native-onesignal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Step 2: In your &lt;code&gt;index.js&lt;/code&gt; or &lt;code&gt;App.tsx&lt;/code&gt; or &lt;code&gt;App.js&lt;/code&gt; whichever is the root of your project, import OneSignal
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { OneSignal } from 'react-native-onesignal';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and you have add this code snippet to initialise OneSignal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OneSignal.initialize('YOUR_APP_ID');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can wrap this inside a &lt;code&gt;useEffect&lt;/code&gt; hook for seamless integration and connectivity with OneSignal.&lt;/p&gt;

&lt;p&gt;This will initialize the device with an unique ID on for OneSignal and you can check that in the subscriptions in the sidebar. Every device that gets initialized will be identified with this unique &lt;em&gt;OneSignal ID&lt;/em&gt; and you can set it manually also if you have users with their own unique id's already by using this code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OneSignal.login(userId)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the user is successfully subscribed, it will show in the dashboard like this&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53kdl06oglp3p8ytwz0e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53kdl06oglp3p8ytwz0e.png" alt="Subscription records" width="800" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Now you might come across some issues with OneSignal not being properly used or some critical errors so here is a part that you can follow which helped me resolve those issues.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Step 3: Inside your &lt;code&gt;android\app\build.gradle&lt;/code&gt; add this code snippet
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies{
...
implementation('com.onesignal:OneSignal:[3.15.4, 3.99.99]')
...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Step 4: In android for providing necessary permissions for push notifications, in &lt;code&gt;android\app\src\main\AndroidManifest.xml&lt;/code&gt; add
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;uses-permission android:name="android.permission.INTERNET" /&amp;gt;
&amp;lt;uses-permission android:name="android.permission.POST_NOTIFICATIONS" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;right before the &lt;code&gt;application&lt;/code&gt; tag. The INTERNET permission is optional however since it might be enabled by default.&lt;/p&gt;

&lt;p&gt;Boom🚀 All the steps are covered for implementing push notifications, and you can send a test notification from the OneSignal dashboard itself.&lt;/p&gt;

&lt;p&gt;Try out yourself and if any doubt you can comment below. Follow for more detailed guides!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;References: &lt;br&gt;
&lt;a href="https://documentation.onesignal.com/docs/react-native-sdk-setup" rel="noopener noreferrer"&gt;https://documentation.onesignal.com/docs/react-native-sdk-setup&lt;/a&gt;&lt;br&gt;
&lt;a href="https://documentation.onesignal.com/reference/push-notification" rel="noopener noreferrer"&gt;https://documentation.onesignal.com/reference/push-notification&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/tribalscale/mobile-push-notifications-implementation-in-react-native-with-one-signal-4e810dddd350" rel="noopener noreferrer"&gt;https://medium.com/tribalscale/mobile-push-notifications-implementation-in-react-native-with-one-signal-4e810dddd350&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy coding!🧑‍💻&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>android</category>
      <category>onesignal</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
