private void Start() { _cameraHub = gameObject.FindOrCreate <CameraHub>(); if (_entryRoom != null) { Current = _entryRoom; } }
private async Task _startClientCommunication(TcpClient client) { NetworkStream clientStream = client.GetStream(); Trace.WriteLine("Waiting to hear client type..."); ClientConnection newConnection; try { //await _send(clientStream, TELL_CLIENT_TYPE, TELL_CLIENT_TYPE.Length); var receivedMessage = await _receiveMessage(clientStream); var clientType = _determineClientType(receivedMessage); switch (clientType) { case ClientType.CAPTURE: { Trace.WriteLine("Adding capture client..."); CameraHub hub = _getHubDetails(receivedMessage); hub.Connection = client; cameraHubs[hub.Name] = hub; await Task.Factory.StartNew(() => _startReceiveCommunication(hub)); await Task.Factory.StartNew(() => _startSendCommunication(hub)); break; } case ClientType.VIEW: { Trace.WriteLine("Adding viewing client..."); viewingClients.Add(client); var viewClient = new ViewClient() { Connection = client, ClientType = clientType }; await Task.Factory.StartNew(() => _startReceiveCommunication(viewClient)); await Task.Factory.StartNew(() => _startSendCommunication(viewClient)); break; } default: { Trace.WriteLine("Error switching on enum type..."); client.Close(); return; } } await _send(clientStream, ACKNOWLEDGE); } catch (Exception e) { Trace.WriteLine($"Exception determining client type...\n\n{e}"); client.Close(); } }