1 | var grammar = module.exports = {
|
2 | v: [{
|
3 | name: 'version',
|
4 | reg: /^(\d*)$/
|
5 | }],
|
6 | o: [{
|
7 |
|
8 |
|
9 | name: 'origin',
|
10 | reg: /^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,
|
11 | names: ['username', 'sessionId', 'sessionVersion', 'netType', 'ipVer', 'address'],
|
12 | format: '%s %s %d %s IP%d %s'
|
13 | }],
|
14 |
|
15 | s: [{ name: 'name' }],
|
16 | i: [{ name: 'description' }],
|
17 | u: [{ name: 'uri' }],
|
18 | e: [{ name: 'email' }],
|
19 | p: [{ name: 'phone' }],
|
20 | z: [{ name: 'timezones' }],
|
21 | r: [{ name: 'repeats' }],
|
22 |
|
23 | t: [{
|
24 |
|
25 | name: 'timing',
|
26 | reg: /^(\d*) (\d*)/,
|
27 | names: ['start', 'stop'],
|
28 | format: '%d %d'
|
29 | }],
|
30 | c: [{
|
31 |
|
32 | name: 'connection',
|
33 | reg: /^IN IP(\d) (\S*)/,
|
34 | names: ['version', 'ip'],
|
35 | format: 'IN IP%d %s'
|
36 | }],
|
37 | b: [{
|
38 |
|
39 | push: 'bandwidth',
|
40 | reg: /^(TIAS|AS|CT|RR|RS):(\d*)/,
|
41 | names: ['type', 'limit'],
|
42 | format: '%s:%s'
|
43 | }],
|
44 | m: [{
|
45 |
|
46 |
|
47 |
|
48 | reg: /^(\w*) (\d*) ([\w/]*)(?: (.*))?/,
|
49 | names: ['type', 'port', 'protocol', 'payloads'],
|
50 | format: '%s %d %s %s'
|
51 | }],
|
52 | a: [
|
53 | {
|
54 |
|
55 | push: 'rtp',
|
56 | reg: /^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,
|
57 | names: ['payload', 'codec', 'rate', 'encoding'],
|
58 | format: function (o) {
|
59 | return (o.encoding)
|
60 | ? 'rtpmap:%d %s/%s/%s'
|
61 | : o.rate
|
62 | ? 'rtpmap:%d %s/%s'
|
63 | : 'rtpmap:%d %s';
|
64 | }
|
65 | },
|
66 | {
|
67 |
|
68 |
|
69 | push: 'fmtp',
|
70 | reg: /^fmtp:(\d*) ([\S| ]*)/,
|
71 | names: ['payload', 'config'],
|
72 | format: 'fmtp:%d %s'
|
73 | },
|
74 | {
|
75 |
|
76 | name: 'control',
|
77 | reg: /^control:(.*)/,
|
78 | format: 'control:%s'
|
79 | },
|
80 | {
|
81 |
|
82 | name: 'rtcp',
|
83 | reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,
|
84 | names: ['port', 'netType', 'ipVer', 'address'],
|
85 | format: function (o) {
|
86 | return (o.address != null)
|
87 | ? 'rtcp:%d %s IP%d %s'
|
88 | : 'rtcp:%d';
|
89 | }
|
90 | },
|
91 | {
|
92 |
|
93 | push: 'rtcpFbTrrInt',
|
94 | reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/,
|
95 | names: ['payload', 'value'],
|
96 | format: 'rtcp-fb:%s trr-int %d'
|
97 | },
|
98 | {
|
99 |
|
100 | push: 'rtcpFb',
|
101 | reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,
|
102 | names: ['payload', 'type', 'subtype'],
|
103 | format: function (o) {
|
104 | return (o.subtype != null)
|
105 | ? 'rtcp-fb:%s %s %s'
|
106 | : 'rtcp-fb:%s %s';
|
107 | }
|
108 | },
|
109 | {
|
110 |
|
111 |
|
112 |
|
113 | push: 'ext',
|
114 | reg: /^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/,
|
115 | names: ['value', 'direction', 'encrypt-uri', 'uri', 'config'],
|
116 | format: function (o) {
|
117 | return (
|
118 | 'extmap:%d' +
|
119 | (o.direction ? '/%s' : '%v') +
|
120 | (o['encrypt-uri'] ? ' %s' : '%v') +
|
121 | ' %s' +
|
122 | (o.config ? ' %s' : '')
|
123 | );
|
124 | }
|
125 | },
|
126 | {
|
127 |
|
128 | name: 'extmapAllowMixed',
|
129 | reg: /^(extmap-allow-mixed)/
|
130 | },
|
131 | {
|
132 |
|
133 | push: 'crypto',
|
134 | reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,
|
135 | names: ['id', 'suite', 'config', 'sessionConfig'],
|
136 | format: function (o) {
|
137 | return (o.sessionConfig != null)
|
138 | ? 'crypto:%d %s %s %s'
|
139 | : 'crypto:%d %s %s';
|
140 | }
|
141 | },
|
142 | {
|
143 |
|
144 | name: 'setup',
|
145 | reg: /^setup:(\w*)/,
|
146 | format: 'setup:%s'
|
147 | },
|
148 | {
|
149 |
|
150 | name: 'connectionType',
|
151 | reg: /^connection:(new|existing)/,
|
152 | format: 'connection:%s'
|
153 | },
|
154 | {
|
155 |
|
156 | name: 'mid',
|
157 | reg: /^mid:([^\s]*)/,
|
158 | format: 'mid:%s'
|
159 | },
|
160 | {
|
161 |
|
162 | name: 'msid',
|
163 | reg: /^msid:(.*)/,
|
164 | format: 'msid:%s'
|
165 | },
|
166 | {
|
167 |
|
168 | name: 'ptime',
|
169 | reg: /^ptime:(\d*(?:\.\d*)*)/,
|
170 | format: 'ptime:%d'
|
171 | },
|
172 | {
|
173 |
|
174 | name: 'maxptime',
|
175 | reg: /^maxptime:(\d*(?:\.\d*)*)/,
|
176 | format: 'maxptime:%d'
|
177 | },
|
178 | {
|
179 |
|
180 | name: 'direction',
|
181 | reg: /^(sendrecv|recvonly|sendonly|inactive)/
|
182 | },
|
183 | {
|
184 |
|
185 | name: 'icelite',
|
186 | reg: /^(ice-lite)/
|
187 | },
|
188 | {
|
189 |
|
190 | name: 'iceUfrag',
|
191 | reg: /^ice-ufrag:(\S*)/,
|
192 | format: 'ice-ufrag:%s'
|
193 | },
|
194 | {
|
195 |
|
196 | name: 'icePwd',
|
197 | reg: /^ice-pwd:(\S*)/,
|
198 | format: 'ice-pwd:%s'
|
199 | },
|
200 | {
|
201 |
|
202 | name: 'fingerprint',
|
203 | reg: /^fingerprint:(\S*) (\S*)/,
|
204 | names: ['type', 'hash'],
|
205 | format: 'fingerprint:%s %s'
|
206 | },
|
207 | {
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 | push:'candidates',
|
214 | reg: /^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,
|
215 | names: ['foundation', 'component', 'transport', 'priority', 'ip', 'port', 'type', 'raddr', 'rport', 'tcptype', 'generation', 'network-id', 'network-cost'],
|
216 | format: function (o) {
|
217 | var str = 'candidate:%s %d %s %d %s %d typ %s';
|
218 |
|
219 | str += (o.raddr != null) ? ' raddr %s rport %d' : '%v%v';
|
220 |
|
221 |
|
222 | str += (o.tcptype != null) ? ' tcptype %s' : '%v';
|
223 |
|
224 | if (o.generation != null) {
|
225 | str += ' generation %d';
|
226 | }
|
227 |
|
228 | str += (o['network-id'] != null) ? ' network-id %d' : '%v';
|
229 | str += (o['network-cost'] != null) ? ' network-cost %d' : '%v';
|
230 | return str;
|
231 | }
|
232 | },
|
233 | {
|
234 |
|
235 | name: 'endOfCandidates',
|
236 | reg: /^(end-of-candidates)/
|
237 | },
|
238 | {
|
239 |
|
240 | name: 'remoteCandidates',
|
241 | reg: /^remote-candidates:(.*)/,
|
242 | format: 'remote-candidates:%s'
|
243 | },
|
244 | {
|
245 |
|
246 | name: 'iceOptions',
|
247 | reg: /^ice-options:(\S*)/,
|
248 | format: 'ice-options:%s'
|
249 | },
|
250 | {
|
251 |
|
252 | push: 'ssrcs',
|
253 | reg: /^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,
|
254 | names: ['id', 'attribute', 'value'],
|
255 | format: function (o) {
|
256 | var str = 'ssrc:%d';
|
257 | if (o.attribute != null) {
|
258 | str += ' %s';
|
259 | if (o.value != null) {
|
260 | str += ':%s';
|
261 | }
|
262 | }
|
263 | return str;
|
264 | }
|
265 | },
|
266 | {
|
267 |
|
268 |
|
269 | push: 'ssrcGroups',
|
270 |
|
271 | reg: /^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,
|
272 | names: ['semantics', 'ssrcs'],
|
273 | format: 'ssrc-group:%s %s'
|
274 | },
|
275 | {
|
276 |
|
277 | name: 'msidSemantic',
|
278 | reg: /^msid-semantic:\s?(\w*) (\S*)/,
|
279 | names: ['semantic', 'token'],
|
280 | format: 'msid-semantic: %s %s'
|
281 | },
|
282 | {
|
283 |
|
284 | push: 'groups',
|
285 | reg: /^group:(\w*) (.*)/,
|
286 | names: ['type', 'mids'],
|
287 | format: 'group:%s %s'
|
288 | },
|
289 | {
|
290 |
|
291 | name: 'rtcpMux',
|
292 | reg: /^(rtcp-mux)/
|
293 | },
|
294 | {
|
295 |
|
296 | name: 'rtcpRsize',
|
297 | reg: /^(rtcp-rsize)/
|
298 | },
|
299 | {
|
300 |
|
301 | name: 'sctpmap',
|
302 | reg: /^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,
|
303 | names: ['sctpmapNumber', 'app', 'maxMessageSize'],
|
304 | format: function (o) {
|
305 | return (o.maxMessageSize != null)
|
306 | ? 'sctpmap:%s %s %s'
|
307 | : 'sctpmap:%s %s';
|
308 | }
|
309 | },
|
310 | {
|
311 |
|
312 | name: 'xGoogleFlag',
|
313 | reg: /^x-google-flag:([^\s]*)/,
|
314 | format: 'x-google-flag:%s'
|
315 | },
|
316 | {
|
317 |
|
318 | push: 'rids',
|
319 | reg: /^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,
|
320 | names: ['id', 'direction', 'params'],
|
321 | format: function (o) {
|
322 | return (o.params) ? 'rid:%s %s %s' : 'rid:%s %s';
|
323 | }
|
324 | },
|
325 | {
|
326 |
|
327 |
|
328 |
|
329 | push: 'imageattrs',
|
330 | reg: new RegExp(
|
331 |
|
332 | '^imageattr:(\\d+|\\*)' +
|
333 |
|
334 | '[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)' +
|
335 |
|
336 | '(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?'
|
337 | ),
|
338 | names: ['pt', 'dir1', 'attrs1', 'dir2', 'attrs2'],
|
339 | format: function (o) {
|
340 | return 'imageattr:%s %s %s' + (o.dir2 ? ' %s %s' : '');
|
341 | }
|
342 | },
|
343 | {
|
344 |
|
345 |
|
346 | name: 'simulcast',
|
347 | reg: new RegExp(
|
348 |
|
349 | '^simulcast:' +
|
350 |
|
351 | '(send|recv) ([a-zA-Z0-9\\-_~;,]+)' +
|
352 |
|
353 | '(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?' +
|
354 |
|
355 | '$'
|
356 | ),
|
357 | names: ['dir1', 'list1', 'dir2', 'list2'],
|
358 | format: function (o) {
|
359 | return 'simulcast:%s %s' + (o.dir2 ? ' %s %s' : '');
|
360 | }
|
361 | },
|
362 | {
|
363 |
|
364 |
|
365 |
|
366 |
|
367 | name: 'simulcast_03',
|
368 | reg: /^simulcast:[\s\t]+([\S+\s\t]+)$/,
|
369 | names: ['value'],
|
370 | format: 'simulcast: %s'
|
371 | },
|
372 | {
|
373 |
|
374 |
|
375 | name: 'framerate',
|
376 | reg: /^framerate:(\d+(?:$|\.\d+))/,
|
377 | format: 'framerate:%s'
|
378 | },
|
379 | {
|
380 |
|
381 |
|
382 | name: 'sourceFilter',
|
383 | reg: /^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,
|
384 | names: ['filterMode', 'netType', 'addressTypes', 'destAddress', 'srcList'],
|
385 | format: 'source-filter: %s %s %s %s %s'
|
386 | },
|
387 | {
|
388 |
|
389 | name: 'bundleOnly',
|
390 | reg: /^(bundle-only)/
|
391 | },
|
392 | {
|
393 |
|
394 | name: 'label',
|
395 | reg: /^label:(.+)/,
|
396 | format: 'label:%s'
|
397 | },
|
398 | {
|
399 |
|
400 |
|
401 | name: 'sctpPort',
|
402 | reg: /^sctp-port:(\d+)$/,
|
403 | format: 'sctp-port:%s'
|
404 | },
|
405 | {
|
406 |
|
407 |
|
408 | name: 'maxMessageSize',
|
409 | reg: /^max-message-size:(\d+)$/,
|
410 | format: 'max-message-size:%s'
|
411 | },
|
412 | {
|
413 |
|
414 |
|
415 | push:'tsRefClocks',
|
416 | reg: /^ts-refclk:([^\s=]*)(?:=(\S*))?/,
|
417 | names: ['clksrc', 'clksrcExt'],
|
418 | format: function (o) {
|
419 | return 'ts-refclk:%s' + (o.clksrcExt != null ? '=%s' : '');
|
420 | }
|
421 | },
|
422 | {
|
423 |
|
424 |
|
425 | name:'mediaClk',
|
426 | reg: /^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,
|
427 | names: ['id', 'mediaClockName', 'mediaClockValue', 'rateNumerator', 'rateDenominator'],
|
428 | format: function (o) {
|
429 | var str = 'mediaclk:';
|
430 | str += (o.id != null ? 'id=%s %s' : '%v%s');
|
431 | str += (o.mediaClockValue != null ? '=%s' : '');
|
432 | str += (o.rateNumerator != null ? ' rate=%s' : '');
|
433 | str += (o.rateDenominator != null ? '/%s' : '');
|
434 | return str;
|
435 | }
|
436 | },
|
437 | {
|
438 |
|
439 | name: 'keywords',
|
440 | reg: /^keywds:(.+)$/,
|
441 | format: 'keywds:%s'
|
442 | },
|
443 | {
|
444 |
|
445 | name: 'content',
|
446 | reg: /^content:(.+)/,
|
447 | format: 'content:%s'
|
448 | },
|
449 |
|
450 | {
|
451 |
|
452 | name: 'bfcpFloorCtrl',
|
453 | reg: /^floorctrl:(c-only|s-only|c-s)/,
|
454 | format: 'floorctrl:%s'
|
455 | },
|
456 | {
|
457 |
|
458 | name: 'bfcpConfId',
|
459 | reg: /^confid:(\d+)/,
|
460 | format: 'confid:%s'
|
461 | },
|
462 | {
|
463 |
|
464 | name: 'bfcpUserId',
|
465 | reg: /^userid:(\d+)/,
|
466 | format: 'userid:%s'
|
467 | },
|
468 | {
|
469 |
|
470 | name: 'bfcpFloorId',
|
471 | reg: /^floorid:(.+) (?:m-stream|mstrm):(.+)/,
|
472 | names: ['id', 'mStream'],
|
473 | format: 'floorid:%s mstrm:%s'
|
474 | },
|
475 | {
|
476 |
|
477 | push: 'invalid',
|
478 | names: ['value']
|
479 | }
|
480 | ]
|
481 | };
|
482 |
|
483 |
|
484 | Object.keys(grammar).forEach(function (key) {
|
485 | var objs = grammar[key];
|
486 | objs.forEach(function (obj) {
|
487 | if (!obj.reg) {
|
488 | obj.reg = /(.*)/;
|
489 | }
|
490 | if (!obj.format) {
|
491 | obj.format = '%s';
|
492 | }
|
493 | });
|
494 | });
|