parent
93bf0c9730
commit
b5fc1bd200
@ -0,0 +1,6 @@ |
||||
object Api { |
||||
const val prefix = "/api" |
||||
const val JSON_API = "$prefix/json" |
||||
const val IMAGE_API = "$prefix/image" |
||||
const val websocketPath = "/webSocket" |
||||
} |
@ -1,21 +1,33 @@ |
||||
import react.dom.render |
||||
import kotlinx.browser.document |
||||
import kotlinx.browser.window |
||||
import kotlinx.serialization.encodeToString |
||||
import kotlinx.serialization.json.Json |
||||
import org.w3c.dom.WebSocket |
||||
import org.w3c.dom.events.Event |
||||
import react.dom.render |
||||
|
||||
val globalJson = Json { ignoreUnknownKeys = true } |
||||
|
||||
fun WebSocket.sendCommand(command: WebSocketClientCommand) { |
||||
send(globalJson.encodeToString(WebSocketClient(command = command.name))) |
||||
} |
||||
|
||||
fun main() { |
||||
window.onload = { |
||||
val webSocket=WebSocket("ws://localhost:8080${websocketPath}") |
||||
webSocket.onopen={event: Event -> console.info("打开连接:${event}") } |
||||
webSocket.onclose={event: Event -> console.info("关闭连接:${event}") } |
||||
webSocket.onerror={event: Event -> console.error("发生错误:${event}") } |
||||
val webSocket = WebSocket("ws://localhost:8080${Api.websocketPath}") |
||||
webSocket.onopen = { event: Event -> console.info("打开连接:${event}") } |
||||
webSocket.onclose = { event: Event -> console.info("关闭连接:${event}") } |
||||
webSocket.onerror = { event: Event -> console.error("发生错误:${event}") } |
||||
window.setInterval({ |
||||
webSocket.sendCommand(command = WebSocketClientCommand.Heart) |
||||
}, 60000) |
||||
render(document.getElementById("root")) { |
||||
child(Welcome::class) { |
||||
attrs { |
||||
this.webSocket=webSocket |
||||
this.webSocket = webSocket |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,4 @@ |
||||
import io.ktor.http.content.* |
||||
|
||||
//打包图片数据 |
||||
data class ImageFileData(val romajiTitle: String, val data: List<PartData.FileItem>) |
Loading…
Reference in new issue