-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement websocket/send action #484
Conversation
|
||
public TestWebSocketServer(InetSocketAddress address) { | ||
super(address); | ||
// TODO Auto-generated constructor stub |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all TODO comments ... replace with appropriate comments if needed?
a658722
to
e758049
Compare
@@ -52,6 +52,7 @@ swagger-tools@0.8.7 \ | |||
tmp@0.0.28 \ | |||
watson-developer-cloud@1.4.1 \ | |||
when@3.7.3 \ | |||
ws@1.1.0 \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will require updating reference.md
and generating pr to bluemix docs @csantanapr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjustin-ibm go ahead and add the new npm package in both places
e69758f
to
06a6ad3
Compare
@rabbah The code is ready and based on the history of the |
ee9e025
to
d965375
Compare
Thanks @bjustin-ibm - now regretting using bash for installing packages ;) |
var WebSocket = require('ws'); | ||
var ws = new WebSocket(uri); | ||
|
||
ws.on('open', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this exploit a warm action? hmm...
@rabbah about
Should we create an issue in the backlog for switching to a cross-platform scripting languages (i.e. nodejs)? |
val run = wsk.action.invoke(websocketSendAction, Map("uri" -> badURI.toString.toJson, "payload" -> "This is the message to send".toJson)) | ||
withActivation(wsk.activation, run) { | ||
activation => | ||
activation.fields("response").asJsObject.fields("success").toString should be("false") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the success
property is invariably of type boolean hence should check against false.toJson instead (same above line 81).
personal preferences are for Python and to see all bash scripts replaced
some day.
|
c4e5cec
to
d43b4c4
Compare
d43b4c4
to
5a2b311
Compare
IPGA 64 @rabbah I believe this is ready to merge. |
-a description "Utilities for communicating with WebSockets" | ||
|
||
waitForAll | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@starpit please review annotations below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- field-level descriptions, e.g. what does the uri or payload field mean?
"description": "the uri blah..."
- i would guess that we should mark the uri field as bindTime? which means that the package-level metadata needs a "parameters" annotation
[ { "key": "parameters": value: [{ "name": "uri", bindTime: true, required: true } }]
- we don't have an established schema for this yet, but the package also needs these annotations
- service icon
- branding text e.g. "Cloudant", unicode rather than graphical, but encodes whatever preferred capitalization the provider uses, service marks, etc.
- branding icon (optional, e.g. if the service provider has a "Cloudant[TM]" wide-form branding icon)
- link to service provider's home page
- link to service instantiation broker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: separability concerns, yes. we can do 1-2, and the 3 as two separate tasks, but we have to make sure that we don't keep kicking the 3 can down the road.
Are the concerns under separable? That requires systematically addressing all the packages since none have these. Whereas 1-2 strike me as in scope. |
@@ -0,0 +1,29 @@ | |||
#!/bin/bash | |||
# | |||
# use the command line interface to install Weather.com package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weather.com ? must be typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed a copy-and-paste-o. Thanks for catching it.
5a2b311
to
9469552
Compare
|
||
createPackage websocket \ | ||
-a description "Utilities for communicating with WebSockets" | ||
-a parameters '[ {"name":"uri", "required":true, "bindTime":true} ]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@starpit Please verify this is what you were asking for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, @bjustin-ibm awesome, thanks!!
Ok @rabbah... for reals this time 😏 I think this is ready. |
ws.send(payload, function(error) { | ||
if (error) { | ||
console.log("Error received communicating with websocket: " + error); | ||
whisk.error(error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ws.close() on error? (i can add this as i merge if you confirm.)
This creates a new package called websocket Implementation is in Node.JS and required added the ws package to the Node.JS runtime. Added unit tests which confirm that a message can be sent to a WebSocket running on Bluemix, as well as handle various error cases.
9469552
to
78bf8a3
Compare
@bjustin-ibm hiya, do the parameters have any sensitive information? e.g. does the uri contain passwords? |
@starpit Like any action parameters, they contain exactly what the caller puts in them, and so it is not generally predictable whether or not they will contain sensitive information. In terms of websockets, I don't believe it is necessarily true that the URI will include authentication information, though I suppose it could. |
ok cool, thanks for the great summary! does a websocket have any sort of lifecycle, e.g. account registration, credentialing, ...? |
@starpit websocket is only a communication protocol for transferring arbitrary data, and is not specific to any particular application or service. This OW action is only meant to act as a client to send data to a running websocket server, and will not act as a websocket server. To answer your question more directly, things like account registration or credentialing could only be accomplished with how a websocket server interprets the data sent to it by clients, and is not something this OW action would actively facilitate or be responsible for. |
ok thanks @bjustin-ibm as much as possible, i think we'd like to avoid the "hey this is tantalizing and sounds cool, but to use it you'll need to do stuff we don't tell you about". e.g. mobile developer wants a websocket server, see this... after all, whisk is trying to help people avoid setting up servers! maybe we can belay this reaction by naming the package or action ... somehow? |
echo Installing WebSocket package. | ||
|
||
createPackage websocket \ | ||
-a description "Utilities for communicating with WebSockets" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@starpit The "websocket" package only has one action named "send". I think the description of the send action (below) makes it pretty clear that it is intended for talking to a websocket server (as opposed to acting as one). The only potentially ambiguous text I could find is the description on the line above. I intentionally left it generic to allow us to add more actions in the future, but if you have a suggestion for making this more clear, we can certainly consider that.
Apart from that, I can't see how naming the package anything but "websocket" could be an improvement, as this term accurately and succinctly describes the specific kind of communication facilitated by the package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option would be to make this "send" action part of some other package (which? I have no idea) and rename the action to something like "websocketSend". That being said, I believe the option of adding this to an existing package was already discussed in #393.
Rebased and merged as 89f2b01. |
This creates a new package called websocket
Implementation is in Node.JS which required adding the
ws
package to the Node.JS runtime (see #523).Added unit tests which confirm that a message can be sent to a running WebSocket, as well as handle various error cases.