Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify dart:html/dart:io WebSocket interfaces. #13513

Closed
DartBot opened this issue Sep 23, 2013 · 10 comments
Closed

Unify dart:html/dart:io WebSocket interfaces. #13513

DartBot opened this issue Sep 23, 2013 · 10 comments
Labels
area-library closed-obsolete Closed as the reported issue is no longer relevant P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Sep 23, 2013

This issue was originally filed by george.moschoviti...@gmail.com


The WbeSocket interface in dart:html is different than the one defined in dart:io.

So when you have a class that could perfectly well work on both the console and the browser (e.g. a client for a websocket protocol) you have to create and maintain two slightly different versions.

@anders-sandholm
Copy link
Contributor

Added Area-IO, Triaged labels.

@sgjesse
Copy link
Contributor

sgjesse commented Sep 25, 2013

In the short term the WebSocket interface in dart:io and dart:html will focus on providing access to all features that each underlying platform supports. Based on these two APIs a common interface can be implemented a a separate package.


Added this to the Later milestone.
Removed Type-Defect, Priority-Unassigned, Area-IO labels.
Added Type-Enhancement, Priority-Low, Area-Library labels.

@DartBot
Copy link
Author

DartBot commented Nov 3, 2013

This comment was originally written by igor.ko...@mailvision.com


Can it be used as such interface ?

import 'dart:async';

abstract class AbstractWebSocket {
  static const int CONNECTING = 0;
  static const int OPEN = 1;
  static const int CLOSING = 2;
  static const int CLOSED = 3;
  
  int readyState;
  int closeCode;
  String closeState;
  
  void close([int code, String reason]);
  void send(dynamic data); // String or List<int>
  
  Stream get onOpen;
  Stream get onMessage;
  Stream get onClose;
  Stream get onError;
}

@DartBot
Copy link
Author

DartBot commented Nov 3, 2013

This comment was originally written by igor.ko...@mailvision.com


Problem here is stream events !

For example html web socket version defined in dartium.dart:
@DomName('WebSocket.onclose')
  @­DocsEditable()
  Stream<CloseEvent> get onClose => closeEvent.forTarget(this);

  @­DomName('WebSocket.onerror')
  @­DocsEditable()
  Stream<Event> get onError => errorEvent.forTarget(this);

  @­DomName('WebSocket.onmessage')
  @­DocsEditable()
  Stream<MessageEvent> get onMessage => messageEvent.forTarget(this);

Event, CloseEvent, MessageEvent defined in the same file, so cannot be used in
server code (dart:io)

@DartBot
Copy link
Author

DartBot commented Nov 11, 2013

This comment was originally written by igor.ko...@mailvision.com


I really needed such common interface, so implemented it for dart:io and dart:html

abstract class AbstractWebSocket {
  static const int CONNECTING = 0;
  static const int OPEN = 1;
  static const int CLOSING = 2;
  static const int CLOSED = 3;

  int get readyState;
  int get closeCode;
  String get closeState;

  void close([int code, String reason]);
  void send(dynamic data); // String or List<int>

  Future<Stream<dynamic>> connect(String url);
  Stream<dynamic> get stream; // data is String or List<int>
}

The test:
 - connect to echo web socket server
 - send string message, send binary message,
 - receive messages
 - disconnect

passed for

  • dart application mode
  • browser mode as dart, and as js (in dartium).

Test projects in attachment.
(I only learn Future/Stream API, so sure that it can be improved)


Attachments:
web_socket_client.zip (135.93 KB)
web_socket_server.zip (1.35 KB)

@DartBot
Copy link
Author

DartBot commented Dec 5, 2013

This comment was originally written by igor.ko...@mailvision.com


  1. to AbstractWebSocket interface
       added optional sub-protocol (header Sec-Websocket-Protocol in http handshake)

  connect(String url, [dymamic subProtocols])

where subProtocols is String or List<String>

  1. compatibility question:
    I see that "io" websocket send in handshake header: Accept-Encoding: gzip
    Can I remove the header (and use plain text) ?

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@DartBot
Copy link
Author

DartBot commented Feb 26, 2015

This comment was originally written by @stevenroose


A unified HTTP interface would be very beneficial as well.

I'd propose a (fictional) dart:http.HttpClient interface that both dart:io.HttpClient and package:browser_client.BrowserClient can implement.

It's very cumbersome that libraries that try to implement a protocol that is specified around HTTP has to worry about whether it is run in VM or a browser.

@DartBot DartBot added Type-Enhancement P3 A lower priority bug or feature request area-library labels Feb 26, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Feb 29, 2016
@matanlurey matanlurey added the closed-obsolete Closed as the reported issue is no longer relevant label Jun 19, 2018
@mtcliatt
Copy link
Contributor

mtcliatt commented Dec 1, 2019

Why was this closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-library closed-obsolete Closed as the reported issue is no longer relevant P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

7 participants