Widgets: Make a generic postMessage API in WidgetVC

It will be used for https://docs.google.com/document/d/1uPF7XWY_dXTKVKV7jZQ2KmsI19wn9-kFRgQ1tFQP7wQ/edit#.

The Modular postMessage API becomes a specialisation of it.
This commit is contained in:
manuroe
2018-05-07 14:18:24 +02:00
parent 6a04301926
commit b1d7617d05
6 changed files with 276 additions and 209 deletions
@@ -20,6 +20,9 @@
/**
`WidgetViewController` displays widget within a webview.
It also exposes a generic pipe, the postMessage API, to communicate with the
content within the webview, ie the widget (matrix app).
*/
@interface WidgetViewController : WebViewViewController
@@ -31,4 +34,64 @@
*/
- (instancetype)initWithUrl:(NSString*)widgetUrl forWidget:(Widget*)widget;
/**
Display an alert over this controller.
@param error the error to display.
*/
- (void)showErrorAsAlert:(NSError*)error;
#pragma mark - postMessage API
/**
Callback called when the widget make a postMessage API request.
This method can be overidden to implement a specific API between the matrix client
and widget.
@param @TODO
*/
- (void)onMessage:(NSDictionary*)JSData;
/**
Send a boolean response to a request from the widget.
@param response the response to send.
@param @TODO
*/
- (void)sendBoolResponse:(BOOL)response toEvent:(NSDictionary*)eventData;
/**
Send an integer response to a request from the widget.
@param response the response to send.
@param @TODO
*/
- (void)sendIntegerResponse:(NSUInteger)response toEvent:(NSDictionary*)eventData;
/**
Send a serialiable object response to a request the widget.
@param response the response to send.
@param @TODO
*/
- (void)sendNSObjectResponse:(NSObject*)response toEvent:(NSDictionary*)eventData;
/**
Send a message error to a request from the widget.
@param message the error message.
@param @TODO
*/
- (void)sendError:(NSString*)message toEvent:(NSDictionary*)eventData;
/**
Send a localised message error to a request from the widget.
@param errorKey the string id of the message error.
@param @TODO
*/
- (void)sendLocalisedError:(NSString*)errorKey toEvent:(NSDictionary*)eventData;
@end