SSE in React native

Viewed 1378

how can i use SSE (server sent events) in react native ?, I have not been able to get it to work,

I try with https://github.com/jordanbyron/react-native-event-source and https://github.com/JonnyBGod/react-native-eventsource but dont work,

My backend api is with spring webflux

import React, {memo, useState, useEffect} from 'react';
import {Navigation} from '../types'
import AppBarHeader from "../components/AppBarHeader";
import RNEventSource from 'react-native-event-source'

type Props = {
    navigation: Navigation;
};

const MessageScreen = ({navigation}: Props) => {

    const getMessages = (email: string) => {

        console.log('obteniendo evt source')

        const options = { headers: { Authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJ1c2VyQHRlc3QuY29tIiwic2NvcGUiOlsicmVhZCIsIndyaXRlIl0sIlVTRVJfSUQiOiI1ZWViYzY4ZmIyMDBlNTAyMjIyNTcyYTEiLCJleHAiOjE1OTI3MDQ0MzAsIkxBU1RfTkFNRSI6IlJvZHJpZ3VleiIsIkVNQUlMIjoidXNlckB0ZXN0LmNvbSIsImF1dGhvcml0aWVzIjpbIlJPTEVfVVNFUiJdLCJqdGkiOiJiNjE3YzE0My04MjhjLTQ3M2ItOGJkNC00MWQ5MmUwN2FkNjUiLCJGSVJTVF9OQU1FIjoiSnVhbiIsImNsaWVudF9pZCI6Im1lZGljYXBwIn0.fNDzx8sjOt1YxwQoxNdlBqXZ6XcMhXGxZQNktAHxmWw'}};

        const eventSource = new RNEventSource('http://localhost:8080/chat', options);

        eventSource.addEventListener('message', (data) => {
            console.log(data.type); // message
            console.log(data.data);
        });

    }

    getMessages('das');

    return (
        <>
            <AppBarHeader navigation={navigation} title={'Chat'} />

        </>
    );
};

export default memo(MessageScreen);

Console log

Thanks

0 Answers
Related