This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(socket): Refactoring for 2.0.0 * chore(socket): Fixed empty middleware issue && adjusted example accordingly * chore(socket): Small polishing, plus added WrapperClass option for IO Decorator
- Loading branch information
Showing
23 changed files
with
758 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,32 @@ | ||
import { listen } from 'socket.io'; | ||
import { | ||
Middleware, | ||
GlobalMiddleware, | ||
ServerMiddleware, | ||
Event, | ||
attachControllers, | ||
Controller, | ||
Socket, | ||
Args, | ||
bootstrapSocketIO, | ||
Namespace, | ||
Socket | ||
IO, | ||
Ack | ||
} from '@decorators/socket'; | ||
|
||
const server = listen(3000); | ||
|
||
class SocketWrapper { | ||
constructor(private socket: SocketIO.Socket) {} | ||
|
||
log() { | ||
console.log('Log'); | ||
class Wrapper { | ||
constructor(data: any) { | ||
console.log('Wrapper'); | ||
} | ||
} | ||
|
||
@ServerMiddleware((io, socket, next) => { | ||
console.log('Global Server Middleware'); | ||
next(); | ||
}) | ||
@GlobalMiddleware((io, socket, packet, next) => { | ||
console.log('Global socket middleware'); | ||
next(); | ||
}) | ||
@Middleware((io, socket, packet, next) => { | ||
console.log('Controller based middleware'); | ||
next(); | ||
}) | ||
@Namespace('/messaging') | ||
class FirstController { | ||
|
||
constructor(...args) { | ||
console.log(args); | ||
} | ||
@Controller('/') | ||
class MessagingController { | ||
|
||
@Event('message', (io, socket, packet, next) => { | ||
console.log('Message middleware'); | ||
next(); | ||
}) | ||
onMessage(@Args() message, @Socket(SocketWrapper) socket: SocketWrapper) { | ||
socket.log(); | ||
console.log(`Message: ${message}`); | ||
@Event('message') | ||
onMessage(@Args() message: string) { | ||
console.log( | ||
`Message: ${message}` | ||
); | ||
} | ||
|
||
} | ||
|
||
bootstrapSocketIO(server, [ | ||
{ provide: FirstController, deps: [1, 2, 3]} | ||
]); | ||
attachControllers(server, [ MessagingController ]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.