Each platform will 'receive' messages according to their own best practices, the following spec describes everything after the message has been delivered from the clientside JavaScript (deliberately avoiding the platform specifics of how messages arrive)
For example, in Android this would be what happens within a @Javascript
Interface, but on macOS it would be within
the WebKit messaging protocol, etc.
s
be an incoming raw JSON
payloadmsg
be the result of parsing s
into key/value pairs
msg.context
exists and is a string
valuemsg.featureName
exists and is a string
valuemsg.method
exists and is a string
value
context
, featureName
or method
are invalid (not a string, or missing), log an "invalid message" Exception and exit.params
be a reference to msg.params
or a new, empty key/value structureparams
is not a valid key/value structure, log an "invalid params" exception and exit.msg.id
field is absent, then:
msg
as being of type Messaging.NotificationMessagemsg.id
field is present, then:
msg.id
a string value, log an "invalid id" exception if it isn't, and exit.msg
as being of type Messaging.RequestMessageOnce you've completed Step 1), you'll know whether you are dealing with a notification or a request (something you need to respond to). At this point you don't know which feature will attempt the message, you just know the format was correct.
feature
be the result of looking up a feature that matches name msg.featureName
feature
is not found:
msg
was marked as type Request
, return a "feature not found" Error Responsemsg
was marked as type Notification
, optionally log a "feature not found" exception and exithandler
be the result of calling feature.handlerFor(msg.method)
handler
is not found:
msg
was marked as type Request
, return a "method not found" Error Responsemsg
was marked as type Notification
, optionally log a "feature not found" exception and exithandler
with msg.params
msg
was marked as a Messaging.NotificationMessage (via step 1), then:
{}
msg
was marked as a Messaging.RequestMessage, then:
response
be a new instance of Messaging.MessageResponse
msg.context
to response.context
msg.featureName
to response.featureName
msg.id
to response.id
result
be the return value of executing handler(msg.params)
result
is empty, assign result
to an empty key/value structureerror
be a new instance of Messaging.MessageErrorerror.message
error
to response.error
result
to response.result
json
be the string result of converting response
into JSONevent
be a new instance of Messaging.SubscriptionEventevent.context
to the target contextevent.featureName
to the target featureevent.subscriptionName
to the target subscriptionNameparams
be a key/value structure
params
to event.params
json
be the string result of converting event
into JSON