@@ -13,17 +13,33 @@ Client library for connecting to a Furhat skill from a skill GUI
1313## Usage
1414
1515``` js
16- import FurhatGUI from ' furhat-gui'
16+ import FurhatGUI , { Furhat } from ' furhat-gui'
1717
18- FurhatGUI ((furhat ) => {
19- furhat .send ({
20- event_name: ' MyEvent' ,
21- param1: ' MyParam1'
22- })
18+ let furhat: Furhat = null
2319
24- furhat .subscribe (' com.myapp.MyCustomeEvent' , (event ) => {
25- console .log (' recieved event: ' , event .event_name )
20+ function setupSubscriptions () {
21+ furhat .subscribe (' com.myapp.MyCustomEvent' , (event ) => {
22+ console .log (' received event: ' , event .event_name )
23+ })
24+ }
25+
26+ FurhatGUI ()
27+ .then (connection => {
28+ furhat = connection
29+ furhat .onConnectionError ((_connection : WebSocket , ev : globalThis .Event ) => {
30+ console .error (" Error occured while connecting to Furhat skill" )
31+ })
32+ furhat .onConnectionClose (() => {
33+ console .warn (" Connection with Furhat skill has been closed" )
34+ })
35+ setupSubscriptions ()
2636 })
37+ .catch (console .error )
38+
39+ // Later somewhere in the code (after awaiting for the connection promise)
40+ furhat .send ({
41+ event_name: ' MyEvent' ,
42+ param1: ' MyParam1'
2743})
2844```
2945
@@ -40,8 +56,4 @@ FurhatGUI((furhat) => {
4056FurhatGUI Function which sets up a connection to the furhat skill and gives
4157the furhat object to send and recieve events to the skill.
4258
43- ** Parameters**
44-
45- - ` callback ` callback that needs to be triggered when a sucessful connection is established
46-
47- Returns ** any** Promise that will return the promise of the connection
59+ Returns ** any** Promise that will return the promise with a ` Furhat ` obkect
0 commit comments