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

Removing browser send offer support. #212

Merged
merged 9 commits into from
Jul 29, 2024
12 changes: 3 additions & 9 deletions Common/protobuf/signalling_messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ message playerConnected {
bool dataChannel = 2;
// True if the player connected is an SFU
bool sfu = 3;
// True if the streamer should send an offer. False if the player is offering to receive
bool sendOffer = 4;
// The ID of the player that connected.
string playerId = 5;
}
Expand All @@ -157,13 +155,9 @@ message playerDisconnected {
}

/**
* An offer message can be an offer of a WebRTC stream, or an offer to
* receive a WebRTC stream, depending on the configuration of the player.
* The default behaviour is that when a player subscribes to a streamer
* the streamer will offer the stream to the new player.
* An alternative configuration exists where a player can be configured
* to offer to receive and in that case the player will subscribe to a
* streamer and then offer to receive the stream.
* An offer message is an offer of a WebRTC stream.
* When a player subscribes to a streamer the streamer will offer the
* stream to the new player.
*/
message offer {
// Should always be 'offer'
Expand Down
24 changes: 3 additions & 21 deletions Common/src/Messages/signalling_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,6 @@ export interface playerConnected {
* @generated from protobuf field: bool sfu = 3;
*/
sfu: boolean;
/**
* True if the streamer should send an offer. False if the player is offering to receive
*
* @generated from protobuf field: bool sendOffer = 4;
*/
sendOffer: boolean;
/**
* The ID of the player that connected.
*
Expand Down Expand Up @@ -294,13 +288,9 @@ export interface playerDisconnected {
}
/**
* *
* An offer message can be an offer of a WebRTC stream, or an offer to
* receive a WebRTC stream, depending on the configuration of the player.
* The default behaviour is that when a player subscribes to a streamer
* the streamer will offer the stream to the new player.
* An alternative configuration exists where a player can be configured
* to offer to receive and in that case the player will subscribe to a
* streamer and then offer to receive the stream.
* An offer message is an offer of a WebRTC stream.
* When a player subscribes to a streamer the streamer will offer the
* stream to the new player.
*
* @generated from protobuf message offer
*/
Expand Down Expand Up @@ -1259,7 +1249,6 @@ class playerConnected$Type extends MessageType<playerConnected> {
{ no: 1, name: "type", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
{ no: 2, name: "dataChannel", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
{ no: 3, name: "sfu", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
{ no: 4, name: "sendOffer", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
{ no: 5, name: "playerId", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
]);
}
Expand All @@ -1268,7 +1257,6 @@ class playerConnected$Type extends MessageType<playerConnected> {
message.type = "";
message.dataChannel = false;
message.sfu = false;
message.sendOffer = false;
message.playerId = "";
if (value !== undefined)
reflectionMergePartial<playerConnected>(this, message, value);
Expand All @@ -1288,9 +1276,6 @@ class playerConnected$Type extends MessageType<playerConnected> {
case /* bool sfu */ 3:
message.sfu = reader.bool();
break;
case /* bool sendOffer */ 4:
message.sendOffer = reader.bool();
break;
case /* string playerId */ 5:
message.playerId = reader.string();
break;
Expand All @@ -1315,9 +1300,6 @@ class playerConnected$Type extends MessageType<playerConnected> {
/* bool sfu = 3; */
if (message.sfu !== false)
writer.tag(3, WireType.Varint).bool(message.sfu);
/* bool sendOffer = 4; */
if (message.sendOffer !== false)
writer.tag(4, WireType.Varint).bool(message.sendOffer);
/* string playerId = 5; */
if (message.playerId !== "")
writer.tag(5, WireType.LengthDelimited).string(message.playerId);
Expand Down
14 changes: 0 additions & 14 deletions Frontend/library/src/Config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class Flags {
static AutoConnect = 'AutoConnect' as const;
static AutoPlayVideo = 'AutoPlayVideo' as const;
static AFKDetection = 'TimeoutIfIdle' as const;
static BrowserSendOffer = 'OfferToReceive' as const;
static HoveringMouseMode = 'HoveringMouse' as const;
static ForceMonoAudio = 'ForceMonoAudio' as const;
static ForceTURN = 'ForceTURN' as const;
Expand Down Expand Up @@ -278,19 +277,6 @@ export class Config {
)
);

this.flags.set(
Flags.BrowserSendOffer,
new SettingFlag(
Flags.BrowserSendOffer,
'Browser send offer',
'Browser will initiate the WebRTC handshake by sending the offer to the streamer',
settings && Object.prototype.hasOwnProperty.call(settings, Flags.BrowserSendOffer) ?
settings[Flags.BrowserSendOffer] :
false,
useUrlParams
)
);

this.flags.set(
Flags.UseMic,
new SettingFlag(
Expand Down
39 changes: 3 additions & 36 deletions Frontend/library/src/WebRtcPlayer/WebRtcPlayerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,8 @@ export class WebRtcPlayerController {
this.handleIceCandidate(iceCandidateMessage.candidate);
});
this.protocol.transport.addListener('open', () => {
const BrowserSendsOffer = this.config.isFlagEnabled(Flags.BrowserSendOffer);
if (!BrowserSendsOffer) {
const message = MessageHelpers.createMessage(Messages.listStreamers);
this.protocol.sendMessage(message);
}
const message = MessageHelpers.createMessage(Messages.listStreamers);
this.protocol.sendMessage(message);
this.reconnectAttempt = 0;
this.isReconnecting = false;
});
Expand Down Expand Up @@ -324,20 +321,10 @@ export class WebRtcPlayerController {
this.setVideoEncoderAvgQP(-1);

this.signallingUrlBuilder = () => {
let signallingServerUrl = this.config.getTextSettingValue(
const signallingServerUrl = this.config.getTextSettingValue(
TextParameters.SignallingServerUrl
);

// If we are connecting to the SFU add a special url parameter to the url
if (this.config.isFlagEnabled(Flags.BrowserSendOffer)) {
signallingServerUrl += '?' + Flags.BrowserSendOffer + '=true';
}

// This code is no longer needed, but is a good example for how subsequent config flags can be appended
// if (this.config.isFlagEnabled(Flags.BrowserSendOffer)) {
// signallingServerUrl += (signallingServerUrl.includes('?') ? '&' : '?') + Flags.BrowserSendOffer + '=true';
// }

return signallingServerUrl;
}
}
Expand Down Expand Up @@ -1292,26 +1279,6 @@ export class WebRtcPlayerController {
/* RTC Peer Connection on Track event -> handle on track */
this.peerConnectionController.onTrack = (trackEvent: RTCTrackEvent) =>
this.streamController.handleOnTrack(trackEvent);

/* Start the Hand shake process by creating an Offer */
const BrowserSendsOffer = this.config.isFlagEnabled(
Flags.BrowserSendOffer
);
if (BrowserSendsOffer) {
// If browser is sending the offer, create an offer and send it to the streamer
this.sendrecvDataChannelController.createDataChannel(
this.peerConnectionController.peerConnection,
'cirrus',
this.datachannelOptions
);
this.sendrecvDataChannelController.handleOnMessage = (
ev: MessageEvent<ArrayBuffer>
) => this.handleOnMessage(ev);
this.peerConnectionController.createOffer(
this.sdpConstraints,
this.config
);
}
}

/**
Expand Down
4 changes: 0 additions & 4 deletions Frontend/ui-library/src/Config/ConfigUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ export class ConfigUI {
psSettingsSection,
this.flagsUi.get(Flags.AutoPlayVideo)
);
this.addSettingFlag(
psSettingsSection,
this.flagsUi.get(Flags.BrowserSendOffer)
);
this.addSettingFlag(
psSettingsSection,
this.flagsUi.get(Flags.UseMic)
Expand Down
9 changes: 2 additions & 7 deletions Signalling/src/PlayerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class PlayerConnection implements IPlayer, LogUtils.IMessageLogger {
remoteAddress?: string;

private server: SignallingServer;
private sendOffer: boolean;
private streamerIdChangeListener: (newId: string) => void;
private streamerDisconnectedListener: () => void;

Expand All @@ -44,16 +43,14 @@ export class PlayerConnection implements IPlayer, LogUtils.IMessageLogger {
* websocket close and error so it can react by unsubscribing and resetting itself.
* @param server - The signalling server object that spawned this player.
* @param ws - The websocket coupled to this player connection.
* @param sendOffer - True if the player is requesting to receive offers from streamers.
* @param remoteAddress - The remote address of this connection. Only used as display.
*/
constructor(server: SignallingServer, ws: WebSocket, sendOffer: boolean, remoteAddress?: string) {
constructor(server: SignallingServer, ws: WebSocket, remoteAddress?: string) {
this.server = server;
this.playerId = '';
this.subscribedStreamer = null;
this.transport = new WebSocketTransportNJS(ws);
this.protocol = new SignallingProtocol(this.transport);
this.sendOffer = sendOffer;
this.remoteAddress = remoteAddress;

this.transport.on('error', this.onTransportError.bind(this));
Expand Down Expand Up @@ -89,7 +86,6 @@ export class PlayerConnection implements IPlayer, LogUtils.IMessageLogger {
playerId: this.playerId,
type: 'Player',
subscribedTo: this.subscribedStreamer?.streamerId,
sendOffer: this.sendOffer,
remoteAddress: this.remoteAddress,
};
}
Expand Down Expand Up @@ -146,8 +142,7 @@ export class PlayerConnection implements IPlayer, LogUtils.IMessageLogger {

const connectedMessage = MessageHelpers.createMessage(Messages.playerConnected, { playerId: this.playerId,
dataChannel: true,
sfu: false,
sendOffer: this.sendOffer });
sfu: false });
this.sendToStreamer(connectedMessage);
}

Expand Down
1 change: 0 additions & 1 deletion Signalling/src/PlayerRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface IPlayerInfo {
playerId: string,
type: string,
subscribedTo: string | undefined,
sendOffer: boolean,
remoteAddress: string | undefined,
}

Expand Down
4 changes: 1 addition & 3 deletions Signalling/src/SFUConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export class SFUConnection extends EventEmitter implements IPlayer, IStreamer, L
type: 'SFU',
remoteAddress: this.remoteAddress,
subscribedTo: this.subscribedStreamer?.streamerId,
sendOffer: true,
};
}

Expand Down Expand Up @@ -149,8 +148,7 @@ export class SFUConnection extends EventEmitter implements IPlayer, IStreamer, L

const connectedMessage = MessageHelpers.createMessage(Messages.playerConnected, { playerId: this.playerId,
dataChannel: true,
sfu: true,
sendOffer: true });
sfu: true });
this.sendToStreamer(connectedMessage);
}

Expand Down
12 changes: 1 addition & 11 deletions Signalling/src/SignallingServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import http from 'http';
import https from 'https';
import WebSocket from 'ws';
import url from 'url';
import { StreamerConnection } from './StreamerConnection';
import { PlayerConnection } from './PlayerConnection';
import { SFUConnection } from './SFUConnection';
Expand Down Expand Up @@ -126,16 +125,7 @@ export class SignallingServer {
private onPlayerConnected(ws: WebSocket, request: http.IncomingMessage) {
Logger.info(`New player connection: %s (%s)`, request.socket.remoteAddress, request.url);

// extract some options from the request url
let sendOffer = true;
if (request.url) {
const parsedUrl = url.parse(request.url);
const urlParams = new URLSearchParams(parsedUrl.search!);
const offerToReceive: boolean = (urlParams.get('OfferToReceive') === 'true');
sendOffer = offerToReceive ? false : true;
}

const newPlayer = new PlayerConnection(this, ws, sendOffer, request.socket.remoteAddress);
const newPlayer = new PlayerConnection(this, ws, request.socket.remoteAddress);

// add it to the registry and when the transport closes, remove it
this.playerRegistry.add(newPlayer);
Expand Down
Loading