@g9tm/lynxcontrols-native 2.5.9 → 2.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/media.d.ts CHANGED
@@ -1,9 +1,19 @@
1
1
  import { type G9MediaProvider } from '@g9tm/lynxcontrols-foundation';
2
+ import { type ReactNode } from '@lynx-js/react';
2
3
  import type { G9HostNativeModule } from './protocol.js';
3
- /** Props of the `<g9-video>` element (`G9VideoUI` on Android, `G9LCVideoUI` on iOS). */
4
+ /** Props of the `<g9-video>` element (`G9VideoUI` on Android, `G9LCVideoUI` on iOS, `registerG9Video` on the web). */
4
5
  export interface G9VideoElementProps {
5
6
  /** `asset:///…` (Android), `file://…` (iOS), or `http(s)://…`. */
6
- readonly src: string;
7
+ readonly src?: string;
8
+ /**
9
+ * A live RTC track's id instead of a file (2.5.10, G9Hub 92): the host's track renderer draws it (Android
10
+ * `G9VideoTracks.register`, iOS `G9LCVideoTracks registerRenderer:`, web `registerG9Video({ tracks })`).
11
+ */
12
+ readonly track?: string;
13
+ /** Flipped left to right (the self view; 2.5.10). */
14
+ readonly mirror?: boolean;
15
+ /** The same as `object-fit` (2.5.10). */
16
+ readonly fit?: 'cover' | 'contain';
7
17
  /** Default true: the element starts paused. */
8
18
  readonly paused?: boolean;
9
19
  /** Default true. */
@@ -32,6 +42,18 @@ export interface G9VideoElementProps {
32
42
  readonly message: string;
33
43
  };
34
44
  }) => void;
45
+ /** The web's own controls on a file (native hosts draw none: use G9VideoPlayer). */
46
+ readonly controls?: boolean;
47
+ /** About four times a second while a file plays. */
48
+ readonly bindprogress?: (event: {
49
+ readonly detail: {
50
+ readonly seconds: number;
51
+ readonly duration: number;
52
+ };
53
+ }) => void;
54
+ /** A file that does not loop reached its end. */
55
+ readonly bindended?: () => void;
56
+ readonly id?: string;
35
57
  }
36
58
  declare module '@lynx-js/types' {
37
59
  interface IntrinsicElements {
@@ -57,4 +79,60 @@ export interface G9NativeMediaOptions {
57
79
  * Throws outside a host that linked `@g9tm/lynxcontrols-native`.
58
80
  */
59
81
  export declare function createNativeMediaProvider(options?: G9NativeMediaOptions): G9MediaProvider;
82
+ /** Props of {@link G9TrackVideo}. */
83
+ export interface G9TrackVideoProps {
84
+ /** The RTC engine's track id (null: nothing shows). */
85
+ readonly track: string | null | undefined;
86
+ /** The self view, flipped. */
87
+ readonly mirror?: boolean;
88
+ /** `cover` (default) or `contain` (a shared screen). */
89
+ readonly fit?: 'cover' | 'contain';
90
+ readonly className?: string;
91
+ readonly style?: Record<string, string | number>;
92
+ /** The track shows. */
93
+ readonly onReady?: () => void;
94
+ /** `no-track-renderer` (the host registered none) or `track-unknown`. */
95
+ readonly onError?: (code: string, message: string) => void;
96
+ }
97
+ /**
98
+ * A live call track in `<g9-video track>` (2.5.10, G9Hub 92): a call tile's `video` — the host's RTC engine (LiveKit)
99
+ * draws it, so the app's thread has no RTC code. Needs the host's track renderer (see {@link G9VideoElementProps.track}).
100
+ */
101
+ export declare function G9TrackVideo(props: G9TrackVideoProps): ReactNode;
102
+ /** Props of {@link G9VideoPlayer}. */
103
+ export interface G9VideoPlayerProps {
104
+ /** The recording (`file://…`, `http(s)://…`). */
105
+ readonly src: string;
106
+ /** A stable id (the element and its bar are addressed by it). */
107
+ readonly id: string;
108
+ /** Starts playing at once. Default false. */
109
+ readonly autoPlay?: boolean;
110
+ /** Starts muted. Default false. */
111
+ readonly muted?: boolean;
112
+ readonly fit?: 'cover' | 'contain';
113
+ readonly className?: string;
114
+ /** The box's style (default full width, 16:9). */
115
+ readonly style?: Record<string, string | number>;
116
+ /** The spoken names of the buttons. */
117
+ readonly words?: {
118
+ readonly play?: string;
119
+ readonly pause?: string;
120
+ readonly back?: string;
121
+ readonly forward?: string;
122
+ readonly mute?: string;
123
+ readonly unmute?: string;
124
+ };
125
+ /** The time as the app writes it (its digits); default m:ss. */
126
+ readonly formatTime?: (seconds: number) => string;
127
+ readonly onEnded?: () => void;
128
+ readonly onError?: (code: string, message: string) => void;
129
+ }
130
+ /** m:ss (h:mm:ss past an hour). */
131
+ export declare function g9VideoTime(seconds: number): string;
132
+ /**
133
+ * A recording with controls (2.5.11, G9Hub 97: video notes, meeting recordings): `<g9-video>` with play / pause,
134
+ * back and forward 10 s, a bar that seeks where it is tapped, the time and mute — the same on Android, iOS and the
135
+ * web (it uses the element's `progress` event and `seek` method).
136
+ */
137
+ export declare function G9VideoPlayer(props: G9VideoPlayerProps): ReactNode;
60
138
  //# sourceMappingURL=media.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.tsx"],"names":[],"mappings":"AAGA,OAAO,EAKL,KAAK,eAAe,EAErB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,kBAAkB,EAAoB,MAAM,YAAY,CAAC;AAQvE,wFAAwF;AACxF,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,oBAAoB;IACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,oBAAoB;IACpB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,mDAAmD;IACnD,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,wDAAwD;IACxD,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,qDAAqD;IACrD,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IACjD,oCAAoC;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,QA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EAAE,MAAM,KAAK,IAAI,CAAC;CAC5D;AAmBD,mCAAmC;AACnC,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMnD;AAsBD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,SAAS,CAiIlE"}
package/dist/media.jsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { G9Error } from "@g9tm/lynxcontrols-foundation";
2
- import { useSyncExternalStore } from "@lynx-js/react";
2
+ import { useRef, useState, useSyncExternalStore } from "@lynx-js/react";
3
3
  const hostModule = ()=>{
4
4
  var _ref;
5
5
  return null != (_ref = "u" < typeof NativeModules ? void 0 : null == NativeModules ? void 0 : NativeModules.G9HostModule) ? _ref : null;
@@ -17,7 +17,7 @@ function nativePlayer(media, options) {
17
17
  ...state,
18
18
  ...next
19
19
  };
20
- for (const view of Array.from(views))view();
20
+ for (const view1 of Array.from(views))view1();
21
21
  };
22
22
  const emit = (event)=>{
23
23
  if (state.disposed) return;
@@ -67,7 +67,7 @@ function nativePlayer(media, options) {
67
67
  ...state,
68
68
  disposed: true
69
69
  };
70
- for (const view of Array.from(views))view();
70
+ for (const view1 of Array.from(views))view1();
71
71
  listeners.clear();
72
72
  },
73
73
  subscribe (listener) {
@@ -114,4 +114,176 @@ function createNativeMediaProvider(options = {}) {
114
114
  createPlayer: (media, playerOptions = {})=>nativePlayer(media, playerOptions)
115
115
  };
116
116
  }
117
- export { createNativeMediaProvider };
117
+ function G9TrackVideo(props) {
118
+ var _props_mirror, _props_fit, _props_className, _props_style;
119
+ if (!props.track) return null;
120
+ return <g9-video track={props.track} mirror={null != (_props_mirror = props.mirror) ? _props_mirror : false} fit={null != (_props_fit = props.fit) ? _props_fit : 'cover'} className={null != (_props_className = props.className) ? _props_className : 'g9-track-video'} style={null != (_props_style = props.style) ? _props_style : {
121
+ width: '100%',
122
+ height: '100%'
123
+ }} {...props.onReady ? {
124
+ bindready: ()=>{
125
+ var _props_onReady;
126
+ return null == (_props_onReady = props.onReady) ? void 0 : _props_onReady.call(props);
127
+ }
128
+ } : {}} {...props.onError ? {
129
+ binderror: (e)=>{
130
+ var _props_onError;
131
+ return null == (_props_onError = props.onError) ? void 0 : _props_onError.call(props, e.detail.code, e.detail.message);
132
+ }
133
+ } : {}}/>;
134
+ }
135
+ const playerSvg = (body)=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#ffffff" stroke="none">${body}</svg>`;
136
+ const PLAY = playerSvg('<path d="M8 5.14v13.72a1 1 0 0 0 1.52.85l11.2-6.86a1 1 0 0 0 0-1.7L9.52 4.29A1 1 0 0 0 8 5.14z"/>');
137
+ const PAUSE = playerSvg('<rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/>');
138
+ const BACK = playerSvg('<path d="M11 6v12l-8.5-6z"/><path d="M21 6v12l-8.5-6z"/>');
139
+ const FORWARD = playerSvg('<path d="M13 6v12l8.5-6z"/><path d="M3 6v12l8.5-6z"/>');
140
+ const SOUND = playerSvg('<path d="M11 5L6 9H2v6h4l5 4z"/><path d="M15.5 8.5a5 5 0 0 1 0 7" stroke="#ffffff" stroke-width="2" fill="none"/>');
141
+ const SILENT = playerSvg('<path d="M11 5L6 9H2v6h4l5 4z"/><path d="M16 9l6 6M22 9l-6 6" stroke="#ffffff" stroke-width="2" fill="none"/>');
142
+ function g9VideoTime(seconds) {
143
+ const s = Math.max(0, Math.floor(seconds));
144
+ const h = Math.floor(s / 3600);
145
+ const m = Math.floor(s % 3600 / 60);
146
+ const ss = String(s % 60).padStart(2, '0');
147
+ return h ? `${h}:${String(m).padStart(2, '0')}:${ss}` : `${m}:${ss}`;
148
+ }
149
+ function PlayerButton(props) {
150
+ return <view id={props.id} style={{
151
+ width: '40px',
152
+ height: '40px',
153
+ display: 'flex',
154
+ alignItems: 'center',
155
+ justifyContent: 'center'
156
+ }} bindtap={props.onTap} accessibility-element={true} accessibility-traits="button" accessibility-label={props.label}>
157
+ <svg content={props.glyph} style={{
158
+ width: '22px',
159
+ height: '22px'
160
+ }}/>
161
+ </view>;
162
+ }
163
+ function G9VideoPlayer(props) {
164
+ var _props_muted, _props_words, _props_formatTime, _props_className, _props_style, _props_fit, _w_play, _w_pause, _w_back, _w_forward, _w_unmute, _w_mute;
165
+ const [paused, setPaused] = useState(!props.autoPlay);
166
+ const [muted, setMuted] = useState(null != (_props_muted = props.muted) ? _props_muted : false);
167
+ const [pos, setPos] = useState({
168
+ seconds: 0,
169
+ duration: 0
170
+ });
171
+ const ended = useRef(false);
172
+ const w = null != (_props_words = props.words) ? _props_words : {};
173
+ const fmt = null != (_props_formatTime = props.formatTime) ? _props_formatTime : g9VideoTime;
174
+ const seek = (seconds)=>{
175
+ try {
176
+ lynx.createSelectorQuery().select(`#${props.id}`).invoke({
177
+ method: 'seek',
178
+ params: {
179
+ seconds
180
+ },
181
+ success: ()=>{},
182
+ fail: ()=>{}
183
+ }).exec();
184
+ } catch {}
185
+ setPos((p)=>({
186
+ ...p,
187
+ seconds
188
+ }));
189
+ };
190
+ const toggle = ()=>{
191
+ if (paused && ended.current) {
192
+ ended.current = false;
193
+ seek(0);
194
+ }
195
+ setPaused(!paused);
196
+ };
197
+ const tapBar = (e)=>{
198
+ var _ref;
199
+ var _e_detail;
200
+ const x = null != (_ref = null == (_e_detail = e.detail) ? void 0 : _e_detail.x) ? _ref : 0;
201
+ try {
202
+ lynx.createSelectorQuery().select(`#${props.id}_Bar`).invoke({
203
+ method: 'boundingClientRect',
204
+ params: {},
205
+ success: (r)=>{
206
+ if (pos.duration > 0 && r.width > 0) seek(Math.max(0, Math.min(1, (x - r.left) / r.width)) * pos.duration);
207
+ },
208
+ fail: ()=>{}
209
+ }).exec();
210
+ } catch {}
211
+ };
212
+ const share = pos.duration > 0 ? Math.min(1, pos.seconds / pos.duration) : 0;
213
+ const time = `${fmt(pos.seconds)} / ${fmt(pos.duration)}`;
214
+ return <view className={null != (_props_className = props.className) ? _props_className : 'g9-video-player'} style={null != (_props_style = props.style) ? _props_style : {
215
+ position: 'relative',
216
+ width: '100%',
217
+ aspectRatio: '16 / 9',
218
+ backgroundColor: '#000000'
219
+ }}>
220
+ <g9-video id={props.id} src={props.src} paused={paused} loop={false} muted={muted} fit={null != (_props_fit = props.fit) ? _props_fit : 'contain'} style={{
221
+ position: 'absolute',
222
+ top: '0px',
223
+ right: '0px',
224
+ bottom: '0px',
225
+ left: '0px'
226
+ }} bindprogress={(e)=>setPos({
227
+ seconds: e.detail.seconds,
228
+ duration: e.detail.duration
229
+ })} bindended={()=>{
230
+ var _props_onEnded;
231
+ ended.current = true;
232
+ setPaused(true);
233
+ null == (_props_onEnded = props.onEnded) || _props_onEnded.call(props);
234
+ }} {...props.onError ? {
235
+ binderror: (e)=>{
236
+ var _props_onError;
237
+ return null == (_props_onError = props.onError) ? void 0 : _props_onError.call(props, e.detail.code, e.detail.message);
238
+ }
239
+ } : {}}/>
240
+ <view style={{
241
+ position: 'absolute',
242
+ left: '0px',
243
+ right: '0px',
244
+ bottom: '0px',
245
+ display: 'flex',
246
+ flexDirection: 'column',
247
+ backgroundColor: 'rgba(0, 0, 0, 0.45)',
248
+ direction: 'ltr'
249
+ }}>
250
+ <view id={`${props.id}_Bar`} style={{
251
+ height: '18px',
252
+ display: 'flex',
253
+ alignItems: 'center',
254
+ padding: '0px 12px'
255
+ }} bindtap={tapBar} accessibility-element={true} accessibility-traits="adjustable" accessibility-label={time}>
256
+ <view style={{
257
+ flex: 1,
258
+ height: '3px',
259
+ borderRadius: '2px',
260
+ backgroundColor: 'rgba(255, 255, 255, 0.35)'
261
+ }}>
262
+ <view style={{
263
+ width: `${Math.round(1000 * share) / 10}%`,
264
+ height: '3px',
265
+ borderRadius: '2px',
266
+ backgroundColor: '#ffffff'
267
+ }}/>
268
+ </view>
269
+ </view>
270
+ <view style={{
271
+ display: 'flex',
272
+ flexDirection: 'row',
273
+ alignItems: 'center',
274
+ padding: '0px 4px 4px 4px'
275
+ }}>
276
+ <PlayerButton id={`${props.id}_Play`} label={paused ? null != (_w_play = w.play) ? _w_play : 'Play' : null != (_w_pause = w.pause) ? _w_pause : 'Pause'} glyph={paused ? PLAY : PAUSE} onTap={toggle}/>
277
+ <PlayerButton id={`${props.id}_Back`} label={null != (_w_back = w.back) ? _w_back : '-10 s'} glyph={BACK} onTap={()=>seek(Math.max(0, pos.seconds - 10))}/>
278
+ <PlayerButton id={`${props.id}_Forward`} label={null != (_w_forward = w.forward) ? _w_forward : '+10 s'} glyph={FORWARD} onTap={()=>seek(pos.duration > 0 ? Math.min(pos.duration, pos.seconds + 10) : pos.seconds + 10)}/>
279
+ <text style={{
280
+ flex: 1,
281
+ fontSize: '12px',
282
+ color: '#ffffff'
283
+ }}>{time}</text>
284
+ <PlayerButton id={`${props.id}_Mute`} label={muted ? null != (_w_unmute = w.unmute) ? _w_unmute : 'Unmute' : null != (_w_mute = w.mute) ? _w_mute : 'Mute'} glyph={muted ? SILENT : SOUND} onTap={()=>setMuted(!muted)}/>
285
+ </view>
286
+ </view>
287
+ </view>;
288
+ }
289
+ export { G9TrackVideo, G9VideoPlayer, createNativeMediaProvider, g9VideoTime };
@@ -6,7 +6,7 @@
6
6
  # same :path. Its version is the family's (npm run check:versions).
7
7
  Pod::Spec.new do |s|
8
8
  s.name = 'g9lynx-native-swift'
9
- s.version = '2.5.9'
9
+ s.version = '2.5.11'
10
10
  s.summary = 'The Swift views of the G9 <g9-richtext>, <g9-canvas> and <g9-blurhash> Lynx elements (UIKit, Core Text).'
11
11
  s.homepage = 'https://github.com/imankari/g9lynxcontrols'
12
12
  s.license = { :type => 'MIT' }
@@ -4,7 +4,7 @@
4
4
  # package version — the family's own LYNX_VERSION (scripts/lynx-version.mjs; npm run check:versions).
5
5
  Pod::Spec.new do |s|
6
6
  s.name = 'g9lynx-native'
7
- s.version = '2.5.9'
7
+ s.version = '2.5.11'
8
8
  s.summary = 'G9 SQLite, host and speech native modules, the <g9-video>, <g9-richtext>, <g9-canvas> and <g9-blurhash> elements and the digit-drawing <input>/<textarea> for Lynx (sqlite3, NSUserDefaults, UIKit, AVFoundation, Speech, Core Text).'
9
9
  s.homepage = 'https://github.com/imankari/g9lynxcontrols'
10
10
  s.license = { :type => 'MIT' }
@@ -7,6 +7,29 @@ NS_ASSUME_NONNULL_BEGIN
7
7
  @interface G9LCVideoView : UIView
8
8
  @end
9
9
 
10
+ /** A live track shown in `<g9-video track="…">` (2.5.10, G9Hub 92): what the RTC engine gives back. */
11
+ @protocol G9LCVideoTrackAttachment <NSObject>
12
+ /** `mirror` or `fit` changed while the track shows. */
13
+ - (void)updateMirror:(BOOL)mirror cover:(BOOL)cover;
14
+ /** The element let go of the track: remove the renderer view. */
15
+ - (void)detach;
16
+ @end
17
+
18
+ /** The app's RTC engine (LiveKit): puts its renderer view for a track into the element's view and keeps it fed. */
19
+ @protocol G9LCVideoTrackRenderer <NSObject>
20
+ /** Shows `track` in `container`; nil when the track is not known (the element sends `error { code: 'track-unknown' }`). */
21
+ - (nullable id<G9LCVideoTrackAttachment>)attachTrack:(NSString *)track
22
+ toView:(UIView *)container
23
+ mirror:(BOOL)mirror
24
+ cover:(BOOL)cover;
25
+ @end
26
+
27
+ /** Where the host registers its track renderer, once: `[G9LCVideoTracks registerRenderer:liveKitRenderer]`. */
28
+ @interface G9LCVideoTracks : NSObject
29
+ + (void)registerRenderer:(nullable id<G9LCVideoTrackRenderer>)renderer;
30
+ + (nullable id<G9LCVideoTrackRenderer>)renderer;
31
+ @end
32
+
10
33
  /**
11
34
  * The `<g9-video>` element on iOS (plan/specs/06 §7), the same contract as Android's `G9LCVideoUI.kt`: muted looping
12
35
  * playback (`AVQueuePlayer` + `AVPlayerLooper`) for the intro carousel. Props: `src` (`file://…`, `http(s)://…`),
@@ -14,6 +37,8 @@ NS_ASSUME_NONNULL_BEGIN
14
37
  * (`cover` | `contain`). Events: `ready` (first frame displayable), `nearend` `{ seconds }`, `looped`, `error`
15
38
  * `{ code, message }`. The host registers it on its `LynxConfig` (2.5.7: no longer process-wide, and prefixed `G9LC`
16
39
  * so an app's own `G9VideoUI` does not clash): `[config registerUI:G9LCVideoUI.class withName:@"g9-video"]`.
40
+ * 2.5.10 (G9Hub): `track` shows a live RTC track drawn by the host's `G9LCVideoTrackRenderer` instead of a file,
41
+ * `mirror` flips the picture (the self view), `fit` is the same as `object-fit`.
17
42
  */
18
43
  @interface G9LCVideoUI : LynxUI <G9LCVideoView *>
19
44
  @end
@@ -5,6 +5,7 @@
5
5
  #import <Lynx/LynxEventEmitter.h>
6
6
  #import <Lynx/LynxPropsProcessor.h>
7
7
  #import <Lynx/LynxUIContext.h>
8
+ #import <Lynx/LynxUIMethodProcessor.h>
8
9
  #import "core/G9VideoCore.h"
9
10
  #include <math.h>
10
11
 
@@ -22,6 +23,24 @@ static void *G9VideoKVO = &G9VideoKVO;
22
23
 
23
24
  @end
24
25
 
26
+ static id<G9LCVideoTrackRenderer> G9VideoTrackRendererShared = nil;
27
+
28
+ @implementation G9LCVideoTracks
29
+
30
+ + (void)registerRenderer:(id<G9LCVideoTrackRenderer>)renderer {
31
+ @synchronized(self) {
32
+ G9VideoTrackRendererShared = renderer;
33
+ }
34
+ }
35
+
36
+ + (id<G9LCVideoTrackRenderer>)renderer {
37
+ @synchronized(self) {
38
+ return G9VideoTrackRendererShared;
39
+ }
40
+ }
41
+
42
+ @end
43
+
25
44
  @implementation G9LCVideoUI {
26
45
  AVQueuePlayer *_player;
27
46
  AVPlayerLooper *_looper;
@@ -39,7 +58,14 @@ static void *G9VideoKVO = &G9VideoKVO;
39
58
  BOOL _applyScheduled;
40
59
  double _startSeconds;
41
60
  NSInteger _loopCount;
61
+ NSInteger _ticks;
62
+ id _endObserver;
42
63
  G9VideoLoopTracker *_tracker;
64
+ BOOL _mirror;
65
+ NSString *_track;
66
+ NSString *_shownTrack;
67
+ id<G9LCVideoTrackAttachment> _attachment;
68
+ UIView *_trackView;
43
69
  }
44
70
 
45
71
  // Not self-registered (2.5.7, G9Hub): a process-wide `g9-video` would take the name from an app that has its own
@@ -97,6 +123,21 @@ LYNX_PROP_SETTER("object-fit", setObjectFit, NSString *) {
97
123
  [self scheduleApply];
98
124
  }
99
125
 
126
+ LYNX_PROP_SETTER("fit", setFit, NSString *) {
127
+ _cover = requestReset || ![value isEqualToString:@"contain"];
128
+ [self scheduleApply];
129
+ }
130
+
131
+ LYNX_PROP_SETTER("mirror", setMirror, BOOL) {
132
+ _mirror = requestReset ? NO : value;
133
+ [self scheduleApply];
134
+ }
135
+
136
+ LYNX_PROP_SETTER("track", setTrack, NSString *) {
137
+ _track = (requestReset || value.length == 0) ? nil : [value copy];
138
+ [self scheduleApply];
139
+ }
140
+
100
141
  // Props arrive one setter at a time; apply them together once per main-queue turn.
101
142
  - (void)scheduleApply {
102
143
  if (_applyScheduled) return;
@@ -111,6 +152,19 @@ LYNX_PROP_SETTER("object-fit", setObjectFit, NSString *) {
111
152
  _applyScheduled = NO;
112
153
  ((AVPlayerLayer *)self.view.layer).videoGravity =
113
154
  _cover ? AVLayerVideoGravityResizeAspectFill : AVLayerVideoGravityResizeAspect;
155
+ // a file is flipped here; a live track is flipped by its renderer (told `mirror`)
156
+ self.view.transform = _mirror && _track == nil ? CGAffineTransformMakeScale(-1, 1) : CGAffineTransformIdentity;
157
+ BOOL trackChanged = !(_track == _shownTrack || [_track isEqualToString:_shownTrack]);
158
+ if (trackChanged) {
159
+ [self showTrack];
160
+ } else {
161
+ [_attachment updateMirror:_mirror cover:_cover];
162
+ }
163
+ if (_track != nil) {
164
+ [self teardown];
165
+ _prepared = NO;
166
+ return;
167
+ }
114
168
  BOOL sourceChanged = !(_src == _preparedSrc || [_src isEqualToString:_preparedSrc]);
115
169
  if (!_prepared || sourceChanged || _loop != _preparedLoop) [self prepare];
116
170
  if (_player == nil) return;
@@ -122,6 +176,40 @@ LYNX_PROP_SETTER("object-fit", setObjectFit, NSString *) {
122
176
  }
123
177
  }
124
178
 
179
+ - (void)showTrack {
180
+ [self detachTrack];
181
+ if (_track == nil) return;
182
+ id<G9LCVideoTrackRenderer> renderer = [G9LCVideoTracks renderer];
183
+ if (renderer == nil) {
184
+ [self send:@"error"
185
+ detail:@{@"code" : @"no-track-renderer", @"message" : @"G9LCVideoTracks registerRenderer: was not called."}];
186
+ return;
187
+ }
188
+ UIView *container = [[UIView alloc] initWithFrame:self.view.bounds];
189
+ container.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
190
+ container.userInteractionEnabled = NO;
191
+ [self.view addSubview:container];
192
+ id<G9LCVideoTrackAttachment> shown = [renderer attachTrack:_track toView:container mirror:_mirror cover:_cover];
193
+ if (shown == nil) {
194
+ [container removeFromSuperview];
195
+ [self send:@"error"
196
+ detail:@{@"code" : @"track-unknown", @"message" : [NSString stringWithFormat:@"No track \"%@\".", _track]}];
197
+ return;
198
+ }
199
+ _trackView = container;
200
+ _attachment = shown;
201
+ _shownTrack = [_track copy];
202
+ [self send:@"ready" detail:@{}];
203
+ }
204
+
205
+ - (void)detachTrack {
206
+ [_attachment detach];
207
+ _attachment = nil;
208
+ [_trackView removeFromSuperview];
209
+ _trackView = nil;
210
+ _shownTrack = nil;
211
+ }
212
+
125
213
  - (void)prepare {
126
214
  [self teardown];
127
215
  _prepared = YES;
@@ -146,6 +234,14 @@ LYNX_PROP_SETTER("object-fit", setObjectFit, NSString *) {
146
234
  [_looper addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:G9VideoKVO];
147
235
  } else {
148
236
  [_player insertItem:item afterItem:nil];
237
+ // a file that does not loop says when it ended (2.5.11)
238
+ __weak G9LCVideoUI *weakEnd = self;
239
+ _endObserver = [[NSNotificationCenter defaultCenter] addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
240
+ object:item
241
+ queue:[NSOperationQueue mainQueue]
242
+ usingBlock:^(NSNotification *note) {
243
+ [weakEnd send:@"ended" detail:@{}];
244
+ }];
149
245
  }
150
246
  [_player addObserver:self forKeyPath:@"currentItem.status" options:NSKeyValueObservingOptionNew context:G9VideoKVO];
151
247
  AVPlayerLayer *layer = (AVPlayerLayer *)self.view.layer;
@@ -167,6 +263,26 @@ LYNX_PROP_SETTER("object-fit", setObjectFit, NSString *) {
167
263
  if (!isfinite(duration) || !isfinite(position)) return;
168
264
  NSNumber *left = [_tracker progressPositionMs:position * 1000.0 durationMs:duration * 1000.0];
169
265
  if (left != nil) [self send:@"nearend" detail:@{@"seconds" : left}];
266
+ // progress about four times a second (the observer runs every 0.1 s for the near-end mark; 2.5.11)
267
+ if (++_ticks % 3 == 0 && _player.rate != 0) {
268
+ [self send:@"progress" detail:@{@"seconds" : @(position), @"duration" : @(duration)}];
269
+ }
270
+ }
271
+
272
+ // Moves a file to `seconds` (2.5.11, the controls of G9VideoPlayer).
273
+ LYNX_UI_METHOD(seek) {
274
+ AVPlayerItem *item = _player.currentItem;
275
+ if (item == nil) {
276
+ callback(kUIMethodUnknown, @"no file is playing");
277
+ return;
278
+ }
279
+ double seconds = [params[@"seconds"] doubleValue];
280
+ double duration = CMTimeGetSeconds(item.duration);
281
+ if (seconds < 0) seconds = 0;
282
+ if (isfinite(duration) && seconds > duration) seconds = duration;
283
+ [_player seekToTime:CMTimeMakeWithSeconds(seconds, 600) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
284
+ [self send:@"progress" detail:@{@"seconds" : @(seconds), @"duration" : @(isfinite(duration) ? duration : 0)}];
285
+ callback(kUIMethodSuccess, nil);
170
286
  }
171
287
 
172
288
  - (void)observeValueForKeyPath:(NSString *)keyPath
@@ -226,6 +342,8 @@ LYNX_PROP_SETTER("object-fit", setObjectFit, NSString *) {
226
342
  }
227
343
 
228
344
  - (void)teardown {
345
+ if (_endObserver != nil) [[NSNotificationCenter defaultCenter] removeObserver:_endObserver];
346
+ _endObserver = nil;
229
347
  if (_player == nil) return;
230
348
  AVPlayerLayer *layer = (AVPlayerLayer *)self.view.layer;
231
349
  [layer removeObserver:self forKeyPath:@"readyForDisplay" context:G9VideoKVO];
@@ -245,6 +363,7 @@ LYNX_PROP_SETTER("object-fit", setObjectFit, NSString *) {
245
363
  }
246
364
 
247
365
  - (void)dealloc {
366
+ [self detachTrack];
248
367
  [self teardown];
249
368
  }
250
369
 
@@ -1,11 +1,12 @@
1
1
  import Foundation
2
2
 
3
3
  /// How `<g9-richtext>` and `<g9-canvas>` fetch pictures (2.5.8): `session` is the host's to set (a pinned one) before the
4
- /// first page opens; plain http is fetched only from this device or the local network.
4
+ /// first page opens; plain http is fetched only from this device or the local network. Public and visible to
5
+ /// Objective-C since 2.5.10 (`G9LCImages.session = G9Http.shared.session`; `[G9LCImages setSession:…]`).
5
6
  @objc(G9LCImages)
6
- final class G9LCImages: NSObject {
7
+ public final class G9LCImages: NSObject {
7
8
  /// The session pictures are fetched with. Default `URLSession.shared`.
8
- @objc static var session: URLSession = .shared
9
+ @objc public static var session: URLSession = .shared
9
10
 
10
11
  /// Whether a host is on this device or the local network.
11
12
  static func isLocal(_ host: String?) -> Bool {
@@ -18,11 +19,38 @@ final class G9LCImages: NSObject {
18
19
  }
19
20
 
20
21
  /// How an exported board becomes the app's file (2.5.8): the PNG's bytes, its name and type → the `cvexport` event's
21
- /// `file` (`id`, `name`, `size`, `mime`, `uri`). The default writes it to the temporary folder.
22
- enum G9LCCanvasFiles {
23
- static var register: (Data, String, String) throws -> [String: Any] = { data, name, mime in
22
+ /// `file` (`id`, `name`, `size`, `mime`, `uri`). The default writes it to the temporary folder. Public since 2.5.10:
23
+ /// Swift sets `register`; Objective-C calls `[G9LCCanvasFiles setRegister:^NSDictionary *(NSData *, NSString *,
24
+ /// NSString *) { … }]` (a nil result fails the export) and `resetRegister` for the default.
25
+ @objc(G9LCCanvasFiles)
26
+ public final class G9LCCanvasFiles: NSObject {
27
+ /// The default: the temporary folder.
28
+ public static let temporaryFolder: (Data, String, String) throws -> [String: Any] = { data, name, mime in
24
29
  let url = FileManager.default.temporaryDirectory.appendingPathComponent("g9canvas-\(UUID().uuidString).png")
25
30
  try data.write(to: url)
26
31
  return ["id": url.path, "name": name, "size": data.count, "mime": mime, "uri": url.absoluteString]
27
32
  }
33
+
34
+ /// Turns an exported board into the app's file (Swift).
35
+ public static var register: (Data, String, String) throws -> [String: Any] = temporaryFolder
36
+
37
+ /// The register block from Objective-C: the file's dictionary, or nil when it could not be stored.
38
+ @objc public static func setRegister(_ block: @escaping (Data, String, String) -> [String: Any]?) {
39
+ register = { data, name, mime in
40
+ guard let file = block(data, name, mime) else { throw G9LCCanvasFilesError.notStored }
41
+ return file
42
+ }
43
+ }
44
+
45
+ /// Back to the temporary folder.
46
+ @objc public static func resetRegister() {
47
+ register = temporaryFolder
48
+ }
49
+
50
+ private override init() {}
51
+ }
52
+
53
+ /// The host's register block returned nil.
54
+ public enum G9LCCanvasFilesError: Error {
55
+ case notStored
28
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g9tm/lynxcontrols-native",
3
- "version": "2.5.9",
3
+ "version": "2.5.11",
4
4
  "description": "Android and iOS platform layer: the G9SqliteModule and G9HostModule native modules (Autolink) and their JS adapters.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -44,14 +44,14 @@
44
44
  "check:android-types": "node scripts/android-bridge-types.mjs"
45
45
  },
46
46
  "dependencies": {
47
- "@g9tm/lynxcontrols-foundation": "2.5.9",
48
- "@g9tm/lynxcontrols-sqlite": "2.5.9"
47
+ "@g9tm/lynxcontrols-foundation": "2.5.11",
48
+ "@g9tm/lynxcontrols-sqlite": "2.5.11"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@lynx-js/react": ">=0.129.3 <0.130.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@g9tm/lynxcontrols-lynxtron": "2.5.9",
54
+ "@g9tm/lynxcontrols-lynxtron": "2.5.11",
55
55
  "@lynx-js/autolink-codegen": "0.6.0"
56
56
  }
57
57
  }