blink for ios-proxy app
This commit is contained in:
1 parent
66cba1a228
commit
412531861b
11 files changed
+314
-8
No files matched your search
@@ -39,7 +39,7 @@ func main() {
|
|||||||
log.Fatal("--cookies is required")
|
log.Fatal("--cookies is required")
|
||||||
}
|
}
|
||||||
if *loginFlag {
|
if *loginFlag {
|
||||||
if err := blink.LoginToFile(*cookiesPath, nil, common.EmitStatus, log.Printf); err != nil {
|
if err := blink.LoginToFile(*cookiesPath, nil, nil, common.EmitStatus, log.Printf); err != nil {
|
||||||
log.Fatalf("[login] %v", err)
|
log.Fatalf("[login] %v", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func main() {
|
|||||||
log.Fatalf("[auth] --cookies is required")
|
log.Fatalf("[auth] --cookies is required")
|
||||||
}
|
}
|
||||||
if *loginFlag {
|
if *loginFlag {
|
||||||
if err := blink.LoginToFile(*cookiesPath, nil, common.EmitStatus, log.Printf); err != nil {
|
if err := blink.LoginToFile(*cookiesPath, nil, nil, common.EmitStatus, log.Printf); err != nil {
|
||||||
log.Fatalf("[login] %v", err)
|
log.Fatalf("[login] %v", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import CoreImage.CIFilterBuiltins
|
||||||
|
|
||||||
|
struct BlinkLoginView: View {
|
||||||
|
let link: String
|
||||||
|
let onCopy: () -> Void
|
||||||
|
let onOpen: () -> Void
|
||||||
|
|
||||||
|
private static let qrContext = CIContext()
|
||||||
|
private static let qrSize: CGFloat = 204
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
Text(NSLocalizedString("blink_login_title", comment: ""))
|
||||||
|
.font(.headline)
|
||||||
|
|
||||||
|
Text(NSLocalizedString("blink_login_subtitle", comment: ""))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
|
||||||
|
if let qr = qrImage(link) {
|
||||||
|
Image(uiImage: qr)
|
||||||
|
.interpolation(.none)
|
||||||
|
.resizable()
|
||||||
|
.frame(width: Self.qrSize, height: Self.qrSize)
|
||||||
|
.padding(8)
|
||||||
|
.background(Color.white)
|
||||||
|
.cornerRadius(8)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(link)
|
||||||
|
.font(.system(.caption, design: .monospaced))
|
||||||
|
.textSelection(.enabled)
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Button(action: onCopy) {
|
||||||
|
Label(NSLocalizedString("blink_login_copy", comment: ""), systemImage: "doc.on.doc")
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
}
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
|
||||||
|
Button(action: onOpen) {
|
||||||
|
Label(NSLocalizedString("blink_login_open", comment: ""), systemImage: "arrow.up.forward.app")
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.horizontal)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func qrImage(_ text: String) -> UIImage? {
|
||||||
|
let filter = CIFilter.qrCodeGenerator()
|
||||||
|
filter.message = Data(text.utf8)
|
||||||
|
guard let output = filter.outputImage,
|
||||||
|
let cgImage = Self.qrContext.createCGImage(output, from: output.extent) else { return nil }
|
||||||
|
return UIImage(cgImage: cgImage)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,6 +47,10 @@ struct ContentView: View {
|
|||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let loginLink = proxyManager.loginLink {
|
||||||
|
BlinkLoginView(link: loginLink, onCopy: proxyManager.copyLoginLink, onOpen: proxyManager.openLoginLink)
|
||||||
|
}
|
||||||
|
|
||||||
if proxyManager.status == .tunnelConnected {
|
if proxyManager.status == .tunnelConnected {
|
||||||
ProxyInfoView(proxyUrl: proxyManager.socksUrl, onCopy: proxyManager.copyProxyUrl)
|
ProxyInfoView(proxyUrl: proxyManager.socksUrl, onCopy: proxyManager.copyProxyUrl)
|
||||||
|
|
||||||
@@ -65,6 +69,18 @@ struct ContentView: View {
|
|||||||
.buttonStyle(.borderedProminent)
|
.buttonStyle(.borderedProminent)
|
||||||
.tint(.blue)
|
.tint(.blue)
|
||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
|
|
||||||
|
Button(action: { proxyManager.runPing() }) {
|
||||||
|
Label(NSLocalizedString(proxyManager.pinging ? "ping_running" : "ping_run", comment: ""), systemImage: "dot.radiowaves.left.and.right")
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
}
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
.disabled(proxyManager.pinging)
|
||||||
|
.padding(.horizontal)
|
||||||
|
|
||||||
|
if let pingResult = proxyManager.pingResult {
|
||||||
|
PingResultView(result: pingResult)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.vertical, 12)
|
.padding(.vertical, 12)
|
||||||
@@ -173,6 +189,40 @@ struct ProxyInfoView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct PingResultView: View {
|
||||||
|
let result: PingResult
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
switch result {
|
||||||
|
case .ok(let ms):
|
||||||
|
pill(text: String(format: NSLocalizedString("ping_ok", comment: ""), Ping.host),
|
||||||
|
detail: String(format: NSLocalizedString("ping_ms", comment: ""), ms),
|
||||||
|
color: .green)
|
||||||
|
case .timeout:
|
||||||
|
pill(text: String(format: NSLocalizedString("ping_fail", comment: ""), Ping.host),
|
||||||
|
detail: NSLocalizedString("ping_timeout", comment: ""),
|
||||||
|
color: .red)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func pill(text: String, detail: String, color: Color) -> some View {
|
||||||
|
HStack {
|
||||||
|
Text(text)
|
||||||
|
.font(.caption)
|
||||||
|
Spacer(minLength: 8)
|
||||||
|
Text(detail)
|
||||||
|
.font(.system(.caption, design: .monospaced))
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundColor(color)
|
||||||
|
}
|
||||||
|
.padding(.horizontal)
|
||||||
|
.padding(.vertical, 6)
|
||||||
|
.background(color.opacity(0.1))
|
||||||
|
.cornerRadius(8)
|
||||||
|
.padding(.horizontal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct LogView: View {
|
struct LogView: View {
|
||||||
let logs: [String]
|
let logs: [String]
|
||||||
@State private var userScrolledUp = false
|
@State private var userScrolledUp = false
|
||||||
|
|||||||
@@ -34,5 +34,16 @@
|
|||||||
"vp8_reliable_title" = "Reliable (KCP)";
|
"vp8_reliable_title" = "Reliable (KCP)";
|
||||||
"vp8_reliable_sub" = "Wrap the video tunnel with KCP reliability. Off = raw VP8, faster but lossy.";
|
"vp8_reliable_sub" = "Wrap the video tunnel with KCP reliability. Off = raw VP8, faster but lossy.";
|
||||||
"proxy_url_copied" = "Proxy URL copied";
|
"proxy_url_copied" = "Proxy URL copied";
|
||||||
|
"ping_run" = "Ping through tunnel";
|
||||||
|
"ping_running" = "Pinging...";
|
||||||
|
"ping_ok" = "%@ reached via tunnel";
|
||||||
|
"ping_fail" = "%@ not reachable via tunnel";
|
||||||
|
"ping_ms" = "%d ms";
|
||||||
|
"ping_timeout" = "timeout";
|
||||||
"toast_happ_params_copied" = "v2ray URL copied";
|
"toast_happ_params_copied" = "v2ray URL copied";
|
||||||
"dc_mode_not_supported" = "DC mode not supported - falling back to video";
|
"dc_mode_not_supported" = "DC mode not supported - falling back to video";
|
||||||
|
"blink_login_title" = "Log in to Blink";
|
||||||
|
"blink_login_subtitle" = "Scan the QR with the Blink app on another phone, open the link on this phone, or copy it and send it to whoever has Blink.";
|
||||||
|
"blink_login_open" = "Open in Blink";
|
||||||
|
"blink_login_copy" = "Copy link";
|
||||||
|
"blink_login_copied" = "Login link copied";
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
enum PingResult {
|
||||||
|
case ok(Int)
|
||||||
|
case timeout
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Ping {
|
||||||
|
static let host = "google.com"
|
||||||
|
static let port: UInt16 = 443
|
||||||
|
static let readTimeoutSeconds = 15
|
||||||
|
|
||||||
|
static func run(socksPort: Int, user: String, pass: String) -> PingResult {
|
||||||
|
let start = DispatchTime.now()
|
||||||
|
guard probeViaSocks5(socksPort: socksPort, user: user, pass: pass) else { return .timeout }
|
||||||
|
let elapsedNs = DispatchTime.now().uptimeNanoseconds - start.uptimeNanoseconds
|
||||||
|
return .ok(Int(Double(elapsedNs) / 1_000_000))
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func probeViaSocks5(socksPort: Int, user: String, pass: String) -> Bool {
|
||||||
|
let userBytes = Array(user.utf8)
|
||||||
|
let passBytes = Array(pass.utf8)
|
||||||
|
let hostBytes = Array(host.utf8)
|
||||||
|
guard userBytes.count <= UInt8.max, passBytes.count <= UInt8.max else { return false }
|
||||||
|
|
||||||
|
let socketFD = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
|
||||||
|
if socketFD == -1 { return false }
|
||||||
|
defer { close(socketFD) }
|
||||||
|
|
||||||
|
var noSigPipe: Int32 = 1
|
||||||
|
setsockopt(socketFD, SOL_SOCKET, SO_NOSIGPIPE, &noSigPipe, socklen_t(MemoryLayout<Int32>.size))
|
||||||
|
var readTimeout = timeval(tv_sec: readTimeoutSeconds, tv_usec: 0)
|
||||||
|
setsockopt(socketFD, SOL_SOCKET, SO_RCVTIMEO, &readTimeout, socklen_t(MemoryLayout<timeval>.size))
|
||||||
|
|
||||||
|
var addr = sockaddr_in()
|
||||||
|
addr.sin_len = UInt8(MemoryLayout<sockaddr_in>.size)
|
||||||
|
addr.sin_family = sa_family_t(AF_INET)
|
||||||
|
addr.sin_port = in_port_t(socksPort).bigEndian
|
||||||
|
addr.sin_addr.s_addr = in_addr_t(INADDR_LOOPBACK).bigEndian
|
||||||
|
let connected = withUnsafePointer(to: &addr) { addrPtr in
|
||||||
|
addrPtr.withMemoryRebound(to: sockaddr.self, capacity: 1) { sockaddrPtr in
|
||||||
|
connect(socketFD, sockaddrPtr, socklen_t(MemoryLayout<sockaddr_in>.size))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if connected != 0 { return false }
|
||||||
|
|
||||||
|
guard sendAll(socketFD, [0x05, 0x01, 0x02]), readBytes(socketFD, 2) == [0x05, 0x02] else { return false }
|
||||||
|
|
||||||
|
let authPacket = [0x01, UInt8(userBytes.count)] + userBytes + [UInt8(passBytes.count)] + passBytes
|
||||||
|
guard sendAll(socketFD, authPacket), readBytes(socketFD, 2) == [0x01, 0x00] else { return false }
|
||||||
|
|
||||||
|
let request = [0x05, 0x01, 0x00, 0x03, UInt8(hostBytes.count)] + hostBytes + [UInt8(port >> 8), UInt8(port & 0xff)]
|
||||||
|
guard sendAll(socketFD, request) else { return false }
|
||||||
|
return readBytes(socketFD, 2) == [0x05, 0x00]
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func sendAll(_ socketFD: Int32, _ bytes: [UInt8]) -> Bool {
|
||||||
|
var offset = 0
|
||||||
|
while offset < bytes.count {
|
||||||
|
let sent = bytes[offset...].withUnsafeBytes { buffer in
|
||||||
|
send(socketFD, buffer.baseAddress, buffer.count, 0)
|
||||||
|
}
|
||||||
|
if sent <= 0 { return false }
|
||||||
|
offset += sent
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func readBytes(_ socketFD: Int32, _ count: Int) -> [UInt8]? {
|
||||||
|
var buffer = [UInt8](repeating: 0, count: count)
|
||||||
|
var offset = 0
|
||||||
|
while offset < count {
|
||||||
|
let received = buffer[offset...].withUnsafeMutableBytes { slice in
|
||||||
|
recv(socketFD, slice.baseAddress, slice.count, 0)
|
||||||
|
}
|
||||||
|
if received <= 0 { return nil }
|
||||||
|
offset += received
|
||||||
|
}
|
||||||
|
return buffer
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -122,11 +122,13 @@ enum CallPlatform: String {
|
|||||||
case wbstream = "wbstream"
|
case wbstream = "wbstream"
|
||||||
case dion = "dion"
|
case dion = "dion"
|
||||||
case bitrix = "bitrix"
|
case bitrix = "bitrix"
|
||||||
|
case blink = "blink"
|
||||||
|
|
||||||
static let wbstreamPrefix = "wbstream://"
|
static let wbstreamPrefix = "wbstream://"
|
||||||
static let dionPrefix = "dion://"
|
static let dionPrefix = "dion://"
|
||||||
static let dionEventInfix = "dion.vc/event/"
|
static let dionEventInfix = "dion.vc/event/"
|
||||||
static let bitrixMarker = "/video/"
|
static let bitrixMarker = "/video/"
|
||||||
|
static let blinkPrefix = "blink://"
|
||||||
|
|
||||||
static func detect(url: String) -> CallPlatform {
|
static func detect(url: String) -> CallPlatform {
|
||||||
if url.hasPrefix(dionPrefix) || url.contains(dionEventInfix) {
|
if url.hasPrefix(dionPrefix) || url.contains(dionEventInfix) {
|
||||||
@@ -138,6 +140,9 @@ enum CallPlatform: String {
|
|||||||
if url.contains("bitrix24") && url.contains(bitrixMarker) {
|
if url.contains("bitrix24") && url.contains(bitrixMarker) {
|
||||||
return .bitrix
|
return .bitrix
|
||||||
}
|
}
|
||||||
|
if url.hasPrefix(blinkPrefix) || (url.contains("blinkmap.com") && url.contains("/join/")) {
|
||||||
|
return .blink
|
||||||
|
}
|
||||||
if url.contains("telemost") {
|
if url.contains("telemost") {
|
||||||
return .telemost
|
return .telemost
|
||||||
}
|
}
|
||||||
@@ -169,6 +174,8 @@ class ProxyManager: ObservableObject {
|
|||||||
@Published var isRunning: Bool = false
|
@Published var isRunning: Bool = false
|
||||||
@Published var toastMessage: String?
|
@Published var toastMessage: String?
|
||||||
@Published var statusText: String?
|
@Published var statusText: String?
|
||||||
|
@Published var pinging: Bool = false
|
||||||
|
@Published var pingResult: PingResult?
|
||||||
var detectedPlatform: CallPlatform = .vk
|
var detectedPlatform: CallPlatform = .vk
|
||||||
|
|
||||||
@Published var callUrl: String = AppDefaults.lastUrl { didSet { AppDefaults.lastUrl = callUrl } }
|
@Published var callUrl: String = AppDefaults.lastUrl { didSet { AppDefaults.lastUrl = callUrl } }
|
||||||
@@ -230,6 +237,12 @@ class ProxyManager: ObservableObject {
|
|||||||
return result == 0
|
return result == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func blinkCookiesPath() -> String {
|
||||||
|
let directory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
|
||||||
|
try? FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
|
||||||
|
return directory.appendingPathComponent("cookies-blink.json").path
|
||||||
|
}
|
||||||
|
|
||||||
func connect() {
|
func connect() {
|
||||||
guard !callUrl.isEmpty else { return }
|
guard !callUrl.isEmpty else { return }
|
||||||
|
|
||||||
@@ -375,6 +388,24 @@ class ProxyManager: ObservableObject {
|
|||||||
IosSendJoinParams(jsonString)
|
IosSendJoinParams(jsonString)
|
||||||
appendLog("Sent join params")
|
appendLog("Sent join params")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case .blink:
|
||||||
|
IosStartBlinkHeadless(socksPort, activeSocksUser, activeSocksPass, bridge)
|
||||||
|
appendLog("Started Blink headless joiner")
|
||||||
|
let joinParams: [String: Any] = [
|
||||||
|
"joinLink": callUrl,
|
||||||
|
"cookiesPath": blinkCookiesPath(),
|
||||||
|
"tunnelMode": tunnelMode.rawValue,
|
||||||
|
"vp8Fps": vp8Fps,
|
||||||
|
"vp8Batch": vp8Batch,
|
||||||
|
"dualTrack": dualTrack,
|
||||||
|
"reliable": reliable,
|
||||||
|
]
|
||||||
|
if let jsonData = try? JSONSerialization.data(withJSONObject: joinParams),
|
||||||
|
let jsonString = String(data: jsonData, encoding: .utf8) {
|
||||||
|
IosSendJoinParams(jsonString)
|
||||||
|
appendLog("Sent join params")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,7 +423,9 @@ class ProxyManager: ObservableObject {
|
|||||||
func resetAll() {
|
func resetAll() {
|
||||||
disconnect()
|
disconnect()
|
||||||
captchaURL = nil
|
captchaURL = nil
|
||||||
|
loginLink = nil
|
||||||
statusText = nil
|
statusText = nil
|
||||||
|
pingResult = nil
|
||||||
logs.removeAll()
|
logs.removeAll()
|
||||||
pendingLogs.removeAll()
|
pendingLogs.removeAll()
|
||||||
errorMessage = ""
|
errorMessage = ""
|
||||||
@@ -400,6 +433,7 @@ class ProxyManager: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Published var captchaURL: String?
|
@Published var captchaURL: String?
|
||||||
|
@Published var loginLink: String?
|
||||||
|
|
||||||
func handleStatus(_ statusString: String) {
|
func handleStatus(_ statusString: String) {
|
||||||
if statusString.hasPrefix("ERROR:") {
|
if statusString.hasPrefix("ERROR:") {
|
||||||
@@ -408,16 +442,27 @@ class ProxyManager: ObservableObject {
|
|||||||
errorMessage = errorText
|
errorMessage = errorText
|
||||||
isRunning = false
|
isRunning = false
|
||||||
captchaURL = nil
|
captchaURL = nil
|
||||||
|
if loginLink != nil {
|
||||||
|
loginLink = nil
|
||||||
|
statusText = nil
|
||||||
|
}
|
||||||
appendLog("ERROR: \(errorText)")
|
appendLog("ERROR: \(errorText)")
|
||||||
} else if statusString.hasPrefix("CAPTCHA:") {
|
} else if statusString.hasPrefix("CAPTCHA:") {
|
||||||
captchaURL = String(statusString.dropFirst(8))
|
captchaURL = String(statusString.dropFirst(8))
|
||||||
statusText = NSLocalizedString("status_solve_captcha", comment: "")
|
statusText = NSLocalizedString("status_solve_captcha", comment: "")
|
||||||
appendLog("Captcha: \(captchaURL ?? "")")
|
appendLog("Captcha: \(captchaURL ?? "")")
|
||||||
|
} else if statusString.hasPrefix("LOGIN_LINK:") {
|
||||||
|
loginLink = String(statusString.dropFirst(11))
|
||||||
|
statusText = NSLocalizedString("blink_login_title", comment: "")
|
||||||
} else {
|
} else {
|
||||||
if captchaURL != nil && statusString != "CAPTCHA" {
|
if captchaURL != nil && statusString != "CAPTCHA" {
|
||||||
captchaURL = nil
|
captchaURL = nil
|
||||||
statusText = nil
|
statusText = nil
|
||||||
}
|
}
|
||||||
|
if loginLink != nil {
|
||||||
|
loginLink = nil
|
||||||
|
statusText = nil
|
||||||
|
}
|
||||||
status = ProxyStatus(rawValue: statusString) ?? .idle
|
status = ProxyStatus(rawValue: statusString) ?? .idle
|
||||||
appendLog("Status: \(statusString)")
|
appendLog("Status: \(statusString)")
|
||||||
}
|
}
|
||||||
@@ -474,4 +519,32 @@ class ProxyManager: ObservableObject {
|
|||||||
showToast(NSLocalizedString("toast_happ_params_copied", comment: ""))
|
showToast(NSLocalizedString("toast_happ_params_copied", comment: ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func copyLoginLink() {
|
||||||
|
guard let link = loginLink else { return }
|
||||||
|
UIPasteboard.general.string = link
|
||||||
|
showToast(NSLocalizedString("blink_login_copied", comment: ""))
|
||||||
|
}
|
||||||
|
|
||||||
|
func openLoginLink() {
|
||||||
|
if let link = loginLink, let url = URL(string: link) {
|
||||||
|
UIApplication.shared.open(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runPing() {
|
||||||
|
guard !pinging else { return }
|
||||||
|
pinging = true
|
||||||
|
pingResult = nil
|
||||||
|
let port = socksPort
|
||||||
|
let user = activeSocksUser
|
||||||
|
let pass = activeSocksPass
|
||||||
|
DispatchQueue.global(qos: .userInitiated).async { [weak self] in
|
||||||
|
let result = Ping.run(socksPort: port, user: user, pass: pass)
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self?.pingResult = result
|
||||||
|
self?.pinging = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+4
-1
@@ -26,7 +26,10 @@ const (
|
|||||||
InviteLinkHost = "blinkmap.com"
|
InviteLinkHost = "blinkmap.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrLoginPending = errors.New("blink login is not approved yet")
|
var (
|
||||||
|
ErrLoginPending = errors.New("blink login is not approved yet")
|
||||||
|
ErrLoginCancelled = errors.New("blink login cancelled")
|
||||||
|
)
|
||||||
|
|
||||||
type StatusError struct {
|
type StatusError struct {
|
||||||
Operation string
|
Operation string
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ func SaveTokens(path string, tokens TokenPair) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoginToFile(path string, client *http.Client, statusFn func(string), logFn func(string, ...any)) error {
|
func LoginToFile(path string, client *http.Client, stop <-chan struct{}, statusFn func(string), logFn func(string, ...any)) error {
|
||||||
tokens, err := waitForLogin(client, statusFn, logFn)
|
tokens, err := waitForLogin(client, stop, statusFn, logFn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ func accessTokenFresh(tokens TokenPair) bool {
|
|||||||
return tokens.Token != "" && expiresIn > accessTokenRefreshMargin
|
return tokens.Token != "" && expiresIn > accessTokenRefreshMargin
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitForLogin(client *http.Client, statusFn func(string), logFn func(string, ...any)) (TokenPair, error) {
|
func waitForLogin(client *http.Client, stop <-chan struct{}, statusFn func(string), logFn func(string, ...any)) (TokenPair, error) {
|
||||||
for {
|
for {
|
||||||
request, err := RequestLogin(client)
|
request, err := RequestLogin(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -190,7 +190,11 @@ func waitForLogin(client *http.Client, statusFn func(string), logFn func(string,
|
|||||||
}
|
}
|
||||||
renewAt := time.Now().Add(time.Duration(float64(ttl)*loginRenewFraction) * time.Second)
|
renewAt := time.Now().Add(time.Duration(float64(ttl)*loginRenewFraction) * time.Second)
|
||||||
for time.Now().Before(renewAt) {
|
for time.Now().Before(renewAt) {
|
||||||
time.Sleep(loginPollInterval)
|
select {
|
||||||
|
case <-stop:
|
||||||
|
return TokenPair{}, ErrLoginCancelled
|
||||||
|
case <-time.After(loginPollInterval):
|
||||||
|
}
|
||||||
tokens, err := PollLogin(client, request.WAT)
|
tokens, err := PollLogin(client, request.WAT)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return tokens, nil
|
return tokens, nil
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ func (j *BlinkHeadlessJoiner) loadCredentials() (*blink.Credentials, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (j *BlinkHeadlessJoiner) login() error {
|
func (j *BlinkHeadlessJoiner) login() error {
|
||||||
return blink.LoginToFile(j.cookiesPath, j.httpClient, j.Status.EmitStatus, j.logFn)
|
return blink.LoginToFile(j.cookiesPath, j.httpClient, j.stopCh, j.Status.EmitStatus, j.logFn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *BlinkHeadlessJoiner) waitBeforeRetry(attempt int) bool {
|
func (j *BlinkHeadlessJoiner) waitBeforeRetry(attempt int) bool {
|
||||||
|
|||||||
@@ -201,6 +201,26 @@ func StartBitrixHeadless(socksPort int, socksUser, socksPass string, callback He
|
|||||||
callback.OnStatus(common.StatusReady)
|
callback.OnStatus(common.StatusReady)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StartBlinkHeadless(socksPort int, socksUser, socksPass string, callback HeadlessCallback) {
|
||||||
|
StopHeadless()
|
||||||
|
|
||||||
|
activeHeadless.Lock()
|
||||||
|
activeHeadless.callback = callback
|
||||||
|
activeHeadless.stopped = false
|
||||||
|
activeHeadless.platform = "blink"
|
||||||
|
activeHeadless.Unlock()
|
||||||
|
|
||||||
|
logFn, resolveFn, statusEmitter := makeHelpers(callback)
|
||||||
|
blinkJoiner := joiner.NewBlinkHeadlessJoiner(logFn, resolveFn, statusEmitter, nil)
|
||||||
|
blinkJoiner.OnConnected = makeOnConnected(socksPort, socksUser, socksPass, logFn, callback, blinkJoiner.MarkConfigAcked)
|
||||||
|
|
||||||
|
activeHeadless.Lock()
|
||||||
|
activeHeadless.joiner = blinkJoiner
|
||||||
|
activeHeadless.Unlock()
|
||||||
|
|
||||||
|
callback.OnStatus(common.StatusReady)
|
||||||
|
}
|
||||||
|
|
||||||
func StartVKHeadless(socksPort int, socksUser, socksPass string, joinLink, displayName, tunnelMode string, vp8Fps, vp8Batch int, dualTrack bool, callback HeadlessCallback) {
|
func StartVKHeadless(socksPort int, socksUser, socksPass string, joinLink, displayName, tunnelMode string, vp8Fps, vp8Batch int, dualTrack bool, callback HeadlessCallback) {
|
||||||
StopHeadless()
|
StopHeadless()
|
||||||
|
|
||||||
@@ -275,6 +295,10 @@ func SendJoinParams(jsonParams string) {
|
|||||||
if bxJoiner, ok := currentJoiner.(*joiner.BitrixHeadlessJoiner); ok {
|
if bxJoiner, ok := currentJoiner.(*joiner.BitrixHeadlessJoiner); ok {
|
||||||
go bxJoiner.RunWithParams(jsonParams)
|
go bxJoiner.RunWithParams(jsonParams)
|
||||||
}
|
}
|
||||||
|
case "blink":
|
||||||
|
if blinkJoiner, ok := currentJoiner.(*joiner.BlinkHeadlessJoiner); ok {
|
||||||
|
go blinkJoiner.RunWithParams(jsonParams)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user