Skip to content

Not working in React Native #633

@zju1

Description

@zju1

This is my code:

StompContainer.tsx

import { PropsWithChildren, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { useAuth } from "../../hooks/useAuth";
import { useAppDispatch } from "../../app/store/store.config";
import { envVars } from "../../constants/envVars";
import { Client, IMessage } from "@stomp/stompjs";
import { setSync } from "../../app/store/slices/auth.slice";

const client = new Client({
  brokerURL: envVars.SOCKET_URL,
  forceBinaryWSFrames: true,
  appendMissingNULLonIncoming: true,
  splitLargeFrames: true,
  webSocketFactory() {
    return new WebSocket(envVars.SOCKET_URL, ["wss", "ws", "https", "http"]);
  },
  onConnect(frame) {
    console.log(frame);
  },
  onStompError(frame) {
    console.log("STOMP ERROR", frame);
  },
  onWebSocketError: (evt) => {
    console.log("WebSocket ERROR", evt);
  },
});

export function StompContainer(props: PropsWithChildren) {
  const { user, sync } = useAuth();
  const dispatch = useAppDispatch();
  const { t } = useTranslation();

  useEffect(() => {
    if (user && !sync) {
      client.activate();
    }
  }, [dispatch, t, user, sync]);

  return props.children;
}

AndroidManifest.xml

<application
     ...
      android:usesCleartextTraffic="true"
      ...">

And the error is:

{"isTrusted": false, "message": "Expected HTTP 101 response but was '403 '"}

Tried everything on the internet. Not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions