horizon icon indicating copy to clipboard operation
horizon copied to clipboard

React Native Chat Example

Open nivoc opened this issue 8 years ago • 11 comments

For #285


This change is Reviewable

nivoc avatar Apr 29 '16 10:04 nivoc

Awesome! Thanks for submitting this PR

deontologician avatar Apr 29 '16 16:04 deontologician

Hey @nivoc would you mind adding me as a collaborator on your fork so I can check out your branch?

cc: @mglukhovsky ^

dalanmiller avatar Apr 29 '16 17:04 dalanmiller

@dalanmiller Sure. Added.

nivoc avatar Apr 29 '16 18:04 nivoc

It sometime fails to connect (about 1 out of 10 times). Not sure yet why. Looks like some timing issue. Refresh helps (cmd+r in the simulator).

nivoc avatar Apr 29 '16 18:04 nivoc

This is awesome @nivoc thank you. @mbseid could you show us how you got around auth/token/AsyncStorage?

dalanmiller avatar Apr 29 '16 18:04 dalanmiller

Note: I've never done anything with react-native so the tool chain is new to me.

To get the example to run properly I had to run the npm start commands separately and there was maybe a race condition with the cli.js not being ready first I think. Not doing this gave me this error:

screenshot 2016-04-29 12 22 07

=== BUILD TARGET ReactNativeChatAppTests OF PROJECT ReactNativeChatApp WITH CONFIGURATION Debug ===

Check dependencies

** BUILD SUCCEEDED **

Installing build/Build/Products/Debug-iphonesimulator/ReactNativeChatApp.app
Launching org.reactjs.native.example.ReactNativeChatApp
org.reactjs.native.example.ReactNativeChatApp: 8227
events.js:154
      throw er; // Unhandled 'error' event
      ^

Error: This socket is closed.
    at Socket._writeGeneric (net.js:662:19)
    at Socket._write (net.js:714:8)
    at doWrite (_stream_writable.js:300:12)
    at writeOrBuffer (_stream_writable.js:286:5)
    at Socket.Writable.write (_stream_writable.js:214:11)
    at Socket.write (net.js:640:40)
    at Console.log (console.js:39:16)
    at process.<anonymous> (server.js:124:15)
    at emitOne (events.js:90:13)
    at process.emit (events.js:182:7)

Then once I had it going I could save and write to the database but it looks like the changefeed isn't working properly:

screenshot 2016-04-29 12 31 01 screenshot 2016-04-29 12 31 00

The console output above shows I'm typing things into it and they're being stored but nothing is returning to the view?

I might've missed something just let me know what I need to fix here @nivoc. This thing was surprisingly easy to get setup and build, react-native is really quite cool thank you for PRing this.

dalanmiller avatar Apr 29 '16 19:04 dalanmiller

@dalanmiller oh good to know. Yes it sound's like a 'not ready'. Works for me - but I may have been lucky with the timing on my machine :-)

About the Changefeed issue: Try to press Command+r on the "no messages yet" screen.

There is an issue. I was not able to track it down yet. For me it works in 9 out of 10 connects but it's may be worse on your system. Press Command+R several times. But yes - needs to be fixed ;-)

nivoc avatar Apr 29 '16 22:04 nivoc

Another thing is that the config.toml shouldn't be committed, since it has a token secret in it. I think it's good to have a convention that config.toml files never make it into the repo proper, to avoid confusion

deontologician avatar May 02 '16 17:05 deontologician

removed.

About the Changefeed-Issue. It's odd. The "watch"-subscription gets called on every start. And it's always possible to write. But sometimes does the horizon not return the values.

nivoc avatar May 02 '16 18:05 nivoc

I wonder if this is some artifact of WebSockets acting weird natively? Have you had other projects that use WebSockets without issues @nivoc or is this unique to Horizon?

dalanmiller avatar May 02 '16 22:05 dalanmiller

@dalanmiller I haven't used WebSockets in RN enough to tell. But at least there are no open Issues in RN that sound like it: https://github.com/facebook/react-native/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+websocket

nivoc avatar May 04 '16 12:05 nivoc