public override async Task OnConnected() { _log.Debug(m => m("connected {0}", Context.ConnectionId)); var ipAddress = GetRemoteClientIPAddress(Context.Request); var client = new ClientModel { Id = Context.ConnectionId, IP = new IPModel { Address = ipAddress, Location = await GetLocation(ipAddress) } }; await _addClientService.ExecuteAsync(client); if (client.IP.Location == LocationModel.Origin) { await _clientStatusService.ExecuteAsync(new ClientStatusModel { Id = Context.ConnectionId, Type = ClientStatusType.Error, Message = ErrorCodes.ERROR_LOCATION_SERVICE }); } await base.OnConnected(); }
public async Task ExecuteAsync(ClientModel client) { foreach (var other in _clientsCache.Values) { _clients.Client(client.Id).Add(Map(other)); } _clientsCache.AddOrUpdate(client.Id, client, (s, existing) => client); _clients.All.Add(Map(client)); }
static object Map(ClientModel client) { return new { id = client.Id, // name = client.IP.Address, location = new { latitude = client.IP.Location.Latitude, longitude = client.IP.Location.Longitude } }; }