Skip to content

Commit

Permalink
Merge pull request #2 from inkrement/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
inkrement committed Jul 6, 2014
2 parents 645159e + b6927ab commit 7c260fb
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 34 deletions.
4 changes: 2 additions & 2 deletions lib/WebRTCMessenger/src/connections/webrtcdatachannel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/WebRTCMessenger/src/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> json = JSON.decode(data);
Expand Down
2 changes: 1 addition & 1 deletion lib/WebRTCMessenger/src/peer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions lib/WebRTCMessenger/src/signaling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
42 changes: 42 additions & 0 deletions lib/WebRTCMessenger/src/signaling/jscallbacksignaling.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* JSCallbacksignaling
*
* simple example for a bidirectional signaling channel based on some undefined js technology
*
* @author Christian Hotz-Behofsits <[email protected]>
*/

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");
}


}
2 changes: 1 addition & 1 deletion lib/WebRTCMessenger/src/signaling/messagepassing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MessagePassing extends SignalingChannel{
* @ TODO: add custom Exceptions
* * prevent self-connections
*/
Future connect(Map<String, MessagePassing> options){
void connect(Map<String, MessagePassing> options){
if(options.isEmpty)
throw new StateError("empty option set excatly one value expected. none found!");
if(options.values.first == null)
Expand Down
2 changes: 1 addition & 1 deletion lib/WebRTCMessenger/src/signaling/signalingchannel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class SignalingChannel{
/**
* establish connection
*/
Future connect(Map options);
void connect(var options);

/**
* send String to other side of Channel
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: webrtcmessenger
version: 0.0.1
version: 0.0.2
author: Christian Hotz-Behofsits <[email protected]>
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
2 changes: 1 addition & 1 deletion test/messenger_test.dart
Original file line number Diff line number Diff line change
@@ -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() {

Expand Down
67 changes: 45 additions & 22 deletions web/webrtc.dart
Original file line number Diff line number Diff line change
@@ -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<NewConnectionEvent> s_a = alice.listen(alice_c);
Stream<NewConnectionEvent> 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);


}
1 change: 0 additions & 1 deletion web/webrtc.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta charset="utf-8">
<title>Webrtc</title>
<link rel="stylesheet" href="webrtc.css">
<script src="packages/browser/interop.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script src="https://apprtc.appspot.com/js/adapter.js"></script>
Expand Down

0 comments on commit 7c260fb

Please sign in to comment.