Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I connect android to actioncable websocket connection?

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)
like image 750
dnwilson Avatar asked Nov 27 '15 13:11

dnwilson


1 Answers

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

like image 179
Jaehyun Shin Avatar answered Oct 20 '22 15:10

Jaehyun Shin