Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
feat(ws): add ws provider and setup
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 12, 2016
1 parent 0ce3aef commit 783f111
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
40 changes: 40 additions & 0 deletions app/Ws/kernel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict'

const Ws = use('Ws')

/*
|--------------------------------------------------------------------------
| Global Middleware
|--------------------------------------------------------------------------
|
| Global middleware are executed on every websocket request handshake and
| must be defined inside below array.
|
*/
const globalMiddleware = [
'Adonis/Middleware/AuthInit'
]

/*
|--------------------------------------------------------------------------
| Named Middleware
|--------------------------------------------------------------------------
|
| Named middleware are key/value pairs. Keys are later used on websocket
| channels.
|
*/
const namedMiddleware = {
auth: 'Adonis/Middleware/Auth'
}

/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Here we finally register our defined middleware to Middleware provider.
|
*/
Ws.global(globalMiddleware)
Ws.named(namedMiddleware)
17 changes: 17 additions & 0 deletions app/Ws/socket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

/*
|-----------------------------------------------------------------------------
| Web Socket
|-----------------------------------------------------------------------------
|
| WebSocket provider makes it so simple for you to write realtime applications
| with the power of channels and dynamic rooms. Make use of this file to
| define channels and bind controllers next to them.
|
|
| @example
| Ws.channel('/chat', 'ChatController')
*/

const Ws = use('Ws')
6 changes: 4 additions & 2 deletions bootstrap/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const providers = [
'adonis-lucid/providers/LucidProvider',
'adonis-lucid/providers/FactoryProvider',
'adonis-middleware/providers/AppMiddlewareProvider',
'adonis-auth/providers/AuthManagerProvider'
'adonis-auth/providers/AuthManagerProvider',
'adonis-websocket/providers/WsProvider'
]

/*
Expand Down Expand Up @@ -74,7 +75,8 @@ const aliases = {
Middleware: 'Adonis/Src/Middleware',
Route: 'Adonis/Src/Route',
Schema: 'Adonis/Src/Schema',
View: 'Adonis/Src/View'
View: 'Adonis/Src/View',
Ws: 'Adonis/Addons/Ws'
}

/*
Expand Down
12 changes: 12 additions & 0 deletions bootstrap/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ module.exports = function (callback) {
use(Helpers.makeNameSpace('Http', 'kernel'))
use(Helpers.makeNameSpace('Http', 'routes'))

/*
|--------------------------------------------------------------------------
| Load Websocket Channels And Middleware
|--------------------------------------------------------------------------
|
| Websocket channels defination should be loaded before firing the Http
| server.
|
*/
use(Helpers.makeNameSpace('Ws', 'kernel'))
use(Helpers.makeNameSpace('Ws', 'socket'))

/*
|--------------------------------------------------------------------------
| Load Database Factory
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"adonis-framework": "^3.0.7",
"adonis-lucid": "^3.0.11",
"adonis-middleware": "^1.0.10",
"adonis-websocket": "^1.0.1",
"standard": "^8.6.0",
"youch": "^1.0.1"
},
Expand Down

0 comments on commit 783f111

Please sign in to comment.