@@ -327,39 +327,39 @@ var ws = require("ws");
327327
328328var wss = new ws.Server({
329329 server: server,
330- path: "/helloworld"
330+ path: "/helloworld",
331331});
332332
333- wss.on("connection", function(ws) {
333+ wss.on("connection", function (ws) {
334334 var sessionId = null;
335335 var request = ws.upgradeReq;
336336 var response = {
337- writeHead: {}
337+ writeHead: {},
338338 };
339339
340- sessionHandler(request, response, function(err) {
340+ sessionHandler(request, response, function (err) {
341341 sessionId = request.session.id;
342342 });
343343
344- ws.on("error", error => {
344+ ws.on("error", ( error) => {
345345 stop(sessionId);
346346 });
347347
348348 ws.on("close", () => {
349349 stop(sessionId);
350350 });
351351
352- ws.on("message", _message => {
352+ ws.on("message", ( _message) => {
353353 var message = JSON.parse(_message);
354354
355355 switch (message.id) {
356356 case "start":
357357 sessionId = request.session.id;
358- start(sessionId, ws, message.sdpOffer, function(error, sdpAnswer) {
358+ start(sessionId, ws, message.sdpOffer, function (error, sdpAnswer) {
359359 ws.send(
360360 JSON.stringify({
361361 id: "startResponse",
362- sdpAnswer: sdpAnswer
362+ sdpAnswer: sdpAnswer,
363363 })
364364 );
365365 });
@@ -434,26 +434,26 @@ function start(sessionId, ws, sdpOffer, callback) {
434434 }
435435 }
436436 // Connect it back on itself (i.e. in loopback)
437- connectMediaElements(webRtcEndpoint, error => {
438- webRtcEndpoint.on("OnIceCandidate", function(event) {
437+ connectMediaElements(webRtcEndpoint, ( error) => {
438+ webRtcEndpoint.on("OnIceCandidate", function (event) {
439439 const candidate = kurento.getComplexType("IceCandidate")(event.candidate);
440440 ws.send(
441441 JSON.stringify({
442442 id: "iceCandidate",
443- candidate: candidate
443+ candidate: candidate,
444444 })
445445 );
446446 });
447447
448448 webRtcEndpoint.processOffer(sdpOffer, (error, sdpAnswer) => {
449449 sessions[sessionId] = {
450450 pipeline: pipeline,
451- webRtcEndpoint: webRtcEndpoint
451+ webRtcEndpoint: webRtcEndpoint,
452452 };
453453 return callback(null, sdpAnswer);
454454 });
455455
456- webRtcEndpoint.gatherCandidates(error => {
456+ webRtcEndpoint.gatherCandidates(( error) => {
457457 if (error) {
458458 return callback(error);
459459 }
@@ -480,15 +480,12 @@ function createMediaElements(pipeline, ws, callback) {
480480
481481` ` ` javascript
482482function connectMediaElements(webRtcEndpoint, callback) {
483- webRtcEndpoint.connect(
484- webRtcEndpoint,
485- error => {
486- if (error) {
487- return callback(error);
488- }
489- return callback(null);
483+ webRtcEndpoint.connect(webRtcEndpoint, (error) => {
484+ if (error) {
485+ return callback(error);
490486 }
491- );
487+ return callback(null);
488+ });
492489}
493490` ` `
494491
@@ -535,10 +532,10 @@ function start() {
535532 var options = {
536533 localVideo: videoInput,
537534 remoteVideo: videoOutput,
538- onicecandidate: onIceCandidate
535+ onicecandidate: onIceCandidate,
539536 };
540537
541- webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(options, function(error) {
538+ webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(options, function (error) {
542539 if (error) return onError(error);
543540 this.generateOffer(onOffer);
544541 });
@@ -547,14 +544,14 @@ function start() {
547544function onIceCandidate(candidate) {
548545 sendMessage({
549546 id: "onIceCandidate",
550- candidate: candidate
547+ candidate: candidate,
551548 });
552549}
553550
554551function onOffer(error, offerSdp) {
555552 sendMessage({
556553 id: "start",
557- sdpOffer: offerSdp
554+ sdpOffer: offerSdp,
558555 });
559556}
560557` ` `
@@ -563,7 +560,7 @@ Whenever a WebSocket message is received, either starting communication, changin
563560an appropriate action is taken.
564561
565562` ` ` javascript
566- ws.onmessage = function(message) {
563+ ws.onmessage = function (message) {
567564 var parsedMessage = JSON.parse(message.data);
568565
569566 switch (parsedMessage.id) {
@@ -654,7 +651,7 @@ function createMediaElements(pipeline, ws, callback) {
654651 -1.2,
655652 1.6,
656653 1.6,
657- function(error) {
654+ function (error) {
658655 if (error) {
659656 return callback(error);
660657 }
@@ -668,24 +665,18 @@ function createMediaElements(pipeline, ws, callback) {
668665
669666` ` ` javascript
670667function connectMediaElements(webRtcEndpoint, faceOverlayFilter, callback) {
671- webRtcEndpoint.connect(
672- faceOverlayFilter,
673- error => {
668+ webRtcEndpoint.connect(faceOverlayFilter, (error) => {
669+ if (error) {
670+ return callback(error);
671+ }
672+ faceOverlayFilter.connect(webRtcEndpoint, (error) => {
674673 if (error) {
675674 return callback(error);
676675 }
677- faceOverlayFilter.connect(
678- webRtcEndpoint,
679- error => {
680- if (error) {
681- return callback(error);
682- }
683676
684- return callback(null);
685- }
686- );
687- }
688- );
677+ return callback(null);
678+ });
679+ });
689680}
690681` ` `
691682
@@ -816,25 +807,19 @@ function createMediaElements(pipeline, ws, callback) {
816807
817808``` javascript
818809function connectMediaElements (webRtcEndpoint , filter , callback ) {
819- webRtcEndpoint .connect (
820- filter,
821- error => {
810+ webRtcEndpoint .connect (filter, (error ) => {
811+ if (error) {
812+ return callback (error);
813+ }
814+
815+ filter .connect (webRtcEndpoint, (error ) => {
822816 if (error) {
823817 return callback (error);
824818 }
825819
826- filter .connect (
827- webRtcEndpoint,
828- error => {
829- if (error) {
830- return callback (error);
831- }
832-
833- return callback (null );
834- }
835- );
836- }
837- );
820+ return callback (null );
821+ });
822+ });
838823}
839824```
840825
0 commit comments