Skip to content

Commit f5a0616

Browse files
committed
Rid 列挙型を追加する
1 parent 18332d3 commit f5a0616

File tree

9 files changed

+119
-14
lines changed

9 files changed

+119
-14
lines changed

CHANGES.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,24 @@
4646
- デフォルト値の `unspecified` の場合はシグナリングパラメータに `simulcast_request_rid` を含めない
4747
- role が sendrecv または recvonly の場合、かつ simulcast が true の場合にのみ有効
4848
- @zztkm
49+
- [ADD] サイマルキャストの rid を表す汎用型 `Rid` 列挙型を追加する
50+
- @zztkm
4951
- [ADD] RPC 機能を追加する
52+
- RPC メソッドを表す列挙型 `RPCMethod` を追加する
53+
- `SignalingOffer` に以下の項目を追加する
54+
- `rpcMethods: [String]?`
55+
- `simulcastRpcRids: [Rid]?` を追加する
5056
- `MediaChannel``rpc` メソッドを追加する
57+
- `MediaChannel` に以下の項目を追加する
58+
- `rpcMethods: [RPCMethod]`
59+
- `rpcSimulcastRids: [Rid]`
5160
- RPC メソッドを定義するための `RPCMethodProtocol` プロトコルを追加する
61+
- `RPCMethodProtocol` に準拠した型を追加する
62+
- `RequestSimulcastRid`
63+
- `RequestSpotlightRid`
64+
- `ResetSpotlightRid`
65+
- `PutSignalingNotifyMetadata`
66+
- `PutSignalingNotifyMetadataItem`
5267
- RPC の ID を表す `RPCID` 列挙型を追加する
5368
- `int(Int)``string(String)` の 2 つのケースをサポート
5469
- RPC エラー応答の詳細を表す `RPCErrorDetail` 構造体を追加する
@@ -71,6 +86,9 @@
7186
- [UPDATE] jazzy の設定ファイルを更新する
7287
- `module_version` を 2025.3.0 に変更
7388
- @zztkm
89+
- [ADD] `Package.swift``testTarget` を追加する
90+
- xcodebuild で test を実行するために target を追加
91+
- @zztkm
7492

7593
## 2025.2.0
7694

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: fmt fmt-lint lint
1+
.PHONY: build fmt fmt-lint lint
22

33
# すべてを実行
44
all: fmt fmt-lint lint
@@ -7,6 +7,19 @@ all: fmt fmt-lint lint
77
fmt:
88
swift format --in-place --recursive Sora SoraTests
99

10+
# build
11+
build:
12+
xcodebuild \
13+
-scheme 'Sora' \
14+
-sdk iphoneos26.1 \
15+
-configuration Release \
16+
-derivedDataPath build \
17+
-destination 'generic/platform=iOS' \
18+
clean build \
19+
CODE_SIGNING_REQUIRED=NO \
20+
CODE_SIGN_IDENTITY= \
21+
PROVISIONING_PROFILE=
22+
1023
# swift-format lint
1124
fmt-lint:
1225
swift format lint --strict --parallel --recursive Sora SoraTests

Package.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@ let package = Package(
3030
exclude: ["Info.plist"],
3131
resources: [.process("VideoView.xib")]
3232
),
33+
.testTarget(
34+
name: "SoraTests",
35+
dependencies: ["Sora"],
36+
path: "SoraTests"
37+
),
3338
]
3439
)

Sora/MediaChannel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public final class MediaChannel {
180180
/// Sora サーバーから通知された、RPC で操作可能なサイマルキャスト rid が取得できます。
181181
///
182182
/// - Returns: 利用可能なサイマルキャスト rid の一覧。RPC が初期化されていない場合は空配列を返します
183-
public var rpcSimulcastRids: [SimulcastRequestRid] {
183+
public var rpcSimulcastRids: [Rid] {
184184
peerChannel.rpcChannel?.simulcastRpcRids ?? []
185185
}
186186

Sora/PeerChannel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class PeerChannel: NSObject, RTCPeerConnectionDelegate {
126126
var switchedToDataChannel: Bool = false
127127
var signalingOfferMessageDataChannels: [[String: Any]] = []
128128
var rpcAllowedMethods: [String] = []
129-
var rpcSimulcastRids: [SimulcastRequestRid] = []
129+
var rpcSimulcastRids: [Rid] = []
130130
var rpcChannel: RPCChannel?
131131

132132
weak var mediaChannel: MediaChannel?
@@ -956,7 +956,7 @@ class PeerChannel: NSObject, RTCPeerConnectionDelegate {
956956
}
957957

958958
if let simulcastRpcRids = offer.simulcastRpcRids {
959-
rpcSimulcastRids = simulcastRpcRids.toSimulcastRequestRids()
959+
rpcSimulcastRids = simulcastRpcRids
960960
} else {
961961
rpcSimulcastRids = []
962962
}

Sora/RPC.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ public final class RPCChannel {
7272
private let allowedMethodNames: Set<String>
7373

7474
/// Sora から払い出されたサイマルキャスト rid の一覧
75-
let simulcastRpcRids: [SimulcastRequestRid]
75+
let simulcastRpcRids: [Rid]
7676

7777
init?(
78-
dataChannel: DataChannel, rpcMethods: [String], simulcastRpcRids: [SimulcastRequestRid]
78+
dataChannel: DataChannel, rpcMethods: [String], simulcastRpcRids: [Rid]
7979
) {
8080
guard !rpcMethods.isEmpty else {
8181
return nil

Sora/Signaling.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public struct SignalingOffer {
479479
public var rpcMethods: [String]?
480480

481481
/// RPC 経由で切り替えられるサイマルキャストの rid
482-
public var simulcastRpcRids: [String]?
482+
public var simulcastRpcRids: [Rid]?
483483

484484
/// audio
485485
public let audio: Bool?
@@ -1167,7 +1167,7 @@ extension SignalingOffer: Codable {
11671167
videoCodecType = try container.decodeIfPresent(String.self, forKey: .video_codec_type)
11681168
videoBitRate = try container.decodeIfPresent(Int.self, forKey: .video_bit_rate)
11691169
rpcMethods = try container.decodeIfPresent([String].self, forKey: .rpc_methods)
1170-
simulcastRpcRids = try container.decodeIfPresent([String].self, forKey: .simulcast_rpc_rids)
1170+
simulcastRpcRids = try container.decodeIfPresent([Rid].self, forKey: .simulcast_rpc_rids)
11711171
}
11721172

11731173
public func encode(to encoder: Encoder) throws {
@@ -1447,9 +1447,3 @@ extension SignalingClose: Decodable {
14471447
}
14481448
}
14491449

1450-
/// :nodoc:
1451-
extension Array where Element == String {
1452-
func toSimulcastRequestRids() -> [SimulcastRequestRid] {
1453-
compactMap { simulcastRequestRidTable.right(other: $0) }
1454-
}
1455-
}

Sora/Types.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/// 映像の rid を表します。
2+
/// type: offer の simulcastRpcRids や RPC で利用される汎用 rid 型です。
3+
public enum Rid {
4+
/// 映像を受信しない
5+
case none
6+
7+
/// r0
8+
case r0
9+
10+
/// r1
11+
case r1
12+
13+
/// r2
14+
case r2
15+
}
16+
17+
private var ridTable: PairTable<String, Rid> =
18+
PairTable(
19+
name: "rid",
20+
pairs: [
21+
("none", .none),
22+
("r0", .r0),
23+
("r1", .r1),
24+
("r2", .r2),
25+
])
26+
27+
/// :nodoc:
28+
extension Rid: Codable {
29+
public init(from decoder: Decoder) throws {
30+
let container = try decoder.singleValueContainer()
31+
let string = try container.decode(String.self)
32+
guard let rid = ridTable.right(other: string) else {
33+
throw SoraError.invalidSignalingMessage
34+
}
35+
self = rid
36+
}
37+
38+
public func encode(to encoder: Encoder) throws {
39+
try ridTable.encode(self, to: encoder)
40+
}
41+
}

SoraTests/RidTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import XCTest
2+
3+
@testable import Sora
4+
5+
class RidTests: XCTestCase {
6+
func testRidEncodingAndDecoding() throws {
7+
let cases: [(Rid, String)] = [
8+
(.none, "\"none\""),
9+
(.r0, "\"r0\""),
10+
(.r1, "\"r1\""),
11+
(.r2, "\"r2\""),
12+
]
13+
14+
for (rid, expectedJson) in cases {
15+
// Encoding
16+
let encoder = JSONEncoder()
17+
let encodedData = try encoder.encode(rid)
18+
let encodedJson = String(data: encodedData, encoding: .utf8)
19+
XCTAssertEqual(encodedJson, expectedJson, "Failed encoding \(rid)")
20+
21+
// Decoding
22+
let decoder = JSONDecoder()
23+
let decodedRid = try decoder.decode(Rid.self, from: expectedJson.data(using: .utf8)!)
24+
XCTAssertEqual(decodedRid, rid, "Failed decoding \(expectedJson)")
25+
}
26+
}
27+
28+
func testDecodeInvalidRidThrowsError() throws {
29+
let decoder = JSONDecoder()
30+
let data = "\"invalid\"".data(using: .utf8)!
31+
XCTAssertThrowsError(try decoder.decode(Rid.self, from: data))
32+
}
33+
}
34+

0 commit comments

Comments
 (0)