Skip to content

Add github workflow and remove travis ci #36

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/dart_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Dart CI

on:
push:
branches:
- 'master'
- 'test_consume_*'
pull_request:
branches:
- '**'

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
sdk: [ stable ]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}
- name: Install dependencies
run: npm install
- name: Analyze project source
run: dartanalyzer .
- name: Run tests
run: ./tool/travis.sh test
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

18 changes: 9 additions & 9 deletions example/echo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "dart:html";
import 'package:logging/logging.dart';
import "package:sockjs_client/sockjs_client.dart" as SockJS;

DivElement div = querySelector('#first div');
InputElement inp = querySelector('#first input');
DivElement div = querySelector('#first div');
InputElement inp = querySelector('#first input');
FormElement form = querySelector('#first form');

_log(LogRecord l) {
Expand All @@ -24,19 +24,19 @@ main() {

LOG.info("Starting");
var sockjs_url = 'http://127.0.0.1:8081/echo';
var sockjs = new SockJS.Client(sockjs_url, protocolsWhitelist:['websocket', 'xhr-streaming'], debug: true);
var sockjs = new SockJS.Client(sockjs_url,
protocolsWhitelist: ['websocket', 'xhr-streaming'], debug: true);
querySelector('#first input').focus();

sockjs.onOpen.listen( (_) => LOG.info('[*] open ${sockjs.protocol}') );
sockjs.onMessage.listen( (e) => LOG.info('[.] message ${e.data}') );
sockjs.onClose.listen( (_) => LOG.info('[*] close') );
sockjs.onOpen.listen((_) => LOG.info('[*] open ${sockjs.protocol}'));
sockjs.onMessage.listen((e) => LOG.info('[.] message ${e.data}'));
sockjs.onClose.listen((_) => LOG.info('[*] close'));

inp.onKeyUp.listen( (KeyboardEvent e) {
inp.onKeyUp.listen((KeyboardEvent e) {
if (e.keyCode == 13) {
LOG.info('[ ] sending ${inp.value}');
sockjs.send(inp.value);
inp.value = '';
}
});

}
}
21 changes: 16 additions & 5 deletions lib/sockjs_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,35 @@ part "src/transport/receiver-xhr.dart";
part "src/transport/websocket.dart";
part "src/transport/xhr.dart";

const version = "<!-- version -->";
const version = "<!-- version -->";

const CONNECTING = 0;
const OPEN = 1;
const CLOSING = 2;
const CLOSED = 3;

typedef TransformFactory(Client client, String transUrl, {String baseUrl, bool noCredentials});
typedef TransformFactory(Client client, String transUrl,
{String baseUrl, bool noCredentials});

class Protocol {
TransformFactory create;
bool enabled;
num roundTrips;
bool needBody;
Protocol({this.create, this.enabled: true, this.roundTrips: 1, this.needBody: false});
Protocol(
{this.create,
this.enabled: true,
this.roundTrips: 1,
this.needBody: false});
}

Map<String, Protocol> PROTOCOLS = {
"websocket": new Protocol(create:WebSocketTransport.create, enabled: WebSocketTransport.enabled, roundTrips: WebSocketTransport.roundTrips),
"xhr-streaming": new Protocol(create:XhrStreamingTransport.create, enabled: XhrStreamingTransport.enabled, roundTrips: XhrStreamingTransport.roundTrips)
"websocket": new Protocol(
create: WebSocketTransport.create,
enabled: WebSocketTransport.enabled,
roundTrips: WebSocketTransport.roundTrips),
"xhr-streaming": new Protocol(
create: XhrStreamingTransport.create,
enabled: XhrStreamingTransport.enabled,
roundTrips: XhrStreamingTransport.roundTrips)
};
96 changes: 53 additions & 43 deletions lib/src/ajax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@ class StatusEvent extends event.Event {
StatusEvent(String type, [this.status = 0, this.text = ""]) : super(type);
}

typedef AbstractXHRObject AjaxObjectFactory(String method, String baseUrl, {bool noCredentials, dynamic payload});
typedef AbstractXHRObject AjaxObjectFactory(String method, String baseUrl,
{bool noCredentials, dynamic payload});

class AbstractXHRObject extends Object with event.Emitter {

html.HttpRequest xhr;
StreamSubscription changeSubscription;

Stream<StatusEvent> get onChunk => getEventStream<StatusEvent>('chunk');
Stream<StatusEvent> get onFinish => getEventStream<StatusEvent>('finish');
Stream<StatusEvent> get onTimeout => getEventStream<StatusEvent>('timeout');

void _start(String method, String url, dynamic payload, {bool noCredentials: false, Map<String, String> headers}) {

void _start(String method, String url, dynamic payload,
{bool noCredentials: false, Map<String, String> headers}) {
try {
xhr = new html.HttpRequest();
} catch(x) {};

if ( xhr == null ) {
try {
// TODO(nelsonsilva) - xhr = new window['ActiveXObject']('Microsoft.XMLHTTP');
} catch(x) {};
xhr = new html.HttpRequest();
} catch (x) {}
;

if (xhr == null) {
try {
// TODO(nelsonsilva) - xhr = new window['ActiveXObject']('Microsoft.XMLHTTP');
} catch (x) {}
;
}
// TODO(nelsonsilva)
//if ( window['ActiveXObject'] != null || window['XDomainRequest'] != null) {
// IE8 caches even POSTs
// IE8 caches even POSTs
// url += ((url.indexOf('?') === -1) ? '?' : '&') + 't='+(+new Date);
//}

Expand All @@ -39,21 +41,22 @@ class AbstractXHRObject extends Object with event.Emitter {
//that.unload_ref = utils.unload_add(function(){that._cleanup(true);});

try {
xhr.open(method, url);
} catch(e) {
// IE raises an exception on wrong port.
dispatch(new StatusEvent("finish"));
_cleanup();
return;
};
xhr.open(method, url);
} catch (e) {
// IE raises an exception on wrong port.
dispatch(new StatusEvent("finish"));
_cleanup();
return;
}
;

if (!noCredentials) {
// Mozilla docs says https://developer.mozilla.org/en/XMLHttpRequest :
// "This never affects same-site requests."
xhr.withCredentials = true;
// Mozilla docs says https://developer.mozilla.org/en/XMLHttpRequest :
// "This never affects same-site requests."
xhr.withCredentials = true;
}
if (headers != null) {
headers.forEach((k, v) => xhr.setRequestHeader(k, v));
headers.forEach((k, v) => xhr.setRequestHeader(k, v));
}

changeSubscription = xhr.onReadyStateChange.listen(_readyStateHandler);
Expand All @@ -71,7 +74,8 @@ class AbstractXHRObject extends Object with event.Emitter {
try {
status = xhr.status;
text = xhr.responseText;
} catch (x) {};
} catch (x) {}
;
// IE does return readystate == 3 for 404 answers.
if (text != null && !text.isEmpty) {
dispatch(new StatusEvent("chunk", status, text));
Expand All @@ -85,20 +89,20 @@ class AbstractXHRObject extends Object with event.Emitter {
}

void _cleanup([bool abort = false]) {

if (xhr == null) return;
// utils.unload_del(that.unload_ref);

// IE needs this field to be a function
changeSubscription.cancel();

if (abort) {
try {
xhr.abort();
} catch(x) {};
try {
xhr.abort();
} catch (x) {}
;
}
//that.unload_ref = that.xhr = null;
}
}

void close() {
// TODO(nelsonsilva) - nuke();
Expand All @@ -107,35 +111,41 @@ class AbstractXHRObject extends Object with event.Emitter {
}

class XHRCorsObject extends AbstractXHRObject {
XHRCorsObject(String method, String url, {Map<String, String> headers, bool noCredentials, dynamic payload}) {
Timer.run(() =>_start(method, url, payload, noCredentials: noCredentials != null ? noCredentials : false));
}
XHRCorsObject(String method, String url,
{Map<String, String> headers, bool noCredentials, dynamic payload}) {
Timer.run(() => _start(method, url, payload,
noCredentials: noCredentials != null ? noCredentials : false));
}
}



class XHRLocalObject extends AbstractXHRObject {
XHRLocalObject(String method, String url, {Map<String, String> headers, bool noCredentials, dynamic payload}) {
Timer.run(() =>_start(method, url, payload, noCredentials: noCredentials != null ? noCredentials : true));
}
XHRLocalObject(String method, String url,
{Map<String, String> headers, bool noCredentials, dynamic payload}) {
Timer.run(() => _start(method, url, payload,
noCredentials: noCredentials != null ? noCredentials : true));
}
}

AbstractXHRObject XHRLocalObjectFactory(String method, String baseUrl, {bool noCredentials, dynamic payload}) {
return new XHRLocalObject(method, baseUrl, noCredentials: noCredentials, payload: payload);
AbstractXHRObject XHRLocalObjectFactory(String method, String baseUrl,
{bool noCredentials, dynamic payload}) {
return new XHRLocalObject(method, baseUrl,
noCredentials: noCredentials, payload: payload);
}

AbstractXHRObject XHRCorsObjectFactory(String method, String baseUrl, {bool noCredentials, dynamic payload}) {
return new XHRCorsObject(method, baseUrl, noCredentials: noCredentials, payload: payload);
AbstractXHRObject XHRCorsObjectFactory(String method, String baseUrl,
{bool noCredentials, dynamic payload}) {
return new XHRCorsObject(method, baseUrl,
noCredentials: noCredentials, payload: payload);
}

// 1. Is natively via XHR
// 2. Is natively via XDR
// 3. Nope, but postMessage is there so it should work via the Iframe.
// 4. Nope, sorry.
int isXHRCorsCapable() {
return 1;
return 1;

/*
/*
if (window["XMLHttpRequest"] != null && window["'withCredentials' in new XMLHttpRequest()) {
return 1;
}
Expand Down
Loading