File tree Expand file tree Collapse file tree 4 files changed +25
-2
lines changed
Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ const DEFAULTS: ModuleOptions = {
1616
1717const nuxtModule : Module < ModuleOptions > = function ( moduleOptions ) {
1818 this . nuxt . hook ( 'builder:extendPlugins' , ( plugins : NuxtOptionsPlugin [ ] ) => {
19- const options : ModuleOptions = defu (
19+ const options = defu (
2020 this . options . echo || { } ,
2121 moduleOptions ,
2222 DEFAULTS
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { ModuleOptions } from './types'
55
66export class Echo extends BaseEcho {
77 ctx : Context ;
8- config : Partial < ModuleOptions > ;
8+ config : ModuleOptions ;
99
1010 constructor ( ctx : Context , config : Partial < ModuleOptions > = { } ) {
1111 // when enabled authModule, start broadcaster with null
@@ -58,11 +58,28 @@ export class Echo extends BaseEcho {
5858 if ( this . config . connectOnLogin && loggedIn ) {
5959 // set broadcaster when user logged in
6060 this . options . broadcaster = this . config . broadcaster
61+
62+ if ( this . config . onBeforeConnect ) {
63+ await this . config . onBeforeConnect ( )
64+ }
65+
6166 this . connect ( )
67+
68+ if ( this . config . onAfterConnect ) {
69+ await this . config . onAfterConnect ( )
70+ }
6271 }
6372
6473 if ( this . config . disconnectOnLogout && ! loggedIn && this . connector ) {
74+ if ( this . config . onBeforeDisconnect ) {
75+ await this . config . onBeforeDisconnect ( )
76+ }
77+
6578 this . disconnect ( )
79+
80+ if ( this . config . onAfterDisconnect ) {
81+ await this . config . onAfterDisconnect ( )
82+ }
6683 }
6784 } ) . bind ( this )
6885 }
Original file line number Diff line number Diff line change @@ -10,10 +10,12 @@ declare module '@nuxt/types' {
1010 $echo : Echo ;
1111 }
1212
13+ // Nuxt 2.14+
1314 interface NuxtConfig {
1415 echo ?: Partial < ModuleOptions >
1516 }
1617
18+ // Nuxt 2.9 - 2.13
1719 interface Configuration {
1820 echo ?: Partial < ModuleOptions >
1921 }
Original file line number Diff line number Diff line change @@ -8,4 +8,8 @@ export interface ModuleOptions extends EchoOptions {
88 connectOnLogin ?: boolean ,
99 disconnectOnLogout ?: boolean ,
1010 optionsPath ?: string ,
11+ onBeforeConnect ?: Function ,
12+ onAfterConnect ?: Function ,
13+ onBeforeDisconnect ?: Function ,
14+ onAfterDisconnect ?: Function ,
1115}
You can’t perform that action at this time.
0 commit comments