Skip to content
Merged
2 changes: 1 addition & 1 deletion OpenParsec/CParsec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum ParsecResolution: String, CaseIterable, Hashable {
case r1280x720_16_9 = "1280x720 (16:9)"
case r1024x768_4_3 = "1024x768 (4:3)"

private static var clientSize: (width: Int, height: Int) = (3480, 2160)
private static var clientSize: (width: Int, height: Int) = (3840, 2160)

var width: Int {
switch self {
Expand Down
6 changes: 0 additions & 6 deletions OpenParsec/GameController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ class GamepadController {
// private var panRecognizer: UIPanGestureRecognizer!
weak var delegate: InputManagerDelegate?

let viewController: UIViewController

init(viewController: UIViewController ) {
self.viewController = viewController
}

public func viewDidLoad() {

NotificationCenter.default.addObserver(self,
Expand Down
57 changes: 34 additions & 23 deletions OpenParsec/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,25 @@ struct LoginView: View {
"tfa": tfa
], options: [])

let task = URLSession.shared.dataTask(with: request) { (data, response, _) in
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
DispatchQueue.main.async {
isLoading = false
if let data = data {
guard let statusCode = (response as? HTTPURLResponse)?.statusCode else { return }
guard let statusCode = (response as? HTTPURLResponse)?.statusCode else {
alertText = "Bad response from the server"
showAlert = true
return
}
let decoder = JSONDecoder()

print("Login Information:")
print(statusCode)
print(String(data: data, encoding: .utf8)!)

if statusCode == 201 { // 201 Created
// store it and recover it from the next app opening, so people won't swear
NetworkHandler.clinfo = try? decoder.decode(ClientInfo.self, from: data)
guard let info: ClientInfo = try? decoder.decode(ClientInfo.self, from: data) else {
alertText = "Bad response from the server"
showAlert = true
return
}
NetworkHandler.clinfo = info

saveToKeychain(data: data, key: GLBDataModel.shared.SessionKeyChainKey)

Expand All @@ -185,27 +190,33 @@ struct LoginView: View {
c.setView(.main)
}
} else if statusCode >= 400 { // 4XX client errors
guard let info: ErrorInfo = try? decoder.decode(ErrorInfo.self, from: data) else { return }

do {
let json = try JSONSerialization.jsonObject(with: data, options: [])
if let dict = json as? [String: Any], let isTFARequired = dict["tfa_required"] as? Bool {
print("Code output:")
print(dict)
if isTFARequired {
presentTFAAlert = true
} else {
alertText = "Error: \(info)"
showAlert = true
}
guard let info: ErrorInfo = try? decoder.decode(ErrorInfo.self, from: data) else {
alertText = "Login failed (HTTP \(statusCode))"
showAlert = true
return
}

let json = try? JSONSerialization.jsonObject(with: data, options: [])
if let dict = json as? [String: Any], let isTFARequired = dict["tfa_required"] as? Bool {
print("Code output:")
print(dict)
if isTFARequired {
presentTFAAlert = true
} else {
alertText = info.error
alertText = "Error: \(info)"
showAlert = true
}
} catch {
print("Error on trying JSON Serialization on error data!")
} else {
alertText = info.error
showAlert = true
}
} else {
alertText = "Login failed (HTTP \(statusCode))"
showAlert = true
}
} else {
alertText = error?.localizedDescription ?? "Could not reach the server"
showAlert = true
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions OpenParsec/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ struct MainView: View {

let task = URLSession.shared.dataTask(with: request) { (data, response, _) in
DispatchQueue.main.async {
defer { isRefreshing = false }

if let data = data {
guard let statusCode = (response as? HTTPURLResponse)?.statusCode else { return }
let decoder = JSONDecoder()
Expand Down Expand Up @@ -478,8 +480,6 @@ struct MainView: View {
showBaseAlert = true
}
}

isRefreshing = false
}
}
task.resume()
Expand Down Expand Up @@ -566,8 +566,6 @@ struct MainView: View {
showBaseAlert = true
}
}

isRefreshing = false
}
}
task.resume()
Expand Down Expand Up @@ -597,6 +595,7 @@ struct MainView: View {
c.setView(.parsec)
}
} else {
CParsec.disconnect()
baseAlertText = "Error connecting to host (code \(status.rawValue))"
showBaseAlert = true
}
Expand Down
12 changes: 7 additions & 5 deletions OpenParsec/ParsecGLKViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ParsecGLKViewController: ParsecPlayground {
var glkRenderer: ParsecGLKRenderer!
let updateImage: () -> Void

let viewController: UIViewController
weak var viewController: UIViewController?

required init(viewController: UIViewController, updateImage: @escaping () -> Void) {
self.viewController = viewController
Expand All @@ -43,7 +43,7 @@ class ParsecGLKViewController: ParsecPlayground {
public func viewDidLoad() {
glkView = GLKView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
glkRenderer = ParsecGLKRenderer(glkView, glkViewController, updateImage)
self.viewController.view.addSubview(glkView)
self.viewController?.view.addSubview(glkView)
setupGLKViewController()
ParsecBackgroundManager.shared.glkViewController = glkViewController

Expand All @@ -62,9 +62,11 @@ class ParsecGLKViewController: ParsecPlayground {
glkViewController.preferredFramesPerSecond = fps
}

self.viewController.addChild(glkViewController)
self.viewController.view.addSubview(glkViewController.view)
self.glkViewController.didMove(toParent: self.viewController)
if let parent = viewController {
parent.addChild(glkViewController)
parent.view.addSubview(glkViewController.view)
glkViewController.didMove(toParent: parent)
}
}

var eaglContext: EAGLContext? {
Expand Down
20 changes: 9 additions & 11 deletions OpenParsec/ParsecSDKBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ class ParsecSDKBridge: ParsecService {
func disconnect() {

pollGeneration += 1
// release any held input (incl. mouse buttons) WHILE still connected, before teardown —
// otherwise a half-sent click leaves a button stuck on the host (right-button = context menu)
// must go before the disconnect, after it the release never reaches the host
sendReleaseMessage()
ParsecClientDisconnect(_parsec)
audio_clear(&_audio)
Expand Down Expand Up @@ -172,9 +171,7 @@ class ParsecSDKBridge: ParsecService {
self.hostHeight = Float(pcs.decoder.0.height)
self.hostWidth = Float(pcs.decoder.0.width)

// on the first live OK of a session, clear any input the host still holds from before
// (a stuck right-button = context menu). teardown releases get dropped before they send;
// this one goes over a known-live socket.
// the teardown release may not have made it out, this one goes over a socket we know is live
if ans == PARSEC_OK && !didReleaseOnConnect {
didReleaseOnConnect = true
sendReleaseMessage()
Expand Down Expand Up @@ -250,13 +247,14 @@ class ParsecSDKBridge: ParsecService {
do {
let decoder = JSONDecoder()
let config = try decoder.decode(ParsecUserDataVideoConfig.self, from: Data(bytesNoCopy: pointer!, count: strlen(pointer!), deallocator: .none))
let videoConfig = config.video[0]

let videoConfig = config.video.first
DispatchQueue.main.async {
DataManager.model.resolutionX = videoConfig.resolutionX
DataManager.model.resolutionY = videoConfig.resolutionY
DataManager.model.bitrate = videoConfig.encoderMaxBitrate
DataManager.model.constantFps = videoConfig.fullFPS
if let cfg = videoConfig {
DataManager.model.resolutionX = cfg.resolutionX
DataManager.model.resolutionY = cfg.resolutionY
DataManager.model.bitrate = cfg.encoderMaxBitrate
DataManager.model.constantFps = cfg.fullFPS
}
if !self.didSetResolution {
self.didSetResolution = true
DataManager.model.resolutionX = SettingsHandler.resolution.width
Expand Down
4 changes: 2 additions & 2 deletions OpenParsec/ParsecViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class ParsecViewController: UIViewController, UIScrollViewDelegate, ParsecTouchI

self.glkView = ParsecGLKViewController(viewController: self, updateImage: updateImage)

self.gamePadController = GamepadController(viewController: self)
self.touchController = TouchController(viewController: self)
self.gamePadController = GamepadController()
self.touchController = TouchController()
}

required init?(coder: NSCoder) {
Expand Down
5 changes: 1 addition & 4 deletions OpenParsec/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
ParsecBackgroundManager.shared.isPaused = false
}
}
// drop any input the host still thinks is held after ANY interruption — Control Center, the
// notification shade, a bottom-bar tap, or a brief sleep/unlock all resign+reactivate WITHOUT a
// full background (isPaused stays false), so the paused-only path above misses them and a
// stranded button (right = context menu) survives the resume. releasing nothing held is a no-op.
// drop any input the host still thinks is held, a stuck modifier survives the resume
if ParsecBackgroundManager.shared.hasActiveConnection {
CParsec.sendReleaseMessage()
}
Expand Down
5 changes: 0 additions & 5 deletions OpenParsec/TouchHandlingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import ParsecSDK
import UIKit

class TouchController {
let viewController: UIViewController

init(viewController: UIViewController) {
self.viewController = viewController
}

func onTouch(typeOfTap: Int, location: CGPoint, state: UIGestureRecognizer.State) {

Expand Down
Loading