liuyu 4 gadi atpakaļ
vecāks
revīzija
3fdbcba574
1 mainītis faili ar 19 papildinājumiem un 8 dzēšanām
  1. 19 8
      app/service/lookuser.js

+ 19 - 8
app/service/lookuser.js

@@ -37,15 +37,26 @@ class LookuserService extends CrudService {
     lookuser.switchrole = switchrole;
     const res = await lookuser.save();
     if (res) {
-      const { mq } = this.ctx;
-      if (mq) {
-        const exchange = 'switch_role_' + res.userid;
-        const parm = {
-          durable: true,
+      if (switchrole === 'anchor') {
+        const { mq } = this.ctx;
+        if (mq) {
+          const exchange = 'switch_role_' + res.userid;
+          const parm = {
+            durable: true,
+            headers: {
+              userid: res.userid,
+            } };
+          await mq.fanout(exchange, res.userid, JSON.stringify(res), parm);
+        }
+      } else {
+        const url = `http://127.0.0.1:6666/api/stomp/exitroom?uid=${res.userid}&roomid=${res.roomname}`;
+        await this.ctx.curl(url, {
+          method: 'get',
           headers: {
-            userid: res.userid,
-          } };
-        await mq.fanout(exchange, res.userid, JSON.stringify(res), parm);
+            'content-type': 'application/json',
+          },
+          dataType: 'json',
+        });
       }
     }
     return res;