refactor: socket

This commit is contained in:
cha0s 2021-01-12 17:31:30 -06:00
parent 18eec3a986
commit 770813148d
3 changed files with 9 additions and 2 deletions

View File

@ -1,6 +1,8 @@
import acceptor from '../packet/acceptor';
import SocketClient from './socket';
export {socket} from './socket';
export default {
hooks: {
'@latus/http/client/up': (latus) => {

View File

@ -15,6 +15,8 @@ const decorate = compose(
EventEmitter,
);
export const socket = (latus) => latus.config['%socket'];
export default class SocketClient extends decorate(Class) {
constructor(latus) {

View File

@ -1,5 +1,7 @@
import {LatusContext, React} from '@latus/react';
import {socket} from '../client/socket';
const {useContext} = React;
export default function useSocket() {
@ -7,8 +9,9 @@ export default function useSocket() {
if (!latus) {
throw new Error('useSocket: no latus context');
}
if (!latus.config['%socket']) {
const sock = socket(latus);
if (!sock) {
throw new Error('useSocket: no configured socket');
}
return latus.config['%socket'];
return sock;
}