Skip to content

Commit

Permalink
Syncing issue hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
yuroyami committed Nov 1, 2022
1 parent 9b97383 commit 6bc5cef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
21 changes: 15 additions & 6 deletions SyncplayApp/src/main/java/app/protocol/SyncplayProtocol.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.protocol

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import app.protocol.JsonHandler.handleJson
Expand Down Expand Up @@ -27,12 +28,12 @@ import io.netty.handler.codec.DelimiterBasedFrameDecoder
import io.netty.handler.codec.Delimiters
import io.netty.handler.codec.string.StringDecoder
import io.netty.handler.codec.string.StringEncoder
import io.netty.handler.ssl.SslHandler
import io.netty.handler.ssl.SslContextBuilder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.InputStream
import javax.net.ssl.SSLEngine
import javax.net.ssl.TrustManagerFactory


open class SyncplayProtocol : ViewModel() {
Expand Down Expand Up @@ -95,11 +96,19 @@ open class SyncplayProtocol : ViewModel() {
val p: ChannelPipeline =
ch.pipeline() /* Getting the pipeline related to the channel */

/** Should be establish a TLS connection ? */
/** Should we establish a TLS connection ? */
if (tls == Constants.TLS.TLS_YES) {
val engine: SSLEngine? = null
engine?.useClientMode = true
p.addLast("ssl", SslHandler(engine))
Log.e("TLS", "Attempting TLS")
val c = SslContextBuilder
.forClient()
.trustManager(TrustManagerFactory.getInstance("TLSv1.2"))
.build()
val h = c.newHandler(ch.alloc(), session.serverHost, session.serverPort)
p.addLast(h)

//val engine: SSLEngine? = SSLContext.getDefault().createSSLEngine()
//engine?.useClientMode = true
//p.addLast("ssl", SslHandler(engine))
}

/** We should never forget \r\n delimiters, or we would get no input */
Expand Down
15 changes: 9 additions & 6 deletions SyncplayApp/src/main/java/app/utils/RoomUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ object RoomUtils {
/** Updates the protocol with the current position of the video playback **/
fun RoomActivity.vidPosUpdater() {
lifecycleScope.launch(Dispatchers.Main) {
if (myExoPlayer?.isCurrentMediaItemSeekable == true) {
/* Informing my ViewModel about current vid position so it is retrieved for networking after */
val progress = (binding.vidplayer.player?.currentPosition?.div(1000.0))
if (progress != null) {
p.currentVideoPosition = progress
while (true) {
if (myExoPlayer?.isCurrentMediaItemSeekable == true) {
/* Informing my ViewModel about current vid position so it is retrieved for networking after */
val progress = (binding.vidplayer.player?.currentPosition?.div(1000.0))
if (progress != null) {
p.currentVideoPosition = progress
}
}
delay(100)
}
delay(100)

}
}

Expand Down

0 comments on commit 6bc5cef

Please sign in to comment.