public WebSocketMessageSource(WebSocketTransportDuplexSessionChannel webSocketTransportDuplexSessionChannel, WebSocket webSocket,
                               bool useStreaming, IDefaultCommunicationTimeouts defaultTimeouts)
 {
     Initialize(webSocketTransportDuplexSessionChannel, webSocket, useStreaming, defaultTimeouts);
     // TODO: Switch IMessageSource to use TimeSpan instead of CancellationToken. See Issue #283
     _asyncReceiveTimeout = TimeSpan.Zero;
     StartNextReceiveAsync();
 }
 private void Initialize(WebSocketTransportDuplexSessionChannel webSocketTransportDuplexSessionChannel, WebSocket webSocket, bool useStreaming, IDefaultCommunicationTimeouts defaultTimeouts)
 {
     _webSocket     = webSocket;
     _encoder       = webSocketTransportDuplexSessionChannel.MessageEncoder;
     _bufferManager = webSocketTransportDuplexSessionChannel.BufferManager;
     _localAddress  = webSocketTransportDuplexSessionChannel.LocalAddress;
     _maxBufferSize = webSocketTransportDuplexSessionChannel.MaxBufferSize;
     _handshakeSecurityMessageProperty = webSocketTransportDuplexSessionChannel.RemoteSecurity;
     _maxReceivedMessageSize           = webSocketTransportDuplexSessionChannel.TransportFactorySettings.MaxReceivedMessageSize;
     _receiveBufferSize = Math.Min(WebSocketHelper.GetReceiveBufferSize(_maxReceivedMessageSize), _maxBufferSize);
     _useStreaming      = useStreaming;
     _defaultTimeouts   = defaultTimeouts;
     _closeDetails      = webSocketTransportDuplexSessionChannel._webSocketCloseDetails;
     _asyncReceiveState = AsyncReceiveState.Finished;
 }
            public WebSocketMessageSource(WebSocketTransportDuplexSessionChannel webSocketTransportDuplexSessionChannel, WebSocketContext context,
                                          bool isStreamed, RemoteEndpointMessageProperty remoteEndpointMessageProperty, IDefaultCommunicationTimeouts defaultTimeouts, HttpContext requestContext)
            {
                Initialize(webSocketTransportDuplexSessionChannel, context.WebSocket, isStreamed, defaultTimeouts);

                IPrincipal user = requestContext?.User;

                _context = new ServiceWebSocketContext(context, user);
                RemoteEndpointMessageProperty = remoteEndpointMessageProperty;
                // Copy any string keyed items from requestContext to properties. This is an attempt to mimic HttpRequestMessage.Properties
                var properties = new Dictionary <string, object>();

                foreach (KeyValuePair <object, object> kv in requestContext.Items)
                {
                    if (kv.Key is string key)
                    {
                        properties[key] = kv.Value;
                    }
                }

                _properties = requestContext == null ? null : new ReadOnlyDictionary <string, object>(properties);

                StartNextReceiveAsync();
            }