diff --git a/lib/sockjs.dart b/lib/sockjs.dart index 58694a3..6298b20 100644 --- a/lib/sockjs.dart +++ b/lib/sockjs.dart @@ -3,6 +3,7 @@ library sockjs_client; import "dart:html"; import "dart:convert"; import "dart:async"; +import "dart:js"; import "src/events.dart" as event; import "src/utils.dart" as utils; @@ -34,15 +35,7 @@ class Protocol { Protocol({this.create, this.enabled: true, this.roundTrips: 1, this.needBody: false}); } -// Keep dart2js happy ... no lazy initialization. -Map _protocols; - -get PROTOCOLS { - if(_protocols == null) { - _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) - }; - } - return _protocols; -} \ No newline at end of file +Map 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) +}; \ No newline at end of file diff --git a/lib/src/transport/sender.dart b/lib/src/transport/sender.dart index cc331a2..2b4b771 100644 --- a/lib/src/transport/sender.dart +++ b/lib/src/transport/sender.dart @@ -113,14 +113,14 @@ class JsonPGenericSender { form.submit(); var readyStateChangeHandler = (e) { - if (iframe.readyState == 'complete') completed(null); + if (new JsObject.fromBrowserObject(iframe)["readyState"] == 'complete') completed(null); }; + var subscriptions; + completed = (e) { - if (iframe.on.error.isEmpty) return; - iframe.on.readyStateChange.remove(readyStateChangeHandler); - iframe.on.error.remove(completed); - iframe.on.load.remove(completed); + if (subscriptions == null) return; + subscriptions.forEach((s) => s.cancel()); // Opera mini doesn't like if we GC iframe // immediately, thus this timeout. @@ -131,9 +131,12 @@ class JsonPGenericSender { area.value = ''; callback(); }; - iframe.on.error.add(completed); - iframe.on.load.add(completed); - iframe.on.readyStateChange.add(readyStateChangeHandler); + + subscriptions = [ + iframe.onError.listen(completed), + iframe.onLoad.listen(completed), + iframe.on["readyStateChange"].listen(readyStateChangeHandler) + ]; //return completed; } @@ -142,7 +145,7 @@ class JsonPGenericSender { createAjaxSender(AjaxObjectFactory xhrFactory) => (url, payload, callback([status, reason])) { AbstractXHRObject xo = xhrFactory('POST', '$url/xhr_send', payload); - xo.on.finish.add((e) { + xo.onFinish.listen((e) { callback(e.status); }); return (abort_reason) {