From efc24cb38867eea5771d650dc4e28ddbd65eed44 Mon Sep 17 00:00:00 2001 From: Myonara Date: Tue, 17 Jul 2018 13:16:43 +0200 Subject: [PATCH] 0.0.6: implmented sound support on GMCP. --- README.md | 3 +- UI/src/app/mudclient/mudclient.component.ts | 7 +++ UI/src/app/shared/mud-signals.ts | 1 + UI/src/app/shared/socket.service.ts | 56 +++++++++++++++++---- backend/server.js | 3 +- 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f5c5ed8a..0aace247 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# webmud3 V0.0.5 !!! +# webmud3 V0.0.6 !!! Webmud3: third generation of the UNItopia Webmud as open source project. In this early stages (Versions < 0.1.0) it's not for production. @@ -6,6 +6,7 @@ Version 0.0.2 delivers a configurable list of muds in frontend/config/config.dev Version 0.0.3 added ANSI colour support Version 0.0.4 fixed an ANSI colour issue and renamed frontend dir to backend. Version 0.0.5 implmented telnet_neg: echo,terminaltype and naws. started with GMCP support. +Version 0.0.6 implemented sound on top of GMCP, working with UNItopia so far. ## Installation in the Development environment ### One time prerequisites: diff --git a/UI/src/app/mudclient/mudclient.component.ts b/UI/src/app/mudclient/mudclient.component.ts index 0beaf6ea..5aa8d8a9 100644 --- a/UI/src/app/mudclient/mudclient.component.ts +++ b/UI/src/app/mudclient/mudclient.component.ts @@ -67,6 +67,13 @@ export class MudclientComponent implements OnInit,OnDestroy { switch (musi.signal) { case 'NOECHO-START': other.inpType = 'password'; break; case 'NOECHO-END': other.inpType = 'text'; break; + case 'Sound.Play.Once': + console.log("Play: ",musi.playSoundFile); + let audio = new Audio(); + audio.src = musi.playSoundFile; + audio.load(); + audio.play(); + break; } }); other.obs_data = other.socketService.mudReceiveData(_id).subscribe(outline => { diff --git a/UI/src/app/shared/mud-signals.ts b/UI/src/app/shared/mud-signals.ts index 02611b8d..81e1b61d 100644 --- a/UI/src/app/shared/mud-signals.ts +++ b/UI/src/app/shared/mud-signals.ts @@ -1,4 +1,5 @@ export class MudSignals { signal : string; id : string; + playSoundFile?: string; } \ No newline at end of file diff --git a/UI/src/app/shared/socket.service.ts b/UI/src/app/shared/socket.service.ts index e8757311..e7ce2091 100644 --- a/UI/src/app/shared/socket.service.ts +++ b/UI/src/app/shared/socket.service.ts @@ -243,6 +243,15 @@ export class SocketService { return observable; } + public sendGMCP(id:string,mod:string,msg:string,data:any) { + if (typeof this.mudConnections[id] === 'undefined') { + console.log('failed[GMCP_Send_packet].mudconn='+id); + return; + } + console.log('GMCP-send:',mod,msg,data); + this.socket.emit('mud-gmcp-outgoing',id,mod,msg,data); + } + public mudReceiveData(_id: string) : Observable { let other = this; let observable = new Observable(observer => { @@ -251,16 +260,6 @@ export class SocketService { return; } other.logger.add('mudReceiveData starting!',false); - other.socket.on('mud-gmcp-incoming',function(id,mod,msg,data){ - if (typeof other.mudConnections[id] === 'undefined') { - console.log('failed[mud-gmcp-incoming].mudconn='+id); - return; - } - if (_id !== id) { - return; - } - console.log('GMCP:',mod,msg,data); - }); other.socket.on('mud-get-naws', function(id,cb) { if (typeof other.mudConnections[id] === 'undefined') { console.log('failed[mud-get-naws].mudconn='+id); @@ -308,6 +307,43 @@ export class SocketService { } observer.next(musi); }) + other.socket.on('mud-gmcp-incoming',function(id,mod,msg,data){ + if (typeof other.mudConnections[id] === 'undefined') { + console.log('failed[mud-gmcp-incoming].mudconn='+id); + return; + } + if (_id !== id) { + return; + } + switch (mod.toLowerCase().trim()) { + case 'core': + switch (msg.toLowerCase().trim()) { + case 'hello': + other.mudConnections[_id]['gmcp-mudname'] = data.name; + other.sendGMCP(_id,'Core','Hello',{'client':'Webmud3a','version':'0.0.6'}); + other.sendGMCP(_id,'Core','Supports.Set',['Sound 1']); + break; + } + break; + case 'sound': + switch (msg.toLowerCase().trim()) { + case 'url': + other.mudConnections[_id]['sound-url'] = data.url; + break; + case 'event': + let soundSignal : MudSignals = { + signal: 'Sound.Play.Once', + id: data.file, + playSoundFile: other.mudConnections[_id]['sound-url']+'/'+data.file, + } + observer.next(soundSignal); + break; + } + break; + default: + } + console.log('GMCP:',mod,msg,data); + }); }); return observable; } diff --git a/backend/server.js b/backend/server.js index c562b31b..ee8b3c1c 100644 --- a/backend/server.js +++ b/backend/server.js @@ -154,7 +154,7 @@ io.on('connection', (socket) => { mudSocket.write(inpline.toString('utf8')+"\r"); } }); - socket.on('mud.gmcp-outgoing', (id,mod,msg,data) => { + socket.on('mud-gmcp-outgoing', (id,mod,msg,data) => { if (typeof id !== 'string' || typeof MudConnections[id] === 'undefined') { io.emit("mud-error","Connection-id unknown"); return; @@ -165,6 +165,7 @@ io.on('connection', (socket) => { let b1 = new Buffer(mod+'.'+msg+' '); let b2 = new Buffer(jsdata); let buf = Buffer.concat([b1,b2],b1.length+b2.length); + console.log(mod,msg,data); mudSocket.writeSub(201 /*TELOPT_GMCP*/, buf); });