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

Add Socket broadcast for cross user transmission #1

Open
silenteyesoncode opened this issue May 6, 2023 · 6 comments
Open

Add Socket broadcast for cross user transmission #1

silenteyesoncode opened this issue May 6, 2023 · 6 comments
Assignees
Labels
Back-end working on backend server enhancement New feature or request

Comments

@silenteyesoncode
Copy link
Member

silenteyesoncode commented May 6, 2023

Description 🚀

This task enables real-time communication between multiple users in an Expo app using Socket.IO broadcast by establishing a socket connection, emitting and receiving events, and broadcasting messages to all connected clients on the server.

Files 🚨

Socket

To Reproduce ✅

This is a task that outlines the steps to add Socket broadcast for cross-user transmission with Expo app as a client. By following these steps, you will be creating a new React Native project with Expo, installing and using the Socket.IO client library, establishing a socket connection to the server, emitting and receiving events, adding event handlers to handle incoming messages, and broadcasting messages to all connected clients on the server. This task aims to enable real-time communication between multiple users in an Expo app using Socket.IO broadcast.

Task✅

Objective

To enable real-time communication between multiple users in an Expo app using Socket.IO broadcast.

Prerequisites

  • Node.js and npm installed
  • Basic knowledge of React Native and Expo
  • Basic knowledge of Socket.IO

Steps

  1. Create a new React Native project with Expo using the following command:

    expo init my-app
    
  2. Install the Socket.IO client for React Native using the following command:

    npm install socket.io-client
    
  3. Create a new component called Chat in your project.

  4. In the Chat component, import the Socket.IO client library using the following code:

    import io from 'socket.io-client';
  5. In the Chat component, create a new socket connection to the server using the following code:

    const socket = io('http://localhost:3000');

    Note: Change the URL to the URL of your Socket.IO server.

  6. Use the socket object to emit and receive events. For example, to send a message to all connected clients, use the following code:

    socket.emit('message', 'Hello, world!');
  7. To receive messages from other clients, use the following code:

    socket.on('message', (data) => {
      console.log(data);
    });
  8. Add event handlers to your Chat component to handle incoming messages and send messages to other clients.

  9. On the server side, add the following code to broadcast messages to all connected clients:

    io.on('connection', (socket) => {
      socket.on('message', (data) => {
        io.emit('message', data);
      });
    });
  10. Test your app by running it on multiple devices or emulators and sending messages between them.

@silenteyesoncode silenteyesoncode added the enhancement New feature or request label May 6, 2023
@silenteyesoncode silenteyesoncode self-assigned this May 6, 2023
@silenteyesoncode
Copy link
Member Author

@all-contributors please add @silenteyesoncode for infrastructure

@allcontributors
Copy link
Contributor

@silenteyesoncode

I've put up a pull request to add @silenteyesoncode! 🎉

@silenteyesoncode
Copy link
Member Author

@all-contributors please add @nandini25-ag for code

@allcontributors
Copy link
Contributor

@silenteyesoncode

I've updated the pull request to add @nandini25-ag! 🎉

@silenteyesoncode silenteyesoncode added the Back-end working on backend server label May 7, 2023
@silenteyesoncode
Copy link
Member Author

@all-contributors please add @yogeshwar-chaudhari-20 for code

Copy link
Contributor

@silenteyesoncode

I've put up a pull request to add @yogeshwar-chaudhari-20! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Back-end working on backend server enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant