Klave logo

SCP APIs

This section describes several useful APIs of the SCP class.

Create SCP with logger, connect, test, close and reset

import { Key, SCP } from '@secretarium/connector';
 
async function main() {
 
    // We create the new connector context and provide the console as a logger
    const context = new SCP({logger: console});
    // We create a new connection key or provide an existing one
    const myKey = await Key.createKey()
    // We start the connection to Klave
    const connection = await context.connect('wss://on.klave.network', myKey)
    // Check the connection
    const isConnected = context.isConnected()
    // Check the endpoint
    const endpoint = context.getEndPoint()
    // Close the connection
    context.close()
    // Reset the connection
    context.reset()
}
 
main()

Callbacks onError and onStateChange

import { Key, SCP } from '@secretarium/connector';
 
async function main() {
 
    const context = new SCP();
    context.onStateChange(state => console.log("SCP new state: " + state));
    context.onError(err => console.log("SCP error: " + err))
 
    const myKey = await Key.createKey()
    const connection = await context.connect('wss://on.klave.network', myKey)
}
 
main()

On this page