Skip to content

Commit 7ba9337

Browse files
authored
Merge pull request #281 from smartdevicelink/feature/sdl-manager-set-rpc-listeners
Add new API and use it in example apps
2 parents c576162 + 512b5a4 commit 7ba9337

13 files changed

Lines changed: 323 additions & 32 deletions

File tree

examples/js/hello-sdl/SDL.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/js/hello-sdl/index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@
5656
SDL.rpc.enums.AppHMIType.DEFAULT,
5757
])
5858
.setTransportConfig(new SDL.transport.WebSocketClientConfig('ws://localhost', 5050))
59-
.setAppIcon(file);
59+
.setAppIcon(file)
60+
.setRpcNotificationListeners({
61+
[SDL.rpc.enums.FunctionID.OnHMIStatus]: this._onHmiStatusListener.bind(this),
62+
});
6063

6164
this._appConfig = new SDL.manager.AppConfig()
6265
.setLifecycleConfig(this._lifecycleConfig);
@@ -94,9 +97,7 @@
9497
});
9598

9699
this._sdlManager = new SDL.manager.SdlManager(this._appConfig, managerListener);
97-
this._sdlManager
98-
.start()
99-
.addRpcListener(SDL.rpc.enums.FunctionID.OnHMIStatus, this._onHmiStatusListener.bind(this));
100+
this._sdlManager.start();
100101
}
101102

102103
async _onConnected () {

examples/node/hello-sdl-tcp/SDL.min.js

Lines changed: 76 additions & 3 deletions
Large diffs are not rendered by default.

examples/node/hello-sdl-tcp/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ class AppClient {
5151
SDL.rpc.enums.AppHMIType.DEFAULT,
5252
])
5353
.setTransportConfig(new SDL.transport.TcpClientConfig(CONFIG.host, CONFIG.port))
54-
.setAppIcon(file);
54+
.setAppIcon(file)
55+
.setRpcNotificationListeners({
56+
[SDL.rpc.enums.FunctionID.OnHMIStatus]: this._onHmiStatusListener.bind(this),
57+
});
5558

5659
this._appConfig = new SDL.manager.AppConfig()
5760
.setLifecycleConfig(this._lifecycleConfig);
@@ -89,9 +92,7 @@ class AppClient {
8992
});
9093

9194
this._sdlManager = new SDL.manager.SdlManager(this._appConfig, managerListener);
92-
this._sdlManager
93-
.start()
94-
.addRpcListener(SDL.rpc.enums.FunctionID.OnHMIStatus, this._onHmiStatusListener.bind(this));
95+
this._sdlManager.start();
9596
}
9697

9798
async _onConnected () {

examples/node/hello-sdl/AppClient.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ class AppClient {
5656
CONFIG.connectionLostTimeout
5757
)
5858
)
59-
.setAppIcon(file);
59+
.setAppIcon(file)
60+
.setRpcNotificationListeners({
61+
[SDL.rpc.enums.FunctionID.OnHMIStatus]: this._onHmiStatusListener.bind(this),
62+
});
6063

6164
this._appConfig = new SDL.manager.AppConfig()
6265
.setLifecycleConfig(this._lifecycleConfig);
@@ -94,9 +97,7 @@ class AppClient {
9497
});
9598

9699
this._sdlManager = new SDL.manager.SdlManager(this._appConfig, managerListener);
97-
this._sdlManager
98-
.start()
99-
.addRpcListener(SDL.rpc.enums.FunctionID.OnHMIStatus, this._onHmiStatusListener.bind(this));
100+
this._sdlManager.start();
100101

101102
// for a cloud server app the hmi full will be received before the managers report that they're ready!
102103
this._managersReady = false;

examples/node/hello-sdl/SDL.min.js

Lines changed: 76 additions & 3 deletions
Large diffs are not rendered by default.

examples/webengine/hello-sdl/SDL.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/webengine/hello-sdl/index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
this._lifecycleConfig = new SDL.manager.LifecycleConfig()
5151
.loadManifest(sdl_manifest)
5252
.setLanguageDesired(SDL.rpc.enums.Language.EN_US)
53-
.setTransportConfig(new SDL.transport.WebSocketClientConfig());
53+
.setTransportConfig(new SDL.transport.WebSocketClientConfig())
54+
.setRpcNotificationListeners({
55+
[SDL.rpc.enums.FunctionID.OnHMIStatus]: this._onHmiStatusListener.bind(this),
56+
});
5457

5558
this._appConfig = new SDL.manager.AppConfig()
5659
.setLifecycleConfig(this._lifecycleConfig);
@@ -88,9 +91,7 @@
8891
});
8992

9093
this._sdlManager = new SDL.manager.SdlManager(this._appConfig, managerListener);
91-
this._sdlManager
92-
.start()
93-
.addRpcListener(SDL.rpc.enums.FunctionID.OnHMIStatus, this._onHmiStatusListener.bind(this));
94+
this._sdlManager.start();
9495
}
9596

9697
async _onConnected () {

lib/js/dist/SDL.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/js/src/manager/LifecycleConfig.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class LifecycleConfig {
5858
this._minimumRpcVersion = new Version(1, 0, 0);
5959
this._minimumProtocolVersion = new Version(1, 0, 0);
6060
this._resumeHash = null;
61+
this._onRpcNotificationListeners = null;
6162
}
6263

6364
/**
@@ -419,6 +420,26 @@ class LifecycleConfig {
419420
});
420421
return this;
421422
}
423+
424+
/**
425+
* Get RPC notification listeners. SdlManager will preload these listeners before any RPCs are sent/received.
426+
* @returns {Object} listeners - a map of listeners that will be called when a notification is received.
427+
* Key represents the FunctionID of the notification and value represents the listener
428+
*/
429+
getRpcNotificationListeners () {
430+
return this._onRpcNotificationListeners;
431+
}
432+
433+
/**
434+
* Set RPC notification listeners. SdlManager will preload these listeners before any RPCs are sent/received.
435+
* @param {Object} listeners - a map of listeners that will be called when a notification is received.
436+
* Key represents the FunctionID of the notification and value represents the listener
437+
* @returns {LifecycleConfig} - A reference to this instance to support method chaining.
438+
*/
439+
setRpcNotificationListeners (listeners) {
440+
this._onRpcNotificationListeners = listeners;
441+
return this;
442+
}
422443
}
423444

424445
export { LifecycleConfig };

0 commit comments

Comments
 (0)