-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRemoteCamScanning.swift
More file actions
77 lines (68 loc) · 2.49 KB
/
RemoteCamScanning.swift
File metadata and controls
77 lines (68 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// OtherStates.swift
// RemoteShutter
//
// Created by Dario Lencina on 10/10/20.
// Copyright © 2020 Security Union. All rights reserved.
//
import Foundation
import MultipeerConnectivity
extension RemoteCamSession {
func scanning(_ lobbyWrapper: Weak<DeviceScannerViewController>) -> Receive {
return { [unowned self] (msg: Actor.Message) in
guard let lobby = lobbyWrapper.value else {
return
}
switch msg {
case is OnEnter,
is UICmd.BecomeCamera,
is UICmd.BecomeMonitor,
is UICmd.StartScanning:
self.startScanning(lobby: lobby)
case is RemoteShutter.DisconnectPeer:
self.startScanning(lobby: lobby)
case let w as ConnectToDevice:
self.multipeerService.invitePeer(w.peer, timeout: 5)
^{
lobby.scannerViewModel.connectingToPeer()
}
case let w as OnConnectToDevice:
^{
lobby.scannerViewModel.connectedToPeer()
}
self.become(
name: .connected,
state: self.connected(lobbyWrapper: lobbyWrapper, peer: w.peer)
)
^{
lobby.goToRole()
}
case let m as UICmd.BrowserFoundPeer:
^{
lobby.scannerViewModel.addPeer(m.peer)
}
case let m as UICmd.BrowserLostPeer:
^{
lobby.scannerViewModel.removePeer(m.peer)
}
case _ as UICmd.BrowserFailed:
^{
lobby.scannerViewModel.scanningFailed()
let alert = UIAlertController(
title: NSLocalizedString("Scanning Error", comment: ""),
message: NSLocalizedString("Unable to scan for nearby devices. Please check your network settings and try again.", comment: ""),
preferredStyle: .alert
)
alert.addAction(UIAlertAction(
title: NSLocalizedString("OK", comment: ""),
style: .default,
handler: nil
))
lobby.present(alert, animated: true)
}
default:
self.receive(msg: msg)
}
}
}
}