Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Video conference #237

Merged
merged 6 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath "gradle.plugin.org.jmailen.gradle:kotlinter-gradle:${versions.kotlinter}"
classpath "org.jmailen.gradle:kotlinter-gradle:${versions.kotlinter}"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}"
}
}
Expand Down
6 changes: 0 additions & 6 deletions compat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

kotlin {
experimental {
coroutines "enable"
}
}

dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/javadoc"
Expand Down
2 changes: 1 addition & 1 deletion compat/src/main/kotlin/chat/rocket/core/compat/Call.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package chat.rocket.core.compat

import kotlinx.coroutines.experimental.Job
import kotlinx.coroutines.Job

class Call(val job: Job) {
fun cancel() {
Expand Down
11 changes: 6 additions & 5 deletions compat/src/main/kotlin/chat/rocket/core/compat/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import chat.rocket.common.model.ServerInfo
import chat.rocket.core.RocketChatClient
import chat.rocket.core.compat.internal.callback
import chat.rocket.core.internal.rest.serverInfo
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.Dispatchers

fun RocketChatClient.serverInfo(future: Callback<ServerInfo>): Call =
callback(CommonPool, future) {
serverInfo()
}
/**
* Returns the current logged server information.
* Must be used with a coroutine context (async, launch, etc)
*/
fun RocketChatClient.serverInfo(future: Callback<ServerInfo>): Call = callback(Dispatchers.IO, future) { serverInfo() }
11 changes: 2 additions & 9 deletions compat/src/main/kotlin/chat/rocket/core/compat/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ import chat.rocket.core.RocketChatClient
import chat.rocket.core.compat.internal.callback
import chat.rocket.core.internal.rest.me
import chat.rocket.core.model.Myself
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.Dispatchers

/**
* Returns the current logged user information, useful to check if the Token from TokenProvider
* is still valid. Must be used with a coroutine context (async, launch, etc)
*
* @return Call
* @see
* @see RocketChatException
*/
fun RocketChatClient.me(future: Callback<Myself>): Call =
callback(CommonPool, future) {
me()
}
fun RocketChatClient.me(future: Callback<Myself>): Call = callback(Dispatchers.IO, future) { me() }
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,35 @@ package chat.rocket.core.compat.internal
import chat.rocket.common.RocketChatException
import chat.rocket.core.compat.Call
import chat.rocket.core.compat.Callback
import kotlinx.coroutines.experimental.AbstractCoroutine
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.DefaultDispatcher
import kotlinx.coroutines.experimental.Job
import kotlinx.coroutines.experimental.newCoroutineContext
import kotlin.coroutines.experimental.CoroutineContext
import kotlin.coroutines.experimental.startCoroutine
import kotlinx.coroutines.AbstractCoroutine
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.newCoroutineContext
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.startCoroutine

@JvmOverloads
fun <T> callback(
context: CoroutineContext = DefaultDispatcher,
context: CoroutineContext = Dispatchers.Default,
callback: Callback<T>,
block: suspend CoroutineScope.() -> T
): Call {
val newContext = newCoroutineContext(context)
val newContext = GlobalScope.newCoroutineContext(context)
val job = Job(newContext[Job])
val coroutine = CallbackCoroutine(newContext + job, callback)
block.startCoroutine(coroutine, coroutine)
return Call(job)
}

@UseExperimental(InternalCoroutinesApi::class)
private class CallbackCoroutine<in T>(
parentContext: CoroutineContext,
private val callback: Callback<T>
) : AbstractCoroutine<T>(parentContext, true) {

override fun onCompleted(value: T) {
callback.onSuccess(value)
}
Expand Down
6 changes: 0 additions & 6 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

kotlin {
experimental {
coroutines "enable"
}
}

dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/javadoc"
Expand Down
10 changes: 8 additions & 2 deletions core/src/main/kotlin/chat/rocket/core/RocketChatClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,25 @@ import chat.rocket.core.model.Myself
import chat.rocket.core.model.Room
import chat.rocket.core.model.url.MetaJsonAdapter
import com.squareup.moshi.Moshi
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import okhttp3.HttpUrl
import okhttp3.MediaType
import okhttp3.OkHttpClient
import java.security.InvalidParameterException
import kotlin.coroutines.CoroutineContext

class RocketChatClient private constructor(
internal val httpClient: OkHttpClient,
baseUrl: String,
userAgent: String,
internal val tokenRepository: TokenRepository,
internal val logger: Logger
) {
) : CoroutineScope {
override val coroutineContext: CoroutineContext
get() = Dispatchers.Default

internal val moshi: Moshi = Moshi.Builder()
.add(FallbackSealedClassJsonAdapter.ADAPTER_FACTORY)
.add(RestResult.JsonAdapterFactory())
Expand Down
110 changes: 55 additions & 55 deletions core/src/main/kotlin/chat/rocket/core/internal/AttachmentAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,34 @@ class AttachmentAdapter(moshi: Moshi, private val logger: Logger) : JsonAdapter<
private val actionAdapter = moshi.adapter<ButtonAction>(ButtonAction::class.java)

private val NAMES = arrayOf(
"title", // 0
"type", // 1
"description", // 2
"author_name", // 3
"text", // 4
"thumb_url", // 5
"color", // 6
"title_link", // 7
"title_link_download", // 8
"image_url", // 9
"image_type", // 10
"image_size", // 11
"video_url", // 12
"video_type", // 13
"video_size", // 14
"audio_url", // 15
"audio_type", // 16
"audio_size", // 17
"message_link", // 18
"attachments", // 19
"ts", // 20
"author_icon", // 21
"author_link", // 22
"image_preview", // 23
"fields", // 24
"fallback", // 25
"button_alignment", // 26
"actions" // 27
"title", // 0
"type", // 1
"description", // 2
"author_name", // 3
"text", // 4
"thumb_url", // 5
"color", // 6
"title_link", // 7
"title_link_download", // 8
"image_url", // 9
"image_type", // 10
"image_size", // 11
"video_url", // 12
"video_type", // 13
"video_size", // 14
"audio_url", // 15
"audio_type", // 16
"audio_size", // 17
"message_link", // 18
"attachments", // 19
"ts", // 20
"author_icon", // 21
"author_link", // 22
"image_preview", // 23
"fields", // 24
"fallback", // 25
"button_alignment", // 26
"actions" // 27
)

private val OPTIONS = JsonReader.Options.of(*NAMES)
Expand All @@ -61,34 +61,34 @@ class AttachmentAdapter(moshi: Moshi, private val logger: Logger) : JsonAdapter<
return reader.nextNull<Attachment>()
}

var title: String? = null // 0
var type: String? = null // 1
var description: String? = null // 2
var authorName: String? = null // 3
var text: String? = null // 4
var thumbUrl: String? = null // 5
var color: Color? = null // 6
var titleLink: String? = null // 7
var titleLinkDownload = false // 8
var imageUrl: String? = null // 9
var imageType: String? = null // 10
var imageSize: Long? = null // 11
var videoUrl: String? = null // 12
var videoType: String? = null // 13
var videoSize: Long? = null // 14
var audioUrl: String? = null // 15
var audioType: String? = null // 16
var audioSize: Long? = null // 17
var messageLink: String? = null // 18
var title: String? = null // 0
var type: String? = null // 1
var description: String? = null // 2
var authorName: String? = null // 3
var text: String? = null // 4
var thumbUrl: String? = null // 5
var color: Color? = null // 6
var titleLink: String? = null // 7
var titleLinkDownload = false // 8
var imageUrl: String? = null // 9
var imageType: String? = null // 10
var imageSize: Long? = null // 11
var videoUrl: String? = null // 12
var videoType: String? = null // 13
var videoSize: Long? = null // 14
var audioUrl: String? = null // 15
var audioType: String? = null // 16
var audioSize: Long? = null // 17
var messageLink: String? = null // 18
var attachments: List<Attachment>? = null // 19
var timestamp: Long? = null // 20
var authorIcon: String? = null // 21
var authorLink: String? = null // 22
var imagePreview: String? = null // 23
var fields: List<Field>? = null // 24
var fallback: String? = null // 25
var buttonAlignment: String? = null // 26
var actions: List<Action>? = null // 27
var timestamp: Long? = null // 20
var authorIcon: String? = null // 21
var authorLink: String? = null // 22
var imagePreview: String? = null // 23
var fields: List<Field>? = null // 24
var fallback: String? = null // 25
var buttonAlignment: String? = null // 26
var actions: List<Action>? = null // 27

reader.beginObject()
while (reader.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class RoomListAdapter(moshi: Moshi, private val logger: Logger) : JsonA
private val adapter = moshi.adapter<Room>(Room::class.java)

override fun toJson(writer: JsonWriter, value: List<Room>?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
TODO("not implemented") // To change body of created functions use File | Settings | File Templates.
}

override fun fromJson(reader: JsonReader): List<Room>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.squareup.moshi.Json
import se.ansman.kotshi.JsonSerializable

@JsonSerializable
data class CreateNewChannelPayload (
data class CreateNewChannelPayload(
@Json(name = "name") val channelName: String,
@Json(name = "members") val membersToInvite: List<String>?,
val readOnly: Boolean?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import chat.rocket.core.internal.realtime.message.roomsStreamMessage
import chat.rocket.core.internal.realtime.message.streamRoomMessages
import chat.rocket.core.internal.realtime.message.streamTypingMessage
import chat.rocket.core.internal.realtime.message.typingMessage
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.withContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

suspend fun RocketChatClient.setTypingStatus(roomId: String, username: String, isTyping: Boolean) =
withContext(CommonPool) {
withContext(Dispatchers.IO) {
socket.send(typingMessage(socket.generateId(), roomId, username, isTyping))
}

Expand Down
Loading