Skip to content

Commit

Permalink
メッセージングのサンプルに header のチェックを追加する
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Oct 28, 2024
1 parent cf417da commit 2551c02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions examples/messaging/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ <h1>DataChannel messaging test</h1>
<input type="checkbox" id="check-compress" checked />
<label for="check-compress">Compress</label>
</div>
<div>
<input type="checkbox" id="check-header" />
<label for="check-header">Header</label>
</div>
<button id="connect">connect</button>
<button id="disconnect" disabled>disconnect</button>
<button id="get-stats">getStats</button><br />
Expand Down
8 changes: 6 additions & 2 deletions examples/messaging/main.mts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ document.addEventListener('DOMContentLoaded', async () => {
document.querySelector('#connect')?.addEventListener('click', async () => {
const checkCompress = document.getElementById('check-compress') as HTMLInputElement
const compress = checkCompress.checked
const checkHeader = document.getElementById('check-header') as HTMLInputElement
const header = checkHeader.checked

await client.connect(compress)
await client.connect(compress, header)
})
document.querySelector('#disconnect')?.addEventListener('click', async () => {
await client.disconnect()
Expand Down Expand Up @@ -100,7 +102,7 @@ class SoraClient {
this.connection.on('message', this.onmessage.bind(this))
}

async connect(compress: boolean) {
async connect(compress: boolean, header: boolean) {
// connect ボタンを無効にする
const connectButton = document.querySelector<HTMLButtonElement>('#connect')
if (connectButton) {
Expand All @@ -113,6 +115,8 @@ class SoraClient {
label: '#example',
direction: 'sendrecv',
compress: compress,
// header が true の場合は sender_connection_id を追加
header: header ? [{ type: 'sender_connection_id' }] : undefined,
},
]
await this.connection.connect()
Expand Down

0 comments on commit 2551c02

Please sign in to comment.