-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmirror.coffee
39 lines (29 loc) · 1.06 KB
/
mirror.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
colors = require 'colors'
Connection = require './connection'
class Mirror
connections: []
add: (connection) =>
@connections.push connection
getOther: (connection) =>
for item in @connections
if item.token isnt connection.token
return item
else
typing: (connection) =>
console.log (connection.token.green.bold + ' is typing').bold
against = @getOther.call @, connection
against.sendTyping.call against
stoppedTyping: (connection) =>
against = @getOther.call @, connection
against.sendStopTyping.call against
gotMessage: (connection, message) =>
console.log connection.token.green.bold + ': ' + message.yellow.bold
against = @getOther.call @, connection
against.sendMessage.call against, message
strangerDisconnected: (connection) =>
console.log connection.token.green.bold + ' disconnected'.red
against = @getOther.call @, connection
connection.sendDisconnect.call connection
connection.lookForPartner.call connection
against.lookForPartner.call against
module.exports = Mirror