Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
553785c
Fix isConnected (#39)
ostap0207 Feb 21, 2019
67baf71
Fix max reconnectAfterMs (#41)
ostap0207 Feb 21, 2019
22c396c
Prepare version 0.1.7
Feb 27, 2019
d7acb33
Fix reply timeouts (#37)
dustinconrad Mar 4, 2019
ccdb9b6
Prepare version 0.1.8
Mar 4, 2019
e4efb05
Created new TimeoutTimer class which makes use of a ScheduledExecutor…
dsrees Apr 12, 2019
d043048
Client without Phx* prefix and matching phoenix 1.4 specs (#43)
dsrees Apr 16, 2019
ce34a27
Socket, Channel, and Presence Tests (#44)
May 1, 2019
ffde1ce
Prepare version 0.2.0
May 1, 2019
d87173d
Updated readme for socket name changes
May 1, 2019
0c3e28b
Downgrade okhttp to 3.12.2 (#47)
May 14, 2019
e7cbc79
Prepare version 0.2.1
May 14, 2019
3179fae
Fix WebSocketTransport not kicking off reconnect strategy (#49)
May 14, 2019
4c7db7a
Prepare version 0.2.2
May 14, 2019
f33dea9
Removed check of connectexception
May 14, 2019
2733ed5
Prepare version 0.2.3
May 14, 2019
dd2d61f
Added support for SSLException (#50)
May 14, 2019
2fd3720
Prepare version 0.2.4
May 14, 2019
86a20a2
Prepare 0.2.5
May 14, 2019
f65ba25
Moving heartbeat task to repeat at fixed rate (#52)
May 22, 2019
55e68ce
Prepare version 0.2.6
May 22, 2019
9439614
Chat Example (#55)
dsrees Jun 7, 2019
5130bd3
Updated gradle to 5.4.1 (#56)
Jun 13, 2019
a8729b3
JUnit 5 (#58)
Jun 13, 2019
a6ee05a
Calling of Java 8 method throws a runtime error in Android API < 24 (…
rawnsley Jun 14, 2019
a11852b
Convert Unit Tests to use JUnit 5 (#60)
Jun 19, 2019
84bdcd3
Optimize Socket Reconnect (#61)
Jun 20, 2019
93064af
Updated ManualDispatchQueue to run items scheduled during a tick (#62)
Jun 20, 2019
caf94bc
Refactor Channel Rejoins (#63)
Jun 20, 2019
e646990
Prepare version 0.3.0
Jun 21, 2019
77ba73c
Prevent entering a rejoin loop if channel leaves before joined (#64)
Jun 25, 2019
eaf9504
Fixed concurrent exception (#66)
Jul 8, 2019
2d5c52f
Prepare version 0.3.1
Jul 8, 2019
3a84464
Fix Concurrency issues with StateChange hooks and add/removing channe…
Aug 8, 2019
0f9d111
Prepare release 0.3.2
Aug 8, 2019
bc25e20
Cleaned up adding and removing from array syntax
Aug 8, 2019
4dfdd0a
Allow Payload value set nullable (#72)
AlonParker Oct 2, 2019
4b9fbb1
Update Socket constructor to accept Map insted of Payload (#73)
dsrees Oct 2, 2019
db797c9
Prepare version 0.3.3
Nov 4, 2019
99584da
Revert "Update Socket constructor to accept Map insted of Payload (#7…
dsrees Nov 4, 2019
f879632
Prepare version 0.3.4
Nov 4, 2019
7ae134b
Replace jcenter with maven central
dsrees Mar 19, 2021
2222d95
Merge pull request #77 from dsrees/jcenter-to-maven
dsrees Mar 19, 2021
2270e90
Updated client to match swift client
dsrees Mar 22, 2021
0246170
Merge pull request #79 from dsrees/update-to-swift-client
dsrees Mar 22, 2021
fce3049
Prepare version 0.4.0
dsrees Mar 22, 2021
365ce86
fixed socket release logic
Apr 19, 2021
de13cd9
Merge pull request #81 from AlonParker/release_logic
dsrees Apr 19, 2021
edd2bf3
Prepare version 0.4.1
dsrees Apr 19, 2021
3019390
Allow providing params via a closure
dsrees Apr 20, 2021
53265a9
Merge pull request #83 from dsrees/feature/accept-params-closure
dsrees Apr 20, 2021
11f8ed0
prepare 0.5.0
dsrees Apr 20, 2021
d5009f2
Added EncodeClosure and DecodeClosure
dsrees Jul 23, 2021
ec36b7b
Merge pull request #85 from dsrees/feature/encode-decode-closures
dsrees Jul 23, 2021
deed980
Prepare version 0.6.0
dsrees Jul 23, 2021
709e35b
Unwrap response from within a reply payload
dsrees Oct 28, 2021
97fbf35
Merge pull request #87 from dsrees/dr/fix-message-response
dsrees Oct 28, 2021
1d29a2a
Prepare version 0.7.0
dsrees Oct 28, 2021
940d9dd
Upgrade test dependencies (#88)
AlvarezAriel Nov 22, 2021
5d82155
Using json serializer v2
dsrees Nov 22, 2021
e61989a
Merge pull request #89 from dsrees/feature/json-serializer-v2
dsrees Dec 14, 2021
faebdc3
Prep version 1.0.0
dsrees Dec 14, 2021
0aec997
Prepare version 1.0.1
dsrees Feb 27, 2023
fdebc1c
Include the payload as a json string in message
dsrees Jun 10, 2023
eb12bc2
Merge pull request #93 from dsrees/feature/include-raw-json-in-message
dsrees Jun 10, 2023
418d47e
Prepare version 1.1.0
dsrees Jun 10, 2023
dbf5a6a
Prepare version 1.1.1
dsrees Jun 10, 2023
cd9ae55
Fixed issue with new message parser
dsrees Jun 12, 2023
0a932c6
Prepare version 1.1.2
dsrees Jun 12, 2023
48a2718
Do not lose payloadJson in trigger
dsrees Jun 12, 2023
5248447
Prepare version 1.1.3
dsrees Jun 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: java
dist: trusty
after_success:
- bash <(curl -s https://codecov.io/bash)
jdk:
- oraclejdk8
sudo: false
Expand Down
13 changes: 13 additions & 0 deletions ChatExample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
1 change: 1 addition & 0 deletions ChatExample/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
53 changes: 53 additions & 0 deletions ChatExample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 30
defaultConfig {
applicationId "com.github.dsrees.chatexample"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
targetCompatibility = "8"
sourceCompatibility = "8"
}
}

dependencies {
/*
To update the JavaPhoenixClient, either use the latest dependency from mavenCentral()
OR run
`./gradlew jar`
and copy
`/build/lib/*.jar` to `/ChatExample/app/libs`
and comment out the mavenCentral() dependency
*/
implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation 'com.github.dsrees:JavaPhoenixClient:0.3.4'


implementation "com.google.code.gson:gson:2.8.5"
implementation "com.squareup.okhttp3:okhttp:3.12.2"


implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

}
Binary file added ChatExample/app/libs/JavaPhoenixClient-0.7.0.jar
Binary file not shown.
21 changes: 21 additions & 0 deletions ChatExample/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
26 changes: 26 additions & 0 deletions ChatExample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.github.dsrees.chatexample">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package com.github.dsrees.chatexample

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.EditText
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_main.*
import org.phoenixframework.Channel
import org.phoenixframework.Socket

class MainActivity : AppCompatActivity() {

companion object {
const val TAG = "MainActivity"
}

private val messagesAdapter = MessagesAdapter()
private val layoutManager = LinearLayoutManager(this)


// Use when connecting to https://github.com/dwyl/phoenix-chat-example
// private val socket = Socket("https://phxchat.herokuapp.com/socket/websocket")
// private val topic = "room:lobby"

// Use when connecting to local server
private val socket = Socket("ws://10.0.2.2:4000/socket/websocket")
private val topic = "rooms:lobby"

private var lobbyChannel: Channel? = null

private val username: String
get() = username_input.text.toString()

private val message: String
get() = message_input.text.toString()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)


layoutManager.stackFromEnd = true

messages_recycler_view.layoutManager = layoutManager
messages_recycler_view.adapter = messagesAdapter

socket.onOpen {
this.addText("Socket Opened")
runOnUiThread { connect_button.text = "Disconnect" }
}

socket.onClose {
this.addText("Socket Closed")
runOnUiThread { connect_button.text = "Connect" }
}

socket.onError { throwable, response ->
Log.e(TAG, "Socket Errored $response", throwable)
this.addText("Socket Error")
}

socket.logger = {
Log.d(TAG, "SOCKET $it")
}


connect_button.setOnClickListener {
if (socket.isConnected) {
this.disconnectAndLeave()
} else {
this.disconnectAndLeave()
this.connectAndJoin()
}
}

send_button.setOnClickListener { sendMessage() }
}

private fun sendMessage() {
val payload = mapOf("user" to username, "body" to message)
this.lobbyChannel?.push("new:msg", payload)
?.receive("ok") { Log.d(TAG, "success $it") }
?.receive("error") { Log.d(TAG, "error $it") }

message_input.text.clear()
}

private fun disconnectAndLeave() {
// Be sure the leave the channel or call socket.remove(lobbyChannel)
lobbyChannel?.leave()
socket.disconnect { this.addText("Socket Disconnected") }
}

private fun connectAndJoin() {
val channel = socket.channel(topic, mapOf("status" to "joining"))
channel.on("join") {
this.addText("You joined the room")
}

channel.on("new:msg") { message ->
val payload = message.payload
val username = payload["user"] as? String
val body = payload["body"]


if (username != null && body != null) {
this.addText("[$username] $body")
}
}

channel.on("user:entered") {
this.addText("[anonymous entered]")
}

this.lobbyChannel = channel
channel
.join()
.receive("ok") {
this.addText("Joined Channel")
}
.receive("error") {
this.addText("Failed to join channel: ${it.payload}")
}


this.socket.connect()
}

private fun addText(message: String) {
runOnUiThread {
this.messagesAdapter.add(message)
layoutManager.smoothScrollToPosition(messages_recycler_view, null, messagesAdapter.itemCount)
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.dsrees.chatexample

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class MessagesAdapter : RecyclerView.Adapter<MessagesAdapter.ViewHolder>() {

private var messages: MutableList<String> = mutableListOf()

fun add(message: String) {
messages.add(message)
notifyItemInserted(messages.size)
}


override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_message, parent, false)
return ViewHolder(view)
}

override fun getItemCount(): Int = messages.size

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.label.text = messages[position]
}

inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val label: TextView = itemView.findViewById(R.id.item_message_label)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeColor="#00000000"
android:strokeWidth="1">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0"/>
<item
android:color="#00000000"
android:offset="1.0"/>
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeColor="#00000000"
android:strokeWidth="1"/>
</vector>
Loading