Skip to main content

Migration from old TIM API JS to TIM API JS with WebAssembly

The following sections will provide information which changes have to be made to switch from the old TIM API JS solution to the new TIM API JS with WebAssembly. Each section contains an example of the old TIM API JS and one of the new TIM API JS with WebAssembly to directly show the differences.

Ready Initialization​

Below is an example how the TIM API must be initialized to be available.

With the old TIM API JS it was essential to check if the TIM API was available before using it. This could be done with the following check:

    if(timapi == undefined) {
// TIM API not ready
}else{
// Start using TIM API
}

In the new TIM API JS with WebAssembly a callback function is called as soon as the TIM API is ready to be used by the application:

function onTimApiReady() {
// Start using TIM API
}

Class Variable Names​

The naming of class variable names changed slightly:

Old TIM API JS used variables names with a '$'-sign like this:

settings.$connectionIPString = "..."

New TIM API JS with WebAssembly uses variables names like this (if " or ' is not important. JS supports both):

settings.connectionIPString = '...'

Listener Declaration​

The old TIM API JS used a non-OOP like way to create listeners. A DefaultTerminalListener was created and then the respective methods were "replaced":

    var listener = new timapi.DefaultTerminalListener();
listener.terminalStatusChanged = function (_terminal) {
timapi.DefaultTerminalListener.prototype.terminalStatusChanged(_terminal);
// Do stuff
}
listener.connectCompleted = function (_event) {
timapi.DefaultTerminalListener.prototype.connectCompleted(_event);
// Do stuff
}
listener.transactionCompleted = function(_event, _data) {
timapi.DefaultTerminalListener.prototype.transactionCompleted(_event, _data);
// Do stuff
}
The new TIM API JS with WebAssembly uses proper subclassing like this:


class myTerminalListener extends timapi.DefaultTerminalListener {
terminalStatusChanged(terminal) {
super.terminalStatusChanged(terminal);
...
}
requestCompleted(event, data) {
super.requestCompleted(event, data);
...
}
}
## Logging

In the old TIM API JS there was only the possibility to set the logging level but there was no chance to control the logging messages on user application level:


timapi.logging.Log.logLevel = timapi.logging.Level.FINE


This is not existing anymore in WebAssembly. Instead the logger goes to the web console by default but can be intercepted by the user application like this:


onTimApiLog = function(message) {
... // message is of type String
}

Which allows to simply output a final predefined log message.

To further filter the logMessages the "onTimApiPublishLogRecord" function can be used.