1.0.16 • Published 6 months ago

@cantoo/cantoo-api v1.0.16

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

cantoo-api

Creating a new connection

To create a new connection with the cantoo api you must call the static method CantooApi.connect(). This method will create an iframe on the provided DOM node and return a new CantooApi instance. Don't forget to call destroy before getting rid of the CantooApi instance.

CantooApi.connect() receives an Object as param. The object should have the following properties:

keytyperequireddescription
domElementHTMLElementrequiredThe DOM element which the iframe will be attached to. It should use display:flex;
userIdstringrequiredThe user id that wants to interact with the api (as received from the GAR)
fileIdstringoptionalThe file id that is going to be edited (as received in the "ready" and "completed" events)
titlestringoptionalThe title of the file that will be created. Should not be set if fileId is set
idEntstringrequiredThe idEnt as received from the GAR
uaistringrequiredThe UAI as received from the GAR
env'prod' \| 'preprod' \| 'develop'requiredThe environment that the client will connect to
readOnlybooleanrequiredShould the user be able to edit the file, or is it only a viewer?
const api = await CantooAPI.connect({domElement, env: 'develop', idEnt: '1', uai: '2', userId: '10', fileId: '10', readOnly: true})

The CantooApi instance

Once the connection is done you can interact with the cantoo api through the following methods:

nametypedescription
loadDocument(id: string, readOnly?: boolean \| undefined) => Promise<void>Loads a new document on the Iframe
addEventListener(eventName: 'ready', callback: (event: { id: string, userId: string, fileId: string }) => void) => voidAdds a new listener to the 'ready' event
addEventListener(eventName: 'completed', callback: (event: { id: string, title: string, userId: string }) => void) => voidAdds a new listener to the 'completed' event
addEventListener(eventName: 'destroyed', callback: () => void) => voidAdds a new listener to the 'destroyed' event
addEventListener(eventName: 'logout', callback: (event: { id: string, userId: string }) => void) => voidAdds a new listener to the 'logout' event
removeEventListener(eventName: 'ready\|completed\|destroyed\|logout', callback) => voidRemoves a listener that is attached to some event. The callback is the function instance that was previously added to the listener
destroy() => voidCloses the connection with the api. This function also removes all listeners and call the listerners that were attached to the 'destroyed' event

The connection state

The CantooApi holds the connection state on the readOnly attribute state.

There are 4 possible states:

namedescription
launchingThe iframe was attached to the DOM and is loading its content
readyThe document id is ready for edition
completedThe document id has been created and can be retrieved or shared
destroyedThe iframe was destroyed and detached
1.0.16

6 months ago

1.0.15

7 months ago

1.0.14

8 months ago

1.0.13

9 months ago

1.0.12

11 months ago

1.0.9

12 months ago

1.0.11

12 months ago

1.0.10

12 months ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

2 years ago