@jokio/sdk
Version:
pure js/ts sdk for building decentralised localfirst web apps. Provides tts ai model integrations, realtime p2p communication & crypto encryptions.
106 lines (74 loc) • 3.08 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>MyLibrary Test</title>
</head>
<body>
<h1>Library Test</h1>
<button onclick="playAudio()">TTS</button>
<button onclick="playAudio2()">Voicevox TTS</button>
<script type="module">
// import { jok } from 'https://esm.run/@jokio/sdk';
import { jok, VoicevoxTtsService } from './dist/jokio.sdk.es.js';
window.jok = jok
window.getVoicevoxVoices = async function () {
const voices = await jok.voicevoxTts.getVoices()
console.log(voices)
}
window.getVoices = async function () {
const voices = await jok.tts.getVoices()
console.log(voices)
}
window.playAudio = async function () {
const audio = await jok.tts.getAudio("Hello there, how are you?", "en-US-AvaNeural")
audio.play()
}
window.playAudio2 = async function () {
const tts = new VoicevoxTtsService({ voicevoxUrl: 'https://voicevox.fly.dev' })
const audio = await tts.getAudio("こんにちわ、おげんきですか?あなたはあたまがいいですね。", 3)
audio.play()
}
window.requestEmailLogin = async function (email) {
const res = await jok.auth.requestEmailLogin(email, 'https://localhost:5173')
return res
}
window.completeEmailLogin = async function (email, otpCode) {
const res = await jok.auth.completeEmailLogin(email, otpCode)
return res
}
window.passkeyLogin = async function (displayName) {
const res = await jok.auth.requestPasskeyLogin(displayName)
return res
}
window.natsConnect = async function () {
await jok.nats.connect()
}
window.natsSubscribe = async function () {
await jok.nats.on('dev.test', (data, ctx) => {
console.log({ data, ctx })
})
}
window.natsPublish = async function () {
await jok.nats.publish('dev.test', { name: 'User', age: 11 })
}
window.p2pChat = async function () {
const kp1 = await jok.crypto.createSessionKeyPair()
const kp2 = await jok.crypto.createSessionKeyPair()
const p1 = await jok.crypto.exportPublicKey(kp1.publicKey)
const p2 = await jok.crypto.exportPublicKey(kp2.publicKey)
console.log({ p1, p2 })
const shared1 = await jok.crypto.deriveAESKey(kp1.privateKey, p2)
const shared2 = await jok.crypto.deriveAESKey(kp2.privateKey, p1)
const originalText = "Hello World"
const encrypted = await jok.crypto.encrypt(originalText, shared1)
const decrypted = await jok.crypto.decrypt(encrypted, shared2)
console.log({
match: originalText === decrypted,
originalText,
decrypted,
})
}
</script>
</body>
</html>