owncast/webroot/js/app-standalone-chat.js

43 lines
1 KiB
JavaScript
Raw Normal View History

import { h, Component } from '/js/web_modules/preact.js';
import htm from '/js/web_modules/htm.js';
const html = htm.bind(h);
2020-08-24 05:37:06 +03:00
import Chat from './components/chat/chat.js';
2020-08-24 05:06:58 +03:00
import Websocket from './utils/websocket.js';
2020-10-14 14:33:55 +03:00
import { getLocalStorage, generateUsername } from './utils/helpers.js';
import { KEY_USERNAME } from './utils/constants.js';
export default class StandaloneChat extends Component {
constructor(props, context) {
super(props, context);
this.state = {
websocket: new Websocket(),
chatEnabled: true, // always true for standalone chat
username: getLocalStorage(KEY_USERNAME) || generateUsername(),
};
this.websocket = null;
this.handleUsernameChange = this.handleUsernameChange.bind(this);
}
2020-10-14 14:33:55 +03:00
handleUsernameChange(newName) {
this.setState({
username: newName,
});
}
render(props, state) {
2020-10-14 14:33:55 +03:00
const { username, websocket } = state;
2020-08-24 05:37:06 +03:00
return (
html`
<${Chat}
websocket=${websocket}
username=${username}
messagesOnly
/>
2020-08-24 05:37:06 +03:00
`
);
}
}