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

Realtime sdk not working in android emulator #22098

Closed
useEffects opened this issue Apr 4, 2024 · 5 comments · Fixed by #22105
Closed

Realtime sdk not working in android emulator #22098

useEffects opened this issue Apr 4, 2024 · 5 comments · Fixed by #22105

Comments

@useEffects
Copy link
Contributor

useEffects commented Apr 4, 2024

Describe the Bug

.connect() failing in android emulator in expo react native project, expo SDK version 50. Not reproducible in expo web

To Reproduce

Create a fresh project of directus and expo app, enable websockets in directus and run the projects

// App.js

import { createDirectus, realtime, staticToken } from '@directus/sdk';
import { StatusBar } from 'expo-status-bar';
import { useEffect } from 'react';
import { StyleSheet, Text, View } from 'react-native';

const token = "QuQp3aEtGr2C-uE0jo07B63mE7qHMhTH"
const url = "ws://192.168.0.109:8055/websocket"

const client = createDirectus(url)
  .with(staticToken(token))
  .with(realtime());

const run = async () => {
  const data = await fetch("http://192.168.0.109:8055/users/me", {
    headers: {
      "Authorization": `Bearer ${token}`
    }
  }).then(res => res.json())
  console.log(data) // token works!

  const ws = new WebSocket(url)
  ws.onopen = (d) => {
    console.log(JSON.stringify(d)) // works
  }

  client.connect().then(w => console.log(w))
}

export default function App() {
  useEffect(() => {
    run()
  }, []);

  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Directus Version

10.10.4

Hosting Strategy

Self-Hosted (Custom)

@useEffects
Copy link
Contributor Author

image
Actual error in the emulator

@useEffects
Copy link
Contributor Author

image
Site reachable in emulator

@br41nslug
Copy link
Member

Can you show where it is actually failing? im not seeing a web request / websocket error in the provided description or screenshots 😬

@useEffects
Copy link
Contributor Author

It fails on whatever route you call the .connect() method, ive tried using the expo debugger but couldnt find an error stack. Its just fails and the only error message is that screenshot

@useEffects
Copy link
Contributor Author

useEffects commented Apr 5, 2024

  E  Exception in native call
java.lang.ClassCastException: com.facebook.react.bridge.ReadableNativeMap cannot be cast to java.lang.String
    at com.facebook.react.bridge.ReadableNativeArray.getString(ReadableNativeArray.java:102)
    at com.facebook.react.bridge.JavaMethodWrapper$5.extractArgument(JavaMethodWrapper.java:73)
    at com.facebook.react.bridge.JavaMethodWrapper$5.extractArgument(JavaMethodWrapper.java:69)
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:356)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:149)
    at com.facebook.jni.NativeRunnable.run(Native Method)
    at android.os.Handler.handleCallback(Handler.java:958)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:294)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:234)
    at java.lang.Thread.run(Thread.java:1012)

from android studio logcat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants