@@ -36,40 +36,34 @@ to instantiate the `WidgetApi` class.
3636The general usage for this would be:
3737
3838``` typescript
39- const widgetId = null // if you know the widget ID, supply it.
40- const api = new WidgetApi (widgetId )
39+ const widgetId = null ; // if you know the widget ID, supply it.
40+ const api = new WidgetApi (widgetId );
4141
4242// Before doing anything else, request capabilities:
43- api .requestCapability (MatrixCapabilities .Screenshots )
44- api .requestCapabilities (StickerpickerCapabilities )
43+ api .requestCapability (MatrixCapabilities .Screenshots );
44+ api .requestCapabilities (StickerpickerCapabilities );
4545
4646// Add custom action handlers (if needed)
47- api .on (
48- ` action:${WidgetApiToWidgetAction .UpdateVisibility } ` ,
49- (ev : CustomEvent <IVisibilityActionRequest >) => {
50- ev .preventDefault () // we're handling it, so stop the widget API from doing something.
51- console .log (ev .detail ) // custom handling here
52- api .transport .reply (ev .detail , <IWidgetApiRequestEmptyData >{})
53- },
54- )
55- api .on (
56- " action:com.example.my_action" ,
57- (ev : CustomEvent <ICustomActionRequest >) => {
58- ev .preventDefault () // we're handling it, so stop the widget API from doing something.
59- console .log (ev .detail ) // custom handling here
60- api .transport .reply (ev .detail , { custom: " reply" })
61- },
62- )
47+ api .on (` action:${WidgetApiToWidgetAction .UpdateVisibility } ` , (ev : CustomEvent <IVisibilityActionRequest >) => {
48+ ev .preventDefault (); // we're handling it, so stop the widget API from doing something.
49+ console .log (ev .detail ); // custom handling here
50+ api .transport .reply (ev .detail , <IWidgetApiRequestEmptyData >{});
51+ });
52+ api .on (" action:com.example.my_action" , (ev : CustomEvent <ICustomActionRequest >) => {
53+ ev .preventDefault (); // we're handling it, so stop the widget API from doing something.
54+ console .log (ev .detail ); // custom handling here
55+ api .transport .reply (ev .detail , { custom: " reply" });
56+ });
6357
6458// Start the messaging
65- api .start ()
59+ api .start ();
6660
6761// If waitForIframeLoad is false, tell the client that we're good to go
68- api .sendContentLoaded ()
62+ api .sendContentLoaded ();
6963
7064// Later, do something else (if needed)
71- api .setAlwaysOnScreen (true )
72- api .transport .send (" com.example.my_action" , { isExample: true })
65+ api .setAlwaysOnScreen (true );
66+ api .transport .send (" com.example.my_action" , { isExample: true });
7367```
7468
7569For a more complete example, see the ` examples ` directory of this repo.
@@ -83,17 +77,15 @@ SDK to provide an interface for other platforms.
8377TODO: Improve this
8478
8579``` typescript
86- const driver = new CustomDriver () // an implementation of WidgetDriver
87- const api = new ClientWidgetApi (widget , iframe , driver )
80+ const driver = new CustomDriver (); // an implementation of WidgetDriver
81+ const api = new ClientWidgetApi (widget , iframe , driver );
8882
8983// The API is automatically started, so we just have to wait for a ready before doing something
9084api .on (" ready" , () => {
91- api .updateVisibility (true ).then (() =>
92- console .log (" Widget knows it is visible now" ),
93- )
94- api .transport .send (" com.example.my_action" , { isExample: true })
95- })
85+ api .updateVisibility (true ).then (() => console .log (" Widget knows it is visible now" ));
86+ api .transport .send (" com.example.my_action" , { isExample: true });
87+ });
9688
9789// Eventually, stop the API handling
98- api .stop ()
90+ api .stop ();
9991```
0 commit comments