@kmamal/sdl 0.9.4 → 0.9.6-0
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/README.md +34 -15
- package/binding.gyp +25 -5
- package/package.json +7 -4
- package/src/javascript/audio/audio-instance.js +9 -6
- package/src/javascript/cleanup.js +1 -1
- package/src/javascript/clipboard/index.js +2 -1
- package/src/javascript/controller/controller-instance.js +6 -0
- package/src/javascript/enums.js +1 -1
- package/src/javascript/events/index.js +302 -305
- package/src/javascript/index.js +1 -1
- package/src/javascript/joystick/joystick-instance.js +7 -0
- package/src/javascript/keyboard/index.js +3 -3
- package/src/javascript/keyboard/key-mapping.js +14 -6
- package/src/javascript/mouse/index.js +13 -12
- package/src/javascript/power/index.js +0 -2
- package/src/javascript/sensor/sensor-instance.js +1 -5
- package/src/javascript/video/window.js +17 -16
- package/src/native/audio.cpp +178 -0
- package/src/native/audio.h +21 -0
- package/src/native/clipboard.cpp +45 -0
- package/src/native/clipboard.h +13 -0
- package/src/native/cocoa-global.h +8 -0
- package/src/native/cocoa-global.mm +8 -0
- package/src/native/cocoa-window.h +9 -4
- package/src/native/cocoa-window.mm +6 -9
- package/src/native/controller.cpp +154 -0
- package/src/native/controller.h +17 -0
- package/src/native/enums.cpp +477 -0
- package/src/native/enums.h +67 -0
- package/src/native/events.cpp +339 -0
- package/src/native/events.h +15 -0
- package/src/native/global.cpp +187 -0
- package/src/native/global.h +15 -0
- package/src/native/joystick.cpp +388 -0
- package/src/native/joystick.h +22 -0
- package/src/native/keyboard.cpp +55 -0
- package/src/native/keyboard.h +18 -0
- package/src/native/module.cpp +98 -0
- package/src/native/mouse.cpp +186 -0
- package/src/native/mouse.h +21 -0
- package/src/native/power.cpp +18 -0
- package/src/native/power.h +12 -0
- package/src/native/sensor.cpp +117 -0
- package/src/native/sensor.h +15 -0
- package/src/native/video.cpp +90 -0
- package/src/native/video.h +12 -0
- package/src/native/window.cpp +755 -0
- package/src/native/window.h +29 -0
- package/src/types/index.d.ts +7 -4
- package/scripts/test.mjs +0 -12
- package/src/native/asprintf.c +0 -47
- package/src/native/asprintf.h +0 -37
- package/src/native/binding.cpp +0 -1680
- package/src/native/sdl-helpers.cpp +0 -2619
- package/src/native/sdl-helpers.h +0 -182
|
@@ -69,341 +69,338 @@ const reconcileDevices = (emitter, mainList, currList, compare) => {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
72
|
+
const handleEvent = (event) => {
|
|
73
|
+
const { family, type } = event
|
|
74
|
+
if (family === undefined || type === undefined) { return }
|
|
75
|
+
delete event.family
|
|
76
|
+
event.type = Enums.eventTypeNames[type]
|
|
77
|
+
|
|
78
|
+
switch (family) {
|
|
79
|
+
// TODO: this also needs a reconcile function
|
|
80
|
+
case Enums.eventFamily.display: {
|
|
81
|
+
const { displayIndex } = event
|
|
82
|
+
delete event.displayIndex
|
|
83
|
+
|
|
84
|
+
const oldDisplays = Globals.displays
|
|
85
|
+
Globals.displays = Bindings.video_getDisplays()
|
|
86
|
+
for (const display of Globals.displays) {
|
|
87
|
+
display.format = Enums.pixelFormatNames[display.format]
|
|
88
|
+
}
|
|
89
|
+
const newDisplays = Globals.displays
|
|
90
|
+
|
|
91
|
+
event.display = event.type === Enums.eventType.displayRemove
|
|
92
|
+
? oldDisplays[displayIndex]
|
|
93
|
+
: newDisplays[displayIndex]
|
|
94
|
+
|
|
95
|
+
videoModule.emit(event.type, event)
|
|
96
|
+
} break
|
|
97
|
+
|
|
98
|
+
case Enums.eventFamily.window: {
|
|
99
|
+
const { windowId } = event
|
|
100
|
+
delete event.windowId
|
|
101
|
+
|
|
102
|
+
const window = Globals.windows.all.get(windowId)
|
|
103
|
+
if (!window) { return }
|
|
104
|
+
|
|
105
|
+
switch (type) {
|
|
106
|
+
case Enums.eventType.move: {
|
|
107
|
+
window._x = event.x
|
|
108
|
+
window._y = event.y
|
|
109
|
+
} break
|
|
110
|
+
case Enums.eventType.resize: {
|
|
111
|
+
window._width = event.width
|
|
112
|
+
window._height = event.height
|
|
113
|
+
window._pixelWidth = event.pixelWidth
|
|
114
|
+
window._pixelHeight = event.pixelHeight
|
|
115
|
+
} break
|
|
116
|
+
|
|
117
|
+
case Enums.eventType.show: {
|
|
118
|
+
window._visible = true
|
|
119
|
+
} break
|
|
120
|
+
case Enums.eventType.hide: {
|
|
121
|
+
window._visible = false
|
|
122
|
+
} break
|
|
123
|
+
case Enums.eventType.expose: {
|
|
124
|
+
// Nothing
|
|
125
|
+
} break
|
|
126
|
+
|
|
127
|
+
case Enums.eventType.minimize: {
|
|
128
|
+
window._visible = false
|
|
129
|
+
window._minimized = true
|
|
130
|
+
window._maximized = false
|
|
131
|
+
window._fullscreen = false
|
|
132
|
+
} break
|
|
133
|
+
case Enums.eventType.maximize: {
|
|
134
|
+
window._visible = true
|
|
135
|
+
window._minimized = false
|
|
136
|
+
window._maximized = true
|
|
137
|
+
window._fullscreen = false
|
|
138
|
+
} break
|
|
139
|
+
case Enums.eventType.restore: {
|
|
140
|
+
window._visible = true
|
|
141
|
+
window._minimized = false
|
|
142
|
+
window._maximized = false
|
|
143
|
+
window._fullscreen = false
|
|
144
|
+
} break
|
|
145
|
+
|
|
146
|
+
case Enums.eventType.focus: {
|
|
147
|
+
Globals.windows.focused = window
|
|
148
|
+
} break
|
|
149
|
+
case Enums.eventType.blur: {
|
|
150
|
+
Globals.windows.focused = null
|
|
151
|
+
} break
|
|
152
|
+
|
|
153
|
+
case Enums.eventType.hover: {
|
|
154
|
+
Globals.windows.hovered = window
|
|
155
|
+
} break
|
|
156
|
+
case Enums.eventType.leave: {
|
|
157
|
+
Globals.windows.hovered = null
|
|
158
|
+
} break
|
|
159
|
+
|
|
160
|
+
case Enums.eventType.close: {
|
|
161
|
+
let shouldPrevent = false
|
|
162
|
+
const prevent = () => { shouldPrevent = true }
|
|
163
|
+
const type2 = 'beforeClose'
|
|
164
|
+
const event2 = { type: type2, prevent }
|
|
165
|
+
window.emit(type2, event2)
|
|
166
|
+
if (shouldPrevent) { return }
|
|
167
|
+
} break
|
|
168
|
+
|
|
169
|
+
default: return
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
window.emit(event.type, event)
|
|
173
|
+
} break
|
|
174
|
+
|
|
175
|
+
case Enums.eventFamily.keyboard: {
|
|
176
|
+
const { windowId } = event
|
|
177
|
+
delete event.windowId
|
|
178
|
+
|
|
179
|
+
const window = Globals.windows.all.get(windowId)
|
|
180
|
+
if (!window) { return }
|
|
181
|
+
|
|
182
|
+
const { key } = event
|
|
183
|
+
event.key = mapping[key] ?? (key?.length === 1 ? key : null)
|
|
184
|
+
|
|
185
|
+
window.emit(event.type, event)
|
|
186
|
+
} break
|
|
187
|
+
|
|
188
|
+
case Enums.eventFamily.mouse:
|
|
189
|
+
case Enums.eventFamily.text:
|
|
190
|
+
case Enums.eventFamily.drop: {
|
|
191
|
+
const { windowId } = event
|
|
192
|
+
delete event.windowId
|
|
193
|
+
|
|
194
|
+
const window = Globals.windows.all.get(windowId)
|
|
195
|
+
if (!window) { return }
|
|
196
|
+
|
|
197
|
+
window.emit(event.type, event)
|
|
198
|
+
} break
|
|
199
|
+
|
|
200
|
+
case Enums.eventFamily.joystickDevice: {
|
|
201
|
+
if (type === Enums.eventType.deviceRemove) {
|
|
202
|
+
const { joystickId } = event
|
|
203
|
+
delete event.joystickId
|
|
183
204
|
|
|
184
|
-
|
|
185
|
-
|
|
205
|
+
closeJoysticks: {
|
|
206
|
+
const collection = Globals.joystickInstances.byId.get(joystickId)
|
|
207
|
+
if (!collection) { break closeJoysticks }
|
|
208
|
+
for (const joystickInstance of collection.values()) {
|
|
209
|
+
joystickInstance.close()
|
|
210
|
+
}
|
|
211
|
+
}
|
|
186
212
|
|
|
187
|
-
|
|
188
|
-
|
|
213
|
+
closeControllers: {
|
|
214
|
+
const collection = Globals.controllerInstances.byId.get(joystickId)
|
|
215
|
+
if (!collection) { break closeControllers }
|
|
216
|
+
for (const controllerInstance of collection.values()) {
|
|
217
|
+
controllerInstance.close()
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const { devices: joystickDevices } = event
|
|
223
|
+
delete event.devices
|
|
224
|
+
|
|
225
|
+
const controllerDevices = JSON.parse(JSON.stringify(joystickDevices
|
|
226
|
+
.filter(filterControllerDevice)))
|
|
227
|
+
|
|
228
|
+
for (const joystickDevice of joystickDevices) {
|
|
229
|
+
makeJoystickDevice(joystickDevice)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
for (const controllerDevice of controllerDevices) {
|
|
233
|
+
makeControllerDevice(controllerDevice)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
reconcileDevices(
|
|
237
|
+
joystickModule,
|
|
238
|
+
Globals.joystickDevices,
|
|
239
|
+
joystickDevices,
|
|
240
|
+
compareJoystickDevice,
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
reconcileDevices(
|
|
244
|
+
controllerModule,
|
|
245
|
+
Globals.controllerDevices,
|
|
246
|
+
controllerDevices,
|
|
247
|
+
compareControllerDevice,
|
|
248
|
+
)
|
|
249
|
+
} break
|
|
250
|
+
|
|
251
|
+
case Enums.eventFamily.joystick: {
|
|
252
|
+
const { joystickId } = event
|
|
253
|
+
delete event.joystickId
|
|
254
|
+
|
|
255
|
+
const collection = Globals.joystickInstances.byId.get(joystickId)
|
|
256
|
+
if (!collection) { return }
|
|
257
|
+
|
|
258
|
+
switch (type) {
|
|
259
|
+
case Enums.eventType.axisMotion: {
|
|
260
|
+
for (const joystickInstance of collection) {
|
|
261
|
+
joystickInstance._axes[event.axis] = event.value
|
|
262
|
+
joystickInstance.emit(event.type, event)
|
|
263
|
+
}
|
|
264
|
+
} break
|
|
265
|
+
|
|
266
|
+
case Enums.eventType.ballMotion: {
|
|
267
|
+
for (const joystickInstance of collection) {
|
|
268
|
+
const ball = joystickInstance._balls[event.ball]
|
|
269
|
+
ball.x = event.x
|
|
270
|
+
ball.y = event.y
|
|
271
|
+
joystickInstance.emit(event.type, event)
|
|
272
|
+
}
|
|
273
|
+
} break
|
|
189
274
|
|
|
190
|
-
|
|
191
|
-
|
|
275
|
+
case Enums.eventType.buttonDown: {
|
|
276
|
+
for (const joystickInstance of collection) {
|
|
277
|
+
joystickInstance._buttons[event.button] = true
|
|
278
|
+
joystickInstance.emit(event.type, event)
|
|
279
|
+
}
|
|
280
|
+
} break
|
|
281
|
+
case Enums.eventType.buttonUp: {
|
|
282
|
+
for (const joystickInstance of collection) {
|
|
283
|
+
joystickInstance._buttons[event.button] = false
|
|
284
|
+
joystickInstance.emit(event.type, event)
|
|
285
|
+
}
|
|
286
|
+
} break
|
|
192
287
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
288
|
+
case Enums.eventType.hatMotion: {
|
|
289
|
+
event.value = Enums.hatPositionNames[event.value]
|
|
290
|
+
for (const joystickInstance of collection) {
|
|
291
|
+
joystickInstance._hats[event.hat] = event.value
|
|
292
|
+
joystickInstance.emit(event.type, event)
|
|
293
|
+
}
|
|
294
|
+
} break
|
|
198
295
|
|
|
199
|
-
|
|
200
|
-
|
|
296
|
+
// No default
|
|
297
|
+
}
|
|
298
|
+
} break
|
|
201
299
|
|
|
202
|
-
|
|
203
|
-
}
|
|
300
|
+
case Enums.eventFamily.controller: {
|
|
301
|
+
const { controllerId } = event
|
|
302
|
+
delete event.controllerId
|
|
204
303
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const { joystickId } = event
|
|
208
|
-
delete event.joystickId
|
|
304
|
+
const collection = Globals.controllerInstances.byId.get(controllerId)
|
|
305
|
+
if (!collection) { return }
|
|
209
306
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
307
|
+
switch (type) {
|
|
308
|
+
case Enums.eventType.axisMotion: {
|
|
309
|
+
event.axis = Enums.controllerAxisNames[event.axis]
|
|
310
|
+
for (const controllerInstance of collection.values()) {
|
|
311
|
+
controllerInstance._axes[event.axis] = event.value
|
|
312
|
+
controllerInstance.emit(event.type, event)
|
|
216
313
|
}
|
|
314
|
+
} break
|
|
217
315
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
316
|
+
case Enums.eventType.buttonDown: {
|
|
317
|
+
event.button = Enums.controllerButtonNames[event.button]
|
|
318
|
+
for (const controllerInstance of collection.values()) {
|
|
319
|
+
controllerInstance._axes[event.button] = true
|
|
320
|
+
controllerInstance.emit(event.type, event)
|
|
224
321
|
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const { devices: joystickDevices } = event
|
|
228
|
-
delete event.devices
|
|
322
|
+
} break
|
|
229
323
|
|
|
230
|
-
|
|
231
|
-
.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
324
|
+
case Enums.eventType.buttonUp: {
|
|
325
|
+
event.button = Enums.controllerButtonNames[event.button]
|
|
326
|
+
for (const controllerInstance of collection.values()) {
|
|
327
|
+
controllerInstance._axes[event.button] = true
|
|
328
|
+
controllerInstance.emit(event.type, event)
|
|
329
|
+
}
|
|
330
|
+
} break
|
|
236
331
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
332
|
+
case Enums.eventType.remap: {
|
|
333
|
+
const { axes, buttons } = event
|
|
334
|
+
delete event.axes
|
|
335
|
+
delete event.buttons
|
|
240
336
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
reconcileDevices(
|
|
249
|
-
controllerModule,
|
|
250
|
-
Globals.controllerDevices,
|
|
251
|
-
controllerDevices,
|
|
252
|
-
compareControllerDevice,
|
|
253
|
-
)
|
|
254
|
-
} break
|
|
255
|
-
|
|
256
|
-
case Enums.eventFamily.joystick: {
|
|
257
|
-
const { joystickId } = event
|
|
258
|
-
delete event.joystickId
|
|
337
|
+
for (const controllerInstance of collection.values()) {
|
|
338
|
+
Object.assign(controllerInstance._axes, axes)
|
|
339
|
+
Object.assign(controllerInstance._buttons, buttons)
|
|
340
|
+
controllerInstance.emit(event.type, event)
|
|
341
|
+
}
|
|
342
|
+
} break
|
|
259
343
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
switch (type) {
|
|
264
|
-
case Enums.eventType.axisMotion: {
|
|
265
|
-
for (const joystickInstance of collection) {
|
|
266
|
-
joystickInstance._axes[event.axis] = event.value
|
|
267
|
-
joystickInstance.emit(event.type, event)
|
|
268
|
-
}
|
|
269
|
-
} break
|
|
270
|
-
|
|
271
|
-
case Enums.eventType.ballMotion: {
|
|
272
|
-
for (const joystickInstance of collection) {
|
|
273
|
-
const ball = joystickInstance._balls[event.ball]
|
|
274
|
-
ball.x = event.x
|
|
275
|
-
ball.y = event.y
|
|
276
|
-
joystickInstance.emit(event.type, event)
|
|
277
|
-
}
|
|
278
|
-
} break
|
|
279
|
-
|
|
280
|
-
case Enums.eventType.buttonDown: {
|
|
281
|
-
for (const joystickInstance of collection) {
|
|
282
|
-
joystickInstance._buttons[event.button] = true
|
|
283
|
-
joystickInstance.emit(event.type, event)
|
|
284
|
-
}
|
|
285
|
-
} break
|
|
286
|
-
case Enums.eventType.buttonUp: {
|
|
287
|
-
for (const joystickInstance of collection) {
|
|
288
|
-
joystickInstance._buttons[event.button] = false
|
|
289
|
-
joystickInstance.emit(event.type, event)
|
|
290
|
-
}
|
|
291
|
-
} break
|
|
292
|
-
|
|
293
|
-
case Enums.eventType.hatMotion: {
|
|
294
|
-
event.value = Enums.hatPositionNames[event.value]
|
|
295
|
-
for (const joystickInstance of collection) {
|
|
296
|
-
joystickInstance._hats[event.hat] = event.value
|
|
297
|
-
joystickInstance.emit(event.type, event)
|
|
298
|
-
}
|
|
299
|
-
} break
|
|
300
|
-
|
|
301
|
-
default: continue
|
|
302
|
-
}
|
|
303
|
-
} break
|
|
304
|
-
|
|
305
|
-
case Enums.eventFamily.controller: {
|
|
306
|
-
const { controllerId } = event
|
|
307
|
-
delete event.controllerId
|
|
308
|
-
|
|
309
|
-
const collection = Globals.controllerInstances.byId.get(controllerId)
|
|
310
|
-
if (!collection) { continue }
|
|
311
|
-
|
|
312
|
-
switch (type) {
|
|
313
|
-
case Enums.eventType.axisMotion: {
|
|
314
|
-
event.axis = Enums.controllerAxisNames[event.axis]
|
|
315
|
-
for (const controllerInstance of collection.values()) {
|
|
316
|
-
controllerInstance._axes[event.axis] = event.value
|
|
317
|
-
controllerInstance.emit(event.type, event)
|
|
318
|
-
}
|
|
319
|
-
} break
|
|
320
|
-
|
|
321
|
-
case Enums.eventType.buttonDown: {
|
|
322
|
-
event.button = Enums.controllerButtonNames[event.button]
|
|
323
|
-
for (const controllerInstance of collection.values()) {
|
|
324
|
-
controllerInstance._axes[event.button] = true
|
|
325
|
-
controllerInstance.emit(event.type, event)
|
|
326
|
-
}
|
|
327
|
-
} break
|
|
328
|
-
|
|
329
|
-
case Enums.eventType.buttonUp: {
|
|
330
|
-
event.button = Enums.controllerButtonNames[event.button]
|
|
331
|
-
for (const controllerInstance of collection.values()) {
|
|
332
|
-
controllerInstance._axes[event.button] = true
|
|
333
|
-
controllerInstance.emit(event.type, event)
|
|
334
|
-
}
|
|
335
|
-
} break
|
|
336
|
-
|
|
337
|
-
case Enums.eventType.remap: {
|
|
338
|
-
const { axes, buttons } = event
|
|
339
|
-
delete event.axes
|
|
340
|
-
delete event.buttons
|
|
341
|
-
|
|
342
|
-
for (const controllerInstance of collection.values()) {
|
|
343
|
-
Object.assign(controllerInstance._axes, axes)
|
|
344
|
-
Object.assign(controllerInstance._buttons, buttons)
|
|
345
|
-
controllerInstance.emit(event.type, event)
|
|
346
|
-
}
|
|
347
|
-
} break
|
|
348
|
-
|
|
349
|
-
default: continue
|
|
350
|
-
}
|
|
351
|
-
} break
|
|
344
|
+
// No default
|
|
345
|
+
}
|
|
346
|
+
} break
|
|
352
347
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
348
|
+
case Enums.eventFamily.sensor: {
|
|
349
|
+
const { sensorId } = event
|
|
350
|
+
delete event.sensorId
|
|
356
351
|
|
|
357
|
-
|
|
358
|
-
|
|
352
|
+
const collection = Globals.sensorInstances.byId.get(sensorId)
|
|
353
|
+
if (!collection) { return }
|
|
359
354
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
355
|
+
switch (type) {
|
|
356
|
+
case Enums.eventType.update: {
|
|
357
|
+
for (const sensorInstance of collection.values()) {
|
|
358
|
+
sensorInstance.emit(event.type, event)
|
|
359
|
+
}
|
|
360
|
+
} break
|
|
366
361
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
362
|
+
// No default
|
|
363
|
+
}
|
|
364
|
+
} break
|
|
370
365
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
366
|
+
case Enums.eventFamily.audioDevice: {
|
|
367
|
+
const { isRecorder } = event
|
|
368
|
+
delete event.isRecorder
|
|
374
369
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
370
|
+
if (type === Enums.eventType.deviceRemove) {
|
|
371
|
+
const { audioId } = event
|
|
372
|
+
delete event.audioId
|
|
378
373
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
374
|
+
const audioInstance = Globals.audioInstances.get(audioId)
|
|
375
|
+
if (audioInstance) { audioInstance.close() }
|
|
376
|
+
}
|
|
382
377
|
|
|
383
|
-
|
|
384
|
-
|
|
378
|
+
const { devices: audioDevices } = event
|
|
379
|
+
delete event.devices
|
|
385
380
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
381
|
+
for (const audioDevice of audioDevices) {
|
|
382
|
+
makeAudioDevice(audioDevice)
|
|
383
|
+
}
|
|
389
384
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
385
|
+
reconcileDevices(
|
|
386
|
+
audioModule,
|
|
387
|
+
Globals.audioDevices[isRecorder ? 'recording' : 'playback'],
|
|
388
|
+
audioDevices,
|
|
389
|
+
compareAudioDevice,
|
|
390
|
+
)
|
|
391
|
+
} break
|
|
397
392
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
393
|
+
case Enums.eventFamily.clipboard: {
|
|
394
|
+
clipboardModule.emit(event.type, event)
|
|
395
|
+
} break
|
|
401
396
|
|
|
402
|
-
|
|
403
|
-
}
|
|
397
|
+
// No default
|
|
404
398
|
}
|
|
405
399
|
}
|
|
406
400
|
|
|
401
|
+
|
|
402
|
+
const poll = () => { Bindings.events_poll(handleEvent) }
|
|
403
|
+
|
|
407
404
|
let eventsInterval = null
|
|
408
405
|
|
|
409
406
|
const startPolling = () => {
|
package/src/javascript/index.js
CHANGED
|
@@ -3,7 +3,7 @@ if (!isMainThread) { throw new Error('@kmamal/sdl can only be used in the main t
|
|
|
3
3
|
|
|
4
4
|
const Bindings = require('./bindings')
|
|
5
5
|
|
|
6
|
-
const info = Bindings.
|
|
6
|
+
const info = Bindings.global_initialize()
|
|
7
7
|
|
|
8
8
|
const { video } = require('./video')
|
|
9
9
|
const { keyboard } = require('./keyboard')
|
|
@@ -54,6 +54,7 @@ class JoystickInstance extends EventsViaPoll {
|
|
|
54
54
|
|
|
55
55
|
get power () {
|
|
56
56
|
const power = Bindings.joystick_getPower(this._device.id)
|
|
57
|
+
if (power === null) { return null }
|
|
57
58
|
return Enums.powerLevelNames[power]
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -66,6 +67,12 @@ class JoystickInstance extends EventsViaPoll {
|
|
|
66
67
|
Bindings.joystick_setPlayer(this._device.id, player)
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
resetPlayer () {
|
|
71
|
+
if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._device.id }) }
|
|
72
|
+
|
|
73
|
+
Bindings.joystick_setPlayer(this._device.id, -1)
|
|
74
|
+
}
|
|
75
|
+
|
|
69
76
|
get hasLed () { return this._hasLed }
|
|
70
77
|
setLed (red, green, blue) {
|
|
71
78
|
if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._device.id }) }
|