[browser][wasm] Wasm websockets support (#37962)
authorKenneth Pouncey <kjpou@pt.lu>
Thu, 2 Jul 2020 21:57:45 +0000 (23:57 +0200)
committerGitHub <noreply@github.com>
Thu, 2 Jul 2020 21:57:45 +0000 (16:57 -0500)
commit9715a9c2b43a9111e91c7997fc2cb838e5250969
treef0d43350f1ed4374dd16a391113c81ba83acb810
parent8126962457be677cb8b9313d5d9f26849da77df2
[browser][wasm] Wasm websockets support (#37962)

* [browser][wasm] Initial addition of WebSockets support

* Clean up usings

* Create and use a WebSocketHandle.Browser.cs module

* Add conditional TARGETS_BROWSER so as not to throw Proxy PNSE during ClientWebSocket creation.

* Update WebSockets code

* Removing debug line

* Remove `ThrowIfReadOnly` method to address review comments

* Address review comments

- change accessor of _requestedSubProtocols to private
- condition more code in WebSocketHandle.Managed.cs to not access _requestedSubProtocols

* Address review comments

* Address review comments

* Change to be PlatformNotSupportedException

* Add ConnectAsync implementation to create a new instance of the BrowserWebSocket implementation.

* Address review comments

* Address subprotocols comments

* Remove internal custom class ActionQueue class in favor of using a Channel.

* Fix object leak.

- Lambdas are not being released automatically.

* Add doc for the constant that is being used.

- Address review comment

* Clean up SendAsync method.

- Validate the message type.
- Validate the array segment that is passed as the message.

* Add validation to ReceiveAsync for invalid buffer.

- remove unnecessary null checks from message buffering.

* Address review comments

* Address review comments about TCS

* Address camel case by using enum

* Address abort request

* Handle nullable

* Address review comment for removing cancellationtoken registration to the connect source.

* Use non-generic TaskCompletionSource

* Cleanup var usage

* Add string to .resx

* Inline dispose

* Fix WebSocket opening exception

* Remove the asynchronous completion from SendAsync.

* Fix object leak, exception on close and address review comments

* Handle race condition

* Address  TaskCompletionSource on connect review comments

* Update src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs

Co-authored-by: campersau <buchholz.bastian@googlemail.com>
* Update src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs

Co-authored-by: campersau <buchholz.bastian@googlemail.com>
* Fix Connect not completing task on error.

* Cleanup reference

* Remove redundant error check of memorystream buffer.

* cleanup

* Update src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj

Co-authored-by: Maxim Lipnin <mlipnin@gmail.com>
* Update src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj

Co-authored-by: Maxim Lipnin <mlipnin@gmail.com>
* Update src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj

Co-authored-by: Maxim Lipnin <mlipnin@gmail.com>
* Update src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj

Co-authored-by: Maxim Lipnin <mlipnin@gmail.com>
* Fix typo

* clean up buffer code

* Modify callbacks to use lambda function.

- These are now released properly after reference counting went in.

* Fix object leak of delegate and clean up deprecated code.

* extract lambda into method

* Update src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Update src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Update src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Review comments addressed

Co-authored-by: campersau <buchholz.bastian@googlemail.com>
Co-authored-by: Maxim Lipnin <mlipnin@gmail.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/libraries/System.Net.WebSockets.Client/src/Resources/Strings.resx
src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs [new file with mode: 0644]
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/ClientWebSocketOptions.cs [new file with mode: 0644]
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/ReceivePayload.cs [new file with mode: 0644]
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Browser.cs