Skip to content

Commit

Permalink
tinny fixes; a little bit updates and some new stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Aug 19, 2013
1 parent d499f77 commit ed178a1
Show file tree
Hide file tree
Showing 42 changed files with 3,654 additions and 2,882 deletions.
42 changes: 29 additions & 13 deletions DataChannel/DataChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,23 @@
if (self.config) return;

self.config = {
onroom: function(room) {
ondatachannel: function(room) {
if (!dataConnector) {
self.room = room;
return;
}

var tempRoom = {
id: room.roomToken,
owner: room.broadcaster
};

if (self.ondatachannel) return self.ondatachannel(tempRoom);

if (self.joinedARoom) return;
self.joinedARoom = true;

dataConnector.joinRoom({
roomToken: room.roomToken,
joinUser: room.broadcaster
});
self.join(tempRoom);
},
onopen: function(userid, _channel) {
self.onopen(userid, _channel);
Expand Down Expand Up @@ -153,7 +157,7 @@
fileReceiver = new FileReceiver();
textReceiver = new TextReceiver();

if (self.room) self.config.onroom(self.room);
if (self.room) self.config.ondatachannel(self.room);
}

this.open = function(_channel) {
Expand All @@ -175,6 +179,18 @@
prepareInit(init);
};

// manually join a room
this.join = function(room) {
if (!room.id || !room.owner) {
throw 'Invalid room info passed.';
}

dataConnector.joinRoom({
roomToken: room.id,
joinUser: room.owner
});
};

this.send = function(data, _channel) {
if (!data) throw 'No file, data or text message to share.';
if (data.size)
Expand Down Expand Up @@ -515,7 +531,7 @@
onmessage: function(response) {
if (response.userToken == self.userToken) return;

if (isGetNewRoom && response.roomToken && response.broadcaster) config.onroom(response);
if (isGetNewRoom && response.roomToken && response.broadcaster) config.ondatachannel(response);

if (response.newParticipant) onNewParticipant(response.newParticipant);

Expand Down Expand Up @@ -627,7 +643,7 @@
packets = 0;

// uuid is used to uniquely identify sending instance
var uuid = getRandomString();
file.uuid = getRandomString();

var reader = new window.FileReader();
reader.readAsDataURL(file);
Expand All @@ -636,7 +652,7 @@
function onReadAsDataURL(event, text) {
var data = {
type: 'file',
uuid: uuid
uuid: file.uuid
};

if (event) {
Expand All @@ -649,15 +665,15 @@
remaining: packets--,
length: numberOfPackets,
sent: numberOfPackets - packets
}, uuid);
}, file.uuid);

if (text.length > packetSize) data.message = text.slice(0, packetSize);
else {
data.message = text;
data.last = true;
data.name = file.name;

if (config.onFileSent) config.onFileSent(file, uuid);
if (config.onFileSent) config.onFileSent(file, file.uuid);
}

// WebRTC-DataChannels.send(data, privateDataChannel)
Expand Down Expand Up @@ -709,7 +725,7 @@
// if you don't want to auto-save to disk:
// channel.autoSaveToDisk=false;
if (root.autoSaveToDisk)
FileSaver.SaveToDisk(virtualURL, data.name);
FileSaver.SaveToDisk(dataURL, data.name);

// channel.onFileReceived = function(fileName, file) {}
// file.blob || file.dataURL || file.url || file.uuid
Expand Down Expand Up @@ -885,7 +901,7 @@
credential: 'homeo',
username: 'homeo'
};
iceServers.iceServers = [TURN, STUN];
iceServers.iceServers = [STUN, TURN];
}

var optional = {
Expand Down
32 changes: 32 additions & 0 deletions DataChannel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ channel.onmessage = function(message, userid, latency) { }

=

##### `ondatachannel`

Allows you show list of all available data channels to the user; and let him choose which one to join:

```javascript
channel.ondatachannel = function(data_channel) {
channel.join(data_channel);

// or
channel.join({
id: data_channel.id,
owner: data_channel.owner
});

// id: unique identifier for the session
// owner: unique identifier for the session initiator
};
```

=

##### Use custom user-ids

```javascript
Expand Down Expand Up @@ -160,6 +181,17 @@ channel.leave(); // closing entire session

=

##### `uuid` for files

You can get `uuid` for each file (being sent) like this:

```javascript
channel.send(file);
var uuid = file.uuid; // "file"-Dot-uuid
```

=

##### To Share files

```javascript
Expand Down
4 changes: 2 additions & 2 deletions DataChannel/auto-session-establishment.html
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ <h2 style="display: block; font-size: 1em; text-align: center;">Share Files</h2>
+ '<section class="message" contenteditable>' + data + '</section>';
}

if (!parent) chatOutput.insertBefore(div, chatOutput.firstChild);
else parent.insertBefore(div, parent.firstChild);
if (!parent) chatOutput.appendChild(div, chatOutput.firstChild);
else fileProgress.appendChild(div, fileProgress.firstChild);

div.tabIndex = 0;
div.focus();
Expand Down
Loading

0 comments on commit ed178a1

Please sign in to comment.