Skip to content

Commit

Permalink
SSEConnection demo fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Aug 23, 2017
1 parent 0cb7a27 commit e4600c3
Show file tree
Hide file tree
Showing 19 changed files with 702 additions and 41 deletions.
14 changes: 13 additions & 1 deletion demos/Audio+Video+TextChat+FileSharing.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ <h1>

<script src="/dev/FileBufferReader.js"></script>
<script>
window.enableAdapter = true; // enable adapter.js

// ......................................................
// .......................UI Code........................
// ......................................................
Expand Down Expand Up @@ -179,8 +181,18 @@ <h1>

connection.videosContainer = document.getElementById('videos-container');
connection.onstream = function(event) {
event.mediaElement.removeAttribute('src');
event.mediaElement.removeAttribute('srcObject');

var video = document.createElement('video');
video.controls = true;
if(event.type === 'local') {
video.muted = true;
}
video.srcObject = event.stream;

var width = parseInt(connection.videosContainer.clientWidth / 2) - 20;
var mediaElement = getHTMLMediaElement(event.mediaElement, {
var mediaElement = getHTMLMediaElement(video, {
title: event.userid,
buttons: ['full-screen'],
width: width,
Expand Down
2 changes: 1 addition & 1 deletion demos/SSEConnection.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Demo version: 2017.08.14 -->
<!-- Demo version: 2017.08.23 -->

<!DOCTYPE html>
<html lang="en" dir="ltr">
Expand Down
6 changes: 3 additions & 3 deletions demos/SSEConnection/SSE.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
require('get-param.php');
require('enableCORS.php');

header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
// date_default_timezone_set("America/New_York");
header("Content-Type: text/event-stream\n\n");

// "me" stands for "Current User Unique ID"
$me = getParam('me');
Expand All @@ -26,4 +26,4 @@

ob_flush();
flush();
?>
?>
2 changes: 1 addition & 1 deletion demos/SSEConnection/enableCORS.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ function enableCORS()
}

enableCORS();
?>
?>
2 changes: 1 addition & 1 deletion demos/SSEConnection/get-param.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ function getParam($id)
}
return $param;
}
?>
?>
2 changes: 1 addition & 1 deletion demos/SSEConnection/publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
echo $response;
exit();
}
?>
?>
2 changes: 1 addition & 1 deletion demos/SSEConnection/write-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ function removeJSON($receiver, $sender)

return true;
}
?>
?>
15 changes: 14 additions & 1 deletion demos/Video-Conferencing.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ <h1>
</section>

<script src="/dist/RTCMultiConnection.min.js"></script>
<script src="/dev/adapter.js"></script>
<script src="/socket.io/socket.io.js"></script>

<!-- custom layout for HTML5 audio/video elements -->
<link rel="stylesheet" href="/dev/getHTMLMediaElement.css">
<script src="/dev/getHTMLMediaElement.js"></script>
<script>
window.enableAdapter = true; // enable adapter.js

// ......................................................
// .......................UI Code........................
// ......................................................
Expand Down Expand Up @@ -114,8 +117,18 @@ <h1>

connection.videosContainer = document.getElementById('videos-container');
connection.onstream = function(event) {
event.mediaElement.removeAttribute('src');
event.mediaElement.removeAttribute('srcObject');

var video = document.createElement('video');
video.controls = true;
if(event.type === 'local') {
video.muted = true;
}
video.srcObject = event.stream;

var width = parseInt(connection.videosContainer.clientWidth / 2) - 20;
var mediaElement = getHTMLMediaElement(event.mediaElement, {
var mediaElement = getHTMLMediaElement(video, {
title: event.userid,
buttons: ['full-screen'],
width: width,
Expand Down
13 changes: 13 additions & 0 deletions dev/RTCMultiConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1649,4 +1649,17 @@
}
connection.join(roomid);
};

connection.resetScreen = function() {
sourceId = null;
if (DetectRTC && DetectRTC.screen) {
delete DetectRTC.screen.sourceId;
}

currentUserMediaRequest = {
streams: [],
mutex: false,
queueRequests: []
};
};
})(this);
45 changes: 25 additions & 20 deletions dev/SSEConnection.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// SSEConnection.js

function SSEConnection(connection, connectCallback) {
connection.trickleIce = false;
// connection.trickleIce = false;

var sseDirPath = 'https://webrtcweb.com/SSE/';

connection.socket = new EventSource(sseDirPath + 'SSE.php?me=' + connection.userid, {
withCredentials: false
});

document.querySelector('h1').innerHTML = connection.userid;
connection.socket = new EventSource(sseDirPath + 'SSE.php?me=' + connection.userid);

var skipDuplicate = {};
connection.socket.onmessage = function(e) {
Expand All @@ -27,9 +23,29 @@ function SSEConnection(connection, connectCallback) {
}
if (!data) return;

if (data.remoteUserId) {
if (data.eventName === connection.socketMessageEvent) {
onMessagesCallback(data.data);
}
return;
}

Object.keys(data).forEach(function(key) {
var message = data[key];
if (!message.length) return;

if (message instanceof Array) {
message.forEach(function(m) {
m = JSON.parse(m);
if (!m) return;

if (m.eventName === connection.socketMessageEvent) {
onMessagesCallback(m.data);
}
});
return;
}

message = JSON.parse(message);
if (!message) return;

Expand All @@ -38,13 +54,10 @@ function SSEConnection(connection, connectCallback) {
}
});
};

connection.socket.emit = function(eventName, data, callback) {
callback = callback || function() {};

if (!eventName || !data) return;
if (eventName === 'changed-uuid') return callback();
if (data.message && data.message.shiftedModerationControl) return callback();
if (eventName === 'changed-uuid') return;
if (data.message && data.message.shiftedModerationControl) return;

if (!data.remoteUserId) return;

Expand All @@ -70,19 +83,11 @@ function SSEConnection(connection, connectCallback) {
connection.socket.onopen = function() {
if (connectCallback) {
if (connection.enableLogs) {
console.log('SSE connection is opened.');
console.info('SSE connection is opened.');
}

connectCallback(connection.socket);
connectCallback = null;

if (connection.isInitiator) {
connection.socket.emit(connection.socketMessageEvent, {
remoteUserId: connection.userid,
message: 'test',
sender: connection.userid
}, function() {});
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions dev/getHTMLMediaElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ function getHTMLMediaElement(mediaElement, config) {
mediaBox.className = 'media-box';
mediaElementContainer.appendChild(mediaBox);

if(config.title) {
var h2 = document.createElement('h2');
if (config.title) {
var h2 = document.createElement('h2');
h2.innerHTML = config.title;
h2.setAttribute('style', 'position: absolute;color:white;font-size:17px;text-shadow: 1px 1px black;padding:0;margin:0;text-align: left; margin-top: 10px; margin-left: 10px;');
mediaBox.appendChild(h2);
Expand Down
15 changes: 14 additions & 1 deletion dist/RTCMultiConnection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

// Last time updated: 2017-08-14 7:41:06 AM UTC
// Last time updated: 2017-08-23 5:50:53 PM UTC

// _________________________
// RTCMultiConnection v3.4.4
Expand Down Expand Up @@ -5753,6 +5753,19 @@ window.RTCMultiConnection = function(roomid, forceOptions) {
}
connection.join(roomid);
};

connection.resetScreen = function() {
sourceId = null;
if (DetectRTC && DetectRTC.screen) {
delete DetectRTC.screen.sourceId;
}

currentUserMediaRequest = {
streams: [],
mutex: false,
queueRequests: []
};
};
})(this);

};
4 changes: 2 additions & 2 deletions dist/RTCMultiConnection.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function serverHandler(request, response) {
return;
}

if(filename && filename.indexOf('Video-Broadcasting.html') !== -1) {
if (filename && filename.indexOf('Video-Broadcasting.html') !== -1) {
filename = filename.replace('Video-Broadcasting.html', 'video-broadcasting.html');
}

Expand Down
19 changes: 17 additions & 2 deletions v2.2.2/RTCMultiConnection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated at Sunday, July 30th, 2017, 11:34:00 AM
// Last time updated at Wednesday, August 23rd, 2017, 9:02:27 PM

// Quick-Demo for newbies: http://jsfiddle.net/c46de0L8/
// Another simple demo: http://jsfiddle.net/zar6fg60/
Expand Down Expand Up @@ -4141,7 +4141,9 @@

this.iceServers = {
iceServers: this.iceServers,
iceTransports: this.rtcConfiguration.iceTransports
iceTransportPolicy: this.rtcConfiguration.iceTransports,
rtcpMuxPolicy: 'require', // or negotiate
bundlePolicy: 'max-bundle'
};
} else this.iceServers = null;

Expand Down Expand Up @@ -6534,6 +6536,19 @@
};

connection.Plugin = Plugin;

connection.resetScreen = function() {
sourceId = null;
if (DetectRTC && DetectRTC.screen) {
delete DetectRTC.screen.sourceId;
}

currentUserMediaRequest = {
streams: [],
mutex: false,
queueRequests: []
};
};
}

})();
4 changes: 2 additions & 2 deletions v2.2.2/RTCMultiConnection.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit e4600c3

Please sign in to comment.