Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochum van der Ploeg committed Mar 27, 2018
1 parent c0ffe5e commit 9334e09
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/js/OT.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# TB.upgradeSystemRequirements()

window.OT =
timeStreamCreated: {}
checkSystemRequirements: ->
return 1
initPublisher: (one, two) ->
Expand Down
26 changes: 14 additions & 12 deletions src/js/OTHelpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,28 @@ OTPublisherError = (error) ->
TBError(error)

TBUpdateObjects = ()->
updateObject = () ->
console.log("JS: Objects being updated in TBUpdateObjects")
objects = document.getElementsByClassName('OT_root')

ratios = TBGetScreenRatios()
for e in objects
console.log("JS: Objects being updated in TBUpdateObjects")
updateObject = (e, time) ->
setTimeout(() ->
ratios = TBGetScreenRatios()
streamId = e.dataset.streamid
position = getPosition(e)

# If not a TBPosition yet set, or new position not equals to the old one. Update views.
if !e.TBPosition || position.top != e.TBPosition.top || position.left != e.TBPosition.left || position.width != e.TBPosition.width || position.height != e.TBPosition.height
console.log("JS: Object updated with sessionId " + streamId + " updated");
e.TBPosition = position;
Cordova.exec(TBSuccess, TBError, OTPlugin, "updateView", [streamId, position.top, position.left, position.width, position.height, TBGetZIndex(e), ratios.widthRatio, ratios.heightRatio]);
, time)
return

if window.Ionic || window.angular
setTimeout(updateObject, 20)
else
updateObject()
objects = document.getElementsByClassName('OT_root')
for e in objects
streamId = e.dataset.streamid
time = 0
if typeof window.angular != "undefined" || typeof window.Ionic != "undefined"
if OT.timeStreamCreated[streamId]
time = performance.now() - OT.timeStreamCreated[streamId]
delete OT.timeStreamCreated[streamId]
updateObject(e, time)
return

TBGenerateDomHelper = ->
Expand Down
1 change: 1 addition & 0 deletions src/js/OTSession.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class TBSession
pdebug "streamCreatedHandler", event
stream = new TBStream( event.stream, @connections[event.stream.connectionId] )
@streams[ stream.streamId ] = stream
OT.timeStreamCreated[stream.streamId] = performance.now()
streamEvent = new TBEvent("streamCreated")
streamEvent.stream = stream
#streamEvent = new TBEvent( {stream: stream } )
Expand Down
37 changes: 22 additions & 15 deletions www/opentok.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
window.OT = {
timeStreamCreated: {},
checkSystemRequirements: function() {
return 1;
},
Expand Down Expand Up @@ -252,28 +253,33 @@ OTPublisherError = function(error) {
};

TBUpdateObjects = function() {
var requestAnimationFrame, updateObject;
updateObject = function() {
var e, objects, position, ratios, streamId, _i, _len;
console.log("JS: Objects being updated in TBUpdateObjects");
objects = document.getElementsByClassName('OT_root');
ratios = TBGetScreenRatios();
for (_i = 0, _len = objects.length; _i < _len; _i++) {
e = objects[_i];
var e, objects, streamId, time, updateObject, _i, _len;
console.log("JS: Objects being updated in TBUpdateObjects");
updateObject = function(e, time) {
setTimeout(function() {
var position, ratios, streamId;
ratios = TBGetScreenRatios();
streamId = e.dataset.streamid;
position = getPosition(e);
if (!e.TBPosition || position.top !== e.TBPosition.top || position.left !== e.TBPosition.left || position.width !== e.TBPosition.width || position.height !== e.TBPosition.height) {
console.log("JS: Object updated with sessionId " + streamId + " updated");
e.TBPosition = position;
Cordova.exec(TBSuccess, TBError, OTPlugin, "updateView", [streamId, position.top, position.left, position.width, position.height, TBGetZIndex(e), ratios.widthRatio, ratios.heightRatio]);
return Cordova.exec(TBSuccess, TBError, OTPlugin, "updateView", [streamId, position.top, position.left, position.width, position.height, TBGetZIndex(e), ratios.widthRatio, ratios.heightRatio]);
}
}
}, time);
};
requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
if (requestAnimationFrame) {
requestAnimationFrame(updateObject);
} else {
setTimeout(updateObject, 1000 / 60);
objects = document.getElementsByClassName('OT_root');
for (_i = 0, _len = objects.length; _i < _len; _i++) {
e = objects[_i];
streamId = e.dataset.streamid;
time = 0;
if (typeof window.angular !== "undefined" || typeof window.Ionic !== "undefined") {
if (OT.timeStreamCreated[streamId]) {
time = performance.now() - OT.timeStreamCreated[streamId];
delete OT.timeStreamCreated[streamId];
}
}
updateObject(e, time);
}
};

Expand Down Expand Up @@ -929,6 +935,7 @@ TBSession = (function() {
pdebug("streamCreatedHandler", event);
stream = new TBStream(event.stream, this.connections[event.stream.connectionId]);
this.streams[stream.streamId] = stream;
OT.timeStreamCreated[stream.streamId] = performance.now();
streamEvent = new TBEvent("streamCreated");
streamEvent.stream = stream;
this.dispatchEvent(streamEvent);
Expand Down

0 comments on commit 9334e09

Please sign in to comment.