-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #456 from CodingFactory-Repos/develop-G6
Implement the text-input and the blueprints with the text
- Loading branch information
Showing
31 changed files
with
1,003 additions
and
332 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { JwtService } from '@nestjs/jwt'; | ||
import { Server } from 'socket.io'; | ||
import { Inject, UseFilters, forwardRef } from '@nestjs/common'; | ||
import { | ||
WebSocketGateway, | ||
WebSocketServer, | ||
OnGatewayInit, | ||
OnGatewayConnection, | ||
OnGatewayDisconnect, | ||
SubscribeMessage, | ||
} from '@nestjs/websockets'; | ||
|
||
import { WSServiceErrorCatcher } from '@/common/decorators/ws.catch.decorator'; | ||
import { AuthSocket, WSAuthMiddleware } from '@/common/middlewares/socket.auth.middleware'; | ||
import { | ||
ElementPosition, | ||
} from '@/base/canvasRoom/interfaces/ws.canvasRoom.interface'; | ||
import { UsersRepository } from '@/base/users/users.repository'; | ||
import { ObjectId } from 'mongodb'; | ||
|
||
@UseFilters(WSServiceErrorCatcher) | ||
@WebSocketGateway({ | ||
transports: ['websocket'], | ||
cors: { | ||
origin: '*', // to be defined later | ||
}, | ||
namespace: 'cursor', | ||
}) | ||
export class CursorGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect { | ||
constructor( | ||
@Inject(forwardRef(() => UsersRepository)) | ||
private usersRepository: UsersRepository, | ||
private readonly jwtService: JwtService, | ||
) {} | ||
@WebSocketServer() server: Server; | ||
|
||
afterInit(server: Server) { | ||
server.use(WSAuthMiddleware(this.jwtService)); | ||
} | ||
|
||
async handleConnection(client: AuthSocket) { | ||
const query = { _id: client.user.id as ObjectId }; | ||
const projection = { projection: { profile: { email: 1 } } }; | ||
const user = await this.usersRepository.findOne(query, projection); | ||
|
||
client.join(client.roomId); | ||
client.join(client.user.id.toString()); | ||
client.to(client.roomId).emit('peer-connected', client.id, user.profile.firstName); | ||
} | ||
|
||
async handleDisconnect(client: AuthSocket) { | ||
client.to(client.roomId).emit('peer-disconnected', client.id); | ||
} | ||
|
||
@SubscribeMessage('update-mouse-moved') | ||
handleMouseMoved(client: AuthSocket, position: ElementPosition) { | ||
client.to(client.roomId).emit('peer-mouse-moved', client.id, position); | ||
} | ||
|
||
@SubscribeMessage('connect-to-peer') | ||
handleConnectToPeer(client: AuthSocket, args: { peerId: string, firstName: string }) { | ||
client.to(args.peerId).emit('peer-connected', client.id, args.firstName, true); | ||
} | ||
} |
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 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
44 changes: 44 additions & 0 deletions
44
front-end/src/lib/pixi-tools-v2/class/socketCursorManager.ts
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Manager, ManagerOptions, Socket } from 'socket.io-client'; | ||
import { ElementPosition } from '../types/pixi-container'; | ||
import { ViewportCursor } from '../viewportCursor'; | ||
|
||
export class SocketCursorManager extends Manager { | ||
public readonly canvasSocket: Socket; | ||
public readonly peersId: Array<string>; | ||
protected readonly viewport: ViewportCursor; | ||
|
||
constructor(uri: string, roomId: string, options: Partial<ManagerOptions>, viewport: ViewportCursor, firstName: string) { | ||
super(uri, options); | ||
|
||
this.viewport = viewport; | ||
this.canvasSocket = this.socket('/cursor'); | ||
this.canvasSocket.auth = { roomId }; | ||
|
||
this.canvasSocket.on('peer-connected', (peerId: string, peerFirstName: string, forced: boolean = false) => { | ||
this.viewport.addCursorElement(peerId, peerFirstName, { x: 0, y: 0 }); | ||
|
||
if(!forced) { | ||
this.canvasSocket.emit('connect-to-peer', { peerId, firstName }); | ||
} | ||
}); | ||
|
||
this.canvasSocket.on('peer-disconnected', (peerId: string) => { | ||
const element = this.viewport.cursorElements[peerId]; | ||
if(element !== undefined) { | ||
this.viewport.removeChild(element); | ||
element.destroy(); | ||
} | ||
}); | ||
|
||
this.canvasSocket.on('peer-mouse-moved', (peerId: string, position: ElementPosition) => { | ||
const element = this.viewport.cursorElements[peerId]; | ||
if(element !== undefined) { | ||
this.viewport.updateCursorElement(element, position); | ||
} | ||
}); | ||
} | ||
|
||
public updateMouseMoved(position: ElementPosition) { | ||
this.canvasSocket.emit('update-mouse-moved', position); | ||
} | ||
} |
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
Oops, something went wrong.