Skip to content
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
9 changes: 4 additions & 5 deletions clients/soa/js/src/deviceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class DeviceHandler extends TypedEmitter<DeviceHandlerEvents> {
resolve();
} else reject('Authentication failed');
} else {
reject(`Expected message with messageType 'authenticate', received ${authenticationMessage.messageType}`);
reject(`Expected message with messageType 'authenticate', received '${authenticationMessage.messageType}'`);
}
};
});
Expand Down Expand Up @@ -118,16 +118,15 @@ export class DeviceHandler extends TypedEmitter<DeviceHandlerEvents> {
this.ws.send(JSON.stringify(connectionStateChangedMessage));
this.emit('connectionsChanged');
});
connection.connect();
this.emit('connectionsChanged');
connection.connect().then(() => this.emit('connectionsChanged'));
}

private handleSignalingMessage(message: SignalingMessage) {
private async handleSignalingMessage(message: SignalingMessage) {
const connection = this.connections.get(message.connectionUrl);
if (connection === undefined) {
throw Error('No Connection for the signaling message was found');
}
connection.handleSignalingMessage(message);
await connection.handleSignalingMessage(message);
}

private handleClosePeerConnectionMessage(message: ClosePeerConnectionMessage) {
Expand Down
2 changes: 1 addition & 1 deletion clients/soa/js/src/peer/channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class DataChannel {
ondata?: (data: string | ArrayBuffer | ArrayBufferView | Blob) => void;
onData?: (data: string | ArrayBuffer | ArrayBufferView | Blob) => void;
channel_type = 'DataChannel' as const;
send: {(data: string): void; (data: Blob): void; (data: ArrayBuffer): void; (data: ArrayBufferView): void};

Expand Down
73 changes: 36 additions & 37 deletions clients/soa/js/src/peer/webrtc-connection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
bundlePolicy: "max-compat", // transport every stream over a seperate connection if necessary
bundlePolicy: "max-compat", // transport every stream over a separate connection if necessary
//certificates: ,// enable certificates for faster (re-)connection time
//iceCandidatePoolSize: , //can make the negotion faster
//iceCandidatePoolSize: , //can make the negotiation faster
iceServers: [], // STUN/TURN - Server
iceTransportPolicy: "all", // We can also connect local und using relay servers
//peerIdentity: , // target peer identity / security consideration
Expand Down Expand Up @@ -40,7 +40,7 @@ enum WebRTCRole {
}

enum ConnectionState {
Unitintialized,
Uninitialized,
Calling,
WaitingForCall,
WaitingForAnswer,
Expand All @@ -52,11 +52,11 @@ const trickleIce = false;
export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> implements PeerConnection {
private signalingQueue: Array<RTCSignalingMessage> = [];
private candidateQueue: Array<RTCIceCandidate> = [];
private isProcessing = true; //dont do anything until connect is called
private isProcessing = true; //don't do anything until connect is called
private role?: WebRTCRole;
private _state: ConnectionState = ConnectionState.Unitintialized;
private _state: ConnectionState = ConnectionState.Uninitialized;
private receivingChannels = new Map<string, Channel>();
private transeiverMap = new Map<RTCRtpTransceiver, string>();
private transceiverMap = new Map<RTCRtpTransceiver, string>();
private mediaChannelMap = new Map<string, MediaChannel>();
tiebreaker!: boolean;
pc: RTCPeerConnection;
Expand All @@ -72,10 +72,10 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
}
}

private onicecandidate(event: RTCPeerConnectionIceEvent) {
private async onicecandidate(event: RTCPeerConnectionIceEvent) {
if (event.candidate && trickleIce) {
this.sendIceCandidate(event.candidate);
} else if(!event.candidate && !trickleIce) {
await this.sendIceCandidate(event.candidate);
} else {
this.iceCandidateResolver && this.iceCandidateResolver();
}
}
Expand All @@ -94,7 +94,7 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
if (channel !== undefined && channel.channel_type === 'DataChannel') {
channel.send = event.channel.send.bind(event.channel);
event.channel.onmessage = message => {
if (channel.ondata) channel.ondata(message.data);
if (channel.onData) channel.onData(message.data);
};
event.channel.onopen = () => {
channel._setReady();
Expand All @@ -117,7 +117,7 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
}

transmit(serviceConfig: ServiceConfig, id: string, channel: Channel): void {
log.trace('WebRTCPeerConnection.tranceive called', {
log.trace('WebRTCPeerConnection.transmit called', {
serviceConfig,
id,
channel,
Expand All @@ -136,10 +136,10 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
console.log(e);
}
webrtcChannel.onmessage = event => {
if (channel.ondata) channel.ondata(event.data);
if (channel.onData) channel.onData(event.data);
};
} else if (channel.channel_type === 'MediaChannel') {
log.trace('WebRTCPeerConnection.tranceive save channel for later consumption', {
log.trace('WebRTCPeerConnection.transmit save channel for later consumption', {
channel,
label,
});
Expand Down Expand Up @@ -168,7 +168,7 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp

async handleSignalingMessage(msg: SignalingMessage) {
this.signalingQueue.push(msg as RTCSignalingMessage);
this.executeQueue();
this.executeQueue().catch(err => { if(err) throw err });
}

private async executeQueue() {
Expand All @@ -180,7 +180,7 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
if (!message) break;
switch (message.signalingType) {
case 'candidate':
this.handleIceCandidate(message);
await this.handleIceCandidate(message);
break;
case 'offer':
await this.handleOffer(message);
Expand All @@ -196,8 +196,8 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp

// Received Signaling and Control handling *************************************************************************
async connect() {
console.log('webrtc connect');
assert(this._state === ConnectionState.Unitintialized);
log.trace('WebRTCPeerConnection.connect called');
assert(this._state === ConnectionState.Uninitialized);
this.isProcessing = false;
this.role = this.tiebreaker ? WebRTCRole.Caller : WebRTCRole.Callee;
if (this.role === WebRTCRole.Caller) {
Expand Down Expand Up @@ -280,7 +280,7 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
});
log.trace('WebRTCPeerConnection.makeAnswer called', {offer});
await this.pc.setRemoteDescription(offer);
this.matchMediaChannels();
await this.matchMediaChannels();
let answer = await this.pc.createAnswer();
log.trace('WebRTCPeerConnection.makeAnswer created answer', {answer});
await this.pc.setLocalDescription(answer); // TODO: gst-webrtc seems to not resolve the promise correctly.
Expand Down Expand Up @@ -309,7 +309,7 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
}

private async addIceCandidate(candidate: RTCIceCandidate) {
this.pc.addIceCandidate(candidate);
await this.pc.addIceCandidate(candidate);
}

private async sendIceCandidate(candidate?: RTCIceCandidate) {
Expand Down Expand Up @@ -347,28 +347,27 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
const midRegex = /a=mid:(\S)/gm;
const msidRegex = /(a=msid:- )\S*/gm;

// Update the "a=msid" attribute from the video stream with the right label from the transeiverMap.
for (const transeiver of this.transeiverMap.keys()) {
const label = this.transeiverMap.get(transeiver);
log.trace('WebRTCPeerConnection.modifySDP setTrack id for transeiver', {
transeiver,
mid: transeiver.mid,
// Update the "a=msid" attribute from the video stream with the right label from the transceiverMap.
for (const transceiver of this.transceiverMap.keys()) {
const label = this.transceiverMap.get(transceiver);
log.trace('WebRTCPeerConnection.modifySDP setTrack id for transceiver', {
transceiver: transceiver,
mid: transceiver.mid,
label,
});
const sectionIdx = sections.findIndex(m => {
const result=midRegex.exec(m)
return result && result[1] === transeiver.mid;
return result && result[1] === transceiver.mid;
});
if (sectionIdx!== -1) {
const modifiedSection = sections[sectionIdx].replace(msidRegex, '$1' + label);

if (modifiedSection===sections[sectionIdx]) {
log.error('WebRTCPeerConnection.modifySDP no msid found for transeiver', {transeiver});
log.error('WebRTCPeerConnection.modifySDP no msid found for transceiver', {transceiver: transceiver});
} else {
sections[sectionIdx]=modifiedSection;
}
} else {
log.error('WebRTCPeerConnection.modifySDP no media found for transeiver', {transeiver});
log.error('WebRTCPeerConnection.modifySDP no media found for transceiver', {transceiver: transceiver});
}
}

Expand All @@ -377,15 +376,15 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
return sdpString;
}

private matchMediaChannels() {
private async matchMediaChannels() {
log.trace('WebRTCPeerConnection.matchMediaChannels called');
const transceivers = this.pc.getTransceivers() as RTCRtpTransceiver[];
log.trace('WebRTCPeerConnection.matchMediaChannels transeivers', {
log.trace('WebRTCPeerConnection.matchMediaChannels transceivers', {
transceivers,
});
for (const transceiver of transceivers) {
const label = transceiver.receiver.track.label;
log.trace('WebRTCPeerConnection.matchMediaChannels matching tramceiver', {
log.trace('WebRTCPeerConnection.matchMediaChannels matching transceiver', {
transceiver,
label,
});
Expand All @@ -400,7 +399,7 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
if (channel.track) {
direction = 'sendonly';
log.trace('WebRTCPeerConnection.matchMediaChannels replace track');
transceiver.sender.replaceTrack(channel.track as MediaStreamTrack);
await transceiver.sender.replaceTrack(channel.track as MediaStreamTrack);
}

if (channel.ontrack) {
Expand All @@ -409,7 +408,7 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
channel.ontrack({track: transceiver.receiver.track});
}

log.trace(`WebRTCPeerConnection.matchMediaChannels set transeiver to ${direction} `);
log.trace(`WebRTCPeerConnection.matchMediaChannels set transceiver to ${direction} `);
transceiver.direction = direction;
}
}
Expand All @@ -424,10 +423,10 @@ export class WebRTCPeerConnection extends TypedEmitter<PeerConnectionEvents> imp
});
continue;
}
const rtpTranseiver: RTCRtpTransceiver = this.pc.addTransceiver(channel.track ? channel.track : 'video', {direction: 'sendrecv'});
this.transeiverMap.set(rtpTranseiver, label);
const rtpTransceiver: RTCRtpTransceiver = this.pc.addTransceiver(channel.track ? channel.track : 'video', {direction: 'sendrecv'});
this.transceiverMap.set(rtpTransceiver, label);
if (channel.ontrack) {
channel.ontrack({track: rtpTranseiver.receiver.track});
channel.ontrack({track: rtpTransceiver.receiver.track});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class GPIOInterface extends TypedEmitter<GPIOInterfaceEvents> implements
this.driverState = state;
const data: GPIOInterfaceData = {driver: this.driver, state: state};
this.emit('upstreamData', data);
this.downstreamData(data); // use the same mechanismn as any other driver data from external devices
this.downstreamData(data); // use the same mechanism as any other driver data from external devices
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class ElectricalConnectionService extends TypedEmitter<ElectricalConnecti
channel.send(JSON.stringify(packet));
});
await channel.ready();
this.queue.start();
this.queue.start().catch(err => { if(err) throw err });
});

// find the bus set or create a new one
Expand Down
2 changes: 1 addition & 1 deletion clients/soa_services/webcam/js/src/webcam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface WebcamServiceConfiguration extends ServiceConfiguration {
}
function checkConfig(config: ServiceConfiguration): asserts config is WebcamServiceConfiguration {
if (config.serviceType !== ServiceType) {
//throw Error("Service Configuration needs to be for Webcamservice type");
//throw Error("Service Configuration needs to be for WebcamService type");
}
}

Expand Down