Conversation
|
(Also, I'm currently having trouble convincing Travis/NPM to correctly install the |
|
Updated to use adobe-photoshop/ws#v0.4.31-no-native. |
lib/generator.js
Outdated
There was a problem hiding this comment.
I believe the code in this function that does the Promise wrangling will work. However, I'm not totally sure why the complexity is necessary.
For a given pluginId, why can't we just do the following:
- If
pluginConfig.websocketServerPromiseis defined, just return the promise (regardless of the state of the promise). - If it isn't defined, we need to make a new server. Immediately make a new promise, and assign it to
websocketServerPromise. Kick off the server creation process, and return the (not yet resolved) promise. - If server creation fails, reject the promise, and then
delete pluginConfig.websocketServerPromise. That way, everyone will be notified, and we'll create a new server on the next call tostartWebsocketServer - If server creation succeeds, resolve the promise with the port number (and leave
pluginConfig.websocketServerPromiseset, while synchronously settingpluginConfig.websocketServer). Future calls tostartWebsocketServerwill return this promise. - When stopping a websocketServer, check if we have
pluginConfig.websocketServerPromiseset. If it's set and resolved, just delete it. If it's set but not resolved, reject it and delete it. Also deletepluginConfig.websocketServerand start the shutdown sequence. Continue to use a completely separate promise for notifying when shutdown is complete.
There was a problem hiding this comment.
One more points to make it appear like I understand this problem.
In step 4, the Promise wouldn't be resolved until the config option was updated. It would be rejected if updating the config option failed (and the websocket server would be shut down).
There was a problem hiding this comment.
Yes, I agree the port stuff is unnecessary. I have (what I think is) a better simplification that I'll push.
|
@iwehrman great work! I've tested on mac and win and all appears well. I've reviewed the new code in generator.js thoroughly -- as soon as you have a moment to give me your thoughts on the promise-wrangling in I didn't review the code in the |
|
I rewrote the websocket server control routines. Now they're perfect!? They're different at the very least. Ready for re-review. |
There was a problem hiding this comment.
this is the code of gods.
Websocket RPC infrastructure
|
Documented this in API changes. Someday, we might want a wiki page that discusses how to use this. (For all n, someday we might want a wiki page that discusses how to use n.) |
|
We also still very much need to clean up the node-connection-example repository and pull it into the adobe-photoshop org. |
|
So this should be a replacement for usecase of me, creating my own In my current "generator server + panel frontend" devstack (not yet documented, but I want to do that soon), I'm relying on randomly chosen high port number which is hardcoded in both generator plugin and panel. It would totally fail if the port is already assigned to someone else. It would be cool, if I can "outsource" this port handshake to this API. How would you also create an express server, which I also need? Could this be (or is it already?) more abstract so that I can only get my guaranteed port number for plugin and do my own thing with that and have the ability to tell panel which port was assigned to my plugin so they can connect? |
|
Hey @marekhrabe, Once the Websocket server is started, you can connect to it, define remote functions or events, and execute or handle them using the generator-connection client module. So, for example, your Generator plugin could have a function that starts an express server, and that could be exposed to the client using a remote function definition, which could then be executed by the client in the CEP panel to start the server at the appropriate moment. Here's a simple client example and generator plugin that demonstrates how to use this infrastructure. Both of those repos are a little rough so, again, expect to read some code. Although we've used this infrastructure previously in Brackets, you could well be the first external client for this in Generator. If you actually do dive in, and if have any questions or suggestions, then please let me or @joelrbrandt know! |
|
@iwehrman Thanks for all the links and tips here. The repos are clean enough to be read, I got a lot of knowhow :) Now I see that I implemented similar concept to this RPC, but using simpler approach with // panel - cep
var bridge = new Bridge
bridge.emit('myEvent')
// photoshop backend - generator
var bridge = new Bridge(require('./package.json'), generator)
bridge.on('myEvent', fuction () {
generator.alert('myEvent received')
})I will probably change my implementation from hardcoded port number to random unassigned port, start my express+ws server and use Just one more thing - can you think about better way to get the port number from |
|
@marekhrabe What you're doing sounds perfectly reasonable. I think that And, yes, if you ever get around to cleaning up your bridge enough to post it somewhere, I'd love to take a look! |

This adds Websocket-based RPC infrastructure to Generator. Much of this code originally came from Brackets-shell, but has been refactored and simplified for this use case.
This pull request adds the following methods to the
Generatorobject:Generator.prototype.getCustomOptions- Asynchronously stores a dictionary per-plugin in the Photoshop memory space. Accessible via ExtendScript.Generator.prototype.setCustomOptions- Asynchronously retrieves the aforementioned dictionaries per-plugin.Generator.prototype.startWebsocketServer- Starts the Websocket server per-plugin. The port can either be specified or dyamically assigned.Generator.prototype.stopWebsocketServer- Stops the Websocket server per-plugin.To test:
bower installin thenode-connection-exampledirectoryfile://.../node-connection-example/index.htmlin ChromeThe
node-connection-examplerelies on a hard-coded port number that's shared between the example plugin and the example client code. Eventually the generator-connection repo will be updated so that Photoshop can (by some mechanism) be used as the intermediary to communicate dynamically assigned ports, but it doesn't do that just yet.