mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
034a230365
refs https://github.com/TryGhost/Team/issues/2561 - added simple socket-io implementation to Ghost server - added alpha flag for websockets - added route in admin to test websockets using a simple counter stored in server local memory (refreshes on reboot)
32 lines
926 B
JavaScript
32 lines
926 B
JavaScript
import Component from '@glimmer/component';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class Websockets extends Component {
|
|
@service('socket-io') socketIOService;
|
|
|
|
constructor(...args) {
|
|
super(...args);
|
|
// initialize connection
|
|
|
|
// TODO: ensure this works with subdirectories
|
|
let origin = window.location.origin; // this gives us host:port
|
|
let socket = this.socketIOService.socketFor(origin);
|
|
// add listener
|
|
socket.on('addCount', (value) => {
|
|
this.counter = value;
|
|
});
|
|
}
|
|
|
|
// button counter
|
|
@tracked counter = 0;
|
|
|
|
// handle button/event
|
|
@action handleClick() {
|
|
let socket = this.socketIOService.socketFor(origin);
|
|
this.counter = 1 + this.counter;
|
|
socket.emit('addCount', this.counter);
|
|
}
|
|
}
|