warpr 1.0.21 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/warpr.mjs +716 -0
- package/fesm2022/warpr.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/components/stream-host/stream-host.component.d.ts +26 -0
- package/lib/data/frames.d.ts +20 -0
- package/lib/data/signaling-messages.d.ts +29 -0
- package/lib/data/streaming-messages.d.ts +53 -0
- package/lib/infrastructure/array-stream.d.ts +21 -0
- package/lib/infrastructure/events.d.ts +25 -0
- package/lib/infrastructure/message-assembler.d.ts +6 -0
- package/lib/networking/messaging-client.d.ts +5 -0
- package/lib/networking/web-socket-client.d.ts +17 -0
- package/lib/services/messaging.service.d.ts +12 -0
- package/lib/services/streaming.service.d.ts +30 -0
- package/package.json +26 -15
- package/{src/public-api.ts → public-api.d.ts} +0 -4
- package/ng-package.json +0 -7
- package/src/lib/components/stream-host/stream-host.component.html +0 -5
- package/src/lib/components/stream-host/stream-host.component.scss +0 -31
- package/src/lib/components/stream-host/stream-host.component.spec.ts +0 -23
- package/src/lib/components/stream-host/stream-host.component.ts +0 -169
- package/src/lib/data/frames.ts +0 -37
- package/src/lib/data/signaling-messages.ts +0 -64
- package/src/lib/data/streaming-messages.ts +0 -136
- package/src/lib/infrastructure/array-stream.ts +0 -109
- package/src/lib/infrastructure/events.ts +0 -61
- package/src/lib/infrastructure/message-assembler.ts +0 -60
- package/src/lib/networking/messaging-client.ts +0 -7
- package/src/lib/networking/web-socket-client.ts +0 -55
- package/src/lib/services/messaging.service.spec.ts +0 -16
- package/src/lib/services/messaging.service.ts +0 -32
- package/src/lib/services/streaming.service.spec.ts +0 -16
- package/src/lib/services/streaming.service.ts +0 -145
- package/tsconfig.lib.json +0 -14
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -14
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { TestBed } from '@angular/core/testing';
|
|
2
|
-
|
|
3
|
-
import { MessagingService } from './messaging.service';
|
|
4
|
-
|
|
5
|
-
describe('MessagingService', () => {
|
|
6
|
-
let service: MessagingService;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
TestBed.configureTestingModule({});
|
|
10
|
-
service = TestBed.inject(MessagingService);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should be created', () => {
|
|
14
|
-
expect(service).toBeTruthy();
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { WebSocketClient } from '../networking/web-socket-client';
|
|
3
|
-
import { WarprSignalingMessage, ConnectionRequest } from '../data/signaling-messages';
|
|
4
|
-
import { v4 as uuid } from 'uuid';
|
|
5
|
-
|
|
6
|
-
@Injectable({
|
|
7
|
-
providedIn: 'root'
|
|
8
|
-
})
|
|
9
|
-
export class MessagingService extends WebSocketClient<WarprSignalingMessage> {
|
|
10
|
-
|
|
11
|
-
private static readonly _connectionUri = 'api/sinks/connect';
|
|
12
|
-
private readonly _sessionId = uuid();
|
|
13
|
-
|
|
14
|
-
constructor() {
|
|
15
|
-
const uri = MessagingService.GetServerUri();
|
|
16
|
-
super(uri);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
private static GetServerUri(): string {
|
|
20
|
-
const location = window.location;
|
|
21
|
-
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
|
|
22
|
-
return `${protocol}://${location.host}/${this._connectionUri}`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
protected override OnConnected(): void {
|
|
26
|
-
super.OnConnected();
|
|
27
|
-
|
|
28
|
-
let request = new ConnectionRequest();
|
|
29
|
-
request.SessionId = this._sessionId;
|
|
30
|
-
this.SendMessage(request);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { TestBed } from '@angular/core/testing';
|
|
2
|
-
|
|
3
|
-
import { StreamingService } from './streaming.service';
|
|
4
|
-
|
|
5
|
-
describe('StreamingService', () => {
|
|
6
|
-
let service: StreamingService;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
TestBed.configureTestingModule({});
|
|
10
|
-
service = TestBed.inject(StreamingService);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should be created', () => {
|
|
14
|
-
expect(service).toBeTruthy();
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { MessagingService } from './messaging.service';
|
|
3
|
-
import { GetConfiguration, PairingCompleteMessage, PeerConnectionCandidateMessage, PeerConnectionDescriptionMessage, WarprSignalingMessage, WarprSignalingMessageType } from '../data/signaling-messages';
|
|
4
|
-
import { IMessagingClient } from '../networking/messaging-client';
|
|
5
|
-
import { EncodedFrame } from '../data/frames';
|
|
6
|
-
import { EventOwner, EventPublisher } from '../infrastructure/events';
|
|
7
|
-
import { MessageAssembler } from '../infrastructure/message-assembler';
|
|
8
|
-
|
|
9
|
-
@Injectable({
|
|
10
|
-
providedIn: 'root'
|
|
11
|
-
})
|
|
12
|
-
export class StreamingService {
|
|
13
|
-
|
|
14
|
-
private _peerConnection?: RTCPeerConnection;
|
|
15
|
-
private _controlConnection?: RTCDataChannel;
|
|
16
|
-
|
|
17
|
-
private _streamConnection?: RTCDataChannel;
|
|
18
|
-
private _messageBuilder?: MessageAssembler;
|
|
19
|
-
|
|
20
|
-
private _auxConnection?: RTCDataChannel;
|
|
21
|
-
|
|
22
|
-
private readonly _events = new EventOwner();
|
|
23
|
-
public readonly FrameReceived = new EventPublisher<StreamingService, EncodedFrame>(this._events);
|
|
24
|
-
public readonly Connected = new EventPublisher<StreamingService, any>(this._events);
|
|
25
|
-
|
|
26
|
-
public readonly ControlMessageReceived = new EventPublisher<StreamingService, any>(this._events);
|
|
27
|
-
public readonly AuxMessageReceived = new EventPublisher<StreamingService, any>(this._events);
|
|
28
|
-
|
|
29
|
-
constructor(
|
|
30
|
-
private _messagingService: MessagingService) {
|
|
31
|
-
|
|
32
|
-
_messagingService.MessageReceived.Subscribe((sender: IMessagingClient<WarprSignalingMessage>, message: WarprSignalingMessage) => this.OnSignalingMessageReceived(sender, message));
|
|
33
|
-
_messagingService.Connect();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private Reconnect(configuration: RTCConfiguration) {
|
|
37
|
-
console.log("Establishing peer connection...");
|
|
38
|
-
|
|
39
|
-
this._controlConnection?.close();
|
|
40
|
-
this._streamConnection?.close();
|
|
41
|
-
this._messageBuilder = new MessageAssembler();
|
|
42
|
-
this._auxConnection?.close();
|
|
43
|
-
this._peerConnection?.close();
|
|
44
|
-
|
|
45
|
-
this._peerConnection = new RTCPeerConnection(configuration);
|
|
46
|
-
this._peerConnection.onicecandidate = (event) => this.OnIceCandidateAdded(event.candidate?.candidate);
|
|
47
|
-
this._peerConnection.ondatachannel = (event) => this.OnDataChannel(event);
|
|
48
|
-
this._peerConnection.onconnectionstatechange = (event) => this.OnConnectionStateChanged();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public SendControlMessage(message: any) {
|
|
52
|
-
let json = JSON.stringify(message);
|
|
53
|
-
this._controlConnection?.send(json);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public SendAuxMessage(message: any) {
|
|
57
|
-
this._auxConnection?.send(message);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private OnConnectionStateChanged() {
|
|
61
|
-
console.log("WebRTC: " + this._peerConnection?.connectionState);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private OnDataChannel(event: RTCDataChannelEvent) {
|
|
65
|
-
console.log(`WebRTC data channel ${event.channel.label} connected.`);
|
|
66
|
-
|
|
67
|
-
switch (event.channel.label) {
|
|
68
|
-
case "control":
|
|
69
|
-
this._controlConnection = event.channel;
|
|
70
|
-
this._controlConnection.binaryType = "arraybuffer"
|
|
71
|
-
this._controlConnection.onmessage = (event) => this._events.Raise(this.ControlMessageReceived, this, event.data);
|
|
72
|
-
this._events.Raise(this.Connected, this, null);
|
|
73
|
-
break;
|
|
74
|
-
case "stream":
|
|
75
|
-
this._streamConnection = event.channel;
|
|
76
|
-
this._streamConnection.binaryType = "arraybuffer"
|
|
77
|
-
this._streamConnection.onmessage = (event) => this.OnLowLatencyMessage(event);
|
|
78
|
-
break;
|
|
79
|
-
case "aux":
|
|
80
|
-
this._auxConnection = event.channel;
|
|
81
|
-
this._auxConnection.binaryType = "arraybuffer"
|
|
82
|
-
this._auxConnection.onmessage = (event) => this._events.Raise(this.AuxMessageReceived, this, event.data);
|
|
83
|
-
this._events.Raise(this.Connected, this, null);
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private _lastRefreshTime = performance.now();
|
|
89
|
-
private _count = 0;
|
|
90
|
-
|
|
91
|
-
private OnLowLatencyMessage(event: MessageEvent<any>) {
|
|
92
|
-
|
|
93
|
-
let message = this._messageBuilder?.PushMessage(event.data as ArrayBuffer);
|
|
94
|
-
if (!message) return;
|
|
95
|
-
|
|
96
|
-
let now = performance.now();
|
|
97
|
-
let elapsed = now - this._lastRefreshTime;
|
|
98
|
-
this._count++;
|
|
99
|
-
|
|
100
|
-
if (elapsed > 1000) {
|
|
101
|
-
this._lastRefreshTime = now;
|
|
102
|
-
|
|
103
|
-
console.debug(`Messages: ${this._count / elapsed * 1000} FPS`);
|
|
104
|
-
this._count = 0;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
let frame = new EncodedFrame(message);
|
|
108
|
-
this._events.Raise(this.FrameReceived, this, frame);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private OnIceCandidateAdded(candidate?: string) {
|
|
112
|
-
if (candidate == null) return;
|
|
113
|
-
|
|
114
|
-
let message = new PeerConnectionCandidateMessage();
|
|
115
|
-
message.Candidate = candidate;
|
|
116
|
-
this._messagingService.SendMessage(message);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private async OnSignalingMessageReceived(sender: IMessagingClient<WarprSignalingMessage>, message: WarprSignalingMessage) {
|
|
120
|
-
|
|
121
|
-
switch (message.$type) {
|
|
122
|
-
case WarprSignalingMessageType.PairingCompleteMessage:
|
|
123
|
-
this.Reconnect(GetConfiguration(message.IceServers));
|
|
124
|
-
break;
|
|
125
|
-
case WarprSignalingMessageType.PeerConnectionDescriptionMessage:
|
|
126
|
-
if (!this._peerConnection) return;
|
|
127
|
-
|
|
128
|
-
await this._peerConnection.setRemoteDescription({ type: "offer", sdp: message.Description });
|
|
129
|
-
let answer = await this._peerConnection.createAnswer();
|
|
130
|
-
await this._peerConnection.setLocalDescription(answer);
|
|
131
|
-
|
|
132
|
-
let answerMessage = new PeerConnectionDescriptionMessage();
|
|
133
|
-
answerMessage.Description = answer.sdp;
|
|
134
|
-
this._messagingService.SendMessage(answerMessage);
|
|
135
|
-
|
|
136
|
-
break;
|
|
137
|
-
case WarprSignalingMessageType.PeerConnectionCandidateMessage:
|
|
138
|
-
if (!this._peerConnection) return;
|
|
139
|
-
|
|
140
|
-
await this._peerConnection.addIceCandidate({ candidate: message.Candidate, sdpMid: "0" });
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
}
|
package/tsconfig.lib.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "../../tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "../../out-tsc/lib",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"inlineSources": true,
|
|
9
|
-
"types": []
|
|
10
|
-
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"**/*.spec.ts"
|
|
13
|
-
]
|
|
14
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "../../tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "../../out-tsc/spec",
|
|
6
|
-
"types": [
|
|
7
|
-
"jasmine"
|
|
8
|
-
]
|
|
9
|
-
},
|
|
10
|
-
"include": [
|
|
11
|
-
"**/*.spec.ts",
|
|
12
|
-
"**/*.d.ts"
|
|
13
|
-
]
|
|
14
|
-
}
|