Skip to content

Commit 010b87a

Browse files
committed
update to remote and local resize logic
1 parent 7fcb490 commit 010b87a

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

addons/gst-web/src/app.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ var app = new Vue({
261261
console.log("scaleLocal changed from " + oldValue + " to " + newValue);
262262
if (oldValue !== null && newValue !== oldValue) {
263263
if (newValue === true) {
264+
webrtc.element.style.width = '';
265+
webrtc.element.style.height = '';
264266
webrtc.element.setAttribute("class", "video scale");
265267
} else {
266268
webrtc.element.setAttribute("class", "video");
@@ -471,7 +473,7 @@ webrtc.input.onfullscreenhotkey = () => {
471473

472474
webrtc.input.onresizeend = () => {
473475
app.windowResolution = webrtc.input.getWindowResolution();
474-
var newRes = parseInt(app.windowResolution[0]/window.devicePixelRatio) + "x" + parseInt(app.windowResolution[1]/window.devicePixelRatio);
476+
var newRes = parseInt(app.windowResolution[0]) + "x" + parseInt(app.windowResolution[1]);
475477
console.log(`Window size changed: ${app.windowResolution[0]}x${app.windowResolution[1]}, scaled to: ${newRes}`);
476478
webrtc.sendDataChannelMessage("r," + newRes);
477479
webrtc.sendDataChannelMessage("s," + window.devicePixelRatio);
@@ -592,13 +594,15 @@ webrtc.onsystemaction = (action) => {
592594
app.scaleLocal = true;
593595
}
594596
}
595-
596-
// Send initial window size.
597+
} else if (action.startsWith("resolution")) {
598+
// Sent when remote resizing is enabled.
599+
// Match the CSS of the video element to the remote resolution.
600+
var remote_res = action.split(",")[1];
601+
console.log("received remote resolution of: " + remote_res);
597602
if (app.resizeRemote === true) {
598-
app.windowResolution = webrtc.input.getWindowResolution();
599-
var newRes = parseInt(app.windowResolution[0]/window.devicePixelRatio) + "x" + parseInt(app.windowResolution[1]/window.devicePixelRatio);
600-
console.log(`Initial window resolution: ${app.windowResolution[0]}x${app.windowResolution[1]}, scaled to: ${newRes}`);
601-
webrtc.sendDataChannelMessage("r," + newRes);
603+
var toks = remote_res.split("x");
604+
webrtc.element.style.width = toks[0]/window.devicePixelRatio+'px';
605+
webrtc.element.style.height = toks[1]/window.devicePixelRatio+'px';
602606
}
603607
} else if (action.startsWith("local_scaling")) {
604608
// Local scaling default pushed from server
@@ -685,6 +689,11 @@ fetch("/turn/")
685689
// get initial local resolution
686690
app.windowResolution = webrtc.input.getWindowResolution();
687691

692+
if (app.scaleLocal === false) {
693+
webrtc.element.style.width = app.windowResolution[0]/window.devicePixelRatio+'px';
694+
webrtc.element.style.height = app.windowResolution[1]/window.devicePixelRatio+'px';
695+
}
696+
688697
if (config.iceServers.length > 1) {
689698
app.debugEntries.push(applyTimestamp("[app] using TURN servers: " + config.iceServers[1].urls.join(", ")));
690699
} else {

addons/gst-web/src/signalling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class WebRTCDemoSignalling {
182182
// Send local device resolution and scaling with HELLO message.
183183
var currRes = webrtc.input.getWindowResolution();
184184
var meta = {
185-
"res": parseInt(currRes[0]/window.devicePixelRatio) + "x" + parseInt(currRes[1]/window.devicePixelRatio),
185+
"res": parseInt(currRes[0]) + "x" + parseInt(currRes[1]),
186186
"scale": window.devicePixelRatio
187187
};
188188
this.state = 'connected';

src/selkies_gstreamer/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,8 @@ def on_resize_handler(res):
635635
logger.warning("skipping resize because last resize failed.")
636636
return
637637
logger.warning("resizing display from {} to {}".format(curr_res, new_res))
638-
resize_display(res)
638+
if resize_display(res):
639+
app.send_remote_resolution(res)
639640

640641
# Initial binding of enable resize handler.
641642
if enable_resize:

src/selkies_gstreamer/gstwebrtc_app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,14 @@ def send_resize_enabled(self, resize_enabled):
933933
self.__send_data_channel_message(
934934
"system", {"action": "resize,"+str(resize_enabled)})
935935

936+
def send_remote_resolution(self, res):
937+
"""sends the current remote resolution to the client
938+
"""
939+
940+
logger.info("sending remote resolution of: " + res)
941+
self.__send_data_channel_message(
942+
"system", {"action": "resolution," + res})
943+
936944
def send_ping(self, t):
937945
"""Sends a ping request over the data channel to measure latency
938946
"""

0 commit comments

Comments
 (0)