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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With