How to use the subscriptions-transport-ws.SubscriptionServer function in subscriptions-transport-ws

To help you get started, we’ve selected a few subscriptions-transport-ws examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github erxes / erxes-widgets / server / server.js View on Github external
app.listen(GRAPHQL_PORT);

// websocket server
const WS_PORT = settings.WS_PORT;

const httpServer = createServer((request, response) => {
  response.writeHead(404);
  response.end();
});

httpServer.listen(WS_PORT, () => console.log( // eslint-disable-line no-console
  `Websocket Server is now running on http://localhost:${WS_PORT}`,
));

// subscription server
const server = new SubscriptionServer( // eslint-disable-line no-unused-vars
  { subscriptionManager },
  httpServer,
);

// receive inAppConnected message and save integrationId, customerId in
// connection
server.wsServer.on('connect', (connection) => {
  connection.on('message', (message) => {
    const parsedMessage = JSON.parse(message.utf8Data);

    if (parsedMessage.type === 'inAppConnected') {
      connection.inAppData = parsedMessage.value; // eslint-disable-line no-param-reassign
    }
  });
});
github janikvonrotz / meteor-apollo-accounts-example / server / main.js View on Github external
// seed the database
seed()
const WS_PORT = process.env.WS_PORT || 8080;

createApolloServer({
  schema: schema,
});

const httpServer = createServer((request, response) => {
  response.writeHead(404);
  response.end();
});
httpServer.listen(WS_PORT, () => console.log(
  `Websocket Server is now running on http://localhost:${WS_PORT}`
));
const server = new SubscriptionServer({ subscriptionManager }, httpServer);
github erxes / erxes-widgets / server / server.js View on Github external
app.listen(GRAPHQL_PORT);

// websocket server
const WS_PORT = settings.WS_PORT;

const httpServer = createServer((request, response) => {
  response.writeHead(404);
  response.end();
});

httpServer.listen(WS_PORT, () => console.log( // eslint-disable-line no-console
  `Websocket Server is now running on http://localhost:${WS_PORT}`,
));

// subscription server
const server = new SubscriptionServer( // eslint-disable-line no-unused-vars
  { subscriptionManager },
  httpServer,
);

// receive inAppConnected message and save integrationId, customerId in
// connection
server.wsServer.on('connect', (connection) => {
  connection.on('message', (message) => {
    const parsedMessage = JSON.parse(message.utf8Data);

    if (parsedMessage.type === 'inAppConnected') {
      connection.inAppData = parsedMessage.value; // eslint-disable-line no-param-reassign
    }
  });
});
github notadamking / React-Realtime-Chat / server / server.js View on Github external
models.sequelize.sync({ force: false }).then(() => {
  const server = app.listen(config.server.port, () => {
    console.info(
      `🔌  HTTP and Websocket Server running in ${app.get('env')}`
      + ` on port ${config.server.port}`
    );
  });

  // eslint-disable-next-line
  new SubscriptionServer({ subscriptionManager }, server);
});
github GraphqlBA / codenames-gql / server / index.js View on Github external
// bodyParser is needed just for POST.
app.use('/api/graphql', bodyParser.json(), graphqlExpress({ schema }))
app.use('/api/graphiql', bodyParser.json(), graphiqlExpress({ endpointURL: '/api/graphql' }))

app.listen(PORT)

const websocketServer = createServer((request, response) => {
  response.writeHead(404)
  response.end()
})

websocketServer.listen(WS_PORT, () => console.log(
  `Websocket Server is now running on http://localhost:${WS_PORT}`
))

const subscriptionsServer = new SubscriptionServer(
  {
    subscriptionManager: subscriptionManager
  },
  {
    server: websocketServer
  }
)
github mrdulin / apollo-server-express-starter / src / subscription / demo-2 / server.js View on Github external
server.listen(port, err => {
    if (err) {
      throw new Error(err);
    }
    console.log('Go to http://localhost:4000/graphiql to run queries!');

    const ss = new SubscriptionServer(
      {
        execute,
        subscribe,
        schema,
        onConnect: (connectionParams, webSocket, context) => {
          console.log('onConnect');
          console.log('connectionParams: ', connectionParams);
          return connectionParams;
        },
        onOperation: (message, params, webSocket) => {
          console.log('onOperation');
          console.log('params: ', params);
          console.log('message: ', message);
          return message;
        },
        onOperationDone: webSocket => {
github back4app / antframework / templates / ant-graphql-express / lib / Server.js View on Github external
_startSubscriptionServer (port) {
    logger.log(`Websocket Server is now running on ws://localhost:${port}/subscriptions`);
    this._subscriptionServer = new SubscriptionServer({
      schema: this._schema,
      execute,
      subscribe
    }, {
      server: this._httpServer,
      path: '/subscriptions',
    });
  }
}
github denlysenko / bookapp-api / src / subscriptions / subscription.service.ts View on Github external
createServer(
    schema: any,
    options: ServerOptions = {},
    socketOptions: WebSocket.ServerOptions = {},
  ) {
    this.subscriptionServer = new SubscriptionServer(
      { execute, subscribe, schema, ...options },
      {
        server: this.ws,
        path: '/subscriptions',
        ...socketOptions,
      },
    );
  }
github sergiodxa / grial / server / index.js View on Github external
server.listen(PORT, HOST, error => {
        if (error) return reject(error)
        resolve({
          http: server,
          ws: new SubscriptionServer(this.getSubscriptionOptions(), {
            server,
            path: `/${SUBSCRIPTION_PATH}`
          })
        })
      })
    })
github pubkey / rxdb / examples / graphql / server / index.js View on Github external
serverSubscription.listen(GRAPHQL_SUBSCRIPTION_PORT, () => {
        log(
            'Started graphql-subscription endpoint at http://localhost:' +
            GRAPHQL_SUBSCRIPTION_PORT + GRAPHQL_SUBSCRIPTION_PATH
        );
        const subServer = new SubscriptionServer(
            {
                execute,
                subscribe,
                schema,
                rootValue: root
            },
            {
                server: serverSubscription,
                path: GRAPHQL_SUBSCRIPTION_PATH,
            }
        );
        return subServer;
    });