Skip to content

Commit

Permalink
ui fixes, connect by link
Browse files Browse the repository at this point in the history
commit 4403e15874cc2e9254e36cf5f0e21df919bb02a4
Author: Hiroshi Horie <[email protected]>
Date:   Mon Feb 28 08:31:09 2022 +0900

    format

commit cb7f2a246aac8d401c7a4c4eaa56e64162d747ce
Author: Hiroshi Horie <[email protected]>
Date:   Wed Feb 23 00:23:09 2022 +0700

    remove default port

commit 10ebd2654d134f5c49ffdc5cc38a659e7564176b
Author: Hiroshi Horie <[email protected]>
Date:   Wed Feb 23 00:17:19 2022 +0700

    impl
  • Loading branch information
hiroshihorie committed Feb 27, 2022
1 parent 4d2e166 commit 740cbaa
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 8 deletions.
10 changes: 6 additions & 4 deletions Shared/ConnectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ struct ConnectView: View {
ScrollView {
VStack(alignment: .center, spacing: 40.0) {

VStack(spacing: 20) {
VStack(spacing: 10) {
Image("logo")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 40)
.frame(height: 30)
Text("SDK Version \(LiveKit.version)")
Text("Example App Version \(Bundle.main.appVersionLong) (\(Bundle.main.appBuild))")
}

VStack(spacing: 20) {
VStack(spacing: 15) {
LKTextField(title: "Server URL", text: $roomCtx.url, type: .URL)
LKTextField(title: "Token", text: $roomCtx.token, type: .ascii)

Expand Down Expand Up @@ -132,7 +132,9 @@ struct ConnectView: View {
.frame(minHeight: geometry.size.height) // Set the content’s min height to the parent
}
}

#if os(macOS)
.frame(minWidth: 500, minHeight: 500)
#endif
.alert(isPresented: $roomCtx.shouldShowError) {
Alert(title: Text("Error"),
message: Text(roomCtx.latestError != nil
Expand Down
2 changes: 1 addition & 1 deletion Shared/Controllers/RoomContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ final class RoomContext: ObservableObject {
extension RoomContext: RoomDelegate {

func room(_ room: Room, didUpdate connectionState: ConnectionState, oldValue: ConnectionState) {

guard !connectionState.isEqual(to: oldValue, includingAssociatedValues: false) else {
print("Skipping same conectionState")
return
Expand Down
2 changes: 1 addition & 1 deletion Shared/ExampleObservableRoom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class ExampleObservableRoom: ObservableRoom {
override func room(_ room: Room, didUpdate connectionState: ConnectionState, oldValue: ConnectionState) {

super.room(room, didUpdate: connectionState, oldValue: oldValue)

guard !connectionState.isEqual(to: oldValue, includingAssociatedValues: false) else {
print("Skipping same conectionState")
return
Expand Down
34 changes: 33 additions & 1 deletion Shared/LiveKitExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let sync = ValueStore<Preferences>(store: Keychain(service: "io.livekit.example"

struct RoomContextView: View {

@EnvironmentObject var appCtx: AppContext
@StateObject var roomCtx = RoomContext(store: sync)

var shouldShowRoomView: Bool {
Expand Down Expand Up @@ -37,14 +38,44 @@ struct RoomContextView: View {
ConnectView()
}

}.foregroundColor(Color.white)
}
.foregroundColor(Color.white)
.environmentObject(roomCtx)
.environmentObject(roomCtx.room)
.navigationTitle(computeTitle())
.onDisappear {
print("\(String(describing: type(of: self))) onDisappear")
roomCtx.disconnect()
}
.onOpenURL(perform: { url in

guard let urlComponent = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return }
guard let host = url.host else { return }

let secureValue = urlComponent.queryItems?.first(where: { $0.name == "secure" })?.value?.lowercased()
let secure = ["true", "1"].contains { $0 == secureValue }

let tokenValue = urlComponent.queryItems?.first(where: { $0.name == "token" })?.value ?? ""

var builder = URLComponents()
builder.scheme = secure ? "wss" : "ws"
builder.host = host
builder.port = url.port

guard let builtUrl = builder.url?.absoluteString else { return }

print("built URL: \(builtUrl), token: \(tokenValue)")

DispatchQueue.main.async {
roomCtx.url = builtUrl
roomCtx.token = tokenValue
if !roomCtx.token.isEmpty {
roomCtx.connect().then { room in
appCtx.connectionHistory.update(room: room)
}
}
}
})
}
}

Expand Down Expand Up @@ -104,6 +135,7 @@ struct LiveKitExample: App {
RoomContextView()
.environmentObject(appCtx)
}
.handlesExternalEvents(matching: Set(arrayLiteral: "*"))
#if os(macOS)
.windowStyle(.hiddenTitleBar)
.windowToolbarStyle(.unifiedCompact)
Expand Down
2 changes: 1 addition & 1 deletion Shared/ParticipantView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct ParticipantView: View {
}
}
}

if let trackStats = trackStats, trackStats.bpsSent != 0 {
HStack(spacing: 3) {
Image(systemSymbol: .arrowUpCircle)
Expand Down
10 changes: 10 additions & 0 deletions Shared/RoomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ struct RoomView: View {

Spacer()

#if os(macOS)
Button {
if let url = URL(string: "livekit://") {
NSWorkspace.shared.open(url)
}
} label: {
Image(systemSymbol: .plusCircle)
}
#endif

Menu {
Toggle("Show info overlay", isOn: $appCtx.showInformationOverlay)

Expand Down
9 changes: 9 additions & 0 deletions iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,14 @@
</array>
<key>NSFaceIDUsageDescription</key>
<string>Keychain is used to store all preferences.</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>livekit</string>
</array>
</dict>
</array>
</dict>
</plist>
9 changes: 9 additions & 0 deletions macOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,14 @@
<string>uses your camera for video chat</string>
<key>NSMicrophoneUsageDescription</key>
<string>uses your microphone for video chat</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>livekit</string>
</array>
</dict>
</array>
</dict>
</plist>

0 comments on commit 740cbaa

Please sign in to comment.