Skip to content

Commit

Permalink
お試し
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Nov 29, 2024
1 parent 10be870 commit dbe985b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
1 change: 1 addition & 0 deletions examples/messaging/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<div class="container">
<h1>DataChannel messaging test</h1>
<p>複数のブラウザで開いて sendMessage することで動作確認できます</p>
<h2>sora-js-sdk version: <span id="sora-js-sdk-version"></span></h2>
<label for="channel-name">チャンネル名:</label>
<input type="text" id="channel-name" name="channel-name" value="messaging"><br>
<div id="connection-id"></div>
Expand Down
6 changes: 6 additions & 0 deletions examples/messaging/main.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ document.addEventListener('DOMContentLoaded', async () => {
const SORA_CHANNEL_ID_SUFFIX = import.meta.env.VITE_SORA_CHANNEL_ID_SUFFIX || ''
const ACCESS_TOKEN = import.meta.env.VITE_ACCESS_TOKEN || ''

const soraJsSdkVersion = Sora.version()
const soraJsSdkVersionElement = document.getElementById('sora-js-sdk-version')
if (soraJsSdkVersionElement) {
soraJsSdkVersionElement.textContent = soraJsSdkVersion
}

let client: SoraClient

document.querySelector('#connect')?.addEventListener('click', async () => {
Expand Down
17 changes: 3 additions & 14 deletions tests/helper.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import * as fs from 'node:fs'
import * as path from 'node:path'

const getPackageVersion = (): string => {
const packageJsonPath = path.resolve(__dirname, '../examples/package.json')
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
return packageJson.dependencies['sora-js-sdk'].replace('^', '')
}

// バージョン比較用のヘルパー関数を追加
export const isVersionGreaterThanOrEqual = (version: string): boolean => {
const packageVersion = getPackageVersion()

export const isVersionGreaterThanOrEqual = (packageVersion: string, version: string): boolean => {
const v1Parts = packageVersion.split('.').map(Number)
const v2Parts = version.split('.').map(Number)

for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
const v1 = v1Parts[i] || 0
const v2 = v2Parts[i] || 0
if (v1 < v2) return true
if (v1 > v2) return false
if (v1 > v2) return true
if (v1 < v2) return false
}
return true
}
17 changes: 12 additions & 5 deletions tests/message_header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { expect, test } from '@playwright/test'
import { isVersionGreaterThanOrEqual } from './helper'

test('messaging pages with header', async ({ browser }) => {
test.skip(
!isVersionGreaterThanOrEqual('2024.2.0'),
'このテストは sora-js-sdk 2024.2.0 以降でのみ実行されます',
)

// 新しいページを2つ作成
const page1 = await browser.newPage()
const page2 = await browser.newPage()
Expand All @@ -15,6 +10,18 @@ test('messaging pages with header', async ({ browser }) => {
await page1.goto('http://localhost:9000/messaging/')
await page2.goto('http://localhost:9000/messaging/')

// sora js sdk のバージョンを取得する
await page1.waitForSelector('#sora-js-sdk-version')
const page1SoraJsSdkVersion = await page1.$eval('#sora-js-sdk-version', (el) => el.textContent)
if (page1SoraJsSdkVersion === null) {
throw new Error('page1SoraJsSdkVersion is null')
}
// sora-js-sdk のバージョンが 2024.2.0 以上であるか確認して、2024.2.0 未満の場合はテストをスキップする
test.skip(
!isVersionGreaterThanOrEqual(page1SoraJsSdkVersion, '2024.2.0'),
'sora-js-sdk のバージョンが 2024.2.0 以上である必要があります',
)

// チャネル名を設定する
await page1.fill('input[name="channel-name"]', 'message-header')
await page2.fill('input[name="channel-name"]', 'message-header')
Expand Down
14 changes: 9 additions & 5 deletions tests/messaging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import { isVersionGreaterThanOrEqual } from './helper'

// sora-js-sdk のバージョンが 2024.2.0 以降の場合のみ実行したい
test('messaging pages', async ({ browser }) => {
test.skip(
!isVersionGreaterThanOrEqual('2024.2.0'),
'このテストは sora-js-sdk 2024.2.0 以降でのみ実行されます',
)

// 新しいページを2つ作成
const page1 = await browser.newPage()
const page2 = await browser.newPage()
Expand All @@ -16,6 +11,15 @@ test('messaging pages', async ({ browser }) => {
await page1.goto('http://localhost:9000/messaging/')
await page2.goto('http://localhost:9000/messaging/')

// sora js sdk のバージョンを取得する
await page1.waitForSelector('#sora-js-sdk-version')
const page1SoraJsSdkVersion = await page1.$eval('#sora-js-sdk-version', (el) => el.textContent)
if (page1SoraJsSdkVersion === null) {
throw new Error('page1SoraJsSdkVersion is null')
}
// sora-js-sdk のバージョンが 2024.2.0 以上であるか確認して、2024.2.0 未満の場合はテストをスキップする
test.skip(!isVersionGreaterThanOrEqual(page1SoraJsSdkVersion, '2024.2.0'), 'sora-js-sdk のバージョンが 2024.2.0 以上である必要があります')

// Compress のTrue/Falseをランダムで設定する
const selectedCompress1 = await page1.evaluate(() => {
const checkCompress = document.getElementById('check-compress') as HTMLInputElement
Expand Down

0 comments on commit dbe985b

Please sign in to comment.