/// <summary> /// Creates a Stormancer client instance. /// </summary> /// <param name="configuration">A configuration instance containing options for the client.</param> public Client(ClientConfiguration configuration) { this._pingInterval = configuration.PingInterval; this._scheduler = configuration.Scheduler; DependencyResolver = new StormancerResolver(); DependencyResolver.Register <ILogger>(() => configuration.Logger); DependencyResolver.Register(() => new ApiClient(configuration, DependencyResolver)); DependencyResolver.Register <ITokenHandler>(() => new TokenHandler()); DependencyResolver.RegisterComponent <IConnectionHandler>(new IConnectionHandler()); DependencyResolver.RegisterComponent <IClock>(new IClock(this)); #if UNITY_EDITOR IConnectionHandler temp = DependencyResolver.Resolve <IConnectionHandler>(); temp.PeerConnected += (PeerConnectedContext pcc) => { ConnectionWrapper connection = new ConnectionWrapper(pcc.Connection, configuration.Plugins.OfType <EditorPlugin.StormancerEditorPlugin>().First()); pcc.Connection = connection; }; #endif this.DependencyResolver.Register <ITransport>(configuration.TransportFactory); this._accountId = configuration.Account; this._applicationName = configuration.Application; //TODO handle scheduler in the transport this._dispatcher = configuration.Dispatcher; _requestProcessor = new Stormancer.Networking.Processors.RequestProcessor(Logger, Enumerable.Empty <IRequestModule>()); _scenesDispatcher = new Processors.SceneDispatcher(); this._dispatcher.AddProcessor(_requestProcessor); this._dispatcher.AddProcessor(_scenesDispatcher); this._metadata = configuration._metadata; foreach (var serializer in configuration.Serializers) { this._serializers.Add(serializer.Name, serializer); } this._maxPeers = configuration.MaxPeers; foreach (var plugin in configuration.Plugins) { plugin.Build(_pluginCtx); } var ev = _pluginCtx.ClientCreated; if (ev != null) { ev(this); } _transport = DependencyResolver.Resolve <ITransport>(); this._metadata.Add("serializers", string.Join(",", this._serializers.Keys.ToArray())); this._metadata.Add("transport", _transport.Name); this._metadata.Add("version", "1.1.0"); this._metadata.Add("platform", "Unity"); this._metadata.Add("protocol", "2"); Initialize(); }
/// <summary> /// Creates a Stormancer client instance. /// </summary> /// <param name="configuration">A configuration instance containing options for the client.</param> public Client(ClientConfiguration configuration) { foreach (var plugin in configuration.Plugins) { plugin.Build(_pluginCtx); } this._pingInterval = configuration.PingInterval; this.DependencyResolver = new DefaultDependencyResolver(b => { b.Register(this); _pluginCtx.BuildingClientResolver?.Invoke(b); }); this._scheduler = configuration.Scheduler; this._logger = configuration.Logger; this._accountId = configuration.Account; this._applicationName = configuration.Application; _apiClient = new ApiClient(configuration, _tokenHandler); this._transport = configuration.TransportFactory(new Dictionary <string, object> { { "ILogger", this._logger }, { "IScheduler", this._scheduler } }); this._dispatcher = configuration.Dispatcher; _requestProcessor = new Stormancer.Networking.Processors.RequestProcessor(_logger, Enumerable.Empty <IRequestModule>(), _systemSerializer); _scenesDispatcher = new Processors.SceneDispatcher(new[] { new RouteScenePacketHandler() }); this._dispatcher.AddProcessor(_requestProcessor); this._dispatcher.AddProcessor(_scenesDispatcher); this._metadata = configuration._metadata; foreach (var serializer in configuration.Serializers) { this._serializers.Add(serializer.Name, serializer); } this._metadata.Add("serializers", string.Join(",", this._serializers.Keys)); this._metadata.Add("transport", _transport.Name); this._metadata.Add("version", "1.0.0a"); this._metadata.Add("platform", "NET45"); this._metadata.Add("protocol", "2"); this._maxPeers = configuration.MaxPeers; if (_pluginCtx.ClientCreated != null) { _pluginCtx.ClientCreated(this); } Initialize(); }