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

Morteza/add_dart_demo #151

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions _includes/demos/dart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'dart:async' show Future;
import 'dart:convert' show json;
import 'dart:io' show WebSocket;

Future<void> main() async {
WebSocket ws;
try {
ws = await WebSocket.connect(
'wss://ws.binaryws.com/websockets/v3?app_id=1089');

if (ws?.readyState == WebSocket.open) {
ws.listen(
(resposne) {
var data = Map<String, dynamic>.from(json.decode(resposne));
print('Ticks update:\r\n $data');
},
onDone: () => print('Done!'),
onError: (e) => throw new Exception(e),
);
ws.add(json.encode({'ticks': 'R_100'}));
}
} catch(e) {
ws?.close();
print('Error: $e');
}
}
2 changes: 2 additions & 0 deletions _pages/demos.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h1 class="post-title">{{ page.title }}</h1>
<option value="clojure">Clojure</option>
<option value="coffeescript">CoffeeScript</option>
<option value="csharp">C#</option>
<option value="dart">Dart</option>
<option value="elixir">Elixir</option>
<option value="go">Go</option>
<option value="perl">Perl</option>
Expand All @@ -31,6 +32,7 @@ <h1 class="post-title">{{ page.title }}</h1>
<pre data-language="clojure">{% include demos/clojure.clj %}</pre>
<pre data-language="coffeescript">{% include demos/coffeescript.coffee %}</pre>
<pre data-language="csharp">{% include demos/csharp.cs %}</pre>
<pre data-language="dart">{% include demos/dart.dart %}</pre>
<pre data-language="elixir">{% include demos/elixir.exs %}</pre>
<pre data-language="go">{% include demos/go.go %}</pre>
<pre data-language="java">{% include demos/java.java %}</pre>
Expand Down