Skip to content

Commit

Permalink
refactored. connect returns feature and tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
inkrement committed Dec 29, 2013
1 parent f51b33e commit d4ff876
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
16 changes: 10 additions & 6 deletions lib/Messenger/src/peers/jswebrtcpeer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class JsWebRtcPeer extends Peer{
/**
* connect to WebrtcPeer
*/
connect(JsWebRtcPeer o){
Future connect(JsWebRtcPeer o){

/// add ice candidates
rtcPeerConnection.onicecandidate = (event) {
Expand All @@ -71,7 +71,7 @@ class JsWebRtcPeer extends Peer{
}
};

/// add Datachannel
/// create datachannel
try {
dc = rtcPeerConnection.createDataChannel("sendDataChannel", js.map(dataChannelOptions));
Expand All @@ -94,13 +94,17 @@ class JsWebRtcPeer extends Peer{

//test datachannel
//dataChannel.send("test");
connection_completer.complete("wuhuu");
});
}, (e)=>print(e), {});


}, (e){
connection_completer.completeError(e, e.stackTrace);
}, {});

} catch (e) {
log.warning("could not create DataChannel: " + e.toString());
connection_completer.completeError(e, e.stackTrace);
}

return connection_completer.future;
}


Expand Down
6 changes: 5 additions & 1 deletion lib/Messenger/src/peers/peer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ abstract class Peer{
///todo: generalize and add to connections to support multiple states
StreamController<String> readyStateEvent;

///completer for connection
///TODO: use another generic type
var connection_completer = new Completer<String>();

/**
* constuctor
*/
Expand Down Expand Up @@ -69,7 +73,7 @@ abstract class Peer{
*
* @param Peer other
*/
connect(Peer other);
Future connect(Peer other);

/**
* send Message to other peer
Expand Down
17 changes: 9 additions & 8 deletions tests/jsrtcpeer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,27 @@ void main() {
});

/**
* Test Connection
* Test connection
*/
test('Webrtc connect',(){
JsWebRtcPeer alice = new JsWebRtcPeer("alice");
JsWebRtcPeer bob = new JsWebRtcPeer("bob");

alice.connect(bob);
expect(alice.connect(bob), completes);
});



/**
* test status opens
* test DataChannel's readyState opens
*/
test('webrtc datachannel open', (){
test('webrtc datachannel', (){
JsWebRtcPeer alice = new JsWebRtcPeer("alice");
JsWebRtcPeer bob = new JsWebRtcPeer("bob");

alice.readyStateEvent.stream.listen((String status){
if(status == "open")
expectAsync0((){});
});
_callback(String status) => expect(status, "open");

alice.readyStateEvent.stream.listen(expectAsync1(_callback));

alice.connect(bob);

Expand Down

0 comments on commit d4ff876

Please sign in to comment.