2018-04-21 02:59:30 -03:00
|
|
|
/*****************************************************************************\
|
|
|
|
| ( )_ _ |
|
|
|
|
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
|
|
|
|
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
|
|
|
|
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
|
|
|
|
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
|
|
|
|
| | | ( )_) | |
|
|
|
|
| (_) \___/' |
|
|
|
|
| |
|
|
|
|
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
|
|
|
|
| Licensed under the AGPL-3.0. |
|
|
|
|
| |
|
|
|
|
| According to our dual licensing model, this program can be used either |
|
|
|
|
| under the terms of the GNU Affero General Public License, version 3, |
|
|
|
|
| or under a proprietary license. |
|
|
|
|
| |
|
|
|
|
| The texts of the GNU Affero General Public License with an additional |
|
|
|
|
| permission and of our proprietary license can be found at and |
|
|
|
|
| in the LICENSE file you have received along with this program. |
|
|
|
|
| |
|
|
|
|
| This program is distributed in the hope that it will be useful, |
|
|
|
|
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
| GNU Affero General Public License for more details. |
|
|
|
|
| |
|
|
|
|
| "General Bots" is a registered trademark of Pragmatismo.io. |
|
|
|
|
| The licensing of the program under the AGPLv3 does not imply a |
|
|
|
|
| trademark license. Therefore any rights, title and interest in |
|
|
|
|
| our trademarks remain entirely with us. |
|
|
|
|
| |
|
|
|
|
\*****************************************************************************/
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
import GBMarkdownPlayer from "./players/GBMarkdownPlayer.js";
|
|
|
|
import GBImagePlayer from "./players/GBImagePlayer.js";
|
|
|
|
import GBVideoPlayer from "./players/GBVideoPlayer.js";
|
|
|
|
import GBBulletPlayer from "./players/GBBulletPlayer.js";
|
|
|
|
import SidebarMenu from "./components/SidebarMenu.js";
|
|
|
|
import GBCss from "./components/GBCss.js";
|
|
|
|
import { DirectLine } from "botframework-directlinejs";
|
|
|
|
import { ConnectionStatus } from "botframework-directlinejs";
|
|
|
|
import { Chat } from "botframework-webchat";
|
|
|
|
import GBPowerBIPlayer from "./players/GBPowerBIPlayer.js";
|
|
|
|
|
|
|
|
class GBUIApp extends React.Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
botConnection: null,
|
|
|
|
instance: null,
|
|
|
|
token: null
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
send(command) {
|
|
|
|
window.botConnection
|
|
|
|
.postActivity({
|
|
|
|
type: "event",
|
|
|
|
name: command,
|
|
|
|
locale: "en-us",
|
|
|
|
textFormat: "plain",
|
|
|
|
timestamp: new Date().toISOString(),
|
|
|
|
from: { id: "webUser", name: "You" }
|
|
|
|
})
|
|
|
|
.subscribe(console.log("EVENT SENT TO Guaribas."));
|
|
|
|
}
|
|
|
|
getUser() {
|
|
|
|
return { id: "webUser@gb", name: "You" };
|
|
|
|
}
|
|
|
|
|
|
|
|
postEvent(name, value) {
|
|
|
|
window.botConnection.postActivity({
|
|
|
|
type: "event",
|
|
|
|
value: value,
|
|
|
|
from: this.getUser(),
|
|
|
|
name: name
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
postMessage(value) {
|
|
|
|
window.botConnection.postActivity({
|
|
|
|
type: "message",
|
|
|
|
text: value,
|
|
|
|
from: this.getUser()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
configureChat() {
|
|
|
|
var botId = window.location.href.split("/")[3];
|
|
|
|
|
|
|
|
if (!botId) {
|
|
|
|
botId = "[default]";
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch("/instances/" + botId)
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(
|
|
|
|
result => {
|
|
|
|
this.setupBotConnection(result.secret);
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.setState({
|
|
|
|
isLoaded: false,
|
|
|
|
err: error
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
setupBotConnection(secret) {
|
2018-05-12 22:36:12 -03:00
|
|
|
let _this_ = this;
|
2018-04-21 02:59:30 -03:00
|
|
|
window["botchatDebug"] = true;
|
|
|
|
|
|
|
|
const botConnection = new DirectLine({
|
|
|
|
secret: secret
|
|
|
|
});
|
|
|
|
|
|
|
|
botConnection.connectionStatus$.subscribe(connectionStatus => {
|
|
|
|
if (connectionStatus === ConnectionStatus.Online) {
|
|
|
|
botConnection.postActivity({
|
|
|
|
type: "event",
|
|
|
|
value: "startGB",
|
|
|
|
from: this.getUser(),
|
|
|
|
name: "startGB"
|
|
|
|
});
|
|
|
|
|
2018-05-12 22:36:12 -03:00
|
|
|
_this_.setState({ botConnection: botConnection });
|
2018-04-21 02:59:30 -03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
window.botConnection = botConnection;
|
|
|
|
this.postEvent("startGB", true);
|
|
|
|
|
|
|
|
botConnection.activity$
|
|
|
|
.filter(
|
|
|
|
activity =>
|
|
|
|
activity.type === "event" && activity.name === "loadInstance"
|
|
|
|
)
|
|
|
|
.subscribe(activity => {
|
2018-05-12 22:36:12 -03:00
|
|
|
_this_.setState({ instance: activity.value });
|
2018-04-21 02:59:30 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
botConnection.activity$
|
|
|
|
.filter(activity => activity.type === "event" && activity.name === "stop")
|
|
|
|
.subscribe(activity => {
|
2018-05-12 22:36:12 -03:00
|
|
|
if (_this_.player) {
|
|
|
|
_this_.player.stop();
|
2018-04-21 02:59:30 -03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
botConnection.activity$
|
|
|
|
.filter(activity => activity.type === "event" && activity.name === "play")
|
|
|
|
.subscribe(activity => {
|
2018-05-12 22:36:12 -03:00
|
|
|
_this_.setState({ playerType: activity.value.playerType });
|
|
|
|
_this_.player.play(activity.value.data);
|
2018-04-21 02:59:30 -03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.configureChat();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let chat = <div />;
|
|
|
|
|
|
|
|
let playerComponent = "";
|
|
|
|
|
|
|
|
if (this.state.playerType) {
|
|
|
|
switch (this.state.playerType) {
|
|
|
|
case "markdown":
|
|
|
|
playerComponent = (
|
|
|
|
<GBMarkdownPlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "bullet":
|
|
|
|
playerComponent = (
|
|
|
|
<GBBulletPlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "video":
|
|
|
|
playerComponent = (
|
|
|
|
<GBVideoPlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "image":
|
|
|
|
playerComponent = (
|
|
|
|
<GBImagePlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "pbi":
|
|
|
|
playerComponent = (
|
|
|
|
<GBPowerBIPlayer
|
|
|
|
app={this}
|
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log(
|
|
|
|
"GBERROR: Unknow player type specified on message from server."
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let sideBar = (
|
|
|
|
<div className="sidebar">
|
|
|
|
<SidebarMenu chat={this.chat} instance={this.state.instance} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (this.state.botConnection) {
|
|
|
|
chat = (
|
|
|
|
<Chat
|
|
|
|
ref={chat => {
|
|
|
|
this.chat = chat;
|
|
|
|
}}
|
|
|
|
botConnection={this.state.botConnection}
|
|
|
|
user={this.getUser()}
|
|
|
|
bot={{ id: "bot@gb", name: "Bot" }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.state.instance) {
|
|
|
|
sideBar = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<GBCss instance={this.state.instance} />
|
|
|
|
{sideBar}
|
|
|
|
<div className="player">{playerComponent}</div>
|
|
|
|
{chat}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default GBUIApp;
|