Giter Club home page Giter Club logo

file-share-and-messaging-application's Introduction

File-Share-And-Messaging

This is a website for sharing media,files and messages in groups or to individuals using pusher-js and rest api (without the support of any database). Demo Link : https://pusher-message.web.app/

Video Demo(click the image below πŸ‘‡πŸ‘‡πŸ‘‡to see the video demo)

IMAGE ALT TEXT HERE

Frontend setup

Use the package manager npm

cd frontend && npm install

Backend setup

Use the package manager npm

cd backend && npm install

Frontend usage

Available Scripts

In the project directory, you can run:

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

Usage

Alt text

  • Enter your name
  • Press the generate or check ID button to create an ID

Alt text

  • Share this id to people with whom you want to communicate and send media files

Backend usage

Use the package manager npm

node index.js

UUID

A universally unique identifier ( UUID ) is a 128-bit number used to identify information in computer systems.We are using uuid to make unique groups with multiple members who can exchange data among themselves


Frontend Architecture

The frontend is completely made in react and is hosted on firebase hostings.

Extra Libraries we used:

*Axios: Axios is a popular, promise-based HTTP client that sports an easy-to-use API and can be used in both the browser and Node. js. Making HTTP requests to fetch or save data

*FS:js File System. Node. js includes fs module to access physical file system. The fs module is responsible for all the asynchronous or synchronous file I/O operations.

Working of Frontend

Like as shown in the diagram we communicate with other servers running the same frontend using pusher.Pusher Connections are made active on all the browsers when the site is opened we send information to pusher and pusher sends the data to these connections demanding for that call.

Pusher Connection

 channel1.bind(id, (data) => {
      setMessage1([data]);
    });
    channel2.bind(id, (data) => {
      console.log(data);
      setMessage2([data]);
    });

    return () => {
      channel1.unbind_all();
      channel1.unsubscribe();
      channel2.unbind_all();
      channel2.unsubscribe();
    };

We return unbind_all() and unsubscribe() function as a cleanup function to avoid multiple connections in the same channel.

-->Channel1 is for to listen to new messages

-->Channel2 is for to listen to new files uploaded

Frontend file upload

upload(file, onUploadProgress) {
    let formData = new FormData();

    formData.append("file", file);

    return http.post("/upload", formData, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
      onUploadProgress,
    });
  }

File is being uploaded on the backend Server In the /uploads directory in the Backend using Rest api.

Frontend file download

 UploadService.upload(curFile, (event) => {
      setProgress(Math.round((100 * event.loaded) / event.total));
    })
      .then((response) => {
        setMessage(response.message);
        return UploadService.getFiles();
      })
      .then(() => {
        axios
          .post(`http://localhost:8080/fileshare/${id}`, {
            name: curFile.name,
          })
          .then(() => console.log(`Sent`))
          .catch(function (error) {
            console.log(error);
          });
      })

This is a javascript promise where when the file is uploaded ,we do a post request on the api to send name of the file and group Uuid to pusher so that all the pusher connections get to know if the file from the required uuid is to be taken into their group with same uuid and their link to be uploaded for download.

Frontend Messaging system

axios.post(`http://localhost:8080/message/${id}`, {
         name: name,
         message: typed,
         date: getDate(),
})

The message service is similar to the file upload system.Here User name,message and current time along with the group’s uuid is sent to the pusher and made available for the connections with same group uuid to get the data

Backend Architecture

The backend is developed in NodeJS and the rest api is created using ExpressJS .PusherJS is used for sending data to the active pusher connections.

API Endpoints

router.post("/message/:room",message)
    router.post("/upload",upload)
    router.get("/files",getListFiles)
    router.get("/files/:name",download)
    router.post("/fileshare/:room",fileshare)
    router.get("/",welcome)

Various endpoints are created for the Api to perform get and post requests The names suggest their Functionalities and their code Can be seen in the git repository

File storage in the backend

let storage = multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, __basedir + "/uploads/");
  },
  filename: (req, file, cb) => {
    console.log(file.originalname);
    cb(null, file.originalname);
  },
});

For storing file we use multer middleware Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files. It is written on top of busboy for maximum efficiency. All the incoming files are getting Stored in the /uploads directory

Picture

THANK YOU

file-share-and-messaging-application's People

Contributors

sanand34 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

file-share-and-messaging-application's Issues

Opportunity at Our Stealth Startup

I hope this message finds you well. I recently came across your profile. Given your expertise and enthusiasm, we believe you could make a valuable contribution to our team.
If you're open to discussing this further, could you please share your Telegram ID or contact with me? You can reach me at rahul10110 on telegram. Let's connect and chat about how you could potentially fit into our startup.

Thank you for considering this opportunity. I look forward to hearing from you soon.

I have also sent you a mail regarding this.

Best regards,
Rahul

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.