@hytopia.com/server-protocol 1.3.51 → 1.3.52-dev.webrtc
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hytopia.com/server-protocol",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.52-dev.webrtc",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@hytopia.com/server-protocol": "^1.1.3",
|
|
15
|
-
"ajv": "^8.17.1"
|
|
15
|
+
"ajv": "^8.17.1",
|
|
16
|
+
"mediasoup": "^3.15.7"
|
|
16
17
|
},
|
|
17
18
|
"repository": {
|
|
18
19
|
"type": "git",
|
package/packets/PacketCore.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import * as bidirectionalPackets from './bidirectional';
|
|
1
2
|
import * as inboundPackets from './inbound';
|
|
2
3
|
import * as outboundPackets from './outbound';
|
|
3
4
|
import type { PacketId, AnyPacket, AnyPacketDefinition, IPacket } from './PacketCore';
|
|
4
5
|
|
|
5
|
-
export { inboundPackets, outboundPackets };
|
|
6
|
+
export { bidirectionalPackets, inboundPackets, outboundPackets };
|
|
6
7
|
|
|
7
8
|
export const registeredPackets = new Map<PacketId, AnyPacketDefinition>();
|
|
8
9
|
|
|
9
|
-
const allPackets = { ...inboundPackets, ...outboundPackets };
|
|
10
|
+
const allPackets = { ...bidirectionalPackets, ...inboundPackets, ...outboundPackets };
|
|
10
11
|
|
|
11
12
|
for (const packet of Object.values(allPackets)) {
|
|
12
13
|
if ('id' in packet && 'schema' in packet) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { definePacket, PacketId } from '../PacketCore';
|
|
2
|
+
import type { IPacket } from '../PacketCore';
|
|
3
|
+
import { connectionSchema } from '../../schemas/Connection';
|
|
4
|
+
import type { ConnectionSchema } from '../../schemas/Connection';
|
|
5
|
+
|
|
6
|
+
export type ConnectionPacket = IPacket<typeof PacketId.CONNECTION, ConnectionSchema>;
|
|
7
|
+
|
|
8
|
+
export const connectionPacketDefinition = definePacket(
|
|
9
|
+
PacketId.CONNECTION,
|
|
10
|
+
connectionSchema
|
|
11
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Connection';
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import * as mediasoup from 'mediasoup';
|
|
2
|
+
import { JSONSchemaType } from 'ajv';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Types
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type WrtcConnectAck = {
|
|
9
|
+
i: string; // transport id
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type WrtcDataChannel = {
|
|
13
|
+
i: string; // data channel id
|
|
14
|
+
di: string; // data producer id
|
|
15
|
+
l: string; // label
|
|
16
|
+
s: mediasoup.types.SctpStreamParameters; // sctp stream parameters
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type WrtcProduceDataAck = {
|
|
20
|
+
i: string; // producer id
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type WrtcTransport = {
|
|
24
|
+
i: string; // transport id
|
|
25
|
+
ip: mediasoup.types.IceParameters; // ice parameters
|
|
26
|
+
ic: mediasoup.types.IceCandidate[]; // ice candidates
|
|
27
|
+
d: mediasoup.types.DtlsParameters; // dtls parameters
|
|
28
|
+
s: mediasoup.types.SctpParameters; // sctp parameters
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type WrtcTransportConnect = {
|
|
32
|
+
i: string; // transport id
|
|
33
|
+
d: mediasoup.types.DtlsParameters; // dtls parameters
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type ConnectionSchema = {
|
|
37
|
+
c?: WrtcTransportConnect[], // wrtc transport connect | client -> server | 3rd wrtc packet
|
|
38
|
+
ca?: WrtcConnectAck[], // wrtc connect ack | server -> client | 4th wrtc packet
|
|
39
|
+
d?: WrtcDataChannel[], // wrtc data channels | server <-> client | 2nd wrtc packet s->c, 5th wrtc packet c->s
|
|
40
|
+
p?: 'wss' | 'wrtc'; // protocol switch signal | client -> server | 1st wrtc packet (send 'wrtc')
|
|
41
|
+
pa?: WrtcProduceDataAck[], // wrtc produce data ack | server -> client | 6th wrtc packet
|
|
42
|
+
t?: WrtcTransport[], // wrtc transports | server -> client | 2nd wrtc packet
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Schemas
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
const wrtcConnectAckSchema: JSONSchemaType<WrtcConnectAck> = {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
i: { type: 'string' },
|
|
53
|
+
},
|
|
54
|
+
required: [ 'i' ],
|
|
55
|
+
additionalProperties: false,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const wrtcDtlsParametersSchema: JSONSchemaType<mediasoup.types.DtlsParameters> = {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
role: { type: 'string', enum: [ 'auto', 'client', 'server' ], nullable: true },
|
|
62
|
+
fingerprints: {
|
|
63
|
+
type: 'array',
|
|
64
|
+
items: {
|
|
65
|
+
type: 'object',
|
|
66
|
+
properties: {
|
|
67
|
+
algorithm: { type: 'string', enum: [ 'sha-1', 'sha-224', 'sha-256', 'sha-384', 'sha-512' ] },
|
|
68
|
+
value: { type: 'string' },
|
|
69
|
+
},
|
|
70
|
+
required: [ 'algorithm', 'value' ],
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
required: [ 'fingerprints' ],
|
|
75
|
+
additionalProperties: false,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const wrtcIceCandidateSchema: JSONSchemaType<mediasoup.types.IceCandidate> = {
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties: {
|
|
81
|
+
foundation: { type: 'string' },
|
|
82
|
+
priority: { type: 'number' },
|
|
83
|
+
ip: { type: 'string' },
|
|
84
|
+
address: { type: 'string' },
|
|
85
|
+
protocol: { type: 'string', enum: [ 'udp', 'tcp' ] },
|
|
86
|
+
port: { type: 'number' },
|
|
87
|
+
type: { type: 'string', enum: [ 'host' ] },
|
|
88
|
+
tcpType: { type: 'string', enum: [ 'passive' ], nullable: true },
|
|
89
|
+
},
|
|
90
|
+
required: [ 'foundation', 'priority', 'ip', 'address', 'protocol', 'port', 'type' ],
|
|
91
|
+
additionalProperties: false,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const wrtcIceParametersSchema: JSONSchemaType<mediasoup.types.IceParameters> = {
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
usernameFragment: { type: 'string' },
|
|
98
|
+
password: { type: 'string' },
|
|
99
|
+
iceLite: { type: 'boolean', nullable: true },
|
|
100
|
+
},
|
|
101
|
+
required: [ 'usernameFragment', 'password' ],
|
|
102
|
+
additionalProperties: false,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const wrtcProduceDataAckSchema: JSONSchemaType<WrtcProduceDataAck> = {
|
|
106
|
+
type: 'object',
|
|
107
|
+
properties: {
|
|
108
|
+
i: { type: 'string' },
|
|
109
|
+
},
|
|
110
|
+
required: [ 'i' ],
|
|
111
|
+
additionalProperties: false,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const wrtcSctpParametersSchema: JSONSchemaType<mediasoup.types.SctpParameters> = {
|
|
115
|
+
type: 'object',
|
|
116
|
+
properties: {
|
|
117
|
+
port: { type: 'number' },
|
|
118
|
+
OS: { type: 'number' },
|
|
119
|
+
MIS: { type: 'number' },
|
|
120
|
+
maxMessageSize: { type: 'number' },
|
|
121
|
+
},
|
|
122
|
+
required: [ 'port', 'OS', 'MIS', 'maxMessageSize' ],
|
|
123
|
+
additionalProperties: false,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const wrtcSctpStreamParametersSchema: JSONSchemaType<mediasoup.types.SctpStreamParameters> = {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
streamId: { type: 'number' },
|
|
130
|
+
ordered: { type: 'boolean', nullable: true },
|
|
131
|
+
maxPacketLifeTime: { type: 'number', nullable: true },
|
|
132
|
+
maxRetransmits: { type: 'number', nullable: true },
|
|
133
|
+
},
|
|
134
|
+
required: [ 'streamId' ],
|
|
135
|
+
additionalProperties: false,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const wrtcTransportSchema: JSONSchemaType<WrtcTransport> = {
|
|
139
|
+
type: 'object',
|
|
140
|
+
properties: {
|
|
141
|
+
i: { type: 'string' },
|
|
142
|
+
ip: wrtcIceParametersSchema,
|
|
143
|
+
ic: { type: 'array', items: wrtcIceCandidateSchema },
|
|
144
|
+
d: wrtcDtlsParametersSchema,
|
|
145
|
+
s: wrtcSctpParametersSchema,
|
|
146
|
+
},
|
|
147
|
+
required: [ 'i', 'ip', 'ic', 'd', 's' ],
|
|
148
|
+
additionalProperties: false,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const wrtcTransportConnectSchema: JSONSchemaType<WrtcTransportConnect> = {
|
|
152
|
+
type: 'object',
|
|
153
|
+
properties: {
|
|
154
|
+
i: { type: 'string' },
|
|
155
|
+
d: wrtcDtlsParametersSchema,
|
|
156
|
+
},
|
|
157
|
+
required: [ 'i', 'd' ],
|
|
158
|
+
additionalProperties: false,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const wrtcDataChannelSchema: JSONSchemaType<WrtcDataChannel> = {
|
|
162
|
+
type: 'object',
|
|
163
|
+
properties: {
|
|
164
|
+
i: { type: 'string' },
|
|
165
|
+
di: { type: 'string' },
|
|
166
|
+
l: { type: 'string' },
|
|
167
|
+
s: wrtcSctpStreamParametersSchema,
|
|
168
|
+
},
|
|
169
|
+
required: [ 'i', 'di', 'l', 's' ],
|
|
170
|
+
additionalProperties: false,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export const connectionSchema: JSONSchemaType<ConnectionSchema> = {
|
|
174
|
+
type: 'object',
|
|
175
|
+
properties: {
|
|
176
|
+
c: { type: 'array', items: { ...wrtcTransportConnectSchema }, nullable: true },
|
|
177
|
+
ca: { type: 'array', items: { ...wrtcConnectAckSchema }, nullable: true },
|
|
178
|
+
d: { type: 'array', items: { ...wrtcDataChannelSchema }, nullable: true },
|
|
179
|
+
p: { type: 'string', enum: [ 'wss', 'wrtc' ], nullable: true },
|
|
180
|
+
pa: { type: 'array', items: { ...wrtcProduceDataAckSchema }, nullable: true },
|
|
181
|
+
t: { type: 'array', items: { ...wrtcTransportSchema }, nullable: true },
|
|
182
|
+
},
|
|
183
|
+
additionalProperties: false,
|
|
184
|
+
};
|