<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def on_message(self, websocket, msg):
        '''When a new message arrives, it publishes to all listening clients.
        '''
        if msg:
            lines = []
            for li in msg.split('\n'):
                li = li.strip()
                if li:
                    lines.append(li)
            msg = ' '.join(lines)
            if msg:
                return self.pubsub.publish(self.channel, msg)