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

Added update room info method #230

Open
wants to merge 4 commits 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
7 changes: 7 additions & 0 deletions src/_library/apps/room/proto/room_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export class Request extends jspb.Message {
getSendmessage(): SendMessageRequest | undefined;
setSendmessage(value?: SendMessageRequest): void;

hasUpdateroom(): boolean;
clearUpdateroom(): void;
getUpdateroom(): UpdateRoomRequest | undefined;
setUpdateroom(value?: UpdateRoomRequest): void;

getPayloadCase(): Request.PayloadCase;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): Request.AsObject;
Expand All @@ -59,13 +64,15 @@ export namespace Request {
join?: JoinRequest.AsObject,
leave?: LeaveRequest.AsObject,
sendmessage?: SendMessageRequest.AsObject,
updateroom?: UpdateRoomRequest.AsObject,
}

export enum PayloadCase {
PAYLOAD_NOT_SET = 0,
JOIN = 1,
LEAVE = 2,
SENDMESSAGE = 3,
UPDATEROOM = 4,
}
}

Expand Down
69 changes: 65 additions & 4 deletions src/_library/apps/room/proto/room_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@
/**
* @fileoverview
* @enhanceable
* @suppress {missingRequire} reports error on implicit type usages.
* @suppress {messageConventions} JS Compiler reports an error if a variable or
* field starts with 'MSG_' and isn't a translatable message.
* @public
*/
// GENERATED CODE -- DO NOT EDIT!
/* eslint-disable */
// @ts-nocheck

var jspb = require('google-protobuf');
var goog = jspb;
var global = Function('return this')();
var global = (function() {
if (this) { return this; }
if (typeof window !== 'undefined') { return window; }
if (typeof global !== 'undefined') { return global; }
if (typeof self !== 'undefined') { return self; }
return Function('return this')();
}.call(null));

goog.exportSymbol('proto.room.AddPeerReply', null, global);
goog.exportSymbol('proto.room.AddPeerRequest', null, global);
Expand Down Expand Up @@ -892,7 +901,7 @@ proto.room.Error.prototype.setReason = function(value) {
* @private {!Array<!Array<number>>}
* @const
*/
proto.room.Request.oneofGroups_ = [[1,2,3]];
proto.room.Request.oneofGroups_ = [[1,2,3,4]];

/**
* @enum {number}
Expand All @@ -901,7 +910,8 @@ proto.room.Request.PayloadCase = {
PAYLOAD_NOT_SET: 0,
JOIN: 1,
LEAVE: 2,
SENDMESSAGE: 3
SENDMESSAGE: 3,
UPDATEROOM: 4
};

/**
Expand Down Expand Up @@ -944,7 +954,8 @@ proto.room.Request.toObject = function(includeInstance, msg) {
var f, obj = {
join: (f = msg.getJoin()) && proto.room.JoinRequest.toObject(includeInstance, f),
leave: (f = msg.getLeave()) && proto.room.LeaveRequest.toObject(includeInstance, f),
sendmessage: (f = msg.getSendmessage()) && proto.room.SendMessageRequest.toObject(includeInstance, f)
sendmessage: (f = msg.getSendmessage()) && proto.room.SendMessageRequest.toObject(includeInstance, f),
updateroom: (f = msg.getUpdateroom()) && proto.room.UpdateRoomRequest.toObject(includeInstance, f)
};

if (includeInstance) {
Expand Down Expand Up @@ -996,6 +1007,11 @@ proto.room.Request.deserializeBinaryFromReader = function(msg, reader) {
reader.readMessage(value,proto.room.SendMessageRequest.deserializeBinaryFromReader);
msg.setSendmessage(value);
break;
case 4:
var value = new proto.room.UpdateRoomRequest;
reader.readMessage(value,proto.room.UpdateRoomRequest.deserializeBinaryFromReader);
msg.setUpdateroom(value);
break;
default:
reader.skipField();
break;
Expand Down Expand Up @@ -1049,6 +1065,14 @@ proto.room.Request.serializeBinaryToWriter = function(message, writer) {
proto.room.SendMessageRequest.serializeBinaryToWriter
);
}
f = message.getUpdateroom();
if (f != null) {
writer.writeMessage(
4,
f,
proto.room.UpdateRoomRequest.serializeBinaryToWriter
);
}
};


Expand Down Expand Up @@ -1163,6 +1187,43 @@ proto.room.Request.prototype.hasSendmessage = function() {
};


/**
* optional UpdateRoomRequest updateRoom = 4;
* @return {?proto.room.UpdateRoomRequest}
*/
proto.room.Request.prototype.getUpdateroom = function() {
return /** @type{?proto.room.UpdateRoomRequest} */ (
jspb.Message.getWrapperField(this, proto.room.UpdateRoomRequest, 4));
};


/**
* @param {?proto.room.UpdateRoomRequest|undefined} value
* @return {!proto.room.Request} returns this
*/
proto.room.Request.prototype.setUpdateroom = function(value) {
return jspb.Message.setOneofWrapperField(this, 4, proto.room.Request.oneofGroups_[0], value);
};


/**
* Clears the message field making it undefined.
* @return {!proto.room.Request} returns this
*/
proto.room.Request.prototype.clearUpdateroom = function() {
return this.setUpdateroom(undefined);
};


/**
* Returns whether this field is set.
* @return {boolean}
*/
proto.room.Request.prototype.hasUpdateroom = function() {
return jspb.Message.getField(this, 4) != null;
};



/**
* Oneof group definitions for this message. Each group defines the field
Expand Down
13 changes: 12 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export class Transport {
};

this.pc.oniceconnectionstatechange = async (e) => {
if (this.pc.iceConnectionState === 'disconnected') {
// iOS iceConnectionState can go straight to "failed" without emitting "disconnected"
if (this.pc.iceConnectionState === 'disconnected' || this.pc.iceConnectionState === 'failed') {
if (this.pc.restartIce !== undefined) {
// this will trigger onNegotiationNeeded
this.pc.restartIce();
Expand Down Expand Up @@ -139,6 +140,7 @@ export default class Client {
});

const offer = await this.transports[Role.pub].pc.createOffer();

await this.transports[Role.pub].pc.setLocalDescription(offer);
const answer = await this.signal.join(sid, uid, offer);
await this.transports[Role.pub].pc.setRemoteDescription(answer);
Expand Down Expand Up @@ -238,8 +240,17 @@ export default class Client {
let answer: RTCSessionDescriptionInit | undefined;
try {
offer = await this.transports[Role.pub].pc.createOffer({ iceRestart });
// Set video send bitrate
// var opts = {
// videoSendBitrate: 20000,
// videoSendInitialBitrate: 5000
// };
// offer.sdp = sdputils.maybeSetVideoSendInitialBitRate(offer.sdp, opts);
// offer.sdp = sdputils.maybeSetVideoSendBitRate(offer.sdp, opts);
//offer.sdp = offer.sdp.replace(/(a=fmtp:\d+ .*level-asymmetry-allowed=.*)\r\n/gm, "$1;x-google-start-bitrate=300;x-google-min-bitrate=500;x-google-max-bitrate=500\r\n");
await this.transports[Role.pub].pc.setLocalDescription(offer);
answer = await this.signal.offer(offer);
console.log("ANSWER = ", answer);
await this.transports[Role.pub].pc.setRemoteDescription(answer);
} catch (err) {
/* tslint:disable-next-line:no-console */
Expand Down
34 changes: 34 additions & 0 deletions src/connector/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export class Room implements Service {
return this._rpc?.sendMessage(sid, from, to, mineType, data);
}

async updateRoom(roomInfo: RoomInfo) : Promise<void> {
return this._rpc?.updateRoom(roomInfo);
}

connect(): void {
if (!this._rpc) {
this._rpc = new RoomGRPCClient(this, this.connector);
Expand Down Expand Up @@ -345,6 +349,36 @@ class RoomGRPCClient extends EventEmitter {
});
}

async updateRoom(rinfo: RoomInfo) {
const request = new room.Request();
const updateRoom = new room.UpdateRoomRequest();

const r = new room.Room();
r.setSid(rinfo.sid);
r.setName(rinfo.name);
r.setLock(rinfo.lock);
r.setPassword(rinfo.password);
r.setDescription(rinfo.description);
r.setMaxpeers(rinfo.maxpeers);
updateRoom.setRoom(r);
request.setUpdateroom(updateRoom);
this._client.send(request);

return new Promise<void>((resolve, reject) => {
// TODO: handle reply
resolve();
});
}

async updatePeer(pinfo: RoomInfo) {
const request = new room.Request()
const updatePeer = new room.UpdatePeerRequest();
const p = new room.Peer();
updatePeer.setPeer(p);

// TODO
}

mapToObj(map: Map<string, any>){
if (!map) {
return {};
Expand Down
2 changes: 2 additions & 0 deletions src/connector/rtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ class RTCGRPCSignal implements Signal {
}
constructor(service: Service, connector: Connector) {
this.connector = connector;
// Eugene G: Remove limit on max events.
this._event.setMaxListeners(0);
const client = grpc.client(sfu_rpc.RTC.Signal, this.connector.grpcClientRpcOptions()) as grpc.Client<pb.Request, pb.Reply>;
client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) =>
connector.onEnd(service, status, statusMessage, trailers));
Expand Down
24 changes: 19 additions & 5 deletions src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ interface VideoConstraints {
};
}

const resolutions = ['qvga', 'vga', 'shd', 'hd', 'fhd', 'qhd'] as const;
const resolutions = ['qvga', 'vga', 'shd', 'hd', 'fhd', 'qhd', 'uhd'] as const;

export const VideoConstraints: VideoConstraints = {
qvga: {
resolution: {
width: { ideal: 320 },
height: { ideal: 180 },
frameRate: {
ideal: 15,
ideal: 30,
max: 30,
},
},
encodings: {
maxBitrate: 150_000,
maxFramerate: 15.0,
maxFramerate: 30.0,
},
},
vga: {
Expand Down Expand Up @@ -83,7 +83,7 @@ export const VideoConstraints: VideoConstraints = {
qhd: {
resolution: {
width: { ideal: 2560 },
height: { ideal: 1440 },
height: { ideal: 1280 },
frameRate: {
ideal: 30,
max: 60,
Expand All @@ -94,6 +94,20 @@ export const VideoConstraints: VideoConstraints = {
maxFramerate: 30.0,
},
},
uhd: {
resolution: {
width: { ideal: 4096 },
height: { ideal: 2048 },
frameRate: {
ideal: 30,
max: 60,
},
},
encodings: {
maxBitrate: 20_000_000,
maxFramerate: 30.0,
},
},
};

export type Layer = 'low' | 'medium' | 'high';
Expand Down Expand Up @@ -255,7 +269,7 @@ export class LocalStream extends MediaStream {
let selCodec: RTCRtpCodecCapability | undefined;
// 42e01f for safari/chrome/firefox cross-browser compatibility
if (kind === 'video' && this.constraints.codec && this.constraints.codec.toLowerCase() === 'h264') {
this.constraints.preferredCodecProfile = '42e01f'
//this.constraints.preferredCodecProfile = '42e01f'
}
if (this.constraints.preferredCodecProfile && kind === 'video') {
const allCodecProfiles = cap.codecs.filter(
Expand Down