-
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.
Allow candidate exchange via REST+SSE
Closes #19
- Loading branch information
1 parent
3aa38bd
commit dc09ab1
Showing
5 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/faforever/icebreaker/security/CurrentUserService.kt
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.faforever.icebreaker.security | ||
|
||
import io.quarkus.oidc.runtime.OidcJwtCallerPrincipal | ||
import io.quarkus.security.identity.SecurityIdentity | ||
import jakarta.enterprise.context.ApplicationScoped | ||
|
||
@ApplicationScoped | ||
class CurrentUserService( | ||
private val securityIdentity: SecurityIdentity, | ||
) { | ||
fun getCurrentUserId(): Long? { | ||
val principal = (securityIdentity.principal as? OidcJwtCallerPrincipal) | ||
val subject = principal?.claims?.claimsMap?.get("sub") as? String | ||
|
||
return subject?.toLong() | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/kotlin/com/faforever/icebreaker/service/CandidatesMessage.kt
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.faforever.icebreaker.service | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude | ||
import com.fasterxml.jackson.annotation.JsonSubTypes | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
import com.fasterxml.jackson.annotation.JsonValue | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "eventType") | ||
@JsonSubTypes( | ||
JsonSubTypes.Type(value = CandidatesMessage::class, name = "candidates"), | ||
JsonSubTypes.Type(value = ConnectedMessage::class, name = "connected"), | ||
) | ||
@JsonInclude(JsonInclude.Include.ALWAYS) | ||
interface EventMessage { | ||
val gameId: Long | ||
val senderId: Long | ||
val recipientId: Long? | ||
} | ||
|
||
@JvmRecord | ||
data class ConnectedMessage( | ||
override val gameId: Long, | ||
override val senderId: Long, | ||
override val recipientId: Long? = null, | ||
) : EventMessage | ||
|
||
@JvmRecord | ||
data class CandidatesMessage( | ||
override val gameId: Long, | ||
override val senderId: Long, | ||
override val recipientId: Long, | ||
val candidates: List<CandidateDescriptor>, | ||
) : EventMessage { | ||
|
||
enum class CandidateType(@JsonValue val jsonValue: String) { | ||
PEER_REFLEXIVE_CANDIDATE("prflx"), | ||
SERVER_REFLEXIVE_CANDIDATE("srflx"), | ||
RELAYED_CANDIDATE("relay"), | ||
HOST_CANDIDATE("host"), | ||
LOCAL_CANDIDATE("local"), | ||
STUN_CANDIDATE("stun"), | ||
} | ||
|
||
@JvmRecord | ||
data class CandidateDescriptor( | ||
val foundation: String, | ||
val protocol: String, | ||
val priority: Long, | ||
val ip: String?, | ||
val port: Int, | ||
val type: CandidateType, | ||
val generation: Int, | ||
val id: String, | ||
val relAddr: String?, | ||
val relPort: Int, | ||
) : Comparable<CandidateDescriptor> { | ||
override operator fun compareTo(other: CandidateDescriptor) = (other.priority - priority).toInt() | ||
} | ||
} |
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