// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
namespace Microsoft.AspNetCore.SignalR
{
///
/// A base class for a SignalR hub.
///
public abstract class Hub : IDisposable
{
private bool _disposed;
private IHubCallerClients _clients;
private HubCallerContext _context;
private IGroupManager _groups;
///
/// Gets or sets an object that can be used to invoke methods on the clients connected to this hub.
///
public IHubCallerClients Clients
{
get
{
CheckDisposed();
return _clients;
}
set
{
CheckDisposed();
_clients = value;
}
}
///
/// Gets or sets the hub caller context.
///
public HubCallerContext Context
{
get
{
CheckDisposed();
return _context;
}
set
{
CheckDisposed();
_context = value;
}
}
///
/// Gets or sets the group manager.
///
public IGroupManager Groups
{
get
{
CheckDisposed();
return _groups;
}
set
{
CheckDisposed();
_groups = value;
}
}
///
/// Called when a new connection is established with the hub.
///
/// A that represents the asynchronous connect.
public virtual Task OnConnectedAsync()
{
return Task.CompletedTask;
}
///
/// Called when a connection with the hub is terminated.
///
/// A that represents the asynchronous disconnect.
public virtual Task OnDisconnectedAsync(Exception exception)
{
return Task.CompletedTask;
}
///
/// Releases all resources currently used by this instance.
///
/// true if this method is being invoked by the method,
/// otherwise false.
protected virtual void Dispose(bool disposing)
{
}
///
public void Dispose()
{
if (_disposed)
{
return;
}
Dispose(true);
_disposed = true;
}
private void CheckDisposed()
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
}
}
}
}