Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
load(
"@io_bazel_rules_go//proto:def.bzl",
"go_proto_library",
)
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
proto_library(
name = "v1_proto",
srcs = ["api.proto"],
tags = ["automanaged"],
deps = ["@gogo_special_proto//github.com/gogo/protobuf/gogoproto"],
)
go_proto_library(
name = "v1_go_proto",
compilers = ["@io_bazel_rules_go//proto:gogofast_grpc"],
importpath = "go-common/app/service/live/rtc/api/v1",
proto = ":v1_proto",
tags = ["automanaged"],
deps = ["@com_github_gogo_protobuf//gogoproto:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = [
"api.bm.go",
"client.go",
"generate.go",
],
embed = [":v1_go_proto"],
importpath = "go-common/app/service/live/rtc/api/v1",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/binding:go_default_library",
"//library/net/rpc/warden:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_x_net//context:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,153 @@
// Code generated by protoc-gen-bm v0.1, DO NOT EDIT.
// source: api.proto
/*
Package v1 is a generated blademaster stub package.
This code was generated with go-common/app/tool/bmgen/protoc-gen-bm v0.1.
package 命名使用 {discovery_id}.{version} 的方式, version 形如 v1, v2, v1beta ..
NOTE: 不知道的 discovery_id 请询问大佬, 新项目找大佬申请 discovery_id先到先得抢注
e.g. account.service.v1
It is generated from these files:
api.proto
*/
package v1
import (
"context"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/binding"
)
// to suppressed 'imported but not used warning'
var _ *bm.Context
var _ context.Context
var _ binding.StructValidator
var PathRtcJoinChannel = "/live.rtc.v1.Rtc/JoinChannel"
var PathRtcLeaveChannel = "/live.rtc.v1.Rtc/LeaveChannel"
var PathRtcPublishStream = "/live.rtc.v1.Rtc/PublishStream"
var PathRtcTerminateStream = "/live.rtc.v1.Rtc/TerminateStream"
var PathRtcChannel = "/live.rtc.v1.Rtc/Channel"
var PathRtcStream = "/live.rtc.v1.Rtc/Stream"
var PathRtcSetRtcConfig = "/live.rtc.v1.Rtc/SetRtcConfig"
var PathRtcVerifyToken = "/live.rtc.v1.Rtc/VerifyToken"
// =============
// Rtc Interface
// =============
type RtcBMServer interface {
// `method:"POST"`
JoinChannel(ctx context.Context, req *JoinChannelRequest) (resp *JoinChannelResponse, err error)
// `method:"POST"`
LeaveChannel(ctx context.Context, req *LeaveChannelRequest) (resp *LeaveChannelResponse, err error)
// `method:"POST"`
PublishStream(ctx context.Context, req *PublishStreamRequest) (resp *PublishStreamResponse, err error)
// `method:"POST"`
TerminateStream(ctx context.Context, req *TerminateStreamRequest) (resp *TerminateStreamResponse, err error)
// `method:"GET"`
Channel(ctx context.Context, req *ChannelRequest) (resp *ChannelResponse, err error)
// `method:"GET"`
Stream(ctx context.Context, req *StreamRequest) (resp *StreamResponse, err error)
// `method:"POST"`
SetRtcConfig(ctx context.Context, req *SetRtcConfigRequest) (resp *SetRtcConfigResponse, err error)
// `method:"GET"`
VerifyToken(ctx context.Context, req *VerifyTokenRequest) (resp *VerifyTokenResponse, err error)
}
var v1RtcSvc RtcBMServer
func rtcJoinChannel(c *bm.Context) {
p := new(JoinChannelRequest)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RtcSvc.JoinChannel(c, p)
c.JSON(resp, err)
}
func rtcLeaveChannel(c *bm.Context) {
p := new(LeaveChannelRequest)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RtcSvc.LeaveChannel(c, p)
c.JSON(resp, err)
}
func rtcPublishStream(c *bm.Context) {
p := new(PublishStreamRequest)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RtcSvc.PublishStream(c, p)
c.JSON(resp, err)
}
func rtcTerminateStream(c *bm.Context) {
p := new(TerminateStreamRequest)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RtcSvc.TerminateStream(c, p)
c.JSON(resp, err)
}
func rtcChannel(c *bm.Context) {
p := new(ChannelRequest)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RtcSvc.Channel(c, p)
c.JSON(resp, err)
}
func rtcStream(c *bm.Context) {
p := new(StreamRequest)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RtcSvc.Stream(c, p)
c.JSON(resp, err)
}
func rtcSetRtcConfig(c *bm.Context) {
p := new(SetRtcConfigRequest)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RtcSvc.SetRtcConfig(c, p)
c.JSON(resp, err)
}
func rtcVerifyToken(c *bm.Context) {
p := new(VerifyTokenRequest)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RtcSvc.VerifyToken(c, p)
c.JSON(resp, err)
}
// RegisterRtcBMServer Register the blademaster route
func RegisterRtcBMServer(e *bm.Engine, server RtcBMServer) {
v1RtcSvc = server
e.POST("/live.rtc.v1.Rtc/JoinChannel", rtcJoinChannel)
e.POST("/live.rtc.v1.Rtc/LeaveChannel", rtcLeaveChannel)
e.POST("/live.rtc.v1.Rtc/PublishStream", rtcPublishStream)
e.POST("/live.rtc.v1.Rtc/TerminateStream", rtcTerminateStream)
e.GET("/live.rtc.v1.Rtc/Channel", rtcChannel)
e.GET("/live.rtc.v1.Rtc/Stream", rtcStream)
e.POST("/live.rtc.v1.Rtc/SetRtcConfig", rtcSetRtcConfig)
e.GET("/live.rtc.v1.Rtc/VerifyToken", rtcVerifyToken)
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,151 @@
// 定义项目 API 的 proto 文件 可以同时描述 gRPC 和 HTTP API
// protobuf 文件参考:
// - https://developers.google.com/protocol-buffers/
// - http://info.bilibili.co/display/documentation/gRPC+Proto
// protobuf 生成 HTTP 工具:
// - http://git.bilibili.co/platform/go-common/tree/master/app/tool/protoc-gen-bm
syntax = "proto3";
// package 命名使用 {discovery_id}.{version} 的方式, version 形如 v1, v2, v1beta ..
// NOTE: 不知道的 discovery_id 请询问大佬, 新项目找大佬申请 discovery_id先到先得抢注
// e.g. account.service.v1
package live.rtc.v1;
//option go_package = "v1";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
// NOTE: 最后请删除这些无用的注释 (゜-゜)つロ
// 呵呵 我特么偏不删(゜-゜)つロ
option go_package = "v1";
service Rtc {
// `method:"POST"`
rpc JoinChannel(JoinChannelRequest) returns (JoinChannelResponse);
// `method:"POST"`
rpc LeaveChannel(LeaveChannelRequest) returns (LeaveChannelResponse);
// `method:"POST"`
rpc PublishStream(PublishStreamRequest) returns (PublishStreamResponse);
// `method:"POST"`
rpc TerminateStream(TerminateStreamRequest) returns (TerminateStreamResponse);
// `method:"GET"`
rpc Channel(ChannelRequest) returns (ChannelResponse);
// `method:"GET"`
rpc Stream(StreamRequest) returns (StreamResponse);
// `method:"POST"`
rpc SetRtcConfig(SetRtcConfigRequest) returns (SetRtcConfigResponse);
// `method:"GET"`
rpc VerifyToken(VerifyTokenRequest) returns (VerifyTokenResponse);
}
message MediaSource {
enum MediaType{
OTHER = 0;
VIDEO = 1;
AUDIO = 2;
DATA = 3;
SMALL_VIDEO = 4;
}
MediaType type = 1 [(gogoproto.jsontag) = "type"];
string codec = 2 [(gogoproto.jsontag) = "codec"];
string media_specific = 3 [(gogoproto.jsontag) = "media_specific"];
uint32 ssrc = 4 [(gogoproto.jsontag) = "ssrc"];
uint64 user_id = 5 [(gogoproto.jsontag) = "user_id"];
}
message EncoderConfig {
uint32 width = 1 [(gogoproto.jsontag) = "width"];
uint32 height = 2 [(gogoproto.jsontag) = "height"];
uint32 bitrate = 3 [(gogoproto.jsontag) = "bitrate"];
uint32 frame_rate = 4 [(gogoproto.jsontag) = "frame_rate"];
string video_codec = 5 [(gogoproto.jsontag) = "video_codec"];
string video_profile = 6 [(gogoproto.jsontag) = "video_profile"];
reserved 7 to 18;
uint32 channel = 19 [(gogoproto.jsontag) = "channel"];
uint32 sample_rate = 20 [(gogoproto.jsontag) = "sample_rate"];
string audio_codec = 21 [(gogoproto.jsontag) = "audio_codec"];
}
message JoinChannelRequest {
uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
uint32 proto_version = 3 [(gogoproto.jsontag) = "proto_version"];
repeated MediaSource source = 4 [(gogoproto.jsontag) = "source"];
}
message JoinChannelResponse {
uint32 call_id = 1 [(gogoproto.jsontag) = "call_id"];
string token = 2 [(gogoproto.jsontag) = "token"];
repeated MediaSource source = 3 [(gogoproto.jsontag) = "source"];
}
message LeaveChannelRequest {
uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
uint32 call_id = 3 [(gogoproto.jsontag) = "call_id"];
}
message LeaveChannelResponse {
}
message PublishStreamRequest{
uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
uint32 call_id = 3 [(gogoproto.jsontag) = "call_id"];
EncoderConfig encoder_config = 4 [(gogoproto.jsontag) = "encoder_config"];
string mix_config = 5 [(gogoproto.jsontag) = "mix_config"];
}
message PublishStreamResponse{
}
message TerminateStreamRequest{
uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
uint32 call_id = 3 [(gogoproto.jsontag) = "call_id"];
}
message TerminateStreamResponse{
}
message ChannelRequest{
uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
}
message ChannelResponse{
repeated MediaSource media_source = 1 [(gogoproto.jsontag) = "media_source"];
string server = 2 [(gogoproto.jsontag) = "server"];
uint32 tcp_port = 3 [(gogoproto.jsontag) = "tcp_port"];
uint32 udp_port = 4 [(gogoproto.jsontag) = "udp_port"];
}
message StreamRequest {
uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
uint32 call_id = 3 [(gogoproto.jsontag) = "call_id"];
}
message StreamResponse {
EncoderConfig encoder_config = 1 [(gogoproto.jsontag) = "encoder_config"];
string mix_config = 2 [(gogoproto.jsontag) = "mix_config"];
}
message SetRtcConfigRequest {
uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
uint32 call_id = 3 [(gogoproto.jsontag) = "call_id"];
string config = 4 [(gogoproto.jsontag) = "config"];
}
message SetRtcConfigResponse {
}
message VerifyTokenRequest {
uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
uint32 call_id = 2 [(gogoproto.jsontag) = "call_id"];
string token = 3 [(gogoproto.jsontag) = "token"];
}
message VerifyTokenResponse {
bool pass = 1 [(gogoproto.jsontag) = "pass"];
}

View File

@@ -0,0 +1,269 @@
<!-- package=live.rtc.v1 -->
- [/live.rtc.v1.Rtc/JoinChannel](#live.rtc.v1.RtcJoinChannel)
- [/live.rtc.v1.Rtc/LeaveChannel](#live.rtc.v1.RtcLeaveChannel)
- [/live.rtc.v1.Rtc/PublishStream](#live.rtc.v1.RtcPublishStream)
- [/live.rtc.v1.Rtc/TerminateStream](#live.rtc.v1.RtcTerminateStream)
- [/live.rtc.v1.Rtc/Channel](#live.rtc.v1.RtcChannel)
- [/live.rtc.v1.Rtc/Stream](#live.rtc.v1.RtcStream)
- [/live.rtc.v1.Rtc/SetRtcConfig](#live.rtc.v1.RtcSetRtcConfig)
- [/live.rtc.v1.Rtc/VerifyToken](#live.rtc.v1.RtcVerifyToken)
## /live.rtc.v1.Rtc/JoinChannel
### 无标题
#### 方法POST
#### 请求参数
```javascript
{
"channel_id": 0,
"user_id": 0,
"proto_version": 0,
"source": [
{
"type": 0,
"codec": "",
"media_specific": "",
"ssrc": 0,
"user_id": 0
}
]
}
```
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
"call_id": 0,
"token": "",
"source": [
{
"type": 0,
"codec": "",
"media_specific": "",
"ssrc": 0,
"user_id": 0
}
]
}
}
```
## /live.rtc.v1.Rtc/LeaveChannel
### 无标题
#### 方法POST
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|channel_id|否|integer||
|user_id|否|integer||
|call_id|否|integer||
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
}
}
```
## /live.rtc.v1.Rtc/PublishStream
### 无标题
#### 方法POST
#### 请求参数
```javascript
{
"channel_id": 0,
"user_id": 0,
"call_id": 0,
"encoder_config": {
"width": 0,
"height": 0,
"bitrate": 0,
"frame_rate": 0,
"video_codec": "",
"video_profile": "",
"channel": 0,
"sample_rate": 0,
"audio_codec": ""
},
"mix_config": ""
}
```
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
}
}
```
## /live.rtc.v1.Rtc/TerminateStream
### 无标题
#### 方法POST
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|channel_id|否|integer||
|user_id|否|integer||
|call_id|否|integer||
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
}
}
```
## /live.rtc.v1.Rtc/Channel
### 无标题
#### 方法GET
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|channel_id|否|integer||
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
"media_source": [
{
"type": 0,
"codec": "",
"media_specific": "",
"ssrc": 0,
"user_id": 0
}
],
"server": "",
"tcp_port": 0,
"udp_port": 0
}
}
```
## /live.rtc.v1.Rtc/Stream
### 无标题
#### 方法GET
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|channel_id|否|integer||
|user_id|否|integer||
|call_id|否|integer||
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
"encoder_config": {
"width": 0,
"height": 0,
"bitrate": 0,
"frame_rate": 0,
"video_codec": "",
"video_profile": "",
"channel": 0,
"sample_rate": 0,
"audio_codec": ""
},
"mix_config": ""
}
}
```
## /live.rtc.v1.Rtc/SetRtcConfig
### 无标题
#### 方法POST
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|channel_id|否|integer||
|user_id|否|integer||
|call_id|否|integer||
|config|否|string||
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
}
}
```
## /live.rtc.v1.Rtc/VerifyToken
### 无标题
#### 方法GET
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|channel_id|否|integer||
|call_id|否|integer||
|token|否|string||
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
"pass": true
}
}
```

View File

@@ -0,0 +1,25 @@
package v1
import (
"context"
"go-common/library/net/rpc/warden"
"google.golang.org/grpc"
)
const kAppID = "live.rtc"
type Client struct {
RtcClient
}
// NewClient new resource grpc client
func NewClient(cfg *warden.ClientConfig, opts ...grpc.DialOption) (*Client, error) {
client := warden.NewClient(cfg, opts...)
conn, err := client.Dial(context.Background(), "discovery://default/"+kAppID)
if err != nil {
return nil, err
}
cli := &Client{}
cli.RtcClient = NewRtcClient(conn)
return cli, nil
}

View File

@@ -0,0 +1,4 @@
package v1
// 生成 gRPC 代码
//go:generate $GOPATH/src/go-common/app/tool/warden/protoc.sh