• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / brs / #213

27 Jan 2025 05:30PM UTC coverage: 86.996% (-2.2%) from 89.205%
#213

push

web-flow
Implemented several improvements to SceneGraph (#87)

* Implemented several improvements to SceneGraph

* Fixed most test cases

* Reduced unnecessary code

* Fixed typo

* Added Warning when trying to create a non-existent Node

* Fixed parser

* Fixed unit tests

* Implemented support for `infoFields`

* Prettier fix

* Simplified execute callback code and matched behavior with Roku

* Adding comment to clarify the exception

2240 of 2807 branches covered (79.8%)

Branch coverage included in aggregate %.

139 of 304 new or added lines in 18 files covered. (45.72%)

2 existing lines in 1 file now uncovered.

6129 of 6813 relevant lines covered (89.96%)

27562.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.0
/src/brsTypes/components/RoDeviceInfo.ts
1
import { BrsValue, ValueKind, BrsString, BrsBoolean, BrsInvalid } from "../BrsType";
143✔
2
import { BrsType, Int32, RoArray, toAssociativeArray } from "..";
143✔
3
import { BrsComponent } from "./BrsComponent";
143✔
4
import { Callable, StdlibArgument } from "../Callable";
143✔
5
import { RoMessagePort } from "./RoMessagePort";
6
import { RoAssociativeArray } from "./RoAssociativeArray";
143✔
7
import { v4 as uuidv4 } from "uuid";
143✔
8

9
export class RoDeviceInfo extends BrsComponent implements BrsValue {
143✔
10
    readonly kind = ValueKind.Object;
58✔
11

12
    private port?: RoMessagePort;
13
    private captionsMode = new BrsString("");
58✔
14
    private captionsOption = new BrsString("");
58✔
15
    private enableAppFocus = BrsBoolean.True;
58✔
16
    private enableScreenSaverExited = BrsBoolean.True;
58✔
17
    private enableLowGeneralMemory = BrsBoolean.True;
58✔
18
    private enableLinkStatus = BrsBoolean.True;
58✔
19
    private enableAudioGuideChanged = BrsBoolean.True;
58✔
20
    private enableCodecCapChanged = BrsBoolean.True;
58✔
21

22
    /** A user-specified locale to use for Brightscript functions. */
23
    private static _locale: string | undefined;
24

25
    constructor() {
26
        super("roDeviceInfo");
58✔
27
        this.registerMethods({
58✔
28
            ifDeviceInfo: [
29
                this.getModel,
30
                this.getModelDisplayName,
31
                this.getModelType,
32
                this.getModelDetails,
33
                this.getFriendlyName,
34
                this.getOSVersion,
35
                this.getVersion,
36
                this.getRIDA,
37
                this.isRIDADisabled,
38
                this.getChannelClientId,
39
                this.getUserCountryCode,
40
                this.getRandomUUID,
41
                this.getTimeZone,
42
                this.hasFeature,
43
                this.getCurrentLocale,
44
                this.getCountryCode,
45
                this.getPreferredCaptionLanguage,
46
                this.timeSinceLastKeyPress,
47
                this.getDrmInfo,
48
                this.getDrmInfoEx,
49
                this.getCaptionsMode,
50
                this.setCaptionsMode,
51
                this.getCaptionsOption,
52
                this.getClockFormat,
53
                this.enableAppFocusEvent,
54
                this.enableScreensaverExitedEvent,
55
                this.enableLowGeneralMemoryEvent,
56
                this.getGeneralMemoryLevel,
57
                this.isStoreDemoMode,
58
                this.getLinkStatus,
59
                this.enableLinkStatusEvent,
60
                this.getConnectionType,
61
                this.getExternalIp,
62
                this.getIPAddrs,
63
                this.getConnectionInfo,
64
                this.getDisplayType,
65
                this.getDisplayMode,
66
                this.getDisplayAspectRatio,
67
                this.getDisplaySize,
68
                this.getVideoMode,
69
                this.getDisplayProperties,
70
                this.getSupportedGraphicsResolutions,
71
                this.canDecodeVideo,
72
                this.getUIResolution,
73
                this.getGraphicsPlatform,
74
                this.enableCodecCapChangedEvent,
75
                this.getAudioOutputChannel,
76
                this.getAudioDecodeInfo,
77
                this.canDecodeAudio,
78
                this.getSoundEffectsVolume,
79
                this.isAudioGuideEnabled,
80
                this.enableAudioGuideChangedEvent,
81
                this.setMessagePort,
82
                this.getMessagePort,
83
            ],
84
        });
85
    }
86

87
    /** Sets the locale for Brightscript functions. */
88
    public static set locale(newLocale: string) {
89
        RoDeviceInfo._locale = newLocale;
2✔
90
    }
91

92
    /**
93
     * Returns the locale for Brightscript functions. If a custom
94
     * locale has been specified, use that. Otherwise, default to the Node process.
95
     */
96
    public static get locale(): string {
97
        return RoDeviceInfo._locale || process.env.LOCALE || "";
13!
98
    }
99

100
    toString(parent?: BrsType): string {
101
        return "<Component: roDeviceInfo>";
1✔
102
    }
103

104
    equalTo(other: BrsType) {
105
        return BrsBoolean.False;
1✔
106
    }
107

108
    private getModel = new Callable("getModel", {
58✔
109
        signature: {
110
            args: [],
111
            returns: ValueKind.String,
112
        },
113
        impl: (_interpreter) => {
114
            return new BrsString("");
4✔
115
        },
116
    });
117

118
    private getModelDisplayName = new Callable("getModelDisplayName", {
58✔
119
        signature: {
120
            args: [],
121
            returns: ValueKind.String,
122
        },
123
        impl: (_interpreter) => {
124
            return new BrsString("");
2✔
125
        },
126
    });
127

128
    private getModelType = new Callable("getModelType", {
58✔
129
        signature: {
130
            args: [],
131
            returns: ValueKind.String,
132
        },
133
        impl: (_interpreter) => {
134
            return new BrsString("");
2✔
135
        },
136
    });
137

138
    private getModelDetails = new Callable("getModelDetails", {
58✔
139
        signature: {
140
            args: [],
141
            returns: ValueKind.Object,
142
        },
143
        impl: (_interpreter) => {
144
            return new RoAssociativeArray([]);
2✔
145
        },
146
    });
147

148
    private getFriendlyName = new Callable("getFriendlyName", {
58✔
149
        signature: {
150
            args: [],
151
            returns: ValueKind.String,
152
        },
153
        impl: (_interpreter) => {
154
            return new BrsString("");
2✔
155
        },
156
    });
157

158
    private getOSVersion = new Callable("getOSVersion", {
58✔
159
        signature: {
160
            args: [],
161
            returns: ValueKind.Object,
162
        },
163
        impl: (_interpreter) => {
164
            return new RoAssociativeArray([]);
2✔
165
        },
166
    });
167

168
    private getVersion = new Callable("getVersion", {
58✔
169
        signature: {
170
            args: [],
171
            returns: ValueKind.String,
172
        },
173
        impl: (_interpreter) => {
174
            return new BrsString("");
2✔
175
        },
176
    });
177

178
    private getRIDA = new Callable("getRIDA", {
58✔
179
        signature: {
180
            args: [],
181
            returns: ValueKind.String,
182
        },
183
        impl: (_interpreter) => {
184
            return new BrsString("");
2✔
185
        },
186
    });
187

188
    private isRIDADisabled = new Callable("isRIDADisabled", {
58✔
189
        signature: {
190
            args: [],
191
            returns: ValueKind.Boolean,
192
        },
193
        impl: (_interpreter) => {
194
            return BrsBoolean.True;
2✔
195
        },
196
    });
197

198
    private getChannelClientId = new Callable("getChannelClientId", {
58✔
199
        signature: {
200
            args: [],
201
            returns: ValueKind.String,
202
        },
203
        impl: (_interpreter) => {
204
            return new BrsString("");
2✔
205
        },
206
    });
207

208
    private getUserCountryCode = new Callable("getUserCountryCode", {
58✔
209
        signature: {
210
            args: [],
211
            returns: ValueKind.String,
212
        },
213
        impl: (_interpreter) => {
214
            return new BrsString(RoDeviceInfo.locale);
3✔
215
        },
216
    });
217

218
    private getRandomUUID = new Callable("getRandomUUID", {
58✔
219
        signature: {
220
            args: [],
221
            returns: ValueKind.String,
222
        },
223
        impl: (_interpreter) => {
224
            let uuid = uuidv4();
2✔
225
            return new BrsString(uuid);
2✔
226
        },
227
    });
228

229
    private getTimeZone = new Callable("getTimeZone", {
58✔
230
        signature: {
231
            args: [],
232
            returns: ValueKind.String,
233
        },
234
        impl: (_interpreter) => {
235
            let timeZone = process.env.TZ;
2✔
236
            return timeZone ? new BrsString(timeZone) : new BrsString("");
2!
237
        },
238
    });
239

240
    private hasFeature = new Callable("hasFeature", {
58✔
241
        signature: {
242
            args: [new StdlibArgument("feature", ValueKind.String)],
243
            returns: ValueKind.Boolean,
244
        },
245
        impl: (_interpreter) => {
246
            return BrsBoolean.False;
2✔
247
        },
248
    });
249

250
    private getCurrentLocale = new Callable("getCurrentLocale", {
58✔
251
        signature: {
252
            args: [],
253
            returns: ValueKind.String,
254
        },
255
        impl: (_interpreter) => {
256
            return new BrsString(RoDeviceInfo.locale);
3✔
257
        },
258
    });
259

260
    private getCountryCode = new Callable("getCountryCode", {
58✔
261
        signature: {
262
            args: [],
263
            returns: ValueKind.String,
264
        },
265
        impl: (_interpreter) => {
266
            return new BrsString(RoDeviceInfo.locale);
3✔
267
        },
268
    });
269

270
    private getPreferredCaptionLanguage = new Callable("getPreferredCaptionLanguage", {
58✔
271
        signature: {
272
            args: [],
273
            returns: ValueKind.String,
274
        },
275
        impl: (_interpreter) => {
276
            return new BrsString("");
2✔
277
        },
278
    });
279

280
    private timeSinceLastKeyPress = new Callable("timeSinceLastKeyPress", {
58✔
281
        signature: {
282
            args: [],
283
            returns: ValueKind.Int32,
284
        },
285
        impl: (_interpreter) => {
286
            return new Int32(0);
2✔
287
        },
288
    });
289

290
    private getDrmInfo = new Callable("getDrmInfo", {
58✔
291
        signature: {
292
            args: [],
293
            returns: ValueKind.Object,
294
        },
295
        impl: (_interpreter) => {
296
            return new RoAssociativeArray([]);
2✔
297
        },
298
    });
299

300
    private getDrmInfoEx = new Callable("getDrmInfoEx", {
58✔
301
        signature: {
302
            args: [],
303
            returns: ValueKind.Object,
304
        },
305
        impl: (_interpreter) => {
306
            return new RoAssociativeArray([]);
2✔
307
        },
308
    });
309

310
    private getCaptionsMode = new Callable("getCaptionsMode", {
58✔
311
        signature: {
312
            args: [],
313
            returns: ValueKind.String,
314
        },
315
        impl: (_interpreter) => {
316
            return this.captionsMode;
2✔
317
        },
318
    });
319

320
    private setCaptionsMode = new Callable("setCaptionsMode", {
58✔
321
        signature: {
322
            args: [new StdlibArgument("mode", ValueKind.String)],
323
            returns: ValueKind.Boolean,
324
        },
325
        impl: (_interpreter, mode: BrsString) => {
326
            this.captionsMode = mode;
3✔
327
            return BrsBoolean.True;
3✔
328
        },
329
    });
330

331
    private getCaptionsOption = new Callable("getCaptionsOption", {
58✔
332
        signature: {
333
            args: [new StdlibArgument("option", ValueKind.String)],
334
            returns: ValueKind.String,
335
        },
336
        impl: (_interpreter, option: BrsString) => {
337
            this.captionsOption = option;
2✔
338
            return this.captionsOption;
2✔
339
        },
340
    });
341

342
    private getClockFormat = new Callable("getClockFormat", {
58✔
343
        signature: {
344
            args: [],
345
            returns: ValueKind.String,
346
        },
347
        impl: (_interpreter) => {
348
            return new BrsString("");
2✔
349
        },
350
    });
351

352
    private enableAppFocusEvent = new Callable("enableAppFocusEvent", {
58✔
353
        signature: {
354
            args: [new StdlibArgument("enable", ValueKind.Boolean)],
355
            returns: ValueKind.Dynamic,
356
        },
357
        impl: (_interpreter, enable: BrsBoolean) => {
358
            this.enableAppFocus = enable;
2✔
359
            return this.enableAppFocus;
2✔
360
        },
361
    });
362

363
    private enableScreensaverExitedEvent = new Callable("enableScreensaverExitedEvent", {
58✔
364
        signature: {
365
            args: [new StdlibArgument("enable", ValueKind.Boolean)],
366
            returns: ValueKind.Dynamic,
367
        },
368
        impl: (_interpreter, enable: BrsBoolean) => {
369
            this.enableScreenSaverExited = enable;
2✔
370
            return this.enableScreenSaverExited;
2✔
371
        },
372
    });
373

374
    private enableLowGeneralMemoryEvent = new Callable("enableLowGeneralMemoryEvent", {
58✔
375
        signature: {
376
            args: [new StdlibArgument("enable", ValueKind.Boolean)],
377
            returns: ValueKind.Dynamic,
378
        },
379
        impl: (_interpreter, enable: BrsBoolean) => {
380
            this.enableLowGeneralMemory = enable;
2✔
381
            return this.enableLowGeneralMemory;
2✔
382
        },
383
    });
384

385
    private getGeneralMemoryLevel = new Callable("getGeneralMemoryLevel", {
58✔
386
        signature: {
387
            args: [],
388
            returns: ValueKind.String,
389
        },
390
        impl: (_interpreter) => {
391
            return new BrsString("");
2✔
392
        },
393
    });
394

395
    private isStoreDemoMode = new Callable("isStoreDemoMode", {
58✔
396
        signature: {
397
            args: [],
398
            returns: ValueKind.Boolean,
399
        },
400
        impl: (_interpreter) => {
401
            return BrsBoolean.False;
2✔
402
        },
403
    });
404

405
    private getLinkStatus = new Callable("getLinkStatus", {
58✔
406
        signature: {
407
            args: [],
408
            returns: ValueKind.Boolean,
409
        },
410
        impl: (_interpreter) => {
411
            return BrsBoolean.True;
2✔
412
        },
413
    });
414

415
    private enableLinkStatusEvent = new Callable("enableLinkStatusEvent", {
58✔
416
        signature: {
417
            args: [new StdlibArgument("enable", ValueKind.Boolean)],
418
            returns: ValueKind.Boolean,
419
        },
420
        impl: (_interpreter, enable: BrsBoolean) => {
421
            this.enableLinkStatus = enable;
2✔
422
            return this.enableLinkStatus;
2✔
423
        },
424
    });
425

426
    private getConnectionType = new Callable("getConnectionType", {
58✔
427
        signature: {
428
            args: [],
429
            returns: ValueKind.String,
430
        },
431
        impl: (_interpreter) => {
432
            return new BrsString("");
2✔
433
        },
434
    });
435

436
    private getExternalIp = new Callable("getExternalIp", {
58✔
437
        signature: {
438
            args: [],
439
            returns: ValueKind.String,
440
        },
441
        impl: (_interpreter) => {
442
            return new BrsString("");
2✔
443
        },
444
    });
445

446
    private getIPAddrs = new Callable("getIPAddrs", {
58✔
447
        signature: {
448
            args: [],
449
            returns: ValueKind.Object,
450
        },
451
        impl: (_interpreter) => {
452
            return new RoAssociativeArray([]);
2✔
453
        },
454
    });
455

456
    private getConnectionInfo = new Callable("getConnectionInfo", {
58✔
457
        signature: {
458
            args: [],
459
            returns: ValueKind.Object,
460
        },
461
        impl: (_interpreter) => {
462
            return new RoAssociativeArray([]);
2✔
463
        },
464
    });
465

466
    private getDisplayType = new Callable("getDisplayType", {
58✔
467
        signature: {
468
            args: [],
469
            returns: ValueKind.String,
470
        },
471
        impl: (_interpreter) => {
472
            return new BrsString("");
2✔
473
        },
474
    });
475

476
    private getDisplayMode = new Callable("getDisplayMode", {
58✔
477
        signature: {
478
            args: [],
479
            returns: ValueKind.String,
480
        },
481
        impl: (_interpreter) => {
482
            return new BrsString("");
2✔
483
        },
484
    });
485

486
    private getDisplayAspectRatio = new Callable("getDisplayAspectRatio", {
58✔
487
        signature: {
488
            args: [],
489
            returns: ValueKind.String,
490
        },
491
        impl: (_interpreter) => {
492
            return new BrsString("");
2✔
493
        },
494
    });
495

496
    private getDisplaySize = new Callable("getDisplaySize", {
58✔
497
        signature: {
498
            args: [],
499
            returns: ValueKind.Object,
500
        },
501
        impl: (_interpreter) => {
502
            return new RoAssociativeArray([]);
2✔
503
        },
504
    });
505

506
    private getVideoMode = new Callable("getVideoMode", {
58✔
507
        signature: {
508
            args: [],
509
            returns: ValueKind.String,
510
        },
511
        impl: (_interpreter) => {
512
            return new BrsString("");
2✔
513
        },
514
    });
515

516
    private getDisplayProperties = new Callable("getDisplayProperties", {
58✔
517
        signature: {
518
            args: [],
519
            returns: ValueKind.Object,
520
        },
521
        impl: (_interpreter) => {
522
            return new RoAssociativeArray([]);
2✔
523
        },
524
    });
525

526
    private getSupportedGraphicsResolutions = new Callable("getSupportedGraphicsResolutions", {
58✔
527
        signature: {
528
            args: [],
529
            returns: ValueKind.Object,
530
        },
531
        impl: (_interpreter) => {
532
            return new RoArray([]);
2✔
533
        },
534
    });
535

536
    private canDecodeVideo = new Callable("canDecodeVideo", {
58✔
537
        signature: {
538
            args: [new StdlibArgument("video_format", ValueKind.Object)],
539
            returns: ValueKind.Object,
540
        },
541
        impl: (_interpreter, videoFormat: ValueKind.Object) => {
542
            return toAssociativeArray({ result: true, codec: "mpeg4 avc" });
3✔
543
        },
544
    });
545

546
    private getUIResolution = new Callable("getUIResolution", {
58✔
547
        signature: {
548
            args: [],
549
            returns: ValueKind.Object,
550
        },
551
        impl: (_interpreter) => {
552
            return new RoAssociativeArray([]);
2✔
553
        },
554
    });
555

556
    private getGraphicsPlatform = new Callable("getGraphicsPlatform", {
58✔
557
        signature: {
558
            args: [],
559
            returns: ValueKind.String,
560
        },
561
        impl: (_interpreter) => {
562
            return new BrsString("");
2✔
563
        },
564
    });
565

566
    private enableCodecCapChangedEvent = new Callable("enableCodecCapChangedEvent", {
58✔
567
        signature: {
568
            args: [new StdlibArgument("enable", ValueKind.Boolean)],
569
            returns: ValueKind.Dynamic,
570
        },
571
        impl: (_interpreter, enable: BrsBoolean) => {
572
            this.enableCodecCapChanged = enable;
2✔
573
            return this.enableCodecCapChanged;
2✔
574
        },
575
    });
576

577
    private getAudioOutputChannel = new Callable("getAudioOutputChannel", {
58✔
578
        signature: {
579
            args: [],
580
            returns: ValueKind.String,
581
        },
582
        impl: (_interpreter) => {
583
            return new BrsString("");
2✔
584
        },
585
    });
586

587
    private getAudioDecodeInfo = new Callable("getAudioDecodeInfo", {
58✔
588
        signature: {
589
            args: [],
590
            returns: ValueKind.Object,
591
        },
592
        impl: (_interpreter) => {
593
            return new RoAssociativeArray([]);
2✔
594
        },
595
    });
596

597
    private canDecodeAudio = new Callable("canDecodeAudio", {
58✔
598
        signature: {
599
            args: [new StdlibArgument("audio_format", ValueKind.Object)],
600
            returns: ValueKind.Object,
601
        },
602
        impl: (_interpreter, audioFormat: ValueKind.Object) => {
603
            return toAssociativeArray({ result: true });
1✔
604
        },
605
    });
606

607
    private getSoundEffectsVolume = new Callable("getSoundEffectsVolume", {
58✔
608
        signature: {
609
            args: [],
610
            returns: ValueKind.Int32,
611
        },
612
        impl: (_interpreter) => {
613
            return new Int32(0);
2✔
614
        },
615
    });
616

617
    private isAudioGuideEnabled = new Callable("isAudioGuideEnabled", {
58✔
618
        signature: {
619
            args: [],
620
            returns: ValueKind.Dynamic,
621
        },
622
        impl: (_interpreter) => {
623
            return new BrsString("");
2✔
624
        },
625
    });
626

627
    private enableAudioGuideChangedEvent = new Callable("enableAudioGuideChangedEvent", {
58✔
628
        signature: {
629
            args: [new StdlibArgument("enable", ValueKind.Boolean)],
630
            returns: ValueKind.Dynamic,
631
        },
632
        impl: (_interpreter, enable: BrsBoolean) => {
633
            this.enableAudioGuideChanged = enable;
2✔
634
            return this.enableAudioGuideChanged;
2✔
635
        },
636
    });
637

638
    private setMessagePort = new Callable("setMessagePort", {
58✔
639
        signature: {
640
            args: [new StdlibArgument("port", ValueKind.Dynamic)],
641
            returns: ValueKind.Void,
642
        },
643
        impl: (_, port: RoMessagePort) => {
NEW
644
            this.port = port;
×
NEW
645
            return BrsInvalid.Instance;
×
646
        },
647
    });
648

649
    private getMessagePort = new Callable("getMessagePort", {
58✔
650
        signature: {
651
            args: [],
652
            returns: ValueKind.Object,
653
        },
654
        impl: (_) => {
NEW
655
            return this.port ?? BrsInvalid.Instance;
×
656
        },
657
    });
658
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc