diff --git a/lib/WebRTCMessenger/src/connections/webrtcdatachannel.dart b/lib/WebRTCMessenger/src/connections/webrtcdatachannel.dart index 56d32c2..1a4e39a 100644 --- a/lib/WebRTCMessenger/src/connections/webrtcdatachannel.dart +++ b/lib/WebRTCMessenger/src/connections/webrtcdatachannel.dart @@ -53,7 +53,7 @@ class WebRtcDataChannel extends Connection{ _dc.onMessage.listen((MessageEvent event){ _log.finest("Message received from DataChannel"); - _newMessageController.add(new NewMessageEvent(new Message.fromString(event.data))); + _newMessageController.add(new NewMessageEvent(Message.fromString(event.data))); }); //onOpen @@ -250,7 +250,7 @@ class WebRtcDataChannel extends Connection{ _dc.onMessage.listen((MessageEvent event){ _log.finest("Message received from DataChannel"); - _newMessageController.add(new NewMessageEvent(new Message.fromString(event.data))); + _newMessageController.add(new NewMessageEvent(Message.fromString(event.data))); }); //TODO: onERROR diff --git a/lib/WebRTCMessenger/src/message.dart b/lib/WebRTCMessenger/src/message.dart index 986bd13..8e43824 100644 --- a/lib/WebRTCMessenger/src/message.dart +++ b/lib/WebRTCMessenger/src/message.dart @@ -32,7 +32,7 @@ class Message{ return JSON.encode(result); } - factory Message.fromString(String data){ + static Message fromString(String data){ if (data == null) return null; Map json = JSON.decode(data); diff --git a/lib/WebRTCMessenger/src/peer.dart b/lib/WebRTCMessenger/src/peer.dart index 405eab3..c111850 100644 --- a/lib/WebRTCMessenger/src/peer.dart +++ b/lib/WebRTCMessenger/src/peer.dart @@ -50,7 +50,7 @@ class Peer{ * constuctor * */ - Peer([String name="", Level loglevel=Level.FINE]){ + Peer([String name="", Level loglevel=Level.WARNING]){ //set name of this peer instance this.name = (name.length < 1)?"peer" + (++num).toString():name; diff --git a/lib/WebRTCMessenger/src/signaling.dart b/lib/WebRTCMessenger/src/signaling.dart index b1d237b..58a621e 100644 --- a/lib/WebRTCMessenger/src/signaling.dart +++ b/lib/WebRTCMessenger/src/signaling.dart @@ -8,9 +8,11 @@ library messenger.signaling; import 'dart:async'; +import 'dart:js'; import 'events.dart'; export 'events.dart'; part 'signaling/messagepassing.dart'; part 'signaling/signalingchannel.dart'; +part 'signaling/jscallbacksignaling.dart'; diff --git a/lib/WebRTCMessenger/src/signaling/jscallbacksignaling.dart b/lib/WebRTCMessenger/src/signaling/jscallbacksignaling.dart new file mode 100644 index 0000000..ba80593 --- /dev/null +++ b/lib/WebRTCMessenger/src/signaling/jscallbacksignaling.dart @@ -0,0 +1,42 @@ +/** + * JSCallbacksignaling + * + * simple example for a bidirectional signaling channel based on some undefined js technology + * + * @author Christian Hotz-Behofsits + */ + +part of messenger.signaling; + +class JSCallbackSignaling extends SignalingChannel{ + + + void recCallback(String message){ + newMessageController.add(new NewMessageEvent(Message.fromString(message))); + } + + /** + * connect + * + * @ TODO: add custom Exceptions + * * prevent self-connections + */ + void connect(var options){ + // register callback + context.callMethod('JSRegisterRecCallback', [recCallback]); + } + + /** + * send message + */ + send(Message message) => context.callMethod('JSSignalingsend', [Message.serialize(message)]); + + /** + * close + */ + close(){ + connection_completer.complete("connection closed"); + } + + +} \ No newline at end of file diff --git a/lib/WebRTCMessenger/src/signaling/messagepassing.dart b/lib/WebRTCMessenger/src/signaling/messagepassing.dart index 2092030..fdc12f0 100644 --- a/lib/WebRTCMessenger/src/signaling/messagepassing.dart +++ b/lib/WebRTCMessenger/src/signaling/messagepassing.dart @@ -19,7 +19,7 @@ class MessagePassing extends SignalingChannel{ * @ TODO: add custom Exceptions * * prevent self-connections */ - Future connect(Map options){ + void connect(Map options){ if(options.isEmpty) throw new StateError("empty option set excatly one value expected. none found!"); if(options.values.first == null) diff --git a/lib/WebRTCMessenger/src/signaling/signalingchannel.dart b/lib/WebRTCMessenger/src/signaling/signalingchannel.dart index c3e6dd8..acc5486 100644 --- a/lib/WebRTCMessenger/src/signaling/signalingchannel.dart +++ b/lib/WebRTCMessenger/src/signaling/signalingchannel.dart @@ -31,7 +31,7 @@ abstract class SignalingChannel{ /** * establish connection */ - Future connect(Map options); + void connect(var options); /** * send String to other side of Channel diff --git a/pubspec.yaml b/pubspec.yaml index 0ec7cf3..49002f2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,13 +1,13 @@ name: webrtcmessenger -version: 0.0.1 +version: 0.0.2 author: Christian Hotz-Behofsits description: A Webrtc Messenger -homepage: https://github.com/inkrement/messenger +homepage: https://github.com/inkrement/WebRTCMessenger environment: sdk: '>0.8.7' dependencies: - browser: ">=0.10.0 <0.11.0" - json: ">=0.9.1 <0.10.0" + browser: '>=0.10.0 <0.11.0' + json: '>=0.9.1 <0.10.0' dev_dependencies: logging: any unittest: any diff --git a/test/messenger_test.dart b/test/messenger_test.dart index 4b70501..444fdbc 100644 --- a/test/messenger_test.dart +++ b/test/messenger_test.dart @@ -1,7 +1,7 @@ library unittest.messenger; import 'package:unittest/unittest.dart'; -import 'package:WebRTCMessenger/WebRTCMessenger/messenger.dart'; +import 'package:WebRTCMessenger/WebRTCMessenger/webrtcmessenger.dart'; main() { diff --git a/web/webrtc.dart b/web/webrtc.dart index 94c61d2..49feaed 100644 --- a/web/webrtc.dart +++ b/web/webrtc.dart @@ -1,31 +1,54 @@ //import 'dart:html'; -import "package:WebRTCMessenger/WebRTCMessenger/messenger.dart"; +import "package:WebRTCMessenger/WebRTCMessenger/webrtcmessenger.dart"; +import 'package:logging/logging.dart'; void main() { /** - * TODO + * test call function to inspect js-output */ - - Messenger msg = new Messenger(); - /* - Peer alice = new Peer("alice_c"); - Peer bob = new Peer("bob_c"); - - //setup signaling channel - MessagePassing alice_sc = new MessagePassing(); - MessagePassing bob_sc = new MessagePassing(); - - //connect signaling channel - alice_sc.connect(bob_sc.identityMap()); - bob_sc.connect(alice_sc.identityMap()); - - //connect peer - JsDataChannelConnection alice_c = new JsDataChannelConnection(bob_sc); - JsDataChannelConnection bob_c = new JsDataChannelConnection(alice_sc); - Stream s_a = alice.listen(alice_c); - Stream s_b = bob.connect(bob_c); - */ + + + Peer alice = new Peer("alice_s3"); + Peer bob = new Peer("bob_s3"); + Peer clark = new Peer("clark_s3"); + + //setup signaling channels + JSCallbackSignaling alice_bob_sc = new JSCallbackSignaling(); + + alice_bob_sc.connect(null); + + + //set callbacks + + String s_alice = "some random string from alice"; + Message tm_alice = new Message(s_alice); + + + //each sould receive two messages + alice.onReceive.listen((NewMessageEvent mevent){ + print("alice revceived message: " + mevent.getMessage().toString()); + }); + + /* + * send messages + */ + alice.newConnectionController.stream.listen((_){ + if(alice.connections.length == 1){ + alice.multicast(tm_alice); + } + }); + + + /* + * create connections + */ + WebRtcDataChannel a_b_c = new WebRtcDataChannel(alice_bob_sc); + + //connect alice/bob bob/alice + alice.listen(a_b_c); + //bob.connect(a_b_c); + } diff --git a/web/webrtc.html b/web/webrtc.html index 772f5ac..b47d318 100644 --- a/web/webrtc.html +++ b/web/webrtc.html @@ -5,7 +5,6 @@ Webrtc -