Skip to content

Commit

Permalink
Merge pull request #13 from Temasys/development
Browse files Browse the repository at this point in the history
Fixing incomingMessage sending it's own peerId
  • Loading branch information
serrynaimo committed Aug 27, 2014
2 parents e3f4da7 + 578bae6 commit 526b0fe
Show file tree
Hide file tree
Showing 13 changed files with 6,504 additions and 5,753 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> SkywayJS is an open-source client-side library for your web-browser that enables any website to easily leverage the capabilities of WebRTC and its direct data streaming powers between peers for audio/video conferencing or file transfer.
You'll need a Temasys Developer Account and an API key to use this. [Register here to get your API key](https://developers.temasys.com.sg).
You'll need a Temasys Developer Account and an API key to use this. [Register here to get your API key](https://developer.temasys.com.sg).

We've gone to great length to make this library work in as many browsers as possible. SkywayJS is build on top of [AdapterJS](https://github.com/Temasys/AdapterJS) and works with our [Temasys WebRTC Plugin](https://temasys.atlassian.net/wiki/display/TWPP/WebRTC+Plugins) even in Internet Explorer and Safari on Mac and PC.

Expand Down
7 changes: 7 additions & 0 deletions demo/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@
<div id="chat_log" class="list-group"></div>
</div>
</div>
<form role="form">
<div class="checkbox">
<label>
<input id="send_data_channel" type="checkbox"> Send via datachannel
</label>
</div>
</form>
<textarea id="chat_input" placeholder="Enter your chat message here" class="well" disabled></textarea>
</div>
</div>
Expand Down
54 changes: 35 additions & 19 deletions demo/app/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Demo.Elements = {
fileLog: '#file_log',
fileBody: '#file_body',
chatLog: '#chat_log',
chatBody: '#chat_body'
chatBody: '#chat_body',
sendDataChannel: '#send_data_channel'
};
Demo.API.displayChatMessage = function (peerId, message, isFile) {
var timestamp = new Date();
Expand Down Expand Up @@ -74,13 +75,17 @@ Demo.Skyway.init({
Skyway Events
*********************************************************/
//---------------------------------------------------
Demo.Skyway.on('dataTransferState', function (state, transferId, peerId, transferInfo){
Demo.Skyway.on('dataTransferState', function (state, transferId, peerId, transferInfo, error){
transferInfo = transferInfo || {};
var element = '#' + transferId;
var name = transferInfo.name;
var size = transferInfo.size;
var senderPeerId = transferInfo.senderPeerId;
var data = transferInfo.data;
if (data) {
console.info(data);
data = URL.createObjectURL(data);
}
var percentage = transferInfo.percentage;

switch (state) {
Expand All @@ -102,7 +107,6 @@ Demo.Skyway.on('dataTransferState', function (state, transferId, peerId, transfe
Demo.API.displayChatMessage(senderPeerId, 'I\'ve sent a File', false);
break;
case Demo.Skyway.DATA_TRANSFER_STATE.DOWNLOAD_STARTED :
alert(JSON.stringify(transferInfo));
Demo.API.displayChatMessage(senderPeerId, {
content: '<p><u><b>' + name + '</b></u><br><em>' + size + ' Bytes</em></p>' +
'<div class="progress progress-striped">' +
Expand Down Expand Up @@ -147,19 +151,20 @@ Demo.Skyway.on('dataTransferState', function (state, transferId, peerId, transfe
alert('User "' + peerId + '" has rejected your file');
break;
case Demo.Skyway.DATA_TRANSFER_STATE.ERROR :
alert('File for ' + transferInfo.type + ' failed to send. Reason: \n' +
transferInfo.message);
alert('File for ' + error.transferType + ' failed to send. Reason: \n' +
error.message);
}
});
//---------------------------------------------------
Demo.Skyway.on('incomingMessage', function (message, peerId, isSelf) {
console.info(message);
Demo.Skyway.on('incomingMessage', function (message, peerId, peerInfo, isSelf) {
if (message.isDataChannel) {
message.content = message.content.header + ': ' + message.content.content;
console.info(peerInfo);
} else {
message.content = message.content.content;
}
Demo.API.displayChatMessage((isSelf) ? 'You' : peerId, message);
Demo.API.displayChatMessage((isSelf) ? 'You' :
peerInfo.userData.displayName, message);
});
//---------------------------------------------------
Demo.Skyway.on('peerJoined', function (peerId, peerInfo, isSelf){
Expand Down Expand Up @@ -230,10 +235,15 @@ Demo.Skyway.on('incomingStream', function (peerId, stream, isSelf){
});
//---------------------------------------------------
Demo.Skyway.on('mediaAccessSuccess', function (stream){
attachMediaStream( $(Demo.Elements.localVideo)[0], stream );
attachMediaStream($(Demo.Elements.localVideo)[0], stream);
Demo.Streams.local = $(Demo.Elements.localVideo)[0].src;
});
//---------------------------------------------------
Demo.Skyway.on('mediaAccessError', function (stream){
alert((typeof error === 'object') ? error.message :
error);
});
//---------------------------------------------------
Demo.Skyway.on('readyStateChange', function (state, error){
console.info('State: ' + state);
var statuses = ['Busy', 'Online', 'Away', 'Offline'];
Expand Down Expand Up @@ -318,7 +328,7 @@ Demo.Skyway.on('handshakeProgress', function (state, peerId) {
Demo.Skyway.on('candidateGenerationState', function (state, peerId) {
var color = 'orange';
switch( state ){
case Demo.Skyway.CANDIDATE_GENERATION_STATE.DONE:
case Demo.Skyway.CANDIDATE_GENERATION_STATE.COMPLETED:
color = 'green'; break;
}
$('#user' + peerId + ' .4' ).css('color', color);
Expand Down Expand Up @@ -377,11 +387,10 @@ Demo.Skyway.on('peerConnectionState', function (state, peerId) {
Demo.Skyway.on('dataChannelState', function (state, peerId) {
var color = 'red';
switch (state) {
case Demo.Skyway.DATA_CHANNEL_STATE.NEW:
case Demo.Skyway.DATA_CHANNEL_STATE.ERROR:
color = 'red';
break;
case Demo.Skyway.DATA_CHANNEL_STATE.LOADING:
case Demo.Skyway.DATA_CHANNEL_STATE.CONNECTING:
color = 'orange';
break;
case Demo.Skyway.DATA_CHANNEL_STATE.OPEN:
Expand Down Expand Up @@ -447,6 +456,10 @@ Demo.Skyway.on('channelError', function (error) {
content: 'Channel Error:<br>' + error
});
});
//---------------------------------------------------
Demo.Skyway.on('mediaAccessError', function (error) {
alert(error);
});
/********************************************************
DOM Events
*********************************************************/
Expand All @@ -457,13 +470,16 @@ $(document).ready(function () {
$(Demo.Elements.chatInput).keyup(function(e) {
e.preventDefault();
if (e.keyCode === 13) {
Demo.Skyway.sendP2PMessage({
header: '[DC]',
content: $(Demo.Elements.chatInput).val()
});
Demo.Skyway.sendMessage({
content: $(Demo.Elements.chatInput).val()
});
if ($(Demo.Elements.sendDataChannel).prop('checked')) {
Demo.Skyway.sendP2PMessage({
header: '[DC]',
content: $(Demo.Elements.chatInput).val()
});
} else {
Demo.Skyway.sendMessage({
content: $(Demo.Elements.chatInput).val()
});
}
$(Demo.Elements.chatInput).val('');
}
});
Expand Down
Loading

0 comments on commit 526b0fe

Please sign in to comment.