Skip to content

Commit

Permalink
Trying to get iframe to work by using dart:js
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson Silva committed Dec 11, 2013
1 parent a4e616e commit 782aa24
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
17 changes: 5 additions & 12 deletions lib/sockjs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Protocol> _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;
}
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)
};
21 changes: 12 additions & 9 deletions lib/src/transport/sender.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down

0 comments on commit 782aa24

Please sign in to comment.