6

I am new to Android development and I am trying to add a chatroom to my android app, powered by Rail's new actioncable. I currently have the chatroom working using Firebase which is cool. However, I would like to have additional features which aren't supported by Firebase so I want to move everything to my server. Problem is I don't know much about websockets on android.

Below is the javascript information being used on the rails browser side. This works without and issue.

hostname = (url) ->
  parser = document.createElement('a')
  parser.href = url
  parser.href = parser.href
  parser.protocol = parser.protocol.replace("http", "ws")
  parser.href

@App = {}
App.cable = Cable.createConsumer hostname("/")

App.messages = App.cable.subscriptions.create "MessagesChannel",
  received: (data) ->
    messages = $('#messages')
    messages.append(data.message)
    messages.scrollTop(messages.height() + 1000)
dnwilson
  • 147
  • 2
  • 10

1 Answers1

1

Actioncable logic is not so different with other common websocket framework. There are many Android websocket libraries.

try,
https://github.com/codebutler/android-websockets

And,
full document of actioncable is not ready yet.(https://github.com/rails/rails/issues/22673)

you should try reading source document of front-end actioncable framework(coffeescript). https://github.com/rails/actioncable/blob/master/lib/assets/javascripts/cable/consumer.coffee https://github.com/rails/actioncable/blob/master/lib/assets/javascripts/cable/subscription.coffee

Jaehyun Shin
  • 1,562
  • 14
  • 25
  • I gave in and just build a chat app with Node.js + Express + socket.io and authenticate with my rails server – dnwilson Dec 20 '15 at 03:58
  • [codebutler/android-websocket](https://github.com/codebutler/android-websockets) does not perform the [closing handshake](https://tools.ietf.org/html/rfc6455#section-7) which is required by [RFC 6455](https://tools.ietf.org/html/rfc6455) and may throw an exception on close. See [this](http://stackoverflow.com/a/30185251/1174054) for details. – Takahiko Kawasaki Dec 20 '15 at 06:49
  • @fiyah Yes, that is a good option, and there are many good websocket libraries, faye(actioncable uses faye) and eventmachine. another option is puser.com. Good luck! – Jaehyun Shin Dec 21 '15 at 07:21