|
@@ -72,40 +72,6 @@ const FilmStrip = {
|
72
|
72
|
return this.calculateThumbnailSizeFromAvailable(width, height);
|
73
|
73
|
},
|
74
|
74
|
|
75
|
|
- /**
|
76
|
|
- * Normalizes local and remote thumbnail ratios
|
77
|
|
- */
|
78
|
|
- normalizeThumbnailRatio () {
|
79
|
|
- let remoteHeightRatio = interfaceConfig.REMOTE_THUMBNAIL_RATIO_HEIGHT;
|
80
|
|
- let remoteWidthRatio = interfaceConfig.REMOTE_THUMBNAIL_RATIO_WIDTH;
|
81
|
|
-
|
82
|
|
- let localHeightRatio = interfaceConfig.LOCAL_THUMBNAIL_RATIO_HEIGHT;
|
83
|
|
- let localWidthRatio = interfaceConfig.LOCAL_THUMBNAIL_RATIO_WIDTH;
|
84
|
|
-
|
85
|
|
- let commonHeightRatio = remoteHeightRatio * localHeightRatio;
|
86
|
|
-
|
87
|
|
- let localRatioCoefficient = localWidthRatio / localHeightRatio;
|
88
|
|
- let remoteRatioCoefficient = remoteWidthRatio / remoteHeightRatio;
|
89
|
|
-
|
90
|
|
- remoteWidthRatio = commonHeightRatio * remoteRatioCoefficient;
|
91
|
|
- remoteHeightRatio = commonHeightRatio;
|
92
|
|
-
|
93
|
|
- localWidthRatio = commonHeightRatio * localRatioCoefficient;
|
94
|
|
- localHeightRatio = commonHeightRatio;
|
95
|
|
-
|
96
|
|
- let localRatio = {
|
97
|
|
- widthRatio: localWidthRatio,
|
98
|
|
- heightRatio: localHeightRatio
|
99
|
|
- };
|
100
|
|
-
|
101
|
|
- let remoteRatio = {
|
102
|
|
- widthRatio: remoteWidthRatio,
|
103
|
|
- heightRatio: remoteHeightRatio
|
104
|
|
- };
|
105
|
|
-
|
106
|
|
- return { localRatio, remoteRatio };
|
107
|
|
- },
|
108
|
|
-
|
109
|
75
|
calculateAvailableSize() {
|
110
|
76
|
let availableHeight = interfaceConfig.FILM_STRIP_MAX_HEIGHT;
|
111
|
77
|
let thumbs = this.getThumbs(true);
|
|
@@ -181,34 +147,67 @@ const FilmStrip = {
|
181
|
147
|
return { availableWidth, availableHeight };
|
182
|
148
|
},
|
183
|
149
|
|
|
150
|
+ /**
|
|
151
|
+ * Calculate the thumbnail size in order to fit all the thumnails in passed
|
|
152
|
+ * dimensions.
|
|
153
|
+ * NOTE: Here we assume that the remote and local thumbnails are with the
|
|
154
|
+ * same height.
|
|
155
|
+ * @param {int} availableWidth the maximum width for all thumbnails
|
|
156
|
+ * @param {int} availableHeight the maximum height for all thumbnails
|
|
157
|
+ */
|
184
|
158
|
calculateThumbnailSizeFromAvailable(availableWidth, availableHeight) {
|
185
|
|
- let { localRatio, remoteRatio } = this.normalizeThumbnailRatio();
|
186
|
|
- let { remoteThumbs } = this.getThumbs(true);
|
187
|
|
- let remoteProportion = remoteRatio.widthRatio * remoteThumbs.length;
|
188
|
|
- let widthProportion = remoteProportion + localRatio.widthRatio;
|
189
|
|
-
|
190
|
|
- let heightUnit = availableHeight / localRatio.heightRatio;
|
191
|
|
- let widthUnit = availableWidth / widthProportion;
|
|
159
|
+ /**
|
|
160
|
+ * Let:
|
|
161
|
+ * lW - width of the local thumbnail
|
|
162
|
+ * rW - width of the remote thumbnail
|
|
163
|
+ * h - the height of the thumbnails
|
|
164
|
+ * remoteRatio - width:height for the remote thumbnail
|
|
165
|
+ * localRatio - width:height for the local thumbnail
|
|
166
|
+ * numberRemoteThumbs - number of remote thumbnails (we have only one
|
|
167
|
+ * local thumbnail)
|
|
168
|
+ *
|
|
169
|
+ * Since the height for local thumbnail = height for remote thumbnail
|
|
170
|
+ * and we know the ratio (width:height) for the local and for the
|
|
171
|
+ * remote thumbnail we can find rW/lW:
|
|
172
|
+ * rW / remoteRatio = lW / localRatio then -
|
|
173
|
+ * remoteLocalWidthRatio = rW / lW = remoteRatio / localRatio
|
|
174
|
+ * and rW = lW * remoteRatio / localRatio = lW * remoteLocalWidthRatio
|
|
175
|
+ * And the total width for the thumbnails is:
|
|
176
|
+ * totalWidth = rW * numberRemoteThumbs + lW
|
|
177
|
+ * = lW * remoteLocalWidthRatio * numberRemoteThumbs + lW =
|
|
178
|
+ * lW * (remoteLocalWidthRatio * numberRemoteThumbs + 1)
|
|
179
|
+ * and the h = lW/localRatio
|
|
180
|
+ *
|
|
181
|
+ * In order to fit all the thumbails in the area defined by
|
|
182
|
+ * availableWidth * availableHeight we should check one of the
|
|
183
|
+ * following options:
|
|
184
|
+ * 1) if availableHeight == h - totalWidth should be less than
|
|
185
|
+ * availableWidth
|
|
186
|
+ * 2) if availableWidth == totalWidth - h should be less than
|
|
187
|
+ * availableHeight
|
|
188
|
+ *
|
|
189
|
+ * 1) or 2) will be true and we are going to use it to calculate all
|
|
190
|
+ * sizes.
|
|
191
|
+ *
|
|
192
|
+ * if 1) is true that means that
|
|
193
|
+ * availableHeight/h > availableWidth/totalWidth otherwise 2) is true
|
|
194
|
+ */
|
192
|
195
|
|
193
|
|
- if (heightUnit < widthUnit) {
|
194
|
|
- widthUnit = heightUnit;
|
195
|
|
- }
|
196
|
|
- else
|
197
|
|
- heightUnit = widthUnit;
|
198
|
|
-
|
199
|
|
- let localVideo = {
|
200
|
|
- thumbWidth: widthUnit * localRatio.widthRatio,
|
201
|
|
- thumbHeight: heightUnit * localRatio.heightRatio
|
202
|
|
- };
|
203
|
|
- let remoteVideo = {
|
204
|
|
- thumbWidth: widthUnit * remoteRatio.widthRatio,
|
205
|
|
- thumbHeight: widthUnit * remoteRatio.heightRatio
|
206
|
|
- };
|
207
|
|
-
|
208
|
|
- return {
|
209
|
|
- localVideo,
|
210
|
|
- remoteVideo
|
211
|
|
- };
|
|
196
|
+ const numberRemoteThumbs = this.getThumbs(true).remoteThumbs.length;
|
|
197
|
+ const remoteLocalWidthRatio = interfaceConfig.REMOTE_THUMBNAIL_RATIO /
|
|
198
|
+ interfaceConfig.LOCAL_THUMBNAIL_RATIO;
|
|
199
|
+ const lW = Math.min(availableWidth /
|
|
200
|
+ (remoteLocalWidthRatio * numberRemoteThumbs + 1), availableHeight *
|
|
201
|
+ interfaceConfig.LOCAL_THUMBNAIL_RATIO);
|
|
202
|
+ const h = lW / interfaceConfig.LOCAL_THUMBNAIL_RATIO;
|
|
203
|
+ return { localVideo:{
|
|
204
|
+ thumbWidth: lW,
|
|
205
|
+ thumbHeight: h
|
|
206
|
+ }, remoteVideo: {
|
|
207
|
+ thumbWidth: lW * remoteLocalWidthRatio,
|
|
208
|
+ thumbHeight: h
|
|
209
|
+ }
|
|
210
|
+ };
|
212
|
211
|
},
|
213
|
212
|
|
214
|
213
|
resizeThumbnails (local, remote,
|