-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add proto files. * Add more interface. * update *_pb. * add IonConnector. * update.
- Loading branch information
1 parent
fcd3724
commit b351608
Showing
22 changed files
with
4,795 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import Client from './client'; | ||
import { LocalStream, RemoteStream, Constraints } from './stream'; | ||
import { Signal, Trickle } from './signal'; | ||
export { Client, LocalStream, RemoteStream, Constraints, Signal, Trickle }; | ||
export { Client, LocalStream, RemoteStream, Constraints, Signal, Trickle }; |
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,156 @@ | ||
import Client, { Configuration } from './client'; | ||
import { LocalStream, RemoteStream, Constraints } from './stream'; | ||
import { BizClient } from './signal/biz'; | ||
import { IonSFUGRPCWebSignal } from './signal/grpc-web-impl'; | ||
import { Signal, Trickle } from './signal'; | ||
export { Client, LocalStream, RemoteStream, Constraints, Signal, Trickle }; | ||
|
||
export interface JoinResult { | ||
success: boolean; | ||
reason: string; | ||
} | ||
|
||
export enum PeerState { | ||
NONE, | ||
JOIN, | ||
UPDATE, | ||
LEAVE, | ||
} | ||
|
||
export interface Peer { | ||
uid: string; | ||
sid: string; | ||
info: Map<string, any>; | ||
} | ||
|
||
export interface PeerEvent { | ||
state: PeerState; | ||
peer: Peer; | ||
} | ||
|
||
export enum StreamState { | ||
NONE, | ||
ADD, | ||
REMOVE, | ||
} | ||
|
||
export interface StreamEvent { | ||
uid: string; | ||
state: StreamState; | ||
streams: Stream[]; | ||
} | ||
|
||
export interface Track { | ||
id: string; | ||
label: string; | ||
kind: string; | ||
simulcast: Map<string,string>; | ||
} | ||
|
||
export interface Stream { | ||
id: string; | ||
tracks: Track[]; | ||
} | ||
|
||
export interface Message { | ||
from: string ; | ||
to: string; | ||
data: Map<string, any>; | ||
} | ||
|
||
export class IonConnector { | ||
private _biz: BizClient; | ||
private _sfu: Client | undefined; | ||
private _sid: string; | ||
private _uid: string; | ||
|
||
onerror?:(err: Error) => void; | ||
|
||
onjoin?:(success: boolean, reason: string) => void; | ||
|
||
onleave?:(reason: string) => void; | ||
|
||
onpeerevent?: (ev: PeerEvent) => void; | ||
|
||
onstreamevent?: (ev: StreamEvent) => void; | ||
|
||
onmessage?:(msg: Message) => void; | ||
|
||
ontrack?: (track: MediaStreamTrack, stream: RemoteStream) => void; | ||
|
||
ondatachannel?: (ev: RTCDataChannelEvent) => void; | ||
|
||
onspeaker?: (ev: string[]) => void; | ||
|
||
constructor(url: string, config?: Configuration) { | ||
this._sid = ""; | ||
this._uid = ""; | ||
this._sfu = undefined; | ||
this._biz = new BizClient(url); | ||
|
||
this._biz.on("join-reply", async (success: boolean, reason: string) => { | ||
if (this.onjoin) { | ||
this.onjoin(success, reason); | ||
} | ||
if (success && !this._sfu) { | ||
const signal = new IonSFUGRPCWebSignal(url); | ||
const sfu = new Client(signal, config); | ||
|
||
sfu.ontrack = (track: MediaStreamTrack, stream: RemoteStream) => | ||
this.ontrack?.call(this, track, stream); | ||
sfu.ondatachannel = (ev: RTCDataChannelEvent) => | ||
this.ondatachannel?.call(this, ev); | ||
sfu.onspeaker = (ev: string[]) => this.onspeaker?.call(this, ev); | ||
|
||
await sfu.join(this._sid, this._uid); | ||
|
||
this._sfu = sfu; | ||
} | ||
}); | ||
|
||
this._biz.on("leave-reply", (reason: string) => { | ||
if (this.onleave) { | ||
this.onleave(reason); | ||
} | ||
}); | ||
|
||
this._biz.on("peer-event", (ev: PeerEvent) => { | ||
if(this.onpeerevent) { | ||
this.onpeerevent(ev); | ||
} | ||
}) | ||
|
||
this._biz.on("stream-event", (ev: StreamEvent) => { | ||
if(this.onstreamevent) { | ||
this.onstreamevent(ev); | ||
} | ||
}) | ||
|
||
this._biz.on("message", (msg: Message) => { | ||
if(this.onmessage) { | ||
this.onmessage(msg); | ||
} | ||
}) | ||
} | ||
|
||
get sfu() { return this._sfu; } | ||
|
||
async join(sid: string, uid: string, info: Map<string, any>, token: string | undefined): Promise<JoinResult> { | ||
this._sid = sid; | ||
this._uid = uid; | ||
return this._biz.join(sid, uid, info, token); | ||
} | ||
|
||
async leave(uid: string): Promise<string> { | ||
return this._biz.leave(uid) | ||
} | ||
|
||
async message(from: string, to: string, data: Map<string, any>): Promise<void> { | ||
return this._biz.sendMessage(from, to, data); | ||
} | ||
|
||
close() { | ||
this._sfu?.close(); | ||
this._biz.close(); | ||
} | ||
} |
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,47 @@ | ||
syntax = "proto3"; | ||
|
||
import "ion.proto"; | ||
|
||
option go_package = "github.com/pion/ion/pkg/grpc/biz"; | ||
|
||
package biz; | ||
|
||
service Biz { | ||
rpc Signal(stream SignalRequest) returns (stream SignalReply); | ||
} | ||
|
||
message Join { | ||
ion.Peer peer = 1; | ||
string token = 2; | ||
} | ||
|
||
message JoinReply { | ||
bool success = 1; | ||
string reason = 2; | ||
} | ||
|
||
message Leave { | ||
string uid = 1; | ||
} | ||
|
||
message LeaveReply { | ||
string reason = 1; | ||
} | ||
|
||
message SignalRequest { | ||
oneof payload { | ||
Join join = 1; | ||
Leave leave = 2; | ||
ion.Message msg = 4; | ||
} | ||
} | ||
|
||
message SignalReply { | ||
oneof payload { | ||
JoinReply joinReply = 1; | ||
LeaveReply leaveReply = 2; | ||
ion.PeerEvent peerEvent = 3; | ||
ion.StreamEvent streamEvent = 4; | ||
ion.Message msg = 5; | ||
} | ||
} |
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,90 @@ | ||
syntax = "proto3"; | ||
|
||
option go_package = "github.com/pion/ion/pkg/grpc/ion"; | ||
|
||
package ion; | ||
|
||
message Empty {} | ||
|
||
message Error { | ||
int32 code = 1; | ||
string reason = 2; | ||
} | ||
|
||
message Track { | ||
string id = 1; | ||
string label = 2; | ||
string kind = 3; | ||
map<string, string> simulcast = 4; | ||
} | ||
|
||
message Stream { | ||
string id = 1; | ||
repeated Track tracks = 2; | ||
} | ||
|
||
message Peer { | ||
string sid = 1; | ||
string uid = 2; | ||
bytes info = 3; | ||
} | ||
|
||
// Describe the basic media info in the session of sfu. | ||
// Write session state key/value to redis | ||
// key = dc1/${nid}/${sid}/${uid} | ||
// key => dc1/sfu-node-01/room1/peer1 | ||
// value => [ | ||
// ${msid}: [{id: ${trackId}, kind:audio}, {id: ${trackId}, kind:video, rid: 'f'}, {id: ${trackId}, kind:video, rid: 'h'},{id: ${trackId}, kind:video, rid: 'q'}] | ||
// ${msid}: [{id: ${trackId}, kind:audio}, {id: ${trackId}, kind:video}] | ||
// ] | ||
|
||
message SessionEvent { | ||
enum State { | ||
ADD = 0; | ||
REMOVE = 1; | ||
} | ||
State state = 2; | ||
string nid = 3; | ||
string sid = 4; | ||
} | ||
|
||
message StreamEvent { | ||
enum State { | ||
ADD = 0; | ||
REMOVE = 1; | ||
} | ||
State state = 2; | ||
string nid = 3; | ||
string sid = 4; | ||
string uid = 5; | ||
repeated ion.Stream streams = 6; | ||
} | ||
|
||
message PeerEvent { | ||
enum State { | ||
JOIN = 0; | ||
UPDATE = 1; | ||
LEAVE = 2; | ||
} | ||
State state = 3; | ||
ion.Peer peer = 4; | ||
} | ||
|
||
message Message { | ||
string from = 1; | ||
string to = 2; | ||
bytes data = 3; | ||
} | ||
|
||
message RPC { | ||
string protocol = 1; | ||
string addr = 2; | ||
map<string, string> params = 3; | ||
} | ||
|
||
message Node { | ||
string dc = 1; | ||
string nid = 2; | ||
string service = 3; | ||
RPC rpc = 4; | ||
} |
Oops, something went wrong.