Skip to content

Commit ed178a1

Browse files
committed
tinny fixes; a little bit updates and some new stuff.
1 parent d499f77 commit ed178a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3654
-2882
lines changed

DataChannel/DataChannel.js

+29-13
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,23 @@
9393
if (self.config) return;
9494

9595
self.config = {
96-
onroom: function(room) {
96+
ondatachannel: function(room) {
9797
if (!dataConnector) {
9898
self.room = room;
9999
return;
100100
}
101101

102+
var tempRoom = {
103+
id: room.roomToken,
104+
owner: room.broadcaster
105+
};
106+
107+
if (self.ondatachannel) return self.ondatachannel(tempRoom);
108+
102109
if (self.joinedARoom) return;
103110
self.joinedARoom = true;
104111

105-
dataConnector.joinRoom({
106-
roomToken: room.roomToken,
107-
joinUser: room.broadcaster
108-
});
112+
self.join(tempRoom);
109113
},
110114
onopen: function(userid, _channel) {
111115
self.onopen(userid, _channel);
@@ -153,7 +157,7 @@
153157
fileReceiver = new FileReceiver();
154158
textReceiver = new TextReceiver();
155159

156-
if (self.room) self.config.onroom(self.room);
160+
if (self.room) self.config.ondatachannel(self.room);
157161
}
158162

159163
this.open = function(_channel) {
@@ -175,6 +179,18 @@
175179
prepareInit(init);
176180
};
177181

182+
// manually join a room
183+
this.join = function(room) {
184+
if (!room.id || !room.owner) {
185+
throw 'Invalid room info passed.';
186+
}
187+
188+
dataConnector.joinRoom({
189+
roomToken: room.id,
190+
joinUser: room.owner
191+
});
192+
};
193+
178194
this.send = function(data, _channel) {
179195
if (!data) throw 'No file, data or text message to share.';
180196
if (data.size)
@@ -515,7 +531,7 @@
515531
onmessage: function(response) {
516532
if (response.userToken == self.userToken) return;
517533

518-
if (isGetNewRoom && response.roomToken && response.broadcaster) config.onroom(response);
534+
if (isGetNewRoom && response.roomToken && response.broadcaster) config.ondatachannel(response);
519535

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

@@ -627,7 +643,7 @@
627643
packets = 0;
628644

629645
// uuid is used to uniquely identify sending instance
630-
var uuid = getRandomString();
646+
file.uuid = getRandomString();
631647

632648
var reader = new window.FileReader();
633649
reader.readAsDataURL(file);
@@ -636,7 +652,7 @@
636652
function onReadAsDataURL(event, text) {
637653
var data = {
638654
type: 'file',
639-
uuid: uuid
655+
uuid: file.uuid
640656
};
641657

642658
if (event) {
@@ -649,15 +665,15 @@
649665
remaining: packets--,
650666
length: numberOfPackets,
651667
sent: numberOfPackets - packets
652-
}, uuid);
668+
}, file.uuid);
653669

654670
if (text.length > packetSize) data.message = text.slice(0, packetSize);
655671
else {
656672
data.message = text;
657673
data.last = true;
658674
data.name = file.name;
659675

660-
if (config.onFileSent) config.onFileSent(file, uuid);
676+
if (config.onFileSent) config.onFileSent(file, file.uuid);
661677
}
662678

663679
// WebRTC-DataChannels.send(data, privateDataChannel)
@@ -709,7 +725,7 @@
709725
// if you don't want to auto-save to disk:
710726
// channel.autoSaveToDisk=false;
711727
if (root.autoSaveToDisk)
712-
FileSaver.SaveToDisk(virtualURL, data.name);
728+
FileSaver.SaveToDisk(dataURL, data.name);
713729

714730
// channel.onFileReceived = function(fileName, file) {}
715731
// file.blob || file.dataURL || file.url || file.uuid
@@ -885,7 +901,7 @@
885901
credential: 'homeo',
886902
username: 'homeo'
887903
};
888-
iceServers.iceServers = [TURN, STUN];
904+
iceServers.iceServers = [STUN, TURN];
889905
}
890906

891907
var optional = {

DataChannel/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ channel.onmessage = function(message, userid, latency) { }
8989

9090
=
9191

92+
##### `ondatachannel`
93+
94+
Allows you show list of all available data channels to the user; and let him choose which one to join:
95+
96+
```javascript
97+
channel.ondatachannel = function(data_channel) {
98+
channel.join(data_channel);
99+
100+
// or
101+
channel.join({
102+
id: data_channel.id,
103+
owner: data_channel.owner
104+
});
105+
106+
// id: unique identifier for the session
107+
// owner: unique identifier for the session initiator
108+
};
109+
```
110+
111+
=
112+
92113
##### Use custom user-ids
93114

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

161182
=
162183

184+
##### `uuid` for files
185+
186+
You can get `uuid` for each file (being sent) like this:
187+
188+
```javascript
189+
channel.send(file);
190+
var uuid = file.uuid; // "file"-Dot-uuid
191+
```
192+
193+
=
194+
163195
##### To Share files
164196

165197
```javascript

DataChannel/auto-session-establishment.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ <h2 style="display: block; font-size: 1em; text-align: center;">Share Files</h2>
298298
+ '<section class="message" contenteditable>' + data + '</section>';
299299
}
300300

301-
if (!parent) chatOutput.insertBefore(div, chatOutput.firstChild);
302-
else parent.insertBefore(div, parent.firstChild);
301+
if (!parent) chatOutput.appendChild(div, chatOutput.firstChild);
302+
else fileProgress.appendChild(div, fileProgress.firstChild);
303303

304304
div.tabIndex = 0;
305305
div.focus();

0 commit comments

Comments
 (0)