-
Notifications
You must be signed in to change notification settings - Fork 350
Code Deep Dive
giongto35 edited this page May 12, 2021
·
9 revisions
Room is the core building block of Cloud Gaming stream in CloudRetro. Room Includes Emulator + Encoder + WebRTC
-
func NewRoom(roomID string, game games.GameMetadata, onlineStorage *storage.Client, cfg worker.Config): Create a New Game Room: Initialize Game Emulator, Encoder, Video Stream Listener, Audio Stream Listener inside.
- for input := range peerconnection.InputChannel: Listen from PeerConnection Data Channel Input and pass to Emulator.
- webRTC.ImageChannel <- webrtc.WebFrame{Data: data.Data, Timestamp: data.Timestamp} : Pass image from emulator to WebRTC Video stream
- webRTC.AudioChannel <- audio : Pass audio from emulator to WebRTC Audio Stream
Worker runs multiple gaming sessions inside a worker. User communicates with Worker directly over P2P connection.
- func NewHandler(cfg worker.Config, wrk *Worker) *Handler : Worker Handler includes Rooms, Cloud Storage, User Sessions, and connection with Coordinator.
User firstly connects to Coordinator. Coordinator first finds the best worker to user and setup WebRTC connection between user and worker. After WebRTC connection is setup, Coordinator is no longer involved.
- func (o *Server) getBestWorkerClient(client *BrowserClient, zone string) (*WorkerClient, error) : get Best Worker Client for new user
- bc.Send(cws.WSPacket{ID: "init", Data: createInitPackage(}, nil) : First init message that trigger peer to peer connection setup
-
func (o *Server) useragentRoutes(bc *BrowserClient) : User's Routing to setup Peer to Peer Connection
- https://github.com/giongto35/cloud-game/blob/master/docs/STREAMING.md : Detailed flow of WebRTC connection setup