Permalink
Browse files

WebRTC almost there.

  • Loading branch information...
Daniel Haehn
Daniel Haehn committed Mar 5, 2013
1 parent d03d1e4 commit 0a42ff2275d5bd53f1c3202d346e9e42ab199e75
Showing with 109 additions and 3 deletions.
  1. +8 −0 css/viewer.css
  2. +4 −0 index.html
  3. +23 −0 js/TB.min.js
  4. +5 −1 js/x.realtime.js
  5. +2 −0 js/x.scene.js
  6. +25 −2 js/x.share.js
  7. +42 −0 js/x.webrtc.js
View
@@ -90,6 +90,14 @@
display:none;
}
+#cams {
+ position: absolute;
+ bottom: 10px;
+ left: 50px;
+ height: 100px;
+ display:none;
+}
+
#body.landscape.webgl_enabled>#viewer>.threeDRenderer {
height: 100%;
width: 80%;
View
@@ -71,8 +71,10 @@
<script type='text/javascript' src='js/x.scene.js'></script>
<script type='text/javascript' src='js/x.share.js'></script>
<script type='text/javascript' src='js/x.realtime.js'></script>
+<script type='text/javascript' src='js/x.webrtc.js'></script>
<script type='text/javascript' src='js/xtk.js'></script>
<script type='text/javascript' src='js/pusher.min.js'></script>
+<script type='text/javascript' src='js/TB.min.js'></script>
<!-- Google Analytics -->
<script type="text/javascript">
@@ -449,6 +451,8 @@ <h1>Drop files anywhere...</h1>
</div>
<div id='log'></div>
+
+ <div id='cams'></div>
</div>
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -6,7 +6,7 @@ RT.pusher = null;
RT.link = function() {
if ( !RT.linked ) {
-
+
var _location = (window.location != window.parent.location) ? document.referrer
: document.location;
// here we make sure that location is a string
@@ -171,6 +171,10 @@ RT.link = function() {
// switch to the blue icon
$('#linklogo').hide();
$('#linkselectedlogo').show();
+
+ // connect webrtc
+ $('cams').show();
+ WRTC.connect();
} else {
View
@@ -215,6 +215,8 @@ function loadScene(sceneUrl) {
// reset the 3d bounding box
ren3d.resetBoundingBox();
+ WRTC.session = scene.sessionId;
+
};
});
View
@@ -162,21 +162,44 @@ function grabSlicedrop(client, foldername, _toUpload) {
return showError(error);
// now write the JSON scene
- writeScene(client, foldername, _toUpload);
+ getWRTCsession(client, foldername, _toUpload);
});
});
}
+function getWRTCsession(client, foldername, _toUpload) {
+
+// var _api = '23161912';
+// var _secret = '492a94430433bb8b47cc07f7bc592bc1e8a8d45b';
+//
+// $.ajax({
+// url : "https://api.opentok.com/hl/session/create",
+// type : "POST",
+// beforeSend : function(xhr) {
+// xhr.setRequestHeader('X-TB-PARTNER-AUTH', _api + ':' + _secret);
+// },
+// success : function(data) {
+//
+ var sessionId = '1_MX4yMzE2MTkxMn4xMjcuMC4wLjF-TW9uIE1hciAwNCAyMDo0MTo1NiBQU1QgMjAxM34wLjI1NTg4OTc3fg';//$(data).find('session_id').text();
+
+ writeScene(client, foldername, _toUpload, sessionId);
+//
+// }
+// });
+
+}
+
/**
* Here we create the scene which later gets parsed by Slice:Drop again.
*/
-function writeScene(client, foldername, _toUpload) {
+function writeScene(client, foldername, _toUpload, sessionId) {
// then we store a JSON scene
var _scene = {
+ sessionId : sessionId,
camera : {
ren3d : Array.apply([], ren3d.camera.view),
sliceX : Array.apply([], sliceX.camera.view),
View
@@ -0,0 +1,42 @@
+WRTC = {};
+
+WRTC.session = -1;
+
+WRTC.connect = function() {
+
+ var sessionId = WRTC.session;
+
+ var _api = '23161912';
+
+ // Todo shall be re-generated
+ var token = 'T1==cGFydG5lcl9pZD0yMzE2MTkxMiZzZGtfdmVyc2lvbj10YnJ1YnktdGJyYi12MC45MS4yMDExLTAyLTE3JnNpZz1kN2ZkYzJkMDQxYWQ2ZTM2Y2VlNTAyMWQ0ZWJkNWM2NGM2ZmY2NTM3OnJvbGU9bW9kZXJhdG9yJnNlc3Npb25faWQ9MV9NWDR5TXpFMk1Ua3hNbjR4TWpjdU1DNHdMakYtVFc5dUlFMWhjaUF3TkNBeU1Eb3pPRG94TWlCUVUxUWdNakF4TTM0d0xqYzFNVFkxTURkLSZjcmVhdGVfdGltZT0xMzYyNDU4NzE5Jm5vbmNlPTAuNTYzMjM2NzE0NTU1OTc0NyZleHBpcmVfdGltZT0xMzY1MDUwNzE0JmNvbm5lY3Rpb25fZGF0YT0=';
+
+ // Initialize session, set up event listeners, and connect
+ var session = TB.initSession(sessionId);
+ session.addEventListener('sessionConnected', sessionConnectedHandler);
+ session.connect(_api, token);
+
+ // session.addEventListener("sessionConnected", sessionConnectedHandler);
+ session.addEventListener("streamCreated", streamCreatedHandler);
+
+ function sessionConnectedHandler(event) {
+ var publisher = TB.initPublisher(_api, 'cams');
+ // session.publish(publisher);
+ subscribeToStreams(event.streams);
+ session.publish(publisher);
+ }
+
+ function subscribeToStreams(streams) {
+ for (var i = 0; i < streams.length; i++) {
+ var stream = streams[i];
+ if ( stream.connection.connectionId != session.connection.connectionId ) {
+ session.subscribe(stream);
+ }
+ }
+ }
+
+ function streamCreatedHandler(event) {
+ subscribeToStreams(event.streams);
+ }
+
+};

0 comments on commit 0a42ff2

Please sign in to comment.