Expose scale factor value

This commit is contained in:
Sergey Stepanov 2024-03-02 16:38:53 +03:00
parent 3568b7a12a
commit 92e59672f9
No known key found for this signature in database
GPG key ID: A56B4929BAA8556B
5 changed files with 16 additions and 10 deletions

View file

@ -64,6 +64,7 @@ type (
AppVideoInfo struct {
W int `json:"w"`
H int `json:"h"`
S int `json:"s"`
A float32 `json:"a"`
}
)

View file

@ -6,6 +6,7 @@ type App interface {
AspectEnabled() bool
Init() error
ViewportSize() (int, int)
Scale() float64
Start()
Close()

View file

@ -130,6 +130,7 @@ func (c *coordinator) HandleGameStart(rq api.StartGameRequest[com.Uid], w *Worke
W: m.VideoW,
H: m.VideoH,
A: app.AspectRatio(),
S: int(app.Scale()),
}})
if err != nil {
c.log.Error().Err(err).Msgf("wrap")
@ -176,7 +177,7 @@ func (c *coordinator) HandleGameStart(rq api.StartGameRequest[com.Uid], w *Worke
response := api.StartGameResponse{Room: api.Room{Rid: r.Id()}, Record: w.conf.Recording.Enabled}
if r.App().AspectEnabled() {
ww, hh := r.App().ViewportSize()
response.AV = &api.AppVideoInfo{W: ww, H: hh, A: r.App().AspectRatio()}
response.AV = &api.AppVideoInfo{W: ww, H: hh, A: r.App().AspectRatio(), S: int(r.App().Scale())}
}
return api.Out{Payload: response}

View file

@ -127,7 +127,7 @@
<script src="js/env.js?v=5"></script>
<script src="js/input/input.js?v=3"></script>
<script src="js/gameList.js?v=3"></script>
<script src="js/stream/stream.js?v=5"></script>
<script src="js/stream/stream.js?v=6"></script>
<script src="js/room.js?v=3"></script>
<script src="js/network/ajax.js?v=3"></script>
<script src="js/network/socket.js?v=4"></script>

View file

@ -175,19 +175,22 @@ const stream = (() => {
const fit = 'contain'
event.sub(APP_VIDEO_CHANGED, (payload) => {
const {w, h, a} = payload
const {w, h, a, s} = payload
const scale = !s ? 1 : s;
const ww = w * scale;
const hh = h * scale;
state.aspect = a
const a2 = w / h
const a2 = ww / hh
state.screen.style['object-fit'] = a.toFixed(6) !== a2.toFixed(6) ? 'fill' : fit
state.h = payload.h
state.w = Math.floor(payload.h * payload.a)
// payload.a > 0 && (state.aspect = payload.a)
state.screen.setAttribute('width', payload.w)
state.screen.setAttribute('height', payload.h)
state.screen.style.aspectRatio = state.aspect
state.h = hh
state.w = Math.floor(hh * a)
state.screen.setAttribute('width', '' + ww)
state.screen.setAttribute('height', '' + hh)
state.screen.style.aspectRatio = '' + state.aspect
})
return {