Skip to content

Commit

Permalink
changed readystate to connectionstate
Browse files Browse the repository at this point in the history
  • Loading branch information
inkrement committed Jan 1, 2014
1 parent 6329a77 commit 4aebd34
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
8 changes: 4 additions & 4 deletions lib/Messenger/src/connections/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ part of messenger.connections;

abstract class Connection{
final SignalingChannel _sc;
ReadyState readyState;
final StreamController<ReadyState> readyStateEvent;
ConnectionState readyState;
final StreamController<ConnectionState> readyStateEvent;
///new message event stream
final StreamController<NewMessageEvent> newMessageController;
final Logger _log;
Expand All @@ -21,7 +21,7 @@ abstract class Connection{


Connection(SignalingChannel sc, Logger log):
readyStateEvent=new StreamController<ReadyState>.broadcast(),
readyStateEvent=new StreamController<ConnectionState>.broadcast(),
_listen_completer = new Completer<int>(),
_connection_completer = new Completer<int>(),
newMessageController = new StreamController<NewMessageEvent>(),
Expand All @@ -35,7 +35,7 @@ abstract class Connection{
*
* @ TODO: make private
*/
changeReadyState(ReadyState readyState){
changeReadyState(ConnectionState readyState){
//break if nothing will change
if (this.readyState == readyState) return;

Expand Down
20 changes: 11 additions & 9 deletions lib/Messenger/src/connections/jsdatachannelconnection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class JsDataChannelConnection extends Connection{
};

_dc.onopen = (_){
changeReadyState(new ReadyState.fromDataChannel(_dc.readyState));
changeReadyState(new ConnectionState.fromRTCDataChannelState(_dc.readyState));
_listen_completer.complete(sc.id);
};

_dc.onclose = (_)=>changeReadyState(new ReadyState.fromDataChannel(_dc.readyState));
_dc.onclose = (_)=>changeReadyState(new ConnectionState.fromRTCDataChannelState(_dc.readyState));
_dc.onerror = (x)=>_log.shout("rtc error callback: " + x.toString());

//set state to current DC_State
changeReadyState(new ReadyState.fromDataChannel(_dc.readyState));
changeReadyState(new ConnectionState.fromRTCDataChannelState(_dc.readyState));
};
}

Expand Down Expand Up @@ -76,7 +76,7 @@ class JsDataChannelConnection extends Connection{
//listen_completer.complete(sc.id);

_sc.send(new Message(this.hashCode.toString(), MessageType.AKN_PEER_ID));
changeReadyState(ReadyState.CONNECTED);
changeReadyState(ConnectionState.CONNECTED);

break;
case MessageType.AKN_PEER_ID:
Expand All @@ -103,8 +103,8 @@ class JsDataChannelConnection extends Connection{
_rtcPeerConnection.setRemoteDescription(sdp);

//send if open
readyStateEvent.stream.listen((ReadyState rs){
if (rs == ReadyState.DC_OPEN){
readyStateEvent.stream.listen((ConnectionState rs){
if (rs == ConnectionState.CONNECTED){
_log.info("send PEER_ID");
_sc.send(new Message(this.hashCode.toString(), MessageType.PEER_ID));
}
Expand Down Expand Up @@ -181,12 +181,14 @@ class JsDataChannelConnection extends Connection{
_log.fine('created new data channel');

_dc.onopen = (_){
changeReadyState(new ReadyState.fromDataChannel(_dc.readyState));
changeReadyState(new ConnectionState.fromRTCDataChannelState(_dc.readyState));
_connection_completer.complete(_sc.id);
};
_dc.onclose = (_){
_log.info("datachannel closed!");

changeReadyState(ReadyState.CONNECTED);
changeReadyState(new ConnectionState.fromRTCDataChannelState(_dc.readyState));
};
_dc.onclose = (_)=>changeReadyState(_dc.readyState);

_dc.onmessage = (MessageEvent event){
_log.finest("Message received from DataChannel");
Expand Down
2 changes: 1 addition & 1 deletion lib/Messenger/src/peer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Peer{
* @returns number of connections
*/

int countConnections([ReadyState filter=null]){
int countConnections([ConnectionState filter=null]){
int i=0;

_connections.forEach((k,v){
Expand Down

0 comments on commit 4aebd34

Please sign in to comment.