Skip to content

Commit

Permalink
Fixed captureStream video rendering issue. Added "designer.renderStream"
Browse files Browse the repository at this point in the history
Releasd v1.3.0
  • Loading branch information
muaz-khan committed Dec 24, 2018
1 parent 043e0f4 commit dbe3563
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 18 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ Remove and clear all drawings from the canvas:
designer.clearCanvas();
```

## `renderStream`

Call this method internally to fix video rendering issues.

```javascript
designer.renderStream();
```

## `addSyncListener`

This callback is invoked as soon as something new is drawn. An array-of-points is passed over this function. That array MUST be shared with remote users for collaboration.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "canvas-designer",
"preferGlobal": false,
"version": "1.2.8",
"version": "1.3.0",
"author": {
"name": "Muaz Khan",
"email": "[email protected]",
Expand Down
8 changes: 8 additions & 0 deletions canvas-designer-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ function CanvasDesigner() {
});
};

designer.renderStream = function() {
if (!designer.iframe) return;

designer.postMessage({
renderStream: true
});
};

designer.widgetHtmlURL = 'widget.html';
designer.widgetJsURL = 'widget.min.js';
}
21 changes: 19 additions & 2 deletions dev/decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ function setSelection(element, prop) {
/* Default: setting default selected shape!! */
is.set(window.selectedIcon);

window.addEventListener('load', function() {
function setDefaultSelectedIcon() {
var toolBox = document.getElementById('tool-box');
var canvasElements = toolBox.getElementsByTagName('canvas');
var shape = window.selectedIcon.toLowerCase();


var firstMatch;
for (var i = 0; i < canvasElements.length; i++) {
if (!firstMatch && (canvasElements[i].id || '').indexOf(shape) !== -1) {
Expand All @@ -69,6 +68,10 @@ window.addEventListener('load', function() {
}

setSelection(firstMatch, window.selectedIcon);
}

window.addEventListener('load', function() {
setDefaultSelectedIcon();
}, false);

(function() {
Expand Down Expand Up @@ -860,3 +863,17 @@ function hideContainers() {
pencilContainer.style.display =
lineWidthContainer.style.display = 'none';
}

function setTemporaryLine() {
var arr = ["line", [139, 261, 170, 219],
[1, "rgba(0,0,0,0)", "rgba(0,0,0,0)", 1, "source-over", "round", "round", "15px \"Arial\""]
];
points.push(arr);
drawHelper.redraw();

setTimeout(function() {
setSelection(document.getElementById('line'), 'Line');
}, 1000);

setTimeout(setDefaultSelectedIcon, 2000);
}
5 changes: 5 additions & 0 deletions dev/share-drawings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ window.addEventListener('message', function(event) {
return;
}

if (event.data.renderStream) {
setTemporaryLine();
return;
}

if (event.data.sdp) {
webrtcHandler.setRemoteDescription(event.data);
return;
Expand Down
9 changes: 6 additions & 3 deletions dev/webrtc-handler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var webrtcHandler = {
createOffer: function(callback) {
var captureStream = document.getElementById('main-canvas').captureStream(15);

var captureStream = document.getElementById('main-canvas').captureStream();
var peer = this.getPeer();

captureStream.getTracks().forEach(function(track) {
Expand All @@ -26,7 +25,11 @@ var webrtcHandler = {
});
},
setRemoteDescription: function(sdp) {
this.peer.setRemoteDescription(new RTCSessionDescription(sdp));
this.peer.setRemoteDescription(new RTCSessionDescription(sdp)).then(function() {
if (typeof setTemporaryLine === 'function') {
setTemporaryLine();
}
});
},
createAnswer: function(sdp, callback) {
var peer = this.getPeer();
Expand Down
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,12 @@ <h2><a href="https://rtcmulticonnection.herokuapp.com/demos/dashboard/">WebRTC D
}

numberOfConnectedUsers.innerHTML = connection.getAllParticipants().length;

if(connection.isInitiator) {
setTimeout(function() {
designer.renderStream();
}, 1000);
}
};

connection.onclose = connection.onerror = connection.onleave = function() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "canvas-designer",
"preferGlobal": false,
"version": "1.2.8",
"version": "1.3.0",
"author": {
"name": "Muaz Khan",
"email": "[email protected]",
Expand Down
37 changes: 31 additions & 6 deletions widget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated: 2018-12-24 7:44:44 AM UTC
// Last time updated: 2018-12-24 8:45:05 AM UTC

// _______________
// Canvas-Designer
Expand Down Expand Up @@ -2817,12 +2817,11 @@
/* Default: setting default selected shape!! */
is.set(window.selectedIcon);

window.addEventListener('load', function() {
function setDefaultSelectedIcon() {
var toolBox = document.getElementById('tool-box');
var canvasElements = toolBox.getElementsByTagName('canvas');
var shape = window.selectedIcon.toLowerCase();


var firstMatch;
for (var i = 0; i < canvasElements.length; i++) {
if (!firstMatch && (canvasElements[i].id || '').indexOf(shape) !== -1) {
Expand All @@ -2835,6 +2834,10 @@
}

setSelection(firstMatch, window.selectedIcon);
}

window.addEventListener('load', function() {
setDefaultSelectedIcon();
}, false);

(function() {
Expand Down Expand Up @@ -3627,6 +3630,20 @@
lineWidthContainer.style.display = 'none';
}

function setTemporaryLine() {
var arr = ["line", [139, 261, 170, 219],
[1, "rgba(0,0,0,0)", "rgba(0,0,0,0)", 1, "source-over", "round", "round", "15px \"Arial\""]
];
points.push(arr);
drawHelper.redraw();

setTimeout(function() {
setSelection(document.getElementById('line'), 'Line');
}, 1000);

setTimeout(setDefaultSelectedIcon, 2000);
}

var canvas = tempContext.canvas,
isTouch = 'createTouch' in document;

Expand Down Expand Up @@ -3903,6 +3920,11 @@
return;
}

if (event.data.renderStream) {
setTemporaryLine();
return;
}

if (event.data.sdp) {
webrtcHandler.setRemoteDescription(event.data);
return;
Expand Down Expand Up @@ -4023,8 +4045,7 @@

var webrtcHandler = {
createOffer: function(callback) {
var captureStream = document.getElementById('main-canvas').captureStream(15);

var captureStream = document.getElementById('main-canvas').captureStream();
var peer = this.getPeer();

captureStream.getTracks().forEach(function(track) {
Expand All @@ -4049,7 +4070,11 @@
});
},
setRemoteDescription: function(sdp) {
this.peer.setRemoteDescription(new RTCSessionDescription(sdp));
this.peer.setRemoteDescription(new RTCSessionDescription(sdp)).then(function() {
if (typeof setTemporaryLine === 'function') {
setTemporaryLine();
}
});
},
createAnswer: function(sdp, callback) {
var peer = this.getPeer();
Expand Down
10 changes: 5 additions & 5 deletions widget.min.js

Large diffs are not rendered by default.

0 comments on commit dbe3563

Please sign in to comment.