Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • videostreaming/polycentricandroid
1 result
Show changes
Commits on Source (2)
......@@ -16,17 +16,34 @@ import userpackage.Protocol
import java.nio.ByteBuffer
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import okhttp3.Cache
import java.io.File
import java.util.concurrent.TimeUnit
class ApiMethods {
companion object {
var UserAgent = "Grayjay Android";
private const val TAG = "ApiMethods"
private val client = OkHttpClient()
private var client: OkHttpClient = OkHttpClient.Builder()
.connectTimeout(3, TimeUnit.SECONDS)
.build()
fun initCache(cacheDir: File) {
client = OkHttpClient.Builder()
.connectTimeout(3, TimeUnit.SECONDS)
.cache(Cache(
directory = File(cacheDir, "http_cache"),
maxSize = 25L * 1024L * 1024L // 25 MiB
))
.build()
}
private val MEDIA_TYPE_OCTET_STREAM = "application/octet-stream".toMediaType()
fun getRequestBuilder(url: String): Request.Builder = Request.Builder().url(url).header("x-polycentric-user-agent", UserAgent)
suspend fun postEvents(server: String, events: Protocol.Events): Unit = withContext(Dispatchers.IO) {
val body = events.toByteArray().toRequestBody(MEDIA_TYPE_OCTET_STREAM)
val request = getRequestBuilder("$server/events").post(body).build()
......