diff --git a/README.md b/README.md index f1883e99..39326f57 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,6 @@ Light Reflective Mirror has a built in room/server list if you would like to use To request the server list you need a reference to the LightReflectiveMirrorTransport from your script and call 'RequestServerList()'. This will invoke a request to the server to update our server list. Once the response is recieved the field 'relayServerList' will be populated and you can get all the servers from there. -#### Free Relay -Note: If you would like to test without creating a server, feel free to use my test server with IP: 34.67.125.123. Which is in there by default :) - #### Server Setup Download the latest Server release from: [Releases](https://github.com/Derek-R-S/Light-Reflective-Mirror/releases) Make sure you have .NET Core 3.1 diff --git a/UnityTransport/LightReflectiveMirrorTransport.cs b/UnityTransport/LightReflectiveMirrorTransport.cs index ea33aed9..21e2c20f 100644 --- a/UnityTransport/LightReflectiveMirrorTransport.cs +++ b/UnityTransport/LightReflectiveMirrorTransport.cs @@ -34,6 +34,7 @@ public class LightReflectiveMirrorTransport : Transport private bool _isServer = false; private bool _isAuthenticated = false; private int _currentMemberId; + private bool _callbacksInitialized = false; private BiDictionary _connectedRelayClients = new BiDictionary(); public bool IsAuthenticated() => _isAuthenticated; @@ -44,14 +45,20 @@ private void Awake() throw new Exception("Haha real funny... Use a different transport."); } + SetupCallbacks(); + if (connectOnAwake) ConnectToRelay(); InvokeRepeating(nameof(SendHeartbeat), heartBeatInterval, heartBeatInterval); } - private void OnEnable() + private void SetupCallbacks() { + if (_callbacksInitialized) + return; + + _callbacksInitialized = true; clientToServerTransport.OnClientConnected = ConnectedToRelay; clientToServerTransport.OnClientDataReceived = DataReceived; clientToServerTransport.OnClientDisconnected = Disconnected;