-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iOS TvCasting app: Send Content Launch By URL request and Open commis…
…sioning window (#19779) * iOS TvCasting app: Open commissioning window and send Content Launch ByURL request * Added docs, fixed typos
- Loading branch information
1 parent
f986b80
commit 2210324
Showing
9 changed files
with
283 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentLauncherView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* | ||
* Copyright (c) 2020-2022 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import SwiftUI | ||
|
||
struct ContentLauncherView: View { | ||
@StateObject var viewModel = ContentLauncherViewModel() | ||
|
||
@State private var contentUrl: String = "" | ||
@State private var contentDisplayStr: String = "" | ||
|
||
var body: some View { | ||
VStack(alignment: .leading) { | ||
HStack() { | ||
Text("Content URL") | ||
|
||
TextField( | ||
"https://www.test.com/videoid", | ||
text: $contentUrl | ||
) | ||
.textInputAutocapitalization(.never) | ||
.disableAutocorrection(true) | ||
.border(.secondary) | ||
} | ||
|
||
HStack() { | ||
Text("Display string") | ||
|
||
TextField( | ||
"Test video", | ||
text: $contentDisplayStr | ||
) | ||
.textInputAutocapitalization(.never) | ||
.disableAutocorrection(true) | ||
.border(.secondary) | ||
} | ||
|
||
Button("Launch URL!") { | ||
viewModel.launchUrl(contentUrl: contentUrl, contentDisplayStr: contentDisplayStr) | ||
} | ||
.background(Color.blue) | ||
.foregroundColor(Color.white) | ||
.cornerRadius(4) | ||
.border(Color.black, width: 1) | ||
.padding() | ||
|
||
Text(viewModel.status ?? "") | ||
} | ||
.navigationTitle("Content Launcher") | ||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .top) | ||
} | ||
} | ||
|
||
struct ContentLauncherView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentLauncherView() | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentLauncherViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* | ||
* Copyright (c) 2020-2022 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
import Foundation | ||
import os.log | ||
|
||
class ContentLauncherViewModel: ObservableObject { | ||
let Log = Logger(subsystem: "com.matter.casting", | ||
category: "ContentLauncherViewModel") | ||
|
||
@Published var status: String?; | ||
|
||
func launchUrl(contentUrl: String?, contentDisplayStr: String?) | ||
{ | ||
if ((contentUrl != nil && !contentUrl!.isEmpty) && (contentDisplayStr != nil && !contentDisplayStr!.isEmpty)) | ||
{ | ||
if let castingServerBridge = CastingServerBridge.getSharedInstance() | ||
{ | ||
castingServerBridge | ||
.contentLauncherLaunchUrl(contentUrl!, | ||
contentDisplayStr: contentDisplayStr!, | ||
launchUrlResponseCallback: | ||
{ (result: Bool) -> () in | ||
self.Log.info("ContentLauncherViewModel.launchUrl.launchUrlResponseCallback result \(result)") | ||
self.status = result ? "Launched URL successfully" : "Launch URL failure!" | ||
}, | ||
clientQueue: DispatchQueue.main, | ||
launchUrlRequestSentHandler: | ||
{ (result: Bool) -> () in | ||
self.Log.info("ContentLauncherViewModel.launchUrl.launcUrlRequestSentHandler result \(result)") | ||
self.status = result ? "Sent Launch URL request" : "Failed to send Launch URL request!" | ||
}) | ||
} | ||
} | ||
else | ||
{ | ||
Log.debug("ContentLauncherViewModel.launchUrl input(s) missing!") | ||
self.status = "Missing input parameter(s)!" | ||
} | ||
} | ||
} |
Oops, something went wrong.