Last active
July 11, 2018 16:49
-
-
Save LukeChannings/5450060fd620360c832876841e081f62 to your computer and use it in GitHub Desktop.
browser.swift
This file contains hidden or 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
import Foundation | |
print("Scanning for chromecasts") | |
class BrowserDelegate : NSObject, NetServiceBrowserDelegate { | |
var chromeCasts: [NetService] = [] | |
func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) { | |
let existingChromeCast = chromeCasts.filter({ $0.name == service.name }) | |
if existingChromeCast.isEmpty { | |
chromeCasts.append(service) | |
} | |
} | |
func netServiceBrowser(_ browser: NetServiceBrowser, didRemove service: NetService, moreComing: Bool) { | |
chromeCasts = chromeCasts.filter({ $0.name != service.name }) | |
} | |
} | |
let browser = NetServiceBrowser() | |
let browserDelegate = BrowserDelegate() | |
browser.delegate = browserDelegate | |
browser.searchForServices(ofType: "_googlecast._tcp.", inDomain: "") | |
RunLoop.current.run(until: Date(timeIntervalSinceNow: 10.0)) | |
print("Found \(browserDelegate.chromeCasts.count) ChromeCasts.") | |
for cc in browserDelegate.chromeCasts { | |
print( | |
""" | |
--- | |
Name: \(cc.name) | |
Type: \(cc.type) | |
Domain: \(cc.domain) | |
Addresses: \(cc.addresses!.map({ String(data: $0, encoding: .utf8) ?? "Couldn't decode Data" }).joined(separator: ", ")). Data length: \(cc.addresses!.count) | |
txtRecordData: \(String(data: cc.txtRecordData()!, encoding: .utf8)!) | |
""" | |
) | |
} |
This file contains hidden or 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
CastIron:master* λ /Users/luke/Library/Developer/Xcode/DerivedData/browse-test-cjdvjeiqrmdmlkaxatplggloinpz/Build/Products/Debug/browse-test | |
Scanning for chromecasts | |
Found 1 ChromeCasts. | |
--- | |
Name: Chromecast-Ultra-0a473f3e7745be6bbf3ad9710e7f9031 | |
Type: _googlecast._tcp. | |
Domain: local. | |
Addresses: . Data length: 0 | |
txtRecordData: | |
CastIron:master* λ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment