-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98e531c
commit dbb36da
Showing
9 changed files
with
122 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,56 @@ | ||
package ru.hihit.cobuy.pusher | ||
|
||
import android.util.Log | ||
import com.pusher.client.Pusher | ||
import com.pusher.client.PusherOptions | ||
import com.pusher.client.channel.Channel | ||
import com.pusher.client.channel.PusherEvent | ||
import com.pusher.client.channel.SubscriptionEventListener | ||
import com.pusher.client.connection.ConnectionState | ||
import ru.hihit.cobuy.BuildConfig | ||
import java.lang.Exception | ||
|
||
class PusherService { | ||
private val pusher: Pusher | ||
|
||
init { | ||
val options = PusherOptions().apply { | ||
setCluster(BuildConfig.PUSHER_CLUSTER) | ||
// setChannelAuthorizer() | ||
} | ||
pusher = Pusher(BuildConfig.PUSHER_KEY, options) | ||
pusher.connect() | ||
} | ||
|
||
fun subscribeToChannel(channelName: String, eventName: String, listener: SubscriptionEventListener) { | ||
fun subscribeToChannel( | ||
channelName: String, | ||
eventName: String, | ||
onEvent: (PusherEvent) -> Unit, | ||
onError: (String?, Exception?) -> Unit | ||
) { | ||
Log.d("PusherService", "Subscribing to channel $channelName") | ||
val channel: Channel = pusher.subscribe(channelName) | ||
val listener: SubscriptionEventListener = object : SubscriptionEventListener { | ||
override fun onEvent(event: PusherEvent) { | ||
Log.d("PusherService", "Received event: $event") | ||
onEvent(event) | ||
} | ||
|
||
override fun onError(message: String?, e: Exception?) { | ||
Log.d("PusherService", "Error: $message") | ||
onError(message, e) | ||
} | ||
} | ||
channel.bind(eventName, listener) | ||
Log.d("PusherService", "Subscribed to channel? ${channel.isSubscribed}") | ||
} | ||
|
||
fun isPusherConnected(): Unit { | ||
Log.d("PusherService", "Checking if Pusher is connected: ${pusher.connection.state == ConnectionState.CONNECTED}") | ||
} | ||
|
||
fun unsubscribeFromChannel(channelName: String) { | ||
Log.d("PusherService", "Unsubscribing from channel $channelName") | ||
pusher.unsubscribe(channelName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,8 +45,8 @@ fun AuthScreen( | |
vm: AuthViewModel | ||
) { | ||
val context = LocalContext.current | ||
var email by remember { mutableStateOf("[email protected]") } | ||
var password by remember { mutableStateOf("qwe123123") } | ||
var email by remember { mutableStateOf("") } | ||
var password by remember { mutableStateOf("") } | ||
var passwordVisible by remember { mutableStateOf(false) } | ||
var login by remember { mutableStateOf("") } | ||
var isRegistering by remember { mutableStateOf(false) } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters