Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nakama console send match signal #981

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions console/console.proto
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ service Console {
option (google.api.http).get = "/v2/console/match/{id}/state";
}

// Send signal to specific match id
rpc SendMatchSignal (MatchSignalRequest) returns (MatchSignalResponse) {
option (google.api.http).post = "/v2/console/match/{id}/signal/{signal}";
}

// Get runtime info
rpc GetRuntime (google.protobuf.Empty) returns (RuntimeInfo) {
option (google.api.http).get = "/v2/console/runtime";
Expand Down Expand Up @@ -823,6 +828,19 @@ message MatchStateRequest {
string id = 1;
}

// Perform match signal
message MatchSignalRequest {
// Match ID
string id = 1;
// Signal
string signal = 2;
}

message MatchSignalResponse {
// Match Signal Result
string result = 1;
}

message DeleteChannelMessagesResponse {
// Total number of messages deleted.
int64 total = 1;
Expand Down
14 changes: 14 additions & 0 deletions console/ui/src/app/console.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ export interface MatchListMatch {
node?:string
}

export interface MatchSignalResponse {
// Match Signal Result
result?:string
}

export interface MatchState {
// Presence list.
presences?:Array<RealtimeUserPresence>
Expand Down Expand Up @@ -1269,6 +1274,15 @@ export class ConsoleService {
return this.httpClient.get<MatchList>(this.config.host + urlPath, { params: params, headers: this.getTokenAuthHeaders(auth_token) })
}

/** Send signal to specific match id */
sendMatchSignal(auth_token: string, id: string, signal: string): Observable<MatchSignalResponse> {
id = encodeURIComponent(String(id))
signal = encodeURIComponent(String(signal))
const urlPath = `/v2/console/match/${id}/signal/${signal}`;
let params = new HttpParams();
return this.httpClient.post<MatchSignalResponse>(this.config.host + urlPath, { params: params, headers: this.getTokenAuthHeaders(auth_token) })
}

/** Get current state of a running match */
getMatchState(auth_token: string, id: string): Observable<MatchState> {
id = encodeURIComponent(String(id))
Expand Down
13 changes: 13 additions & 0 deletions console/ui/src/app/matches/matches.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ <h6 class="mr-2 d-inline font-weight-bold">An error occurred: {{error}}</h6>
<small><b>Match Label</b></small>

<pre class="pre-wrap m-0 p-0"><small>{{m.api_match.label}}</small></pre>

<small><b>Match Signal</b></small>
<form [formGroup]="signalForm" (ngSubmit)="sendMatchSignal(i, m, signal.value)">
<div class="input-group">
<input type="text" class="form-control border-right-0" formControlName="signal" placeholder="Signal" #signal/>
<button type="submit" class="btn btn-secondary" [disabled]="signal.value.length==0">Send</button>
</div>
</form>
<pre class="pre-wrap m-0 p-0" *ngIf="matchSignalResult[i]"><small>{{matchSignalResult[i]}}</small></pre>
<ngb-alert [dismissible]="true" type="danger" *ngIf="matchSignalError[i]" (click)="matchSignalError[i]=null">
<img src="/static/svg/red-triangle.svg" alt="" width="16" height="" class="mr-2">
<h6 class="mr-2 d-inline font-weight-bold">{{matchSignalError[i]}}</h6>
</ngb-alert>
</div>

<div class="p-3 w-33 border border-left-0">
Expand Down
16 changes: 16 additions & 0 deletions console/ui/src/app/matches/matches.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export class MatchesComponent implements OnInit {
public matches: Array<MatchListMatch> = [];
public matchStates: Array<MatchState> = [];
public matchStatesOpen: Array<boolean> = [];
public matchSignalResult: Array<string> = [];
public matchSignalError: Array<string> = [];
public updated = false;
public signalForm: FormGroup;
public searchForm1: FormGroup;
public searchForm2: FormGroup;
public searchForm3: FormGroup; //Authoritative
Expand All @@ -50,6 +53,9 @@ export class MatchesComponent implements OnInit {
private readonly formBuilder: FormBuilder,
private readonly consoleService: ConsoleService,
) {
this.signalForm = this.formBuilder.group({
signal: '', result: '',
})
this.searchForm1 = this.formBuilder.group({
match_id: '',
});
Expand Down Expand Up @@ -185,6 +191,16 @@ export class MatchesComponent implements OnInit {
});
}

sendMatchSignal(i: number, match: MatchListMatch, signal: string) : void {
this.consoleService.sendMatchSignal('', match.api_match.match_id, signal).subscribe(d => {
this.matchSignalResult[i] = d.result;
this.matchSignalError[i] = null;
}, err => {
this.matchSignalResult[i] = null;
this.matchSignalError[i] = err;
});
}

getMatchPresencesString(ps: Array<RealtimeUserPresence>): string {
return JSON.stringify(ps);
}
Expand Down
8 changes: 8 additions & 0 deletions server/console_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,11 @@ func (s *ConsoleServer) GetMatchState(ctx context.Context, in *console.MatchStat

return &console.MatchState{Presences: presences, Tick: tick, State: state}, nil
}

func (s *ConsoleServer) SendMatchSignal(ctx context.Context, in *console.MatchSignalRequest) (*console.MatchSignalResponse, error) {
result, err := s.matchRegistry.Signal(ctx, in.Id, in.Signal)
if err != nil {
return nil, status.Error(codes.Aborted, err.Error())
}
return &console.MatchSignalResponse{Result: result}, nil
}