What are the strings for missing Edit2D events? - autodesk-forge

Below you will find an excerpt from the utodesk documentation for the v7 viewer found here.
There are two event listeners im trying to reference. There is, however, no existing event strings for these. Autodesk.Edit2D.SELECTION_CHANGED and Autodesk.Edit2D.SELECTION_HOVER_CHANGED won't work in my console after the extension is loaded (they just return undefined. Is there a way to find the list of event strings for this extension?
Synchronizing selection
You can also synchronize selection with Edit2D for certain items in your UI using >edit2d.context.selection.
One way to do this is to register a handler. The handler ensures the application is notified if >selection changes.
In the following example, we’ve set the handler to listen for mouse clicks.
// Register your handler
ctx.selection.addEventListener(Autodesk.Edit2D.SELECTION_CHANGED, onSelectionChanged);
Similarly, you can set the handler to synchronize mouse hovering:
// Update UI state on hover changes
ctx.selection.addEventListener(Autodesk.Edit2D.SELECTION_HOVER_CHANGED, onHoverChanged);

You can find the event string for the two event under 'Autodesk.Edit2D.Selection.Events' like below code.
// Register your handler
ctx.selection.addEventListener(Autodesk.Edit2D.Selection.Events.SELECTION_CHANGED, onSelectionChanged);
// Update UI state on hover changes
ctx.selection.addEventListener(Autodesk.Edit2D.Selection.Events.SELECTION_HOVER_CHANGED, onHoverChanged);

Related

TVML resumable player (in tvOS 14)

I have a TVML/TVJS app that presents a document with a number of playable items. Each item is a lockup element with an event handler to launch the built-in media player, very much like in the example project:
https://developer.apple.com/documentation/tvmljs/playing_media_in_a_client-server_app
In the example code, the event handler creates a new Player object from scratch every time it is triggered, but I would like the player to be resumable: when the user exits the player (e.g. with the menu button) and returns by selecting the item again, I would like to resume the player where it left off.
Before, I would do this by creating Player objects for each item already when the document is loaded (including Playlist and MediaItem), and just execute player.select() or player.play() in the event handler. That would work well.
Since tvOS 14, creating all these Player objects when the document loads seems to overload the app (perhaps it already starts fetching all these items from the network). So I no longer create the Player objects beforehand, but I check in the event handler if I already have a Player for the item, and I create it when it's the first time, otherwise I reuse the Player object.
But even though I checked that I reuse the existing Player object, calling play() or present() causes the playback to restart from the beginning. So what would be the appropriate way to obtain a resumable player?

Chrome (open) Shadow DOM Events Not Reaching Host

I'm running Chrome 56.0.x (corporate mandate), along with Polymer 2. My sample component isn't doing anything fancy; just raising a CustomEvent after making a simple AJAX call. I'm setting "bubbles":true and "composed":true, and I can validate that the event is dispatched and that my host is listening for the event properly.
sample-component.html
raiseDataRetrievedEvent() {
this.dispatchEvent(
new CustomEvent('sample-component-data-retrieved', {
bubbles: true,
composed: true,
detail: { data: "loading complete" }
}));
}
However, the events never make it out of the Shadow DOM to my host page listeners.
index.html
// Listen to Custom event from Sample Component
document.querySelector('sample-component').addEventListener('sample-component-data-retrieved', function (e) {
alert(e.detail);
console.log(e.detail);
});
Interestingly enough, when I have a user initiated event (e.g. click) trigger this CustomEvent, it happily makes its way through the Shadow DOM to my listener. It's just the events that are programmatically created that are getting stuck.
UPDATE 1
This issue only seems to manifest itself when I'm serving my site locally (e.g. http://localhost, http://127.0.0.1, http://COMPUTERNAME). When I publish the site to another host, all the events seem to propagate as expected. Feels to me more like a Chrome issue at this point...
UPDATE 2
I put my code out on github here: https://github.com/davidfilkins/polymer-test.
I did some more testing and the results keep getting weirder... when I'm developing / testing in Chrome, I almost always have Dev Tools open. I noticed strangely enough that when my tools are open, that the event isn't captured by the host page (index.html)... but this seems to only happen locally. When I close tools and load the page locally, the events bubble properly... But this is only for the dispatched events that aren’t tied to an explicit user action; those all seem to work regardless of the tools being open or not.
When I access the simple Azure app that I created - http://samplepolymertwo.azurewebsites.net/index.html - all events are bubbled / captured regardless of whether the tools are open.
No clue if this is fixed in more current versions of Chrome or not.
The culprit was all timing...
In Chrome, with Dev Tools open, running on localhost, the event was dispatched from the component before the event listener was wired up on the host page.
Event Timing
I suppose the ideal scenario would be for the web component to wait until the event listener on the host had been wired up before broadcasting the event.

See what file/function deals with a WebSocket?

Is there a way to, possibly using the Chrome DevTools, see in what javascript file or function a WebSocket is handled with?
For instance, I am able to see the frames of the data in the Frames tab, but I am not able to find where they are handled. Is this even possible using only Chrome's DevTools?
I think doing a full-text search of the page source for "onmessage" is the easiest way of doing this.
Other than that, a more accurate method is to overwrite the native WebSocket object and putting in a debugger statement:
var nativeWebSocket = window.WebSocket
window.WebSocket = function(){
debugger
}
Paste this in the console before the WebSocket is created. You can use "Script First Statement" in Event Listener Breakpoints to pause when the page starts loading.
Chrome will pause when the WebSocket object is created, and you can go up the call stack to find the source code that's responsible.
This may be very different from where the onmessage handler is defined. However, you can then put a manual breakpoint on the line that contains new WebSocket, reload the page, and put this code in the console when the breakpoint is hit:
Object.defineProperty(e, "onmessage", {
set: function(){
debugger
}
})
Now the debugger will pause when the onmessage property is set on that WebSocket object.

"busy" state of angular directive

I want to create a directive that displays some data.
At some point I want the directive to signal to the context that is using it that it needs to get some fresh data (e.g. the user pressed some "more" button) I will do this by invoking a bound scope expression "moreClicked".
I assume that when this more button is clicked a round trip to a server will take place until the data to which the directive bound to will update and I would like to display some "busy" indicator until the data actually refreshes.
My Q is what would be a good pattern to implement such functionality?
Would It be true to claim that the directive can not know if it is indeed busy r not and that if it has some ui that represents that such a state it should also have a "busy" attribute that will allow binding and let the user of this directive change this value on its own?
Are there any other alternatives or considerations to make?

HTML: Possible to get keyboard event data without a keyboard event?

In order to get the keyboard state we can listen to "keydown" event but is it possible to interrogate the keyboard without an event? Something like window.keyState.shiftkey?
In 2018 I'm investigating the same thing: (re-)initialisation on acquisition of focus.
Initialisation (determination of system state) is required when the application starts. It is required every time the application recovers focus after losing it to another application, because state like NumLock can change while the application does not have focus.
As the question notes, this information can be obtains from event objects.
There doesn't appear to be any way to request this information.
This requires a change to browsers. In my opinion a low impact solution
for this and parallel situations is a general mechanism for requesting a "null event" of a specified type, eg
var ke = window.requestEvent("keyboard");
var me = window.requestEvent("mouse");
var te = window.requestEvent("haptic");
Since a keyboard/mouse/touch event is not actually occurring, the field that would otherwise quantify the event (key code, mouse position etc) should be null.
This API should not be a breaking change for event handlers, since it doesn't actually trigger an event, it's a function that returns an event object. It's completely new so there is no legacy code, and it can be extended without change simply by defining more event class strings. No new data structures are defined.
If I knew how to submit a change request to the pertinent browser standards committee, this seems to me like a very tight, robust, compatible solution to several problems. I'm recording this here as a sort of message in a bottle, in the hope that one day it will be seen by someone who can act on it.