push.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2015 rain1017.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  12. // implied. See the License for the specific language governing
  13. // permissions and limitations under the License. See the AUTHORS file
  14. // for names of contributors.
  15. 'use strict';
  16. module.exports = function(app){
  17. var opts = app.get('pushConfig') || {};
  18. var prefix = opts.prefix || '';
  19. var mdbgoose = app.memdb.goose;
  20. var Types = mdbgoose.Schema.Types;
  21. var ChannelSchema = new mdbgoose.Schema({
  22. _id : String,
  23. players : [String], // [playerId]
  24. connectors : [String], // [connectorId]
  25. }, {collection : prefix + 'channel'});
  26. var ChannelMsgSchema = new mdbgoose.Schema({
  27. _id : String, // channelId
  28. msgs : [Types.Mixed], // [msg, msg]
  29. seq : {type : Number, default : 0}, // next message seq
  30. }, {collection : prefix + 'channel_msg'});
  31. var PlayerChannelSchema = new mdbgoose.Schema({
  32. _id : String, // playerId
  33. channels : [String], // [channelId]
  34. }, {collection : prefix + 'player_channel'});
  35. mdbgoose.model('Channel', ChannelSchema);
  36. mdbgoose.model('ChannelMsg', ChannelMsgSchema);
  37. mdbgoose.model('PlayerChannel', PlayerChannelSchema);
  38. };