** Player
- Add new callbacks : onUserActive / onUserInactive / onSessionStopped

** SDK Debug
- Add ws:// il ws URL.

** Update readme
This commit is contained in:
Maxence Brasselet 2020-05-06 14:02:29 +02:00
Родитель b149af8a7d
Коммит 1aa0da0c8f
3 изменённых файлов: 44 добавлений и 3 удалений

Просмотреть файл

@ -38,6 +38,18 @@ Instanciate the player for a given app.
Bind a callback that will be called when the player is ready.
- `callback: Function`: Your own code to do what you want when it's ready (ex: call start()).
#### onUserActive(callback)
Bind a callback that will be called when the user is active on your session (only fired when a session is running).
- `callback: Function`: Implement your code.
#### onUserInactive(callback)
Bind a callback that will be called when the user is inactive on your session (only fired when a session is running).
- `callback: Function`: Implement your code.
#### onSessionStopped(callback)
Bind a callback that will be called when the session is stopped (ex: stopped for inactivity)
- `callback: Function`: Implement your code.
### Methods to create your own interface
Those methods permit you to create your own interface.

Просмотреть файл

@ -23,7 +23,10 @@ const _eventNames = {
RESTART_STREAM: "restartStream",
ON_SDK_MESSAGE: "onSDKMessage",
SEND_SDK_MESSAGE: "sendSDKMessage",
SET_LOCATION: "setLocation"
SET_LOCATION: "setLocation",
ON_USER_ACTIVE: "onUserActive",
ON_USER_INACTIVE: "onUserInactive",
ON_SESSION_STOPPED: "onSessionStopped"
};
const _qualityValues = {
@ -161,6 +164,21 @@ module.exports = class Player {
this._onSDKMessageCallback(e.data.value);
}
return;
case _eventNames.ON_USER_ACTIVE:
if (this._onUserActiveCallback) {
this._onUserActiveCallback();
}
return;
case _eventNames.ON_USER_INACTIVE:
if (this._onUserInactiveCallback) {
this._onUserInactiveCallback();
}
return;
case _eventNames.ON_SESSION_STOPPED:
if (this._onSessionStoppedCallback) {
this._onSessionStoppedCallback();
}
return;
case _eventNames.ERROR:
this._displayErrorMessage(e.data.value);
return;
@ -281,6 +299,18 @@ module.exports = class Player {
this._onSDKMessageCallback = onSDKMessageCallback;
}
onUserActive(onUserActiveCallback) {
this._onUserActiveCallback = onUserActiveCallback;
}
onUserInactive(onUserInactiveCallback) {
this._onUserInactiveCallback = onUserInactiveCallback;
}
onSessionStopped(onSessionStoppedCallback) {
this._onSessionStoppedCallback = onSessionStoppedCallback;
}
sendSDKMessage(data) {
if (!this.loaded) {
return; // Not loaded.

Просмотреть файл

@ -5,7 +5,7 @@ module.exports = class SDKDebug {
}
// Init WS connection.
this.ws = new WebSocket(localServerAddress);
this.ws = new WebSocket("ws://" + localServerAddress);
this.ws.binaryType = 'arraybuffer';
this.ws.onerror = (event) => {this._wsOnError(event)};
this.ws.onclose = (event) => {this._wsOnClose(event);}
@ -53,7 +53,6 @@ module.exports = class SDKDebug {
return; // Not loaded.
}
this.ws.send(JSON.stringify(data),this._wsOnSendError);
}
}