This library is used at least for the following adapters:
const TTL_SEC = 3600;
const SocketAdmin = require('@iobroker/socket-classes').SocketAdmin;
const ws = require('@iobroker/ws-server');
const session = require('express-session');
const utils = require('@iobroker/adapter-core'); // Get common adapter utils
const AdapterStore = require(utils.controllerDir + '/lib/session.js')(session, TTL_SEC);
const store = new AdapterStore({adapter});
const io = new SocketAdmin(adapter.config, adapter, objects);
io.start(
server,
ws,
{
userKey: 'connect.sid',
store,
secret: adapter.config.secret
}
);
// subscribe on all object changes
io.subscribe('objectChange', '*');
// later
io.close();
const TTL_SEC = 3600;
const ws = require('@iobroker/ws-server');
const SocketWS = require('@iobroker/socket-classes').SocketCommon;
const session = require('express-session');
const utils = require('@iobroker/adapter-core'); // Get common adapter utils
const AdapterStore = require(utils.controllerDir + '/lib/session.js')(session, TTL_SEC);
const store = new AdapterStore({adapter});
const settings = adapter.config;
settings.crossDomain = true;
settings.ttl = settings.ttl || TTL_SEC;
const io = new SocketWS(settings, adapter);
io.start(server.server, ws, {userKey: 'connect.sid', checkUser, store, secret: adapter.config.secret});
// later
io.close();
GUI client can send to desired instance the subscribe
message
socket.emit('clientSubscribe', 'cameras.0', 'startCamera', { width: 640, height: 480 }, result => console.log('Started: ' + result));
The instance 'cameras.0' will receive message clientSubscribe
with information who want to receive messages.
adapter.on('message', obj => {
if (obj?.command === 'clientSubscribe') {
if (obj?.message.type && obj.message.type.startsWith('startCamera/')) {
const [, camera] = obj.message.type.split('/');
// start camera with obj.message.data
// ...
// inform GUI that camera is started
adapter.sendTo(obj.from, obj.command, {result: true}, obj.callback);
this.subscribes = this.subscribes || [];
this.subscribes.push({sid: obj.message.sid, from: obj.from, type: obj.message.type, camera});
}
} else if (obj?.command === 'clientUnsubscribe' || obj?.command === 'clientSubscribeError') {
if (obj?.message.type && obj.message.type.startsWith('startCamera/')) {
const [, camera] = obj.message.type.split('/');
if (this.subscribes) {
const pos = this.subscribes.findIndex(s => s.sid === obj.message.sid && s.from === obj.from && s.type === obj.message.type);
if (pos !== -1) {
this.subscribes.splice(pos, 1);
// stop camera
// ...
}
}
}
}
});
and after that client will receive messages from instance
function sendImage(camera, data) {
this.subscribes.forEach(it => {
if (it.camera !== camera) {
return;
}
// send image to GUI
adapter.sendTo(it.from, 'im', {m: it.type, s: it.sid, d: data});
});
}
authenticate
error
log
checkFeatureSupported
getHistory
httpGet
sendTo
sendToHost
authEnabled
logout
listPermissions
getUserPermissions
getVersion
getAdapterName
clientSubscribe
clientUnsubscribe
getAdapterInstances
getObject
getObjects
subscribeObjects
unsubscribeObjects
getObjectView
setObject
delObject
getStates
getForeignStates
getState
setState
getBinaryState
setBinaryState
subscribe
subscribeStates
unsubscribe
unsubscribeStates
readFile
readFile64
writeFile64
writeFile
unlink
deleteFile
deleteFolder
renameFile
rename
mkdir
readDir
chmodFile
chownFile
fileExists
subscribeFiles
unsubscribeFiles
Wait till the user is authenticated. As the user authenticates himself, the callback will be called
callback
(isUserAuthenticated: boolean, isAuthenticationUsed: boolean) => void) => void: Callback(isUserAuthenticated: boolean, isAuthenticationUsed: boolean) => void
Write error into ioBroker log
error
Error | string: Error object or error text
Write log entry into ioBroker log
text
string: log textlevel
ioBroker.LogLevel: one of['silly', 'debug', 'info', 'warn', 'error']
. Default is 'debug'.
Check if the same feature is supported by the current js-controller
feature
SupportedFeature: feature name likeCONTROLLER_LICENSE_MANAGER
callback
(error: string | Error | null | undefined, isSupported?: boolean) => void) => void: callback(error: string | Error | null | undefined, isSupported: boolean) => void
Get history data from specific instance
id
string: object IDoptions
ioBroker.GetHistoryOptions: History optionscallback
(error: string | Error | null | undefined, result: ioBroker.GetHistoryResult) => void) => void: callback(error: string | Error | null | undefined, result: ioBroker.GetHistoryResult) => void
Read content of HTTP(s) page server-side (without CORS and stuff)
url
string: Page URLcallback
(error: Error | null | undefined | string, result?: {status: number; statusText: string}, data?: string) => void: callback(error: Error | null, result?: { status: number; statusText: string }, data?: string) => void
Send the message to specific instance
adapterInstance
string: instance name, e.g.history.0
command
string: command namemessage
any: the message is instance-dependentcallback
(result: any) => void) => void: callback(result: any) => void
Send a message to the specific host.
Host can answer to the following commands: cmdExec, getRepository, getInstalled, getInstalledAdapter, getVersion, getDiagData, getLocationOnDisk, getDevList, getLogs, getHostInfo, delLogs, readDirAsZip, writeDirAsZip, readObjectsAsZip, writeObjectsAsZip, checkLogging, updateMultihost
.
host
string: Host name. With or without 'system.host.' prefixcommand
* 'shell' | 'cmdExec' | 'getRepository' | 'getInstalled' | 'getInstalledAdapter' | 'getVersion' | 'getDiagData' | 'getLocationOnDisk' | 'getDevList' | 'getLogs' | 'getLogFile' | 'getLogFiles' | 'getHostInfo' | 'getHostInfoShort' | 'delLogs' | 'readDirAsZip' | 'writeDirAsZip' | 'readObjectsAsZip' | 'writeObjectsAsZip' | 'checkLogging' | 'updateMultihost' | 'upgradeController' | 'upgradeAdapterWithWebserver' | 'getInterfaces' | 'upload' | 'rebuildAdapter' | 'readBaseSettings' | 'writeBaseSettings' | 'addNotification' | 'clearNotifications' | 'getNotifications' | 'updateLicenses' | 'upgradeOsPackages' | 'restartController' | 'sendToSentry'*: Host commandmessage
any: the message is command-specificcallback
(result: {error?: string; result?: any}) => void) => void: callback(result: { error?: string; result?: any }) => void
Ask server is authentication enabled, and if the user authenticated
callback
(isUserAuthenticated: boolean | Error | string, isAuthenticationUsed: boolean) => void) => void: callback(isUserAuthenticated: boolean | Error | string, isAuthenticationUsed: boolean) => void
Logout user
callback
ioBroker.ErrorCallback: callback(error?: Error) => void
List commands and permissions
callback
(permissions: Record< string, {type: 'object' | 'state' | 'users' | 'other' | 'file' | ''; operation: SocketOperation} >) => void: callback(permissions: Record<string, { type: 'object' | 'state' | 'users' | 'other' | 'file' | ''; operation: SocketOperation }>) => void
Get user permissions
callback
(error: string | null | undefined, userPermissions?: SocketACL | null) => void) => void: callback(error: string | null | undefined, userPermissions?: SocketACL | null) => void
Get the adapter version. Not the socket-classes version!
callback
(error: string | Error | null | undefined, version: string | undefined, adapterName: string) => void: callback(error: string | Error | null | undefined, version: string | undefined, adapterName: string) => void
Get adapter name: "iobroker.ws", "iobroker.socketio", "iobroker.web", "iobroker.admin"
callback
(error: string | Error | null | undefined, adapterName: string) => void) => void: callback(error: string | Error | null | undefined, version: string | undefined, adapterName: string) => void
Client subscribes to specific instance's messages. Client informs specific instance about subscription on its messages. After subscription, the socket will receive "im" messages from desired instance The target instance MUST acknowledge the subscription and return result
targetInstance
string: Instance name, e.g., 'cameras.0'messageType
string: Message type, e.g., 'startRecording/cam1'data
any: Optional data object, e.g., {width: 640, height: 480}callback
(error: string | null | Error | undefined, result?: {accepted: boolean; heartbeat?: number; error?: string}) => void: Callback(error: string | null, result?:{ accepted: boolean; heartbeat?: number; error?: string; }) => void
Client unsubscribes from specific instance's messages. The target instance MUST NOT acknowledge the un-subscription
targetInstance
string: Instance name, e.g., 'cameras.0'messageType
string: Message type, e.g., 'startRecording/cam1'callback
(error: string | null | Error | undefined) => void) => void: Callback(error: string | null) => void
Read all instances of the given adapter, or all instances of all adapters if adapterName is not defined
adapterName
string | undefined: adapter name, e.g.history
. To get all instances of all adapters just place here "".callback
(error: null | undefined | Error | string, instanceList?: ioBroker.InstanceObject[]) => void) => void: callback(error: null | undefined | Error | string, instanceList?: ioBroker.InstanceObject[]) => void
Get one object.
id
string: Object IDcallback
(error: Error | undefined | string | null, obj?: ioBroker.Object) => void) => void: Callback(error: string | null, obj?: ioBroker.Object) => void
Get all objects that are relevant for web: all states and enums with rooms. This is non-admin version of "all objects" and will be overloaded in admin
list
string[] | null: Optional list of IDscallback
(error: Error | undefined | string | null, objs?: Record<string, ioBroker.Object>) => void) => void: Callback(error: string | null, objs?: Record<string, ioBroker.Object>) => void
Subscribe to object changes by pattern. The events will come as 'objectChange' events to the socket.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of IDs like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: Error | undefined | string | null) => void) => void: Callback(error: string | null) => void
Unsubscribe from object changes by pattern.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of IDs like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: string | null | Error | undefined) => void) => void: Callback(error: string | null) => void
Get a view of objects. Make a query to the object database.
design
string: Design name, e.g., 'system' or other designs likecustom
, but it must exist object_design/custom
. To 99,9% usesystem
.search
string: Search name, object type, likestate
,instance
,adapter
,host
, ...params
{startkey?: string; endkey?: string; depth?: number}: Parameters for the query, e.g.,{startkey: 'system.adapter.', endkey: 'system.adapter.\u9999', depth?: number}
callback
(error: string | null | Error | undefined, result?: {rows: {id: string; value: ioBroker.Object & {virtual: boolean; hasChildren: number;};}[];}) => void: Callback(error: string | null, result?: { rows: Array<GetObjectViewItem> }) => void
Set an object.
id
string: Object IDobj
ioBroker.Object: Object to setcallback
(error: string | null | Error | undefined) => void) => void: Callback(error: string | null) => void
Delete an object. Only deletion of flot and fullcalendar objects is allowed
id
string: Object ID, like 'flot.0.myChart'_options
any: Options for deletion. Ignoredcallback
(error: string | null | Error | undefined) => void) => void: Callback(error: string | null) => void
Get states by pattern of current adapter
pattern
string | string[] | undefined: optional pattern, likesystem.adapter.*
or array of state IDs. If the pattern is omitted, you will get ALL states of current adaptercallback
(error: null | undefined | Error | string, states?: Record<string, ioBroker.State>) => void) => void: callback(error: null | undefined | Error | string, states?: Record<string, ioBroker.State>) => void
Same as getStates
pattern
string | string[]: pattern likesystem.adapter.*
or array of state IDscallback
(error: null | undefined | Error | string, states?: Record<string, ioBroker.State>) => void) => void: callback(error: null | undefined | Error | string, states?: Record<string, ioBroker.State>) => void
Get a state by ID
id
string: State ID, e.g.system.adapter.admin.0.memRss
callback
(error: null | undefined | Error | string, state?: ioBroker.State) => void) => void: Callback(error: null | undefined | Error | string, state?: ioBroker.State) => void
Set a state by ID
id
string: State ID, e.g.system.adapter.admin.0.memRss
state
ioBroker.SettableState: State value or object, e.g.{val: 123, ack: true}
callback
(error: null | undefined | Error | string, state?: ioBroker.State) => void) => void: Callback(error: null | undefined | Error | string, state?: ioBroker.State) => void
Get a binary state by ID
id
string: State ID, e.g.javascript.0.binary
callback
(error: null | undefined | Error | string, base64?: string) => void) => void: Callback(error: null | undefined | Error | string, base64?: string) => void
Set a binary state by ID
id
string: State ID, e.g.javascript.0.binary
_base64
string: State value as base64 string. Binary states have no acknowledged flag.callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Subscribe to state changes by pattern. The events will come as 'stateChange' events to the socket.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of states like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: string | null) => void) => void: Callback(error: string | null) => void
Subscribe to state changes by pattern. Same as subscribe
.
The events will come as 'stateChange' events to the socket.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of states like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: string | null) => void) => void: Callback(error: string | null) => void
Unsubscribe from state changes by pattern.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of states like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: string | null) => void) => void: Callback(error: string | null) => void
Unsubscribe from state changes by pattern. Same as unsubscribe
.
The events will come as 'stateChange' events to the socket.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of states like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: string | null) => void) => void: Callback(error: string | null) => void
Read a file from ioBroker DB
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
callback
(error: null | undefined | Error | string, data: Buffer | string, mimeType: string) => void) => void: Callback(error: null | undefined | Error | string, data: Buffer | string, mimeType: string) => void
Read a file from ioBroker DB as base64 string
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
callback
(error: null | undefined | Error | string, base64?: string, mimeType?: string) => void) => void: Callback(error: null | undefined | Error | string, base64: string, mimeType: string) => void
Write a file into ioBroker DB as base64 string
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
data64
string: file content as base64 stringoptions
{mode?: number} | ((error: null | undefined | Error | string) => void): optional{mode: 0x0644}
callback?
(error: null | undefined | Error | string) => void: Callback(error: null | undefined | Error | string) => void
Write a file into ioBroker DB as text This function is overloaded in admin (because admin accepts only base64)
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
data
string: file content as textoptions
{mode?: number} | ((error: null | undefined | Error | string) => void): optional{mode: 0x0644}
callback?
(error: null | undefined | Error | string) => void: Callback(error: null | undefined | Error | string) => void
Delete file in ioBroker DB
adapter
string: instance name, e.g.vis.0
name
string: file name, e.g.main/vis-views.json
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Delete a file in ioBroker DB (same as "unlink", but only for files)
adapter
string: instance name, e.g.vis.0
name
string: file name, e.g.main/vis-views.json
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Delete folder in ioBroker DB (same as unlink
, but only for folders)
adapter
string: instance name, e.g.vis.0
name
string: folder name, e.g.main
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Rename a file in ioBroker DB
adapter
string: instance name, e.g.vis.0
oldName
string: current file name, e.g.main/vis-views.json
newName
string: new file name, e.g.main/vis-views-new.json
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Rename file or folder in ioBroker DB
adapter
string: instance name, e.g.vis.0
oldName
string: current file name, e.g.main/vis-views.json
newName
string: new file name, e.g.main/vis-views-new.json
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Create a folder in ioBroker DB
adapter
string: instance name, e.g.vis.0
dirName
string: desired folder name, e.g.main
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Read content of folder in ioBroker DB
adapter
string: instance name, e.g.vis.0
dirName
string: folder name, e.g.main
options
object | ((error: null | undefined | Error | string, files: ioBroker.ReadDirResult[]) => void): for future usecallback?
(error: null | undefined | Error | string, files: ioBroker.ReadDirResult[]) => void: Callback(error: null | undefined | Error | string, files: Array<{file: string, isDir: boolean, stats: {size: number}, modifiedAt: number, acl: {owner: string, ownerGroup: string, permissions: number, read: boolean, write: boolean}}>) => void
Change a file mode in ioBroker DB
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
options
{mode?: number}: options{mode: 0x644}
callback?
(error: string | Error | null | undefined) => void: Callback(error: string | Error | null | undefined) => void
Change file owner in ioBroker DB
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
options
{owner:system.user.${string}
; ownerGroup?:system.group.${string}
}: options{owner: 'system.user.user', ownerGroup: 'system.group.administrator'}
orsystem.user.user
. If ownerGroup is not defined, it will be taken from owner.callback?
(error: null | undefined | Error | string) => void: Callback(error: null | undefined | Error | string) => void
Check if the file or folder exists in ioBroker DB
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
callback
(error: null | undefined | Error | string, exists?: boolean) => void) => void: Callback(error: null | undefined | Error | string, exists?: boolean) => void
Subscribe to file changes in ioBroker DB
id
string: instance name, e.g.vis.0
or any object ID of typemeta
.id
could have wildcards*
too.pattern
string | string[]: file name pattern, e.g.main/*.json
or array of namescallback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Unsubscribe from file changes in ioBroker DB
id
string: instance name, e.g.vis.0
or any object ID of typemeta
.id
could have wildcards*
too.pattern
string | string[]: file name pattern, e.g.main/*.json
or array of namescallback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
authenticate
error
log
checkFeatureSupported
getHistory
httpGet
sendTo
sendToHost
authEnabled
logout
listPermissions
getUserPermissions
getVersion
getAdapterName
clientSubscribe
clientUnsubscribe
getAdapterInstances
getHostByIp
requireLog
readLogs
cmdExec
eventsThreshold
getRatings
getCurrentInstance
decrypt
encrypt
getIsEasyModeStrict
getEasyMode
getAdapters
updateLicenses
getCompactInstances
getCompactAdapters
getCompactInstalled
getCompactSystemConfig
getCompactSystemRepositories
getCompactRepository
getCompactHosts
delState
getStates
getForeignStates
getState
setState
getBinaryState
setBinaryState
subscribe
subscribeStates
unsubscribe
unsubscribeStates
addUser
delUser
addGroup
delGroup
changePassword
getObject
getObjects
subscribeObjects
unsubscribeObjects
getObjectView
setObject
delObject
getAllObjects
extendObject
getForeignObjects
delObjects
readFile
readFile64
writeFile64
writeFile
unlink
deleteFile
deleteFolder
renameFile
rename
mkdir
readDir
chmodFile
chownFile
fileExists
subscribeFiles
unsubscribeFiles
Wait till the user is authenticated. As the user authenticates himself, the callback will be called
callback
(isUserAuthenticated: boolean, isAuthenticationUsed: boolean) => void) => void: Callback(isUserAuthenticated: boolean, isAuthenticationUsed: boolean) => void
Write error into ioBroker log
error
Error | string: Error object or error text
Write log entry into ioBroker log
text
string: log textlevel
ioBroker.LogLevel: one of['silly', 'debug', 'info', 'warn', 'error']
. Default is 'debug'.
Check if the same feature is supported by the current js-controller
feature
SupportedFeature: feature name likeCONTROLLER_LICENSE_MANAGER
callback
(error: string | Error | null | undefined, isSupported?: boolean) => void) => void: callback(error: string | Error | null | undefined, isSupported: boolean) => void
Get history data from specific instance
id
string: object IDoptions
ioBroker.GetHistoryOptions: History optionscallback
(error: string | Error | null | undefined, result: ioBroker.GetHistoryResult) => void) => void: callback(error: string | Error | null | undefined, result: ioBroker.GetHistoryResult) => void
Read content of HTTP(s) page server-side (without CORS and stuff)
url
string: Page URLcallback
(error: Error | null | undefined | string, result?: {status: number; statusText: string}, data?: string) => void: callback(error: Error | null, result?: { status: number; statusText: string }, data?: string) => void
Send the message to specific instance
adapterInstance
string: instance name, e.g.history.0
command
string: command namemessage
any: the message is instance-dependentcallback
(result: any) => void) => void: callback(result: any) => void
Send a message to the specific host.
Host can answer to the following commands: cmdExec, getRepository, getInstalled, getInstalledAdapter, getVersion, getDiagData, getLocationOnDisk, getDevList, getLogs, getHostInfo, delLogs, readDirAsZip, writeDirAsZip, readObjectsAsZip, writeObjectsAsZip, checkLogging, updateMultihost
.
host
string: Host name. With or without 'system.host.' prefixcommand
* 'shell' | 'cmdExec' | 'getRepository' | 'getInstalled' | 'getInstalledAdapter' | 'getVersion' | 'getDiagData' | 'getLocationOnDisk' | 'getDevList' | 'getLogs' | 'getLogFile' | 'getLogFiles' | 'getHostInfo' | 'getHostInfoShort' | 'delLogs' | 'readDirAsZip' | 'writeDirAsZip' | 'readObjectsAsZip' | 'writeObjectsAsZip' | 'checkLogging' | 'updateMultihost' | 'upgradeController' | 'upgradeAdapterWithWebserver' | 'getInterfaces' | 'upload' | 'rebuildAdapter' | 'readBaseSettings' | 'writeBaseSettings' | 'addNotification' | 'clearNotifications' | 'getNotifications' | 'updateLicenses' | 'upgradeOsPackages' | 'restartController' | 'sendToSentry'*: Host commandmessage
any: the message is command-specificcallback
(result: {error?: string; result?: any}) => void) => void: callback(result: { error?: string; result?: any }) => void
Ask server is authentication enabled, and if the user authenticated
callback
(isUserAuthenticated: boolean | Error | string, isAuthenticationUsed: boolean) => void) => void: callback(isUserAuthenticated: boolean | Error | string, isAuthenticationUsed: boolean) => void
Logout user
callback
ioBroker.ErrorCallback: callback(error?: Error) => void
List commands and permissions
callback
(permissions: Record< string, {type: 'object' | 'state' | 'users' | 'other' | 'file' | ''; operation: SocketOperation} >) => void: callback(permissions: Record<string, { type: 'object' | 'state' | 'users' | 'other' | 'file' | ''; operation: SocketOperation }>) => void
Get user permissions
callback
(error: string | null | undefined, userPermissions?: SocketACL | null) => void) => void: callback(error: string | null | undefined, userPermissions?: SocketACL | null) => void
Get the adapter version. Not the socket-classes version!
callback
(error: string | Error | null | undefined, version: string | undefined, adapterName: string) => void: callback(error: string | Error | null | undefined, version: string | undefined, adapterName: string) => void
Get adapter name: "iobroker.ws", "iobroker.socketio", "iobroker.web", "iobroker.admin"
callback
(error: string | Error | null | undefined, adapterName: string) => void) => void: callback(error: string | Error | null | undefined, version: string | undefined, adapterName: string) => void
Client subscribes to specific instance's messages. Client informs specific instance about subscription on its messages. After subscription, the socket will receive "im" messages from desired instance The target instance MUST acknowledge the subscription and return result
targetInstance
string: Instance name, e.g., 'cameras.0'messageType
string: Message type, e.g., 'startRecording/cam1'data
any: Optional data object, e.g., {width: 640, height: 480}callback
(error: string | null | Error | undefined, result?: {accepted: boolean; heartbeat?: number; error?: string}) => void: Callback(error: string | null, result?:{ accepted: boolean; heartbeat?: number; error?: string; }) => void
Client unsubscribes from specific instance's messages. The target instance MUST NOT acknowledge the un-subscription
targetInstance
string: Instance name, e.g., 'cameras.0'messageType
string: Message type, e.g., 'startRecording/cam1'callback
(error: string | null | Error | undefined) => void) => void: Callback(error: string | null) => void
Read all instances of the given adapter, or all instances of all adapters if adapterName is not defined
adapterName
string | undefined: adapter name, e.g.history
. To get all instances of all adapters just place here "".callback
(error: null | undefined | Error | string, instanceList?: ioBroker.InstanceObject[]) => void) => void: callback(error: null | undefined | Error | string, instanceList?: ioBroker.InstanceObject[]) => void
Read the host object by IP address.
ip
string: - IP address, e.g.,192.168.1.1
. IPv4 or IPv6callback?
(error: string | null | Error | undefined, hostObject?: ioBroker.HostObject | null) => void: - Callback function(ip: string, obj: ioBroker.HostObject | null) => void
Activate or deactivate logging events. Events will be sent to the socket as log
event. Adapter must have common.logTransporter = true
.
isEnabled
boolean: - Is logging enabledcallback?
(error: string | null | Error | undefined) => void: - Callback function(error: string | null) => void
Get the log files from the given host.
host
string: - Host ID, e.g.,system.host.raspberrypi
callback?
(error: string | null | Error | undefined, list?: {fileName: string; size: number}[]) => void: - Callback function(error: string | null, list?: { fileName: string; size: number }[]) => void
Execute the shell command on host/controller.
Following response commands are expected: cmdStdout
, cmdStderr
, cmdExit
.
host
string: - Host name, e.g.,system.host.raspberrypi
id
number: - Session ID, e.g.,Date.now()
. This session ID will come in eventscmdStdout
,cmdStderr
,cmdExit
cmd
string: - Command to executecallback?
(error: string | null | Error | undefined) => void: - Callback function(error: string | null) => void
Enable or disable the event threshold. Used only for admin to limit the number of events to the front-end.
isActive
boolean: - If true, then events will be limited
Get the ratings of adapters.
update
boolean | ((error: string | null | Error | undefined, ratings?: Ratings) => void): - If true, the ratings will be read from the central server, if false from the local cachecallback?
(error: string | null | Error | undefined, ratings?: Ratings) => void: - Callback function(error: string | null, ratings?: Ratings) => void
Get the current instance name, like "admin.0"
callback
(error: string | null | Error | undefined, namespace: string) => void) => void: - Callback function(error: string | null, namespace?: string) => void
Decrypts text with the system secret key.
encryptedText
string: - Encrypted textcallback
(error: string | null | Error | undefined, decryptedText?: string) => void) => void: - Callback function(error: string | null, decryptedText?: string) => void
Encrypts text with the system secret key.
plainText
string: - Plain text to encryptcallback
(error: string | null | Error | undefined, encryptedText?: string) => void) => void: - Callback function(error: string | null, encryptedText?: string) => void
Get if the admin has easy mode enabled.
callback
(error: string | null | Error | undefined, isEasyModeStrict?: boolean) => void) => void: - Callback function(error: string | null, isEasyModeStrict?: boolean) => void
Get easy mode configuration.
callback
(error: string | null | Error | undefined, easyModeConfig?: {strict: boolean; configs: InstanceConfig[]}) => void: - Callback function(error: string | null, easyModeConfig?: { strict: boolean; configs: InstanceConfig[] }) => void
Get all adapter as objects.
adapterName
string: - Optional adapter namecallback
(error: string | null | Error | undefined, result?: ioBroker.AdapterObject[]) => void) => void: - Callback function(error: string | null, results?: ioBroker.Object[]) => void
Read software licenses (vis, knx, ...) from ioBroker.net cloud for given user
login
string: - Cloud loginpassword
string: - Cloud passwordcallback
(error: string | null | Error | undefined, result?: License[]) => void) => void: - Callback function(error: string | null, results?: License[]) => void
Get all instances in a compact form to save bandwidth.
callback
(error: string | null | Error | undefined, result?: Record<string, CompactInstanceInfo>) => void) => void: - Callback function(error: string | null, results?: Record<string, { adminTab: boolean; name: string; icon: string; enabled: boolean }>) => void
Get all adapters in a compact form to save bandwidth.
callback
(error: string | null | Error | undefined, result?: Record<string, CompactAdapterInfo>) => void) => void: - Callback function(error: string | null, results?: Record<string, { icon: string; v: string; iv: string }>) => void
Get all installed adapters in a compact form to save bandwidth.
host
string: - Host name, e.g.,system.host.raspberrypi
callback
(result?: Record<string, {version: string}>) => void) => void: - Callback function(error: string | null, results?: Record<string, { version: string }>) => void
Get the system configuration in a compact form to save bandwidth.
callback
(error: string | null | Error | undefined, systemConfig?: {common: ioBroker.SystemConfigCommon; native?: {secret: string}}) => void: - Callback function(error: string | null, systemConfig?: { common: any; native?: { secret: string } }) => void
Get system repositories in a compact form to save bandwidth.
callback
(error: string | null | Error | undefined, systemRepositories?: CompactSystemRepository) => void) => void: - Callback function(error: string | null, systemRepositories?: { common: any; native?: { repositories: Record<string, { json: { _repoInfo: any } } } } }) => void
Get the repository in a compact form to save bandwidth.
host
string: - Host name, e.g.,system.host.raspberrypi
callback
(result: Record<string, {version: string; icon?: string}>) => void) => void: - Callback function(error: string | null, results?: Record<string, { version: string; icon?: string }>) => void
Get all hosts in a compact form to save bandwidth.
callback
(error: string | null | Error | undefined, hosts?: CompactHost[]) => void) => void: - Callback function(error: string | null, results?: Record<string, { common: { name: string; icon: string; color: string; installedVersion: string }; native: { hardware: { networkInterfaces: any[] } } }>) => void
Delete a state. The corresponding object will be deleted too.
id
string: - State IDcallback?
(error: string | null | Error | undefined) => void: - Callback function(error: string | null) => void
Get states by pattern of current adapter
pattern
string | string[] | undefined: optional pattern, likesystem.adapter.*
or array of state IDs. If the pattern is omitted, you will get ALL states of current adaptercallback
(error: null | undefined | Error | string, states?: Record<string, ioBroker.State>) => void) => void: callback(error: null | undefined | Error | string, states?: Record<string, ioBroker.State>) => void
Same as getStates
pattern
string | string[]: pattern likesystem.adapter.*
or array of state IDscallback
(error: null | undefined | Error | string, states?: Record<string, ioBroker.State>) => void) => void: callback(error: null | undefined | Error | string, states?: Record<string, ioBroker.State>) => void
Get a state by ID
id
string: State ID, e.g.system.adapter.admin.0.memRss
callback
(error: null | undefined | Error | string, state?: ioBroker.State) => void) => void: Callback(error: null | undefined | Error | string, state?: ioBroker.State) => void
Set a state by ID
id
string: State ID, e.g.system.adapter.admin.0.memRss
state
ioBroker.SettableState: State value or object, e.g.{val: 123, ack: true}
callback
(error: null | undefined | Error | string, state?: ioBroker.State) => void) => void: Callback(error: null | undefined | Error | string, state?: ioBroker.State) => void
Get a binary state by ID
id
string: State ID, e.g.javascript.0.binary
callback
(error: null | undefined | Error | string, base64?: string) => void) => void: Callback(error: null | undefined | Error | string, base64?: string) => void
Set a binary state by ID
id
string: State ID, e.g.javascript.0.binary
_base64
string: State value as base64 string. Binary states have no acknowledged flag.callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Subscribe to state changes by pattern. The events will come as 'stateChange' events to the socket.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of states like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: string | null) => void) => void: Callback(error: string | null) => void
Subscribe to state changes by pattern. Same as subscribe
.
The events will come as 'stateChange' events to the socket.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of states like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: string | null) => void) => void: Callback(error: string | null) => void
Unsubscribe from state changes by pattern.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of states like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: string | null) => void) => void: Callback(error: string | null) => void
Unsubscribe from state changes by pattern. Same as unsubscribe
.
The events will come as 'stateChange' events to the socket.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of states like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: string | null) => void) => void: Callback(error: string | null) => void
Add a new user.
user
string: - User name, e.g.,benjamin
pass
string: - User passwordcallback?
(error: string | null | Error | undefined) => void: - Callback function(error: string | null) => void
Delete an existing user. Admin cannot be deleted.
user
string: - User name, e.g.,benjamin
callback?
(error: string | null | Error | undefined) => void: - Callback function(error: string | null) => void
Add a new group.
group
string: - Group name, e.g.,users
desc
ioBroker.StringOrTranslated | null: - Optional descriptionacl
Omit<ioBroker.PermissionSet, 'user' | 'groups'> | null: - Optional access control list object, e.g.,{"object":{"list":true,"read":true,"write":false,"delete":false},"state":{"list":true,"read":true,"write":true,"create":true,"delete":false},"users":{"list":true,"read":true,"write":false,"create":false,"delete":false},"other":{"execute":false,"http":true,"sendto":false},"file":{"list":true,"read":true,"write":false,"create":false,"delete":false}}
callback?
(error: string | null | Error | undefined) => void: - Callback function(error: string | null) => void
Delete an existing group. Administrator group cannot be deleted.
group
string: - Group name, e.g.,users
callback?
(error: string | null | Error | undefined) => void: - Callback function(error: string | null) => void
Change user password.
user
string: - User name, e.g.,benjamin
pass
string: - New passwordcallback?
(error: string | null | Error | undefined) => void: - Callback function(error: string | null) => void
Get one object.
id
string: Object IDcallback
(error: Error | undefined | string | null, obj?: ioBroker.Object) => void) => void: Callback(error: string | null, obj?: ioBroker.Object) => void
Get all objects that are relevant for web: all states and enums with rooms. This is non-admin version of "all objects" and will be overloaded in admin
list
string[] | null: Optional list of IDscallback
(error: Error | undefined | string | null, objs?: Record<string, ioBroker.Object>) => void) => void: Callback(error: string | null, objs?: Record<string, ioBroker.Object>) => void
Subscribe to object changes by pattern. The events will come as 'objectChange' events to the socket.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of IDs like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: Error | undefined | string | null) => void) => void: Callback(error: string | null) => void
Unsubscribe from object changes by pattern.
pattern
string | string[]: Pattern likesystem.adapter.*
or array of IDs like['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
callback
(error: string | null | Error | undefined) => void) => void: Callback(error: string | null) => void
Get a view of objects. Make a query to the object database.
design
string: Design name, e.g., 'system' or other designs likecustom
, but it must exist object_design/custom
. To 99,9% usesystem
.search
string: Search name, object type, likestate
,instance
,adapter
,host
, ...params
{startkey?: string; endkey?: string; depth?: number}: Parameters for the query, e.g.,{startkey: 'system.adapter.', endkey: 'system.adapter.\u9999', depth?: number}
callback
(error: string | null | Error | undefined, result?: {rows: {id: string; value: ioBroker.Object & {virtual: boolean; hasChildren: number;};}[];}) => void: Callback(error: string | null, result?: { rows: Array<GetObjectViewItem> }) => void
Set an object.
id
string: Object IDobj
ioBroker.Object: Object to setcallback
(error: string | null | Error | undefined) => void) => void: Callback(error: string | null) => void
Delete an object. Only deletion of flot and fullcalendar objects is allowed
id
string: Object ID, like 'flot.0.myChart'_options
any: Options for deletion. Ignoredcallback
(error: string | null | Error | undefined) => void) => void: Callback(error: string | null) => void
Read absolutely all objects.
callback
(error: null | undefined | Error | string, result?: Record<string, ioBroker.Object>) => void) => void: - Callback function(error: string | null, objects?: Record<string, ioBroker.Object>) => void
Extend the existing object.
id
string: - Object IDobj
Partial<ioBroker.Object>: - New parts of the object, e.g.,{common: {name: 'new name'}}
callback?
(error: string | null | Error | undefined) => void: - Callback function(error: string | null) => void
Read objects by pattern.
pattern
string: - Pattern likesystem.adapter.admin.0.*
type
* ioBroker.ObjectType | undefined | ((error: string | null | Error | undefined, objects?: Record<string, ioBroker.Object>) => void)*: - Type of objects to delete, likestate
,channel
,device
,host
,adapter
. Default -state
callback?
(error: string | null | Error | undefined, objects?: Record<string, ioBroker.Object>) => void: - Callback function(error: string | null, objects?: Record<string, ioBroker.Object>) => void
Delete an object or objects recursively.
Objects with dontDelete
cannot be deleted.
Same as delObject
but with recursive: true
.
id
string: - Object ID, like 'adapterName.0.channel'options?
ioBroker.DelObjectOptions | ((error: string | null | Error | undefined) => void) | null: - Options for deletion.callback?
(error: string | null | Error | undefined) => void: - Callback function(error: string | null) => void
Read a file from ioBroker DB
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
callback
(error: null | undefined | Error | string, data: Buffer | string, mimeType: string) => void) => void: Callback(error: null | undefined | Error | string, data: Buffer | string, mimeType: string) => void
Read a file from ioBroker DB as base64 string
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
callback
(error: null | undefined | Error | string, base64?: string, mimeType?: string) => void) => void: Callback(error: null | undefined | Error | string, base64: string, mimeType: string) => void
Write a file into ioBroker DB as base64 string
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
data64
string: file content as base64 stringoptions
{mode?: number} | ((error: null | undefined | Error | string) => void): optional{mode: 0x0644}
callback?
(error: null | undefined | Error | string) => void: Callback(error: null | undefined | Error | string) => void
Write a file into ioBroker DB as text This function is overloaded in admin (because admin accepts only base64)
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
data
string: file content as textoptions
{mode?: number} | ((error: null | undefined | Error | string) => void): optional{mode: 0x0644}
callback?
(error: null | undefined | Error | string) => void: Callback(error: null | undefined | Error | string) => void
Delete file in ioBroker DB
adapter
string: instance name, e.g.vis.0
name
string: file name, e.g.main/vis-views.json
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Delete a file in ioBroker DB (same as "unlink", but only for files)
adapter
string: instance name, e.g.vis.0
name
string: file name, e.g.main/vis-views.json
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Delete folder in ioBroker DB (same as unlink
, but only for folders)
adapter
string: instance name, e.g.vis.0
name
string: folder name, e.g.main
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Rename a file in ioBroker DB
adapter
string: instance name, e.g.vis.0
oldName
string: current file name, e.g.main/vis-views.json
newName
string: new file name, e.g.main/vis-views-new.json
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Rename file or folder in ioBroker DB
adapter
string: instance name, e.g.vis.0
oldName
string: current file name, e.g.main/vis-views.json
newName
string: new file name, e.g.main/vis-views-new.json
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Create a folder in ioBroker DB
adapter
string: instance name, e.g.vis.0
dirName
string: desired folder name, e.g.main
callback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Read content of folder in ioBroker DB
adapter
string: instance name, e.g.vis.0
dirName
string: folder name, e.g.main
options
object | ((error: null | undefined | Error | string, files: ioBroker.ReadDirResult[]) => void): for future usecallback?
(error: null | undefined | Error | string, files: ioBroker.ReadDirResult[]) => void: Callback(error: null | undefined | Error | string, files: Array<{file: string, isDir: boolean, stats: {size: number}, modifiedAt: number, acl: {owner: string, ownerGroup: string, permissions: number, read: boolean, write: boolean}}>) => void
Change a file mode in ioBroker DB
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
options
{mode?: number}: options{mode: 0x644}
callback?
(error: string | Error | null | undefined) => void: Callback(error: string | Error | null | undefined) => void
Change file owner in ioBroker DB
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
options
{owner:system.user.${string}
; ownerGroup?:system.group.${string}
}: options{owner: 'system.user.user', ownerGroup: 'system.group.administrator'}
orsystem.user.user
. If ownerGroup is not defined, it will be taken from owner.callback?
(error: null | undefined | Error | string) => void: Callback(error: null | undefined | Error | string) => void
Check if the file or folder exists in ioBroker DB
adapter
string: instance name, e.g.vis.0
fileName
string: file name, e.g.main/vis-views.json
callback
(error: null | undefined | Error | string, exists?: boolean) => void) => void: Callback(error: null | undefined | Error | string, exists?: boolean) => void
Subscribe to file changes in ioBroker DB
id
string: instance name, e.g.vis.0
or any object ID of typemeta
.id
could have wildcards*
too.pattern
string | string[]: file name pattern, e.g.main/*.json
or array of namescallback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
Unsubscribe from file changes in ioBroker DB
id
string: instance name, e.g.vis.0
or any object ID of typemeta
.id
could have wildcards*
too.pattern
string | string[]: file name pattern, e.g.main/*.json
or array of namescallback
(error: null | undefined | Error | string) => void) => void: Callback(error: null | undefined | Error | string) => void
- (@GermanBluefox) Code migrated to TypeScript
- (@GermanBluefox) Caught the error if no authentication and logout called
- (@GermanBluefox) Added support for iobroker.SocketIO with TypeScript
- (@GermanBluefox) Corrected call of getObjectView with null parameter
- (@GermanBluefox) updated packages
- (@GermanBluefox) extend
getCompactInstances
method with version information
- (foxriver76) ensure compatible
adapter-core
version
- (@GermanBluefox) Extended getObjects function with the possibility to read the list of IDs in admin
- (@GermanBluefox) Added
publishInstanceMessageAll
command
- (@GermanBluefox) Caught errors by subscribe/unsubscribe
- (foxriver76) do not await the subscribes anymore
- (@GermanBluefox) Corrected error by unsubscribing on client disconnect
- (foxriver76) do not cancel follow subscribes if one subscribe has an error
- (foxriver76) fixed crash on invalid patterns with js-controller version 5
- (@GermanBluefox) Implemented subscribing of a client on messages from specific instance
- (@GermanBluefox) Moved checkFeatureSupported to regular connection and not only admin
- (foxriver76) fixed crash on invalid patterns with js-controller version 5
- (@GermanBluefox) extended the getObjects function with the possibility to read the list of IDs
- (@GermanBluefox) Added command
name
- (@GermanBluefox) Treat
json5
asjson
- (@GermanBluefox) Allow deletion of fullcalendar objects
- (@GermanBluefox) Corrected error with subscribe
- (@GermanBluefox) Added user check to many commands
- (@GermanBluefox) Downgrade axios to 0.27.2
- (@GermanBluefox) Function
getObjects
for web was extended by devices, channels and enums
- (@GermanBluefox) Fixed error with delObject
- (Apollon77) Prepare for future js-controller versions
- (@GermanBluefox) Fixed error in
delObjects
method
- (@GermanBluefox) Caught error by subscribing
- (@GermanBluefox) Added command
getCompactSystemRepositories
- (@GermanBluefox) Buffer conversion errors caught and handled
- (@GermanBluefox) Corrected getAdapterInstances method
- (@GermanBluefox) Corrected log transportation
- (@GermanBluefox) Corrected getAdapterInstances
- (@GermanBluefox) Do not show error with failed authentication
- (@GermanBluefox) Allowed overloading system language
- (@GermanBluefox) updated
passport
- (@GermanBluefox) allowed running socket.io behind reverse proxy
- (@GermanBluefox) Do not show requireLog message
- (@GermanBluefox) Allowed call of getAdapterInstances for non admin
- (@GermanBluefox) Corrected renameFile command for admin
- (@GermanBluefox) Corrected changePassword command for admin
- (@GermanBluefox) Added support of socket.io 4.x
- (@GermanBluefox) Hide warn messages
- (@GermanBluefox) Added back compatibility with [email protected] for
writeDirAsZip
- (@GermanBluefox) Process
writeDirAsZip
locally
- (@GermanBluefox) fixed
getObjects
command
- (@GermanBluefox) fixed
delObjects
command
- (@GermanBluefox) Added support for fileChanges
- (@GermanBluefox) Corrected readLogs command and implement file subscriptions
- (@GermanBluefox) Caught some sentry errors
- (@GermanBluefox) fixed
delObject
command
- (@GermanBluefox) added updateRatings
- (@GermanBluefox) added passportSocket
- (@GermanBluefox) initial commit
The MIT License (MIT)
Copyright (c) 2020-2025 @GermanBluefox [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.