Add polling
This commit is contained in:
parent
927649bba6
commit
ce4e4635e3
6 changed files with 59 additions and 15 deletions
|
@ -13,7 +13,7 @@ import org.w3c.xhr.XMLHttpRequest
|
|||
import kotlin.browser.document
|
||||
import kotlin.browser.window
|
||||
|
||||
class WebSocketClient {
|
||||
class PushServiceClient {
|
||||
private val prefix = js("prefix")
|
||||
private val url = "$prefix/api/updates"
|
||||
private val body = document.body ?: createHtmlView()
|
|
@ -12,7 +12,7 @@ import de.westermann.kwebview.components.init
|
|||
import kotlin.browser.document
|
||||
|
||||
fun main() = init {
|
||||
WebSocketClient()
|
||||
PushServiceClient()
|
||||
|
||||
if (document.getElementsByClassName("calendar").length > 0) {
|
||||
initCalendar()
|
||||
|
|
|
@ -21,15 +21,15 @@ object AnnouncementRepository {
|
|||
|
||||
suspend fun getAnnouncement(): String {
|
||||
val json = repositoryGet("$prefix/api/announcement") ?: return ""
|
||||
return parser.parse(json, String.serializer())
|
||||
return json as String
|
||||
}
|
||||
|
||||
suspend fun setAnnouncement(value: String){
|
||||
return repositoryPost("$prefix/api/announcement", Serialization.stringify(String.serializer(), value))
|
||||
return repositoryPost("$prefix/api/announcement", value)
|
||||
?: throw IllegalStateException("Cannot set announcement!")
|
||||
}
|
||||
|
||||
val handler = object : MessageHandler(RepositoryType.ROOM) {
|
||||
val handler = object : MessageHandler(RepositoryType.ANNOUNCEMENT) {
|
||||
|
||||
override fun onCreate(id: Long) {}
|
||||
|
||||
|
|
|
@ -18,4 +18,4 @@ fun initAnnouncement() {
|
|||
span.textContent = text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue