diff --git a/packages/socket/src/client/index.js b/packages/socket/src/client/index.js index 62ddf5a..4e5cec1 100644 --- a/packages/socket/src/client/index.js +++ b/packages/socket/src/client/index.js @@ -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) => { diff --git a/packages/socket/src/client/socket.js b/packages/socket/src/client/socket.js index 83947d3..e8337ef 100644 --- a/packages/socket/src/client/socket.js +++ b/packages/socket/src/client/socket.js @@ -15,6 +15,8 @@ const decorate = compose( EventEmitter, ); +export const socket = (latus) => latus.config['%socket']; + export default class SocketClient extends decorate(Class) { constructor(latus) { diff --git a/packages/socket/src/hooks/use-socket.js b/packages/socket/src/hooks/use-socket.js index c5e7a22..8b159cb 100644 --- a/packages/socket/src/hooks/use-socket.js +++ b/packages/socket/src/hooks/use-socket.js @@ -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; }