1
1
// eslint-disable-next-line import/no-extraneous-dependencies
2
- import { ref } from 'vue' ;
2
+ import { ref , inject } from 'vue' ;
3
3
import Observe from './Observe' ;
4
4
import GlobalEmitter from './GlobalEmitter' ;
5
5
import createMixin from './createMixin' ;
@@ -53,6 +53,8 @@ function defineSocketIoClient(socket, obj) {
53
53
} ) ;
54
54
}
55
55
56
+ const SocketExtensionKey = Symbol ( '$socket' ) ;
57
+
56
58
function install ( app , socket , options ) {
57
59
if ( ! isSocketIo ( socket ) ) {
58
60
throw new Error ( '[vue-socket.io-ext] you have to pass `socket.io-client` instance to the plugin' ) ;
@@ -67,6 +69,11 @@ function install(app, socket, options) {
67
69
app . config . optionMergeStrategies . sockets = ( toVal , fromVal ) => ( { ...toVal , ...fromVal } ) ;
68
70
Observe ( socket , options ) ;
69
71
app . mixin ( createMixin ( GlobalEmitter ) ) ;
72
+ app . provide ( SocketExtensionKey , $socket ) ;
70
73
}
71
74
72
- export { defaults , install } ;
75
+ const useSocket = ( ) => inject ( SocketExtensionKey ) ;
76
+
77
+ export default {
78
+ defaults, install, useSocket, SocketExtensionKey,
79
+ } ;
0 commit comments