Skip to content

Commit

Permalink
整理
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Feb 20, 2024
1 parent 7c60d01 commit 839ac0d
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 126 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"editor.codeActionsOnSave": {
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit"
}
},
"cSpell.words": ["remotevideo"]
}
3 changes: 3 additions & 0 deletions env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_SORA_SIGNLAING_URL=wss://sora.example.com/signaling
VITE_SORA_CHANNEL_ID=sora-js-sdk
VITE_ACCESS_TOKEN=secret
22 changes: 0 additions & 22 deletions example/README.md

This file was deleted.

File renamed without changes.
62 changes: 0 additions & 62 deletions example/recvonly.html

This file was deleted.

22 changes: 22 additions & 0 deletions example/recvonly/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<html lang="ja">

<head>
<meta charset="utf-8">
<title>Recvonly test</title>
</head>

<body>
<div class="container">
<h1>Recvonly test</h1>
<button id="start-recvonly">start</button>
<button id="stop-recvonly">stop</button><br />
<div style="display: flex;">
<div id="remote-videos"></div>
</div>
</div>

<script type="module" src="./main.js"></script>
</script>
</body>

</html>
48 changes: 48 additions & 0 deletions example/recvonly/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Sora from '../../dist/sora.js'

const SORA_SIGNALING_URL = import.meta.env.VITE_SORA_SIGNALING_URL
const SORA_CHANNEL_ID = import.meta.env.VITE_SORA_CHANNEL_ID
const ACCESS_TOKEN = import.meta.env.VITE_ACCESS_TOKEN

const channelId = SORA_CHANNEL_ID
const debug = false
const sora = Sora.connection(SORA_SIGNALING_URL, debug)
const metadata = { access_token: ACCESS_TOKEN }
const options = {}

const recvonly = sora.recvonly(channelId, metadata, options)

recvonly.on('track', (event) => {
const stream = event.streams[0]
if (!stream) return
const remoteVideoId = `remotevideo-${stream.id}`
const remoteVideos = document.querySelector('#remote-videos')
if (!remoteVideos.querySelector(`#${remoteVideoId}`)) {
const remoteVideo = document.createElement('video')
remoteVideo.id = remoteVideoId
remoteVideo.style.border = '1px solid red'
remoteVideo.autoplay = true
remoteVideo.playsinline = true
remoteVideo.controls = true
remoteVideo.width = '320'
remoteVideo.height = '240'
remoteVideo.srcObject = stream
remoteVideos.appendChild(remoteVideo)
}
})

recvonly.on('removetrack', (event) => {
const remoteVideo = document.querySelector(`#remotevideo-${event.target.id}`)
if (remoteVideo) {
document.querySelector('#remote-videos').removeChild(remoteVideo)
}
})

document.querySelector('#start-recvonly').addEventListener('click', async () => {
await recvonly.connect()
})

document.querySelector('#stop-recvonly').addEventListener('click', async () => {
await recvonly.disconnect()
document.querySelector('#remote-videos').innerHTML = null
})
39 changes: 0 additions & 39 deletions example/sendonly.html

This file was deleted.

21 changes: 21 additions & 0 deletions example/sendonly/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Sendonly test</title>
</head>
<body>
<div class="container">
<h1>Sendonly test</h1>
<div>
<h2>sendonly1</h2>
<button id="start-sendonly">start</button>
<button id="stop-sendonly">stop</button><br />
<video id="sendonly-local-video" autoplay="" playsinline="" controls="" style="width: 320px; height: 240px; border: 1px solid black;"></video>
</div>
</div>

<script src="./sora.js"></script>
<script type="text/javascript">
</script>
</body>
</html>
24 changes: 24 additions & 0 deletions example/sendonly/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Sora from '../../dist/sora.js'

const SORA_SIGNALING_URL = import.meta.env.VITE_SORA_SIGNALING_URL
const SORA_CHANNEL_ID = import.meta.env.VITE_SORA_CHANNEL_ID
const ACCESS_TOKEN = import.meta.env.VITE_ACCESS_TOKEN

const channelId = SORA_CHANNEL_ID
const debug = false
const sora = Sora.connection(SORA_SIGNALING_URL, debug)
const metadata = { access_token: ACCESS_TOKEN }
const options = {}

const sendonly = sora.sendonly(channelId, metadata, options)

document.querySelector('#start-sendonly').addEventListener('click', async () => {
const mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true })
await sendonly.connect(mediaStream)
document.querySelector('#sendonly-local-video').srcObject = mediaStream
})

document.querySelector('#stop-sendonly').addEventListener('click', async () => {
await sendonly.disconnect()
document.querySelector('#sendonly-local-video').srcObject = null
})
2 changes: 1 addition & 1 deletion example/sendrecv/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Sora from '../../dist/sora.js'

const SORA_SIGNALING_URL = import.meta.env.VITE_SORA_SIGNALING_URL
const SORA_CHANNEL_ID = import.meta.env.VITE_SORA_CHANNEL_ID
const SORA_ACCESS_TOKEN = import.meta.env.VITE_SORA_ACCESS_TOKEN
const ACCESS_TOKEN = import.meta.env.VITE_ACCESS_TOKEN

const channelId = SORA_CHANNEL_ID
const debug = false
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion example/sora.js

This file was deleted.

File renamed without changes.
File renamed without changes.

0 comments on commit 839ac0d

Please sign in to comment.