Skip to content

Commit

Permalink
0.0.6: implmented sound support on GMCP.
Browse files Browse the repository at this point in the history
  • Loading branch information
Myonara committed Jul 17, 2018
1 parent b571db5 commit efc24cb
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# 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.
Version 0.0.2 delivers a configurable list of muds in frontend/config/config.development, so that the development mode can be used as local browser-mudclient to multiple muds.
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:
Expand Down
7 changes: 7 additions & 0 deletions UI/src/app/mudclient/mudclient.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions UI/src/app/shared/mud-signals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class MudSignals {
signal : string;
id : string;
playSoundFile?: string;
}
56 changes: 46 additions & 10 deletions UI/src/app/shared/socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
let other = this;
let observable = new Observable<string>(observer => {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
});

Expand Down

0 comments on commit efc24cb

Please sign in to comment.