如何获取如图红色框中的弹幕信息呢?想做一些基于弹幕信息的二次开发。
-1.如果不想看长文,直接使用.则在安装好Python3或者Ruby2.0以上版本.
<code class="language-bash"><span class="c">#安装Python客户端</span> pip3 install danmu.fm <span class="c"># 比如主播的直播间</span> danmu.fm http://www.douyutv.com/16789 <span class="c">#或者</span> danmu.fm 16789 <span class="c">#安装Ruby客户端</span> gem install danmu <span class="c">#使用</span> danmu douyu <span class="o">[</span>room_id/url<span class="o">]</span> <span class="c">#比如</span> danmu douyu qiuri danmu douyu http://www.douyutv.com/13861 </code>
<code class="language-json"><span class="p">[{</span><span class="nt">"ip"</span><span class="p">:</span><span class="s2">"119.90.49.107"</span><span class="p">,</span><span class="nt">"port"</span><span class="p">:</span><span class="s2">"8035"</span><span class="p">},{</span><span class="nt">"ip"</span><span class="p">:</span><span class="s2">"119.90.49.102"</span><span class="p">,</span><span class="nt">"port"</span><span class="p">:</span><span class="s2">"8008"</span><span class="p">},{</span><span class="nt">"ip"</span><span class="p">:</span><span class="s2">"119.90.49.110"</span><span class="p">,</span><span class="nt">"port"</span><span class="p">:</span><span class="s2">"8050"</span><span class="p">},{</span><span class="nt">"ip"</span><span class="p">:</span><span class="s2">"119.90.49.104"</span><span class="p">,</span><span class="nt">"port"</span><span class="p">:</span><span class="s2">"8020"</span><span class="p">},{</span><span class="nt">"ip"</span><span class="p">:</span><span class="s2">"119.90.49.107"</span><span class="p">,</span><span class="nt">"port"</span><span class="p">:</span><span class="s2">"8034"</span><span class="p">},{</span><span class="nt">"ip"</span><span class="p">:</span><span class="s2">"119.90.49.92"</span><span class="p">,</span><span class="nt">"port"</span><span class="p">:</span><span class="s2">"8059"</span><span class="p">},{</span><span class="nt">"ip"</span><span class="p">:</span><span class="s2">"119.90.49.95"</span><span class="p">,</span><span class="nt">"port"</span><span class="p">:</span><span class="s2">"8071"</span><span class="p">},{</span><span class="nt">"ip"</span><span class="p">:</span><span class="s2">"119.90.49.101"</span><span class="p">,</span><span class="nt">"port"</span><span class="p">:</span><span class="s2">"8001"</span><span class="p">},{</span><span class="nt">"ip"</span><span class="p">:</span><span class="s2">"119.90.49.93"</span><span class="p">,</span><span class="nt">"port"</span><span class="p">:</span><span class="s2">"8063"</span><span class="p">},{</span><span class="nt">"ip"</span><span class="p">:</span><span class="s2">"119.90.49.91"</span><span class="p">,</span><span class="nt">"port"</span><span class="p">:</span><span class="s2">"8053"</span><span class="p">}]</span> </code>
<code class="language-python3"><span class="n">b</span><span class="s">'</span><span class="se">\x81\x00\x00\x00\x81\x00\x00\x00\xb2\x02\x00\x00</span><span class="s">type@=chatmsg/rid@=9401/uid@=12635840/nn@=</span><span class="se">\xe8\xb6\x85\xe8\xb6\x8a\xe7\xa5\x9e\xe7\x9a\x84</span><span class="s">boy/txt@=</span><span class="se">\xe6\x89\x93\xe8\x84\xb8\xe5\x90\xa7</span><span class="s">/cid@=20e4e3fe427e410c67c5010000000000/level@=5/</span><span class="se">\x00</span><span class="s">'</span> </code>
<code class="language-text">client_danmu = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #在客户端开启心跳维护 client_danmu.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) #官方弹幕服务器'openbarrage.douyutv.com' SERVER = socket.gethostbyname('openbarrage.douyutv.com') PORT = 8601 client_danmu.connect((SERVER,PORT)) client_danmu.settimeout(2) #记得设置延迟,不然卡着recv #这里发的要处理下发送内容,用最高赞的方法获取封包格式就好了 封包1 = 'type@=loginreq/username@=visitor1234567/password@=/roomid@=房间号/' #登陆弹幕服务器 client_danmu.send(封包1) 封包2 = 'type@=joingroup/rid@=房间号/gid@=-9999/' #加入弹幕组,这里要注意,gid就是弹幕组号。-9999是斗鱼开放的第三方获取弹幕的组别。是能获取所有弹幕的。因为有些主播动辄几十万人,那弹幕量如果都发给所有用户,那卡死用户事小,斗鱼自己流量事大啊。所以一般都是分组发送,所以你平时在浏览器看的并不一定是所有弹幕。用-9999这个组别号是可以获取所有的 client_danmu.send(封包2) #这里开始就是用while循环获取弹幕了,记得大概每30秒发一个心跳包过去。 封包3 = 'type@=mrkl/' client_danmu.send(封包3) </code>
<code class="language-text"> 弹幕连接 OnConn (program):1 弹幕 UserLogin [type@=loginreq/username@=xxxx/password@=1234567890123456/roomid@=58718/] (program):1 弹幕 网络数据 [type@=loginres/userid@=0/roomgroup@=67108896/pg@=0/sessionid@=6/username@=/nickname@=/is_signined@=432003648/signin_count@=32756/s@=% ô/live_stat@=125387584/npv@=32756/] (program):1 弹幕登录成功 VM160:1 弹幕分组 [type@=joingroup/rid@=58718/gid@=0/] 2VM171:1 FMPNetStream连接状态:NetStream.Buffer.Full VM175:1 弹幕 网络数据 [type@=userenter/rid@=58718/gid@=0/userinfo@=id@A=4295897@Sname@A=auto_DJUziSYiJo@Snick@A=芙苏不语丶怪力乱神@Srg@A=1@Spg@A=1@Srt@A=1416480352@Sbg@A=0@Sweight@A=12800@Sstrength@A=51800@Scps_id@A=0@Sps@A=1@Sver@A=0@Sm_deserve_lev@A=0@S/] VM176:1 新用户进入信息: [id@=4295897/name@=auto_DJUziSYiJo/nick@=芙苏不语丶怪力乱神/rg@=1/bg@=0/pg@=1/rt@=1416480352/weight@=12800/strength@=51800/cps_id@=0/] </code>
<code class="language-js"><span class="kd">var</span> <span class="nx">net</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'net'</span><span class="p">);</span> <span class="kd">var</span> <span class="nx">uuid</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'node-uuid'</span><span class="p">);</span> <span class="kd">var</span> <span class="nx">md5</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'md5'</span><span class="p">);</span> <span class="kd">var</span> <span class="nx">request</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'request'</span><span class="p">);</span> <span class="kd">var</span> <span class="nx">HOST</span> <span class="o">=</span> <span class="s1">'danmu.douyutv.com'</span><span class="p">;</span> <span class="kd">var</span> <span class="nx">PORT</span> <span class="o">=</span> <span class="mi">8602</span><span class="p">;</span> <span class="kd">function</span> <span class="nx">send</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="nx">payload</span><span class="p">)</span> <span class="p">{</span> <span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Buffer</span><span class="p">(</span><span class="mi">4</span> <span class="o">+</span> <span class="mi">4</span> <span class="o">+</span> <span class="mi">4</span> <span class="o">+</span> <span class="nx">payload</span><span class="p">.</span><span class="nx">length</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="nx">data</span><span class="p">.</span><span class="nx">writeInt32LE</span><span class="p">(</span><span class="mi">4</span> <span class="o">+</span> <span class="mi">4</span> <span class="o">+</span> <span class="nx">payload</span><span class="p">.</span><span class="nx">length</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="c1">//length</span> <span class="nx">data</span><span class="p">.</span><span class="nx">writeInt32LE</span><span class="p">(</span><span class="mi">4</span> <span class="o">+</span> <span class="mi">4</span> <span class="o">+</span> <span class="nx">payload</span><span class="p">.</span><span class="nx">length</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">);</span> <span class="c1">//code</span> <span class="nx">data</span><span class="p">.</span><span class="nx">writeInt32LE</span><span class="p">(</span><span class="mh">0x000002b1</span><span class="p">,</span> <span class="mi">8</span><span class="p">);</span> <span class="c1">//magic</span> <span class="nx">data</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">payload</span><span class="p">,</span> <span class="mi">12</span><span class="p">);</span> <span class="c1">//payload</span> <span class="nx">data</span><span class="p">.</span><span class="nx">writeInt8</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span> <span class="o">+</span> <span class="mi">4</span> <span class="o">+</span> <span class="mi">4</span> <span class="o">+</span> <span class="nx">payload</span><span class="p">.</span><span class="nx">length</span><span class="p">);</span> <span class="c1">//end of string</span> <span class="nx">socket</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">}</span> <span class="kd">function</span> <span class="nx">login</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="nx">roomid</span><span class="p">,</span> <span class="nx">user</span><span class="p">,</span> <span class="nx">password</span><span class="p">)</span> <span class="p">{</span> <span class="kd">var</span> <span class="nx">req</span> <span class="o">=</span> <span class="s1">'type@=loginreq/username@='</span> <span class="o">+</span> <span class="nx">user</span> <span class="o">+</span> <span class="s1">'/password@='</span> <span class="o">+</span> <span class="nx">password</span> <span class="o">+</span> <span class="s1">'/roomid@='</span> <span class="o">+</span> <span class="nx">roomid</span><span class="p">;</span> <span class="nx">send</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="nx">req</span><span class="p">);</span> <span class="p">}</span> <span class="kd">function</span> <span class="nx">getGroupServer</span><span class="p">(</span><span class="nx">roomid</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span> <span class="nx">request</span><span class="p">({</span><span class="nx">uri</span><span class="o">:</span><span class="s1">'http://www.douyutv.com/'</span> <span class="o">+</span> <span class="nx">roomid</span><span class="p">},</span> <span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">resp</span><span class="p">,</span> <span class="nx">body</span><span class="p">)</span> <span class="p">{</span> <span class="kd">var</span> <span class="nx">server_config</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">body</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/room_args = (.*?)\}\;/g</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'room_args = '</span><span class="p">,</span> <span class="s1">''</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="s1">';'</span><span class="p">,</span> <span class="s1">''</span><span class="p">));</span> <span class="nx">server_config</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">unescape</span><span class="p">(</span><span class="nx">server_config</span><span class="p">[</span><span class="s1">'server_config'</span><span class="p">]));</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">server_config</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">ip</span><span class="p">,</span> <span class="nx">server_config</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">port</span><span class="p">);</span> <span class="p">});</span> <span class="p">}</span> <span class="kd">function</span> <span class="nx">getGroupId</span><span class="p">(</span><span class="nx">roomid</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span> <span class="kd">var</span> <span class="nx">rt</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">().</span><span class="nx">now</span><span class="p">;</span> <span class="kd">var</span> <span class="nx">devid</span> <span class="o">=</span> <span class="nx">uuid</span><span class="p">.</span><span class="nx">v4</span><span class="p">().</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/-/g</span><span class="p">,</span> <span class="s1">''</span><span class="p">);</span> <span class="kd">var</span> <span class="nx">vk</span> <span class="o">=</span> <span class="nx">md5</span><span class="p">(</span><span class="nx">rt</span> <span class="o">+</span> <span class="s1">'7oE9nPEG9xXV69phU31FYCLUagKeYtsF'</span> <span class="o">+</span> <span class="nx">devid</span><span class="p">)</span> <span class="kd">var</span> <span class="nx">req</span> <span class="o">=</span> <span class="s1">'type@=loginreq/username@=/password@=/roomid@='</span> <span class="o">+</span> <span class="nx">roomid</span> <span class="o">+</span> <span class="s1">'/ct@=0/vk@='</span> <span class="o">+</span> <span class="nx">vk</span> <span class="o">+</span> <span class="s1">'/devid@='</span> <span class="o">+</span> <span class="nx">devid</span> <span class="o">+</span> <span class="s1">'/rt@='</span> <span class="o">+</span> <span class="nx">rt</span> <span class="o">+</span> <span class="s1">'/ver=@20150929/'</span><span class="p">;</span> <span class="nx">getGroupServer</span><span class="p">(</span><span class="nx">roomid</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">server</span><span class="p">,</span> <span class="nx">port</span><span class="p">)</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">'group server: '</span> <span class="o">+</span> <span class="nx">server</span> <span class="o">+</span> <span class="s1">':'</span> <span class="o">+</span> <span class="nx">port</span><span class="p">);</span> <span class="kd">var</span> <span class="nx">socket</span> <span class="o">=</span> <span class="nx">net</span><span class="p">.</span><span class="nx">connect</span><span class="p">(</span><span class="nx">port</span><span class="p">,</span> <span class="nx">server</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="nx">send</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="nx">req</span><span class="p">);</span> <span class="p">});</span> <span class="nx">socket</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">'data'</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span> <span class="k">if</span> <span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=setmsggroup'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="kd">var</span> <span class="nx">gid</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">toString</span><span class="p">().</span><span class="nx">match</span><span class="p">(</span><span class="sr">/gid@=(.*?)\//g</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'gid@='</span><span class="p">,</span> <span class="s1">''</span><span class="p">);</span> <span class="nx">gid</span> <span class="o">=</span> <span class="nx">gid</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">gid</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span> <span class="nx">socket</span><span class="p">.</span><span class="nx">destroy</span><span class="p">();</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">gid</span><span class="p">);</span> <span class="p">}</span> <span class="p">});</span> <span class="p">});</span> <span class="p">}</span> <span class="kd">function</span> <span class="nx">monitorRoom</span><span class="p">(</span><span class="nx">roomid</span><span class="p">)</span> <span class="p">{</span> <span class="kd">var</span> <span class="nx">socket</span> <span class="o">=</span> <span class="nx">net</span><span class="p">.</span><span class="nx">connect</span><span class="p">(</span><span class="nx">PORT</span><span class="p">,</span> <span class="nx">HOST</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="nx">login</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="s1">'visitor1234567'</span><span class="p">,</span> <span class="s1">'1234567890123456'</span><span class="p">);</span> <span class="p">});</span> <span class="nx">setInterval</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="nx">send</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="s1">'type@=keeplive/tick@=70/'</span><span class="p">);</span> <span class="c1">//send keep alive message repeatly</span> <span class="p">},</span> <span class="mi">50000</span><span class="p">);</span> <span class="nx">socket</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">'data'</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//data is a Buffer here</span> <span class="k">if</span> <span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=loginres'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="nx">getGroupId</span><span class="p">(</span><span class="nx">roomid</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">gid</span><span class="p">)</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">'gid of room['</span> <span class="o">+</span> <span class="nx">roomid</span> <span class="o">+</span><span class="s1">'] is '</span> <span class="o">+</span> <span class="nx">gid</span><span class="p">)</span> <span class="nx">send</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="s1">'type@=joingroup/rid@='</span> <span class="o">+</span> <span class="nx">roomid</span> <span class="o">+</span> <span class="s1">'/gid@='</span> <span class="o">+</span> <span class="nx">gid</span> <span class="o">+</span> <span class="s1">'/'</span><span class="p">);</span> <span class="p">});</span> <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=chatmessage'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="kd">var</span> <span class="nx">msg</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">toString</span><span class="p">();</span> <span class="kd">var</span> <span class="nx">snick</span> <span class="o">=</span> <span class="nx">msg</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/snick@=(.*?)\//g</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'snick@='</span><span class="p">,</span> <span class="s1">''</span><span class="p">);</span> <span class="kd">var</span> <span class="nx">content</span> <span class="o">=</span> <span class="nx">msg</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/content@=(.*?)\//g</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'content@='</span><span class="p">,</span> <span class="s1">''</span><span class="p">);</span> <span class="nx">snick</span> <span class="o">=</span> <span class="nx">snick</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">snick</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span> <span class="nx">content</span> <span class="o">=</span> <span class="nx">content</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">content</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">snick</span> <span class="o">+</span> <span class="s1">': '</span> <span class="o">+</span> <span class="nx">content</span><span class="p">);</span><span class="c1">// 弹幕</span> <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=userenter'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">||</span> <span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=keeplive'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">||</span> <span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=dgn/gfid@=131'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">||</span> <span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=blackres'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">||</span> <span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=dgn/gfid@=129'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">||</span> <span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=upgrade'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">||</span> <span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=ranklist'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">||</span> <span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=onlinegift'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//没用的消息</span> <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'type@=spbc'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="kd">var</span> <span class="nx">drid</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">toString</span><span class="p">().</span><span class="nx">match</span><span class="p">(</span><span class="sr">/drid@=(.*?)\//g</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'drid@='</span><span class="p">,</span> <span class="s1">''</span><span class="p">);</span> <span class="nx">drid</span> <span class="o">=</span> <span class="nx">drid</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">drid</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">'rocket! room id:'</span> <span class="o">+</span> <span class="nx">drid</span><span class="p">);</span> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">toString</span><span class="p">());</span> <span class="c1">//在这里显示其它类型的消息</span> <span class="p">}</span> <span class="p">});</span> <span class="p">}</span> <span class="nx">monitorRoom</span><span class="p">(</span><span class="s1">''</span><span class="p">);</span> </code>
<code class="language-text">type@=loginreq/roomid@=****/ </code>