Skip to content

Commit ac4f416

Browse files
update: regenerate dist, delete gha
1 parent ed80691 commit ac4f416

File tree

13 files changed

+672
-78
lines changed

13 files changed

+672
-78
lines changed

.github/workflows/npm-release.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

dist/fabric-interop/NativeViro.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export declare const generateCallbackId: () => string;
1313
export declare function handleViroEvent(callbackId: string, event: any): void;
1414
export declare function registerEventListener(nodeId: string, eventName: string, callback: ViroEventCallback): string;
1515
export declare function unregisterEventListener(nodeId: string, eventName: string, callbackId: string): void;
16-
export declare function initializeViro(): Promise<boolean>;
16+
export declare function initializeViro(config?: {
17+
debug?: boolean;
18+
arEnabled?: boolean;
19+
worldAlignment?: string;
20+
}): Promise<boolean>;
1721
export declare function createScene(sceneId: string, sceneType: string, props?: ViroNodeProps): void;
1822
export declare function activateScene(sceneId: string): void;
1923
export declare function deactivateScene(sceneId: string): void;

dist/fabric-interop/NativeViro.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ function unregisterEventListener(nodeId, eventName, callbackId) {
8686
}
8787
}
8888
// Initialize the Viro platform
89-
function initializeViro() {
89+
function initializeViro(config) {
9090
const nativeViro = (0, ViroGlobal_1.getNativeViro)();
9191
if (nativeViro) {
92-
return nativeViro.initialize();
92+
return nativeViro.initialize(config);
9393
}
9494
return Promise.reject(new Error("NativeViro not available"));
9595
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
declare const _default: ViroEventsManager;
2+
export default _default;
3+
declare class ViroEventsManager {
4+
eventEmitter: NativeEventEmitter;
5+
listeners: Map<any, any>;
6+
callbackRegistry: Map<any, any>;
7+
setupEventListeners(): void;
8+
/**
9+
* Register a callback for JSI events
10+
* @param {string} callbackId - The callback ID from JSI
11+
* @param {function} callback - The JavaScript callback function
12+
*/
13+
registerJSICallback(callbackId: string, callback: Function): void;
14+
/**
15+
* Unregister a JSI callback
16+
* @param {string} callbackId - The callback ID to remove
17+
*/
18+
unregisterJSICallback(callbackId: string): void;
19+
/**
20+
* Register a listener for node events
21+
* @param {string} nodeId - The node ID
22+
* @param {string} eventName - The event name
23+
* @param {function} callback - The callback function
24+
*/
25+
registerNodeEventListener(nodeId: string, eventName: string, callback: Function): void;
26+
/**
27+
* Register a listener for scene events
28+
* @param {string} sceneId - The scene ID
29+
* @param {string} eventName - The event name
30+
* @param {function} callback - The callback function
31+
*/
32+
registerSceneEventListener(sceneId: string, eventName: string, callback: Function): void;
33+
/**
34+
* Handle JSI callback events
35+
* @private
36+
*/
37+
private handleJSICallback;
38+
/**
39+
* Handle node events
40+
* @private
41+
*/
42+
private handleNodeEvent;
43+
/**
44+
* Handle scene events
45+
* @private
46+
*/
47+
private handleSceneEvent;
48+
/**
49+
* Check if the event system is ready
50+
* @returns {boolean}
51+
*/
52+
isEventSystemReady(): boolean;
53+
/**
54+
* Get the number of active listeners
55+
* @returns {number}
56+
*/
57+
getActiveListenerCount(): number;
58+
/**
59+
* Manually emit a JSI callback (for testing)
60+
* @param {string} callbackId - The callback ID
61+
* @param {object} eventData - The event data
62+
*/
63+
emitJSICallback(callbackId: string, eventData?: object): void;
64+
/**
65+
* Manually emit a node event (for testing)
66+
* @param {string} nodeId - The node ID
67+
* @param {string} eventName - The event name
68+
* @param {object} eventData - The event data
69+
*/
70+
emitNodeEvent(nodeId: string, eventName: string, eventData?: object): void;
71+
/**
72+
* Manually emit a scene event (for testing)
73+
* @param {string} sceneId - The scene ID
74+
* @param {string} eventName - The event name
75+
* @param {object} eventData - The event data
76+
*/
77+
emitSceneEvent(sceneId: string, eventName: string, eventData?: object): void;
78+
/**
79+
* Clean up all listeners and callbacks
80+
*/
81+
cleanup(): void;
82+
}
83+
import { NativeEventEmitter } from "react-native";
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
"use strict";
2+
/**
3+
* ViroEventsManager.js
4+
* JavaScript integration for ViroEventsTurboModule
5+
*
6+
* This module provides the JavaScript interface for handling
7+
* Viro JSI events through the TurboModule system
8+
*/
9+
var __importDefault = (this && this.__importDefault) || function (mod) {
10+
return (mod && mod.__esModule) ? mod : { "default": mod };
11+
};
12+
Object.defineProperty(exports, "__esModule", { value: true });
13+
const react_native_1 = require("react-native");
14+
const ViroEventsTurboModule_1 = __importDefault(require("./specs/ViroEventsTurboModule"));
15+
class ViroEventsManager {
16+
constructor() {
17+
this.eventEmitter = new react_native_1.NativeEventEmitter(ViroEventsTurboModule_1.default);
18+
this.listeners = new Map();
19+
this.callbackRegistry = new Map();
20+
// Set up event listeners
21+
this.setupEventListeners();
22+
}
23+
setupEventListeners() {
24+
// Listen for JSI callbacks
25+
this.eventEmitter.addListener("ViroJSICallback", (event) => {
26+
this.handleJSICallback(event);
27+
});
28+
// Listen for node events
29+
this.eventEmitter.addListener("ViroNodeEvent", (event) => {
30+
this.handleNodeEvent(event);
31+
});
32+
// Listen for scene events
33+
this.eventEmitter.addListener("ViroSceneEvent", (event) => {
34+
this.handleSceneEvent(event);
35+
});
36+
}
37+
/**
38+
* Register a callback for JSI events
39+
* @param {string} callbackId - The callback ID from JSI
40+
* @param {function} callback - The JavaScript callback function
41+
*/
42+
registerJSICallback(callbackId, callback) {
43+
if (typeof callback === "function") {
44+
this.callbackRegistry.set(callbackId, callback);
45+
console.log(`[ViroEventsManager] Registered JSI callback: ${callbackId}`);
46+
}
47+
else {
48+
console.warn(`[ViroEventsManager] Invalid callback for ID: ${callbackId}`);
49+
}
50+
}
51+
/**
52+
* Unregister a JSI callback
53+
* @param {string} callbackId - The callback ID to remove
54+
*/
55+
unregisterJSICallback(callbackId) {
56+
if (this.callbackRegistry.has(callbackId)) {
57+
this.callbackRegistry.delete(callbackId);
58+
console.log(`[ViroEventsManager] Unregistered JSI callback: ${callbackId}`);
59+
}
60+
}
61+
/**
62+
* Register a listener for node events
63+
* @param {string} nodeId - The node ID
64+
* @param {string} eventName - The event name
65+
* @param {function} callback - The callback function
66+
*/
67+
registerNodeEventListener(nodeId, eventName, callback) {
68+
const key = `${nodeId}.${eventName}`;
69+
this.listeners.set(key, callback);
70+
console.log(`[ViroEventsManager] Registered node event listener: ${key}`);
71+
}
72+
/**
73+
* Register a listener for scene events
74+
* @param {string} sceneId - The scene ID
75+
* @param {string} eventName - The event name
76+
* @param {function} callback - The callback function
77+
*/
78+
registerSceneEventListener(sceneId, eventName, callback) {
79+
const key = `scene.${sceneId}.${eventName}`;
80+
this.listeners.set(key, callback);
81+
console.log(`[ViroEventsManager] Registered scene event listener: ${key}`);
82+
}
83+
/**
84+
* Handle JSI callback events
85+
* @private
86+
*/
87+
handleJSICallback(event) {
88+
const { callbackId, eventData, timestamp } = event;
89+
console.log(`[ViroEventsManager] Received JSI callback: ${callbackId}`, eventData);
90+
const callback = this.callbackRegistry.get(callbackId);
91+
if (callback) {
92+
try {
93+
callback(eventData);
94+
}
95+
catch (error) {
96+
console.error(`[ViroEventsManager] Error executing JSI callback ${callbackId}:`, error);
97+
}
98+
}
99+
else {
100+
console.warn(`[ViroEventsManager] No callback registered for ID: ${callbackId}`);
101+
}
102+
}
103+
/**
104+
* Handle node events
105+
* @private
106+
*/
107+
handleNodeEvent(event) {
108+
const { nodeId, eventName, eventData, timestamp } = event;
109+
const key = `${nodeId}.${eventName}`;
110+
console.log(`[ViroEventsManager] Received node event: ${key}`, eventData);
111+
const callback = this.listeners.get(key);
112+
if (callback) {
113+
try {
114+
callback(eventData);
115+
}
116+
catch (error) {
117+
console.error(`[ViroEventsManager] Error executing node event callback ${key}:`, error);
118+
}
119+
}
120+
}
121+
/**
122+
* Handle scene events
123+
* @private
124+
*/
125+
handleSceneEvent(event) {
126+
const { sceneId, eventName, eventData, timestamp } = event;
127+
const key = `scene.${sceneId}.${eventName}`;
128+
console.log(`[ViroEventsManager] Received scene event: ${key}`, eventData);
129+
const callback = this.listeners.get(key);
130+
if (callback) {
131+
try {
132+
callback(eventData);
133+
}
134+
catch (error) {
135+
console.error(`[ViroEventsManager] Error executing scene event callback ${key}:`, error);
136+
}
137+
}
138+
}
139+
/**
140+
* Check if the event system is ready
141+
* @returns {boolean}
142+
*/
143+
isEventSystemReady() {
144+
try {
145+
return ViroEventsTurboModule_1.default.isEventSystemReady();
146+
}
147+
catch (error) {
148+
console.error("[ViroEventsManager] Error checking event system status:", error);
149+
return false;
150+
}
151+
}
152+
/**
153+
* Get the number of active listeners
154+
* @returns {number}
155+
*/
156+
getActiveListenerCount() {
157+
try {
158+
return ViroEventsTurboModule_1.default.getActiveListenerCount();
159+
}
160+
catch (error) {
161+
console.error("[ViroEventsManager] Error getting listener count:", error);
162+
return 0;
163+
}
164+
}
165+
/**
166+
* Manually emit a JSI callback (for testing)
167+
* @param {string} callbackId - The callback ID
168+
* @param {object} eventData - The event data
169+
*/
170+
emitJSICallback(callbackId, eventData = {}) {
171+
try {
172+
ViroEventsTurboModule_1.default.emitJSICallback(callbackId, eventData);
173+
}
174+
catch (error) {
175+
console.error("[ViroEventsManager] Error emitting JSI callback:", error);
176+
}
177+
}
178+
/**
179+
* Manually emit a node event (for testing)
180+
* @param {string} nodeId - The node ID
181+
* @param {string} eventName - The event name
182+
* @param {object} eventData - The event data
183+
*/
184+
emitNodeEvent(nodeId, eventName, eventData = {}) {
185+
try {
186+
ViroEventsTurboModule_1.default.emitNodeEvent(nodeId, eventName, eventData);
187+
}
188+
catch (error) {
189+
console.error("[ViroEventsManager] Error emitting node event:", error);
190+
}
191+
}
192+
/**
193+
* Manually emit a scene event (for testing)
194+
* @param {string} sceneId - The scene ID
195+
* @param {string} eventName - The event name
196+
* @param {object} eventData - The event data
197+
*/
198+
emitSceneEvent(sceneId, eventName, eventData = {}) {
199+
try {
200+
ViroEventsTurboModule_1.default.emitSceneEvent(sceneId, eventName, eventData);
201+
}
202+
catch (error) {
203+
console.error("[ViroEventsManager] Error emitting scene event:", error);
204+
}
205+
}
206+
/**
207+
* Clean up all listeners and callbacks
208+
*/
209+
cleanup() {
210+
console.log("[ViroEventsManager] Cleaning up event manager");
211+
// Remove all event listeners
212+
this.eventEmitter.removeAllListeners("ViroJSICallback");
213+
this.eventEmitter.removeAllListeners("ViroNodeEvent");
214+
this.eventEmitter.removeAllListeners("ViroSceneEvent");
215+
// Clear registries
216+
this.listeners.clear();
217+
this.callbackRegistry.clear();
218+
console.log("[ViroEventsManager] Event manager cleanup completed");
219+
}
220+
}
221+
// Export singleton instance
222+
exports.default = new ViroEventsManager();

dist/fabric-interop/components/ViroGlobal.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ export interface NativeViroType {
3535
recenterTracking: (nodeId: string) => void;
3636
project: (nodeId: string, point: [number, number, number]) => Promise<[number, number, number]>;
3737
unproject: (nodeId: string, point: [number, number, number]) => Promise<[number, number, number]>;
38-
initialize: () => Promise<boolean>;
38+
initialize: (config?: {
39+
debug?: boolean;
40+
arEnabled?: boolean;
41+
worldAlignment?: string;
42+
}) => Promise<boolean>;
3943
}
4044
export declare function getNativeViro(): NativeViroType | null;
4145
export declare function isNativeViroAvailable(): boolean;

dist/fabric-interop/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ export * from "./components/ViroUtils";
1010
export { generateNodeId, generateCallbackId, handleViroEvent, registerEventListener, unregisterEventListener, initializeViro, createScene, activateScene, deactivateScene, destroyScene, getSceneState, getMemoryStats, performMemoryCleanup, createNode, updateNode, deleteNode, addChild, removeChild, createMaterial, createAnimation, setARPlaneDetection, setARImageTargets, isViroJSIAvailable, type ViroNodeProps, type ViroNodeType, type ViroEventCallback, } from "./NativeViro";
1111
export { executeAnimation as executeNativeAnimation, updateMaterial as updateNativeMaterial, } from "./NativeViro";
1212
export { executeAnimation, updateMaterial } from "./NativeViro";
13+
export { default as ViroEventsManager } from "./ViroEventsManager";
14+
export type { Spec as ViroEventsTurboModuleSpec } from "./specs/ViroEventsTurboModule";

dist/fabric-interop/index.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)