# Off-Cloud Anchor Sharing Framework for Multi-User and Multi-Platform Mixed Reality Applications
## 3 Design and Implementation of the System
### System Design
#### 3.3.1 Automatic User Connection Module  
In order to improve UX, a functionality was developed to enable the automatic connection of multiple devices, in such a way that each device searches for any other device in the local network to connect to. In this way, the participating users simply need to start the application by selecting the \"host\" mode (if there are no previously connected devices in that network) or \"client\" mode if there is already an active \"host\" available.  
For this purpose, the NetworkDiscoveryUI class was created, from which the interactions of the interface buttons for new server or client connections are managed. This new script must be included in each scene inside the GameObject that is acting as the NetworkManager. This component requires the GameObject to also have Mirror's NetworkDiscovery associated with it. In addition, if desired, TextMeshPro can be added to show on screen to the person who is connecting as a client how many and which IPs the servers of their local network have.  
In addition, it was also necessary to modify the OverCookedNetworkManager class: first, to add the management of the interaction with the new buttons and, secondly, whenever a person connects as a server, a message is sent, indicating that there is a new server available on the network by executing the \"networkDiscovery.AdvertiseServer()\" method. In contrast, if the person connects as a client, the device is able to find the server by using the \"networkDiscovery.StartDiscovery()\" method provided by Mirror.  
As it was previously indicated, when the users open the application, they will be able to connect as a client or host (acting as server and client simultaneously). For this purpose, when the application is started, a panel is displayed in which the user can select the connection mode: host or client. Users can also perform a previous search to find out whether there are servers in the local network (find servers) or directly enter an IP in case they want to connect to a remote server (server IP).  
Below is a detailed explanation of the process of creating a new connection in case the user starts as a client, which is illustrated in Figure 3:  
Figure 2: System design: simplified class diagram showing Mirror-related classes.  
A person (Player 2) starts the application and selects the menu button to connect as a client. This is the only action performed by Player 2, the rest of the process is executed automatically by the system.
2. The system executes the method \"networkDiscovery.StartDiscovery()\" to search if there is any server available in the network. The active server (in this case, Player 1 acting as host) responds by sending its IP.
3. The system configures the received IP as a connection point and connects to that server.
4. The system calls the \"networkManager.StartClient()\" method, and configures and synchronizes the scene with the server.
5. Then, the system invokes the \"OnStartClient()\" and \"Start()\" methods, where all the internal variables for the correct operation of Player 2 and the system are configured.
6. From this moment, [PERSON] will be able to play freely and the system will synchronize its movements and actions with the server, which will be in charge of broadcasting these actions to the rest of the clients of the network, in case there are any.  
Figure 3: Sequence diagram representing system behavior when a new user starts the application.