• Categories
    • Unread
    • Recent
    • Popular
    • Users
    • Groups
    • Register
    • Login
    1. Home
    2. Schamper
    Offline
    • Profile
    • Following 0
    • Followers 2
    • Topics 17
    • Posts 155
    • Groups 1

    Schamper

    @Schamper

    809
    Profile views
    155
    Posts
    2
    Followers
    0
    Following
    Joined
    Last Online
    Website

    Schamper Unfollow Follow

    Best posts made by Schamper

    • How the shoutbox client sockets work

      This is about the following file: sockets.js

      We need more posts, why not write something about how the shoutbox works? Could be interesting for some people I suppose :P

      The fun thing about the recent refactor of the client sockets is that you can call them by simple doing Shoutbox.sockets.<action>(data, callback);. This is possible because we add each message to the global Shoutbox.sockets object. Doing this for every single message would take a lot of time and code, especially with the recent addition of commands. So how do we do this?

      As you can see at the beginning of the file there are 2 objects with a bunch of method names as key and socket events as value, these names will later be used as the <action>:

      	var Messages = {
      		getShouts: 'plugins.shoutbox.get',
      		sendShout: 'plugins.shoutbox.send',
      		removeShout : 'plugins.shoutbox.remove',
      		editShout: 'plugins.shoutbox.edit',
      		notifyStartTyping: 'plugins.shoutbox.notifyStartTyping',
      		notifyStopTyping: 'plugins.shoutbox.notifyStopTyping',
      		getOriginalShout: 'plugins.shoutbox.getOriginalShout',
      		saveSettings: 'plugins.shoutbox.saveSetting',
      		getSettings: 'plugins.shoutbox.getSettings',
      		getUsers: 'user.loadMore',
      		getUserStatus: 'user.isOnline'
      	};
      
      	var Events = {
      		onUserStatusChange: Messages.getUserStatus,
      		onReceive: 'event:shoutbox.receive',
      		onDelete: 'event:shoutbox.delete',
      		onEdit: 'event:shoutbox.edit',
      		onStartTyping: 'event:shoutbox.startTyping',
      		onStopTyping: 'event:shoutbox.stopTyping'
      	};
      

      These are the default messages and events we work with. Extra events or messages required for commands etc are defined by the command itself (we get to this later).

      After that we have a Handlers object, which essentially has all the default socket handlers required for the shoutbox to actually work. You can see some basic stuff ilke onReceive, onDelete etc. You can pretty much guess by their name what their function is. Interesting here is the defaultSocketHandler:

      	var Handlers = {
      		onReceive: ...,
      		onDelete: ...,
      		onEdit: ...,
      		onUserStatusChange: ..,
      		onStartTyping: ...,
      		onStopTyping: ...,
      		defaultSocketHandler: function(message) {
      			this.message = message;
      			var self = this;
      
      			return function (data, callback) {
      				if (typeof data === 'function') {
      					callback = data;
      					data = null;
      				}
      
      				socket.emit(self.message, data, callback);
      			};
      		}
      	};
      

      In the next bit I explain how the defaultSocketHandler works.

      At the very end of the file we find what we actually “expose” to the public/global Shoutbox object.

      	Shoutbox.sockets = {
      		messages: Messages,
      		events: Events,
      		registerMessage: function(handle, message) {
      			if (!Shoutbox.sockets.hasOwnProperty(handle)) {
      				Shoutbox.sockets[handle] = new Handlers.defaultSocketHandler(message);
      			}
      		},
      		registerEvent: function(event, handler) {
      			if (socket.listeners(event).length === 0) {
      				socket.on(event, handler);
      			}
      		},
      		initialize: function() {
      			for (var e in Events) {
      				if (Events.hasOwnProperty(e)) {
      					this.registerEvent(Events[e], Handlers[e]);
      				}
      			}
      
      			for (var m in Messages) {
      				if (Messages.hasOwnProperty(m)) {
      					this.registerMessage(m, Messages[m]);
      				}
      			}
      		}
      	};
      

      The first two keys, messages and events simply expose the default messages and events that we talked about at the beginning. registerMessage is more interesting. Let’s take a closer look at it.

      		registerMessage: function(handle, message) {
      			if (!Shoutbox.sockets.hasOwnProperty(handle)) {
      				Shoutbox.sockets[handle] = new Handlers.defaultSocketHandler(message);
      			}
      		},
      

      registerMessage first checks if we don’t already have the requested key in the Shoutbox.sockets object, if we don’t it adds a new key with a new defaultSocketHandler as value. We pass the message from the second argument to the defaultSocketHandler constructor, which, if you scroll up, is stored in the newly created object with this.message = message;. If you look at the return value of defaultSocketHandler you can see that it returns a function that takes 2 arguments. This function essentially just emits a socket message with the data and callback as arguments. Because we store this newly created function as the value of the Shoutbox.sockets[handle] key, this allows us to do the Shoutbox.sockets.<action>(data, callback); from the beginning of this post.

      registerEvent just registers a new event with socket.io for the passed in event and handler.

      intialize simply loops over all the Events and Messages and calls the appropriate functions to register all the default events and messages.

      Because we expose registerMessage and registerEvent commands and actions can easily add their own methods and event handlers to the Shoutbox.sockets object.

      Hopefully this post was somewhat interesting to read ;)

      posted in Development and Coding
      SchamperS
      Schamper
    • Blog post for my internship

      My boss kept nagging me to make a short blog post about my internship project, so I did. Some of you might know that I’m having trouble getting feedback on my work, so I put in some comments about that in this post.

      Android application development

      I’ve been working on the Projectcampus Android application since September, and I must say I’ve learned a lot about Android and personally think the application is coming along nicely.

      ​​​It all started as a very simple list of hardcoded data, but gradually grew to make use of various Android components such as a Content Provider, Authenticator, Sync Adapter and even custom views. Besides these components I’ve learned about using various mainstream libraries such as Retrofit, OkHttp, Glide, Butterknife, Eventbus, Crashlytics and the Android Support Library.
      ​
      Retrofit powers the REST communication with the Projectcampus backend in combination with EventBus. EventBus is exactly what it sounds like, an event bus. This makes it possible to launch a REST request from anywhere in the application and also to allow any part of the application to receive any REST response. EventBus is also used for other inner-application communication.
      Glide is an image loading and caching library used for the various images used throughout the application. All of the networking is backed by OkHttp.​
      Butterknife is a view “injection” library for Android and is used to reduce the amount of boilerplate code. Crashlytics is used to report crashes and errors.
      The Android Support Library is used for a couple of things like Material support for API levels below 21, Toolbar and new Swipe Refresh Layout.
      ​
      In the current structure, all REST request events are handled by a Retrofit client. This client posts all the results to the event bus. A database service listens to all the response events and writes these to the database through a content provider. Any fragment or activity subscribed to the affected URI’s will be automatically updated through the magic of cursor loaders.
      ​
      I’ve also made sure to improve performance where I can. Making use of the View holder pattern, reducing layout XML complexity and depth and reducing overdraw are a few examples I can currently think of. I’m sure there are parts in my code that can be refactored to be more performant, but that’s hard to determine when you’re the only person looking at the code.
      ​
      The application is also configurable at build time using gradle. There are several properties that can be set to configure the application, most important being the URLs and client ID for the API. There are also properties to disable certain features of the application.
      ​
      All in all I’m fairly happy with the current state of the application. However, I also feel like it could be a lot better and further along if I had occasional feedback. A very large portion of my time has been spend redoing something I did the previous week. On the other hand, I’m also kind of proud of myself that I’ve managed to put together the application in its current state all by myself.

      app

      posted in Development and Coding internship blog
      SchamperS
      Schamper
    • RE: Who is upgrading to Windows 10?

      Or you can use the download tool from here to get it now.

      posted in General Computing
      SchamperS
      Schamper
    • RE: Hardcore Gamer is Here (Well, almost hardcore)

      @Firelad said:

      @Schamper I hope you’re working on your shoutbox when you can. :)

      I already can’t distinguish you from the other members ;)

      posted in Introductions
      SchamperS
      Schamper
    • RE: When Will You Notice Me?

      @Scuzz Might even be the only person with negative rep on NodeBB ever.

      posted in The lounge
      SchamperS
      Schamper
    • RE: BitBangermobiles

      I don’t have a car but this is the closest thing I have :stuck_out_tongue_winking_eye:

      Before
      Before

      After
      After

      posted in The lounge
      SchamperS
      Schamper
    • RE: I did shit today

      I shipped @Almost his E3 flasher.

      posted in The lounge
      SchamperS
      Schamper
    • nodebb-plugin-shoutbox

      After having it integrated at first, I thought it’d be way better if this was a plugin, so here we go!
      Source:
      https://github.com/MrWaffle/nodebb-plugin-shoutbox

      Can be installed from npm:

      npm install nodebb-plugin-shoutbox
      

      After installation has to be enabled in admincp.

      It’s still a work in progress. I plan to add a load of features/settings. See this as a PoC that it can work from a plugin ;)

      posted in Development and Coding
      SchamperS
      Schamper
    • RE: What's up yall?

      The shoutbox is pretty much one big shitbox so you’ll fit right in ;)

      posted in Introductions
      SchamperS
      Schamper
    • RE: Random Facts

      http://instanerd.me/

      posted in The lounge
      SchamperS
      Schamper

    Latest posts made by Schamper

    • RE: What are you listening to today?

      Listening to some older Dutch rap, found this little gem that was a huge success here. Figured I’d share it with you all ;) NSFW.

      https://www.youtube.com/watch?v=eW7MtGV67lc

      posted in The lounge
      SchamperS
      Schamper
    • RE: What are you listening to today?

      @President_Choob didn’t know they had a new album, thanks for reminding me.

      I’ve been listening all sorts of things lately, but since @Almost thanks me for introducing him to Dutch rap, I suppose I must thank him for introducing me to Seeed ;)

      https://www.youtube.com/watch?v=_yWU0lFghxU

      posted in The lounge
      SchamperS
      Schamper
    • RE: Shit Scuzz Says

      posted in The lounge
      SchamperS
      Schamper
    • RE: Shit Scuzz Says

      Doesn’t really fit in here but it was too good not to save.
      shit

      Also pretty curious as to why exactly @Scuzz can’t work for the government.

      posted in The lounge
      SchamperS
      Schamper
    • RE: What are you listening to today?

      https://www.youtube.com/watch?v=gMqIuAJ92tM

      posted in The lounge
      SchamperS
      Schamper
    • RE: [Spoilers?]Star wars

      I agree that they could’ve spent more time on fleshing out Finn’s deal. Especially in the beginning I felt like they just kept jumping from action sequence to action sequence without much story or explanation in between.

      posted in The lounge
      SchamperS
      Schamper
    • RE: Kodi addons

      Genesis is probably the most popular one atm. You can also check out Pulsar.

      posted in General Computing
      SchamperS
      Schamper
    • RE: [Spoilers?]Star wars

      Did not expect that face under that mask. Looked like he walked straight out of Disney XD.

      posted in The lounge
      SchamperS
      Schamper
    • RE: Gumwrapper Truth or Truth

      Well if you classify downloading as stealing… Several Terabytes.

      posted in The lounge
      SchamperS
      Schamper
    • RE: Shit Scuzz Says

      It’s been a while since a good #ShitScuzzySays.

      posted in The lounge
      SchamperS
      Schamper