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

Develop #74

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.5.0

Websocket format is changed.

## 0.4.0

Fix Websockets
Expand Down
9 changes: 3 additions & 6 deletions example/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,10 @@ void main() {
});
});

app.ws('/socket').listen((socket) {
socket.on('connected').listen((data) {
socket.send('ping', 'data-from-ping');
});
app.ws('/').listen((socket) {

socket.on('pong').listen((data) {
print('pong: $data');
socket.onMessage().listen((data) {
print('msg: $data');
socket.close(1000, 'requested');
});

Expand Down
14 changes: 6 additions & 8 deletions lib/socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ class Socket implements SocketBase {
this._ws = new WebSocket(url) {
_messages = _messageController.stream.asBroadcastStream();
_ws.onMessage.listen((e) {
var msg = new Message.fromPacket(e.data);
var msg = e.data;
_messageController.add(msg);
});
}

void send(String messageName, [ data ]) {
var message = new Message(messageName, data);
_ws.send(message.toPacket());
void send(String message) {
_ws.send(message);
}

Stream on(String messageName) {
return _messages.where((msg) => msg.name == messageName).map((msg) =>
msg.data);
Stream onMessage() {
return _messages;
}

Stream get onOpen => _ws.onOpen;
Expand All @@ -36,4 +34,4 @@ class Socket implements SocketBase {
void close([int status, String reason]) {
_ws.close(status, reason);
}
}
}
35 changes: 0 additions & 35 deletions lib/src/message.dart

This file was deleted.

13 changes: 5 additions & 8 deletions lib/src/socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ class Socket implements SocketBase {

_openController.add(_ws);
_ws.listen((data) {
var msg = new Message.fromPacket(data);
_messageController.add(msg);
_messageController.add(data);
},
onDone: () {
_closeController.add(_ws);
});
}

void send(String messageName, [ data ]) {
var message = new Message(messageName, data);
_ws.add(message.toPacket());
void send(String message) {
_ws.add(message);
}

Stream on(String messageName) {
return _messages.where((msg) => msg.name == messageName).map((msg) =>
msg.data);
Stream onMessage() {
return _messages;
}

Stream get onOpen => _openController.stream;
Expand Down
6 changes: 2 additions & 4 deletions lib/src/socket_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ library start_socket;

import 'dart:async';

export 'message.dart' show Message;

abstract class SocketBase {
void send(String msg_name, [ data ]);
void send(String msg);

Stream on(String message_name);
Stream onMessage();

void close([int status, String reason]);
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: start
author: Yehor Lvivski <[email protected]>
version: 0.4.0
author: Yehor Lvivski <[email protected]>, Benjamin Jung <[email protected]>
version: 0.5.0
homepage: http://github.com/lvivski/start
description: Sinatra inspired Web framework
environment:
Expand Down